Procházet zdrojové kódy

The LR(1) parser produces a parse tree (pt) not ast

Signed-off-by: Sean Young <sean@mess.org>
Sean Young před 5 roky
rodič
revize
5763d2e11e

+ 2 - 3
src/abi/ethereum.rs

@@ -1,6 +1,5 @@
 // ethereum style ABIs
-
-use parser::ast;
+use parser::pt;
 use resolver::{Namespace, Type};
 use serde::Serialize;
 
@@ -63,7 +62,7 @@ pub fn gen_abi(contract_no: usize, ns: &Namespace) -> Vec<ABI> {
         .functions
         .iter()
         .filter(|f| match f.visibility {
-            ast::Visibility::Public(_) | ast::Visibility::External(_) => true,
+            pt::Visibility::Public(_) | pt::Visibility::External(_) => true,
             _ => false,
         })
         .map(|f| ABI {

+ 3 - 4
src/abi/substrate.rs

@@ -1,7 +1,6 @@
 // Parity Substrate style ABIs/metadata
-
 use num_traits::ToPrimitive;
-use parser::ast;
+use parser::pt;
 use resolver;
 use serde::{Deserialize, Serialize};
 
@@ -424,8 +423,8 @@ pub fn gen_abi(contract_no: usize, ns: &resolver::Namespace) -> Metadata {
         .functions
         .iter()
         .filter(|f| match f.visibility {
-            ast::Visibility::Public(_) | ast::Visibility::External(_) => {
-                f.ty == ast::FunctionTy::Function
+            pt::Visibility::Public(_) | pt::Visibility::External(_) => {
+                f.ty == pt::FunctionTy::Function
             }
             _ => false,
         })

+ 2 - 2
src/emit/ewasm.rs

@@ -1,4 +1,4 @@
-use parser::ast;
+use parser::pt;
 use resolver;
 use resolver::cfg::HashTy;
 use std::cell::RefCell;
@@ -568,7 +568,7 @@ impl EwasmTarget {
 
         contract.emit_function_dispatch(
             &contract.contract.functions,
-            ast::FunctionTy::Function,
+            pt::FunctionTy::Function,
             &contract.functions,
             argsdata,
             argslen,

+ 4 - 4
src/emit/mod.rs

@@ -1,5 +1,5 @@
 use hex;
-use parser::ast;
+use parser::pt;
 use resolver;
 use resolver::cfg;
 use resolver::expression::{Expression, StringLocation};
@@ -680,10 +680,10 @@ impl<'a> Contract<'a> {
 
         for resolver_func in &self.contract.functions {
             let name = match resolver_func.ty {
-                ast::FunctionTy::Function => {
+                pt::FunctionTy::Function => {
                     format!("sol::function::{}", resolver_func.wasm_symbol(self.ns))
                 }
-                ast::FunctionTy::Constructor => {
+                pt::FunctionTy::Constructor => {
                     format!("sol::constructor{}", resolver_func.wasm_symbol(self.ns))
                 }
                 _ => format!("sol::{}", resolver_func.ty),
@@ -3191,7 +3191,7 @@ impl<'a> Contract<'a> {
     pub fn emit_function_dispatch<F>(
         &self,
         resolver_functions: &[resolver::FunctionDecl],
-        function_ty: ast::FunctionTy,
+        function_ty: pt::FunctionTy,
         functions: &[FunctionValue<'a>],
         argsdata: inkwell::values::PointerValue<'a>,
         argslen: inkwell::values::IntValue<'a>,

+ 2 - 2
src/emit/sabre.rs

@@ -1,4 +1,4 @@
-use parser::ast;
+use parser::pt;
 use resolver;
 use resolver::cfg::HashTy;
 use std::str;
@@ -207,7 +207,7 @@ impl SabreTarget {
 
         contract.emit_function_dispatch(
             &contract.contract.functions,
-            ast::FunctionTy::Function,
+            pt::FunctionTy::Function,
             &contract.functions,
             argsdata,
             argslen,

+ 3 - 3
src/emit/substrate.rs

@@ -7,7 +7,7 @@ use inkwell::AddressSpace;
 use inkwell::IntPredicate;
 use inkwell::OptimizationLevel;
 use num_traits::ToPrimitive;
-use parser::ast;
+use parser::pt;
 use resolver;
 use resolver::cfg::HashTy;
 use std::collections::HashMap;
@@ -443,7 +443,7 @@ impl SubstrateTarget {
 
         contract.emit_function_dispatch(
             &contract.contract.functions,
-            ast::FunctionTy::Constructor,
+            pt::FunctionTy::Constructor,
             &contract.functions,
             deploy_args,
             deploy_args_length,
@@ -476,7 +476,7 @@ impl SubstrateTarget {
 
         contract.emit_function_dispatch(
             &contract.contract.functions,
-            ast::FunctionTy::Function,
+            pt::FunctionTy::Function,
             &contract.functions,
             call_args,
             call_args_length,

+ 15 - 20
src/output.rs

@@ -1,4 +1,4 @@
-use parser::ast;
+use parser::pt;
 use serde::Serialize;
 
 #[derive(Debug, PartialEq)]
@@ -20,7 +20,7 @@ pub enum ErrorType {
 
 #[derive(Debug, PartialEq)]
 pub struct Note {
-    pub pos: ast::Loc,
+    pub pos: pt::Loc,
     pub message: String,
 }
 
@@ -28,7 +28,7 @@ pub struct Note {
 pub struct Output {
     pub level: Level,
     pub ty: ErrorType,
-    pub pos: ast::Loc,
+    pub pos: pt::Loc,
     pub message: String,
     pub notes: Vec<Note>,
 }
@@ -44,7 +44,7 @@ impl Level {
 }
 
 impl Output {
-    pub fn info(pos: ast::Loc, message: String) -> Self {
+    pub fn info(pos: pt::Loc, message: String) -> Self {
         Output {
             level: Level::Info,
             ty: ErrorType::None,
@@ -54,7 +54,7 @@ impl Output {
         }
     }
 
-    pub fn parser_error(pos: ast::Loc, message: String) -> Self {
+    pub fn parser_error(pos: pt::Loc, message: String) -> Self {
         Output {
             level: Level::Error,
             ty: ErrorType::ParserError,
@@ -64,7 +64,7 @@ impl Output {
         }
     }
 
-    pub fn error(pos: ast::Loc, message: String) -> Self {
+    pub fn error(pos: pt::Loc, message: String) -> Self {
         Output {
             level: Level::Error,
             ty: ErrorType::SyntaxError,
@@ -74,7 +74,7 @@ impl Output {
         }
     }
 
-    pub fn decl_error(pos: ast::Loc, message: String) -> Self {
+    pub fn decl_error(pos: pt::Loc, message: String) -> Self {
         Output {
             level: Level::Error,
             ty: ErrorType::DeclarationError,
@@ -84,7 +84,7 @@ impl Output {
         }
     }
 
-    pub fn type_error(pos: ast::Loc, message: String) -> Self {
+    pub fn type_error(pos: pt::Loc, message: String) -> Self {
         Output {
             level: Level::Error,
             ty: ErrorType::TypeError,
@@ -94,7 +94,7 @@ impl Output {
         }
     }
 
-    pub fn warning(pos: ast::Loc, message: String) -> Self {
+    pub fn warning(pos: pt::Loc, message: String) -> Self {
         Output {
             level: Level::Warning,
             ty: ErrorType::Warning,
@@ -105,9 +105,9 @@ impl Output {
     }
 
     pub fn warning_with_note(
-        pos: ast::Loc,
+        pos: pt::Loc,
         message: String,
-        note_pos: ast::Loc,
+        note_pos: pt::Loc,
         note: String,
     ) -> Self {
         Output {
@@ -122,7 +122,7 @@ impl Output {
         }
     }
 
-    pub fn warning_with_notes(pos: ast::Loc, message: String, notes: Vec<Note>) -> Self {
+    pub fn warning_with_notes(pos: pt::Loc, message: String, notes: Vec<Note>) -> Self {
         Output {
             level: Level::Warning,
             ty: ErrorType::Warning,
@@ -132,12 +132,7 @@ impl Output {
         }
     }
 
-    pub fn error_with_note(
-        pos: ast::Loc,
-        message: String,
-        note_pos: ast::Loc,
-        note: String,
-    ) -> Self {
+    pub fn error_with_note(pos: pt::Loc, message: String, note_pos: pt::Loc, note: String) -> Self {
         Output {
             level: Level::Error,
             ty: ErrorType::None,
@@ -150,7 +145,7 @@ impl Output {
         }
     }
 
-    pub fn error_with_notes(pos: ast::Loc, message: String, notes: Vec<Note>) -> Self {
+    pub fn error_with_notes(pos: pt::Loc, message: String, notes: Vec<Note>) -> Self {
         Output {
             level: Level::Error,
             ty: ErrorType::None,
@@ -262,7 +257,7 @@ impl FilePostitions {
         FilePostitions(line_starts)
     }
 
-    fn to_string(&self, loc: ast::Loc) -> String {
+    fn to_string(&self, loc: pt::Loc) -> String {
         let (from_line, from_column) = self.convert(loc.0);
         let (to_line, to_column) = self.convert(loc.1);
 

+ 1 - 1
src/parser/lexer.rs

@@ -9,7 +9,7 @@ use std::iter::Peekable;
 use std::str::CharIndices;
 use unicode_xid::UnicodeXID;
 
-use super::ast::Loc;
+use super::pt::Loc;
 
 pub type Spanned<Token, Loc, Error> = Result<(Loc, Token, Loc), Error>;
 

+ 7 - 7
src/parser/mod.rs

@@ -1,5 +1,5 @@
-pub mod ast;
 pub mod lexer;
+pub mod pt;
 
 #[allow(clippy::all)]
 #[cfg_attr(rustfmt, rustfmt_skip)]
@@ -8,7 +8,7 @@ pub mod solidity;
 use lalrpop_util::ParseError;
 use output::Output;
 
-pub fn parse(src: &str) -> Result<ast::SourceUnit, Vec<Output>> {
+pub fn parse(src: &str) -> Result<pt::SourceUnit, Vec<Output>> {
     // parse phase
     let lex = lexer::Lexer::new(src);
 
@@ -19,13 +19,13 @@ pub fn parse(src: &str) -> Result<ast::SourceUnit, Vec<Output>> {
     if let Err(e) = s {
         errors.push(match e {
             ParseError::InvalidToken { location } => {
-                Output::parser_error(ast::Loc(location, location), "invalid token".to_string())
+                Output::parser_error(pt::Loc(location, location), "invalid token".to_string())
             }
             ParseError::UnrecognizedToken {
                 token: (l, token, r),
                 expected,
             } => Output::parser_error(
-                ast::Loc(l, r),
+                pt::Loc(l, r),
                 format!(
                     "unrecognised token `{}', expected {}",
                     token,
@@ -34,11 +34,11 @@ pub fn parse(src: &str) -> Result<ast::SourceUnit, Vec<Output>> {
             ),
             ParseError::User { error } => Output::parser_error(error.loc(), error.to_string()),
             ParseError::ExtraToken { token } => Output::parser_error(
-                ast::Loc(token.0, token.2),
+                pt::Loc(token.0, token.2),
                 format!("extra token `{}' encountered", token.0),
             ),
             ParseError::UnrecognizedEOF { location, expected } => Output::parser_error(
-                ast::Loc(location, location),
+                pt::Loc(location, location),
                 format!("unexpected end of file, expecting {}", expected.join(", ")),
             ),
         });
@@ -58,8 +58,8 @@ pub fn box_option<T>(o: Option<T>) -> Option<Box<T>> {
 
 #[cfg(test)]
 mod test {
-    use parser::ast::*;
     use parser::lexer;
+    use parser::pt::*;
     use parser::solidity;
 
     #[test]

+ 0 - 0
src/parser/ast.rs → src/parser/pt.rs


+ 1 - 1
src/parser/solidity.lalrpop

@@ -1,6 +1,6 @@
 use std::str::FromStr;
 use num_bigint::BigInt;
-use parser::ast::*;
+use parser::pt::*;
 use parser::box_option;
 use super::lexer::{Token, LexicalError, fold_doc_comments, CommentType};
 

+ 3 - 3
src/parser/solidity.rs

@@ -1,8 +1,8 @@
 // auto-generated: "lalrpop 0.19.0"
-// sha256: 9687b6d0ce3e299eb69b12bd39eb7b5bd033d55f39651b848c578c59e468
+// sha256: 531dd9ad2e484a9afeab7ce8693924d79591f39761f1a395e71202e9ed1f471
 use std::str::FromStr;
 use num_bigint::BigInt;
-use parser::ast::*;
+use parser::pt::*;
 use parser::box_option;
 use super::lexer::{Token, LexicalError, fold_doc_comments, CommentType};
 #[allow(unused_extern_crates)]
@@ -16,7 +16,7 @@ mod __parse__SourceUnit {
 
     use std::str::FromStr;
     use num_bigint::BigInt;
-    use parser::ast::*;
+    use parser::pt::*;
     use parser::box_option;
     use super::super::lexer::{Token, LexicalError, fold_doc_comments, CommentType};
     #[allow(unused_extern_crates)]

+ 46 - 46
src/resolver/builtin.rs

@@ -2,7 +2,7 @@ use super::cfg::{ControlFlowGraph, HashTy, Instr, Vartable};
 use super::expression::Expression;
 use super::{FunctionDecl, Namespace, Parameter};
 use crate::Target;
-use parser::ast;
+use parser::pt;
 use resolver;
 
 pub fn add_builtin_function(ns: &mut Namespace, contract_no: usize) {
@@ -15,19 +15,19 @@ pub fn add_builtin_function(ns: &mut Namespace, contract_no: usize) {
 }
 
 fn add_assert(ns: &mut Namespace, contract_no: usize) {
-    let id = ast::Identifier {
-        loc: ast::Loc(0, 0),
+    let id = pt::Identifier {
+        loc: pt::Loc(0, 0),
         name: "assert".to_owned(),
     };
 
     let mut assert = FunctionDecl::new(
-        ast::Loc(0, 0),
+        pt::Loc(0, 0),
         "assert".to_owned(),
         vec![],
-        ast::FunctionTy::Function,
+        pt::FunctionTy::Function,
         None,
         None,
-        ast::Visibility::Private(ast::Loc(0, 0)),
+        pt::Visibility::Private(pt::Loc(0, 0)),
         vec![Parameter {
             name: "arg0".to_owned(),
             ty: resolver::Type::Bool,
@@ -46,7 +46,7 @@ fn add_assert(ns: &mut Namespace, contract_no: usize) {
     cfg.add(
         &mut vartab,
         Instr::BranchCond {
-            cond: Expression::FunctionArg(ast::Loc(0, 0), 0),
+            cond: Expression::FunctionArg(pt::Loc(0, 0), 0),
             true_,
             false_,
         },
@@ -75,19 +75,19 @@ fn add_assert(ns: &mut Namespace, contract_no: usize) {
 }
 
 fn add_print(ns: &mut Namespace, contract_no: usize) {
-    let id = ast::Identifier {
-        loc: ast::Loc(0, 0),
+    let id = pt::Identifier {
+        loc: pt::Loc(0, 0),
         name: "print".to_owned(),
     };
 
     let mut assert = FunctionDecl::new(
-        ast::Loc(0, 0),
+        pt::Loc(0, 0),
         "print".to_owned(),
         vec![],
-        ast::FunctionTy::Function,
+        pt::FunctionTy::Function,
         None,
         None,
-        ast::Visibility::Private(ast::Loc(0, 0)),
+        pt::Visibility::Private(pt::Loc(0, 0)),
         vec![Parameter {
             name: "arg0".to_owned(),
             ty: resolver::Type::String,
@@ -103,7 +103,7 @@ fn add_print(ns: &mut Namespace, contract_no: usize) {
     cfg.add(
         &mut vartab,
         Instr::Print {
-            expr: Expression::FunctionArg(ast::Loc(0, 0), 0),
+            expr: Expression::FunctionArg(pt::Loc(0, 0), 0),
         },
     );
     cfg.add(&mut vartab, Instr::Return { value: Vec::new() });
@@ -124,19 +124,19 @@ fn add_print(ns: &mut Namespace, contract_no: usize) {
 }
 
 fn add_require(ns: &mut Namespace, contract_no: usize) {
-    let id = ast::Identifier {
-        loc: ast::Loc(0, 0),
+    let id = pt::Identifier {
+        loc: pt::Loc(0, 0),
         name: "require".to_owned(),
     };
 
     let mut require = FunctionDecl::new(
-        ast::Loc(0, 0),
+        pt::Loc(0, 0),
         "require".to_owned(),
         vec![],
-        ast::FunctionTy::Function,
+        pt::FunctionTy::Function,
         None,
         None,
-        ast::Visibility::Private(ast::Loc(0, 0)),
+        pt::Visibility::Private(pt::Loc(0, 0)),
         vec![
             Parameter {
                 name: "condition".to_owned(),
@@ -160,7 +160,7 @@ fn add_require(ns: &mut Namespace, contract_no: usize) {
     cfg.add(
         &mut vartab,
         Instr::BranchCond {
-            cond: Expression::FunctionArg(ast::Loc(0, 0), 0),
+            cond: Expression::FunctionArg(pt::Loc(0, 0), 0),
             true_,
             false_,
         },
@@ -173,7 +173,7 @@ fn add_require(ns: &mut Namespace, contract_no: usize) {
     cfg.add(
         &mut vartab,
         Instr::AssertFailure {
-            expr: Some(Expression::FunctionArg(ast::Loc(0, 0), 1)),
+            expr: Some(Expression::FunctionArg(pt::Loc(0, 0), 1)),
         },
     );
 
@@ -186,13 +186,13 @@ fn add_require(ns: &mut Namespace, contract_no: usize) {
     ns.contracts[contract_no].functions.push(require);
 
     let mut require = FunctionDecl::new(
-        ast::Loc(0, 0),
+        pt::Loc(0, 0),
         "require".to_owned(),
         vec![],
-        ast::FunctionTy::Function,
+        pt::FunctionTy::Function,
         None,
         None,
-        ast::Visibility::Private(ast::Loc(0, 0)),
+        pt::Visibility::Private(pt::Loc(0, 0)),
         vec![Parameter {
             name: "condition".to_owned(),
             ty: resolver::Type::Bool,
@@ -211,7 +211,7 @@ fn add_require(ns: &mut Namespace, contract_no: usize) {
     cfg.add(
         &mut vartab,
         Instr::BranchCond {
-            cond: Expression::FunctionArg(ast::Loc(0, 0), 0),
+            cond: Expression::FunctionArg(pt::Loc(0, 0), 0),
             true_,
             false_,
         },
@@ -243,19 +243,19 @@ fn add_require(ns: &mut Namespace, contract_no: usize) {
 }
 
 fn add_revert(ns: &mut Namespace, contract_no: usize) {
-    let id = ast::Identifier {
-        loc: ast::Loc(0, 0),
+    let id = pt::Identifier {
+        loc: pt::Loc(0, 0),
         name: "revert".to_owned(),
     };
 
     let mut revert = FunctionDecl::new(
-        ast::Loc(0, 0),
+        pt::Loc(0, 0),
         "revert".to_owned(),
         vec![],
-        ast::FunctionTy::Function,
+        pt::FunctionTy::Function,
         None,
         None,
-        ast::Visibility::Private(ast::Loc(0, 0)),
+        pt::Visibility::Private(pt::Loc(0, 0)),
         vec![Parameter {
             name: "ReasonCode".to_owned(),
             ty: resolver::Type::String,
@@ -272,7 +272,7 @@ fn add_revert(ns: &mut Namespace, contract_no: usize) {
     cfg.add(
         &mut vartab,
         Instr::AssertFailure {
-            expr: Some(Expression::FunctionArg(ast::Loc(0, 0), 0)),
+            expr: Some(Expression::FunctionArg(pt::Loc(0, 0), 0)),
         },
     );
 
@@ -286,13 +286,13 @@ fn add_revert(ns: &mut Namespace, contract_no: usize) {
 
     // now add variant with no argument
     let mut revert = FunctionDecl::new(
-        ast::Loc(0, 0),
+        pt::Loc(0, 0),
         "revert".to_owned(),
         vec![],
-        ast::FunctionTy::Function,
+        pt::FunctionTy::Function,
         None,
         None,
-        ast::Visibility::Private(ast::Loc(0, 0)),
+        pt::Visibility::Private(pt::Loc(0, 0)),
         vec![],
         vec![],
         ns,
@@ -323,19 +323,19 @@ fn add_revert(ns: &mut Namespace, contract_no: usize) {
 }
 
 fn add_selfdestruct(ns: &mut Namespace, contract_no: usize) {
-    let id = ast::Identifier {
-        loc: ast::Loc(0, 0),
+    let id = pt::Identifier {
+        loc: pt::Loc(0, 0),
         name: "selfdestruct".to_owned(),
     };
 
     let mut selfdestruct = FunctionDecl::new(
-        ast::Loc(0, 0),
+        pt::Loc(0, 0),
         "selfdestruct".to_owned(),
         vec![],
-        ast::FunctionTy::Function,
+        pt::FunctionTy::Function,
         None,
         None,
-        ast::Visibility::Private(ast::Loc(0, 0)),
+        pt::Visibility::Private(pt::Loc(0, 0)),
         vec![Parameter {
             name: "recipient".to_owned(),
             ty: resolver::Type::Address(true),
@@ -353,7 +353,7 @@ fn add_selfdestruct(ns: &mut Namespace, contract_no: usize) {
     cfg.add(
         &mut vartab,
         Instr::SelfDestruct {
-            recipient: Expression::FunctionArg(ast::Loc(0, 0), 0),
+            recipient: Expression::FunctionArg(pt::Loc(0, 0), 0),
         },
     );
     cfg.add(&mut vartab, Instr::Unreachable);
@@ -419,19 +419,19 @@ fn add_crypto_hash(ns: &mut Namespace, contract_no: usize) {
             }
         }
 
-        let id = ast::Identifier {
-            loc: ast::Loc(0, 0),
+        let id = pt::Identifier {
+            loc: pt::Loc(0, 0),
             name: hash.function_name.to_owned(),
         };
 
         let mut assert = FunctionDecl::new(
-            ast::Loc(0, 0),
+            pt::Loc(0, 0),
             hash.function_name.to_owned(),
             vec![],
-            ast::FunctionTy::Function,
+            pt::FunctionTy::Function,
             None,
             None,
-            ast::Visibility::Private(ast::Loc(0, 0)),
+            pt::Visibility::Private(pt::Loc(0, 0)),
             vec![Parameter {
                 name: "bs".to_owned(),
                 ty: resolver::Type::DynamicBytes,
@@ -454,13 +454,13 @@ fn add_crypto_hash(ns: &mut Namespace, contract_no: usize) {
             Instr::Hash {
                 res,
                 hash: hash.hash_ty.clone(),
-                expr: Expression::FunctionArg(ast::Loc(0, 0), 0),
+                expr: Expression::FunctionArg(pt::Loc(0, 0), 0),
             },
         );
         cfg.add(
             &mut vartab,
             Instr::Return {
-                value: vec![Expression::Variable(ast::Loc(0, 0), res)],
+                value: vec![Expression::Variable(pt::Loc(0, 0), res)],
             },
         );
 

+ 66 - 66
src/resolver/cfg.rs

@@ -8,7 +8,7 @@ use std::str;
 use hex;
 use output;
 use output::Output;
-use parser::ast;
+use parser::pt;
 use resolver;
 use resolver::expression::{
     cast, constructor_named_args, expression, function_call_expr, named_function_call_expr, new,
@@ -761,7 +761,7 @@ impl ControlFlowGraph {
 }
 
 pub fn generate_cfg(
-    ast_f: &ast::FunctionDefinition,
+    ast_f: &pt::FunctionDefinition,
     resolve_f: &resolver::FunctionDecl,
     contract_no: usize,
     ns: &resolver::Namespace,
@@ -822,8 +822,8 @@ pub fn generate_cfg(
             } else {
                 // this variable can never be assigned but will need a zero value
                 let pos = vartab.temp(
-                    &ast::Identifier {
-                        loc: ast::Loc(0, 0),
+                    &pt::Identifier {
+                        loc: pt::Loc(0, 0),
                         name: format!("arg{}", i),
                     },
                     &resolve_f.returns[i].ty.clone(),
@@ -869,7 +869,7 @@ pub fn generate_cfg(
 }
 
 fn check_return(
-    f: &ast::FunctionDefinition,
+    f: &pt::FunctionDefinition,
     cfg: &mut ControlFlowGraph,
     vartab: &Vartable,
     errors: &mut Vec<output::Output>,
@@ -890,7 +890,7 @@ fn check_return(
             value: vartab
                 .returns
                 .iter()
-                .map(|pos| Expression::Variable(ast::Loc(0, 0), *pos))
+                .map(|pos| Expression::Variable(pt::Loc(0, 0), *pos))
                 .collect(),
         });
 
@@ -906,8 +906,8 @@ fn check_return(
 
 /// Resolve the type of a variable declaration
 pub fn resolve_var_decl_ty(
-    ty: &ast::Expression,
-    storage: &Option<ast::StorageLocation>,
+    ty: &pt::Expression,
+    storage: &Option<pt::StorageLocation>,
     contract_no: Option<usize>,
     ns: &resolver::Namespace,
     errors: &mut Vec<output::Output>,
@@ -926,7 +926,7 @@ pub fn resolve_var_decl_ty(
             return Err(());
         }
 
-        if let ast::StorageLocation::Storage(_) = storage {
+        if let pt::StorageLocation::Storage(_) = storage {
             var_ty = resolver::Type::StorageRef(Box::new(var_ty));
         }
 
@@ -955,7 +955,7 @@ pub fn resolve_var_decl_ty(
 
 /// Resolve a statement, which might be a block of statements or an entire body of a function
 fn statement(
-    stmt: &ast::Statement,
+    stmt: &pt::Statement,
     f: &resolver::FunctionDecl,
     cfg: &mut ControlFlowGraph,
     contract_no: usize,
@@ -965,7 +965,7 @@ fn statement(
     errors: &mut Vec<output::Output>,
 ) -> Result<bool, ()> {
     match stmt {
-        ast::Statement::VariableDefinition(_, decl, init) => {
+        pt::Statement::VariableDefinition(_, decl, init) => {
             let var_ty =
                 resolve_var_decl_ty(&decl.ty, &decl.storage, Some(contract_no), ns, errors)?;
 
@@ -995,7 +995,7 @@ fn statement(
             }
             Ok(true)
         }
-        ast::Statement::Block(_, bs) => {
+        pt::Statement::Block(_, bs) => {
             vartab.new_scope();
             let mut reachable = true;
 
@@ -1014,7 +1014,7 @@ fn statement(
 
             Ok(reachable)
         }
-        ast::Statement::Return(loc, None) => {
+        pt::Statement::Return(loc, None) => {
             let no_returns = f.returns.len();
 
             if vartab.returns.len() != no_returns {
@@ -1034,17 +1034,17 @@ fn statement(
                     value: vartab
                         .returns
                         .iter()
-                        .map(|pos| Expression::Variable(ast::Loc(0, 0), *pos))
+                        .map(|pos| Expression::Variable(pt::Loc(0, 0), *pos))
                         .collect(),
                 },
             );
 
             Ok(false)
         }
-        ast::Statement::Return(loc, Some(returns)) => {
+        pt::Statement::Return(loc, Some(returns)) => {
             return_with_values(returns, loc, f, cfg, contract_no, ns, vartab, errors)
         }
-        ast::Statement::Expression(_, expr) => {
+        pt::Statement::Expression(_, expr) => {
             let (expr, _) =
                 expression(expr, cfg, Some(contract_no), ns, &mut Some(vartab), errors)?;
 
@@ -1065,7 +1065,7 @@ fn statement(
                 }
             }
         }
-        ast::Statement::If(_, cond, then_stmt, None) => if_then(
+        pt::Statement::If(_, cond, then_stmt, None) => if_then(
             cond,
             then_stmt,
             f,
@@ -1076,7 +1076,7 @@ fn statement(
             loops,
             errors,
         ),
-        ast::Statement::If(_, cond, then_stmt, Some(else_stmt)) => if_then_else(
+        pt::Statement::If(_, cond, then_stmt, Some(else_stmt)) => if_then_else(
             cond,
             then_stmt,
             else_stmt,
@@ -1088,7 +1088,7 @@ fn statement(
             loops,
             errors,
         ),
-        ast::Statement::Break(_) => match loops.do_break() {
+        pt::Statement::Break(_) => match loops.do_break() {
             Some(bb) => {
                 cfg.add(vartab, Instr::Branch { bb });
                 Ok(false)
@@ -1101,7 +1101,7 @@ fn statement(
                 Err(())
             }
         },
-        ast::Statement::Continue(_) => match loops.do_continue() {
+        pt::Statement::Continue(_) => match loops.do_continue() {
             Some(bb) => {
                 cfg.add(vartab, Instr::Branch { bb });
                 Ok(false)
@@ -1114,7 +1114,7 @@ fn statement(
                 Err(())
             }
         },
-        ast::Statement::DoWhile(_, body_stmt, cond_expr) => {
+        pt::Statement::DoWhile(_, body_stmt, cond_expr) => {
             let body = cfg.new_basic_block("body".to_string());
             let cond = cfg.new_basic_block("conf".to_string());
             let end = cfg.new_basic_block("enddowhile".to_string());
@@ -1180,7 +1180,7 @@ fn statement(
 
             Ok(body_reachable || control.no_breaks > 0)
         }
-        ast::Statement::While(_, cond_expr, body_stmt) => {
+        pt::Statement::While(_, cond_expr, body_stmt) => {
             let cond = cfg.new_basic_block("cond".to_string());
             let body = cfg.new_basic_block("body".to_string());
             let end = cfg.new_basic_block("endwhile".to_string());
@@ -1238,7 +1238,7 @@ fn statement(
 
             Ok(true)
         }
-        ast::Statement::For(_, init_stmt, None, next_stmt, body_stmt) => {
+        pt::Statement::For(_, init_stmt, None, next_stmt, body_stmt) => {
             let body = cfg.new_basic_block("body".to_string());
             let next = cfg.new_basic_block("next".to_string());
             let end = cfg.new_basic_block("endfor".to_string());
@@ -1303,7 +1303,7 @@ fn statement(
 
             Ok(control.no_breaks > 0)
         }
-        ast::Statement::For(_, init_stmt, Some(cond_expr), next_stmt, body_stmt) => {
+        pt::Statement::For(_, init_stmt, Some(cond_expr), next_stmt, body_stmt) => {
             let body = cfg.new_basic_block("body".to_string());
             let cond = cfg.new_basic_block("cond".to_string());
             let next = cfg.new_basic_block("next".to_string());
@@ -1401,10 +1401,10 @@ fn statement(
 
             Ok(true)
         }
-        ast::Statement::Try(_, _, _, _, _) => {
+        pt::Statement::Try(_, _, _, _, _) => {
             try_catch(stmt, f, cfg, contract_no, ns, vartab, loops, errors)
         }
-        ast::Statement::Args(_, _) => {
+        pt::Statement::Args(_, _) => {
             errors.push(Output::error(
                 stmt.loc(),
                 "expected code block, not list of named arguments".to_string(),
@@ -1417,8 +1417,8 @@ fn statement(
 
 /// Parse return statement with values
 fn return_with_values(
-    returns: &ast::Expression,
-    loc: &ast::Loc,
+    returns: &pt::Expression,
+    loc: &pt::Loc,
     f: &resolver::FunctionDecl,
     cfg: &mut ControlFlowGraph,
     contract_no: usize,
@@ -1476,8 +1476,8 @@ fn return_with_values(
 
 /// Parse if-then-no-else
 fn if_then(
-    cond: &ast::Expression,
-    then_stmt: &ast::Statement,
+    cond: &pt::Expression,
+    then_stmt: &pt::Statement,
     f: &resolver::FunctionDecl,
     cfg: &mut ControlFlowGraph,
     contract_no: usize,
@@ -1529,9 +1529,9 @@ fn if_then(
 
 /// Parse if-then-else
 fn if_then_else(
-    cond: &ast::Expression,
-    then_stmt: &ast::Statement,
-    else_stmt: &ast::Statement,
+    cond: &pt::Expression,
+    then_stmt: &pt::Statement,
+    else_stmt: &pt::Statement,
     f: &resolver::FunctionDecl,
     cfg: &mut ControlFlowGraph,
     contract_no: usize,
@@ -1598,7 +1598,7 @@ fn if_then_else(
 
 /// Resolve try catch statement
 fn try_catch(
-    try: &ast::Statement,
+    try: &pt::Statement,
     f: &resolver::FunctionDecl,
     cfg: &mut ControlFlowGraph,
     contract_no: usize,
@@ -1607,11 +1607,11 @@ fn try_catch(
     loops: &mut LoopScopes,
     errors: &mut Vec<output::Output>,
 ) -> Result<bool, ()> {
-    if let ast::Statement::Try(_, expr, returns_and_ok, error_stmt, catch_stmt) = &try {
+    if let pt::Statement::Try(_, expr, returns_and_ok, error_stmt, catch_stmt) = &try {
         let mut expr = expr;
         let mut ok = None;
 
-        while let ast::Expression::FunctionCallBlock(_, e, block) = expr {
+        while let pt::Expression::FunctionCallBlock(_, e, block) = expr {
             if ok.is_some() {
                 errors.push(Output::error(
                     block.loc(),
@@ -1626,7 +1626,7 @@ fn try_catch(
         }
 
         let fcall = match expr {
-            ast::Expression::FunctionCall(loc, ty, args) => function_call_expr(
+            pt::Expression::FunctionCall(loc, ty, args) => function_call_expr(
                 loc,
                 ty,
                 args,
@@ -1636,7 +1636,7 @@ fn try_catch(
                 &mut Some(vartab),
                 errors,
             )?,
-            ast::Expression::NamedFunctionCall(loc, ty, args) => named_function_call_expr(
+            pt::Expression::NamedFunctionCall(loc, ty, args) => named_function_call_expr(
                 loc,
                 ty,
                 args,
@@ -1646,10 +1646,10 @@ fn try_catch(
                 &mut Some(vartab),
                 errors,
             )?,
-            ast::Expression::New(loc, call) => {
+            pt::Expression::New(loc, call) => {
                 let mut call = call.as_ref();
 
-                while let ast::Expression::FunctionCallBlock(_, expr, block) = call {
+                while let pt::Expression::FunctionCallBlock(_, expr, block) = call {
                     if ok.is_some() {
                         errors.push(Output::error(
                             block.loc(),
@@ -1664,7 +1664,7 @@ fn try_catch(
                 }
 
                 match call {
-                    ast::Expression::FunctionCall(_, ty, args) => new(
+                    pt::Expression::FunctionCall(_, ty, args) => new(
                         loc,
                         ty,
                         args,
@@ -1674,7 +1674,7 @@ fn try_catch(
                         &mut Some(vartab),
                         errors,
                     )?,
-                    ast::Expression::NamedFunctionCall(_, ty, args) => constructor_named_args(
+                    pt::Expression::NamedFunctionCall(_, ty, args) => constructor_named_args(
                         loc,
                         ty,
                         args,
@@ -1719,7 +1719,7 @@ fn try_catch(
                 let pos = expr.loc().1;
 
                 errors.push(Output::error(
-                    ast::Loc(pos, pos),
+                    pt::Loc(pos, pos),
                     "code block missing for no catch".to_string(),
                 ));
                 return Err(());
@@ -1727,8 +1727,8 @@ fn try_catch(
         };
 
         let success = vartab.temp(
-            &ast::Identifier {
-                loc: ast::Loc(0, 0),
+            &pt::Identifier {
+                loc: pt::Loc(0, 0),
                 name: "success".to_owned(),
             },
             &resolver::Type::Bool,
@@ -1766,7 +1766,7 @@ fn try_catch(
                 cfg.add(
                     vartab,
                     Instr::BranchCond {
-                        cond: Expression::Variable(ast::Loc(0, 0), success),
+                        cond: Expression::Variable(pt::Loc(0, 0), success),
                         true_: success_block,
                         false_: catch_block,
                     },
@@ -1790,8 +1790,8 @@ fn try_catch(
                     let mut returns = Vec::new();
                     let mut res = Vec::new();
                     for ret in &ftype.returns {
-                        let id = ast::Identifier {
-                            loc: ast::Loc(0, 0),
+                        let id = pt::Identifier {
+                            loc: pt::Loc(0, 0),
                             name: "".to_owned(),
                         };
                         let temp_pos = vartab.temp(&id, &ret.ty);
@@ -1805,7 +1805,7 @@ fn try_catch(
                             selector: None,
                             exception: None,
                             tys: ftype.returns.clone(),
-                            data: Expression::ReturnData(ast::Loc(0, 0)),
+                            data: Expression::ReturnData(pt::Loc(0, 0)),
                         },
                     );
                     returns
@@ -1842,7 +1842,7 @@ fn try_catch(
                 cfg.add(
                     vartab,
                     Instr::BranchCond {
-                        cond: Expression::Variable(ast::Loc(0, 0), success),
+                        cond: Expression::Variable(pt::Loc(0, 0), success),
                         true_: success_block,
                         false_: catch_block,
                     },
@@ -1882,7 +1882,7 @@ fn try_catch(
             let (arg, arg_ty) = args.remove(0);
 
             match &param.1 {
-                Some(ast::Parameter { ty, storage, name }) => {
+                Some(pt::Parameter { ty, storage, name }) => {
                     let ret_ty = resolve_var_decl_ty(&ty, &storage, Some(contract_no), ns, errors)?;
 
                     if arg_ty != ret_ty {
@@ -1973,7 +1973,7 @@ fn try_catch(
                         name: "error".to_string(),
                         ty: resolver::Type::String,
                     }],
-                    data: Expression::ReturnData(ast::Loc(0, 0)),
+                    data: Expression::ReturnData(pt::Loc(0, 0)),
                 },
             );
 
@@ -1986,7 +1986,7 @@ fn try_catch(
                         vartab,
                         Instr::Set {
                             res: pos,
-                            expr: Expression::Variable(ast::Loc(0, 0), error_var),
+                            expr: Expression::Variable(pt::Loc(0, 0), error_var),
                         },
                     );
                 }
@@ -2043,7 +2043,7 @@ fn try_catch(
                     vartab,
                     Instr::Set {
                         res: pos,
-                        expr: Expression::ReturnData(ast::Loc(0, 0)),
+                        expr: Expression::ReturnData(pt::Loc(0, 0)),
                     },
                 );
             }
@@ -2095,7 +2095,7 @@ pub enum Storage {
 
 #[derive(Clone)]
 pub struct Variable {
-    pub id: ast::Identifier,
+    pub id: pt::Identifier,
     pub ty: resolver::Type,
     pub pos: usize,
     pub storage: Storage,
@@ -2132,7 +2132,7 @@ impl Vartable {
 
     pub fn add(
         &mut self,
-        id: &ast::Identifier,
+        id: &pt::Identifier,
         ty: resolver::Type,
         errors: &mut Vec<output::Output>,
     ) -> Option<usize> {
@@ -2176,7 +2176,7 @@ impl Vartable {
 
     pub fn find(
         &mut self,
-        id: &ast::Identifier,
+        id: &pt::Identifier,
         contract_no: usize,
         ns: &resolver::Namespace,
         errors: &mut Vec<output::Output>,
@@ -2214,9 +2214,9 @@ impl Vartable {
         let pos = self.vars.len();
 
         self.vars.push(Variable {
-            id: ast::Identifier {
+            id: pt::Identifier {
                 name: format!("temp.{}", pos),
-                loc: ast::Loc(0, 0),
+                loc: pt::Loc(0, 0),
             },
             ty: ty.clone(),
             pos,
@@ -2226,11 +2226,11 @@ impl Vartable {
         pos
     }
 
-    pub fn temp(&mut self, id: &ast::Identifier, ty: &resolver::Type) -> usize {
+    pub fn temp(&mut self, id: &pt::Identifier, ty: &resolver::Type) -> usize {
         let pos = self.vars.len();
 
         self.vars.push(Variable {
-            id: ast::Identifier {
+            id: pt::Identifier {
                 name: format!("{}.temp.{}", id.name, pos),
                 loc: id.loc,
             },
@@ -2327,22 +2327,22 @@ impl resolver::Type {
     fn default(&self, ns: &resolver::Namespace) -> Expression {
         match self {
             resolver::Type::Uint(b) | resolver::Type::Int(b) => {
-                Expression::NumberLiteral(ast::Loc(0, 0), *b, BigInt::from(0))
+                Expression::NumberLiteral(pt::Loc(0, 0), *b, BigInt::from(0))
             }
-            resolver::Type::Bool => Expression::BoolLiteral(ast::Loc(0, 0), false),
+            resolver::Type::Bool => Expression::BoolLiteral(pt::Loc(0, 0), false),
             resolver::Type::Address(_) => Expression::NumberLiteral(
-                ast::Loc(0, 0),
+                pt::Loc(0, 0),
                 ns.address_length as u16 * 8,
                 BigInt::from(0),
             ),
             resolver::Type::Bytes(n) => {
                 let mut l = Vec::new();
                 l.resize(*n as usize, 0);
-                Expression::BytesLiteral(ast::Loc(0, 0), l)
+                Expression::BytesLiteral(pt::Loc(0, 0), l)
             }
             resolver::Type::Enum(e) => ns.enums[*e].ty.default(ns),
             resolver::Type::Struct(_) => {
-                Expression::StructLiteral(ast::Loc(0, 0), self.clone(), Vec::new())
+                Expression::StructLiteral(pt::Loc(0, 0), self.clone(), Vec::new())
             }
             resolver::Type::Ref(_) => unreachable!(),
             resolver::Type::StorageRef(_) => unreachable!(),

+ 1 - 1
src/resolver/eval.rs

@@ -7,7 +7,7 @@ use num_traits::Zero;
 use super::expression::Expression;
 use output;
 use output::Output;
-use parser::ast::Loc;
+use parser::pt::Loc;
 
 /// Resolve an expression where a compile-time constant is expected
 pub fn eval_number_expression(

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 172 - 174
src/resolver/expression.rs


+ 30 - 30
src/resolver/functions.rs

@@ -1,10 +1,10 @@
 use super::{FunctionDecl, Namespace, Parameter, Symbol, Type};
 use output::Output;
-use parser::ast;
+use parser::pt;
 use Target;
 
 pub fn function_decl(
-    f: &ast::FunctionDefinition,
+    f: &pt::FunctionDefinition,
     i: usize,
     contract_no: usize,
     ns: &mut Namespace,
@@ -15,7 +15,7 @@ pub fn function_decl(
     // The parser allows constructors to have return values. This is so that we can give a
     // nicer error message than "returns unexpected"
     match f.ty {
-        ast::FunctionTy::Function => {
+        pt::FunctionTy::Function => {
             // Function name cannot be the same as the contract name
             if let Some(n) = &f.name {
                 if n.name == ns.contracts[contract_no].name {
@@ -33,7 +33,7 @@ pub fn function_decl(
                 return false;
             }
         }
-        ast::FunctionTy::Constructor => {
+        pt::FunctionTy::Constructor => {
             if !f.returns.is_empty() {
                 errors.push(Output::warning(
                     f.loc,
@@ -49,7 +49,7 @@ pub fn function_decl(
                 return false;
             }
         }
-        ast::FunctionTy::Fallback | ast::FunctionTy::Receive => {
+        pt::FunctionTy::Fallback | pt::FunctionTy::Receive => {
             if !f.returns.is_empty() {
                 errors.push(Output::warning(
                     f.loc,
@@ -74,12 +74,12 @@ pub fn function_decl(
         }
     }
 
-    let mut mutability: Option<ast::StateMutability> = None;
-    let mut visibility: Option<ast::Visibility> = None;
+    let mut mutability: Option<pt::StateMutability> = None;
+    let mut visibility: Option<pt::Visibility> = None;
 
     for a in &f.attributes {
         match &a {
-            ast::FunctionAttribute::StateMutability(m) => {
+            pt::FunctionAttribute::StateMutability(m) => {
                 if let Some(e) = &mutability {
                     errors.push(Output::error_with_note(
                         m.loc(),
@@ -93,7 +93,7 @@ pub fn function_decl(
 
                 mutability = Some(m.clone());
             }
-            ast::FunctionAttribute::Visibility(v) => {
+            pt::FunctionAttribute::Visibility(v) => {
                 if let Some(e) = &visibility {
                     errors.push(Output::error_with_note(
                         v.loc(),
@@ -116,15 +116,15 @@ pub fn function_decl(
             errors.push(Output::error(f.loc, "no visibility specified".to_string()));
             success = false;
             // continue processing while assuming it's a public
-            ast::Visibility::Public(ast::Loc(0, 0))
+            pt::Visibility::Public(pt::Loc(0, 0))
         }
     };
 
     // Reference types can't be passed through the ABI encoder/decoder, so
     // storage parameters/returns are only allowed in internal/private functions
     let storage_allowed = match visibility {
-        ast::Visibility::Internal(_) | ast::Visibility::Private(_) => {
-            if let Some(ast::StateMutability::Payable(loc)) = mutability {
+        pt::Visibility::Internal(_) | pt::Visibility::Private(_) => {
+            if let Some(pt::StateMutability::Payable(loc)) = mutability {
                 errors.push(Output::error(
                     loc,
                     "internal or private function cannot be payable".to_string(),
@@ -133,7 +133,7 @@ pub fn function_decl(
             }
             true
         }
-        ast::Visibility::Public(_) | ast::Visibility::External(_) => false,
+        pt::Visibility::Public(_) | pt::Visibility::External(_) => false,
     };
 
     let (params, params_success) = resolve_params(f, storage_allowed, contract_no, ns, errors);
@@ -162,7 +162,7 @@ pub fn function_decl(
         ns,
     );
 
-    if f.ty == ast::FunctionTy::Constructor {
+    if f.ty == pt::FunctionTy::Constructor {
         // In the eth solidity, only one constructor is allowed
         if ns.target == Target::Ewasm {
             if let Some(prev) = ns.contracts[contract_no]
@@ -198,7 +198,7 @@ pub fn function_decl(
 
         // FIXME: Internal visibility is allowed on abstract contracts, but we don't support those yet
         match fdecl.visibility {
-            ast::Visibility::Public(_) => (),
+            pt::Visibility::Public(_) => (),
             _ => {
                 errors.push(Output::error(
                     f.loc,
@@ -209,14 +209,14 @@ pub fn function_decl(
         }
 
         match fdecl.mutability {
-            Some(ast::StateMutability::Pure(loc)) => {
+            Some(pt::StateMutability::Pure(loc)) => {
                 errors.push(Output::error(
                     loc,
                     "constructor cannot be declared pure".to_string(),
                 ));
                 return false;
             }
-            Some(ast::StateMutability::View(loc)) => {
+            Some(pt::StateMutability::View(loc)) => {
                 errors.push(Output::error(
                     loc,
                     "constructor cannot be declared view".to_string(),
@@ -246,7 +246,7 @@ pub fn function_decl(
         ns.contracts[contract_no].functions.push(fdecl);
 
         true
-    } else if f.ty == ast::FunctionTy::Receive || f.ty == ast::FunctionTy::Fallback {
+    } else if f.ty == pt::FunctionTy::Receive || f.ty == pt::FunctionTy::Fallback {
         if let Some(prev) = ns.contracts[contract_no]
             .functions
             .iter()
@@ -261,7 +261,7 @@ pub fn function_decl(
             return false;
         }
 
-        if let ast::Visibility::External(_) = fdecl.visibility {
+        if let pt::Visibility::External(_) = fdecl.visibility {
             // ok
         } else {
             errors.push(Output::error(
@@ -271,15 +271,15 @@ pub fn function_decl(
             return false;
         }
 
-        if let Some(ast::StateMutability::Payable(_)) = fdecl.mutability {
-            if f.ty == ast::FunctionTy::Fallback {
+        if let Some(pt::StateMutability::Payable(_)) = fdecl.mutability {
+            if f.ty == pt::FunctionTy::Fallback {
                 errors.push(Output::error(
                     f.loc,
                     format!("{} function must not be declare payable, use ‘receive() external payable’ instead", f.ty),
                 ));
                 return false;
             }
-        } else if f.ty == ast::FunctionTy::Receive {
+        } else if f.ty == pt::FunctionTy::Receive {
             errors.push(Output::error(
                 f.loc,
                 format!("{} function must be declared payable", f.ty),
@@ -334,7 +334,7 @@ pub fn function_decl(
 
 /// Resolve the parameters
 fn resolve_params(
-    f: &ast::FunctionDefinition,
+    f: &pt::FunctionDefinition,
     storage_allowed: bool,
     contract_no: usize,
     ns: &mut Namespace,
@@ -366,7 +366,7 @@ fn resolve_params(
                     }
 
                     ty
-                } else if let Some(ast::StorageLocation::Storage(loc)) = p.storage {
+                } else if let Some(pt::StorageLocation::Storage(loc)) = p.storage {
                     if storage_allowed {
                         Type::StorageRef(Box::new(ty))
                     } else {
@@ -406,7 +406,7 @@ fn resolve_params(
 
 /// Resolve the return values
 fn resolve_returns(
-    f: &ast::FunctionDefinition,
+    f: &pt::FunctionDefinition,
     storage_allowed: bool,
     contract_no: usize,
     ns: &mut Namespace,
@@ -440,7 +440,7 @@ fn resolve_returns(
                     ty
                 } else {
                     match r.storage {
-                        Some(ast::StorageLocation::Calldata(loc)) => {
+                        Some(pt::StorageLocation::Calldata(loc)) => {
                             errors.push(Output::error(
                                 loc,
                                 "data location ‘calldata’ can not be used for return types"
@@ -449,7 +449,7 @@ fn resolve_returns(
                             success = false;
                             ty
                         }
-                        Some(ast::StorageLocation::Storage(loc)) => {
+                        Some(pt::StorageLocation::Storage(loc)) => {
                             if storage_allowed {
                                 Type::StorageRef(Box::new(ty))
                             } else {
@@ -499,13 +499,13 @@ fn signatures() {
     let ns = Namespace::new(Target::Ewasm, 20);
 
     let fdecl = FunctionDecl::new(
-        ast::Loc(0, 0),
+        pt::Loc(0, 0),
         "foo".to_owned(),
         vec![],
-        ast::FunctionTy::Function,
+        pt::FunctionTy::Function,
         Some(0),
         None,
-        ast::Visibility::Public(ast::Loc(0, 0)),
+        pt::Visibility::Public(pt::Loc(0, 0)),
         vec![
             Parameter {
                 name: "".to_string(),

+ 71 - 78
src/resolver/mod.rs

@@ -4,7 +4,7 @@ use num_bigint::BigInt;
 use num_traits::Signed;
 use num_traits::{One, Zero};
 use output::{any_errors, Note, Output};
-use parser::ast;
+use parser::pt;
 use std::cell::RefCell;
 use std::collections::HashMap;
 use std::ops::Mul;
@@ -26,7 +26,7 @@ use resolver::cfg::{ControlFlowGraph, Instr, Vartable};
 use resolver::eval::eval_number_expression;
 use resolver::expression::{expression, Expression};
 
-pub type ArrayDimension = Option<(ast::Loc, BigInt)>;
+pub type ArrayDimension = Option<(pt::Loc, BigInt)>;
 
 #[derive(PartialEq, Clone, Debug)]
 pub enum Type {
@@ -374,13 +374,13 @@ impl Type {
 
 pub struct StructField {
     pub name: String,
-    pub loc: ast::Loc,
+    pub loc: pt::Loc,
     pub ty: Type,
 }
 
 pub struct StructDecl {
     pub name: String,
-    pub loc: ast::Loc,
+    pub loc: pt::Loc,
     pub contract: Option<String>,
     pub fields: Vec<StructField>,
 }
@@ -400,7 +400,7 @@ pub struct EnumDecl {
     pub name: String,
     pub contract: Option<String>,
     pub ty: Type,
-    pub values: HashMap<String, (ast::Loc, usize)>,
+    pub values: HashMap<String, (pt::Loc, usize)>,
 }
 
 impl EnumDecl {
@@ -422,13 +422,13 @@ pub struct Parameter {
 
 pub struct FunctionDecl {
     pub doc: Vec<String>,
-    pub loc: ast::Loc,
+    pub loc: pt::Loc,
     pub name: String,
-    pub ty: ast::FunctionTy,
+    pub ty: pt::FunctionTy,
     pub signature: String,
     pub ast_index: Option<usize>,
-    pub mutability: Option<ast::StateMutability>,
-    pub visibility: ast::Visibility,
+    pub mutability: Option<pt::StateMutability>,
+    pub visibility: pt::Visibility,
     pub params: Vec<Parameter>,
     pub returns: Vec<Parameter>,
     pub noreturn: bool,
@@ -438,13 +438,13 @@ pub struct FunctionDecl {
 
 impl FunctionDecl {
     fn new(
-        loc: ast::Loc,
+        loc: pt::Loc,
         name: String,
         doc: Vec<String>,
-        ty: ast::FunctionTy,
+        ty: pt::FunctionTy,
         ast_index: Option<usize>,
-        mutability: Option<ast::StateMutability>,
-        visibility: ast::Visibility,
+        mutability: Option<pt::StateMutability>,
+        visibility: pt::Visibility,
         params: Vec<Parameter>,
         returns: Vec<Parameter>,
         ns: &Namespace,
@@ -485,12 +485,12 @@ impl FunctionDecl {
 
     /// Is this a constructor
     pub fn is_constructor(&self) -> bool {
-        self.ty == ast::FunctionTy::Constructor
+        self.ty == pt::FunctionTy::Constructor
     }
 
     /// Does this function have the payable state
     pub fn is_payable(&self) -> bool {
-        if let Some(ast::StateMutability::Payable(_)) = self.mutability {
+        if let Some(pt::StateMutability::Payable(_)) = self.mutability {
             true
         } else {
             false
@@ -500,7 +500,7 @@ impl FunctionDecl {
     /// Is this function accessable externally
     pub fn is_public(&self) -> bool {
         match self.visibility {
-            ast::Visibility::Public(_) | ast::Visibility::External(_) => true,
+            pt::Visibility::Public(_) | pt::Visibility::External(_) => true,
             _ => false,
         }
     }
@@ -558,20 +558,20 @@ impl FunctionDecl {
     }
 }
 
-impl From<&ast::Type> for Type {
-    fn from(p: &ast::Type) -> Type {
+impl From<&pt::Type> for Type {
+    fn from(p: &pt::Type) -> Type {
         match p {
-            ast::Type::Bool => Type::Bool,
-            ast::Type::Address => Type::Address(false),
-            ast::Type::AddressPayable => Type::Address(true),
-            ast::Type::Payable => Type::Address(true),
-            ast::Type::Int(n) => Type::Int(*n),
-            ast::Type::Uint(n) => Type::Uint(*n),
-            ast::Type::Bytes(n) => Type::Bytes(*n),
-            ast::Type::String => Type::String,
-            ast::Type::DynamicBytes => Type::DynamicBytes,
+            pt::Type::Bool => Type::Bool,
+            pt::Type::Address => Type::Address(false),
+            pt::Type::AddressPayable => Type::Address(true),
+            pt::Type::Payable => Type::Address(true),
+            pt::Type::Int(n) => Type::Int(*n),
+            pt::Type::Uint(n) => Type::Uint(*n),
+            pt::Type::Bytes(n) => Type::Bytes(*n),
+            pt::Type::String => Type::String,
+            pt::Type::DynamicBytes => Type::DynamicBytes,
             // needs special casing
-            ast::Type::Mapping(_, _, _) => unimplemented!(),
+            pt::Type::Mapping(_, _, _) => unimplemented!(),
         }
     }
 }
@@ -585,7 +585,7 @@ pub struct ContractVariable {
     pub doc: Vec<String>,
     pub name: String,
     pub ty: Type,
-    pub visibility: ast::Visibility,
+    pub visibility: pt::Visibility,
     pub var: ContractVariableType,
 }
 
@@ -600,11 +600,11 @@ impl ContractVariable {
 }
 
 pub enum Symbol {
-    Enum(ast::Loc, usize),
-    Function(Vec<(ast::Loc, usize)>),
-    Variable(ast::Loc, usize),
-    Struct(ast::Loc, usize),
-    Contract(ast::Loc, usize),
+    Enum(pt::Loc, usize),
+    Function(Vec<(pt::Loc, usize)>),
+    Variable(pt::Loc, usize),
+    Struct(pt::Loc, usize),
+    Contract(pt::Loc, usize),
 }
 
 /// When resolving a Solidity file, this holds all the resolved items
@@ -635,7 +635,7 @@ impl Namespace {
     pub fn add_symbol(
         &mut self,
         contract_no: Option<usize>,
-        id: &ast::Identifier,
+        id: &pt::Identifier,
         symbol: Symbol,
         errors: &mut Vec<Output>,
     ) -> bool {
@@ -752,7 +752,7 @@ impl Namespace {
         true
     }
 
-    pub fn resolve_enum(&self, contract_no: Option<usize>, id: &ast::Identifier) -> Option<usize> {
+    pub fn resolve_enum(&self, contract_no: Option<usize>, id: &pt::Identifier) -> Option<usize> {
         if let Some(Symbol::Enum(_, n)) = self.symbols.get(&(contract_no, id.name.to_owned())) {
             return Some(*n);
         }
@@ -766,7 +766,7 @@ impl Namespace {
         None
     }
 
-    pub fn resolve_contract(&self, id: &ast::Identifier) -> Option<usize> {
+    pub fn resolve_contract(&self, id: &pt::Identifier) -> Option<usize> {
         if let Some(Symbol::Contract(_, n)) = self.symbols.get(&(None, id.name.to_owned())) {
             return Some(*n);
         }
@@ -777,9 +777,9 @@ impl Namespace {
     pub fn resolve_func(
         &self,
         contract_no: usize,
-        id: &ast::Identifier,
+        id: &pt::Identifier,
         errors: &mut Vec<Output>,
-    ) -> Result<&Vec<(ast::Loc, usize)>, ()> {
+    ) -> Result<&Vec<(pt::Loc, usize)>, ()> {
         match self.symbols.get(&(Some(contract_no), id.name.to_owned())) {
             Some(Symbol::Function(v)) => Ok(v),
             _ => {
@@ -796,7 +796,7 @@ impl Namespace {
     pub fn resolve_var(
         &self,
         contract_no: usize,
-        id: &ast::Identifier,
+        id: &pt::Identifier,
         errors: &mut Vec<Output>,
     ) -> Result<usize, ()> {
         let mut s = self.symbols.get(&(Some(contract_no), id.name.to_owned()));
@@ -848,7 +848,7 @@ impl Namespace {
     pub fn check_shadowing(
         &self,
         contract_no: usize,
-        id: &ast::Identifier,
+        id: &pt::Identifier,
         errors: &mut Vec<Output>,
     ) {
         let mut s = self.symbols.get(&(Some(contract_no), id.name.to_owned()));
@@ -915,11 +915,11 @@ impl Namespace {
         &self,
         contract_no: Option<usize>,
         casting: bool,
-        id: &ast::Expression,
+        id: &pt::Expression,
         errors: &mut Vec<Output>,
     ) -> Result<Type, ()> {
         fn resolve_dimensions(
-            ast_dimensions: &[Option<(ast::Loc, BigInt)>],
+            ast_dimensions: &[Option<(pt::Loc, BigInt)>],
             errors: &mut Vec<Output>,
         ) -> Result<Vec<Option<BigInt>>, ()> {
             let mut dimensions = Vec::new();
@@ -950,11 +950,11 @@ impl Namespace {
 
         let (contract_name, id, dimensions) = self.expr_to_type(&id, errors)?;
 
-        if let ast::Expression::Type(_, ty) = &id {
+        if let pt::Expression::Type(_, ty) = &id {
             assert_eq!(contract_name, None);
 
             let ty = match ty {
-                ast::Type::Mapping(_, k, v) => {
+                pt::Type::Mapping(_, k, v) => {
                     let key = self.resolve_type(contract_no, false, k, errors)?;
                     let value = self.resolve_type(contract_no, false, v, errors)?;
 
@@ -983,7 +983,7 @@ impl Namespace {
                         _ => Type::Mapping(Box::new(key), Box::new(value)),
                     }
                 }
-                ast::Type::Payable => {
+                pt::Type::Payable => {
                     if !casting {
                         errors.push(Output::decl_error(
                             id.loc(),
@@ -1009,7 +1009,7 @@ impl Namespace {
         }
 
         let id = match id {
-            ast::Expression::Variable(id) => id,
+            pt::Expression::Variable(id) => id,
             _ => unreachable!(),
         };
 
@@ -1108,39 +1108,32 @@ impl Namespace {
     // no unexpected expressions types.
     pub fn expr_to_type(
         &self,
-        expr: &ast::Expression,
+        expr: &pt::Expression,
         errors: &mut Vec<Output>,
-    ) -> Result<
-        (
-            Option<ast::Identifier>,
-            ast::Expression,
-            Vec<ArrayDimension>,
-        ),
-        (),
-    > {
+    ) -> Result<(Option<pt::Identifier>, pt::Expression, Vec<ArrayDimension>), ()> {
         let mut expr = expr;
         let mut dimensions = Vec::new();
 
         loop {
             expr = match expr {
-                ast::Expression::ArraySubscript(_, r, None) => {
+                pt::Expression::ArraySubscript(_, r, None) => {
                     dimensions.push(None);
 
                     &*r
                 }
-                ast::Expression::ArraySubscript(_, r, Some(index)) => {
+                pt::Expression::ArraySubscript(_, r, Some(index)) => {
                     dimensions.push(self.resolve_array_dimension(index, errors)?);
 
                     &*r
                 }
-                ast::Expression::Variable(_) | ast::Expression::Type(_, _) => {
+                pt::Expression::Variable(_) | pt::Expression::Type(_, _) => {
                     return Ok((None, expr.clone(), dimensions))
                 }
-                ast::Expression::MemberAccess(_, namespace, id) => {
-                    if let ast::Expression::Variable(namespace) = namespace.as_ref() {
+                pt::Expression::MemberAccess(_, namespace, id) => {
+                    if let pt::Expression::Variable(namespace) = namespace.as_ref() {
                         return Ok((
                             Some(namespace.clone()),
-                            ast::Expression::Variable(id.clone()),
+                            pt::Expression::Variable(id.clone()),
                             dimensions,
                         ));
                     } else {
@@ -1165,7 +1158,7 @@ impl Namespace {
     /// Resolve an expression which defines the array length, e.g. 2**8 in "bool[2**8]"
     pub fn resolve_array_dimension(
         &self,
-        expr: &ast::Expression,
+        expr: &pt::Expression,
         errors: &mut Vec<Output>,
     ) -> Result<ArrayDimension, ()> {
         let mut cfg = ControlFlowGraph::new();
@@ -1217,7 +1210,7 @@ impl Contract {
     /// Return the index of the fallback function, if any
     pub fn fallback_function(&self) -> Option<usize> {
         for (i, f) in self.functions.iter().enumerate() {
-            if f.ty == ast::FunctionTy::Fallback {
+            if f.ty == pt::FunctionTy::Fallback {
                 return Some(i);
             }
         }
@@ -1227,7 +1220,7 @@ impl Contract {
     /// Return the index of the receive function, if any
     pub fn receive_function(&self) -> Option<usize> {
         for (i, f) in self.functions.iter().enumerate() {
-            if f.ty == ast::FunctionTy::Receive {
+            if f.ty == pt::FunctionTy::Receive {
                 return Some(i);
             }
         }
@@ -1263,7 +1256,7 @@ impl Contract {
     }
 }
 
-pub fn resolver(s: ast::SourceUnit, target: Target) -> (Option<Namespace>, Vec<Output>) {
+pub fn resolver(s: pt::SourceUnit, target: Target) -> (Option<Namespace>, Vec<Output>) {
     // first resolve all the types we can find
     let (mut ns, mut errors) = types::resolve(&s, target);
 
@@ -1276,7 +1269,7 @@ pub fn resolver(s: ast::SourceUnit, target: Target) -> (Option<Namespace>, Vec<O
     // contracts before they are declared
     let mut contract_no = 0;
     for part in &s.0 {
-        if let ast::SourceUnitPart::ContractDefinition(def) = part {
+        if let pt::SourceUnitPart::ContractDefinition(def) = part {
             resolve_contract_declarations(def, contract_no, target, &mut errors, &mut ns);
 
             contract_no += 1;
@@ -1286,7 +1279,7 @@ pub fn resolver(s: ast::SourceUnit, target: Target) -> (Option<Namespace>, Vec<O
     // Now we can resolve the bodies
     let mut contract_no = 0;
     for part in &s.0 {
-        if let ast::SourceUnitPart::ContractDefinition(def) = part {
+        if let pt::SourceUnitPart::ContractDefinition(def) = part {
             resolve_contract_bodies(def, contract_no, &mut errors, &mut ns);
 
             contract_no += 1;
@@ -1302,7 +1295,7 @@ pub fn resolver(s: ast::SourceUnit, target: Target) -> (Option<Namespace>, Vec<O
 
 /// Resolve functions declarations, constructor declarations, and contract variables
 fn resolve_contract_declarations(
-    def: &ast::ContractDefinition,
+    def: &pt::ContractDefinition,
     contract_no: usize,
     target: Target,
     errors: &mut Vec<Output>,
@@ -1319,7 +1312,7 @@ fn resolve_contract_declarations(
 
     // resolve function signatures
     for (i, parts) in def.parts.iter().enumerate() {
-        if let ast::ContractPart::FunctionDefinition(ref f) = parts {
+        if let pt::ContractPart::FunctionDefinition(ref f) = parts {
             if !functions::function_decl(f, i, contract_no, ns, errors) {
                 broken = true;
             }
@@ -1339,13 +1332,13 @@ fn resolve_contract_declarations(
         && target == Target::Substrate
     {
         let mut fdecl = FunctionDecl::new(
-            ast::Loc(0, 0),
+            pt::Loc(0, 0),
             "".to_owned(),
             vec![],
-            ast::FunctionTy::Constructor,
+            pt::FunctionTy::Constructor,
             None,
             None,
-            ast::Visibility::Public(ast::Loc(0, 0)),
+            pt::Visibility::Public(pt::Loc(0, 0)),
             Vec::new(),
             Vec::new(),
             ns,
@@ -1366,7 +1359,7 @@ fn resolve_contract_declarations(
 }
 
 fn resolve_contract_bodies(
-    def: &ast::ContractDefinition,
+    def: &pt::ContractDefinition,
     contract_no: usize,
     errors: &mut Vec<Output>,
     ns: &mut Namespace,
@@ -1376,7 +1369,7 @@ fn resolve_contract_bodies(
     // resolve function bodies
     for f in 0..ns.contracts[contract_no].functions.len() {
         if let Some(ast_index) = ns.contracts[contract_no].functions[f].ast_index {
-            if let ast::ContractPart::FunctionDefinition(ref ast_f) = def.parts[ast_index] {
+            if let pt::ContractPart::FunctionDefinition(ref ast_f) = def.parts[ast_index] {
                 match cfg::generate_cfg(
                     ast_f,
                     &ns.contracts[contract_no].functions[f],
@@ -1386,7 +1379,7 @@ fn resolve_contract_bodies(
                 ) {
                     Ok(c) => {
                         match &ns.contracts[contract_no].functions[f].mutability {
-                            Some(ast::StateMutability::Pure(loc)) => {
+                            Some(pt::StateMutability::Pure(loc)) => {
                                 if c.writes_contract_storage {
                                     errors.push(Output::error(
                                         *loc,
@@ -1403,7 +1396,7 @@ fn resolve_contract_bodies(
                                     broken = true;
                                 }
                             }
-                            Some(ast::StateMutability::View(loc)) => {
+                            Some(pt::StateMutability::View(loc)) => {
                                 if c.writes_contract_storage {
                                     errors.push(Output::error(
                                         *loc,
@@ -1418,7 +1411,7 @@ fn resolve_contract_bodies(
                                     ));
                                 }
                             }
-                            Some(ast::StateMutability::Payable(_)) => {
+                            Some(pt::StateMutability::Payable(_)) => {
                                 //
                             }
                             None => {

+ 18 - 18
src/resolver/storage.rs

@@ -6,14 +6,14 @@ use num_traits::Zero;
 use super::cfg::{ControlFlowGraph, Instr, Vartable};
 use super::expression::{cast, expression, Expression};
 use output::Output;
-use parser::ast;
+use parser::pt;
 use resolver;
 
 /// Given a storage slot which is the start of the array, calculate the
 /// offset of the array element. This function exists to avoid doing
 /// 256 bit multiply if possible.
 pub fn array_offset(
-    loc: &ast::Loc,
+    loc: &pt::Loc,
     start: Expression,
     index: Expression,
     elem_ty: resolver::Type,
@@ -55,8 +55,8 @@ pub fn array_offset(
 
 /// Resolve delete statement
 pub fn delete(
-    loc: &ast::Loc,
-    var: &ast::Expression,
+    loc: &pt::Loc,
+    var: &pt::Expression,
     cfg: &mut ControlFlowGraph,
     contract_no: Option<usize>,
     ns: &resolver::Namespace,
@@ -106,11 +106,11 @@ pub fn delete(
 
 /// Push() method on dynamic array in storage
 pub fn array_push(
-    loc: &ast::Loc,
+    loc: &pt::Loc,
     var_expr: Expression,
-    func: &ast::Identifier,
+    func: &pt::Identifier,
     ty: &resolver::Type,
-    args: &[ast::Expression],
+    args: &[pt::Expression],
     cfg: &mut ControlFlowGraph,
     contract_no: Option<usize>,
     ns: &resolver::Namespace,
@@ -232,11 +232,11 @@ pub fn array_push(
 
 /// Pop() method on dynamic array in storage
 pub fn array_pop(
-    loc: &ast::Loc,
+    loc: &pt::Loc,
     var_expr: Expression,
-    func: &ast::Identifier,
+    func: &pt::Identifier,
     ty: &resolver::Type,
-    args: &[ast::Expression],
+    args: &[pt::Expression],
     cfg: &mut ControlFlowGraph,
     ns: &resolver::Namespace,
     vartab: &mut Option<&mut Vartable>,
@@ -364,10 +364,10 @@ pub fn array_pop(
 
 /// Push() method on dynamic bytes in storage
 pub fn bytes_push(
-    loc: &ast::Loc,
+    loc: &pt::Loc,
     var_expr: Expression,
-    func: &ast::Identifier,
-    args: &[ast::Expression],
+    func: &pt::Identifier,
+    args: &[pt::Expression],
     cfg: &mut ControlFlowGraph,
     contract_no: Option<usize>,
     ns: &resolver::Namespace,
@@ -427,10 +427,10 @@ pub fn bytes_push(
 
 /// Pop() method on dynamic bytes in storage
 pub fn bytes_pop(
-    loc: &ast::Loc,
+    loc: &pt::Loc,
     var_expr: Expression,
-    func: &ast::Identifier,
-    args: &[ast::Expression],
+    func: &pt::Identifier,
+    args: &[pt::Expression],
     cfg: &mut ControlFlowGraph,
     errors: &mut Vec<Output>,
 ) -> Result<(Expression, resolver::Type), ()> {
@@ -452,10 +452,10 @@ pub fn bytes_pop(
 
 /// Calculate storage subscript
 pub fn mapping_subscript(
-    loc: &ast::Loc,
+    loc: &pt::Loc,
     mapping: Expression,
     mapping_ty: &resolver::Type,
-    index: &ast::Expression,
+    index: &pt::Expression,
     cfg: &mut ControlFlowGraph,
     contract_no: Option<usize>,
     ns: &resolver::Namespace,

+ 1 - 1
src/resolver/structs.rs

@@ -7,7 +7,7 @@ use parser::ast;
 /// contract, so that we can continue producing compiler messages for the remainder
 /// of the contract, even if the struct contains an invalid definition.
 pub fn struct_decl(
-    def: &ast::StructDefinition,
+    def: &pt::StructDefinition,
     contract_no: Option<usize>,
     ns: &mut Namespace,
     errors: &mut Vec<Output>,

+ 25 - 25
src/resolver/types.rs

@@ -1,12 +1,12 @@
 use super::{Contract, EnumDecl, Namespace, StructDecl, StructField, Symbol, Type};
 use output::Output;
-use parser::ast;
+use parser::pt;
 use std::collections::HashMap;
 use Target;
 
 /// Resolve all the types we can find (enums, structs, contracts). structs can have other
 /// structs as fields, including ones that have not been declared yet.
-pub fn resolve(s: &ast::SourceUnit, target: Target) -> (Namespace, Vec<Output>) {
+pub fn resolve(s: &pt::SourceUnit, target: Target) -> (Namespace, Vec<Output>) {
     let mut errors = Vec::new();
     let mut ns = Namespace::new(
         target,
@@ -23,20 +23,20 @@ pub fn resolve(s: &ast::SourceUnit, target: Target) -> (Namespace, Vec<Output>)
     // done
     for part in &s.0 {
         match part {
-            ast::SourceUnitPart::PragmaDirective(name, value) => {
+            pt::SourceUnitPart::PragmaDirective(name, value) => {
                 if name.name == "solidity" {
                     errors.push(Output::info(
-                        ast::Loc(name.loc.0, value.loc.1),
+                        pt::Loc(name.loc.0, value.loc.1),
                         "pragma ‘solidity’ is ignored".to_string(),
                     ));
                 } else if name.name == "experimental" && value.string == "ABIEncoderV2" {
                     errors.push(Output::info(
-                        ast::Loc(name.loc.0, value.loc.1),
+                        pt::Loc(name.loc.0, value.loc.1),
                         "pragma ‘experimental’ with value ‘ABIEncoderV2’ is ignored".to_string(),
                     ));
                 } else {
                     errors.push(Output::warning(
-                        ast::Loc(name.loc.0, value.loc.1),
+                        pt::Loc(name.loc.0, value.loc.1),
                         format!(
                             "unknown pragma ‘{}’ with value ‘{}’ ignored",
                             name.name, value.string
@@ -44,13 +44,13 @@ pub fn resolve(s: &ast::SourceUnit, target: Target) -> (Namespace, Vec<Output>)
                     ));
                 }
             }
-            ast::SourceUnitPart::ContractDefinition(def) => {
+            pt::SourceUnitPart::ContractDefinition(def) => {
                 resolve_contract(&def, &mut structs, &mut errors, &mut ns);
             }
-            ast::SourceUnitPart::EnumDefinition(def) => {
+            pt::SourceUnitPart::EnumDefinition(def) => {
                 let _ = enum_decl(&def, None, &mut ns, &mut errors);
             }
-            ast::SourceUnitPart::StructDefinition(def) => {
+            pt::SourceUnitPart::StructDefinition(def) => {
                 if ns.add_symbol(
                     None,
                     &def.name,
@@ -122,8 +122,8 @@ pub fn resolve(s: &ast::SourceUnit, target: Target) -> (Namespace, Vec<Output>)
 
 /// Resolve all the types in a contract
 fn resolve_contract<'a>(
-    def: &'a ast::ContractDefinition,
-    structs: &mut Vec<(StructDecl, &'a ast::StructDefinition, Option<usize>)>,
+    def: &'a pt::ContractDefinition,
+    structs: &mut Vec<(StructDecl, &'a pt::StructDefinition, Option<usize>)>,
     errors: &mut Vec<Output>,
     ns: &mut Namespace,
 ) -> bool {
@@ -139,12 +139,12 @@ fn resolve_contract<'a>(
 
     for parts in &def.parts {
         match parts {
-            ast::ContractPart::EnumDefinition(ref e) => {
+            pt::ContractPart::EnumDefinition(ref e) => {
                 if !enum_decl(e, Some(contract_no), ns, errors) {
                     broken = true;
                 }
             }
-            ast::ContractPart::StructDefinition(ref s) => {
+            pt::ContractPart::StructDefinition(ref s) => {
                 if ns.add_symbol(
                     Some(contract_no),
                     &s.name,
@@ -175,7 +175,7 @@ fn resolve_contract<'a>(
 /// contract, so that we can continue producing compiler messages for the remainder
 /// of the contract, even if the struct contains an invalid definition.
 pub fn struct_decl(
-    def: &ast::StructDefinition,
+    def: &pt::StructDefinition,
     contract_no: Option<usize>,
     ns: &mut Namespace,
     errors: &mut Vec<Output>,
@@ -249,7 +249,7 @@ pub fn struct_decl(
 /// Parse enum declaration. If the declaration is invalid, it is still generated
 /// so that we can continue parsing, with errors recorded.
 fn enum_decl(
-    enum_: &ast::EnumDefinition,
+    enum_: &pt::EnumDefinition,
     contract_no: Option<usize>,
     ns: &mut Namespace,
     errors: &mut Vec<Output>,
@@ -278,7 +278,7 @@ fn enum_decl(
     }
 
     // check for duplicates
-    let mut entries: HashMap<String, (ast::Loc, usize)> = HashMap::new();
+    let mut entries: HashMap<String, (pt::Loc, usize)> = HashMap::new();
 
     for (i, e) in enum_.values.iter().enumerate() {
         if let Some(prev) = entries.get(&e.name.to_string()) {
@@ -323,10 +323,10 @@ fn enum_decl(
 
 #[test]
 fn enum_256values_is_uint8() {
-    let mut e = ast::EnumDefinition {
+    let mut e = pt::EnumDefinition {
         doc: vec![],
-        name: ast::Identifier {
-            loc: ast::Loc(0, 0),
+        name: pt::Identifier {
+            loc: pt::Loc(0, 0),
             name: "foo".into(),
         },
         values: Vec::new(),
@@ -334,8 +334,8 @@ fn enum_256values_is_uint8() {
 
     let mut ns = Namespace::new(Target::Ewasm, 20);
 
-    e.values.push(ast::Identifier {
-        loc: ast::Loc(0, 0),
+    e.values.push(pt::Identifier {
+        loc: pt::Loc(0, 0),
         name: "first".into(),
     });
 
@@ -343,8 +343,8 @@ fn enum_256values_is_uint8() {
     assert_eq!(ns.enums.last().unwrap().ty, Type::Uint(8));
 
     for i in 1..256 {
-        e.values.push(ast::Identifier {
-            loc: ast::Loc(0, 0),
+        e.values.push(pt::Identifier {
+            loc: pt::Loc(0, 0),
             name: format!("val{}", i),
         })
     }
@@ -355,8 +355,8 @@ fn enum_256values_is_uint8() {
     assert!(enum_decl(&e, None, &mut ns, &mut Vec::new()));
     assert_eq!(ns.enums.last().unwrap().ty, Type::Uint(8));
 
-    e.values.push(ast::Identifier {
-        loc: ast::Loc(0, 0),
+    e.values.push(pt::Identifier {
+        loc: pt::Loc(0, 0),
         name: "another".into(),
     });
 

+ 9 - 9
src/resolver/variables.rs

@@ -1,12 +1,12 @@
 use super::{ContractVariable, Namespace, Symbol};
 use output::Output;
-use parser::ast;
+use parser::pt;
 use resolver::cfg::{ControlFlowGraph, Instr, Storage, Vartable};
 use resolver::expression::{cast, expression, Expression};
 use resolver::ContractVariableType;
 
 pub fn contract_variables(
-    def: &ast::ContractDefinition,
+    def: &pt::ContractDefinition,
     contract_no: usize,
     ns: &mut Namespace,
     errors: &mut Vec<Output>,
@@ -16,7 +16,7 @@ pub fn contract_variables(
     let mut cfg = ControlFlowGraph::new();
 
     for parts in &def.parts {
-        if let ast::ContractPart::ContractVariableDefinition(ref s) = parts {
+        if let pt::ContractPart::ContractVariableDefinition(ref s) = parts {
             if !var_decl(s, contract_no, ns, &mut cfg, &mut vartab, errors) {
                 broken = true;
             }
@@ -33,7 +33,7 @@ pub fn contract_variables(
 }
 
 fn var_decl(
-    s: &ast::ContractVariableDefinition,
+    s: &pt::ContractVariableDefinition,
     contract_no: usize,
     ns: &mut Namespace,
     cfg: &mut ControlFlowGraph,
@@ -48,11 +48,11 @@ fn var_decl(
     };
 
     let mut is_constant = false;
-    let mut visibility: Option<ast::Visibility> = None;
+    let mut visibility: Option<pt::Visibility> = None;
 
     for attr in &s.attrs {
         match &attr {
-            ast::VariableAttribute::Constant(loc) => {
+            pt::VariableAttribute::Constant(loc) => {
                 if is_constant {
                     errors.push(Output::warning(
                         *loc,
@@ -61,14 +61,14 @@ fn var_decl(
                 }
                 is_constant = true;
             }
-            ast::VariableAttribute::Visibility(ast::Visibility::External(loc)) => {
+            pt::VariableAttribute::Visibility(pt::Visibility::External(loc)) => {
                 errors.push(Output::error(
                     *loc,
                     "variable cannot be declared external".to_string(),
                 ));
                 return false;
             }
-            ast::VariableAttribute::Visibility(v) => {
+            pt::VariableAttribute::Visibility(v) => {
                 if let Some(e) = &visibility {
                     errors.push(Output::error_with_note(
                         v.loc(),
@@ -86,7 +86,7 @@ fn var_decl(
 
     let visibility = match visibility {
         Some(v) => v,
-        None => ast::Visibility::Private(ast::Loc(0, 0)),
+        None => pt::Visibility::Private(pt::Loc(0, 0)),
     };
 
     let var = if !is_constant {

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů