Compare commits
No commits in common. "e578250ee652b5f00f71700464070edd0484cefd" and "eaebf8c926df80f64f3930d69e1532c6a635addc" have entirely different histories.
e578250ee6
...
eaebf8c926
@ -36,7 +36,6 @@ pub fn make_struct_ast_node_impl(spec: &StructSpec) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MemberChildBuild::Boolean(_) => None,
|
MemberChildBuild::Boolean(_) => None,
|
||||||
MemberChildBuild::Special(_) => None,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.filter(Option::is_some)
|
.filter(Option::is_some)
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
use crate::deserialize::util::{make_build_fn_name, make_build_pair};
|
use crate::deserialize::util::{make_build_fn_name, make_build_pair};
|
||||||
use crate::spec::struct_spec::{MemberChildBuild, NodeMemberBuild, SpecialMemberBuild, StructChild, StructSpec, VecChild, VecChildBuild};
|
use crate::spec::struct_spec::{
|
||||||
use proc_macro2::{Ident, TokenStream};
|
MemberChildBuild, NodeMemberBuild, StructChild, StructSpec, VecChild, VecChildBuild,
|
||||||
|
};
|
||||||
|
use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
fn make_vec_child_holder(vec_child: &VecChild) -> TokenStream {
|
fn make_vec_child_holder(vec_child: &VecChild) -> TokenStream {
|
||||||
@ -44,7 +46,6 @@ fn make_child_holder(child_spec: &StructChild) -> Option<TokenStream> {
|
|||||||
Some(make_node_child_holder(member_child.name(), node_child))
|
Some(make_node_child_holder(member_child.name(), node_child))
|
||||||
}
|
}
|
||||||
MemberChildBuild::Boolean(_) => Some(make_boolean_child_holder(member_child.name())),
|
MemberChildBuild::Boolean(_) => Some(make_boolean_child_holder(member_child.name())),
|
||||||
MemberChildBuild::Special(_) => None,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,37 +83,32 @@ fn make_boolean_member_child_match_action(name: &str) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_rule_matcher(child_spec: &StructChild) -> Option<TokenStream> {
|
fn make_match_action(child_spec: &StructChild) -> TokenStream {
|
||||||
match child_spec {
|
match child_spec {
|
||||||
StructChild::SkipChild(_) => None,
|
StructChild::SkipChild(_) => quote! {},
|
||||||
StructChild::VecChild(vec_child) => {
|
StructChild::VecChild(vec_child) => make_vec_child_match_action(vec_child),
|
||||||
let rule_ident = format_ident!("{}", vec_child.rule());
|
StructChild::MemberChild(member_child) => match member_child.build() {
|
||||||
let action = make_vec_child_match_action(vec_child);
|
MemberChildBuild::Node(node_child) => {
|
||||||
Some(quote! {
|
make_node_member_child_match_action(member_child.name(), node_child)
|
||||||
Rule::#rule_ident => { #action }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
StructChild::MemberChild(member_child) => {
|
|
||||||
match member_child.build() {
|
|
||||||
MemberChildBuild::Node(node_member_build) => {
|
|
||||||
let rule_ident = format_ident!("{}", member_child.rule());
|
|
||||||
let action = make_node_member_child_match_action(
|
|
||||||
member_child.name(),
|
|
||||||
node_member_build
|
|
||||||
);
|
|
||||||
Some(quote! {
|
|
||||||
Rule::#rule_ident => { #action }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
MemberChildBuild::Boolean(_) => {
|
|
||||||
let rule_ident = format_ident!("{}", member_child.rule());
|
|
||||||
let action = make_boolean_member_child_match_action(member_child.name());
|
|
||||||
Some(quote! {
|
|
||||||
Rule::#rule_ident => { #action }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
MemberChildBuild::Special(_) => None
|
|
||||||
}
|
}
|
||||||
|
MemberChildBuild::Boolean(_) => {
|
||||||
|
make_boolean_member_child_match_action(member_child.name())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_rule_matcher(child_spec: &StructChild) -> TokenStream {
|
||||||
|
let rule_ident = match child_spec {
|
||||||
|
StructChild::SkipChild(skip_child) => format_ident!("{}", skip_child.rule()),
|
||||||
|
StructChild::VecChild(vec_child) => format_ident!("{}", vec_child.rule()),
|
||||||
|
StructChild::MemberChild(single_child) => format_ident!("{}", single_child.rule()),
|
||||||
|
};
|
||||||
|
let action = make_match_action(child_spec);
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
Rule::#rule_ident => {
|
||||||
|
#action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +142,7 @@ fn make_boolean_member_child_arg(name: &str) -> TokenStream {
|
|||||||
quote! { #child_ident }
|
quote! { #child_ident }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_child_arg(child_spec: &StructChild, pair_ident: &Ident) -> Option<TokenStream> {
|
fn make_child_arg(child_spec: &StructChild) -> Option<TokenStream> {
|
||||||
match child_spec {
|
match child_spec {
|
||||||
StructChild::SkipChild(_) => None,
|
StructChild::SkipChild(_) => None,
|
||||||
StructChild::VecChild(vec_child) => Some(make_vec_child_arg(vec_child)),
|
StructChild::VecChild(vec_child) => Some(make_vec_child_arg(vec_child)),
|
||||||
@ -158,31 +154,16 @@ fn make_child_arg(child_spec: &StructChild, pair_ident: &Ident) -> Option<TokenS
|
|||||||
)),
|
)),
|
||||||
MemberChildBuild::Boolean(_) => {
|
MemberChildBuild::Boolean(_) => {
|
||||||
Some(make_boolean_member_child_arg(member_child.name()))
|
Some(make_boolean_member_child_arg(member_child.name()))
|
||||||
},
|
}
|
||||||
MemberChildBuild::Special(special_member_build) => {
|
|
||||||
match special_member_build {
|
|
||||||
SpecialMemberBuild::FileId => {
|
|
||||||
Some(quote! { file_id })
|
|
||||||
}
|
|
||||||
SpecialMemberBuild::Range => {
|
|
||||||
Some(quote! {
|
|
||||||
Range {
|
|
||||||
start: #pair_ident.as_span().start(),
|
|
||||||
end: #pair_ident.as_span().end(),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_return_value_stream(build_spec: &StructSpec, pair_ident: &Ident) -> TokenStream {
|
fn make_return_value_stream(build_spec: &StructSpec) -> TokenStream {
|
||||||
let type_ident = format_ident!("{}", build_spec.build());
|
let type_ident = format_ident!("{}", build_spec.build());
|
||||||
let child_args = build_spec
|
let child_args = build_spec
|
||||||
.children()
|
.children()
|
||||||
.map(|child| make_child_arg(child, pair_ident))
|
.map(|child| make_child_arg(child))
|
||||||
.filter(|child_arg| child_arg.is_some())
|
.filter(|child_arg| child_arg.is_some())
|
||||||
.map(|child_arg| child_arg.unwrap())
|
.map(|child_arg| child_arg.unwrap())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@ -220,7 +201,7 @@ pub fn make_struct_build_fn(build_spec: &StructSpec) -> TokenStream {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_stream = make_return_value_stream(build_spec, &pair_ident);
|
let new_stream = make_return_value_stream(build_spec);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
fn #build_fn_ident(file_id: usize, #pair_ident: Pair<Rule>) -> #return_type_ident {
|
fn #build_fn_ident(file_id: usize, #pair_ident: Pair<Rule>) -> #return_type_ident {
|
||||||
|
|||||||
@ -12,12 +12,22 @@ fn deserialize_skip_child(props: &Yaml) -> StructChild {
|
|||||||
|
|
||||||
fn deserialize_vec_child(child_name: &str, props: &Yaml) -> StructChild {
|
fn deserialize_vec_child(child_name: &str, props: &Yaml) -> StructChild {
|
||||||
let rule = props["rule"].as_str().unwrap();
|
let rule = props["rule"].as_str().unwrap();
|
||||||
let kind = props["kind"].as_str().unwrap_or(rule);
|
let kind = props["kind"].as_str()
|
||||||
|
.unwrap_or(rule);
|
||||||
if kind == "string" {
|
if kind == "string" {
|
||||||
let build = VecChildBuild::String(VecChildStringBuild::new(&make_build_fn_name(rule)));
|
let build = VecChildBuild::String(VecChildStringBuild::new(
|
||||||
StructChild::VecChild(VecChild::new(child_name, rule, Box::new(build)))
|
&make_build_fn_name(rule)
|
||||||
|
));
|
||||||
|
StructChild::VecChild(VecChild::new(
|
||||||
|
child_name,
|
||||||
|
rule,
|
||||||
|
Box::new(build),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
let build = VecChildBuild::Node(VecChildNodeBuild::new(rule, &make_build_fn_name(rule)));
|
let build = VecChildBuild::Node(VecChildNodeBuild::new(
|
||||||
|
rule,
|
||||||
|
&make_build_fn_name(rule)
|
||||||
|
));
|
||||||
StructChild::VecChild(VecChild::new(child_name, rule, Box::new(build)))
|
StructChild::VecChild(VecChild::new(child_name, rule, Box::new(build)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,15 +66,9 @@ fn deserialize_member_build(child_name: &str, rule: &str, props: &Yaml) -> Membe
|
|||||||
} else {
|
} else {
|
||||||
panic!("Expected 'on' in 'boolean' in 'build' in {}", child_name);
|
panic!("Expected 'on' in 'boolean' in 'build' in {}", child_name);
|
||||||
}
|
}
|
||||||
} else if props["special"].is_hash() {
|
|
||||||
match props["special"]["kind"].as_str().unwrap() {
|
|
||||||
"file_id" => MemberChildBuild::Special(SpecialMemberBuild::FileId),
|
|
||||||
"range" => MemberChildBuild::Special(SpecialMemberBuild::Range),
|
|
||||||
_ => panic!(),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
"Expected one of 'node', 'boolean', or 'special' in 'build' in {}",
|
"Expected either of 'node' or 'boolean' in 'build' in {}",
|
||||||
child_name
|
child_name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -231,7 +231,6 @@ fn make_struct_p2_impl(struct_build_spec: &StructSpec) -> TokenStream {
|
|||||||
writer.writeln_indented(&format!(#format_string, self.#child_ident()))?;
|
writer.writeln_indented(&format!(#format_string, self.#child_ident()))?;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
MemberChildBuild::Special(_) => None
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.filter(Option::is_some)
|
.filter(Option::is_some)
|
||||||
|
|||||||
@ -48,7 +48,7 @@ impl SkipChild {
|
|||||||
pub struct VecChild {
|
pub struct VecChild {
|
||||||
name: String,
|
name: String,
|
||||||
rule: String,
|
rule: String,
|
||||||
build: Box<VecChildBuild>,
|
build: Box<VecChildBuild>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VecChild {
|
impl VecChild {
|
||||||
@ -56,7 +56,7 @@ impl VecChild {
|
|||||||
Self {
|
Self {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
rule: rule.to_string(),
|
rule: rule.to_string(),
|
||||||
build,
|
build
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ impl VecChild {
|
|||||||
pub fn rule(&self) -> &str {
|
pub fn rule(&self) -> &str {
|
||||||
&self.rule
|
&self.rule
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(&self) -> &VecChildBuild {
|
pub fn build(&self) -> &VecChildBuild {
|
||||||
&self.build
|
&self.build
|
||||||
}
|
}
|
||||||
@ -77,20 +77,18 @@ impl VecChild {
|
|||||||
|
|
||||||
pub enum VecChildBuild {
|
pub enum VecChildBuild {
|
||||||
String(VecChildStringBuild),
|
String(VecChildStringBuild),
|
||||||
Node(VecChildNodeBuild),
|
Node(VecChildNodeBuild)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct VecChildStringBuild {
|
pub struct VecChildStringBuild {
|
||||||
with: String,
|
with: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VecChildStringBuild {
|
impl VecChildStringBuild {
|
||||||
pub fn new(with: &str) -> Self {
|
pub fn new(with: &str) -> Self {
|
||||||
Self {
|
Self { with: with.to_string() }
|
||||||
with: with.to_string(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with(&self) -> &str {
|
pub fn with(&self) -> &str {
|
||||||
&self.with
|
&self.with
|
||||||
}
|
}
|
||||||
@ -98,21 +96,21 @@ impl VecChildStringBuild {
|
|||||||
|
|
||||||
pub struct VecChildNodeBuild {
|
pub struct VecChildNodeBuild {
|
||||||
kind: String,
|
kind: String,
|
||||||
with: String,
|
with: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VecChildNodeBuild {
|
impl VecChildNodeBuild {
|
||||||
pub fn new(kind: &str, with: &str) -> Self {
|
pub fn new(kind: &str, with: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
kind: kind.to_string(),
|
kind: kind.to_string(),
|
||||||
with: with.to_string(),
|
with: with.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kind(&self) -> &str {
|
pub fn kind(&self) -> &str {
|
||||||
&self.kind
|
&self.kind
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with(&self) -> &str {
|
pub fn with(&self) -> &str {
|
||||||
&self.with
|
&self.with
|
||||||
}
|
}
|
||||||
@ -160,7 +158,6 @@ impl MemberChild {
|
|||||||
pub enum MemberChildBuild {
|
pub enum MemberChildBuild {
|
||||||
Node(NodeMemberBuild),
|
Node(NodeMemberBuild),
|
||||||
Boolean(BooleanMemberBuild),
|
Boolean(BooleanMemberBuild),
|
||||||
Special(SpecialMemberBuild),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -203,7 +200,7 @@ impl BooleanMemberBuild {
|
|||||||
pub fn new(on: BooleanMemberBuildOn) -> Self {
|
pub fn new(on: BooleanMemberBuildOn) -> Self {
|
||||||
Self { on }
|
Self { on }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on(&self) -> &BooleanMemberBuildOn {
|
pub fn on(&self) -> &BooleanMemberBuildOn {
|
||||||
&self.on
|
&self.on
|
||||||
}
|
}
|
||||||
@ -211,11 +208,5 @@ impl BooleanMemberBuild {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum BooleanMemberBuildOn {
|
pub enum BooleanMemberBuildOn {
|
||||||
RulePresent,
|
RulePresent
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum SpecialMemberBuild {
|
|
||||||
FileId,
|
|
||||||
Range,
|
|
||||||
}
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
use crate::spec::struct_spec::{
|
use crate::spec::struct_spec::{
|
||||||
MemberChild, MemberChildBuild, SpecialMemberBuild, StructChild, StructSpec, VecChild,
|
MemberChild, MemberChildBuild, StructChild, StructSpec, VecChild, VecChildBuild,
|
||||||
VecChildBuild,
|
|
||||||
};
|
};
|
||||||
use proc_macro2::{Ident, TokenStream};
|
use proc_macro2::{Ident, TokenStream};
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
@ -76,22 +75,6 @@ fn make_member_child_accessors(member_child: &MemberChild) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MemberChildBuild::Special(special_member_build) => match special_member_build {
|
|
||||||
SpecialMemberBuild::FileId => {
|
|
||||||
quote! {
|
|
||||||
pub fn file_id(&self) -> usize {
|
|
||||||
self.file_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SpecialMemberBuild::Range => {
|
|
||||||
quote! {
|
|
||||||
pub fn range(&self) -> Range<usize> {
|
|
||||||
self.range
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,10 +118,6 @@ fn make_member_child_type_ident(member_child: &MemberChild) -> TokenStream {
|
|||||||
MemberChildBuild::Boolean(_) => {
|
MemberChildBuild::Boolean(_) => {
|
||||||
quote! { bool }
|
quote! { bool }
|
||||||
}
|
}
|
||||||
MemberChildBuild::Special(special_member_build) => match special_member_build {
|
|
||||||
SpecialMemberBuild::FileId => quote! { usize },
|
|
||||||
SpecialMemberBuild::Range => quote! { Range<usize> },
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,62 +1,25 @@
|
|||||||
use crate::ast::ast_node::{AstNode, AstNodeRef};
|
|
||||||
use crate::ast::node::{CompilationUnit, Identifier, UseStatement, UseStatementSuffix};
|
|
||||||
use crate::diagnostic::DmDiagnostic;
|
|
||||||
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
|
||||||
use crate::name_analysis::symbol::use_symbol::StarUseStatementSymbol;
|
|
||||||
use crate::name_analysis::symbol::UseStatementSymbol;
|
|
||||||
use crate::name_analysis::symbol_table::SymbolTable;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use crate::ast::ast_node::AstNodeRef;
|
||||||
|
use crate::ast::node::{CompilationUnit, Identifier};
|
||||||
|
use crate::ast::walk::walk_depth_first;
|
||||||
|
use crate::diagnostic::DmDiagnostic;
|
||||||
|
use crate::name_analysis::symbol_table::SymbolTable;
|
||||||
|
|
||||||
fn gather_identifier(
|
fn gather_identifier(identifier: &Identifier, symbol_table: &SymbolTable, identifier_scope_ids: &mut HashMap<Identifier, usize>) {
|
||||||
identifier: &Identifier,
|
|
||||||
symbol_table: &SymbolTable,
|
|
||||||
identifier_scope_ids: &mut HashMap<Identifier, usize>,
|
|
||||||
) {
|
|
||||||
identifier_scope_ids.insert(identifier.clone(), symbol_table.current_scope_id());
|
identifier_scope_ids.insert(identifier.clone(), symbol_table.current_scope_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gather_use_statement(
|
pub fn gather_compilation_unit(
|
||||||
use_statement: &UseStatement,
|
compilation_unit: &mut CompilationUnit,
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
|
identifier_scope_ids: &mut HashMap<Identifier, usize>,
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
let mut fully_qualified_name = String::new();
|
walk_depth_first(compilation_unit, &mut |child| match child {
|
||||||
for prefix in use_statement.prefixes() {
|
|
||||||
fully_qualified_name.push_str(&format!("{}::", prefix.identifier().name()));
|
|
||||||
}
|
|
||||||
match use_statement.suffix() {
|
|
||||||
UseStatementSuffix::Identifier(identifier) => {}
|
|
||||||
UseStatementSuffix::Star => {
|
|
||||||
let symbol_inner = StarUseStatementSymbol::new(
|
|
||||||
&fully_qualified_name,
|
|
||||||
Some(SourceDefinition::from_use_statement(use_statement)),
|
|
||||||
);
|
|
||||||
let symbol = UseStatementSymbol::Star(symbol_inner);
|
|
||||||
symbol_table.insert_use_statement_symbol(symbol);
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
UseStatementSuffix::UseList(use_list) => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_node_children(
|
|
||||||
node: &impl AstNode,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
for child in node.children() {
|
|
||||||
gather_node(child, symbol_table, diagnostics);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gather_node(
|
|
||||||
node: AstNodeRef,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
match node {
|
|
||||||
AstNodeRef::Operator(_) => {}
|
AstNodeRef::Operator(_) => {}
|
||||||
AstNodeRef::Identifier(_) => {}
|
AstNodeRef::Identifier(identifier) => {
|
||||||
|
gather_identifier(&identifier, symbol_table, identifier_scope_ids);
|
||||||
|
}
|
||||||
AstNodeRef::FullyQualifiedName(_) => {}
|
AstNodeRef::FullyQualifiedName(_) => {}
|
||||||
AstNodeRef::TypeUseList(_) => {}
|
AstNodeRef::TypeUseList(_) => {}
|
||||||
AstNodeRef::IdentifierList(_) => {}
|
AstNodeRef::IdentifierList(_) => {}
|
||||||
@ -74,13 +37,9 @@ fn gather_node(
|
|||||||
AstNodeRef::Parameters(_) => {}
|
AstNodeRef::Parameters(_) => {}
|
||||||
AstNodeRef::Parameter(_) => {}
|
AstNodeRef::Parameter(_) => {}
|
||||||
AstNodeRef::ReturnType(_) => {}
|
AstNodeRef::ReturnType(_) => {}
|
||||||
AstNodeRef::CompilationUnit(compilation_unit) => {
|
AstNodeRef::CompilationUnit(_) => {}
|
||||||
gather_node_children(compilation_unit, symbol_table, diagnostics);
|
|
||||||
}
|
|
||||||
AstNodeRef::ParentMod(_) => {}
|
AstNodeRef::ParentMod(_) => {}
|
||||||
AstNodeRef::UseStatement(use_statement) => {
|
AstNodeRef::UseStatement(_) => {}
|
||||||
gather_use_statement(use_statement, symbol_table, diagnostics);
|
|
||||||
}
|
|
||||||
AstNodeRef::UseStatementPrefix(_) => {}
|
AstNodeRef::UseStatementPrefix(_) => {}
|
||||||
AstNodeRef::UseStatementSuffix(_) => {}
|
AstNodeRef::UseStatementSuffix(_) => {}
|
||||||
AstNodeRef::UseList(_) => {}
|
AstNodeRef::UseList(_) => {}
|
||||||
@ -152,14 +111,5 @@ fn gather_node(
|
|||||||
AstNodeRef::DString(_) => {}
|
AstNodeRef::DString(_) => {}
|
||||||
AstNodeRef::DStringExpression(_) => {}
|
AstNodeRef::DStringExpression(_) => {}
|
||||||
AstNodeRef::BacktickString(_) => {}
|
AstNodeRef::BacktickString(_) => {}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
pub fn gather_compilation_unit(
|
|
||||||
compilation_unit: &mut CompilationUnit,
|
|
||||||
symbol_table: &mut SymbolTable,
|
|
||||||
identifier_scope_ids: &mut HashMap<Identifier, usize>,
|
|
||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
|
||||||
) {
|
|
||||||
gather_node(compilation_unit.as_node_ref(), symbol_table, diagnostics);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,41 @@
|
|||||||
pub(super) mod source_definition;
|
|
||||||
pub(super) mod use_symbol;
|
|
||||||
|
|
||||||
use crate::ast::node::Identifier;
|
use crate::ast::node::Identifier;
|
||||||
use source_definition::SourceDefinition;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::range::Range;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct SourceDefinition {
|
||||||
|
file_id: usize,
|
||||||
|
range: Range<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SourceDefinition {
|
||||||
|
pub fn from_identifier(identifier: &Identifier) -> Self {
|
||||||
|
SourceDefinition {
|
||||||
|
file_id: identifier.file_id(),
|
||||||
|
range: identifier.range(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 file_id(&self) -> usize {
|
||||||
|
self.file_id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn range(&self) -> Range<usize> {
|
||||||
|
self.range.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait SymbolInner {
|
pub trait SymbolInner {
|
||||||
fn declared_name(&self) -> &str;
|
fn declared_name(&self) -> &str;
|
||||||
fn definition(&self) -> Option<SourceDefinition>;
|
fn definition(&self) -> Option<SourceDefinition>;
|
||||||
@ -1,42 +0,0 @@
|
|||||||
use std::cell::RefCell;
|
|
||||||
use std::range::Range;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use crate::ast::node::{Identifier, UseStatement};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct SourceDefinition {
|
|
||||||
file_id: usize,
|
|
||||||
range: Range<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SourceDefinition {
|
|
||||||
pub fn from_identifier(identifier: &Identifier) -> Self {
|
|
||||||
SourceDefinition {
|
|
||||||
file_id: identifier.file_id(),
|
|
||||||
range: identifier.range(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
Self {
|
|
||||||
file_id: use_statement.file_id(),
|
|
||||||
range: use_statement.range(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn file_id(&self) -> usize {
|
|
||||||
self.file_id
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(&self) -> Range<usize> {
|
|
||||||
self.range.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
|
||||||
|
|
||||||
pub enum UseStatementSymbol {
|
|
||||||
Concrete,
|
|
||||||
Star(StarUseStatementSymbol),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct StarUseStatementSymbol {
|
|
||||||
base_fqn: String,
|
|
||||||
source_definition: Option<SourceDefinition>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StarUseStatementSymbol {
|
|
||||||
pub fn new(base_fqn: &str, source_definition: Option<SourceDefinition>) -> Self {
|
|
||||||
Self {
|
|
||||||
base_fqn: base_fqn.to_string(),
|
|
||||||
source_definition,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn base_fqn(&self) -> &str {
|
|
||||||
&self.base_fqn
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn source_definition(&self) -> Option<&SourceDefinition> {
|
|
||||||
self.source_definition.as_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -148,7 +148,6 @@ $defs:
|
|||||||
oneOf:
|
oneOf:
|
||||||
- $ref: "#/$defs/StructChildMemberBuildNodeHash"
|
- $ref: "#/$defs/StructChildMemberBuildNodeHash"
|
||||||
- $ref: "#/$defs/StructChildMemberBuildBooleanHash"
|
- $ref: "#/$defs/StructChildMemberBuildBooleanHash"
|
||||||
- $ref: "#/$defs/StructChildMemberBuildSpecialHash"
|
|
||||||
StructChildMemberBuildNodeHash:
|
StructChildMemberBuildNodeHash:
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
@ -191,24 +190,6 @@ $defs:
|
|||||||
- rule_present
|
- rule_present
|
||||||
required:
|
required:
|
||||||
- on
|
- on
|
||||||
StructChildMemberBuildSpecialHash:
|
|
||||||
type: object
|
|
||||||
additionalProperties: false
|
|
||||||
description: A special member to be built.
|
|
||||||
properties:
|
|
||||||
special:
|
|
||||||
type: object
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
kind:
|
|
||||||
type: string
|
|
||||||
enum:
|
|
||||||
- file_id
|
|
||||||
- range
|
|
||||||
required:
|
|
||||||
- kind
|
|
||||||
required:
|
|
||||||
- special
|
|
||||||
|
|
||||||
# Leaf Struct Node
|
# Leaf Struct Node
|
||||||
LeafStructNodeDefinition:
|
LeafStructNodeDefinition:
|
||||||
|
|||||||
@ -214,16 +214,6 @@ UseStatement:
|
|||||||
- suffix:
|
- suffix:
|
||||||
member:
|
member:
|
||||||
rule: UseStatementSuffix
|
rule: UseStatementSuffix
|
||||||
- file_id:
|
|
||||||
member:
|
|
||||||
build:
|
|
||||||
special:
|
|
||||||
kind: file_id
|
|
||||||
- range:
|
|
||||||
member:
|
|
||||||
build:
|
|
||||||
special:
|
|
||||||
kind: range
|
|
||||||
UseStatementPrefix:
|
UseStatementPrefix:
|
||||||
struct:
|
struct:
|
||||||
children:
|
children:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user