Introduce scope_ids hash table.
This commit is contained in:
parent
5d41a22899
commit
f0772fbf11
@ -151,5 +151,15 @@ pub fn deserialize_struct_spec(name: &str, struct_yaml: &Yaml) -> StructSpec {
|
|||||||
} else {
|
} else {
|
||||||
deserialize_error!("array", "children", name);
|
deserialize_error!("array", "children", name);
|
||||||
};
|
};
|
||||||
StructSpec::new(name, children)
|
let derive = if struct_yaml["derive"].is_array() {
|
||||||
|
struct_yaml["derive"].as_vec()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|derive| derive.as_str().unwrap().to_string())
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
};
|
||||||
|
|
||||||
|
StructSpec::new(name, children, derive)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
pub struct StructSpec {
|
pub struct StructSpec {
|
||||||
build: String,
|
build: String,
|
||||||
children: Vec<Box<StructChild>>,
|
children: Vec<Box<StructChild>>,
|
||||||
|
derive: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StructSpec {
|
impl StructSpec {
|
||||||
pub fn new(build: &str, children: Vec<Box<StructChild>>) -> Self {
|
pub fn new(build: &str, children: Vec<Box<StructChild>>, derive: Vec<String>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
build: build.to_string(),
|
build: build.to_string(),
|
||||||
children,
|
children,
|
||||||
|
derive,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +22,10 @@ impl StructSpec {
|
|||||||
pub fn children(&self) -> impl Iterator<Item = &StructChild> {
|
pub fn children(&self) -> impl Iterator<Item = &StructChild> {
|
||||||
self.children.iter().map(Box::as_ref)
|
self.children.iter().map(Box::as_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn derive(&self) -> &[String] {
|
||||||
|
&self.derive
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum StructChild {
|
pub enum StructChild {
|
||||||
|
|||||||
@ -205,10 +205,30 @@ pub fn make_struct_type(build_spec: &StructSpec) -> TokenStream {
|
|||||||
.map(Option::unwrap)
|
.map(Option::unwrap)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
quote! {
|
let struct_stream = {
|
||||||
pub struct #type_ident {
|
let base = quote! {
|
||||||
#(#annotated_members),*
|
pub struct #type_ident {
|
||||||
|
#(#annotated_members),*
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if !build_spec.derive().is_empty() {
|
||||||
|
let derives = build_spec
|
||||||
|
.derive()
|
||||||
|
.iter()
|
||||||
|
.map(|derive| format_ident!("{}", derive))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
#[derive(#(#derives,)*)]
|
||||||
|
#base
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
base
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
#struct_stream
|
||||||
|
|
||||||
impl #type_ident {
|
impl #type_ident {
|
||||||
pub fn new(#(#annotated_members),*) -> Self {
|
pub fn new(#(#annotated_members),*) -> Self {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use crate::ast::node::{
|
|||||||
Class, CompilationUnit, Function, FunctionBody, Identifier, Interface,
|
Class, CompilationUnit, Function, FunctionBody, Identifier, Interface,
|
||||||
InterfaceDefaultFunction, InterfaceDefaultOperatorFunction, InterfaceFunction,
|
InterfaceDefaultFunction, InterfaceDefaultOperatorFunction, InterfaceFunction,
|
||||||
InterfaceOperatorFunction, Member, Module, Namespace, OperatorFunction, PlatformFunction,
|
InterfaceOperatorFunction, Member, Module, Namespace, OperatorFunction, PlatformFunction,
|
||||||
PlatformOperatorFunction, Statement, UseStatement, UseStatementSuffix, VariableDeclaration,
|
PlatformOperatorFunction, UseStatement, UseStatementSuffix, VariableDeclaration, VariableUse,
|
||||||
};
|
};
|
||||||
use crate::diagnostic::DmDiagnostic;
|
use crate::diagnostic::DmDiagnostic;
|
||||||
use crate::name_analysis::fqn_context::FqnContext;
|
use crate::name_analysis::fqn_context::FqnContext;
|
||||||
@ -18,6 +18,7 @@ use crate::name_analysis::symbol::use_symbol::{ConcreteUseSymbol, StarUseSymbol}
|
|||||||
use crate::name_analysis::symbol::variable_symbol::VariableSymbol;
|
use crate::name_analysis::symbol::variable_symbol::VariableSymbol;
|
||||||
use crate::name_analysis::symbol_table::{SymbolInsertError, SymbolTable};
|
use crate::name_analysis::symbol_table::{SymbolInsertError, SymbolTable};
|
||||||
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::range::Range;
|
use std::range::Range;
|
||||||
|
|
||||||
fn handle_insert_error(
|
fn handle_insert_error(
|
||||||
@ -56,10 +57,11 @@ fn gather_node_children(
|
|||||||
node: &impl AstNode,
|
node: &impl AstNode,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
for child in node.children() {
|
for child in node.children() {
|
||||||
gather_node(child, symbol_table, fqn_context, diagnostics);
|
gather_node(child, symbol_table, fqn_context, scope_ids, diagnostics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ fn gather_node(
|
|||||||
node: AstNodeRef,
|
node: AstNodeRef,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
match node {
|
match node {
|
||||||
@ -97,7 +100,13 @@ fn gather_node(
|
|||||||
AstNodeRef::Parameter(_) => {}
|
AstNodeRef::Parameter(_) => {}
|
||||||
AstNodeRef::ReturnType(_) => {}
|
AstNodeRef::ReturnType(_) => {}
|
||||||
AstNodeRef::CompilationUnit(compilation_unit) => {
|
AstNodeRef::CompilationUnit(compilation_unit) => {
|
||||||
gather_node_children(compilation_unit, symbol_table, fqn_context, diagnostics);
|
gather_node_children(
|
||||||
|
compilation_unit,
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::Namespace(namespace) => {
|
AstNodeRef::Namespace(namespace) => {
|
||||||
gather_namespace(namespace, fqn_context);
|
gather_namespace(namespace, fqn_context);
|
||||||
@ -119,6 +128,7 @@ fn gather_node(
|
|||||||
module_level_declaration,
|
module_level_declaration,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -127,6 +137,7 @@ fn gather_node(
|
|||||||
interface_level_declaration,
|
interface_level_declaration,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -135,43 +146,64 @@ fn gather_node(
|
|||||||
class_level_declaration,
|
class_level_declaration,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::Module(module) => {
|
AstNodeRef::Module(module) => {
|
||||||
gather_module(module, symbol_table, fqn_context, diagnostics);
|
gather_module(module, symbol_table, fqn_context, scope_ids, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::Interface(interface) => {
|
AstNodeRef::Interface(interface) => {
|
||||||
gather_interface(interface, symbol_table, fqn_context, diagnostics);
|
gather_interface(interface, symbol_table, fqn_context, scope_ids, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::Class(class) => {
|
AstNodeRef::Class(class) => {
|
||||||
gather_class(class, symbol_table, fqn_context, diagnostics);
|
gather_class(class, symbol_table, fqn_context, scope_ids, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::Function(function) => {
|
AstNodeRef::Function(function) => {
|
||||||
gather_function(function, symbol_table, fqn_context, diagnostics);
|
gather_function(function, symbol_table, fqn_context, scope_ids, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::OperatorFunction(operator_function) => {
|
AstNodeRef::OperatorFunction(operator_function) => {
|
||||||
gather_operator_function(operator_function, symbol_table, fqn_context, diagnostics);
|
gather_operator_function(
|
||||||
|
operator_function,
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::PlatformFunction(platform_function) => {
|
AstNodeRef::PlatformFunction(platform_function) => {
|
||||||
gather_platform_function(platform_function, symbol_table, fqn_context, diagnostics);
|
gather_platform_function(
|
||||||
|
platform_function,
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::PlatformOperatorFunction(platform_operator_function) => {
|
AstNodeRef::PlatformOperatorFunction(platform_operator_function) => {
|
||||||
gather_platform_operator_function(
|
gather_platform_operator_function(
|
||||||
platform_operator_function,
|
platform_operator_function,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::InterfaceFunction(interface_function) => {
|
AstNodeRef::InterfaceFunction(interface_function) => {
|
||||||
gather_interface_function(interface_function, symbol_table, fqn_context, diagnostics);
|
gather_interface_function(
|
||||||
|
interface_function,
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::InterfaceDefaultFunction(interface_default_function) => {
|
AstNodeRef::InterfaceDefaultFunction(interface_default_function) => {
|
||||||
gather_interface_default_function(
|
gather_interface_default_function(
|
||||||
interface_default_function,
|
interface_default_function,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -180,6 +212,7 @@ fn gather_node(
|
|||||||
interface_operator_function,
|
interface_operator_function,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -188,35 +221,61 @@ fn gather_node(
|
|||||||
interface_default_operator_function,
|
interface_default_operator_function,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::FunctionBody(function_body) => {
|
AstNodeRef::FunctionBody(function_body) => {
|
||||||
gather_function_body(function_body, symbol_table, fqn_context, diagnostics);
|
gather_function_body(
|
||||||
|
function_body,
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::FunctionEqualsBody(function_equals_body) => {
|
AstNodeRef::FunctionEqualsBody(function_equals_body) => {
|
||||||
gather_node_children(function_equals_body, symbol_table, fqn_context, diagnostics);
|
gather_node_children(
|
||||||
|
function_equals_body,
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::FunctionAliasBody(_) => {
|
AstNodeRef::FunctionAliasBody(_) => {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
AstNodeRef::FunctionBlockBody(function_block_body) => {
|
AstNodeRef::FunctionBlockBody(function_block_body) => {
|
||||||
gather_node_children(function_block_body, symbol_table, fqn_context, diagnostics);
|
gather_node_children(
|
||||||
|
function_block_body,
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::ClassConstructor(class_constructor) => {
|
AstNodeRef::ClassConstructor(class_constructor) => {
|
||||||
gather_node_children(class_constructor, symbol_table, fqn_context, diagnostics);
|
gather_node_children(
|
||||||
|
class_constructor,
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
AstNodeRef::Member(member) => {
|
AstNodeRef::Member(member) => {
|
||||||
gather_member(member, symbol_table, fqn_context, diagnostics);
|
gather_member(member, symbol_table, fqn_context, scope_ids, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::Statement(statement) => {
|
AstNodeRef::Statement(statement) => {
|
||||||
gather_node_children(statement, symbol_table, fqn_context, diagnostics);
|
gather_node_children(statement, symbol_table, fqn_context, scope_ids, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::VariableDeclaration(variable_declaration) => {
|
AstNodeRef::VariableDeclaration(variable_declaration) => {
|
||||||
gather_variable_declaration(
|
gather_variable_declaration(
|
||||||
variable_declaration,
|
variable_declaration,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -228,9 +287,11 @@ fn gather_node(
|
|||||||
AstNodeRef::IfElse(_) => {}
|
AstNodeRef::IfElse(_) => {}
|
||||||
AstNodeRef::WhileStatement(_) => {}
|
AstNodeRef::WhileStatement(_) => {}
|
||||||
AstNodeRef::ForStatement(_) => {}
|
AstNodeRef::ForStatement(_) => {}
|
||||||
AstNodeRef::LValue(_) => {},
|
AstNodeRef::LValue(_) => {}
|
||||||
AstNodeRef::LValueSuffix(_) => {},
|
AstNodeRef::LValueSuffix(_) => {}
|
||||||
AstNodeRef::VariableUse(_) => {},
|
AstNodeRef::VariableUse(variable_use) => {
|
||||||
|
gather_variable_use(variable_use, symbol_table, scope_ids);
|
||||||
|
}
|
||||||
AstNodeRef::Expression(_) => {}
|
AstNodeRef::Expression(_) => {}
|
||||||
AstNodeRef::TernaryExpression(_) => {}
|
AstNodeRef::TernaryExpression(_) => {}
|
||||||
AstNodeRef::TernaryRhs(_) => {}
|
AstNodeRef::TernaryRhs(_) => {}
|
||||||
@ -276,6 +337,7 @@ pub fn gather_compilation_unit(
|
|||||||
compilation_unit: &mut CompilationUnit,
|
compilation_unit: &mut CompilationUnit,
|
||||||
file_name: &str,
|
file_name: &str,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let mut fqn_context = FqnContext::new();
|
let mut fqn_context = FqnContext::new();
|
||||||
@ -284,6 +346,7 @@ pub fn gather_compilation_unit(
|
|||||||
compilation_unit.as_node_ref(),
|
compilation_unit.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
&mut fqn_context,
|
&mut fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -362,6 +425,7 @@ fn gather_module(
|
|||||||
module: &Module,
|
module: &Module,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let module_symbol = ModuleSymbol::new(
|
let module_symbol = ModuleSymbol::new(
|
||||||
@ -389,6 +453,7 @@ fn gather_module(
|
|||||||
declaration.as_node_ref(),
|
declaration.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -401,6 +466,7 @@ fn gather_interface(
|
|||||||
interface: &Interface,
|
interface: &Interface,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let type_symbol = ConcreteTypeSymbol::new(
|
let type_symbol = ConcreteTypeSymbol::new(
|
||||||
@ -431,6 +497,7 @@ fn gather_interface(
|
|||||||
declaration.as_node_ref(),
|
declaration.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -443,6 +510,7 @@ fn gather_class(
|
|||||||
class: &Class,
|
class: &Class,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let class_symbol = ConcreteTypeSymbol::new(
|
let class_symbol = ConcreteTypeSymbol::new(
|
||||||
@ -472,6 +540,7 @@ fn gather_class(
|
|||||||
class.class_constructor().as_node_ref(),
|
class.class_constructor().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
for declaration in class.class_level_declarations() {
|
for declaration in class.class_level_declarations() {
|
||||||
@ -479,6 +548,7 @@ fn gather_class(
|
|||||||
declaration.as_node_ref(),
|
declaration.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -491,6 +561,7 @@ fn gather_function(
|
|||||||
function: &Function,
|
function: &Function,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
||||||
@ -515,24 +586,28 @@ fn gather_function(
|
|||||||
function.generics().as_node_ref(),
|
function.generics().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
function.parameters().as_node_ref(),
|
function.parameters().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
function.return_type().as_node_ref(),
|
function.return_type().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
function.function_body().as_node_ref(),
|
function.function_body().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -542,6 +617,7 @@ fn gather_operator_function(
|
|||||||
operator_function: &OperatorFunction,
|
operator_function: &OperatorFunction,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
||||||
@ -571,24 +647,28 @@ fn gather_operator_function(
|
|||||||
operator_function.generics().as_node_ref(),
|
operator_function.generics().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
operator_function.parameters().as_node_ref(),
|
operator_function.parameters().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
operator_function.return_type().as_node_ref(),
|
operator_function.return_type().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
operator_function.function_body().as_node_ref(),
|
operator_function.function_body().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -598,6 +678,7 @@ fn gather_platform_function(
|
|||||||
platform_function: &PlatformFunction,
|
platform_function: &PlatformFunction,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
||||||
@ -627,18 +708,21 @@ fn gather_platform_function(
|
|||||||
platform_function.generics().as_node_ref(),
|
platform_function.generics().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
platform_function.parameters().as_node_ref(),
|
platform_function.parameters().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
platform_function.return_type().as_node_ref(),
|
platform_function.return_type().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -648,6 +732,7 @@ fn gather_platform_operator_function(
|
|||||||
platform_operator_function: &PlatformOperatorFunction,
|
platform_operator_function: &PlatformOperatorFunction,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
||||||
@ -677,18 +762,21 @@ fn gather_platform_operator_function(
|
|||||||
platform_operator_function.generics().as_node_ref(),
|
platform_operator_function.generics().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
platform_operator_function.parameters().as_node_ref(),
|
platform_operator_function.parameters().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
platform_operator_function.return_type().as_node_ref(),
|
platform_operator_function.return_type().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -698,6 +786,7 @@ fn gather_interface_function(
|
|||||||
interface_function: &InterfaceFunction,
|
interface_function: &InterfaceFunction,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
||||||
@ -727,18 +816,21 @@ fn gather_interface_function(
|
|||||||
interface_function.generics().as_node_ref(),
|
interface_function.generics().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
interface_function.parameters().as_node_ref(),
|
interface_function.parameters().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
interface_function.return_type().as_node_ref(),
|
interface_function.return_type().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -748,6 +840,7 @@ fn gather_interface_default_function(
|
|||||||
interface_default_function: &InterfaceDefaultFunction,
|
interface_default_function: &InterfaceDefaultFunction,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
||||||
@ -777,24 +870,28 @@ fn gather_interface_default_function(
|
|||||||
interface_default_function.generics().as_node_ref(),
|
interface_default_function.generics().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
interface_default_function.parameters().as_node_ref(),
|
interface_default_function.parameters().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
interface_default_function.return_type().as_node_ref(),
|
interface_default_function.return_type().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
interface_default_function.function_body().as_node_ref(),
|
interface_default_function.function_body().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -804,6 +901,7 @@ fn gather_interface_operator_function(
|
|||||||
interface_operator_function: &InterfaceOperatorFunction,
|
interface_operator_function: &InterfaceOperatorFunction,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
||||||
@ -833,18 +931,21 @@ fn gather_interface_operator_function(
|
|||||||
interface_operator_function.generics().as_node_ref(),
|
interface_operator_function.generics().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
interface_operator_function.parameters().as_node_ref(),
|
interface_operator_function.parameters().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
interface_operator_function.return_type().as_node_ref(),
|
interface_operator_function.return_type().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -854,6 +955,7 @@ fn gather_interface_default_operator_function(
|
|||||||
interface_default_operator_function: &InterfaceDefaultOperatorFunction,
|
interface_default_operator_function: &InterfaceDefaultOperatorFunction,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
||||||
@ -897,6 +999,7 @@ fn gather_interface_default_operator_function(
|
|||||||
interface_default_operator_function.generics().as_node_ref(),
|
interface_default_operator_function.generics().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
@ -905,6 +1008,7 @@ fn gather_interface_default_operator_function(
|
|||||||
.as_node_ref(),
|
.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
@ -913,6 +1017,7 @@ fn gather_interface_default_operator_function(
|
|||||||
.as_node_ref(),
|
.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
gather_node(
|
gather_node(
|
||||||
@ -921,6 +1026,7 @@ fn gather_interface_default_operator_function(
|
|||||||
.as_node_ref(),
|
.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
@ -930,35 +1036,17 @@ fn gather_function_body(
|
|||||||
function_body: &FunctionBody,
|
function_body: &FunctionBody,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
symbol_table.push_scope("FunctionBodyScope");
|
symbol_table.push_scope("FunctionBodyScope");
|
||||||
match function_body {
|
gather_node_children(
|
||||||
FunctionBody::FunctionAliasBody(alias_body) => {
|
function_body,
|
||||||
gather_node(
|
symbol_table,
|
||||||
alias_body.as_node_ref(),
|
fqn_context,
|
||||||
symbol_table,
|
scope_ids,
|
||||||
fqn_context,
|
diagnostics,
|
||||||
diagnostics,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
FunctionBody::FunctionEqualsBody(equals_body) => {
|
|
||||||
gather_node(
|
|
||||||
equals_body.as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
FunctionBody::FunctionBlockBody(block_body) => {
|
|
||||||
gather_node(
|
|
||||||
block_body.as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -966,6 +1054,7 @@ fn gather_member(
|
|||||||
member: &Member,
|
member: &Member,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let member_symbol = ClassMemberSymbol::new(
|
let member_symbol = ClassMemberSymbol::new(
|
||||||
@ -988,6 +1077,7 @@ fn gather_member(
|
|||||||
member.type_use().as_node_ref(),
|
member.type_use().as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -996,6 +1086,7 @@ fn gather_variable_declaration(
|
|||||||
variable_declaration: &VariableDeclaration,
|
variable_declaration: &VariableDeclaration,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
fqn_context: &mut FqnContext,
|
fqn_context: &mut FqnContext,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let variable_symbol = VariableSymbol::new(
|
let variable_symbol = VariableSymbol::new(
|
||||||
@ -1020,7 +1111,16 @@ fn gather_variable_declaration(
|
|||||||
expression.as_node_ref(),
|
expression.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
|
scope_ids,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gather_variable_use(
|
||||||
|
variable_use: &VariableUse,
|
||||||
|
symbol_table: &mut SymbolTable,
|
||||||
|
scope_ids: &mut HashMap<VariableUse, usize>,
|
||||||
|
) {
|
||||||
|
scope_ids.insert(variable_use.clone(), symbol_table.current_scope_id());
|
||||||
|
}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ The resolve phase has one main responsibility: resolve all references based on t
|
|||||||
`scope_id` property.
|
`scope_id` property.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::ast::node::{CompilationUnit, Identifier};
|
use crate::ast::node::{CompilationUnit, VariableUse};
|
||||||
use crate::diagnostic::DmDiagnostic;
|
use crate::diagnostic::DmDiagnostic;
|
||||||
use crate::name_analysis::gather::gather_compilation_unit;
|
use crate::name_analysis::gather::gather_compilation_unit;
|
||||||
// use crate::name_analysis::resolve::resolve_compilation_unit;
|
// use crate::name_analysis::resolve::resolve_compilation_unit;
|
||||||
@ -39,12 +39,18 @@ pub fn analyze_names<'a, F: Files<'a, FileId = usize, Name = String>>(
|
|||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
) -> Vec<DmDiagnostic> {
|
) -> Vec<DmDiagnostic> {
|
||||||
let mut diagnostics = vec![];
|
let mut diagnostics = vec![];
|
||||||
let mut identifier_scope_ids: HashMap<Identifier, usize> = HashMap::new();
|
let mut scope_ids: HashMap<VariableUse, usize> = HashMap::new();
|
||||||
|
|
||||||
// gather symbols
|
// gather symbols
|
||||||
for compilation_unit in compilation_units.iter_mut() {
|
for compilation_unit in compilation_units.iter_mut() {
|
||||||
let file_name = files.name(compilation_unit.file_id()).unwrap();
|
let file_name = files.name(compilation_unit.file_id()).unwrap();
|
||||||
gather_compilation_unit(compilation_unit, &file_name, symbol_table, &mut diagnostics);
|
gather_compilation_unit(
|
||||||
|
compilation_unit,
|
||||||
|
&file_name,
|
||||||
|
symbol_table,
|
||||||
|
&mut scope_ids,
|
||||||
|
&mut diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve symbols
|
// resolve symbols
|
||||||
|
|||||||
@ -730,6 +730,11 @@ VariableUse:
|
|||||||
struct:
|
struct:
|
||||||
children:
|
children:
|
||||||
- identifier
|
- identifier
|
||||||
|
derive:
|
||||||
|
- Clone
|
||||||
|
- PartialEq
|
||||||
|
- Eq
|
||||||
|
- Hash
|
||||||
|
|
||||||
# Expressions
|
# Expressions
|
||||||
Expression:
|
Expression:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user