Fmt all the old code.
This commit is contained in:
parent
b4ebee0c34
commit
19194271aa
@ -1,5 +1,7 @@
|
|||||||
|
use crate::spec::polymorphic_enum_inner_build::{
|
||||||
|
PolymorphicEnumInnerBuild, PolymorphicEnumInnerBuildMemberKind,
|
||||||
|
};
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use crate::spec::polymorphic_enum_inner_build::{PolymorphicEnumInnerBuild, PolymorphicEnumInnerBuildMemberKind};
|
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
@ -8,7 +10,8 @@ pub fn make_polymorphic_enum_inner_build_ast_node_impl(
|
|||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
let type_ident = format_ident!("{}", spec.name());
|
let type_ident = format_ident!("{}", spec.name());
|
||||||
|
|
||||||
let match_arms = spec.members()
|
let match_arms = spec
|
||||||
|
.members()
|
||||||
.map(|member| {
|
.map(|member| {
|
||||||
let member_ident = format_ident!("{}", member.name());
|
let member_ident = format_ident!("{}", member.name());
|
||||||
match member.kind() {
|
match member.kind() {
|
||||||
@ -25,11 +28,12 @@ pub fn make_polymorphic_enum_inner_build_ast_node_impl(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut_match_arms = spec.members()
|
let mut_match_arms = spec
|
||||||
|
.members()
|
||||||
.map(|member| {
|
.map(|member| {
|
||||||
let member_ident = format_ident!("{}", member.name());
|
let member_ident = format_ident!("{}", member.name());
|
||||||
match member.kind() {
|
match member.kind() {
|
||||||
@ -49,7 +53,7 @@ pub fn make_polymorphic_enum_inner_build_ast_node_impl(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl<'a> AstNode<'a> for #type_ident {
|
impl<'a> AstNode<'a> for #type_ident {
|
||||||
fn children(&'a self) -> Vec<&'a dyn AstNode<'a>> {
|
fn children(&'a self) -> Vec<&'a dyn AstNode<'a>> {
|
||||||
|
|||||||
@ -8,11 +8,11 @@ pub fn make_node_production_build_fn(spec: &NodeProductionBuildSpec) -> TokenStr
|
|||||||
let pair_ident = format_ident!("{}", make_build_pair(spec.name()));
|
let pair_ident = format_ident!("{}", make_build_pair(spec.name()));
|
||||||
let return_type_ident = format_ident!("{}", spec.kind());
|
let return_type_ident = format_ident!("{}", spec.kind());
|
||||||
let inner_build_fn_ident = format_ident!("{}", spec.with());
|
let inner_build_fn_ident = format_ident!("{}", spec.with());
|
||||||
|
|
||||||
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 {
|
||||||
let inner_pair = #pair_ident.into_inner().next().unwrap();
|
let inner_pair = #pair_ident.into_inner().next().unwrap();
|
||||||
#inner_build_fn_ident(file_id, inner_pair)
|
#inner_build_fn_ident(file_id, inner_pair)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,15 @@
|
|||||||
|
use crate::deserialize::util::{make_build_fn_name, make_build_pair};
|
||||||
use crate::spec::polymorphic_enum_inner_build::PolymorphicEnumInnerBuild;
|
use crate::spec::polymorphic_enum_inner_build::PolymorphicEnumInnerBuild;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use crate::deserialize::util::{make_build_fn_name, make_build_pair};
|
|
||||||
|
|
||||||
pub fn make_polymorphic_enum_inner_build_build_fn(spec: &PolymorphicEnumInnerBuild) -> TokenStream {
|
pub fn make_polymorphic_enum_inner_build_build_fn(spec: &PolymorphicEnumInnerBuild) -> TokenStream {
|
||||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(spec.name()));
|
let build_fn_ident = format_ident!("{}", make_build_fn_name(spec.name()));
|
||||||
let pair_ident = format_ident!("{}", make_build_pair(spec.name()));
|
let pair_ident = format_ident!("{}", make_build_pair(spec.name()));
|
||||||
let return_type_ident = format_ident!("{}", spec.name());
|
let return_type_ident = format_ident!("{}", spec.name());
|
||||||
|
|
||||||
let rule_branches = spec.rules()
|
let rule_branches = spec
|
||||||
|
.rules()
|
||||||
.map(|rule| {
|
.map(|rule| {
|
||||||
let rule_ident = format_ident!("{}", rule.name());
|
let rule_ident = format_ident!("{}", rule.name());
|
||||||
let rule_build_fn_ident = format_ident!("{}", rule.with());
|
let rule_build_fn_ident = format_ident!("{}", rule.with());
|
||||||
@ -17,7 +18,7 @@ pub fn make_polymorphic_enum_inner_build_build_fn(spec: &PolymorphicEnumInnerBui
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
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 {
|
||||||
let inner_pair = #pair_ident.into_inner().next().unwrap();
|
let inner_pair = #pair_ident.into_inner().next().unwrap();
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
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::SpecialChildKind;
|
||||||
use crate::spec::polymorphic_enum_loop_spec::{
|
use crate::spec::polymorphic_enum_loop_spec::{
|
||||||
PolymorphicEnumLoopBuildSpec, PolymorphicEnumLoopRule, PolymorphicEnumLoopRuleBuild,
|
PolymorphicEnumLoopBuildSpec, PolymorphicEnumLoopRule, PolymorphicEnumLoopRuleBuild,
|
||||||
PolymorphicEnumLoopRuleBuildChild, PolymorphicEnumLoopRuleChildOnEach,
|
PolymorphicEnumLoopRuleBuildChild, PolymorphicEnumLoopRuleChildOnEach,
|
||||||
PolymorphicEnumLoopRulePassThrough,
|
PolymorphicEnumLoopRulePassThrough,
|
||||||
};
|
};
|
||||||
use crate::spec::SpecialChildKind;
|
|
||||||
use proc_macro2::{Ident, TokenStream};
|
use proc_macro2::{Ident, TokenStream};
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
|
|||||||
@ -7,16 +7,17 @@ pub fn make_polymorphic_leaf_enum_build_fn(spec: &PolymorphicLeafEnum) -> TokenS
|
|||||||
let build_fn_ident = format_ident!("build_{}", spec.name().to_case(Case::Snake));
|
let build_fn_ident = format_ident!("build_{}", spec.name().to_case(Case::Snake));
|
||||||
let pair_ident = format_ident!("{}_pair", spec.name().to_case(Case::Snake));
|
let pair_ident = format_ident!("{}_pair", spec.name().to_case(Case::Snake));
|
||||||
let return_type_ident = format_ident!("{}", spec.kind());
|
let return_type_ident = format_ident!("{}", spec.kind());
|
||||||
|
|
||||||
let child_matchers = spec.rules()
|
let child_matchers = spec
|
||||||
|
.rules()
|
||||||
.map(|rule| {
|
.map(|rule| {
|
||||||
let rule_ident = format_ident!("{}", rule);
|
let rule_ident = format_ident!("{}", rule);
|
||||||
quote! {
|
quote! {
|
||||||
Rule::#rule_ident => #return_type_ident::#rule_ident
|
Rule::#rule_ident => #return_type_ident::#rule_ident
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
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 {
|
||||||
let inner_pair = #pair_ident.into_inner().next().unwrap();
|
let inner_pair = #pair_ident.into_inner().next().unwrap();
|
||||||
|
|||||||
@ -15,8 +15,7 @@ pub fn make_enum_build_fn(enum_build_spec: &TreeEnumBuildSpec) -> TokenStream {
|
|||||||
if let Some(child) = enum_rule.child() {
|
if let Some(child) = enum_rule.child() {
|
||||||
let inner_builder = match child.kind() {
|
let inner_builder = match child.kind() {
|
||||||
EnumRuleChildKind::Node(node_child) => {
|
EnumRuleChildKind::Node(node_child) => {
|
||||||
let inner_build_fn_ident =
|
let inner_build_fn_ident = format_ident!("{}", node_child.with());
|
||||||
format_ident!("{}", node_child.with());
|
|
||||||
quote! { #inner_build_fn_ident(file_id, inner_pair) }
|
quote! { #inner_build_fn_ident(file_id, inner_pair) }
|
||||||
}
|
}
|
||||||
EnumRuleChildKind::Int(name_and_with) => {
|
EnumRuleChildKind::Int(name_and_with) => {
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
use yaml_rust2::Yaml;
|
|
||||||
use crate::spec::leaf_enum_spec::LeafEnumBuildSpec;
|
use crate::spec::leaf_enum_spec::LeafEnumBuildSpec;
|
||||||
|
use yaml_rust2::Yaml;
|
||||||
|
|
||||||
pub fn deserialize_leaf_enum(name: &str, props: &Yaml) -> LeafEnumBuildSpec {
|
pub fn deserialize_leaf_enum(name: &str, props: &Yaml) -> LeafEnumBuildSpec {
|
||||||
let rules = props["rules"].as_vec()
|
let rules = props["rules"]
|
||||||
|
.as_vec()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|rule_yaml| {
|
.map(|rule_yaml| rule_yaml.as_str().unwrap().to_string())
|
||||||
rule_yaml.as_str().unwrap().to_string()
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
LeafEnumBuildSpec::new(name, rules)
|
LeafEnumBuildSpec::new(name, rules)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
use crate::deserialize::util::unwrap_single_member_hash;
|
use crate::deserialize::util::unwrap_single_member_hash;
|
||||||
use yaml_rust2::Yaml;
|
|
||||||
use crate::spec::leaf_struct_spec::{LeafStructBuildSpec, LeafStructMember, LeafStructMemberKind};
|
use crate::spec::leaf_struct_spec::{LeafStructBuildSpec, LeafStructMember, LeafStructMemberKind};
|
||||||
|
use yaml_rust2::Yaml;
|
||||||
|
|
||||||
fn deserialize_member(member_name: &str, member_props: &Yaml) -> LeafStructMember {
|
fn deserialize_member(member_name: &str, member_props: &Yaml) -> LeafStructMember {
|
||||||
let kind = match member_props["kind"].as_str().unwrap() {
|
let kind = match member_props["kind"].as_str().unwrap() {
|
||||||
"string" => LeafStructMemberKind::String,
|
"string" => LeafStructMemberKind::String,
|
||||||
"file_id" => LeafStructMemberKind::FileId,
|
"file_id" => LeafStructMemberKind::FileId,
|
||||||
"range" => LeafStructMemberKind::Range,
|
"range" => LeafStructMemberKind::Range,
|
||||||
_ => panic!()
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
LeafStructMember::new(member_name, kind)
|
LeafStructMember::new(member_name, kind)
|
||||||
}
|
}
|
||||||
@ -26,12 +26,12 @@ pub fn deserialize_leaf_struct(name: &str, props: &Yaml) -> LeafStructBuildSpec
|
|||||||
let derive = props["derive"]
|
let derive = props["derive"]
|
||||||
.as_vec()
|
.as_vec()
|
||||||
.map(|derive_yaml| {
|
.map(|derive_yaml| {
|
||||||
derive_yaml.iter()
|
derive_yaml
|
||||||
.map(|trait_yaml| {
|
.iter()
|
||||||
trait_yaml.as_str().unwrap().to_string()
|
.map(|trait_yaml| trait_yaml.as_str().unwrap().to_string())
|
||||||
}).collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
LeafStructBuildSpec::new(name, members, derive)
|
LeafStructBuildSpec::new(name, members, derive)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,13 +19,13 @@ use crate::deserialize::polymorphic_enum_build_inner::deserialize_polymorphic_en
|
|||||||
use crate::deserialize::polymorphic_enum_loop_spec::deserialize_polymorphic_enum_loop;
|
use crate::deserialize::polymorphic_enum_loop_spec::deserialize_polymorphic_enum_loop;
|
||||||
use crate::deserialize::polymorphic_leaf_enum::deserialize_polymorphic_leaf_enum;
|
use crate::deserialize::polymorphic_leaf_enum::deserialize_polymorphic_leaf_enum;
|
||||||
use crate::deserialize::polymorphic_pass_through_spec::deserialize_polymorphic_pass_through;
|
use crate::deserialize::polymorphic_pass_through_spec::deserialize_polymorphic_pass_through;
|
||||||
|
use crate::deserialize::polymorphic_tree_enum::deserialize_polymorphic_tree_enum;
|
||||||
use crate::deserialize::polymorphic_type_spec::deserialize_polymorphic_type;
|
use crate::deserialize::polymorphic_type_spec::deserialize_polymorphic_type;
|
||||||
use crate::deserialize::production_spec::deserialize_production;
|
use crate::deserialize::production_spec::deserialize_production;
|
||||||
use crate::deserialize::struct_spec::deserialize_struct_spec;
|
use crate::deserialize::struct_spec::deserialize_struct_spec;
|
||||||
use crate::deserialize::tree_enum_spec::deserialize_tree_enum;
|
use crate::deserialize::tree_enum_spec::deserialize_tree_enum;
|
||||||
use crate::spec::BuildSpec;
|
use crate::spec::BuildSpec;
|
||||||
use yaml_rust2::{Yaml, YamlLoader};
|
use yaml_rust2::{Yaml, YamlLoader};
|
||||||
use crate::deserialize::polymorphic_tree_enum::deserialize_polymorphic_tree_enum;
|
|
||||||
|
|
||||||
fn deserialize_build_spec(build_spec_name: &str, build_spec: &Yaml) -> BuildSpec {
|
fn deserialize_build_spec(build_spec_name: &str, build_spec: &Yaml) -> BuildSpec {
|
||||||
if build_spec["struct"].is_hash() {
|
if build_spec["struct"].is_hash() {
|
||||||
|
|||||||
@ -46,21 +46,17 @@ fn deserialize_build(name: &str, props: &Yaml) -> PolymorphicEnumLoopRuleBuild {
|
|||||||
let fields = props["fields"]
|
let fields = props["fields"]
|
||||||
.as_vec()
|
.as_vec()
|
||||||
.map(|fields| {
|
.map(|fields| {
|
||||||
fields.iter()
|
fields
|
||||||
|
.iter()
|
||||||
.map(|field_yaml| {
|
.map(|field_yaml| {
|
||||||
let (field_name, field_props) = unwrap_single_member_hash(field_yaml);
|
let (field_name, field_props) = unwrap_single_member_hash(field_yaml);
|
||||||
let kind = field_props["kind"].as_str().unwrap();
|
let kind = field_props["kind"].as_str().unwrap();
|
||||||
StructField::new(
|
StructField::new(&field_name, kind, None, false)
|
||||||
&field_name,
|
|
||||||
kind,
|
|
||||||
None,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| vec![]);
|
.unwrap_or_else(|| vec![]);
|
||||||
|
|
||||||
PolymorphicEnumLoopRuleBuild::new(name, variant, children, fields)
|
PolymorphicEnumLoopRuleBuild::new(name, variant, children, fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
use yaml_rust2::Yaml;
|
|
||||||
use crate::spec::polymorphic_leaf_enum::PolymorphicLeafEnum;
|
use crate::spec::polymorphic_leaf_enum::PolymorphicLeafEnum;
|
||||||
|
use yaml_rust2::Yaml;
|
||||||
|
|
||||||
pub fn deserialize_polymorphic_leaf_enum(name: &str, props: &Yaml) -> PolymorphicLeafEnum {
|
pub fn deserialize_polymorphic_leaf_enum(name: &str, props: &Yaml) -> PolymorphicLeafEnum {
|
||||||
let kind = props["kind"].as_str().unwrap();
|
let kind = props["kind"].as_str().unwrap();
|
||||||
let rules = props["rules"].as_vec().unwrap()
|
let rules = props["rules"]
|
||||||
|
.as_vec()
|
||||||
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|rule| {
|
.map(|rule| rule.as_str().unwrap().to_string())
|
||||||
rule.as_str().unwrap().to_string()
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
PolymorphicLeafEnum::new(name, kind, rules)
|
PolymorphicLeafEnum::new(name, kind, rules)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,17 @@
|
|||||||
use crate::deserialize::util::unwrap_single_member_hash;
|
use crate::deserialize::util::unwrap_single_member_hash;
|
||||||
use crate::spec::polymorphic_pass_through_spec::{PolymorphicPassThroughBuildSpec, PolymorphicPassThroughVariant};
|
use crate::spec::polymorphic_pass_through_spec::{
|
||||||
|
PolymorphicPassThroughBuildSpec, PolymorphicPassThroughVariant,
|
||||||
|
};
|
||||||
use yaml_rust2::Yaml;
|
use yaml_rust2::Yaml;
|
||||||
|
|
||||||
pub fn deserialize_polymorphic_pass_through(name: &str, props: &Yaml) -> PolymorphicPassThroughBuildSpec {
|
pub fn deserialize_polymorphic_pass_through(
|
||||||
|
name: &str,
|
||||||
|
props: &Yaml,
|
||||||
|
) -> PolymorphicPassThroughBuildSpec {
|
||||||
let build_kind = props["build"]["kind"].as_str().unwrap();
|
let build_kind = props["build"]["kind"].as_str().unwrap();
|
||||||
let variants = props["variants"].as_vec().unwrap()
|
let variants = props["variants"]
|
||||||
|
.as_vec()
|
||||||
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|variant_yaml| {
|
.map(|variant_yaml| {
|
||||||
let (variant_name, variant_props) = unwrap_single_member_hash(variant_yaml);
|
let (variant_name, variant_props) = unwrap_single_member_hash(variant_yaml);
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
use yaml_rust2::Yaml;
|
|
||||||
use crate::spec::polymorphic_tree_enum_spec::PolymorphicTreeEnumSpec;
|
use crate::spec::polymorphic_tree_enum_spec::PolymorphicTreeEnumSpec;
|
||||||
|
use yaml_rust2::Yaml;
|
||||||
|
|
||||||
pub fn deserialize_polymorphic_tree_enum(name: &str, props: &Yaml) -> PolymorphicTreeEnumSpec {
|
pub fn deserialize_polymorphic_tree_enum(name: &str, props: &Yaml) -> PolymorphicTreeEnumSpec {
|
||||||
let kind = props["kind"].as_str().unwrap();
|
let kind = props["kind"].as_str().unwrap();
|
||||||
let rules = props["rules"].as_vec().unwrap()
|
let rules = props["rules"]
|
||||||
|
.as_vec()
|
||||||
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|rule| rule.as_str().unwrap())
|
.map(|rule| rule.as_str().unwrap())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
PolymorphicTreeEnumSpec::new(name, kind, &rules)
|
PolymorphicTreeEnumSpec::new(name, kind, &rules)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use yaml_rust2::Yaml;
|
|||||||
|
|
||||||
fn deserialize_variant(variant_name: &str, props: &Yaml) -> PolymorphicTypeVariant {
|
fn deserialize_variant(variant_name: &str, props: &Yaml) -> PolymorphicTypeVariant {
|
||||||
let inner_kind = props["inner"]["kind"].as_str().unwrap();
|
let inner_kind = props["inner"]["kind"].as_str().unwrap();
|
||||||
PolymorphicTypeVariant::new(variant_name, inner_kind)
|
PolymorphicTypeVariant::new(variant_name, inner_kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize_polymorphic_type(name: &str, props: &Yaml) -> PolymorphicTypeBuildSpec {
|
pub fn deserialize_polymorphic_type(name: &str, props: &Yaml) -> PolymorphicTypeBuildSpec {
|
||||||
@ -20,4 +20,4 @@ pub fn deserialize_polymorphic_type(name: &str, props: &Yaml) -> PolymorphicType
|
|||||||
.collect();
|
.collect();
|
||||||
let kind = props["build"]["kind"].as_str().unwrap();
|
let kind = props["build"]["kind"].as_str().unwrap();
|
||||||
PolymorphicTypeBuildSpec::new(name, variants, kind)
|
PolymorphicTypeBuildSpec::new(name, variants, kind)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
use crate::spec::production_spec::{ProductionBooleanFrom, ProductionBuildSpec, ProductionKind, ProductionStringFrom};
|
use crate::spec::production_spec::{
|
||||||
|
ProductionBooleanFrom, ProductionBuildSpec, ProductionKind, ProductionStringFrom,
|
||||||
|
};
|
||||||
use yaml_rust2::Yaml;
|
use yaml_rust2::Yaml;
|
||||||
|
|
||||||
pub fn deserialize_production(name: &str, props: &Yaml) -> ProductionBuildSpec {
|
pub fn deserialize_production(name: &str, props: &Yaml) -> ProductionBuildSpec {
|
||||||
@ -10,12 +12,18 @@ pub fn deserialize_production(name: &str, props: &Yaml) -> ProductionBuildSpec {
|
|||||||
let from = match props["from"].as_str().unwrap() {
|
let from = match props["from"].as_str().unwrap() {
|
||||||
"string_inner" => ProductionStringFrom::StringInner,
|
"string_inner" => ProductionStringFrom::StringInner,
|
||||||
"whole_pair" => ProductionStringFrom::WholePair,
|
"whole_pair" => ProductionStringFrom::WholePair,
|
||||||
_ => panic!("Unknown string production from: {}", props["from"].as_str().unwrap())
|
_ => panic!(
|
||||||
|
"Unknown string production from: {}",
|
||||||
|
props["from"].as_str().unwrap()
|
||||||
|
),
|
||||||
};
|
};
|
||||||
ProductionKind::String(from)
|
ProductionKind::String(from)
|
||||||
},
|
}
|
||||||
"boolean" => ProductionKind::Boolean(ProductionBooleanFrom::ParseWholePair),
|
"boolean" => ProductionKind::Boolean(ProductionBooleanFrom::ParseWholePair),
|
||||||
_ => panic!("Unknown production kind: {}", props["kind"].as_str().unwrap()),
|
_ => panic!(
|
||||||
|
"Unknown production kind: {}",
|
||||||
|
props["kind"].as_str().unwrap()
|
||||||
|
),
|
||||||
};
|
};
|
||||||
ProductionBuildSpec::new(name, kind)
|
ProductionBuildSpec::new(name, kind)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
use convert_case::{Case, Casing};
|
|
||||||
use crate::deserialize::util::{get_as_bool_or, make_build_fn_name, unwrap_single_member_hash};
|
use crate::deserialize::util::{get_as_bool_or, make_build_fn_name, unwrap_single_member_hash};
|
||||||
use crate::spec::tree_enum_spec::{EnumRuleChild, EnumRuleChildKind, EnumRuleChildNodeKind, NameAndWith, TreeEnumBuildSpec, TreeEnumRule};
|
use crate::spec::tree_enum_spec::{
|
||||||
|
EnumRuleChild, EnumRuleChildKind, EnumRuleChildNodeKind, NameAndWith, TreeEnumBuildSpec,
|
||||||
|
TreeEnumRule,
|
||||||
|
};
|
||||||
|
use convert_case::{Case, Casing};
|
||||||
use yaml_rust2::Yaml;
|
use yaml_rust2::Yaml;
|
||||||
|
|
||||||
fn deserialize_hash_enum_rule(rule: &str, props: &Yaml) -> TreeEnumRule {
|
fn deserialize_hash_enum_rule(rule: &str, props: &Yaml) -> TreeEnumRule {
|
||||||
if get_as_bool_or(&props["child"], true) {
|
if get_as_bool_or(&props["child"], true) {
|
||||||
let name_and_with = NameAndWith::new(
|
let name_and_with = NameAndWith::new(&rule.to_case(Case::Snake), &make_build_fn_name(rule));
|
||||||
&rule.to_case(Case::Snake),
|
|
||||||
&make_build_fn_name(rule)
|
|
||||||
);
|
|
||||||
let kind = match props["kind"].as_str().unwrap() {
|
let kind = match props["kind"].as_str().unwrap() {
|
||||||
"int" => EnumRuleChildKind::Int(name_and_with),
|
"int" => EnumRuleChildKind::Int(name_and_with),
|
||||||
"long" => EnumRuleChildKind::Long(name_and_with),
|
"long" => EnumRuleChildKind::Long(name_and_with),
|
||||||
@ -28,10 +28,7 @@ fn deserialize_string_enum_rule(rule: &str) -> TreeEnumRule {
|
|||||||
TreeEnumRule::new(
|
TreeEnumRule::new(
|
||||||
rule,
|
rule,
|
||||||
Some(Box::new(EnumRuleChild::new(Box::new(
|
Some(Box::new(EnumRuleChild::new(Box::new(
|
||||||
EnumRuleChildKind::Node(EnumRuleChildNodeKind::new(
|
EnumRuleChildKind::Node(EnumRuleChildNodeKind::new(rule, &make_build_fn_name(rule))),
|
||||||
rule,
|
|
||||||
&make_build_fn_name(rule)
|
|
||||||
)),
|
|
||||||
)))),
|
)))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use crate::spec::BuildSpec;
|
||||||
use crate::spec::leaf_enum_spec::LeafEnumBuildSpec;
|
use crate::spec::leaf_enum_spec::LeafEnumBuildSpec;
|
||||||
use crate::spec::leaf_struct_spec::{LeafStructBuildSpec, LeafStructMemberKind};
|
use crate::spec::leaf_struct_spec::{LeafStructBuildSpec, LeafStructMemberKind};
|
||||||
use crate::spec::polymorphic_enum_inner_build::{
|
use crate::spec::polymorphic_enum_inner_build::{
|
||||||
@ -9,7 +10,6 @@ use crate::spec::polymorphic_enum_loop_spec::{
|
|||||||
use crate::spec::polymorphic_type_spec::PolymorphicTypeBuildSpec;
|
use crate::spec::polymorphic_type_spec::PolymorphicTypeBuildSpec;
|
||||||
use crate::spec::struct_spec::{MemberChildBuild, StructChild, StructSpec, VecChildBuild};
|
use crate::spec::struct_spec::{MemberChildBuild, StructChild, StructSpec, VecChildBuild};
|
||||||
use crate::spec::tree_enum_spec::{EnumRuleChildKind, TreeEnumBuildSpec};
|
use crate::spec::tree_enum_spec::{EnumRuleChildKind, TreeEnumBuildSpec};
|
||||||
use crate::spec::BuildSpec;
|
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
|
|||||||
@ -18,4 +18,4 @@ impl LeafEnumBuildSpec {
|
|||||||
pub fn rules(&self) -> impl Iterator<Item = &str> {
|
pub fn rules(&self) -> impl Iterator<Item = &str> {
|
||||||
self.rules.iter().map(AsRef::as_ref)
|
self.rules.iter().map(AsRef::as_ref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ impl LeafStructBuildSpec {
|
|||||||
pub fn members(&self) -> impl Iterator<Item = &LeafStructMember> {
|
pub fn members(&self) -> impl Iterator<Item = &LeafStructMember> {
|
||||||
self.members.iter().map(Box::as_ref)
|
self.members.iter().map(Box::as_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn derive(&self) -> impl Iterator<Item = &str> {
|
pub fn derive(&self) -> impl Iterator<Item = &str> {
|
||||||
self.derive.iter().map(String::as_str)
|
self.derive.iter().map(String::as_str)
|
||||||
}
|
}
|
||||||
@ -51,5 +51,5 @@ impl LeafStructMember {
|
|||||||
pub enum LeafStructMemberKind {
|
pub enum LeafStructMemberKind {
|
||||||
String,
|
String,
|
||||||
FileId,
|
FileId,
|
||||||
Range
|
Range,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
pub struct NodeProductionBuildSpec {
|
pub struct NodeProductionBuildSpec {
|
||||||
name: String,
|
name: String,
|
||||||
kind: String,
|
kind: String,
|
||||||
with: String
|
with: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeProductionBuildSpec {
|
impl NodeProductionBuildSpec {
|
||||||
@ -9,19 +9,19 @@ impl NodeProductionBuildSpec {
|
|||||||
Self {
|
Self {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
kind: kind.to_string(),
|
kind: kind.to_string(),
|
||||||
with: with.to_string()
|
with: with.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,11 @@ pub struct PolymorphicEnumInnerBuild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PolymorphicEnumInnerBuild {
|
impl PolymorphicEnumInnerBuild {
|
||||||
pub fn new(name: &str, members: Vec<PolymorphicEnumInnerBuildMember>, rules: Vec<PolymorphicEnumInnerBuildRule>) -> Self {
|
pub fn new(
|
||||||
|
name: &str,
|
||||||
|
members: Vec<PolymorphicEnumInnerBuildMember>,
|
||||||
|
rules: Vec<PolymorphicEnumInnerBuildRule>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
members,
|
members,
|
||||||
@ -28,21 +32,21 @@ impl PolymorphicEnumInnerBuild {
|
|||||||
|
|
||||||
pub struct PolymorphicEnumInnerBuildMember {
|
pub struct PolymorphicEnumInnerBuildMember {
|
||||||
name: String,
|
name: String,
|
||||||
kind: PolymorphicEnumInnerBuildMemberKind
|
kind: PolymorphicEnumInnerBuildMemberKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PolymorphicEnumInnerBuildMember {
|
impl PolymorphicEnumInnerBuildMember {
|
||||||
pub fn new(name: &str, kind: PolymorphicEnumInnerBuildMemberKind) -> Self {
|
pub fn new(name: &str, kind: PolymorphicEnumInnerBuildMemberKind) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
kind
|
kind,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kind(&self) -> &PolymorphicEnumInnerBuildMemberKind {
|
pub fn kind(&self) -> &PolymorphicEnumInnerBuildMemberKind {
|
||||||
&self.kind
|
&self.kind
|
||||||
}
|
}
|
||||||
@ -50,7 +54,7 @@ impl PolymorphicEnumInnerBuildMember {
|
|||||||
|
|
||||||
pub enum PolymorphicEnumInnerBuildMemberKind {
|
pub enum PolymorphicEnumInnerBuildMemberKind {
|
||||||
Leaf,
|
Leaf,
|
||||||
Struct
|
Struct,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PolymorphicEnumInnerBuildRule {
|
pub struct PolymorphicEnumInnerBuildRule {
|
||||||
@ -65,12 +69,12 @@ impl PolymorphicEnumInnerBuildRule {
|
|||||||
with: with.to_string(),
|
with: with.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with(&self) -> &str {
|
pub fn with(&self) -> &str {
|
||||||
&self.with
|
&self.with
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -105,7 +105,7 @@ impl PolymorphicEnumLoopRuleBuild {
|
|||||||
pub fn children(&self) -> impl Iterator<Item = &PolymorphicEnumLoopRuleBuildChild> {
|
pub fn children(&self) -> impl Iterator<Item = &PolymorphicEnumLoopRuleBuildChild> {
|
||||||
self.children.iter().map(Box::as_ref)
|
self.children.iter().map(Box::as_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fields(&self) -> &[StructField] {
|
pub fn fields(&self) -> &[StructField] {
|
||||||
&self.fields
|
&self.fields
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,16 +12,16 @@ impl PolymorphicTreeEnumSpec {
|
|||||||
rules: rules.iter().map(ToString::to_string).collect(),
|
rules: rules.iter().map(ToString::to_string).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kind(&self) -> &str {
|
pub fn kind(&self) -> &str {
|
||||||
&self.kind
|
&self.kind
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rules(&self) -> impl Iterator<Item = &str> {
|
pub fn rules(&self) -> impl Iterator<Item = &str> {
|
||||||
self.rules.iter().map(AsRef::as_ref)
|
self.rules.iter().map(AsRef::as_ref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,7 +88,7 @@ impl EnumRuleChildNodeKind {
|
|||||||
pub fn node_kind(&self) -> &str {
|
pub fn node_kind(&self) -> &str {
|
||||||
&self.node_kind
|
&self.node_kind
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with(&self) -> &str {
|
pub fn with(&self) -> &str {
|
||||||
&self.with
|
&self.with
|
||||||
}
|
}
|
||||||
@ -106,11 +106,11 @@ impl NameAndWith {
|
|||||||
with: with.to_string(),
|
with: with.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with(&self) -> &str {
|
pub fn with(&self) -> &str {
|
||||||
&self.with
|
&self.with
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
|
use crate::spec::tree_enum_spec::{EnumRuleChildKind, TreeEnumBuildSpec};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use crate::spec::tree_enum_spec::{EnumRuleChildKind, TreeEnumBuildSpec};
|
|
||||||
|
|
||||||
pub fn make_enum_type(build_spec: &TreeEnumBuildSpec) -> TokenStream {
|
pub fn make_enum_type(build_spec: &TreeEnumBuildSpec) -> TokenStream {
|
||||||
let children: Vec<TokenStream> = build_spec
|
let children: Vec<TokenStream> = build_spec
|
||||||
@ -34,4 +34,4 @@ pub fn make_enum_type(build_spec: &TreeEnumBuildSpec) -> TokenStream {
|
|||||||
#(#children),*
|
#(#children),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,10 +84,11 @@ pub fn make_leaf_struct_type(build_spec: &LeafStructBuildSpec) -> TokenStream {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let struct_stream = if build_spec.derive().count() > 0 {
|
let struct_stream = if build_spec.derive().count() > 0 {
|
||||||
let derives = build_spec.derive().map(|derive| {
|
let derives = build_spec
|
||||||
format_ident!("{}", derive)
|
.derive()
|
||||||
}).collect::<Vec<_>>();
|
.map(|derive| format_ident!("{}", derive))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#[derive(#(#derives),*)]
|
#[derive(#(#derives),*)]
|
||||||
pub struct #type_ident {
|
pub struct #type_ident {
|
||||||
@ -101,7 +102,7 @@ pub fn make_leaf_struct_type(build_spec: &LeafStructBuildSpec) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#struct_stream
|
#struct_stream
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
|
use crate::spec::polymorphic_enum_inner_build::{
|
||||||
|
PolymorphicEnumInnerBuild, PolymorphicEnumInnerBuildMemberKind,
|
||||||
|
};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use crate::spec::polymorphic_enum_inner_build::{PolymorphicEnumInnerBuild, PolymorphicEnumInnerBuildMemberKind};
|
|
||||||
|
|
||||||
pub fn make_polymorphic_enum_inner_build_type(spec: &PolymorphicEnumInnerBuild) -> TokenStream {
|
pub fn make_polymorphic_enum_inner_build_type(spec: &PolymorphicEnumInnerBuild) -> TokenStream {
|
||||||
let members = spec.members()
|
let members = spec
|
||||||
|
.members()
|
||||||
.map(|member| {
|
.map(|member| {
|
||||||
let name_ident = format_ident!("{}", member.name());
|
let name_ident = format_ident!("{}", member.name());
|
||||||
match member.kind() {
|
match member.kind() {
|
||||||
@ -22,4 +25,4 @@ pub fn make_polymorphic_enum_inner_build_type(spec: &PolymorphicEnumInnerBuild)
|
|||||||
#(#members,)*
|
#(#members,)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
|
use crate::spec::SpecialChildKind;
|
||||||
use crate::spec::polymorphic_enum_loop_spec::{
|
use crate::spec::polymorphic_enum_loop_spec::{
|
||||||
PolymorphicEnumLoopBuildSpec, PolymorphicEnumLoopRule, PolymorphicEnumLoopRuleBuildChild,
|
PolymorphicEnumLoopBuildSpec, PolymorphicEnumLoopRule, PolymorphicEnumLoopRuleBuildChild,
|
||||||
};
|
};
|
||||||
use crate::spec::SpecialChildKind;
|
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
|
|||||||
2
build.rs
2
build.rs
@ -1,4 +1,4 @@
|
|||||||
use ast_generator::{get_build_specs, generate_files};
|
use ast_generator::{generate_files, get_build_specs};
|
||||||
use cst_test_generator::generate_test_files;
|
use cst_test_generator::generate_test_files;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|||||||
@ -191,14 +191,12 @@ fn assemble_ir_call(ir_call: &IrCall, context: &mut AssemblyContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn assemble_ir_return(ir_return: &IrReturn, context: &mut AssemblyContext) {
|
fn assemble_ir_return(ir_return: &IrReturn, context: &mut AssemblyContext) {
|
||||||
let operand = ir_return.expression().map(|expression| {
|
let operand = ir_return.expression().map(|expression| match expression {
|
||||||
match expression {
|
IrExpression::Variable(ir_variable) => {
|
||||||
IrExpression::Variable(ir_variable) => {
|
let variable_virtual_register_id = context.get_virtual_register(ir_variable.name());
|
||||||
let variable_virtual_register_id = context.get_virtual_register(ir_variable.name());
|
AsmOperand::VirtualRegister(variable_virtual_register_id)
|
||||||
AsmOperand::VirtualRegister(variable_virtual_register_id)
|
|
||||||
}
|
|
||||||
IrExpression::Literal(ir_literal) => ir_literal_to_asm_operand(ir_literal),
|
|
||||||
}
|
}
|
||||||
|
IrExpression::Literal(ir_literal) => ir_literal_to_asm_operand(ir_literal),
|
||||||
});
|
});
|
||||||
context
|
context
|
||||||
.current_control_unit_mut()
|
.current_control_unit_mut()
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use deimos::parser::{DeimosParser, Rule};
|
use deimos::parser::{DeimosParser, Rule};
|
||||||
use std::path::PathBuf;
|
|
||||||
use pest::iterators::{Pair, Pairs};
|
use pest::iterators::{Pair, Pairs};
|
||||||
use pest::Parser;
|
use pest::Parser;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn print_pair(pair: Pair<Rule>) {
|
fn print_pair(pair: Pair<Rule>) {
|
||||||
println!("{:?}", pair.as_rule());
|
println!("{:?}", pair.as_rule());
|
||||||
@ -27,4 +27,4 @@ pub fn show_cst(path: &PathBuf) {
|
|||||||
eprintln!("{:?}", error);
|
eprintln!("{:?}", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ use codespan_reporting::files::SimpleFiles;
|
|||||||
use codespan_reporting::term;
|
use codespan_reporting::term;
|
||||||
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
|
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
|
||||||
use deimos::ast::build::build_ast;
|
use deimos::ast::build::build_ast;
|
||||||
|
use deimos::ast::node::CompilationUnit;
|
||||||
use deimos::name_analysis::analyze_names;
|
use deimos::name_analysis::analyze_names;
|
||||||
use deimos::name_analysis::symbol_table::SymbolTable;
|
use deimos::name_analysis::symbol_table::SymbolTable;
|
||||||
use deimos::parser::{DeimosParser, Rule};
|
use deimos::parser::{DeimosParser, Rule};
|
||||||
@ -10,7 +11,6 @@ use pest::Parser;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use deimos::ast::node::CompilationUnit;
|
|
||||||
|
|
||||||
struct ParseErrors {
|
struct ParseErrors {
|
||||||
errors: Vec<pest::error::Error<Rule>>,
|
errors: Vec<pest::error::Error<Rule>>,
|
||||||
@ -34,7 +34,9 @@ impl Display for ParseErrors {
|
|||||||
|
|
||||||
impl std::error::Error for ParseErrors {}
|
impl std::error::Error for ParseErrors {}
|
||||||
|
|
||||||
pub fn name_analysis(paths: &[PathBuf]) -> Result<Vec<CompilationUnit>, Box<dyn std::error::Error>> {
|
pub fn name_analysis(
|
||||||
|
paths: &[PathBuf],
|
||||||
|
) -> Result<Vec<CompilationUnit>, Box<dyn std::error::Error>> {
|
||||||
let mut paths_and_sources: HashMap<String, String> = HashMap::new();
|
let mut paths_and_sources: HashMap<String, String> = HashMap::new();
|
||||||
for path in paths {
|
for path in paths {
|
||||||
let src = std::fs::read_to_string(path).unwrap();
|
let src = std::fs::read_to_string(path).unwrap();
|
||||||
|
|||||||
@ -8,10 +8,10 @@ use crate::ir::{
|
|||||||
IrPrimitiveKind, IrReturn, IrStatement, IrStructKind, IrVariable,
|
IrPrimitiveKind, IrReturn, IrStatement, IrStructKind, IrVariable,
|
||||||
};
|
};
|
||||||
use crate::name_analysis::symbol::{ClassSymbol, ParameterSymbol, PrimitiveTypeSymbol, TypeSymbol};
|
use crate::name_analysis::symbol::{ClassSymbol, ParameterSymbol, PrimitiveTypeSymbol, TypeSymbol};
|
||||||
|
use crate::type_analysis::kinds::Kind;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::type_analysis::kinds::Kind;
|
|
||||||
|
|
||||||
struct CuContext {
|
struct CuContext {
|
||||||
irs: Vec<Ir>,
|
irs: Vec<Ir>,
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
use crate::ast::node::{
|
use crate::ast::node::{
|
||||||
AssignmentStatement, BacktickString, Call, Closure, ClosureParameters,
|
AssignmentStatement, BacktickString, Call, Closure, ClosureParameters, CompilationUnit,
|
||||||
CompilationUnit, ConcreteUseStatement, ConcreteUseStatementSuffix, DString, Expression,
|
ConcreteUseStatement, ConcreteUseStatementSuffix, DString, Expression, ExpressionList,
|
||||||
ExpressionList, ExpressionStatement, Function, FunctionAliasBody, FunctionBlockBody,
|
ExpressionStatement, Function, FunctionAliasBody, FunctionBlockBody, FunctionBody,
|
||||||
FunctionBody, FunctionEqualsBody, GenericParameters, Identifier, IdentifierExpression,
|
FunctionEqualsBody, GenericParameters, Identifier, IdentifierExpression, IdentifierOrFqn,
|
||||||
IdentifierOrFqn, LValue, LValueSuffix, Literal, ModuleLevelDeclaration
|
LValue, LValueSuffix, Literal, ModuleLevelDeclaration, ObjectIndex, Parameter, Parameters,
|
||||||
, ObjectIndex, Parameter, Parameters, PlatformFunction, PrimitiveType,
|
PlatformFunction, PrimitiveType, ReturnType, StarUseStatement, Statement, SuffixExpression,
|
||||||
ReturnType, StarUseStatement, Statement, SuffixExpression, SuffixOperator, TypeUse, TypedArray,
|
SuffixOperator, TypeUse, TypedArray, UseStatement, UseStatementIdentifier, UseStatementPrefix,
|
||||||
UseStatement, UseStatementIdentifier, UseStatementPrefix, VariableDeclaration,
|
VariableDeclaration,
|
||||||
};
|
};
|
||||||
use crate::diagnostic::DmDiagnostic;
|
use crate::diagnostic::DmDiagnostic;
|
||||||
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
||||||
@ -529,7 +529,11 @@ fn na_p2_variable_declaration(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// initializer
|
// initializer
|
||||||
na_p2_expression(variable_declaration.expression_mut(), symbol_table, diagnostics);
|
na_p2_expression(
|
||||||
|
variable_declaration.expression_mut(),
|
||||||
|
symbol_table,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn na_p2_assignment_statement(
|
fn na_p2_assignment_statement(
|
||||||
@ -628,7 +632,11 @@ fn na_p2_expression(
|
|||||||
}
|
}
|
||||||
Expression::Additive(additive) => {
|
Expression::Additive(additive) => {
|
||||||
na_p2_expression(additive.left_mut(), symbol_table, diagnostics);
|
na_p2_expression(additive.left_mut(), symbol_table, diagnostics);
|
||||||
na_p2_expression(additive.rhs_mut().expression_mut(), symbol_table, diagnostics);
|
na_p2_expression(
|
||||||
|
additive.rhs_mut().expression_mut(),
|
||||||
|
symbol_table,
|
||||||
|
diagnostics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Expression::Multiplicative(multiplicative) => {
|
Expression::Multiplicative(multiplicative) => {
|
||||||
todo!()
|
todo!()
|
||||||
|
|||||||
@ -23,15 +23,15 @@ impl ClassSymbol {
|
|||||||
source_definition,
|
source_definition,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fqn_formatted(&self) -> String {
|
pub fn fqn_formatted(&self) -> String {
|
||||||
self.fqn_parts.join("::")
|
self.fqn_parts.join("::")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn declared_name(&self) -> &str {
|
pub fn declared_name(&self) -> &str {
|
||||||
self.fqn_parts.last().unwrap()
|
self.fqn_parts.last().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn declared_name_owned(&self) -> Rc<str> {
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
||||||
self.fqn_parts.last().unwrap().clone()
|
self.fqn_parts.last().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
use crate::name_analysis::symbol::{ClassMemberSymbol, ClassSymbol, FunctionSymbol, ParameterSymbol, Symbol, VariableSymbol};
|
use crate::name_analysis::symbol::{
|
||||||
|
ClassMemberSymbol, ClassSymbol, FunctionSymbol, ParameterSymbol, Symbol, VariableSymbol,
|
||||||
|
};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -13,9 +15,7 @@ pub enum ExpressibleSymbol {
|
|||||||
impl ExpressibleSymbol {
|
impl ExpressibleSymbol {
|
||||||
pub fn to_symbol(self) -> Rc<RefCell<dyn Symbol>> {
|
pub fn to_symbol(self) -> Rc<RefCell<dyn Symbol>> {
|
||||||
match self {
|
match self {
|
||||||
ExpressibleSymbol::Class(class_symbol) => {
|
ExpressibleSymbol::Class(class_symbol) => class_symbol as Rc<RefCell<dyn Symbol>>,
|
||||||
class_symbol as Rc<RefCell<dyn Symbol>>
|
|
||||||
}
|
|
||||||
ExpressibleSymbol::Function(function_symbol) => {
|
ExpressibleSymbol::Function(function_symbol) => {
|
||||||
function_symbol as Rc<RefCell<dyn Symbol>>
|
function_symbol as Rc<RefCell<dyn Symbol>>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ impl FunctionSymbol {
|
|||||||
return_type,
|
return_type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fqn_formatted(&self) -> String {
|
pub fn fqn_formatted(&self) -> String {
|
||||||
self.fqn_parts.join("::")
|
self.fqn_parts.join("::")
|
||||||
}
|
}
|
||||||
@ -82,11 +82,11 @@ impl FunctionSymbol {
|
|||||||
pub fn set_parameter_symbols(&mut self, parameter_symbols: Vec<Rc<RefCell<ParameterSymbol>>>) {
|
pub fn set_parameter_symbols(&mut self, parameter_symbols: Vec<Rc<RefCell<ParameterSymbol>>>) {
|
||||||
self.parameters = parameter_symbols;
|
self.parameters = parameter_symbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn return_type(&self) -> Option<&TypeSymbol> {
|
pub fn return_type(&self) -> Option<&TypeSymbol> {
|
||||||
self.return_type.as_ref()
|
self.return_type.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn return_type_owned(&self) -> Option<TypeSymbol> {
|
pub fn return_type_owned(&self) -> Option<TypeSymbol> {
|
||||||
self.return_type.clone()
|
self.return_type.clone()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ impl GenericTypeSymbol {
|
|||||||
pub fn declared_name(&self) -> &str {
|
pub fn declared_name(&self) -> &str {
|
||||||
&self.declared_name
|
&self.declared_name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn declared_name_owned(&self) -> Rc<str> {
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
||||||
self.declared_name.clone()
|
self.declared_name.clone()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,11 +20,11 @@ impl InterfaceSymbol {
|
|||||||
source_definition,
|
source_definition,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn declared_name(&self) -> &str {
|
pub fn declared_name(&self) -> &str {
|
||||||
self.fqn_parts.last().unwrap().as_ref()
|
self.fqn_parts.last().unwrap().as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn declared_name_owned(&self) -> Rc<str> {
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
||||||
self.fqn_parts.last().unwrap().clone()
|
self.fqn_parts.last().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use crate::name_analysis::symbol::class_member_symbol::ClassMemberSymbol;
|
use crate::name_analysis::symbol::class_member_symbol::ClassMemberSymbol;
|
||||||
use crate::name_analysis::symbol::parameter_symbol::ParameterSymbol;
|
use crate::name_analysis::symbol::parameter_symbol::ParameterSymbol;
|
||||||
use crate::name_analysis::symbol::Symbol;
|
|
||||||
use crate::name_analysis::symbol::variable_symbol::VariableSymbol;
|
use crate::name_analysis::symbol::variable_symbol::VariableSymbol;
|
||||||
|
use crate::name_analysis::symbol::Symbol;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub enum LVSymbol {
|
pub enum LVSymbol {
|
||||||
ClassMember(Rc<RefCell<ClassMemberSymbol>>),
|
ClassMember(Rc<RefCell<ClassMemberSymbol>>),
|
||||||
@ -17,12 +17,8 @@ impl LVSymbol {
|
|||||||
LVSymbol::ClassMember(class_member_symbol) => {
|
LVSymbol::ClassMember(class_member_symbol) => {
|
||||||
class_member_symbol as Rc<RefCell<dyn Symbol>>
|
class_member_symbol as Rc<RefCell<dyn Symbol>>
|
||||||
}
|
}
|
||||||
LVSymbol::Parameter(parameter_symbol) => {
|
LVSymbol::Parameter(parameter_symbol) => parameter_symbol as Rc<RefCell<dyn Symbol>>,
|
||||||
parameter_symbol as Rc<RefCell<dyn Symbol>>
|
LVSymbol::Variable(variable_symbol) => variable_symbol as Rc<RefCell<dyn Symbol>>,
|
||||||
}
|
|
||||||
LVSymbol::Variable(variable_symbol) => {
|
|
||||||
variable_symbol as Rc<RefCell<dyn Symbol>>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,11 +30,11 @@ impl ParameterSymbol {
|
|||||||
pub fn declared_name_owned(&self) -> Rc<str> {
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
||||||
self.declared_name.clone()
|
self.declared_name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_symbol(&self) -> Option<&TypeSymbol> {
|
pub fn type_symbol(&self) -> Option<&TypeSymbol> {
|
||||||
self.type_symbol.as_ref()
|
self.type_symbol.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_symbol_mut(&mut self) -> Option<&mut TypeSymbol> {
|
pub fn type_symbol_mut(&mut self) -> Option<&mut TypeSymbol> {
|
||||||
self.type_symbol.as_mut()
|
self.type_symbol.as_mut()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,4 +36,4 @@ impl SourceDefinition {
|
|||||||
pub fn range(&self) -> Range<usize> {
|
pub fn range(&self) -> Range<usize> {
|
||||||
self.range.clone()
|
self.range.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,10 +2,10 @@ use crate::name_analysis::symbol::class_symbol::ClassSymbol;
|
|||||||
use crate::name_analysis::symbol::generic_type_symbol::GenericTypeSymbol;
|
use crate::name_analysis::symbol::generic_type_symbol::GenericTypeSymbol;
|
||||||
use crate::name_analysis::symbol::interface_symbol::InterfaceSymbol;
|
use crate::name_analysis::symbol::interface_symbol::InterfaceSymbol;
|
||||||
use crate::name_analysis::symbol::primitive_type_symbol::PrimitiveTypeSymbol;
|
use crate::name_analysis::symbol::primitive_type_symbol::PrimitiveTypeSymbol;
|
||||||
|
use crate::name_analysis::symbol::Symbol;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::name_analysis::symbol::Symbol;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TypeSymbol {
|
pub enum TypeSymbol {
|
||||||
@ -21,15 +21,9 @@ impl TypeSymbol {
|
|||||||
TypeSymbol::Primitive(primitive_type_symbol) => {
|
TypeSymbol::Primitive(primitive_type_symbol) => {
|
||||||
Rc::new(RefCell::new(primitive_type_symbol))
|
Rc::new(RefCell::new(primitive_type_symbol))
|
||||||
}
|
}
|
||||||
TypeSymbol::Class(class_symbol) => {
|
TypeSymbol::Class(class_symbol) => class_symbol as Rc<RefCell<dyn Symbol>>,
|
||||||
class_symbol as Rc<RefCell<dyn Symbol>>
|
TypeSymbol::Interface(interface_symbol) => interface_symbol as Rc<RefCell<dyn Symbol>>,
|
||||||
}
|
TypeSymbol::Generic(generic_symbol) => generic_symbol as Rc<RefCell<dyn Symbol>>,
|
||||||
TypeSymbol::Interface(interface_symbol) => {
|
|
||||||
interface_symbol as Rc<RefCell<dyn Symbol>>
|
|
||||||
}
|
|
||||||
TypeSymbol::Generic(generic_symbol) => {
|
|
||||||
generic_symbol as Rc<RefCell<dyn Symbol>>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ impl ConcreteUseSymbol {
|
|||||||
pub fn declared_name(&self) -> &str {
|
pub fn declared_name(&self) -> &str {
|
||||||
self.fqn_parts.last().unwrap()
|
self.fqn_parts.last().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn declared_name_owned(&self) -> Rc<str> {
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
||||||
self.fqn_parts.last().unwrap().clone()
|
self.fqn_parts.last().unwrap().clone()
|
||||||
}
|
}
|
||||||
@ -87,15 +87,15 @@ impl StarUseSymbol {
|
|||||||
resolved_symbols: vec![],
|
resolved_symbols: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fqn_parts(&self) -> &[Rc<str>] {
|
pub fn fqn_parts(&self) -> &[Rc<str>] {
|
||||||
&self.fqn_parts
|
&self.fqn_parts
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolved_symbols(&self) -> &[UsableSymbol] {
|
pub fn resolved_symbols(&self) -> &[UsableSymbol] {
|
||||||
&self.resolved_symbols
|
&self.resolved_symbols
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_resolved_symbols(&mut self, symbols: Vec<UsableSymbol>) {
|
pub fn set_resolved_symbols(&mut self, symbols: Vec<UsableSymbol>) {
|
||||||
self.resolved_symbols = symbols;
|
self.resolved_symbols = symbols;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
||||||
use crate::name_analysis::symbol::Symbol;
|
use crate::name_analysis::symbol::Symbol;
|
||||||
|
use crate::type_analysis::kinds::Kind;
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::type_analysis::kinds::Kind;
|
|
||||||
|
|
||||||
pub struct VariableSymbol {
|
pub struct VariableSymbol {
|
||||||
declared_name: Rc<str>,
|
declared_name: Rc<str>,
|
||||||
@ -28,7 +28,7 @@ impl VariableSymbol {
|
|||||||
pub fn declared_name(&self) -> &str {
|
pub fn declared_name(&self) -> &str {
|
||||||
&self.declared_name
|
&self.declared_name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn declared_name_owned(&self) -> Rc<str> {
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
||||||
self.declared_name.clone()
|
self.declared_name.clone()
|
||||||
}
|
}
|
||||||
@ -36,11 +36,11 @@ impl VariableSymbol {
|
|||||||
pub fn is_mutable(&self) -> bool {
|
pub fn is_mutable(&self) -> bool {
|
||||||
self.is_mutable
|
self.is_mutable
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_analyzed_kind(&mut self, analyzed_kind: Kind) {
|
pub fn set_analyzed_kind(&mut self, analyzed_kind: Kind) {
|
||||||
self.analyzed_kind = Some(analyzed_kind);
|
self.analyzed_kind = Some(analyzed_kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn analyzed_kind(&self) -> Option<&Kind> {
|
pub fn analyzed_kind(&self) -> Option<&Kind> {
|
||||||
self.analyzed_kind.as_ref()
|
self.analyzed_kind.as_ref()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,11 +17,11 @@ impl FqnContext {
|
|||||||
pub fn pop(&mut self) {
|
pub fn pop(&mut self) {
|
||||||
self.stack.pop();
|
self.stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_fqn(&self) -> Vec<&str> {
|
pub fn current_fqn(&self) -> Vec<&str> {
|
||||||
self.stack.iter().map(|part| part.as_ref()).collect()
|
self.stack.iter().map(|part| part.as_ref()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_fqn_owned(&self) -> Vec<Rc<str>> {
|
pub fn current_fqn_owned(&self) -> Vec<Rc<str>> {
|
||||||
self.stack.clone()
|
self.stack.clone()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,7 +141,9 @@ impl SymbolTable {
|
|||||||
.find_usable_symbol(concrete_use_symbol.borrow().fqn_parts())
|
.find_usable_symbol(concrete_use_symbol.borrow().fqn_parts())
|
||||||
{
|
{
|
||||||
Ok(usable_symbol) => {
|
Ok(usable_symbol) => {
|
||||||
concrete_use_symbol.borrow_mut().set_resolved_symbol(usable_symbol);
|
concrete_use_symbol
|
||||||
|
.borrow_mut()
|
||||||
|
.set_resolved_symbol(usable_symbol);
|
||||||
}
|
}
|
||||||
Err(symbol_lookup_error) => {
|
Err(symbol_lookup_error) => {
|
||||||
// panic because this is definitely a compiler/configuration error
|
// panic because this is definitely a compiler/configuration error
|
||||||
@ -153,10 +155,13 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for star_use_symbol in global_scope.star_use_symbols() {
|
for star_use_symbol in global_scope.star_use_symbols() {
|
||||||
let mut star_use_symbol_ref_mut = star_use_symbol.borrow_mut();
|
let mut star_use_symbol_ref_mut = star_use_symbol.borrow_mut();
|
||||||
match self.symbol_tree.find_all_by_base_fqn(star_use_symbol_ref_mut.fqn_parts()) {
|
match self
|
||||||
|
.symbol_tree
|
||||||
|
.find_all_by_base_fqn(star_use_symbol_ref_mut.fqn_parts())
|
||||||
|
{
|
||||||
Ok(usable_symbols) => {
|
Ok(usable_symbols) => {
|
||||||
star_use_symbol_ref_mut.set_resolved_symbols(usable_symbols);
|
star_use_symbol_ref_mut.set_resolved_symbols(usable_symbols);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,11 +69,11 @@ impl Scope {
|
|||||||
pub fn id(&self) -> usize {
|
pub fn id(&self) -> usize {
|
||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn concrete_use_symbols(&self) -> impl Iterator<Item = &Rc<RefCell<ConcreteUseSymbol>>> {
|
pub fn concrete_use_symbols(&self) -> impl Iterator<Item = &Rc<RefCell<ConcreteUseSymbol>>> {
|
||||||
self.concrete_use_symbols.values()
|
self.concrete_use_symbols.values()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn star_use_symbols(&self) -> impl Iterator<Item = &Rc<RefCell<StarUseSymbol>>> {
|
pub fn star_use_symbols(&self) -> impl Iterator<Item = &Rc<RefCell<StarUseSymbol>>> {
|
||||||
self.star_use_symbols.values()
|
self.star_use_symbols.values()
|
||||||
}
|
}
|
||||||
@ -225,7 +225,7 @@ impl Scope {
|
|||||||
// which are in scope. If we don't find any of those, try looking through imports; start
|
// which are in scope. If we don't find any of those, try looking through imports; start
|
||||||
// with concrete imports by declared name; if none of those match, check all resolved
|
// with concrete imports by declared name; if none of those match, check all resolved
|
||||||
// symbols of the star imports until one is found or none.
|
// symbols of the star imports until one is found or none.
|
||||||
// !! Eventually consider registering star-imported symbols in a scope so that we can just
|
// !! Eventually consider registering star-imported symbols in a scope so that we can just
|
||||||
// check them via the hash maps instead of looping through the star symbols.
|
// check them via the hash maps instead of looping through the star symbols.
|
||||||
self.class_symbols
|
self.class_symbols
|
||||||
.get(declared_name)
|
.get(declared_name)
|
||||||
@ -255,16 +255,14 @@ impl Scope {
|
|||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
if let Some(concrete_use_symbol) = self.concrete_use_symbols.get(declared_name) {
|
if let Some(concrete_use_symbol) = self.concrete_use_symbols.get(declared_name) {
|
||||||
return match concrete_use_symbol.borrow().resolved_symbol().unwrap() {
|
return match concrete_use_symbol.borrow().resolved_symbol().unwrap() {
|
||||||
UsableSymbol::Interface(_) => {
|
UsableSymbol::Interface(_) => None,
|
||||||
None
|
|
||||||
}
|
|
||||||
UsableSymbol::Class(class_symbol) => {
|
UsableSymbol::Class(class_symbol) => {
|
||||||
Some(ExpressibleSymbol::Class(class_symbol.clone()))
|
Some(ExpressibleSymbol::Class(class_symbol.clone()))
|
||||||
}
|
}
|
||||||
UsableSymbol::Function(function_symbol) => {
|
UsableSymbol::Function(function_symbol) => {
|
||||||
Some(ExpressibleSymbol::Function(function_symbol.clone()))
|
Some(ExpressibleSymbol::Function(function_symbol.clone()))
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
@ -279,7 +277,9 @@ impl Scope {
|
|||||||
}
|
}
|
||||||
UsableSymbol::Function(function_symbol) => {
|
UsableSymbol::Function(function_symbol) => {
|
||||||
if function_symbol.borrow().declared_name() == declared_name {
|
if function_symbol.borrow().declared_name() == declared_name {
|
||||||
return Some(ExpressibleSymbol::Function(function_symbol.clone()));
|
return Some(ExpressibleSymbol::Function(
|
||||||
|
function_symbol.clone(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
|
|||||||
@ -3,18 +3,18 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub struct ClassKind {
|
pub struct ClassKind {
|
||||||
fqn: Rc<str>
|
fqn: Rc<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClassKind {
|
impl ClassKind {
|
||||||
pub fn new(fqn: &str) -> Self {
|
pub fn new(fqn: &str) -> Self {
|
||||||
Self { fqn: fqn.into() }
|
Self { fqn: fqn.into() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fqn(&self) -> &str {
|
pub fn fqn(&self) -> &str {
|
||||||
&self.fqn
|
&self.fqn
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fqn_owned(&self) -> Rc<str> {
|
pub fn fqn_owned(&self) -> Rc<str> {
|
||||||
self.fqn.clone()
|
self.fqn.clone()
|
||||||
}
|
}
|
||||||
@ -24,4 +24,4 @@ impl Display for ClassKind {
|
|||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
write!(f, "{}", self.fqn)
|
write!(f, "{}", self.fqn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use std::fmt::Display;
|
|
||||||
use crate::type_analysis::kinds::Kind;
|
use crate::type_analysis::kinds::Kind;
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum PrimitiveKind {
|
pub enum PrimitiveKind {
|
||||||
|
|||||||
@ -200,11 +200,10 @@ fn ta_additive_expression(
|
|||||||
"Incompatible types for additive expression: {} vs. {}",
|
"Incompatible types for additive expression: {} vs. {}",
|
||||||
left_kind, right_kind
|
left_kind, right_kind
|
||||||
))
|
))
|
||||||
.with_label(Label::primary(
|
.with_label(
|
||||||
*additive_expression.file_id(),
|
Label::primary(*additive_expression.file_id(), *additive_expression.range())
|
||||||
*additive_expression.range(),
|
.with_message("Incompatible types here."),
|
||||||
)
|
),
|
||||||
.with_message("Incompatible types here.")),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
additive_expression.set_analyzed_kind(left_kind);
|
additive_expression.set_analyzed_kind(left_kind);
|
||||||
|
|||||||
@ -394,7 +394,9 @@ impl Drop for GcHeap {
|
|||||||
let mut current = self.head().take();
|
let mut current = self.head().take();
|
||||||
while let Some(gc_any) = &mut current {
|
while let Some(gc_any) = &mut current {
|
||||||
let next = gc_any.next();
|
let next = gc_any.next();
|
||||||
unsafe { gc_any.dealloc(); }
|
unsafe {
|
||||||
|
gc_any.dealloc();
|
||||||
|
}
|
||||||
current = next;
|
current = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -464,7 +466,9 @@ fn collect_garbage(stack: &Vec<DvmValue>, heap: &mut GcHeap) {
|
|||||||
}
|
}
|
||||||
heap.subtract_current_size(current_gc.allocated_size());
|
heap.subtract_current_size(current_gc.allocated_size());
|
||||||
collected_size += current_gc.dynamic_size();
|
collected_size += current_gc.dynamic_size();
|
||||||
unsafe { current_gc.dealloc(); }
|
unsafe {
|
||||||
|
current_gc.dealloc();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
current_gc.set_color(GcColor::White);
|
current_gc.set_color(GcColor::White);
|
||||||
previous = Some(current_gc.clone());
|
previous = Some(current_gc.clone());
|
||||||
|
|||||||
@ -344,7 +344,7 @@ fn constant_to_value(constant: &DvmConstant) -> DvmValue {
|
|||||||
|
|
||||||
fn immediate_to_value(immediate: &Immediate) -> DvmValue {
|
fn immediate_to_value(immediate: &Immediate) -> DvmValue {
|
||||||
match immediate {
|
match immediate {
|
||||||
_ => todo!()
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user