Compare commits
No commits in common. "f0772fbf11d2ec5dff1411f331392b89a8da3540" and "d5ac6dfc2d2a1319371b193e5b6e75c4077ac781" have entirely different histories.
f0772fbf11
...
d5ac6dfc2d
@ -151,15 +151,5 @@ pub fn deserialize_struct_spec(name: &str, struct_yaml: &Yaml) -> StructSpec {
|
|||||||
} else {
|
} else {
|
||||||
deserialize_error!("array", "children", name);
|
deserialize_error!("array", "children", name);
|
||||||
};
|
};
|
||||||
let derive = if struct_yaml["derive"].is_array() {
|
StructSpec::new(name, children)
|
||||||
struct_yaml["derive"].as_vec()
|
|
||||||
.unwrap()
|
|
||||||
.iter()
|
|
||||||
.map(|derive| derive.as_str().unwrap().to_string())
|
|
||||||
.collect()
|
|
||||||
} else {
|
|
||||||
vec![]
|
|
||||||
};
|
|
||||||
|
|
||||||
StructSpec::new(name, children, derive)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,13 @@
|
|||||||
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>>, derive: Vec<String>) -> Self {
|
pub fn new(build: &str, children: Vec<Box<StructChild>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
build: build.to_string(),
|
build: build.to_string(),
|
||||||
children,
|
children,
|
||||||
derive,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,10 +20,6 @@ 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,30 +205,10 @@ pub fn make_struct_type(build_spec: &StructSpec) -> TokenStream {
|
|||||||
.map(Option::unwrap)
|
.map(Option::unwrap)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let struct_stream = {
|
|
||||||
let base = quote! {
|
|
||||||
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! {
|
quote! {
|
||||||
#struct_stream
|
pub struct #type_ident {
|
||||||
|
#(#annotated_members),*
|
||||||
|
}
|
||||||
|
|
||||||
impl #type_ident {
|
impl #type_ident {
|
||||||
pub fn new(#(#annotated_members),*) -> Self {
|
pub fn new(#(#annotated_members),*) -> Self {
|
||||||
|
|||||||
@ -1,36 +1,6 @@
|
|||||||
pub mod node {
|
pub mod node {
|
||||||
include!(concat!(env!("OUT_DIR"), "/src/ast/node.rs"));
|
include!(concat!(env!("OUT_DIR"), "/src/ast/node.rs"));
|
||||||
|
|
||||||
impl OperatorInner {
|
|
||||||
pub fn name(&self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
OperatorInner::Or => "op_or",
|
|
||||||
OperatorInner::And => "op_and",
|
|
||||||
OperatorInner::EqualTo => "op_eq",
|
|
||||||
OperatorInner::NotEqualTo => "op_neq",
|
|
||||||
OperatorInner::Greater => "op_gt",
|
|
||||||
OperatorInner::Less => "op_lt",
|
|
||||||
OperatorInner::GreaterEqual => "op_ge",
|
|
||||||
OperatorInner::LessEqual => "op_le",
|
|
||||||
OperatorInner::Add => "op_add",
|
|
||||||
OperatorInner::Subtract => "op_sub",
|
|
||||||
OperatorInner::Multiply => "op_mul",
|
|
||||||
OperatorInner::Divide => "op_div",
|
|
||||||
OperatorInner::Modulo => "op_mod",
|
|
||||||
OperatorInner::LeftShift => "op_ls",
|
|
||||||
OperatorInner::RightShift => "op_rs",
|
|
||||||
OperatorInner::Spread => "op_spread",
|
|
||||||
OperatorInner::Star => "op_star",
|
|
||||||
OperatorInner::Not => "op_not",
|
|
||||||
OperatorInner::Negative => "op_neg",
|
|
||||||
OperatorInner::PlusPlus => "op_pp",
|
|
||||||
OperatorInner::MinusMinus => "op_mm",
|
|
||||||
OperatorInner::CallOp => "op_call",
|
|
||||||
OperatorInner::Index => "op_index",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Parameters {
|
impl Default for Parameters {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new(vec![])
|
Self::new(vec![])
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
use crate::ast::ast_node::{AstNode, AstNodeRef};
|
use crate::ast::ast_node::{AstNode, AstNodeRef};
|
||||||
use crate::ast::node::{
|
use crate::ast::node::{
|
||||||
Class, CompilationUnit, Function, FunctionBody, Identifier, Interface,
|
Class, CompilationUnit, Function, FunctionBlockBody, FunctionBody, Identifier, Interface,
|
||||||
InterfaceDefaultFunction, InterfaceDefaultOperatorFunction, InterfaceFunction,
|
Module, Namespace, Statement, UseStatement, UseStatementSuffix, VariableDeclaration,
|
||||||
InterfaceOperatorFunction, Member, Module, Namespace, OperatorFunction, PlatformFunction,
|
|
||||||
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;
|
||||||
use crate::name_analysis::symbol::class_member_symbol::ClassMemberSymbol;
|
|
||||||
use crate::name_analysis::symbol::function_symbol::FunctionSymbol;
|
use crate::name_analysis::symbol::function_symbol::FunctionSymbol;
|
||||||
use crate::name_analysis::symbol::module_symbol::ModuleSymbol;
|
use crate::name_analysis::symbol::module_symbol::ModuleSymbol;
|
||||||
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
||||||
@ -18,7 +15,6 @@ 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(
|
||||||
@ -57,11 +53,10 @@ 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, scope_ids, diagnostics);
|
gather_node(child, symbol_table, fqn_context, diagnostics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,18 +64,12 @@ 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 {
|
||||||
AstNodeRef::Operator(_) => {
|
AstNodeRef::Operator(_) => {}
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
AstNodeRef::OperatorInner(_) => {
|
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
AstNodeRef::Identifier(_) => {
|
AstNodeRef::Identifier(_) => {
|
||||||
unreachable!();
|
unreachable!()
|
||||||
}
|
}
|
||||||
AstNodeRef::FullyQualifiedName(_) => {}
|
AstNodeRef::FullyQualifiedName(_) => {}
|
||||||
AstNodeRef::TypeUseList(_) => {}
|
AstNodeRef::TypeUseList(_) => {}
|
||||||
@ -100,13 +89,7 @@ fn gather_node(
|
|||||||
AstNodeRef::Parameter(_) => {}
|
AstNodeRef::Parameter(_) => {}
|
||||||
AstNodeRef::ReturnType(_) => {}
|
AstNodeRef::ReturnType(_) => {}
|
||||||
AstNodeRef::CompilationUnit(compilation_unit) => {
|
AstNodeRef::CompilationUnit(compilation_unit) => {
|
||||||
gather_node_children(
|
gather_node_children(compilation_unit, symbol_table, fqn_context, diagnostics);
|
||||||
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);
|
||||||
@ -115,20 +98,19 @@ fn gather_node(
|
|||||||
gather_use_statement(use_statement, symbol_table, diagnostics);
|
gather_use_statement(use_statement, symbol_table, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::UseStatementPrefix(_) => {
|
AstNodeRef::UseStatementPrefix(_) => {
|
||||||
unreachable!();
|
unreachable!()
|
||||||
}
|
}
|
||||||
AstNodeRef::UseStatementSuffix(_) => {
|
AstNodeRef::UseStatementSuffix(_) => {
|
||||||
unreachable!();
|
unreachable!()
|
||||||
}
|
}
|
||||||
AstNodeRef::UseList(_) => {
|
AstNodeRef::UseList(_) => {
|
||||||
unreachable!();
|
unreachable!()
|
||||||
}
|
}
|
||||||
AstNodeRef::ModuleLevelDeclaration(module_level_declaration) => {
|
AstNodeRef::ModuleLevelDeclaration(module_level_declaration) => {
|
||||||
gather_node_children(
|
gather_node_children(
|
||||||
module_level_declaration,
|
module_level_declaration,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -137,7 +119,6 @@ fn gather_node(
|
|||||||
interface_level_declaration,
|
interface_level_declaration,
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -146,139 +127,77 @@ 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, scope_ids, diagnostics);
|
gather_module(module, symbol_table, fqn_context, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::Interface(interface) => {
|
AstNodeRef::Interface(interface) => {
|
||||||
gather_interface(interface, symbol_table, fqn_context, scope_ids, diagnostics);
|
gather_interface(interface, symbol_table, fqn_context, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::Class(class) => {
|
AstNodeRef::Class(class) => {
|
||||||
gather_class(class, symbol_table, fqn_context, scope_ids, diagnostics);
|
gather_class(class, symbol_table, fqn_context, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::Function(function) => {
|
AstNodeRef::Function(function) => {
|
||||||
gather_function(function, symbol_table, fqn_context, scope_ids, diagnostics);
|
gather_function(function, symbol_table, fqn_context, diagnostics);
|
||||||
}
|
}
|
||||||
AstNodeRef::OperatorFunction(operator_function) => {
|
AstNodeRef::OperatorFunction(_) => {}
|
||||||
gather_operator_function(
|
AstNodeRef::PlatformFunction(_) => {}
|
||||||
operator_function,
|
AstNodeRef::InterfaceFunction(_) => {}
|
||||||
symbol_table,
|
AstNodeRef::InterfaceDefaultFunction(_) => {}
|
||||||
fqn_context,
|
AstNodeRef::InterfaceOperatorFunction(_) => {}
|
||||||
scope_ids,
|
AstNodeRef::InterfaceDefaultOperatorFunction(_) => {}
|
||||||
diagnostics,
|
AstNodeRef::FunctionBody(function_body) => match function_body {
|
||||||
);
|
FunctionBody::FunctionAliasBody(alias_body) => {
|
||||||
}
|
gather_node(
|
||||||
AstNodeRef::PlatformFunction(platform_function) => {
|
alias_body.as_node_ref(),
|
||||||
gather_platform_function(
|
symbol_table,
|
||||||
platform_function,
|
fqn_context,
|
||||||
symbol_table,
|
diagnostics,
|
||||||
fqn_context,
|
);
|
||||||
scope_ids,
|
}
|
||||||
diagnostics,
|
FunctionBody::FunctionEqualsBody(equals_body) => {
|
||||||
);
|
gather_node(
|
||||||
}
|
equals_body.as_node_ref(),
|
||||||
AstNodeRef::PlatformOperatorFunction(platform_operator_function) => {
|
symbol_table,
|
||||||
gather_platform_operator_function(
|
fqn_context,
|
||||||
platform_operator_function,
|
diagnostics,
|
||||||
symbol_table,
|
);
|
||||||
fqn_context,
|
}
|
||||||
scope_ids,
|
FunctionBody::FunctionBlockBody(block_body) => {
|
||||||
diagnostics,
|
gather_node(
|
||||||
);
|
block_body.as_node_ref(),
|
||||||
}
|
symbol_table,
|
||||||
AstNodeRef::InterfaceFunction(interface_function) => {
|
fqn_context,
|
||||||
gather_interface_function(
|
diagnostics,
|
||||||
interface_function,
|
);
|
||||||
symbol_table,
|
}
|
||||||
fqn_context,
|
},
|
||||||
scope_ids,
|
AstNodeRef::FunctionEqualsBody(_) => {}
|
||||||
diagnostics,
|
AstNodeRef::FunctionAliasBody(_) => {}
|
||||||
);
|
AstNodeRef::FunctionBlockBody(block_body) => {
|
||||||
}
|
gather_function_block_body(block_body, symbol_table, fqn_context, diagnostics);
|
||||||
AstNodeRef::InterfaceDefaultFunction(interface_default_function) => {
|
|
||||||
gather_interface_default_function(
|
|
||||||
interface_default_function,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AstNodeRef::InterfaceOperatorFunction(interface_operator_function) => {
|
|
||||||
gather_interface_operator_function(
|
|
||||||
interface_operator_function,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AstNodeRef::InterfaceDefaultOperatorFunction(interface_default_operator_function) => {
|
|
||||||
gather_interface_default_operator_function(
|
|
||||||
interface_default_operator_function,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AstNodeRef::FunctionBody(function_body) => {
|
|
||||||
gather_function_body(
|
|
||||||
function_body,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AstNodeRef::FunctionEqualsBody(function_equals_body) => {
|
|
||||||
gather_node_children(
|
|
||||||
function_equals_body,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AstNodeRef::FunctionAliasBody(_) => {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
AstNodeRef::FunctionBlockBody(function_block_body) => {
|
|
||||||
gather_node_children(
|
|
||||||
function_block_body,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AstNodeRef::ClassConstructor(class_constructor) => {
|
|
||||||
gather_node_children(
|
|
||||||
class_constructor,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AstNodeRef::Member(member) => {
|
|
||||||
gather_member(member, symbol_table, fqn_context, scope_ids, diagnostics);
|
|
||||||
}
|
|
||||||
AstNodeRef::Statement(statement) => {
|
|
||||||
gather_node_children(statement, symbol_table, fqn_context, scope_ids, diagnostics);
|
|
||||||
}
|
|
||||||
AstNodeRef::VariableDeclaration(variable_declaration) => {
|
|
||||||
gather_variable_declaration(
|
|
||||||
variable_declaration,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
AstNodeRef::ClassConstructor(_) => {}
|
||||||
|
AstNodeRef::Member(_) => {}
|
||||||
|
AstNodeRef::Statement(statement) => match statement {
|
||||||
|
Statement::VariableDeclaration(variable_declaration) => {
|
||||||
|
gather_node(
|
||||||
|
variable_declaration.as_node_ref(),
|
||||||
|
symbol_table,
|
||||||
|
fqn_context,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Statement::AssignmentStatement(_) => {}
|
||||||
|
Statement::ExpressionStatement(_) => {}
|
||||||
|
Statement::UseStatement(_) => {}
|
||||||
|
Statement::IfStatement(_) => {}
|
||||||
|
Statement::WhileStatement(_) => {}
|
||||||
|
Statement::ForStatement(_) => {}
|
||||||
|
},
|
||||||
|
AstNodeRef::VariableDeclaration(_) => {}
|
||||||
AstNodeRef::AssignmentStatement(_) => {}
|
AstNodeRef::AssignmentStatement(_) => {}
|
||||||
AstNodeRef::ExpressionStatement(_) => {}
|
AstNodeRef::ExpressionStatement(_) => {}
|
||||||
AstNodeRef::IfStatement(_) => {}
|
AstNodeRef::IfStatement(_) => {}
|
||||||
@ -287,11 +206,6 @@ fn gather_node(
|
|||||||
AstNodeRef::IfElse(_) => {}
|
AstNodeRef::IfElse(_) => {}
|
||||||
AstNodeRef::WhileStatement(_) => {}
|
AstNodeRef::WhileStatement(_) => {}
|
||||||
AstNodeRef::ForStatement(_) => {}
|
AstNodeRef::ForStatement(_) => {}
|
||||||
AstNodeRef::LValue(_) => {}
|
|
||||||
AstNodeRef::LValueSuffix(_) => {}
|
|
||||||
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(_) => {}
|
||||||
@ -337,7 +251,6 @@ 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();
|
||||||
@ -346,7 +259,6 @@ 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();
|
||||||
@ -425,7 +337,6 @@ 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(
|
||||||
@ -453,7 +364,6 @@ fn gather_module(
|
|||||||
declaration.as_node_ref(),
|
declaration.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -466,7 +376,6 @@ 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(
|
||||||
@ -497,7 +406,6 @@ fn gather_interface(
|
|||||||
declaration.as_node_ref(),
|
declaration.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -510,7 +418,6 @@ 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(
|
||||||
@ -536,19 +443,11 @@ fn gather_class(
|
|||||||
fqn_context.push(class.identifier().name());
|
fqn_context.push(class.identifier().name());
|
||||||
symbol_table.push_scope(&format!("ClassScope {}", class.identifier().name()));
|
symbol_table.push_scope(&format!("ClassScope {}", class.identifier().name()));
|
||||||
|
|
||||||
gather_node(
|
|
||||||
class.class_constructor().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
for declaration in class.class_level_declarations() {
|
for declaration in class.class_level_declarations() {
|
||||||
gather_node(
|
gather_node(
|
||||||
declaration.as_node_ref(),
|
declaration.as_node_ref(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
fqn_context,
|
fqn_context,
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -561,7 +460,6 @@ 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(
|
||||||
@ -581,512 +479,29 @@ fn gather_function(
|
|||||||
diagnostics,
|
diagnostics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
symbol_table.push_scope(&format!("FunctionScope {}", function.identifier().name()));
|
|
||||||
gather_node(
|
|
||||||
function.generics().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
function.parameters().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
function.return_type().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gather_operator_function(
|
fn gather_function_block_body(
|
||||||
operator_function: &OperatorFunction,
|
function_block_body: &FunctionBlockBody,
|
||||||
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(
|
symbol_table.push_scope("FunctionBlockBody");
|
||||||
&fqn_context.resolve(&operator_function.operator().inner().name()),
|
gather_node_children(function_block_body, symbol_table, fqn_context, diagnostics);
|
||||||
operator_function.operator().inner().name(),
|
|
||||||
operator_function.is_public(),
|
|
||||||
false,
|
|
||||||
Some(SourceDefinition::from_operator(
|
|
||||||
operator_function.operator(),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
if let Err(insert_error) = symbol_table.insert_function_symbol(function_symbol) {
|
|
||||||
handle_insert_error(
|
|
||||||
insert_error,
|
|
||||||
operator_function.operator().inner().name(),
|
|
||||||
operator_function.operator().file_id(),
|
|
||||||
operator_function.operator().range(),
|
|
||||||
"Operator",
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
symbol_table.push_scope(&format!(
|
|
||||||
"FunctionScope {}",
|
|
||||||
operator_function.operator().inner().name()
|
|
||||||
));
|
|
||||||
gather_node(
|
|
||||||
operator_function.generics().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
operator_function.parameters().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
operator_function.return_type().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
operator_function.function_body().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gather_platform_function(
|
|
||||||
platform_function: &PlatformFunction,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
fqn_context: &mut FqnContext,
|
|
||||||
scope_ids: &mut HashMap<VariableUse, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
|
||||||
&fqn_context.resolve(platform_function.identifier().name()),
|
|
||||||
platform_function.identifier().name(),
|
|
||||||
platform_function.is_public(),
|
|
||||||
true,
|
|
||||||
Some(SourceDefinition::from_identifier(
|
|
||||||
platform_function.identifier(),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
if let Err(insert_error) = symbol_table.insert_function_symbol(function_symbol) {
|
|
||||||
handle_insert_error(
|
|
||||||
insert_error,
|
|
||||||
platform_function.identifier().name(),
|
|
||||||
platform_function.identifier().file_id(),
|
|
||||||
platform_function.identifier().range(),
|
|
||||||
"Function",
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
symbol_table.push_scope(&format!(
|
|
||||||
"PlatformFunctionScope {}",
|
|
||||||
platform_function.identifier().name()
|
|
||||||
));
|
|
||||||
gather_node(
|
|
||||||
platform_function.generics().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
platform_function.parameters().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
platform_function.return_type().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
symbol_table.pop_scope();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_platform_operator_function(
|
|
||||||
platform_operator_function: &PlatformOperatorFunction,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
fqn_context: &mut FqnContext,
|
|
||||||
scope_ids: &mut HashMap<VariableUse, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
|
||||||
&fqn_context.resolve(platform_operator_function.operator().inner().name()),
|
|
||||||
platform_operator_function.operator().inner().name(),
|
|
||||||
platform_operator_function.is_public(),
|
|
||||||
true,
|
|
||||||
Some(SourceDefinition::from_operator(
|
|
||||||
platform_operator_function.operator(),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
if let Err(insert_error) = symbol_table.insert_function_symbol(function_symbol) {
|
|
||||||
handle_insert_error(
|
|
||||||
insert_error,
|
|
||||||
platform_operator_function.operator().inner().name(),
|
|
||||||
platform_operator_function.operator().file_id(),
|
|
||||||
platform_operator_function.operator().range(),
|
|
||||||
"Function",
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
symbol_table.push_scope(&format!(
|
|
||||||
"PlatformOperatorFunctionScope {}",
|
|
||||||
platform_operator_function.operator().inner().name()
|
|
||||||
));
|
|
||||||
gather_node(
|
|
||||||
platform_operator_function.generics().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
platform_operator_function.parameters().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
platform_operator_function.return_type().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
symbol_table.pop_scope();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_interface_function(
|
|
||||||
interface_function: &InterfaceFunction,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
fqn_context: &mut FqnContext,
|
|
||||||
scope_ids: &mut HashMap<VariableUse, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
|
||||||
&fqn_context.resolve(interface_function.identifier().name()),
|
|
||||||
interface_function.identifier().name(),
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
Some(SourceDefinition::from_identifier(
|
|
||||||
interface_function.identifier(),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
if let Err(insert_error) = symbol_table.insert_function_symbol(function_symbol) {
|
|
||||||
handle_insert_error(
|
|
||||||
insert_error,
|
|
||||||
interface_function.identifier().name(),
|
|
||||||
interface_function.identifier().file_id(),
|
|
||||||
interface_function.identifier().range(),
|
|
||||||
"Type",
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
symbol_table.push_scope(&format!(
|
|
||||||
"InterfaceFunctionScope {}",
|
|
||||||
interface_function.identifier().name()
|
|
||||||
));
|
|
||||||
gather_node(
|
|
||||||
interface_function.generics().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_function.parameters().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_function.return_type().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
symbol_table.pop_scope();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_interface_default_function(
|
|
||||||
interface_default_function: &InterfaceDefaultFunction,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
fqn_context: &mut FqnContext,
|
|
||||||
scope_ids: &mut HashMap<VariableUse, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
|
||||||
&fqn_context.resolve(interface_default_function.identifier().name()),
|
|
||||||
interface_default_function.identifier().name(),
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
Some(SourceDefinition::from_identifier(
|
|
||||||
interface_default_function.identifier(),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
if let Err(insert_error) = symbol_table.insert_function_symbol(function_symbol) {
|
|
||||||
handle_insert_error(
|
|
||||||
insert_error,
|
|
||||||
interface_default_function.identifier().name(),
|
|
||||||
interface_default_function.identifier().file_id(),
|
|
||||||
interface_default_function.identifier().range(),
|
|
||||||
"Function",
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
symbol_table.push_scope(&format!(
|
|
||||||
"InterfaceDefaultFunctionScope {}",
|
|
||||||
interface_default_function.identifier().name()
|
|
||||||
));
|
|
||||||
gather_node(
|
|
||||||
interface_default_function.generics().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_default_function.parameters().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_default_function.return_type().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_default_function.function_body().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
symbol_table.pop_scope();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_interface_operator_function(
|
|
||||||
interface_operator_function: &InterfaceOperatorFunction,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
fqn_context: &mut FqnContext,
|
|
||||||
scope_ids: &mut HashMap<VariableUse, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
|
||||||
&fqn_context.resolve(interface_operator_function.operator().inner().name()),
|
|
||||||
interface_operator_function.operator().inner().name(),
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
Some(SourceDefinition::from_operator(
|
|
||||||
interface_operator_function.operator(),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
if let Err(insert_error) = symbol_table.insert_function_symbol(function_symbol) {
|
|
||||||
handle_insert_error(
|
|
||||||
insert_error,
|
|
||||||
interface_operator_function.operator().inner().name(),
|
|
||||||
interface_operator_function.operator().file_id(),
|
|
||||||
interface_operator_function.operator().range(),
|
|
||||||
"Function",
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
symbol_table.push_scope(&format!(
|
|
||||||
"InterfaceOperatorFunctionScope {}",
|
|
||||||
interface_operator_function.operator().inner().name()
|
|
||||||
));
|
|
||||||
gather_node(
|
|
||||||
interface_operator_function.generics().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_operator_function.parameters().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_operator_function.return_type().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
symbol_table.pop_scope();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_interface_default_operator_function(
|
|
||||||
interface_default_operator_function: &InterfaceDefaultOperatorFunction,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
fqn_context: &mut FqnContext,
|
|
||||||
scope_ids: &mut HashMap<VariableUse, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
let function_symbol = FunctionSymbol::without_parameters_or_return_type(
|
|
||||||
&fqn_context.resolve(
|
|
||||||
interface_default_operator_function
|
|
||||||
.operator()
|
|
||||||
.inner()
|
|
||||||
.name(),
|
|
||||||
),
|
|
||||||
interface_default_operator_function
|
|
||||||
.operator()
|
|
||||||
.inner()
|
|
||||||
.name(),
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
Some(SourceDefinition::from_operator(
|
|
||||||
interface_default_operator_function.operator(),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
if let Err(insert_error) = symbol_table.insert_function_symbol(function_symbol) {
|
|
||||||
handle_insert_error(
|
|
||||||
insert_error,
|
|
||||||
interface_default_operator_function
|
|
||||||
.operator()
|
|
||||||
.inner()
|
|
||||||
.name(),
|
|
||||||
interface_default_operator_function.operator().file_id(),
|
|
||||||
interface_default_operator_function.operator().range(),
|
|
||||||
"Function",
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
symbol_table.push_scope(&format!(
|
|
||||||
"InterfaceDefaultOperatorFunctionScope {}",
|
|
||||||
interface_default_operator_function
|
|
||||||
.operator()
|
|
||||||
.inner()
|
|
||||||
.name()
|
|
||||||
));
|
|
||||||
gather_node(
|
|
||||||
interface_default_operator_function.generics().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_default_operator_function
|
|
||||||
.parameters()
|
|
||||||
.as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_default_operator_function
|
|
||||||
.return_type()
|
|
||||||
.as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
gather_node(
|
|
||||||
interface_default_operator_function
|
|
||||||
.function_body()
|
|
||||||
.as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
symbol_table.pop_scope();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_function_body(
|
|
||||||
function_body: &FunctionBody,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
fqn_context: &mut FqnContext,
|
|
||||||
scope_ids: &mut HashMap<VariableUse, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
symbol_table.push_scope("FunctionBodyScope");
|
|
||||||
gather_node_children(
|
|
||||||
function_body,
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
symbol_table.pop_scope();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_member(
|
|
||||||
member: &Member,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
fqn_context: &mut FqnContext,
|
|
||||||
scope_ids: &mut HashMap<VariableUse, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
let member_symbol = ClassMemberSymbol::new(
|
|
||||||
member.is_public(),
|
|
||||||
member.is_mut(),
|
|
||||||
member.identifier().name(),
|
|
||||||
Some(SourceDefinition::from_identifier(member.identifier())),
|
|
||||||
);
|
|
||||||
if let Err(insert_error) = symbol_table.insert_class_member_symbol(member_symbol) {
|
|
||||||
handle_insert_error(
|
|
||||||
insert_error,
|
|
||||||
member.identifier().name(),
|
|
||||||
member.identifier().file_id(),
|
|
||||||
member.identifier().range(),
|
|
||||||
"Class Member",
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
gather_node(
|
|
||||||
member.type_use().as_node_ref(),
|
|
||||||
symbol_table,
|
|
||||||
fqn_context,
|
|
||||||
scope_ids,
|
|
||||||
diagnostics,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_variable_declaration(
|
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(
|
||||||
@ -1111,16 +526,7 @@ 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, VariableUse};
|
use crate::ast::node::{CompilationUnit, Identifier};
|
||||||
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,18 +39,12 @@ 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 scope_ids: HashMap<VariableUse, usize> = HashMap::new();
|
let mut identifier_scope_ids: HashMap<Identifier, 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(
|
gather_compilation_unit(compilation_unit, &file_name, symbol_table, &mut diagnostics);
|
||||||
compilation_unit,
|
|
||||||
&file_name,
|
|
||||||
symbol_table,
|
|
||||||
&mut scope_ids,
|
|
||||||
&mut diagnostics,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve symbols
|
// resolve symbols
|
||||||
|
|||||||
@ -3,39 +3,32 @@ use std::fmt::{Debug, Formatter};
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ClassMemberSymbol {
|
pub struct ClassMemberSymbol {
|
||||||
is_public: bool,
|
|
||||||
is_mut: bool,
|
|
||||||
declared_name: String,
|
declared_name: String,
|
||||||
|
is_field: bool,
|
||||||
source_definition: Option<SourceDefinition>,
|
source_definition: Option<SourceDefinition>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClassMemberSymbol {
|
impl ClassMemberSymbol {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
is_public: bool,
|
|
||||||
is_mut: bool,
|
|
||||||
declared_name: &str,
|
declared_name: &str,
|
||||||
|
is_field: bool,
|
||||||
source_definition: Option<SourceDefinition>,
|
source_definition: Option<SourceDefinition>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_public,
|
|
||||||
is_mut,
|
|
||||||
declared_name: declared_name.to_string(),
|
declared_name: declared_name.to_string(),
|
||||||
|
is_field,
|
||||||
source_definition,
|
source_definition,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_public(&self) -> bool {
|
|
||||||
self.is_public
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_mut(&self) -> bool {
|
|
||||||
self.is_mut
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn declared_name(&self) -> &str {
|
pub fn declared_name(&self) -> &str {
|
||||||
&self.declared_name
|
&self.declared_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_field(&self) -> bool {
|
||||||
|
self.is_field
|
||||||
|
}
|
||||||
|
|
||||||
pub fn source_definition(&self) -> Option<&SourceDefinition> {
|
pub fn source_definition(&self) -> Option<&SourceDefinition> {
|
||||||
self.source_definition.as_ref()
|
self.source_definition.as_ref()
|
||||||
}
|
}
|
||||||
@ -44,9 +37,8 @@ impl ClassMemberSymbol {
|
|||||||
impl Debug for ClassMemberSymbol {
|
impl Debug for ClassMemberSymbol {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("ClassMemberSymbol")
|
f.debug_struct("ClassMemberSymbol")
|
||||||
.field("is_public", &self.is_public)
|
|
||||||
.field("is_mut", &self.is_mut)
|
|
||||||
.field("declared_name", &self.declared_name)
|
.field("declared_name", &self.declared_name)
|
||||||
|
.field("is_field", &self.is_field)
|
||||||
.field("source_definition", &self.source_definition)
|
.field("source_definition", &self.source_definition)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::range::Range;
|
use std::range::Range;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::ast::node::{Identifier, Operator, UseStatement};
|
use crate::ast::node::{Identifier, UseStatement};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SourceDefinition {
|
pub struct SourceDefinition {
|
||||||
@ -17,6 +17,14 @@ impl SourceDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_identifier_rc(identifier: Rc<RefCell<Identifier>>) -> Self {
|
||||||
|
let borrowed = identifier.borrow();
|
||||||
|
SourceDefinition {
|
||||||
|
file_id: borrowed.file_id(),
|
||||||
|
range: borrowed.range(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_use_statement(use_statement: &UseStatement) -> Self {
|
pub fn from_use_statement(use_statement: &UseStatement) -> Self {
|
||||||
Self {
|
Self {
|
||||||
file_id: use_statement.file_id(),
|
file_id: use_statement.file_id(),
|
||||||
@ -24,13 +32,6 @@ impl SourceDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_operator(operator: &Operator) -> Self {
|
|
||||||
Self {
|
|
||||||
file_id: operator.file_id(),
|
|
||||||
range: operator.range(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn file_id(&self) -> usize {
|
pub fn file_id(&self) -> usize {
|
||||||
self.file_id
|
self.file_id
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,11 +57,11 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn current_scope(&self) -> &Scope {
|
fn current_scope(&self) -> &Scope {
|
||||||
&self.scopes[self.current_scope_id]
|
self.scopes.last().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_scope_mut(&mut self) -> &mut Scope {
|
fn current_scope_mut(&mut self) -> &mut Scope {
|
||||||
&mut self.scopes[self.current_scope_id]
|
self.scopes.last_mut().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_current_scope_concrete_use_symbol(
|
fn find_current_scope_concrete_use_symbol(
|
||||||
|
|||||||
@ -127,13 +127,7 @@ macro_rules! write_symbols {
|
|||||||
|
|
||||||
impl Display for Scope {
|
impl Display for Scope {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
writeln!(
|
writeln!(f, "----Scope {} {}----", self.id(), self.debug_name())?;
|
||||||
f,
|
|
||||||
"----Scope {} (p: {}) {}----",
|
|
||||||
self.id(),
|
|
||||||
self.parent().map(|parent_id| format!("{}", parent_id)).unwrap_or_else(|| "None".to_string()),
|
|
||||||
self.debug_name()
|
|
||||||
)?;
|
|
||||||
write_symbols!(f, self.concrete_use_symbols());
|
write_symbols!(f, self.concrete_use_symbols());
|
||||||
write_symbols!(f, self.star_use_symbols());
|
write_symbols!(f, self.star_use_symbols());
|
||||||
write_symbols!(f, self.module_symbols());
|
write_symbols!(f, self.module_symbols());
|
||||||
|
|||||||
@ -1,18 +1,6 @@
|
|||||||
# $schema: ./ast.schema.yaml
|
# $schema: ./ast.schema.yaml
|
||||||
# Operators
|
# Operators
|
||||||
Operator:
|
Operator:
|
||||||
struct:
|
|
||||||
children:
|
|
||||||
- inner:
|
|
||||||
member:
|
|
||||||
rule: OperatorInner
|
|
||||||
- file_id:
|
|
||||||
special:
|
|
||||||
kind: file_id
|
|
||||||
- range:
|
|
||||||
special:
|
|
||||||
kind: range
|
|
||||||
OperatorInner:
|
|
||||||
leaf_enum:
|
leaf_enum:
|
||||||
rules:
|
rules:
|
||||||
- Or
|
- Or
|
||||||
@ -441,30 +429,6 @@ PlatformFunction:
|
|||||||
- identifier
|
- identifier
|
||||||
- parameters
|
- parameters
|
||||||
- return_type
|
- return_type
|
||||||
PlatformOperatorFunction:
|
|
||||||
struct:
|
|
||||||
children:
|
|
||||||
- is_public:
|
|
||||||
member:
|
|
||||||
rule: Pub
|
|
||||||
build:
|
|
||||||
boolean:
|
|
||||||
on: rule_present
|
|
||||||
- platform_kw:
|
|
||||||
skip:
|
|
||||||
rule: Platform
|
|
||||||
- op_kw:
|
|
||||||
skip:
|
|
||||||
rule: Op
|
|
||||||
- generics:
|
|
||||||
member:
|
|
||||||
rule: GenericParameters
|
|
||||||
build:
|
|
||||||
node:
|
|
||||||
or_else_default: true
|
|
||||||
- operator
|
|
||||||
- parameters
|
|
||||||
- return_type
|
|
||||||
InterfaceFunction:
|
InterfaceFunction:
|
||||||
struct:
|
struct:
|
||||||
children:
|
children:
|
||||||
@ -628,8 +592,12 @@ VariableDeclaration:
|
|||||||
AssignmentStatement:
|
AssignmentStatement:
|
||||||
struct:
|
struct:
|
||||||
children:
|
children:
|
||||||
- l_value
|
- left:
|
||||||
- expression
|
member:
|
||||||
|
rule: Expression
|
||||||
|
- right:
|
||||||
|
member:
|
||||||
|
rule: Expression
|
||||||
ExpressionStatement:
|
ExpressionStatement:
|
||||||
struct:
|
struct:
|
||||||
children:
|
children:
|
||||||
@ -711,31 +679,6 @@ ForStatement:
|
|||||||
skip:
|
skip:
|
||||||
rule: End
|
rule: End
|
||||||
|
|
||||||
# LValue
|
|
||||||
LValue:
|
|
||||||
struct:
|
|
||||||
children:
|
|
||||||
- variable_use
|
|
||||||
- suffixes:
|
|
||||||
vec:
|
|
||||||
rule: LValueSuffix
|
|
||||||
LValueSuffix:
|
|
||||||
tree_enum:
|
|
||||||
rules:
|
|
||||||
- ObjectProperty
|
|
||||||
- ObjectIndex
|
|
||||||
|
|
||||||
# VariableUse
|
|
||||||
VariableUse:
|
|
||||||
struct:
|
|
||||||
children:
|
|
||||||
- identifier
|
|
||||||
derive:
|
|
||||||
- Clone
|
|
||||||
- PartialEq
|
|
||||||
- Eq
|
|
||||||
- Hash
|
|
||||||
|
|
||||||
# Expressions
|
# Expressions
|
||||||
Expression:
|
Expression:
|
||||||
polymorphic_type:
|
polymorphic_type:
|
||||||
@ -770,9 +713,6 @@ Expression:
|
|||||||
- Literal:
|
- Literal:
|
||||||
inner:
|
inner:
|
||||||
kind: Literal
|
kind: Literal
|
||||||
- VariableUse:
|
|
||||||
inner:
|
|
||||||
kind: VariableUse
|
|
||||||
- Fqn:
|
- Fqn:
|
||||||
inner:
|
inner:
|
||||||
kind: FullyQualifiedName
|
kind: FullyQualifiedName
|
||||||
@ -1115,9 +1055,6 @@ PrimaryExpression:
|
|||||||
- Literal:
|
- Literal:
|
||||||
inner:
|
inner:
|
||||||
kind: Literal
|
kind: Literal
|
||||||
- VariableUse:
|
|
||||||
inner:
|
|
||||||
kind: VariableUse
|
|
||||||
- Fqn:
|
- Fqn:
|
||||||
inner:
|
inner:
|
||||||
kind: FullyQualifiedName
|
kind: FullyQualifiedName
|
||||||
|
|||||||
@ -131,10 +131,6 @@ Index = { "[]" }
|
|||||||
BorrowMut = { Borrow ~ Mut }
|
BorrowMut = { Borrow ~ Mut }
|
||||||
|
|
||||||
Operator = {
|
Operator = {
|
||||||
OperatorInner
|
|
||||||
}
|
|
||||||
|
|
||||||
OperatorInner = {
|
|
||||||
Or
|
Or
|
||||||
| And
|
| And
|
||||||
| EqualTo
|
| EqualTo
|
||||||
@ -435,16 +431,6 @@ PlatformFunction = {
|
|||||||
~ ReturnType
|
~ ReturnType
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformOperatorFunction = {
|
|
||||||
Pub?
|
|
||||||
~ Platform
|
|
||||||
~ Op
|
|
||||||
~ GenericParameters?
|
|
||||||
~ Operator
|
|
||||||
~ Parameters
|
|
||||||
~ ReturnType
|
|
||||||
}
|
|
||||||
|
|
||||||
InterfaceFunction = {
|
InterfaceFunction = {
|
||||||
Fn
|
Fn
|
||||||
~ GenericParameters?
|
~ GenericParameters?
|
||||||
@ -542,7 +528,7 @@ VariableDeclaration = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AssignmentStatement = {
|
AssignmentStatement = {
|
||||||
LValue
|
Expression
|
||||||
~ "="
|
~ "="
|
||||||
~ Expression
|
~ Expression
|
||||||
}
|
}
|
||||||
@ -593,24 +579,6 @@ ForStatement = {
|
|||||||
~ End
|
~ End
|
||||||
}
|
}
|
||||||
|
|
||||||
// LValue
|
|
||||||
|
|
||||||
LValue = {
|
|
||||||
VariableUse
|
|
||||||
~ LValueSuffix*
|
|
||||||
}
|
|
||||||
|
|
||||||
LValueSuffix = {
|
|
||||||
ObjectProperty
|
|
||||||
| ObjectIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
// Variable Use
|
|
||||||
|
|
||||||
VariableUse = {
|
|
||||||
Identifier
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
|
|
||||||
Expression = {
|
Expression = {
|
||||||
@ -759,7 +727,6 @@ ObjectIndex = {
|
|||||||
|
|
||||||
PrimaryExpression = {
|
PrimaryExpression = {
|
||||||
Literal
|
Literal
|
||||||
| VariableUse
|
|
||||||
| FullyQualifiedName
|
| FullyQualifiedName
|
||||||
| Closure
|
| Closure
|
||||||
| ListExpression
|
| ListExpression
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user