Refactor name-analysis module to use new AST api.
This commit is contained in:
parent
20dcb4f6ce
commit
cbf7921c95
@ -128,7 +128,7 @@ impl HasChildren for GenericParameters {
|
||||
|
||||
impl HasChildren for TupleArguments {
|
||||
fn children(&self) -> Vec<ChildRef> {
|
||||
self.arguments()
|
||||
self.type_uses()
|
||||
.iter()
|
||||
.map(|type_use| ChildRef::TypeUse(*type_use))
|
||||
.collect()
|
||||
|
@ -367,11 +367,11 @@ impl TupleArguments {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
pub fn arguments(&self) -> Vec<&TypeUse> {
|
||||
pub fn type_uses(&self) -> Vec<&TypeUse> {
|
||||
self.0.iter().map(Box::as_ref).collect()
|
||||
}
|
||||
|
||||
pub fn arguments_mut(&mut self) -> Vec<&mut TypeUse> {
|
||||
pub fn type_uses_mut(&mut self) -> Vec<&mut TypeUse> {
|
||||
self.0.iter_mut().map(Box::as_mut).collect()
|
||||
}
|
||||
}
|
||||
@ -674,6 +674,14 @@ impl UseStatement {
|
||||
pub fn last_mut(&mut self) -> &mut UseStatementLast {
|
||||
&mut self.last
|
||||
}
|
||||
|
||||
pub fn file_id(&self) -> usize {
|
||||
self.file_id
|
||||
}
|
||||
|
||||
pub fn range(&self) -> Range<usize> {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -1324,6 +1332,10 @@ impl ClassConstructor {
|
||||
pub fn parameters(&self) -> Vec<&ClassConstructorParameter> {
|
||||
self.0.iter().map(|p| p.as_ref()).collect()
|
||||
}
|
||||
|
||||
pub fn parameters_mut(&mut self) -> Vec<&mut ClassConstructorParameter> {
|
||||
self.0.iter_mut().map(|p| p.as_mut()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -278,7 +278,7 @@ impl ListUnparse for TupleArguments {
|
||||
}
|
||||
|
||||
fn inner(&self) -> Vec<&dyn Unparse> {
|
||||
to_unparse_vec!(self.arguments())
|
||||
to_unparse_vec!(self.type_uses())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ use crate::name_analysis::fqn_context::FqnContext;
|
||||
use crate::name_analysis::symbol::*;
|
||||
use crate::name_analysis::symbol_table::{SymbolInsertError, SymbolTable};
|
||||
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||||
use std::cell::RefCell;
|
||||
use std::ops::DerefMut;
|
||||
use std::range::Range;
|
||||
use std::rc::Rc;
|
||||
@ -106,9 +105,9 @@ fn gather_interface_or_class_type_use(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_fully_qualified_name(&mut interface_or_class_type_use.fqn, symbol_table);
|
||||
gather_fully_qualified_name(interface_or_class_type_use.fqn_mut(), symbol_table);
|
||||
gather_generic_arguments(
|
||||
&mut interface_or_class_type_use.generics,
|
||||
interface_or_class_type_use.generics_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -121,7 +120,7 @@ fn gather_tuple_type_use(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for generic_argument in &mut tuple_type_use.arguments.0 {
|
||||
for generic_argument in tuple_type_use.arguments_mut().type_uses_mut() {
|
||||
gather_type_use(generic_argument, symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -133,15 +132,15 @@ fn gather_function_type_use(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
symbol_table.push_scope("FunctionTypeUseScope");
|
||||
gather_generic_parameters(&mut function_type_use.generics, symbol_table, diagnostics);
|
||||
gather_generic_parameters(function_type_use.generics_mut(), symbol_table, diagnostics);
|
||||
gather_parameters(
|
||||
&mut function_type_use.parameters,
|
||||
function_type_use.parameters_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
);
|
||||
gather_return_type(
|
||||
&mut function_type_use.return_type,
|
||||
function_type_use.return_type_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -157,7 +156,7 @@ fn gather_generic_arguments(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for argument in &mut generic_arguments.0 {
|
||||
for argument in generic_arguments.arguments_mut() {
|
||||
gather_type_use(argument, symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -169,7 +168,7 @@ fn gather_generic_parameters(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for identifier in &mut generic_parameters.0 {
|
||||
for identifier in generic_parameters.identifiers_mut() {
|
||||
let insert_result =
|
||||
symbol_table.insert_type_symbol(TypeSymbol::Generic(GenericTypeSymbol::new(
|
||||
&identifier.name(),
|
||||
@ -199,7 +198,7 @@ fn gather_implements_list(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for type_use in &mut implements_list.0 {
|
||||
for type_use in implements_list.type_uses_mut() {
|
||||
gather_type_use(type_use, symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -213,7 +212,7 @@ fn gather_parameters(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) -> Option<Vec<Rc<ParameterSymbol>>> {
|
||||
parameters
|
||||
.0
|
||||
.parameters_mut()
|
||||
.iter_mut()
|
||||
.map(|parameter| gather_parameter(parameter, symbol_table, fqn_context, diagnostics))
|
||||
.collect()
|
||||
@ -225,21 +224,21 @@ fn gather_parameter(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) -> Option<Rc<ParameterSymbol>> {
|
||||
let parameter_name = parameter.identifier.name();
|
||||
let parameter_name = parameter.identifier().name();
|
||||
|
||||
let insert_result = symbol_table.insert_parameter_symbol(ParameterSymbol::new(
|
||||
¶meter_name,
|
||||
Some(¶meter.identifier),
|
||||
Some(¶meter.identifier()),
|
||||
));
|
||||
|
||||
match insert_result {
|
||||
Ok(parameter_symbol) => {
|
||||
parameter
|
||||
.identifier
|
||||
.identifier_mut()
|
||||
.set_scope_id(symbol_table.current_scope_id());
|
||||
|
||||
gather_type_use(
|
||||
&mut parameter.type_use,
|
||||
parameter.type_use_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -250,8 +249,8 @@ fn gather_parameter(
|
||||
handle_insert_error(
|
||||
err,
|
||||
¶meter_name,
|
||||
parameter.identifier.file_id(),
|
||||
parameter.identifier.range(),
|
||||
parameter.identifier().file_id(),
|
||||
parameter.identifier().range(),
|
||||
"function/variable",
|
||||
diagnostics,
|
||||
);
|
||||
@ -269,18 +268,18 @@ fn gather_return_type(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_type_use(
|
||||
&mut return_type.declared_type,
|
||||
return_type.declared_type_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
);
|
||||
gather_references(&mut return_type.references, symbol_table);
|
||||
gather_references(return_type.references_mut(), symbol_table);
|
||||
}
|
||||
|
||||
/* References */
|
||||
|
||||
fn gather_references(references: &mut References, symbol_table: &mut SymbolTable) {
|
||||
for identifier in &mut references.0 {
|
||||
for identifier in references.identifiers_mut() {
|
||||
gather_identifier(identifier, symbol_table);
|
||||
}
|
||||
}
|
||||
@ -293,15 +292,15 @@ pub(super) fn gather_compilation_unit(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let mut fqn_context = FqnContext::new();
|
||||
if let Some(namespace) = &compilation_unit.namespace {
|
||||
if let Some(namespace) = compilation_unit.namespace() {
|
||||
fqn_context.push(&namespace.name());
|
||||
}
|
||||
|
||||
symbol_table.push_scope(&format!("FileScope({})", compilation_unit.file_name));
|
||||
for use_statement in &mut compilation_unit.use_statements {
|
||||
symbol_table.push_scope(&format!("FileScope({})", compilation_unit.file_name()));
|
||||
for use_statement in compilation_unit.use_statements_mut() {
|
||||
gather_use_statement(use_statement, symbol_table, &mut fqn_context, diagnostics)
|
||||
}
|
||||
for declaration in &mut compilation_unit.declarations {
|
||||
for declaration in compilation_unit.declarations_mut() {
|
||||
gather_module_level_declaration(declaration, symbol_table, &mut fqn_context, diagnostics);
|
||||
}
|
||||
symbol_table.pop_scope();
|
||||
@ -313,34 +312,28 @@ pub(super) fn gather_compilation_unit(
|
||||
fn handle_use_statement_import(
|
||||
symbol_table: &mut SymbolTable,
|
||||
base_name: &str,
|
||||
identifier: Rc<RefCell<Identifier>>,
|
||||
identifier: &mut Identifier,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let borrowed_identifier = identifier.borrow();
|
||||
let declared_name = borrowed_identifier.name().to_string();
|
||||
let declared_name = identifier.name().to_string();
|
||||
let insert_result = symbol_table.insert_use_statement_symbol(UseStatementSymbol::new(
|
||||
&format!("{}::{}", base_name, &declared_name),
|
||||
&declared_name,
|
||||
Some(identifier.clone()),
|
||||
Some(identifier),
|
||||
));
|
||||
|
||||
match insert_result {
|
||||
Ok(use_statement_symbol) => {
|
||||
drop(borrowed_identifier);
|
||||
gather_identifier(identifier, symbol_table);
|
||||
|
||||
let mut mutable_borrowed_identifier = identifier.borrow_mut();
|
||||
|
||||
gather_identifier(mutable_borrowed_identifier.deref_mut(), symbol_table);
|
||||
|
||||
mutable_borrowed_identifier
|
||||
.set_saved_symbol(Symbol::UseStatement(use_statement_symbol));
|
||||
identifier.set_saved_symbol(Symbol::UseStatement(use_statement_symbol));
|
||||
}
|
||||
Err(err) => {
|
||||
handle_insert_error(
|
||||
err,
|
||||
&declared_name,
|
||||
borrowed_identifier.file_id(),
|
||||
borrowed_identifier.range(),
|
||||
identifier.file_id(),
|
||||
identifier.range(),
|
||||
"Use statement",
|
||||
diagnostics,
|
||||
);
|
||||
@ -358,18 +351,13 @@ fn gather_use_statement(
|
||||
todo!()
|
||||
}
|
||||
let base_name = use_statement.base_name().to_string();
|
||||
match &mut use_statement.last {
|
||||
match use_statement.last_mut() {
|
||||
UseStatementLast::Identifier(identifier) => {
|
||||
handle_use_statement_import(symbol_table, &base_name, identifier.clone(), diagnostics)
|
||||
handle_use_statement_import(symbol_table, &base_name, identifier, diagnostics)
|
||||
}
|
||||
UseStatementLast::Identifiers(identifiers) => {
|
||||
for identifier in identifiers {
|
||||
handle_use_statement_import(
|
||||
symbol_table,
|
||||
&base_name,
|
||||
identifier.clone(),
|
||||
diagnostics,
|
||||
)
|
||||
handle_use_statement_import(symbol_table, &base_name, identifier, diagnostics)
|
||||
}
|
||||
}
|
||||
UseStatementLast::Star => panic!(),
|
||||
@ -525,13 +513,13 @@ fn gather_module_declaration(
|
||||
// 5. Pop scope
|
||||
// 6. Pop fqn_context
|
||||
|
||||
let module_name = declaration.identifier.name();
|
||||
let module_name = declaration.identifier().name();
|
||||
|
||||
let insert_result = symbol_table.insert_module_symbol(ModuleSymbol::new(
|
||||
&fqn_context.resolve(&module_name),
|
||||
&module_name,
|
||||
declaration.is_public,
|
||||
Some(&declaration.identifier),
|
||||
declaration.is_public(),
|
||||
Some(declaration.identifier()),
|
||||
));
|
||||
|
||||
match insert_result {
|
||||
@ -539,7 +527,7 @@ fn gather_module_declaration(
|
||||
fqn_context.push(&module_name);
|
||||
symbol_table.push_scope(&format!("ModuleScope({})", module_name));
|
||||
|
||||
for inner_declaration in &mut declaration.declarations {
|
||||
for inner_declaration in declaration.declarations_mut() {
|
||||
gather_module_level_declaration(
|
||||
inner_declaration,
|
||||
symbol_table,
|
||||
@ -554,8 +542,8 @@ fn gather_module_declaration(
|
||||
Err(insert_error) => handle_insert_error(
|
||||
insert_error,
|
||||
&module_name,
|
||||
declaration.identifier.file_id(),
|
||||
declaration.identifier.range(),
|
||||
declaration.identifier().file_id(),
|
||||
declaration.identifier().range(),
|
||||
"Module",
|
||||
diagnostics,
|
||||
),
|
||||
@ -568,14 +556,14 @@ fn gather_interface_declaration(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let interface_name = declaration.identifier.name();
|
||||
let interface_name = declaration.identifier().name();
|
||||
|
||||
let insert_result =
|
||||
symbol_table.insert_type_symbol(TypeSymbol::Concrete(ConcreteTypeSymbol::new(
|
||||
&fqn_context.resolve(&interface_name),
|
||||
&interface_name,
|
||||
declaration.is_public,
|
||||
Some(&declaration.identifier),
|
||||
declaration.is_public(),
|
||||
Some(declaration.identifier()),
|
||||
)));
|
||||
|
||||
match insert_result {
|
||||
@ -583,7 +571,7 @@ fn gather_interface_declaration(
|
||||
fqn_context.push(&interface_name);
|
||||
symbol_table.push_scope(&format!("InterfaceScope({})", interface_name));
|
||||
|
||||
for inner_declaration in &mut declaration.declarations {
|
||||
for inner_declaration in declaration.declarations_mut() {
|
||||
gather_interface_level_declaration(
|
||||
inner_declaration,
|
||||
symbol_table,
|
||||
@ -599,8 +587,8 @@ fn gather_interface_declaration(
|
||||
handle_insert_error(
|
||||
insert_error,
|
||||
&interface_name,
|
||||
declaration.identifier.file_id(),
|
||||
declaration.identifier.range(),
|
||||
declaration.identifier().file_id(),
|
||||
declaration.identifier().range(),
|
||||
"Interface",
|
||||
diagnostics,
|
||||
);
|
||||
@ -614,21 +602,21 @@ fn gather_class_declaration(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let class_name = class_declaration.identifier.name();
|
||||
let class_name = class_declaration.identifier().name().to_string();
|
||||
|
||||
let insert_result =
|
||||
symbol_table.insert_type_symbol(TypeSymbol::Concrete(ConcreteTypeSymbol::new(
|
||||
&fqn_context.resolve(&class_name),
|
||||
&class_name,
|
||||
class_declaration.is_public,
|
||||
Some(&class_declaration.identifier),
|
||||
class_declaration.is_public(),
|
||||
Some(class_declaration.identifier()),
|
||||
)));
|
||||
|
||||
match insert_result {
|
||||
Ok(_) => {
|
||||
// Do this first so we can't implement generic parameters!
|
||||
gather_implements_list(
|
||||
&mut class_declaration.implements,
|
||||
class_declaration.implements_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -637,13 +625,13 @@ fn gather_class_declaration(
|
||||
fqn_context.push(&class_name);
|
||||
symbol_table.push_scope(&format!("ClassScope({})", class_name));
|
||||
|
||||
gather_generic_parameters(&mut class_declaration.generics, symbol_table, diagnostics);
|
||||
gather_generic_parameters(class_declaration.generics_mut(), symbol_table, diagnostics);
|
||||
|
||||
if let Some(class_constructor) = &mut class_declaration.class_constructor {
|
||||
if let Some(class_constructor) = class_declaration.class_constructor_mut() {
|
||||
gather_class_constructor(class_constructor, symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
|
||||
for inner_declaration in &mut class_declaration.declarations {
|
||||
for inner_declaration in class_declaration.declarations_mut() {
|
||||
gather_class_level_declaration(
|
||||
inner_declaration,
|
||||
symbol_table,
|
||||
@ -659,8 +647,8 @@ fn gather_class_declaration(
|
||||
handle_insert_error(
|
||||
insert_error,
|
||||
&class_name,
|
||||
class_declaration.identifier.file_id(),
|
||||
class_declaration.identifier.range(),
|
||||
class_declaration.identifier().file_id(),
|
||||
class_declaration.identifier().range(),
|
||||
"interface/class",
|
||||
diagnostics,
|
||||
);
|
||||
@ -676,27 +664,27 @@ fn gather_function_definition(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let declared_name = function.identifier.name();
|
||||
let declared_name = function.identifier().name();
|
||||
let resolved_name = fqn_context.resolve(&declared_name);
|
||||
|
||||
let insert_result = symbol_table.insert_function_symbol(FunctionSymbol::new(
|
||||
&resolved_name,
|
||||
&declared_name,
|
||||
function.is_public,
|
||||
function.is_public(),
|
||||
false,
|
||||
Some(&function.identifier),
|
||||
Some(function.identifier()),
|
||||
));
|
||||
|
||||
match insert_result {
|
||||
Ok(function_symbol) => {
|
||||
function
|
||||
.identifier
|
||||
.identifier_mut()
|
||||
.set_scope_id(symbol_table.current_scope_id());
|
||||
|
||||
symbol_table.push_scope(&format!("FunctionParameterScope({})", resolved_name));
|
||||
|
||||
let parameters_result = gather_parameters(
|
||||
&mut function.parameters,
|
||||
function.parameters_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -712,7 +700,7 @@ fn gather_function_definition(
|
||||
}
|
||||
|
||||
gather_return_type(
|
||||
&mut function.return_type,
|
||||
function.return_type_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -720,7 +708,7 @@ fn gather_function_definition(
|
||||
|
||||
symbol_table.push_scope(&format!("FunctionBodyScope({})", resolved_name));
|
||||
|
||||
gather_function_body(&mut function.body, symbol_table, fqn_context, diagnostics);
|
||||
gather_function_body(function.body_mut(), symbol_table, fqn_context, diagnostics);
|
||||
|
||||
symbol_table.pop_scope(); // body
|
||||
symbol_table.pop_scope(); // parameters
|
||||
@ -729,8 +717,8 @@ fn gather_function_definition(
|
||||
handle_insert_error(
|
||||
err,
|
||||
&declared_name,
|
||||
function.identifier.file_id(),
|
||||
function.identifier.range(),
|
||||
function.identifier().file_id(),
|
||||
function.identifier().range(),
|
||||
"function/variable",
|
||||
diagnostics,
|
||||
);
|
||||
@ -753,24 +741,26 @@ fn gather_platform_function_definition(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let declared_name = platform_function_declaration.identifier.name();
|
||||
let declared_name = platform_function_declaration.identifier().name();
|
||||
let fully_qualified_name = fqn_context.resolve(&declared_name);
|
||||
|
||||
let insert_result = symbol_table.insert_function_symbol(FunctionSymbol::new(
|
||||
&fully_qualified_name,
|
||||
&declared_name,
|
||||
platform_function_declaration.is_public,
|
||||
platform_function_declaration.is_public(),
|
||||
true,
|
||||
Some(&platform_function_declaration.identifier),
|
||||
Some(platform_function_declaration.identifier()),
|
||||
));
|
||||
|
||||
match insert_result {
|
||||
Ok(function_symbol) => {
|
||||
let declared_name_as_string =
|
||||
platform_function_declaration.identifier.name().to_string();
|
||||
let declared_name_as_string = platform_function_declaration
|
||||
.identifier()
|
||||
.name()
|
||||
.to_string();
|
||||
|
||||
platform_function_declaration
|
||||
.identifier
|
||||
.identifier_mut()
|
||||
.set_scope_id(symbol_table.current_scope_id());
|
||||
|
||||
symbol_table.push_scope(&format!(
|
||||
@ -779,7 +769,7 @@ fn gather_platform_function_definition(
|
||||
));
|
||||
|
||||
let parameter_symbols_result = gather_parameters(
|
||||
&mut platform_function_declaration.parameters,
|
||||
platform_function_declaration.parameters_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -795,7 +785,7 @@ fn gather_platform_function_definition(
|
||||
}
|
||||
|
||||
gather_return_type(
|
||||
&mut platform_function_declaration.return_type,
|
||||
platform_function_declaration.return_type_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -807,8 +797,8 @@ fn gather_platform_function_definition(
|
||||
handle_insert_error(
|
||||
err,
|
||||
&declared_name,
|
||||
platform_function_declaration.identifier.file_id(),
|
||||
platform_function_declaration.identifier.range(),
|
||||
platform_function_declaration.identifier().file_id(),
|
||||
platform_function_declaration.identifier().range(),
|
||||
"(Platform-) Function",
|
||||
diagnostics,
|
||||
);
|
||||
@ -822,23 +812,23 @@ fn gather_interface_function_declaration(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let name = declaration.identifier.name();
|
||||
let name = declaration.identifier().name();
|
||||
let insert_result = symbol_table.insert_function_symbol(FunctionSymbol::new(
|
||||
&fqn_context.resolve(&name),
|
||||
&name,
|
||||
true,
|
||||
false,
|
||||
Some(&declaration.identifier),
|
||||
Some(declaration.identifier()),
|
||||
));
|
||||
|
||||
match insert_result {
|
||||
Ok(function_symbol) => {
|
||||
symbol_table.push_scope(&format!("FunctionParameterScope({})", &name));
|
||||
|
||||
gather_generic_parameters(&mut declaration.generics, symbol_table, diagnostics);
|
||||
gather_generic_parameters(declaration.generics_mut(), symbol_table, diagnostics);
|
||||
|
||||
let parameters = gather_parameters(
|
||||
&mut declaration.parameters,
|
||||
declaration.parameters_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -850,13 +840,13 @@ fn gather_interface_function_declaration(
|
||||
}
|
||||
|
||||
gather_return_type(
|
||||
&mut declaration.return_type,
|
||||
declaration.return_type_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
);
|
||||
|
||||
if let Some(body) = &mut declaration.body {
|
||||
if let Some(body) = declaration.body_mut() {
|
||||
gather_function_body(body, symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
|
||||
@ -866,8 +856,8 @@ fn gather_interface_function_declaration(
|
||||
handle_insert_error(
|
||||
insert_error,
|
||||
&name,
|
||||
declaration.identifier.file_id(),
|
||||
declaration.identifier.range(),
|
||||
declaration.identifier().file_id(),
|
||||
declaration.identifier().range(),
|
||||
"Interface Function",
|
||||
diagnostics,
|
||||
);
|
||||
@ -906,13 +896,18 @@ fn gather_class_constructor(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for parameter in &mut class_constructor.0 {
|
||||
for parameter in class_constructor.parameters_mut() {
|
||||
match parameter {
|
||||
ClassConstructorParameter::Property(property) => {
|
||||
gather_property_declaration(property, symbol_table, fqn_context, diagnostics);
|
||||
gather_property_declaration(
|
||||
property.deref_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
);
|
||||
}
|
||||
ClassConstructorParameter::Field(field) => {
|
||||
gather_field_declaration(field, symbol_table, fqn_context, diagnostics);
|
||||
gather_field_declaration(field.deref_mut(), symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -924,19 +919,18 @@ fn gather_property_declaration(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let insert_result = symbol_table.insert_class_member_symbol(
|
||||
ClassMemberSymbol::new(
|
||||
&property_declaration.identifier.name(),
|
||||
false,
|
||||
Some(SourceDefinition::from_identifier(&property_declaration.identifier))
|
||||
)
|
||||
);
|
||||
let identifier = property_declaration.identifier();
|
||||
let insert_result = symbol_table.insert_class_member_symbol(ClassMemberSymbol::new(
|
||||
&identifier.name(),
|
||||
false,
|
||||
Some(SourceDefinition::from_identifier(identifier)),
|
||||
));
|
||||
if let Err(insert_error) = insert_result {
|
||||
handle_insert_error(
|
||||
insert_error,
|
||||
&property_declaration.identifier.name(),
|
||||
property_declaration.identifier.file_id(),
|
||||
property_declaration.identifier.range(),
|
||||
&identifier.name(),
|
||||
identifier.file_id(),
|
||||
identifier.range(),
|
||||
"Data Member",
|
||||
diagnostics,
|
||||
);
|
||||
@ -949,19 +943,18 @@ fn gather_field_declaration(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let insert_result = symbol_table.insert_class_member_symbol(
|
||||
ClassMemberSymbol::new(
|
||||
&field_declaration.identifier.name(),
|
||||
true,
|
||||
Some(SourceDefinition::from_identifier(&field_declaration.identifier))
|
||||
)
|
||||
);
|
||||
let identifier = field_declaration.identifier();
|
||||
let insert_result = symbol_table.insert_class_member_symbol(ClassMemberSymbol::new(
|
||||
&identifier.name(),
|
||||
true,
|
||||
Some(SourceDefinition::from_identifier(identifier)),
|
||||
));
|
||||
if let Err(insert_error) = insert_result {
|
||||
handle_insert_error(
|
||||
insert_error,
|
||||
&field_declaration.identifier.name(),
|
||||
field_declaration.identifier.file_id(),
|
||||
field_declaration.identifier.range(),
|
||||
&identifier.name(),
|
||||
identifier.file_id(),
|
||||
identifier.range(),
|
||||
"Data Member",
|
||||
diagnostics,
|
||||
);
|
||||
@ -987,10 +980,10 @@ fn gather_block_statement_inner(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for statement in &mut block.statements {
|
||||
for statement in block.statements_mut() {
|
||||
gather_statement(statement, symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
if let Some(expression) = &mut block.expression {
|
||||
if let Some(expression) = block.expression_mut() {
|
||||
gather_expression(expression, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -1024,30 +1017,31 @@ fn gather_variable_declaration(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let variable_name = variable_declaration.identifier.name();
|
||||
let identifier = variable_declaration.identifier();
|
||||
let variable_name = identifier.name();
|
||||
|
||||
let insert_result = symbol_table.insert_variable_symbol(VariableSymbol::new(
|
||||
&variable_name,
|
||||
variable_declaration.is_mutable,
|
||||
Some(&variable_declaration.identifier),
|
||||
variable_declaration.is_mutable(),
|
||||
Some(identifier),
|
||||
));
|
||||
|
||||
if let Err(err) = insert_result {
|
||||
handle_insert_error(
|
||||
err,
|
||||
&variable_name,
|
||||
variable_declaration.identifier.file_id(),
|
||||
variable_declaration.identifier.range(),
|
||||
identifier.file_id(),
|
||||
identifier.range(),
|
||||
"function/variable",
|
||||
diagnostics,
|
||||
)
|
||||
}
|
||||
|
||||
variable_declaration
|
||||
.identifier
|
||||
.identifier_mut()
|
||||
.set_scope_id(symbol_table.current_scope_id());
|
||||
|
||||
if let Some(initializer) = &mut variable_declaration.initializer {
|
||||
if let Some(initializer) = variable_declaration.initializer_mut() {
|
||||
gather_expression(initializer, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -1058,8 +1052,8 @@ fn gather_assign_statement(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut assign_statement.lhs, symbol_table, diagnostics);
|
||||
gather_expression(&mut assign_statement.rhs, symbol_table, diagnostics);
|
||||
gather_expression(assign_statement.lhs_mut(), symbol_table, diagnostics);
|
||||
gather_expression(assign_statement.rhs_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn gather_call_statement(
|
||||
@ -1067,16 +1061,15 @@ fn gather_call_statement(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut call_statement.0, symbol_table, diagnostics);
|
||||
gather_expression(call_statement.expression_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn gather_return_statement(
|
||||
return_statement: &mut ReturnStatement,
|
||||
symbol_table: &mut SymbolTable,
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
if let Some(expression) = &mut return_statement.0 {
|
||||
if let Some(expression) = return_statement.expression_mut() {
|
||||
gather_expression(expression, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -1087,9 +1080,9 @@ fn gather_if_statement(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut if_statement.condition, symbol_table, diagnostics);
|
||||
gather_expression(if_statement.condition_mut(), symbol_table, diagnostics);
|
||||
gather_block_statement(
|
||||
&mut if_statement.then_block,
|
||||
if_statement.then_block_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -1103,16 +1096,21 @@ fn gather_if_else_statement(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_if_statement(
|
||||
&mut if_else_statement.if_statement,
|
||||
if_else_statement.if_statement_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
);
|
||||
for if_statement in &mut if_else_statement.else_ifs.0 {
|
||||
for if_statement in if_else_statement.else_ifs_mut().if_statements_mut() {
|
||||
gather_if_statement(if_statement, symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
if let Some(else_block) = &mut if_else_statement.else_block {
|
||||
gather_block_statement(&mut else_block.0, symbol_table, fqn_context, diagnostics);
|
||||
if let Some(else_block) = if_else_statement.else_block_mut() {
|
||||
gather_block_statement(
|
||||
else_block.block_statement_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1122,9 +1120,9 @@ fn gather_while_statement(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut while_statement.condition, symbol_table, diagnostics);
|
||||
gather_expression(while_statement.condition_mut(), symbol_table, diagnostics);
|
||||
gather_block_statement(
|
||||
&mut while_statement.body,
|
||||
while_statement.body_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -1137,9 +1135,9 @@ fn gather_for_statement(
|
||||
fqn_context: &mut FqnContext,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut for_statement.iterator, symbol_table, diagnostics);
|
||||
gather_expression(for_statement.iterator_mut(), symbol_table, diagnostics);
|
||||
symbol_table.push_scope("ForStatementScope");
|
||||
let variable_identifier = &mut for_statement.variable;
|
||||
let variable_identifier = for_statement.variable_mut();
|
||||
let insert_result = symbol_table.insert_variable_symbol(VariableSymbol::new(
|
||||
&variable_identifier.name(),
|
||||
false,
|
||||
@ -1149,7 +1147,7 @@ fn gather_for_statement(
|
||||
match insert_result {
|
||||
Ok(_) => {
|
||||
gather_block_statement_inner(
|
||||
&mut for_statement.body,
|
||||
for_statement.body_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
@ -1214,14 +1212,18 @@ fn gather_ternary_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut ternary_expression.condition, symbol_table, diagnostics);
|
||||
gather_expression(
|
||||
&mut ternary_expression.true_expression,
|
||||
ternary_expression.condition_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
gather_expression(
|
||||
&mut ternary_expression.false_expression,
|
||||
ternary_expression.true_expression_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
gather_expression(
|
||||
ternary_expression.false_expression_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
@ -1232,8 +1234,8 @@ fn gather_binary_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut binary_expression.left, symbol_table, diagnostics);
|
||||
gather_expression(&mut binary_expression.right, symbol_table, diagnostics);
|
||||
gather_expression(binary_expression.left_mut(), symbol_table, diagnostics);
|
||||
gather_expression(binary_expression.right_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn gather_prefix_expression(
|
||||
@ -1241,7 +1243,11 @@ fn gather_prefix_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut prefix_expression.expression, symbol_table, diagnostics);
|
||||
gather_expression(
|
||||
prefix_expression.expression_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
}
|
||||
|
||||
fn gather_suffix_expression(
|
||||
@ -1249,7 +1255,11 @@ fn gather_suffix_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut suffix_expression.expression, symbol_table, diagnostics);
|
||||
gather_expression(
|
||||
suffix_expression.expression_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
}
|
||||
|
||||
fn gather_call_expression(
|
||||
@ -1257,12 +1267,12 @@ fn gather_call_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut call_expression.callee, symbol_table, diagnostics);
|
||||
if let Some(turbo_fish) = &mut call_expression.turbo_fish {
|
||||
gather_expression(call_expression.callee_mut(), symbol_table, diagnostics);
|
||||
if let Some(turbo_fish) = call_expression.turbo_fish_mut() {
|
||||
gather_turbo_fish(turbo_fish, symbol_table, diagnostics);
|
||||
}
|
||||
for call_argument in &mut call_expression.arguments.0 {
|
||||
gather_expression(&mut call_argument.0, symbol_table, diagnostics);
|
||||
for call_argument in call_expression.arguments_mut().arguments_mut() {
|
||||
gather_expression(call_argument.expression_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1287,8 +1297,8 @@ fn gather_object_access(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
gather_expression(&mut object_access.receiver, symbol_table, diagnostics);
|
||||
for object_navigation in &mut object_access.navigations.0 {
|
||||
gather_expression(object_access.receiver_mut(), symbol_table, diagnostics);
|
||||
for object_navigation in object_access.navigations_mut().navigations_mut() {
|
||||
match object_navigation {
|
||||
ObjectNavigation::Index(index_expression) => {
|
||||
gather_expression(index_expression, symbol_table, diagnostics);
|
||||
|
@ -4,9 +4,8 @@ use crate::diagnostic::DmDiagnostic;
|
||||
use crate::name_analysis::symbol::Symbol;
|
||||
use crate::name_analysis::symbol_table::{SymbolLookupError, SymbolTable};
|
||||
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||||
use std::cell::RefCell;
|
||||
use std::ops::DerefMut;
|
||||
use std::range::Range;
|
||||
use std::rc::Rc;
|
||||
|
||||
/* Type Use */
|
||||
|
||||
@ -56,7 +55,7 @@ fn resolve_interface_or_class_type_use(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
// 1. handle main name
|
||||
let fqn = &mut interface_or_class_type_use.fqn;
|
||||
let fqn = interface_or_class_type_use.fqn_mut();
|
||||
let lookup_result = if fqn.is_single_identifier() {
|
||||
let identifier = fqn.last();
|
||||
symbol_table.lookup_type_by_declared_name(
|
||||
@ -86,7 +85,7 @@ fn resolve_interface_or_class_type_use(
|
||||
|
||||
// 2. generics
|
||||
resolve_generic_arguments(
|
||||
&mut interface_or_class_type_use.generics,
|
||||
interface_or_class_type_use.generics_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
@ -97,7 +96,7 @@ fn resolve_tuple_type_use(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_tuple_arguments(&mut tuple_type_use.arguments, symbol_table, diagnostics);
|
||||
resolve_tuple_arguments(tuple_type_use.arguments_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_function_type_use(
|
||||
@ -105,9 +104,13 @@ fn resolve_function_type_use(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_parameters(&mut function_type_use.parameters, symbol_table, diagnostics);
|
||||
resolve_parameters(
|
||||
function_type_use.parameters_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
resolve_return_type(
|
||||
&mut function_type_use.return_type,
|
||||
function_type_use.return_type_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
@ -120,7 +123,7 @@ fn resolve_generic_arguments(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for generic_argument in &mut generic_arguments.0 {
|
||||
for generic_argument in generic_arguments.arguments_mut() {
|
||||
resolve_type_use(generic_argument, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -134,7 +137,7 @@ fn resolve_tuple_arguments(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for type_use in &mut tuple_type_use.0 {
|
||||
for type_use in tuple_type_use.type_uses_mut() {
|
||||
resolve_type_use(type_use, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -146,7 +149,7 @@ fn resolve_implements_list(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for type_use in &mut implements_list.0 {
|
||||
for type_use in implements_list.type_uses_mut() {
|
||||
resolve_type_use(type_use, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -158,8 +161,8 @@ fn resolve_parameters(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for parameter in &mut parameters.0 {
|
||||
resolve_type_use(&mut parameter.type_use, symbol_table, diagnostics);
|
||||
for parameter in parameters.parameters_mut() {
|
||||
resolve_type_use(parameter.type_use_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,8 +173,8 @@ fn resolve_return_type(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_type_use(&mut return_type.declared_type, symbol_table, diagnostics);
|
||||
resolve_references(&mut return_type.references, symbol_table, diagnostics);
|
||||
resolve_type_use(return_type.declared_type_mut(), symbol_table, diagnostics);
|
||||
resolve_references(return_type.references_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
/* References */
|
||||
@ -181,7 +184,7 @@ fn resolve_references(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for reference in &mut references.0 {
|
||||
for reference in references.identifiers_mut() {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@ -193,10 +196,10 @@ pub(super) fn resolve_compilation_unit(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for use_statement in &mut compilation_unit.use_statements {
|
||||
for use_statement in compilation_unit.use_statements_mut() {
|
||||
resolve_use_statement(use_statement, symbol_table, diagnostics);
|
||||
}
|
||||
for declaration in &mut compilation_unit.declarations {
|
||||
for declaration in compilation_unit.declarations_mut() {
|
||||
resolve_module_level_declaration(declaration, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -204,22 +207,20 @@ pub(super) fn resolve_compilation_unit(
|
||||
/* Use Statement */
|
||||
|
||||
fn handle_use_statement_identifier(
|
||||
identifier: Rc<RefCell<Identifier>>,
|
||||
identifier: &mut Identifier,
|
||||
base_name: &str,
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
file_id: usize,
|
||||
error_range: Range<usize>,
|
||||
) {
|
||||
let borrowed_identifier = identifier.borrow();
|
||||
let declared_name = borrowed_identifier.name().to_string();
|
||||
let declared_name = identifier.name().to_string();
|
||||
let fqn = format!("{}::{}", base_name, &declared_name);
|
||||
let lookup_result =
|
||||
symbol_table.lookup_usable_by_fqn(&fqn, borrowed_identifier.scope_id().unwrap());
|
||||
let lookup_result = symbol_table.lookup_usable_by_fqn(&fqn, identifier.scope_id().unwrap());
|
||||
|
||||
match lookup_result {
|
||||
Ok(referenced_symbol) => {
|
||||
let saved_symbol = borrowed_identifier
|
||||
let saved_symbol = identifier
|
||||
.saved_symbol()
|
||||
.expect("Identifier's saved_symbol is not set.");
|
||||
let use_statement_symbol = saved_symbol.unwrap_use_statement_symbol();
|
||||
@ -242,28 +243,31 @@ fn resolve_use_statement(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
let file_id = use_statement.file_id();
|
||||
let use_statement_range = use_statement.range();
|
||||
let base_name = use_statement.base_name().to_string();
|
||||
|
||||
match &use_statement.last {
|
||||
match use_statement.last_mut() {
|
||||
UseStatementLast::Identifier(identifier) => {
|
||||
handle_use_statement_identifier(
|
||||
identifier.clone(),
|
||||
identifier.deref_mut(),
|
||||
&base_name,
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
use_statement.file_id,
|
||||
use_statement.range,
|
||||
file_id,
|
||||
use_statement_range,
|
||||
);
|
||||
}
|
||||
UseStatementLast::Identifiers(identifiers) => {
|
||||
for identifier in identifiers {
|
||||
let identifier_range = identifier.range();
|
||||
handle_use_statement_identifier(
|
||||
identifier.clone(),
|
||||
identifier.deref_mut(),
|
||||
&base_name,
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
use_statement.file_id,
|
||||
identifier.borrow().range(),
|
||||
file_id,
|
||||
identifier_range,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -382,7 +386,7 @@ fn resolve_module_declaration(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for declaration in &mut module_declaration.declarations {
|
||||
for declaration in module_declaration.declarations_mut() {
|
||||
resolve_module_level_declaration(declaration, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -393,11 +397,11 @@ fn resolve_interface_declaration(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_implements_list(
|
||||
&mut interface_declaration.implements,
|
||||
interface_declaration.implements_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
for declaration in &mut interface_declaration.declarations {
|
||||
for declaration in interface_declaration.declarations_mut() {
|
||||
resolve_interface_level_declaration(declaration, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -407,11 +411,11 @@ fn resolve_class_declaration(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
if let Some(class_constructor) = &mut class_declaration.class_constructor {
|
||||
if let Some(class_constructor) = class_declaration.class_constructor_mut() {
|
||||
resolve_class_constructor(class_constructor, symbol_table, diagnostics);
|
||||
}
|
||||
resolve_implements_list(&mut class_declaration.implements, symbol_table, diagnostics);
|
||||
for declaration in &mut class_declaration.declarations {
|
||||
resolve_implements_list(class_declaration.implements_mut(), symbol_table, diagnostics);
|
||||
for declaration in class_declaration.declarations_mut() {
|
||||
resolve_class_level_declaration(declaration, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -424,16 +428,16 @@ fn resolve_function_definition(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_parameters(
|
||||
&mut function_definition.parameters,
|
||||
function_definition.parameters_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
resolve_return_type(
|
||||
&mut function_definition.return_type,
|
||||
function_definition.return_type_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
resolve_function_body(&mut function_definition.body, symbol_table, diagnostics);
|
||||
resolve_function_body(function_definition.body_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_operator_function_definition(
|
||||
@ -450,12 +454,12 @@ fn resolve_platform_function_declaration(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_parameters(
|
||||
&mut platform_function_declaration.parameters,
|
||||
platform_function_declaration.parameters_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
resolve_return_type(
|
||||
&mut platform_function_declaration.return_type,
|
||||
platform_function_declaration.return_type_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
@ -467,16 +471,16 @@ fn resolve_interface_function_declaration(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_parameters(
|
||||
&mut interface_function_declaration.parameters,
|
||||
interface_function_declaration.parameters_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
resolve_return_type(
|
||||
&mut interface_function_declaration.return_type,
|
||||
interface_function_declaration.return_type_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
if let Some(body) = &mut interface_function_declaration.body {
|
||||
if let Some(body) = interface_function_declaration.body_mut() {
|
||||
resolve_function_body(body, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -518,7 +522,7 @@ fn resolve_class_constructor(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
use crate::ast::ClassConstructorParameter::*;
|
||||
for parameter in &mut class_constructor.0 {
|
||||
for parameter in class_constructor.parameters_mut() {
|
||||
match parameter {
|
||||
Property(property) => resolve_property_declaration(property, symbol_table, diagnostics),
|
||||
Field(field) => resolve_field_declaration(field, symbol_table, diagnostics),
|
||||
@ -532,7 +536,7 @@ fn resolve_property_declaration(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_type_use(
|
||||
&mut property_declaration.declared_type,
|
||||
property_declaration.declared_type_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
@ -544,7 +548,7 @@ fn resolve_field_declaration(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_type_use(
|
||||
&mut field_declaration.declared_type,
|
||||
field_declaration.declared_type_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
@ -557,10 +561,10 @@ fn resolve_block_statement(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for statement in block_statement.statements.iter_mut() {
|
||||
for statement in block_statement.statements_mut() {
|
||||
resolve_statement(statement, symbol_table, diagnostics);
|
||||
}
|
||||
if let Some(expression) = block_statement.expression.as_mut() {
|
||||
if let Some(expression) = block_statement.expression_mut() {
|
||||
resolve_expression(expression, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -591,7 +595,7 @@ fn resolve_variable_declaration(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
if let Some(initializer) = &mut variable_declaration.initializer {
|
||||
if let Some(initializer) = variable_declaration.initializer_mut() {
|
||||
resolve_expression(initializer, symbol_table, diagnostics)
|
||||
}
|
||||
}
|
||||
@ -601,8 +605,8 @@ fn resolve_assign_statement(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_expression(&mut assign_statement.lhs, symbol_table, diagnostics);
|
||||
resolve_expression(&mut assign_statement.rhs, symbol_table, diagnostics);
|
||||
resolve_expression(assign_statement.lhs_mut(), symbol_table, diagnostics);
|
||||
resolve_expression(assign_statement.rhs_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_call_statement(
|
||||
@ -610,7 +614,7 @@ fn resolve_call_statement(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_expression(&mut call_statement.0, symbol_table, diagnostics)
|
||||
resolve_expression(call_statement.expression_mut(), symbol_table, diagnostics)
|
||||
}
|
||||
|
||||
fn resolve_return_statement(
|
||||
@ -618,7 +622,7 @@ fn resolve_return_statement(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
if let Some(expression) = &mut return_statement.0 {
|
||||
if let Some(expression) = return_statement.expression_mut() {
|
||||
resolve_expression(expression, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -737,14 +741,14 @@ fn resolve_ternary_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_expression(&mut ternary_expression.condition, symbol_table, diagnostics);
|
||||
resolve_expression(ternary_expression.condition_mut(), symbol_table, diagnostics);
|
||||
resolve_expression(
|
||||
&mut ternary_expression.true_expression,
|
||||
ternary_expression.true_expression_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
resolve_expression(
|
||||
&mut ternary_expression.false_expression,
|
||||
ternary_expression.false_expression_mut(),
|
||||
symbol_table,
|
||||
diagnostics,
|
||||
);
|
||||
@ -755,8 +759,8 @@ fn resolve_binary_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_expression(&mut binary_expression.left, symbol_table, diagnostics);
|
||||
resolve_expression(&mut binary_expression.right, symbol_table, diagnostics);
|
||||
resolve_expression(binary_expression.left_mut(), symbol_table, diagnostics);
|
||||
resolve_expression(binary_expression.right_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_prefix_expression(
|
||||
@ -764,7 +768,7 @@ fn resolve_prefix_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_expression(&mut prefix_expression.expression, symbol_table, diagnostics);
|
||||
resolve_expression(prefix_expression.expression_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_suffix_expression(
|
||||
@ -772,7 +776,7 @@ fn resolve_suffix_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_expression(&mut suffix_expression.expression, symbol_table, diagnostics);
|
||||
resolve_expression(suffix_expression.expression_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_call_expression(
|
||||
@ -780,11 +784,11 @@ fn resolve_call_expression(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_expression(&mut call_expression.callee, symbol_table, diagnostics);
|
||||
if let Some(turbo_fish) = &mut call_expression.turbo_fish {
|
||||
resolve_expression(call_expression.callee_mut(), symbol_table, diagnostics);
|
||||
if let Some(turbo_fish) = call_expression.turbo_fish_mut() {
|
||||
resolve_turbo_fish(turbo_fish, symbol_table, diagnostics);
|
||||
}
|
||||
resolve_call_arguments(&mut call_expression.arguments, symbol_table, diagnostics);
|
||||
resolve_call_arguments(call_expression.arguments_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_turbo_fish(
|
||||
@ -792,7 +796,7 @@ fn resolve_turbo_fish(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_generic_arguments(&mut turbo_fish.0, symbol_table, diagnostics);
|
||||
resolve_generic_arguments(turbo_fish.generics_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_call_arguments(
|
||||
@ -800,7 +804,7 @@ fn resolve_call_arguments(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
for argument in &mut call_arguments.0 {
|
||||
for argument in call_arguments.arguments_mut() {
|
||||
resolve_call_argument(argument, symbol_table, diagnostics);
|
||||
}
|
||||
}
|
||||
@ -810,7 +814,7 @@ fn resolve_call_argument(
|
||||
symbol_table: &mut SymbolTable,
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
resolve_expression(&mut call_argument.0, symbol_table, diagnostics);
|
||||
resolve_expression(call_argument.expression_mut(), symbol_table, diagnostics);
|
||||
}
|
||||
|
||||
fn resolve_closure(
|
||||
|
@ -31,8 +31,8 @@ impl SourceDefinition {
|
||||
#[deprecated(note = "Use identifier instead.")]
|
||||
pub fn from_use_statement(use_statement: &UseStatement) -> Self {
|
||||
SourceDefinition {
|
||||
file_id: use_statement.file_id,
|
||||
range: use_statement.range,
|
||||
file_id: use_statement.file_id(),
|
||||
range: use_statement.range(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,12 +100,12 @@ impl UseStatementSymbol {
|
||||
pub fn new(
|
||||
fqn: &str,
|
||||
declared_name: &str,
|
||||
identifier: Option<Rc<RefCell<Identifier>>>,
|
||||
identifier: Option<&Identifier>,
|
||||
) -> Self {
|
||||
UseStatementSymbol {
|
||||
fqn: fqn.to_string(),
|
||||
declared_name: declared_name.to_string(),
|
||||
definition: identifier.map(SourceDefinition::from_identifier_rc),
|
||||
definition: identifier.map(SourceDefinition::from_identifier),
|
||||
referenced_symbol: None,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user