From 1c31aa6e8edad5fb5dc2786c9399f5c58cf10ff1 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 2 Dec 2021 10:45:46 +0800 Subject: [PATCH] consistent naming --- nac3core/src/toplevel/builtins.rs | 2 +- nac3core/src/toplevel/composer.rs | 40 +++++++++++++++---------------- nac3core/src/toplevel/test.rs | 6 ++--- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index d200aa12..94b598bc 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -8,7 +8,7 @@ type BuiltinInfo = ( &'static [&'static str] ); -pub fn get_built_ins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { +pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { let int32 = primitives.0.int32; let int64 = primitives.0.int64; let float = primitives.0.float; diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index c5367845..02b800da 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -24,7 +24,7 @@ pub struct TopLevelComposer { // get the class def id of a class method pub method_class: HashMap, // number of built-in function and classes in the definition list, later skip - pub built_in_num: usize, + pub builtin_num: usize, } impl Default for TopLevelComposer { @@ -40,7 +40,7 @@ impl TopLevelComposer { builtins: Vec<(StrRef, FunSignature, Arc)>, ) -> (Self, HashMap, HashMap) { let mut primitives = Self::make_primitives(); - let (mut definition_ast_list, builtin_name_list) = builtins::get_built_ins(&mut primitives); + let (mut definition_ast_list, builtin_name_list) = builtins::get_builtins(&mut primitives); let primitives_ty = primitives.0; let mut unifier = primitives.1; let mut keyword_list: HashSet = HashSet::from_iter(vec![ @@ -63,8 +63,8 @@ impl TopLevelComposer { let defined_names: HashSet = Default::default(); let method_class: HashMap = Default::default(); - let mut built_in_id: HashMap = Default::default(); - let mut built_in_ty: HashMap = Default::default(); + let mut builtin_id: HashMap = Default::default(); + let mut builtin_ty: HashMap = Default::default(); for (id, name) in builtin_name_list.iter().rev().enumerate() { let name = (**name).into(); @@ -72,8 +72,8 @@ impl TopLevelComposer { let def = definition_ast_list[id].0.read(); if let TopLevelDef::Function { simple_name, signature, .. } = &*def { assert!(name == *simple_name); - built_in_ty.insert(name, *signature); - built_in_id.insert(name, DefinitionId(id)); + builtin_ty.insert(name, *signature); + builtin_id.insert(name, DefinitionId(id)); } else { unreachable!() } @@ -81,8 +81,8 @@ impl TopLevelComposer { for (name, sig, codegen_callback) in builtins { let fun_sig = unifier.add_ty(TypeEnum::TFunc(RefCell::new(sig))); - built_in_ty.insert(name, fun_sig); - built_in_id.insert(name, DefinitionId(definition_ast_list.len())); + builtin_ty.insert(name, fun_sig); + builtin_id.insert(name, DefinitionId(definition_ast_list.len())); definition_ast_list.push(( Arc::new(RwLock::new(TopLevelDef::Function { name: name.into(), @@ -101,7 +101,7 @@ impl TopLevelComposer { ( TopLevelComposer { - built_in_num: definition_ast_list.len(), + builtin_num: definition_ast_list.len(), definition_ast_list, primitives_ty, unifier, @@ -109,8 +109,8 @@ impl TopLevelComposer { defined_names, method_class, }, - built_in_id, - built_in_ty, + builtin_id, + builtin_ty, ) } @@ -320,7 +320,7 @@ impl TopLevelComposer { let primitives_store = &self.primitives_ty; // skip 5 to skip analyzing the primitives - for (class_def, class_ast) in def_list.iter().skip(self.built_in_num) { + for (class_def, class_ast) in def_list.iter().skip(self.builtin_num) { // only deal with class def here let mut class_def = class_def.write(); let (class_bases_ast, class_def_type_vars, class_resolver) = { @@ -426,7 +426,7 @@ impl TopLevelComposer { // first, only push direct parent into the list // skip 5 to skip analyzing the primitives - for (class_def, class_ast) in self.definition_ast_list.iter_mut().skip(self.built_in_num) { + for (class_def, class_ast) in self.definition_ast_list.iter_mut().skip(self.builtin_num) { let mut class_def = class_def.write(); let (class_def_id, class_bases, class_ancestors, class_resolver, class_type_vars) = { if let TopLevelDef::Class { ancestors, resolver, object_id, type_vars, .. } = @@ -490,7 +490,7 @@ impl TopLevelComposer { // second, get all ancestors let mut ancestors_store: HashMap> = Default::default(); // skip 5 to skip analyzing the primitives - for (class_def, _) in self.definition_ast_list.iter().skip(self.built_in_num) { + for (class_def, _) in self.definition_ast_list.iter().skip(self.builtin_num) { let class_def = class_def.read(); let (class_ancestors, class_id) = { if let TopLevelDef::Class { ancestors, object_id, .. } = class_def.deref() { @@ -512,7 +512,7 @@ impl TopLevelComposer { // insert the ancestors to the def list // skip 5 to skip analyzing the primitives - for (class_def, _) in self.definition_ast_list.iter_mut().skip(self.built_in_num) { + for (class_def, _) in self.definition_ast_list.iter_mut().skip(self.builtin_num) { let mut class_def = class_def.write(); let (class_ancestors, class_id, class_type_vars) = { if let TopLevelDef::Class { ancestors, object_id, type_vars, .. } = @@ -545,7 +545,7 @@ impl TopLevelComposer { let mut type_var_to_concrete_def: HashMap = HashMap::new(); // skip 5 to skip analyzing the primitives - for (class_def, class_ast) in def_ast_list.iter().skip(self.built_in_num) { + for (class_def, class_ast) in def_ast_list.iter().skip(self.builtin_num) { if matches!(&*class_def.read(), TopLevelDef::Class { .. }) { Self::analyze_single_class_methods_fields( class_def.clone(), @@ -566,7 +566,7 @@ impl TopLevelComposer { loop { let mut finished = true; - for (class_def, _) in def_ast_list.iter().skip(self.built_in_num) { + for (class_def, _) in def_ast_list.iter().skip(self.builtin_num) { let mut class_def = class_def.write(); if let TopLevelDef::Class { ancestors, .. } = class_def.deref() { // if the length of the ancestor is equal to the current depth @@ -625,7 +625,7 @@ impl TopLevelComposer { let primitives_store = &self.primitives_ty; // skip 5 to skip analyzing the primitives - for (function_def, function_ast) in def_list.iter().skip(self.built_in_num) { + for (function_def, function_ast) in def_list.iter().skip(self.builtin_num) { let mut function_def = function_def.write(); let function_def = function_def.deref_mut(); let function_ast = if let Some(x) = function_ast.as_ref() { @@ -1235,7 +1235,7 @@ impl TopLevelComposer { fn analyze_function_instance(&mut self) -> Result<(), String> { // first get the class contructor type correct for the following type check in function body // also do class field instantiation check - for (def, ast) in self.definition_ast_list.iter().skip(self.built_in_num) { + for (def, ast) in self.definition_ast_list.iter().skip(self.builtin_num) { let class_def = def.read(); if let TopLevelDef::Class { constructor, @@ -1306,7 +1306,7 @@ impl TopLevelComposer { let ctx = Arc::new(self.make_top_level_context()); // type inference inside function body - for (id, (def, ast)) in self.definition_ast_list.iter().enumerate().skip(self.built_in_num) + for (id, (def, ast)) in self.definition_ast_list.iter().enumerate().skip(self.builtin_num) { let mut function_def = def.write(); if let TopLevelDef::Function { diff --git a/nac3core/src/toplevel/test.rs b/nac3core/src/toplevel/test.rs index d1135c7d..81b3e62e 100644 --- a/nac3core/src/toplevel/test.rs +++ b/nac3core/src/toplevel/test.rs @@ -162,7 +162,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s composer.start_analysis(true).unwrap(); - for (i, (def, _)) in composer.definition_ast_list.iter().skip(composer.built_in_num).enumerate() + for (i, (def, _)) in composer.definition_ast_list.iter().skip(composer.builtin_num).enumerate() { let def = &*def.read(); if let TopLevelDef::Function { signature, name, .. } = def { @@ -530,7 +530,7 @@ fn test_analyze(source: Vec<&str>, res: Vec<&str>) { } else { // skip 5 to skip primitives let mut res_vec: Vec = Vec::new(); - for (def, _) in composer.definition_ast_list.iter().skip(composer.built_in_num) { + for (def, _) in composer.definition_ast_list.iter().skip(composer.builtin_num) { let def = &*def.read(); res_vec.push(format!("{}\n", def.to_string(composer.unifier.borrow_mut()))); } @@ -715,7 +715,7 @@ fn test_inference(source: Vec<&str>, res: Vec<&str>) { // skip 5 to skip primitives let mut stringify_folder = TypeToStringFolder { unifier: &mut composer.unifier }; for (_i, (def, _)) in - composer.definition_ast_list.iter().skip(composer.built_in_num).enumerate() + composer.definition_ast_list.iter().skip(composer.builtin_num).enumerate() { let def = &*def.read();