forked from M-Labs/nac3
1
0
Fork 0

change the symbol resolver back and add some test case

This commit is contained in:
ychenfo 2021-07-27 10:57:25 +08:00
parent 512fc59281
commit 9603aa644a
2 changed files with 13 additions and 5 deletions

View File

@ -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();

View File

@ -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<Type>;
fn parse_type_name(&mut self, expr: &Expr<()>) -> Option<Type>;
fn get_symbol_value(&mut self, str: &str) -> Option<SymbolValue>;
fn get_symbol_location(&mut self, str: &str) -> Option<Location>;
fn get_symbol_type(&self, str: &str) -> Option<SymbolType>;
fn get_symbol_value(&self, str: &str) -> Option<SymbolValue>;
fn get_symbol_location(&self, str: &str) -> Option<Location>;
// handle function call etc.
}