Immutable use of FqnContext.
This commit is contained in:
parent
7d7626809d
commit
178ce5d1a6
@ -88,7 +88,7 @@ impl Class {
|
|||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_symbols(&self, fqn_context: &mut FqnContext) -> Vec<Symbol> {
|
pub fn make_symbols(&self, fqn_context: &FqnContext) -> Vec<Symbol> {
|
||||||
let mut all_symbols: Vec<Symbol> = Vec::new();
|
let mut all_symbols: Vec<Symbol> = Vec::new();
|
||||||
|
|
||||||
let mut generic_parameter_symbols = Vec::new();
|
let mut generic_parameter_symbols = Vec::new();
|
||||||
@ -105,16 +105,17 @@ impl Class {
|
|||||||
field_symbols.push(symbol);
|
field_symbols.push(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
fqn_context.push(self.declared_name.clone()); // namespace this class' members
|
let class_body_fqn_context = fqn_context.with_part(&self.declared_name);
|
||||||
|
|
||||||
let constructor_symbol = if let Some(constructor) = &self.constructor {
|
let constructor_symbol = if let Some(constructor) = &self.constructor {
|
||||||
let (constructor_symbol, mut symbols) = constructor.make_symbols(fqn_context);
|
let (constructor_symbol, mut symbols) =
|
||||||
|
constructor.make_symbols(&class_body_fqn_context);
|
||||||
all_symbols.append(&mut symbols);
|
all_symbols.append(&mut symbols);
|
||||||
constructor_symbol
|
constructor_symbol
|
||||||
} else {
|
} else {
|
||||||
Rc::new(ConstructorSymbol::new(
|
Rc::new(ConstructorSymbol::new(
|
||||||
&self.declared_name_source_range,
|
&self.declared_name_source_range,
|
||||||
resolve_ctor_name(fqn_context),
|
resolve_ctor_name(&class_body_fqn_context),
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
self.self_class_body_scope_id.unwrap(),
|
self.self_class_body_scope_id.unwrap(),
|
||||||
@ -125,17 +126,16 @@ impl Class {
|
|||||||
|
|
||||||
let mut function_symbols = Vec::new();
|
let mut function_symbols = Vec::new();
|
||||||
for function in &self.functions {
|
for function in &self.functions {
|
||||||
let (function_symbol, mut symbols) = function.make_symbols(fqn_context, true);
|
let (function_symbol, mut symbols) =
|
||||||
|
function.make_symbols(&class_body_fqn_context, true);
|
||||||
all_symbols.append(&mut symbols);
|
all_symbols.append(&mut symbols);
|
||||||
function_symbols.push(function_symbol);
|
function_symbols.push(function_symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
fqn_context.pop(); // un-namespace
|
|
||||||
|
|
||||||
let class_symbol = Rc::new(ClassSymbol::new(
|
let class_symbol = Rc::new(ClassSymbol::new(
|
||||||
&self.declared_name,
|
&self.declared_name,
|
||||||
Some(self.declared_name_source_range.clone()),
|
Some(self.declared_name_source_range.clone()),
|
||||||
fqn_context.resolve(&self.declared_name),
|
fqn_context.resolve(&self.declared_name), // not class body!
|
||||||
false,
|
false,
|
||||||
self.scope_id.unwrap(),
|
self.scope_id.unwrap(),
|
||||||
generic_parameter_symbols,
|
generic_parameter_symbols,
|
||||||
|
|||||||
@ -60,19 +60,19 @@ impl CompilationUnit {
|
|||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
) -> Result<(), Vec<Diagnostic>> {
|
) -> Result<(), Vec<Diagnostic>> {
|
||||||
let mut diagnostics = vec![];
|
let mut diagnostics = vec![];
|
||||||
let mut fqn_context = FqnContext::new();
|
let fqn_context = FqnContext::new();
|
||||||
for class in &self.classes {
|
for class in &self.classes {
|
||||||
handle_diagnostics!(
|
handle_diagnostics!(
|
||||||
try_insert_symbols_into(class.make_symbols(&mut fqn_context), symbol_table),
|
try_insert_symbols_into(class.make_symbols(&fqn_context), symbol_table),
|
||||||
diagnostics
|
diagnostics
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for function in &self.functions {
|
for function in &self.functions {
|
||||||
let (_, symbols) = function.make_symbols(&mut fqn_context, false);
|
let (_, symbols) = function.make_symbols(&fqn_context, false);
|
||||||
handle_diagnostics!(try_insert_symbols_into(symbols, symbol_table), diagnostics);
|
handle_diagnostics!(try_insert_symbols_into(symbols, symbol_table), diagnostics);
|
||||||
}
|
}
|
||||||
for extern_function in &self.extern_functions {
|
for extern_function in &self.extern_functions {
|
||||||
let (_, symbols) = extern_function.make_symbols(&mut fqn_context);
|
let (_, symbols) = extern_function.make_symbols(&fqn_context);
|
||||||
handle_diagnostics!(try_insert_symbols_into(symbols, symbol_table), diagnostics);
|
handle_diagnostics!(try_insert_symbols_into(symbols, symbol_table), diagnostics);
|
||||||
}
|
}
|
||||||
diagnostics_result!(diagnostics)
|
diagnostics_result!(diagnostics)
|
||||||
|
|||||||
@ -9,12 +9,10 @@ impl FqnContext {
|
|||||||
Self { parts: vec![] }
|
Self { parts: vec![] }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push(&mut self, part: Rc<str>) {
|
pub fn with_part(&self, part: &Rc<str>) -> Self {
|
||||||
self.parts.push(part);
|
let mut new_parts = self.parts.clone();
|
||||||
}
|
new_parts.push(part.clone());
|
||||||
|
Self { parts: new_parts }
|
||||||
pub fn pop(&mut self) {
|
|
||||||
self.parts.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve(&self, name: &str) -> Vec<Rc<str>> {
|
pub fn resolve(&self, name: &str) -> Vec<Rc<str>> {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user