Renamings.

This commit is contained in:
Sergey Pepyakin 2019-04-15 20:17:44 +02:00
parent 0b11d665aa
commit 9935df3307
6 changed files with 24 additions and 22 deletions

View File

@ -112,7 +112,6 @@ extern crate core;
#[cfg(test)] #[cfg(test)]
extern crate wabt; extern crate wabt;
#[cfg(test)] #[cfg(test)]
#[macro_use]
extern crate assert_matches; extern crate assert_matches;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]

View File

@ -8,7 +8,7 @@ use validation::func::{
}; };
use validation::stack::StackWithLimit; use validation::stack::StackWithLimit;
use validation::util::Locals; use validation::util::Locals;
use validation::{Error, FunctionValidator}; use validation::{Error, FuncValidator};
use isa; use isa;
@ -67,7 +67,7 @@ pub struct Compiler {
label_stack: Vec<BlockFrameType>, label_stack: Vec<BlockFrameType>,
} }
impl FunctionValidator for Compiler { impl FuncValidator for Compiler {
type Output = isa::Instructions; type Output = isa::Instructions;
fn new(_module: &FunctionValidationContext) -> Self { fn new(_module: &FunctionValidationContext) -> Self {
let mut compiler = Compiler { let mut compiler = Compiler {

View File

@ -26,7 +26,7 @@ pub struct WasmiValidation {
// validation time. // validation time.
impl Validation for WasmiValidation { impl Validation for WasmiValidation {
type Output = Vec<isa::Instructions>; type Output = Vec<isa::Instructions>;
type FunctionValidator = compile::Compiler; type FuncValidator = compile::Compiler;
fn new(_module: &Module) -> Self { fn new(_module: &Module) -> Self {
WasmiValidation { WasmiValidation {
// TODO: with capacity? // TODO: with capacity?

View File

@ -2,7 +2,7 @@
use alloc::prelude::v1::*; use alloc::prelude::v1::*;
use crate::{ use crate::{
context::ModuleContext, stack::StackWithLimit, util::Locals, Error, FunctionValidator, context::ModuleContext, stack::StackWithLimit, util::Locals, Error, FuncValidator,
DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX, DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX,
}; };
@ -99,7 +99,7 @@ impl PartialEq<StackValueType> for ValueType {
} }
} }
pub fn drive<T: FunctionValidator>( pub fn drive<T: FuncValidator>(
module: &ModuleContext, module: &ModuleContext,
func: &Func, func: &Func,
body: &FuncBody, body: &FuncBody,

View File

@ -79,17 +79,17 @@ impl From<stack::Error> for Error {
pub trait Validation { pub trait Validation {
type Output; type Output;
type FunctionValidator: FunctionValidator; type FuncValidator: FuncValidator;
fn new(module: &Module) -> Self; fn new(module: &Module) -> Self;
fn on_function_validated( fn on_function_validated(
&mut self, &mut self,
index: u32, index: u32,
output: <<Self as Validation>::FunctionValidator as FunctionValidator>::Output, output: <<Self as Validation>::FuncValidator as FuncValidator>::Output,
); );
fn finish(self) -> Self::Output; fn finish(self) -> Self::Output;
} }
pub trait FunctionValidator { pub trait FuncValidator {
type Output; type Output;
fn new(ctx: &func::FunctionValidationContext) -> Self; fn new(ctx: &func::FunctionValidationContext) -> Self;
fn next_instruction( fn next_instruction(
@ -100,19 +100,19 @@ pub trait FunctionValidator {
fn finish(self) -> Self::Output; fn finish(self) -> Self::Output;
} }
pub struct SimpleValidation; /// A module validator that just validates modules and produces no result.
pub struct SimpleFunctionValidator; pub struct PlainValidator;
impl Validation for SimpleValidation { impl Validation for PlainValidator {
type Output = (); type Output = ();
type FunctionValidator = SimpleFunctionValidator; type FuncValidator = PlainFuncValidator;
fn new(_module: &Module) -> SimpleValidation { fn new(_module: &Module) -> PlainValidator {
SimpleValidation PlainValidator
} }
fn on_function_validated( fn on_function_validated(
&mut self, &mut self,
_index: u32, _index: u32,
_output: <<Self as Validation>::FunctionValidator as FunctionValidator>::Output, _output: <<Self as Validation>::FuncValidator as FuncValidator>::Output,
) -> () { ) -> () {
() ()
} }
@ -121,11 +121,14 @@ impl Validation for SimpleValidation {
} }
} }
impl FunctionValidator for SimpleFunctionValidator { /// A function validator that just validates modules and produces no result.
pub struct PlainFuncValidator;
impl FuncValidator for PlainFuncValidator {
type Output = (); type Output = ();
fn new(_ctx: &func::FunctionValidationContext) -> SimpleFunctionValidator { fn new(_ctx: &func::FunctionValidationContext) -> PlainFuncValidator {
SimpleFunctionValidator PlainFuncValidator
} }
fn next_instruction( fn next_instruction(
@ -232,7 +235,7 @@ pub fn validate_module<V: Validation>(module: &Module) -> Result<V::Output, Erro
.get(index as usize) .get(index as usize)
.ok_or(Error(format!("Missing body for function {}", index)))?; .ok_or(Error(format!("Missing body for function {}", index)))?;
let output = func::drive::<V::FunctionValidator>(&context, function, function_body) let output = func::drive::<V::FuncValidator>(&context, function, function_body)
.map_err(|Error(ref msg)| { .map_err(|Error(ref msg)| {
Error(format!( Error(format!(
"Function #{} reading/validation error: {}", "Function #{} reading/validation error: {}",

View File

@ -1,4 +1,4 @@
use crate::{Error, SimpleValidation}; use crate::{Error, PlainValidator};
use parity_wasm::builder::module; use parity_wasm::builder::module;
use parity_wasm::elements::{ use parity_wasm::elements::{
BlockType, External, GlobalEntry, GlobalType, ImportEntry, InitExpr, Instruction, Instructions, BlockType, External, GlobalEntry, GlobalType, ImportEntry, InitExpr, Instruction, Instructions,
@ -6,7 +6,7 @@ use parity_wasm::elements::{
}; };
fn validate_module(module: &Module) -> Result<(), Error> { fn validate_module(module: &Module) -> Result<(), Error> {
super::validate_module::<SimpleValidation>(module) super::validate_module::<PlainValidator>(module)
} }
#[test] #[test]