From acd73d21fe2dd13604eb449b158f46e5e72ffa2d Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 27 Aug 2021 23:45:47 +0900 Subject: [PATCH] Compiler::qualified_name as vec --- src/compile.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/compile.rs b/src/compile.rs index 259d766..beded10 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -56,7 +56,7 @@ struct Compiler { symbol_table_stack: Vec, source_path: String, current_source_location: ast::Location, - current_qualified_path: Option, + qualified_path: Vec, done_with_future_stmts: bool, ctx: CompileContext, class_name: Option, @@ -190,7 +190,7 @@ impl Compiler { symbol_table_stack: Vec::new(), source_path, current_source_location: ast::Location::default(), - current_qualified_path: None, + qualified_path: Vec::new(), done_with_future_stmts: false, ctx: CompileContext { loop_data: None, @@ -1020,10 +1020,9 @@ impl Compiler { }, }; - let old_qualified_path = self.current_qualified_path.clone(); - self.push_qualified_name(name); - let qualified_name = self.current_qualified_path.clone().unwrap(); - self.push_qualified_name(""); + self.push_qualified_path(name); + let qualified_name = self.qualified_path.join("."); + self.push_qualified_path(""); let (body, doc_str) = get_doc(body); @@ -1041,7 +1040,8 @@ impl Compiler { } let code = self.pop_code_object(); - self.current_qualified_path = old_qualified_path; + self.qualified_path.pop(); + self.qualified_path.pop(); self.ctx = prev_ctx; // Prepare type annotations: @@ -1191,9 +1191,8 @@ impl Compiler { let prev_class_name = std::mem::replace(&mut self.class_name, Some(name.to_owned())); - let old_qualified_path = self.current_qualified_path.clone(); - self.push_qualified_name(name); - let qualified_name = self.current_qualified_path.clone().unwrap(); + self.push_qualified_path(name); + let qualified_name = self.qualified_path.join("."); self.push_output(bytecode::CodeFlags::empty(), 0, 0, 0, name.to_owned()); @@ -1239,7 +1238,7 @@ impl Compiler { let code = self.pop_code_object(); self.class_name = prev_class_name; - self.current_qualified_path = old_qualified_path; + self.qualified_path.pop(); self.ctx = prev_ctx; let mut funcflags = bytecode::MakeFunctionFlags::empty(); @@ -2465,13 +2464,8 @@ impl Compiler { self.current_source_location.row() } - fn push_qualified_name(&mut self, name: &str) { - if let Some(ref mut qualified_path) = self.current_qualified_path { - qualified_path.push('.'); - qualified_path.push_str(name); - } else { - self.current_qualified_path = Some(name.to_owned()); - } + fn push_qualified_path(&mut self, name: &str) { + self.qualified_path.push(name.to_owned()); } fn mark_generator(&mut self) {