From 43236db9bd38de83412de0ba47d744922d651f13 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Wed, 11 Aug 2021 13:31:59 +0800 Subject: [PATCH] update some previous work on top level with the clean up --- nac3core/src/top_level.rs | 23 +++++++++++++++-------- shell.nix | 2 -- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/nac3core/src/top_level.rs b/nac3core/src/top_level.rs index 754fca9d0..6f1dcbb7d 100644 --- a/nac3core/src/top_level.rs +++ b/nac3core/src/top_level.rs @@ -180,6 +180,7 @@ impl<'a> TopLevelComposer<'a> { ancestors: vec![DefinitionId(index)], } } + pub fn make_top_level_function_def(name: String, ty: Type) -> TopLevelDef { TopLevelDef::Function { name, @@ -189,8 +190,8 @@ impl<'a> TopLevelComposer<'a> { } } - // like to make and return a "primitive" symbol resolver? so that the symbol resolver can later - // figure out primitive type definitions when passed a primitive type name + // like to make and return a "primitive" symbol resolver? so that the symbol resolver + // can later figure out primitive type definitions when passed a primitive type name pub fn get_primitives_definition(&self) -> Vec<(String, DefinitionId, Type)> { vec![ ("int32".into(), DefinitionId(0), self.primitives.int32), @@ -220,8 +221,11 @@ impl<'a> TopLevelComposer<'a> { let mut ret_vector: Vec<(String, DefinitionId, Type)> = vec![(class_name.clone(), DefinitionId(class_def_id), ty)]; // parse class def body and register class methods into the def list - // NOTE: module's symbol resolver would not know the name of the class methods, thus cannot return their definition_id? so we have to manage it ourselves? - // or do we return the class method list of (method_name, def_id, type) to application to be used to build symbol resolver? <- current implementation + // NOTE: module's symbol resolver would not know the name of the class methods, + // thus cannot return their definition_id? so we have to manage it ourselves? + // or do we return the class method list of (method_name, def_id, type) to + // application to be used to build symbol resolver? <- current implementation + // FIXME: better do not return and let symbol resolver to manage the mangled name for b in body { if let ast::StmtKind::FunctionDef {name, ..} = &b.node { let fun_name = name_mangling(class_name.clone(), name); @@ -243,18 +247,20 @@ impl<'a> TopLevelComposer<'a> { ); ret_vector.push((fun_name, DefinitionId(def_id), ty)); - if name == "__init__" { // if it is the contructor, special handling is needed. In the above handling, we still add __init__ function to the class method + // if it is the contructor, special handling is needed. In the above + // handling, we still add __init__ function to the class method + if name == "__init__" { self.definition_list.push( TopLevelDefInfo { def: TopLevelDef::Initializer { - class_id: DefinitionId(class_def_id) // FIXME: None if have no parameter, Some if same as __init__? + class_id: DefinitionId(class_def_id) }, ty: self.primitives.none, // arbitary picked one ast: None, // it is inside the class def body statments resolver: Some(resolver) } ) - // FIXME: should we return this to the symbol resolver? + // FIXME: should we return this to the symbol resolver?, should be yes } } else { } // else do nothing } @@ -415,7 +421,8 @@ impl<'a> TopLevelComposer<'a> { } } - // ----------- class method and field are analyzed by looking into the class body ast node ----------- + // class method and field are analyzed by + // looking into the class body ast node for stmt in body { if let ast::StmtKind::FunctionDef { name, diff --git a/shell.nix b/shell.nix index 8f4e2ec85..858e68b93 100644 --- a/shell.nix +++ b/shell.nix @@ -6,6 +6,4 @@ in buildInputs = with pkgs; [ llvm_10 clang_10 cargo rustc libffi libxml2 clippy ]; - - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; }