From 9603aa644a980103e427cac04983acb866a6590f Mon Sep 17 00:00:00 2001 From: ychenfo Date: Tue, 27 Jul 2021 10:57:25 +0800 Subject: [PATCH] change the symbol resolver back and add some test case --- nac3core/src/typecheck/expression_inference.rs | 3 +++ nac3core/src/typecheck/symbol_resolver.rs | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/nac3core/src/typecheck/expression_inference.rs b/nac3core/src/typecheck/expression_inference.rs index 4f3ee814..3e90eb96 100644 --- a/nac3core/src/typecheck/expression_inference.rs +++ b/nac3core/src/typecheck/expression_inference.rs @@ -659,6 +659,9 @@ pub mod test { #[test_case("1 if True else False")] #[test_case("1 and 2")] #[test_case("False or 1")] + #[test_case("1 + False")] + #[test_case("1 < 2 > False")] + #[test_case("not 2")] fn test_err_msg(prog: &'static str) { let mut inf = new_ctx(); let ast = rustpython_parser::parser::parse_expression(prog).unwrap(); diff --git a/nac3core/src/typecheck/symbol_resolver.rs b/nac3core/src/typecheck/symbol_resolver.rs index a5328491..c96e75d5 100644 --- a/nac3core/src/typecheck/symbol_resolver.rs +++ b/nac3core/src/typecheck/symbol_resolver.rs @@ -1,6 +1,11 @@ use super::typedef::Type; use super::location::Location; -use rustpython_parser::ast::Expr; + +pub enum SymbolType { + TypeName(Type), + Identifier(Type), +} + pub enum SymbolValue<'a> { I32(i32), I64(i64), @@ -9,10 +14,10 @@ pub enum SymbolValue<'a> { Tuple(&'a [SymbolValue<'a>]), Bytes(&'a [u8]), } + pub trait SymbolResolver { - fn get_symbol_type(&mut self, str: &str) -> Option; - fn parse_type_name(&mut self, expr: &Expr<()>) -> Option; - fn get_symbol_value(&mut self, str: &str) -> Option; - fn get_symbol_location(&mut self, str: &str) -> Option; + fn get_symbol_type(&self, str: &str) -> Option; + fn get_symbol_value(&self, str: &str) -> Option; + fn get_symbol_location(&self, str: &str) -> Option; // handle function call etc. } \ No newline at end of file