diff --git a/ast-generator/src/ast_node/polymorphic_enum_inner_build_ast_node.rs b/ast-generator/src/ast_node/polymorphic_enum_inner_build_ast_node.rs index f8f34b0..728cfa5 100644 --- a/ast-generator/src/ast_node/polymorphic_enum_inner_build_ast_node.rs +++ b/ast-generator/src/ast_node/polymorphic_enum_inner_build_ast_node.rs @@ -1,5 +1,7 @@ +use crate::spec::polymorphic_enum_inner_build::{ + PolymorphicEnumInnerBuild, PolymorphicEnumInnerBuildMemberKind, +}; use convert_case::{Case, Casing}; -use crate::spec::polymorphic_enum_inner_build::{PolymorphicEnumInnerBuild, PolymorphicEnumInnerBuildMemberKind}; use proc_macro2::TokenStream; use quote::{format_ident, quote}; @@ -8,7 +10,8 @@ pub fn make_polymorphic_enum_inner_build_ast_node_impl( ) -> TokenStream { let type_ident = format_ident!("{}", spec.name()); - let match_arms = spec.members() + let match_arms = spec + .members() .map(|member| { let member_ident = format_ident!("{}", member.name()); match member.kind() { @@ -25,11 +28,12 @@ pub fn make_polymorphic_enum_inner_build_ast_node_impl( ] } } - } + } }) .collect::>(); - - let mut_match_arms = spec.members() + + let mut_match_arms = spec + .members() .map(|member| { let member_ident = format_ident!("{}", member.name()); match member.kind() { @@ -49,7 +53,7 @@ pub fn make_polymorphic_enum_inner_build_ast_node_impl( } }) .collect::>(); - + quote! { impl<'a> AstNode<'a> for #type_ident { fn children(&'a self) -> Vec<&'a dyn AstNode<'a>> { diff --git a/ast-generator/src/build_fn/node_production_build_fn.rs b/ast-generator/src/build_fn/node_production_build_fn.rs index 0cab792..a666460 100644 --- a/ast-generator/src/build_fn/node_production_build_fn.rs +++ b/ast-generator/src/build_fn/node_production_build_fn.rs @@ -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 return_type_ident = format_ident!("{}", spec.kind()); let inner_build_fn_ident = format_ident!("{}", spec.with()); - + quote! { fn #build_fn_ident(file_id: usize, #pair_ident: Pair) -> #return_type_ident { let inner_pair = #pair_ident.into_inner().next().unwrap(); #inner_build_fn_ident(file_id, inner_pair) } } -} \ No newline at end of file +} diff --git a/ast-generator/src/build_fn/polymorphic_enum_inner_build_build_fn.rs b/ast-generator/src/build_fn/polymorphic_enum_inner_build_build_fn.rs index 5591acc..0b0b85f 100644 --- a/ast-generator/src/build_fn/polymorphic_enum_inner_build_build_fn.rs +++ b/ast-generator/src/build_fn/polymorphic_enum_inner_build_build_fn.rs @@ -1,14 +1,15 @@ +use crate::deserialize::util::{make_build_fn_name, make_build_pair}; use crate::spec::polymorphic_enum_inner_build::PolymorphicEnumInnerBuild; use proc_macro2::TokenStream; 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 { let build_fn_ident = format_ident!("{}", make_build_fn_name(spec.name())); let pair_ident = format_ident!("{}", make_build_pair(spec.name())); let return_type_ident = format_ident!("{}", spec.name()); - - let rule_branches = spec.rules() + + let rule_branches = spec + .rules() .map(|rule| { let rule_ident = format_ident!("{}", rule.name()); 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::>(); - + quote! { fn #build_fn_ident(file_id: usize, #pair_ident: Pair) -> #return_type_ident { let inner_pair = #pair_ident.into_inner().next().unwrap(); diff --git a/ast-generator/src/build_fn/polymorphic_enum_loop_build_fn.rs b/ast-generator/src/build_fn/polymorphic_enum_loop_build_fn.rs index 2825bd4..847a819 100644 --- a/ast-generator/src/build_fn/polymorphic_enum_loop_build_fn.rs +++ b/ast-generator/src/build_fn/polymorphic_enum_loop_build_fn.rs @@ -1,10 +1,10 @@ use crate::deserialize::util::{make_build_fn_name, make_build_pair}; +use crate::spec::SpecialChildKind; use crate::spec::polymorphic_enum_loop_spec::{ PolymorphicEnumLoopBuildSpec, PolymorphicEnumLoopRule, PolymorphicEnumLoopRuleBuild, PolymorphicEnumLoopRuleBuildChild, PolymorphicEnumLoopRuleChildOnEach, PolymorphicEnumLoopRulePassThrough, }; -use crate::spec::SpecialChildKind; use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote}; diff --git a/ast-generator/src/build_fn/polymorphic_leaf_enum_build_fn.rs b/ast-generator/src/build_fn/polymorphic_leaf_enum_build_fn.rs index 5dad9ad..4bb7a56 100644 --- a/ast-generator/src/build_fn/polymorphic_leaf_enum_build_fn.rs +++ b/ast-generator/src/build_fn/polymorphic_leaf_enum_build_fn.rs @@ -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 pair_ident = format_ident!("{}_pair", spec.name().to_case(Case::Snake)); let return_type_ident = format_ident!("{}", spec.kind()); - - let child_matchers = spec.rules() + + let child_matchers = spec + .rules() .map(|rule| { let rule_ident = format_ident!("{}", rule); quote! { Rule::#rule_ident => #return_type_ident::#rule_ident - } + } }) .collect::>(); - + quote! { fn #build_fn_ident(file_id: usize, #pair_ident: Pair) -> #return_type_ident { let inner_pair = #pair_ident.into_inner().next().unwrap(); diff --git a/ast-generator/src/build_fn/tree_enum_build_fn.rs b/ast-generator/src/build_fn/tree_enum_build_fn.rs index 323dbf2..f18b0fe 100644 --- a/ast-generator/src/build_fn/tree_enum_build_fn.rs +++ b/ast-generator/src/build_fn/tree_enum_build_fn.rs @@ -15,8 +15,7 @@ pub fn make_enum_build_fn(enum_build_spec: &TreeEnumBuildSpec) -> TokenStream { if let Some(child) = enum_rule.child() { let inner_builder = match child.kind() { EnumRuleChildKind::Node(node_child) => { - let inner_build_fn_ident = - format_ident!("{}", node_child.with()); + let inner_build_fn_ident = format_ident!("{}", node_child.with()); quote! { #inner_build_fn_ident(file_id, inner_pair) } } EnumRuleChildKind::Int(name_and_with) => { diff --git a/ast-generator/src/deserialize/leaf_enum_spec.rs b/ast-generator/src/deserialize/leaf_enum_spec.rs index bb145ac..3de6040 100644 --- a/ast-generator/src/deserialize/leaf_enum_spec.rs +++ b/ast-generator/src/deserialize/leaf_enum_spec.rs @@ -1,13 +1,12 @@ -use yaml_rust2::Yaml; use crate::spec::leaf_enum_spec::LeafEnumBuildSpec; +use yaml_rust2::Yaml; pub fn deserialize_leaf_enum(name: &str, props: &Yaml) -> LeafEnumBuildSpec { - let rules = props["rules"].as_vec() + let rules = props["rules"] + .as_vec() .unwrap() .iter() - .map(|rule_yaml| { - rule_yaml.as_str().unwrap().to_string() - }) + .map(|rule_yaml| rule_yaml.as_str().unwrap().to_string()) .collect(); LeafEnumBuildSpec::new(name, rules) } diff --git a/ast-generator/src/deserialize/leaf_struct_spec.rs b/ast-generator/src/deserialize/leaf_struct_spec.rs index 73b1115..d409ae6 100644 --- a/ast-generator/src/deserialize/leaf_struct_spec.rs +++ b/ast-generator/src/deserialize/leaf_struct_spec.rs @@ -1,13 +1,13 @@ use crate::deserialize::util::unwrap_single_member_hash; -use yaml_rust2::Yaml; use crate::spec::leaf_struct_spec::{LeafStructBuildSpec, LeafStructMember, LeafStructMemberKind}; +use yaml_rust2::Yaml; fn deserialize_member(member_name: &str, member_props: &Yaml) -> LeafStructMember { let kind = match member_props["kind"].as_str().unwrap() { "string" => LeafStructMemberKind::String, "file_id" => LeafStructMemberKind::FileId, "range" => LeafStructMemberKind::Range, - _ => panic!() + _ => panic!(), }; LeafStructMember::new(member_name, kind) } @@ -26,12 +26,12 @@ pub fn deserialize_leaf_struct(name: &str, props: &Yaml) -> LeafStructBuildSpec let derive = props["derive"] .as_vec() .map(|derive_yaml| { - derive_yaml.iter() - .map(|trait_yaml| { - trait_yaml.as_str().unwrap().to_string() - }).collect::>() + derive_yaml + .iter() + .map(|trait_yaml| trait_yaml.as_str().unwrap().to_string()) + .collect::>() }) .unwrap_or_default(); - + LeafStructBuildSpec::new(name, members, derive) } diff --git a/ast-generator/src/deserialize/mod.rs b/ast-generator/src/deserialize/mod.rs index da1f801..dc46846 100644 --- a/ast-generator/src/deserialize/mod.rs +++ b/ast-generator/src/deserialize/mod.rs @@ -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_leaf_enum::deserialize_polymorphic_leaf_enum; 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::production_spec::deserialize_production; use crate::deserialize::struct_spec::deserialize_struct_spec; use crate::deserialize::tree_enum_spec::deserialize_tree_enum; use crate::spec::BuildSpec; 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 { if build_spec["struct"].is_hash() { diff --git a/ast-generator/src/deserialize/polymorphic_enum_loop_spec.rs b/ast-generator/src/deserialize/polymorphic_enum_loop_spec.rs index 8f62524..a65a7fd 100644 --- a/ast-generator/src/deserialize/polymorphic_enum_loop_spec.rs +++ b/ast-generator/src/deserialize/polymorphic_enum_loop_spec.rs @@ -46,21 +46,17 @@ fn deserialize_build(name: &str, props: &Yaml) -> PolymorphicEnumLoopRuleBuild { let fields = props["fields"] .as_vec() .map(|fields| { - fields.iter() + fields + .iter() .map(|field_yaml| { let (field_name, field_props) = unwrap_single_member_hash(field_yaml); let kind = field_props["kind"].as_str().unwrap(); - StructField::new( - &field_name, - kind, - None, - false - ) + StructField::new(&field_name, kind, None, false) }) .collect::>() }) .unwrap_or_else(|| vec![]); - + PolymorphicEnumLoopRuleBuild::new(name, variant, children, fields) } diff --git a/ast-generator/src/deserialize/polymorphic_leaf_enum.rs b/ast-generator/src/deserialize/polymorphic_leaf_enum.rs index 4d31973..ca44ab4 100644 --- a/ast-generator/src/deserialize/polymorphic_leaf_enum.rs +++ b/ast-generator/src/deserialize/polymorphic_leaf_enum.rs @@ -1,13 +1,13 @@ -use yaml_rust2::Yaml; use crate::spec::polymorphic_leaf_enum::PolymorphicLeafEnum; +use yaml_rust2::Yaml; pub fn deserialize_polymorphic_leaf_enum(name: &str, props: &Yaml) -> PolymorphicLeafEnum { let kind = props["kind"].as_str().unwrap(); - let rules = props["rules"].as_vec().unwrap() + let rules = props["rules"] + .as_vec() + .unwrap() .iter() - .map(|rule| { - rule.as_str().unwrap().to_string() - }) + .map(|rule| rule.as_str().unwrap().to_string()) .collect::>(); PolymorphicLeafEnum::new(name, kind, rules) -} \ No newline at end of file +} diff --git a/ast-generator/src/deserialize/polymorphic_pass_through_spec.rs b/ast-generator/src/deserialize/polymorphic_pass_through_spec.rs index dd3ac17..b64f9a1 100644 --- a/ast-generator/src/deserialize/polymorphic_pass_through_spec.rs +++ b/ast-generator/src/deserialize/polymorphic_pass_through_spec.rs @@ -1,10 +1,17 @@ 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; -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 variants = props["variants"].as_vec().unwrap() + let variants = props["variants"] + .as_vec() + .unwrap() .iter() .map(|variant_yaml| { let (variant_name, variant_props) = unwrap_single_member_hash(variant_yaml); diff --git a/ast-generator/src/deserialize/polymorphic_tree_enum.rs b/ast-generator/src/deserialize/polymorphic_tree_enum.rs index b78c474..e3c005a 100644 --- a/ast-generator/src/deserialize/polymorphic_tree_enum.rs +++ b/ast-generator/src/deserialize/polymorphic_tree_enum.rs @@ -1,12 +1,14 @@ -use yaml_rust2::Yaml; use crate::spec::polymorphic_tree_enum_spec::PolymorphicTreeEnumSpec; +use yaml_rust2::Yaml; pub fn deserialize_polymorphic_tree_enum(name: &str, props: &Yaml) -> PolymorphicTreeEnumSpec { let kind = props["kind"].as_str().unwrap(); - let rules = props["rules"].as_vec().unwrap() + let rules = props["rules"] + .as_vec() + .unwrap() .iter() .map(|rule| rule.as_str().unwrap()) .collect::>(); - + PolymorphicTreeEnumSpec::new(name, kind, &rules) -} \ No newline at end of file +} diff --git a/ast-generator/src/deserialize/polymorphic_type_spec.rs b/ast-generator/src/deserialize/polymorphic_type_spec.rs index 54d34c8..17d58ad 100644 --- a/ast-generator/src/deserialize/polymorphic_type_spec.rs +++ b/ast-generator/src/deserialize/polymorphic_type_spec.rs @@ -4,7 +4,7 @@ use yaml_rust2::Yaml; fn deserialize_variant(variant_name: &str, props: &Yaml) -> PolymorphicTypeVariant { 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 { @@ -20,4 +20,4 @@ pub fn deserialize_polymorphic_type(name: &str, props: &Yaml) -> PolymorphicType .collect(); let kind = props["build"]["kind"].as_str().unwrap(); PolymorphicTypeBuildSpec::new(name, variants, kind) -} \ No newline at end of file +} diff --git a/ast-generator/src/deserialize/production_spec.rs b/ast-generator/src/deserialize/production_spec.rs index 34ea86c..2e40053 100644 --- a/ast-generator/src/deserialize/production_spec.rs +++ b/ast-generator/src/deserialize/production_spec.rs @@ -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; 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() { "string_inner" => ProductionStringFrom::StringInner, "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) - }, + } "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) } diff --git a/ast-generator/src/deserialize/tree_enum_spec.rs b/ast-generator/src/deserialize/tree_enum_spec.rs index 2090096..6980565 100644 --- a/ast-generator/src/deserialize/tree_enum_spec.rs +++ b/ast-generator/src/deserialize/tree_enum_spec.rs @@ -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::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; fn deserialize_hash_enum_rule(rule: &str, props: &Yaml) -> TreeEnumRule { if get_as_bool_or(&props["child"], true) { - let name_and_with = NameAndWith::new( - &rule.to_case(Case::Snake), - &make_build_fn_name(rule) - ); + let name_and_with = NameAndWith::new(&rule.to_case(Case::Snake), &make_build_fn_name(rule)); let kind = match props["kind"].as_str().unwrap() { "int" => EnumRuleChildKind::Int(name_and_with), "long" => EnumRuleChildKind::Long(name_and_with), @@ -28,10 +28,7 @@ fn deserialize_string_enum_rule(rule: &str) -> TreeEnumRule { TreeEnumRule::new( rule, Some(Box::new(EnumRuleChild::new(Box::new( - EnumRuleChildKind::Node(EnumRuleChildNodeKind::new( - rule, - &make_build_fn_name(rule) - )), + EnumRuleChildKind::Node(EnumRuleChildNodeKind::new(rule, &make_build_fn_name(rule))), )))), ) } diff --git a/ast-generator/src/pretty_print.rs b/ast-generator/src/pretty_print.rs index 8317e8b..2b94124 100644 --- a/ast-generator/src/pretty_print.rs +++ b/ast-generator/src/pretty_print.rs @@ -1,3 +1,4 @@ +use crate::spec::BuildSpec; use crate::spec::leaf_enum_spec::LeafEnumBuildSpec; use crate::spec::leaf_struct_spec::{LeafStructBuildSpec, LeafStructMemberKind}; 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::struct_spec::{MemberChildBuild, StructChild, StructSpec, VecChildBuild}; use crate::spec::tree_enum_spec::{EnumRuleChildKind, TreeEnumBuildSpec}; -use crate::spec::BuildSpec; use convert_case::{Case, Casing}; use proc_macro2::TokenStream; use quote::{format_ident, quote}; diff --git a/ast-generator/src/spec/leaf_enum_spec.rs b/ast-generator/src/spec/leaf_enum_spec.rs index 5c687fc..1d6c70c 100644 --- a/ast-generator/src/spec/leaf_enum_spec.rs +++ b/ast-generator/src/spec/leaf_enum_spec.rs @@ -18,4 +18,4 @@ impl LeafEnumBuildSpec { pub fn rules(&self) -> impl Iterator { self.rules.iter().map(AsRef::as_ref) } -} \ No newline at end of file +} diff --git a/ast-generator/src/spec/leaf_struct_spec.rs b/ast-generator/src/spec/leaf_struct_spec.rs index e148c31..42e74fe 100644 --- a/ast-generator/src/spec/leaf_struct_spec.rs +++ b/ast-generator/src/spec/leaf_struct_spec.rs @@ -20,7 +20,7 @@ impl LeafStructBuildSpec { pub fn members(&self) -> impl Iterator { self.members.iter().map(Box::as_ref) } - + pub fn derive(&self) -> impl Iterator { self.derive.iter().map(String::as_str) } @@ -51,5 +51,5 @@ impl LeafStructMember { pub enum LeafStructMemberKind { String, FileId, - Range + Range, } diff --git a/ast-generator/src/spec/node_production_spec.rs b/ast-generator/src/spec/node_production_spec.rs index 2f019a6..98e73ee 100644 --- a/ast-generator/src/spec/node_production_spec.rs +++ b/ast-generator/src/spec/node_production_spec.rs @@ -1,7 +1,7 @@ pub struct NodeProductionBuildSpec { name: String, kind: String, - with: String + with: String, } impl NodeProductionBuildSpec { @@ -9,19 +9,19 @@ impl NodeProductionBuildSpec { Self { name: name.to_string(), kind: kind.to_string(), - with: with.to_string() + with: with.to_string(), } } - + pub fn name(&self) -> &str { &self.name } - + pub fn kind(&self) -> &str { &self.kind } - + pub fn with(&self) -> &str { &self.with } -} \ No newline at end of file +} diff --git a/ast-generator/src/spec/polymorphic_enum_inner_build.rs b/ast-generator/src/spec/polymorphic_enum_inner_build.rs index 64c7b35..6d871bf 100644 --- a/ast-generator/src/spec/polymorphic_enum_inner_build.rs +++ b/ast-generator/src/spec/polymorphic_enum_inner_build.rs @@ -5,7 +5,11 @@ pub struct PolymorphicEnumInnerBuild { } impl PolymorphicEnumInnerBuild { - pub fn new(name: &str, members: Vec, rules: Vec) -> Self { + pub fn new( + name: &str, + members: Vec, + rules: Vec, + ) -> Self { Self { name: name.to_string(), members, @@ -28,21 +32,21 @@ impl PolymorphicEnumInnerBuild { pub struct PolymorphicEnumInnerBuildMember { name: String, - kind: PolymorphicEnumInnerBuildMemberKind + kind: PolymorphicEnumInnerBuildMemberKind, } impl PolymorphicEnumInnerBuildMember { pub fn new(name: &str, kind: PolymorphicEnumInnerBuildMemberKind) -> Self { Self { name: name.to_string(), - kind + kind, } } - + pub fn name(&self) -> &str { &self.name } - + pub fn kind(&self) -> &PolymorphicEnumInnerBuildMemberKind { &self.kind } @@ -50,7 +54,7 @@ impl PolymorphicEnumInnerBuildMember { pub enum PolymorphicEnumInnerBuildMemberKind { Leaf, - Struct + Struct, } pub struct PolymorphicEnumInnerBuildRule { @@ -65,12 +69,12 @@ impl PolymorphicEnumInnerBuildRule { with: with.to_string(), } } - + pub fn name(&self) -> &str { &self.name } - + pub fn with(&self) -> &str { &self.with } -} \ No newline at end of file +} diff --git a/ast-generator/src/spec/polymorphic_enum_loop_spec.rs b/ast-generator/src/spec/polymorphic_enum_loop_spec.rs index 7b3256d..1bbaeaa 100644 --- a/ast-generator/src/spec/polymorphic_enum_loop_spec.rs +++ b/ast-generator/src/spec/polymorphic_enum_loop_spec.rs @@ -105,7 +105,7 @@ impl PolymorphicEnumLoopRuleBuild { pub fn children(&self) -> impl Iterator { self.children.iter().map(Box::as_ref) } - + pub fn fields(&self) -> &[StructField] { &self.fields } diff --git a/ast-generator/src/spec/polymorphic_tree_enum_spec.rs b/ast-generator/src/spec/polymorphic_tree_enum_spec.rs index c5c2691..6ba3bed 100644 --- a/ast-generator/src/spec/polymorphic_tree_enum_spec.rs +++ b/ast-generator/src/spec/polymorphic_tree_enum_spec.rs @@ -12,16 +12,16 @@ impl PolymorphicTreeEnumSpec { rules: rules.iter().map(ToString::to_string).collect(), } } - + pub fn name(&self) -> &str { &self.name } - + pub fn kind(&self) -> &str { &self.kind } - + pub fn rules(&self) -> impl Iterator { self.rules.iter().map(AsRef::as_ref) } -} \ No newline at end of file +} diff --git a/ast-generator/src/spec/tree_enum_spec.rs b/ast-generator/src/spec/tree_enum_spec.rs index 4de0d35..8da2095 100644 --- a/ast-generator/src/spec/tree_enum_spec.rs +++ b/ast-generator/src/spec/tree_enum_spec.rs @@ -88,7 +88,7 @@ impl EnumRuleChildNodeKind { pub fn node_kind(&self) -> &str { &self.node_kind } - + pub fn with(&self) -> &str { &self.with } @@ -106,11 +106,11 @@ impl NameAndWith { with: with.to_string(), } } - + pub fn name(&self) -> &str { &self.name } - + pub fn with(&self) -> &str { &self.with } diff --git a/ast-generator/src/type_gen/enum_type.rs b/ast-generator/src/type_gen/enum_type.rs index d2dc2c6..c59297d 100644 --- a/ast-generator/src/type_gen/enum_type.rs +++ b/ast-generator/src/type_gen/enum_type.rs @@ -1,6 +1,6 @@ +use crate::spec::tree_enum_spec::{EnumRuleChildKind, TreeEnumBuildSpec}; use proc_macro2::TokenStream; use quote::{format_ident, quote}; -use crate::spec::tree_enum_spec::{EnumRuleChildKind, TreeEnumBuildSpec}; pub fn make_enum_type(build_spec: &TreeEnumBuildSpec) -> TokenStream { let children: Vec = build_spec @@ -34,4 +34,4 @@ pub fn make_enum_type(build_spec: &TreeEnumBuildSpec) -> TokenStream { #(#children),* } } -} \ No newline at end of file +} diff --git a/ast-generator/src/type_gen/leaf_struct_type.rs b/ast-generator/src/type_gen/leaf_struct_type.rs index 6bdce5f..bee5904 100644 --- a/ast-generator/src/type_gen/leaf_struct_type.rs +++ b/ast-generator/src/type_gen/leaf_struct_type.rs @@ -84,10 +84,11 @@ pub fn make_leaf_struct_type(build_spec: &LeafStructBuildSpec) -> TokenStream { .collect::>(); let struct_stream = if build_spec.derive().count() > 0 { - let derives = build_spec.derive().map(|derive| { - format_ident!("{}", derive) - }).collect::>(); - + let derives = build_spec + .derive() + .map(|derive| format_ident!("{}", derive)) + .collect::>(); + quote! { #[derive(#(#derives),*)] pub struct #type_ident { @@ -101,7 +102,7 @@ pub fn make_leaf_struct_type(build_spec: &LeafStructBuildSpec) -> TokenStream { } } }; - + quote! { #struct_stream diff --git a/ast-generator/src/type_gen/polymorphic_enum_inner_build_type.rs b/ast-generator/src/type_gen/polymorphic_enum_inner_build_type.rs index 57d7d6d..be195fa 100644 --- a/ast-generator/src/type_gen/polymorphic_enum_inner_build_type.rs +++ b/ast-generator/src/type_gen/polymorphic_enum_inner_build_type.rs @@ -1,9 +1,12 @@ +use crate::spec::polymorphic_enum_inner_build::{ + PolymorphicEnumInnerBuild, PolymorphicEnumInnerBuildMemberKind, +}; use proc_macro2::TokenStream; 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 { - let members = spec.members() + let members = spec + .members() .map(|member| { let name_ident = format_ident!("{}", member.name()); match member.kind() { @@ -22,4 +25,4 @@ pub fn make_polymorphic_enum_inner_build_type(spec: &PolymorphicEnumInnerBuild) #(#members,)* } } -} \ No newline at end of file +} diff --git a/ast-generator/src/type_gen/polymorphic_enum_loop_type.rs b/ast-generator/src/type_gen/polymorphic_enum_loop_type.rs index 1eb2a65..a106144 100644 --- a/ast-generator/src/type_gen/polymorphic_enum_loop_type.rs +++ b/ast-generator/src/type_gen/polymorphic_enum_loop_type.rs @@ -1,7 +1,7 @@ +use crate::spec::SpecialChildKind; use crate::spec::polymorphic_enum_loop_spec::{ PolymorphicEnumLoopBuildSpec, PolymorphicEnumLoopRule, PolymorphicEnumLoopRuleBuildChild, }; -use crate::spec::SpecialChildKind; use proc_macro2::TokenStream; use quote::{format_ident, quote}; diff --git a/build.rs b/build.rs index 96f819c..d236ab4 100644 --- a/build.rs +++ b/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 std::env; use std::fs; diff --git a/src/asm/assemble_ir.rs b/src/asm/assemble_ir.rs index fc67444..dcd064f 100644 --- a/src/asm/assemble_ir.rs +++ b/src/asm/assemble_ir.rs @@ -191,14 +191,12 @@ fn assemble_ir_call(ir_call: &IrCall, context: &mut AssemblyContext) { } fn assemble_ir_return(ir_return: &IrReturn, context: &mut AssemblyContext) { - let operand = ir_return.expression().map(|expression| { - match expression { - IrExpression::Variable(ir_variable) => { - let variable_virtual_register_id = context.get_virtual_register(ir_variable.name()); - AsmOperand::VirtualRegister(variable_virtual_register_id) - } - IrExpression::Literal(ir_literal) => ir_literal_to_asm_operand(ir_literal), + let operand = ir_return.expression().map(|expression| match expression { + IrExpression::Variable(ir_variable) => { + let variable_virtual_register_id = context.get_virtual_register(ir_variable.name()); + AsmOperand::VirtualRegister(variable_virtual_register_id) } + IrExpression::Literal(ir_literal) => ir_literal_to_asm_operand(ir_literal), }); context .current_control_unit_mut() diff --git a/src/bin/dmc/cst.rs b/src/bin/dmc/cst.rs index 231fe2a..f62d56d 100644 --- a/src/bin/dmc/cst.rs +++ b/src/bin/dmc/cst.rs @@ -1,7 +1,7 @@ use deimos::parser::{DeimosParser, Rule}; -use std::path::PathBuf; use pest::iterators::{Pair, Pairs}; use pest::Parser; +use std::path::PathBuf; fn print_pair(pair: Pair) { println!("{:?}", pair.as_rule()); @@ -27,4 +27,4 @@ pub fn show_cst(path: &PathBuf) { eprintln!("{:?}", error); } } -} \ No newline at end of file +} diff --git a/src/bin/dmc/name_analysis.rs b/src/bin/dmc/name_analysis.rs index dd9001c..e79906e 100644 --- a/src/bin/dmc/name_analysis.rs +++ b/src/bin/dmc/name_analysis.rs @@ -2,6 +2,7 @@ use codespan_reporting::files::SimpleFiles; use codespan_reporting::term; use codespan_reporting::term::termcolor::{ColorChoice, StandardStream}; use deimos::ast::build::build_ast; +use deimos::ast::node::CompilationUnit; use deimos::name_analysis::analyze_names; use deimos::name_analysis::symbol_table::SymbolTable; use deimos::parser::{DeimosParser, Rule}; @@ -10,7 +11,6 @@ use pest::Parser; use std::collections::HashMap; use std::fmt::{Debug, Display, Formatter}; use std::path::PathBuf; -use deimos::ast::node::CompilationUnit; struct ParseErrors { errors: Vec>, @@ -34,7 +34,9 @@ impl Display for ParseErrors { impl std::error::Error for ParseErrors {} -pub fn name_analysis(paths: &[PathBuf]) -> Result, Box> { +pub fn name_analysis( + paths: &[PathBuf], +) -> Result, Box> { let mut paths_and_sources: HashMap = HashMap::new(); for path in paths { let src = std::fs::read_to_string(path).unwrap(); diff --git a/src/ir/lower_ast.rs b/src/ir/lower_ast.rs index f21860a..456fb17 100644 --- a/src/ir/lower_ast.rs +++ b/src/ir/lower_ast.rs @@ -8,10 +8,10 @@ use crate::ir::{ IrPrimitiveKind, IrReturn, IrStatement, IrStructKind, IrVariable, }; use crate::name_analysis::symbol::{ClassSymbol, ParameterSymbol, PrimitiveTypeSymbol, TypeSymbol}; +use crate::type_analysis::kinds::Kind; use std::cell::RefCell; use std::ops::Deref; use std::rc::Rc; -use crate::type_analysis::kinds::Kind; struct CuContext { irs: Vec, diff --git a/src/name_analysis/second_pass.rs b/src/name_analysis/second_pass.rs index 989f1ed..fea5973 100644 --- a/src/name_analysis/second_pass.rs +++ b/src/name_analysis/second_pass.rs @@ -1,12 +1,12 @@ use crate::ast::node::{ - AssignmentStatement, BacktickString, Call, Closure, ClosureParameters, - CompilationUnit, ConcreteUseStatement, ConcreteUseStatementSuffix, DString, Expression, - ExpressionList, ExpressionStatement, Function, FunctionAliasBody, FunctionBlockBody, - FunctionBody, FunctionEqualsBody, GenericParameters, Identifier, IdentifierExpression, - IdentifierOrFqn, LValue, LValueSuffix, Literal, ModuleLevelDeclaration - , ObjectIndex, Parameter, Parameters, PlatformFunction, PrimitiveType, - ReturnType, StarUseStatement, Statement, SuffixExpression, SuffixOperator, TypeUse, TypedArray, - UseStatement, UseStatementIdentifier, UseStatementPrefix, VariableDeclaration, + AssignmentStatement, BacktickString, Call, Closure, ClosureParameters, CompilationUnit, + ConcreteUseStatement, ConcreteUseStatementSuffix, DString, Expression, ExpressionList, + ExpressionStatement, Function, FunctionAliasBody, FunctionBlockBody, FunctionBody, + FunctionEqualsBody, GenericParameters, Identifier, IdentifierExpression, IdentifierOrFqn, + LValue, LValueSuffix, Literal, ModuleLevelDeclaration, ObjectIndex, Parameter, Parameters, + PlatformFunction, PrimitiveType, ReturnType, StarUseStatement, Statement, SuffixExpression, + SuffixOperator, TypeUse, TypedArray, UseStatement, UseStatementIdentifier, UseStatementPrefix, + VariableDeclaration, }; use crate::diagnostic::DmDiagnostic; use crate::name_analysis::symbol::source_definition::SourceDefinition; @@ -529,7 +529,11 @@ fn na_p2_variable_declaration( } // 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( @@ -628,7 +632,11 @@ fn na_p2_expression( } Expression::Additive(additive) => { 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) => { todo!() diff --git a/src/name_analysis/symbol/class_symbol.rs b/src/name_analysis/symbol/class_symbol.rs index ea7f50a..ed3322d 100644 --- a/src/name_analysis/symbol/class_symbol.rs +++ b/src/name_analysis/symbol/class_symbol.rs @@ -23,15 +23,15 @@ impl ClassSymbol { source_definition, } } - + pub fn fqn_formatted(&self) -> String { self.fqn_parts.join("::") } - + pub fn declared_name(&self) -> &str { self.fqn_parts.last().unwrap() } - + pub fn declared_name_owned(&self) -> Rc { self.fqn_parts.last().unwrap().clone() } diff --git a/src/name_analysis/symbol/expressible_symbol.rs b/src/name_analysis/symbol/expressible_symbol.rs index ba0a5b5..ed2f42f 100644 --- a/src/name_analysis/symbol/expressible_symbol.rs +++ b/src/name_analysis/symbol/expressible_symbol.rs @@ -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::rc::Rc; @@ -13,9 +15,7 @@ pub enum ExpressibleSymbol { impl ExpressibleSymbol { pub fn to_symbol(self) -> Rc> { match self { - ExpressibleSymbol::Class(class_symbol) => { - class_symbol as Rc> - } + ExpressibleSymbol::Class(class_symbol) => class_symbol as Rc>, ExpressibleSymbol::Function(function_symbol) => { function_symbol as Rc> } diff --git a/src/name_analysis/symbol/function_symbol.rs b/src/name_analysis/symbol/function_symbol.rs index d1468c3..a090d7f 100644 --- a/src/name_analysis/symbol/function_symbol.rs +++ b/src/name_analysis/symbol/function_symbol.rs @@ -50,7 +50,7 @@ impl FunctionSymbol { return_type, } } - + pub fn fqn_formatted(&self) -> String { self.fqn_parts.join("::") } @@ -82,11 +82,11 @@ impl FunctionSymbol { pub fn set_parameter_symbols(&mut self, parameter_symbols: Vec>>) { self.parameters = parameter_symbols; } - + pub fn return_type(&self) -> Option<&TypeSymbol> { self.return_type.as_ref() } - + pub fn return_type_owned(&self) -> Option { self.return_type.clone() } diff --git a/src/name_analysis/symbol/generic_type_symbol.rs b/src/name_analysis/symbol/generic_type_symbol.rs index c821e35..417e0fc 100644 --- a/src/name_analysis/symbol/generic_type_symbol.rs +++ b/src/name_analysis/symbol/generic_type_symbol.rs @@ -20,7 +20,7 @@ impl GenericTypeSymbol { pub fn declared_name(&self) -> &str { &self.declared_name } - + pub fn declared_name_owned(&self) -> Rc { self.declared_name.clone() } diff --git a/src/name_analysis/symbol/interface_symbol.rs b/src/name_analysis/symbol/interface_symbol.rs index 678f42e..a036de6 100644 --- a/src/name_analysis/symbol/interface_symbol.rs +++ b/src/name_analysis/symbol/interface_symbol.rs @@ -20,11 +20,11 @@ impl InterfaceSymbol { source_definition, } } - + pub fn declared_name(&self) -> &str { self.fqn_parts.last().unwrap().as_ref() } - + pub fn declared_name_owned(&self) -> Rc { self.fqn_parts.last().unwrap().clone() } diff --git a/src/name_analysis/symbol/lv_symbol.rs b/src/name_analysis/symbol/lv_symbol.rs index d174f3d..dc62d9d 100644 --- a/src/name_analysis/symbol/lv_symbol.rs +++ b/src/name_analysis/symbol/lv_symbol.rs @@ -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::parameter_symbol::ParameterSymbol; -use crate::name_analysis::symbol::Symbol; 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 { ClassMember(Rc>), @@ -17,12 +17,8 @@ impl LVSymbol { LVSymbol::ClassMember(class_member_symbol) => { class_member_symbol as Rc> } - LVSymbol::Parameter(parameter_symbol) => { - parameter_symbol as Rc> - } - LVSymbol::Variable(variable_symbol) => { - variable_symbol as Rc> - } + LVSymbol::Parameter(parameter_symbol) => parameter_symbol as Rc>, + LVSymbol::Variable(variable_symbol) => variable_symbol as Rc>, } } -} \ No newline at end of file +} diff --git a/src/name_analysis/symbol/parameter_symbol.rs b/src/name_analysis/symbol/parameter_symbol.rs index f7a25d7..bd6d86a 100644 --- a/src/name_analysis/symbol/parameter_symbol.rs +++ b/src/name_analysis/symbol/parameter_symbol.rs @@ -30,11 +30,11 @@ impl ParameterSymbol { pub fn declared_name_owned(&self) -> Rc { self.declared_name.clone() } - + pub fn type_symbol(&self) -> Option<&TypeSymbol> { self.type_symbol.as_ref() } - + pub fn type_symbol_mut(&mut self) -> Option<&mut TypeSymbol> { self.type_symbol.as_mut() } diff --git a/src/name_analysis/symbol/source_definition.rs b/src/name_analysis/symbol/source_definition.rs index 02f29e9..d090fd3 100644 --- a/src/name_analysis/symbol/source_definition.rs +++ b/src/name_analysis/symbol/source_definition.rs @@ -36,4 +36,4 @@ impl SourceDefinition { pub fn range(&self) -> Range { self.range.clone() } -} \ No newline at end of file +} diff --git a/src/name_analysis/symbol/type_symbol.rs b/src/name_analysis/symbol/type_symbol.rs index 0fad753..669b059 100644 --- a/src/name_analysis/symbol/type_symbol.rs +++ b/src/name_analysis/symbol/type_symbol.rs @@ -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::interface_symbol::InterfaceSymbol; use crate::name_analysis::symbol::primitive_type_symbol::PrimitiveTypeSymbol; +use crate::name_analysis::symbol::Symbol; use std::cell::RefCell; use std::fmt::Debug; use std::rc::Rc; -use crate::name_analysis::symbol::Symbol; #[derive(Debug, Clone)] pub enum TypeSymbol { @@ -21,15 +21,9 @@ impl TypeSymbol { TypeSymbol::Primitive(primitive_type_symbol) => { Rc::new(RefCell::new(primitive_type_symbol)) } - TypeSymbol::Class(class_symbol) => { - class_symbol as Rc> - } - TypeSymbol::Interface(interface_symbol) => { - interface_symbol as Rc> - } - TypeSymbol::Generic(generic_symbol) => { - generic_symbol as Rc> - } + TypeSymbol::Class(class_symbol) => class_symbol as Rc>, + TypeSymbol::Interface(interface_symbol) => interface_symbol as Rc>, + TypeSymbol::Generic(generic_symbol) => generic_symbol as Rc>, } } } diff --git a/src/name_analysis/symbol/use_symbol.rs b/src/name_analysis/symbol/use_symbol.rs index 0a5da5d..a2a0f77 100644 --- a/src/name_analysis/symbol/use_symbol.rs +++ b/src/name_analysis/symbol/use_symbol.rs @@ -43,7 +43,7 @@ impl ConcreteUseSymbol { pub fn declared_name(&self) -> &str { self.fqn_parts.last().unwrap() } - + pub fn declared_name_owned(&self) -> Rc { self.fqn_parts.last().unwrap().clone() } @@ -87,15 +87,15 @@ impl StarUseSymbol { resolved_symbols: vec![], } } - + pub fn fqn_parts(&self) -> &[Rc] { &self.fqn_parts } - + pub fn resolved_symbols(&self) -> &[UsableSymbol] { &self.resolved_symbols } - + pub fn set_resolved_symbols(&mut self, symbols: Vec) { self.resolved_symbols = symbols; } diff --git a/src/name_analysis/symbol/variable_symbol.rs b/src/name_analysis/symbol/variable_symbol.rs index 466d90b..401646a 100644 --- a/src/name_analysis/symbol/variable_symbol.rs +++ b/src/name_analysis/symbol/variable_symbol.rs @@ -1,8 +1,8 @@ use crate::name_analysis::symbol::source_definition::SourceDefinition; use crate::name_analysis::symbol::Symbol; +use crate::type_analysis::kinds::Kind; use std::fmt::{Debug, Formatter}; use std::rc::Rc; -use crate::type_analysis::kinds::Kind; pub struct VariableSymbol { declared_name: Rc, @@ -28,7 +28,7 @@ impl VariableSymbol { pub fn declared_name(&self) -> &str { &self.declared_name } - + pub fn declared_name_owned(&self) -> Rc { self.declared_name.clone() } @@ -36,11 +36,11 @@ impl VariableSymbol { pub fn is_mutable(&self) -> bool { self.is_mutable } - + pub fn set_analyzed_kind(&mut self, analyzed_kind: Kind) { self.analyzed_kind = Some(analyzed_kind); } - + pub fn analyzed_kind(&self) -> Option<&Kind> { self.analyzed_kind.as_ref() } diff --git a/src/name_analysis/symbol_table/fqn_context.rs b/src/name_analysis/symbol_table/fqn_context.rs index 2eb19d9..63c5607 100644 --- a/src/name_analysis/symbol_table/fqn_context.rs +++ b/src/name_analysis/symbol_table/fqn_context.rs @@ -17,11 +17,11 @@ impl FqnContext { pub fn pop(&mut self) { self.stack.pop(); } - + pub fn current_fqn(&self) -> Vec<&str> { self.stack.iter().map(|part| part.as_ref()).collect() } - + pub fn current_fqn_owned(&self) -> Vec> { self.stack.clone() } diff --git a/src/name_analysis/symbol_table/mod.rs b/src/name_analysis/symbol_table/mod.rs index 6d841f6..cd486c3 100644 --- a/src/name_analysis/symbol_table/mod.rs +++ b/src/name_analysis/symbol_table/mod.rs @@ -141,7 +141,9 @@ impl SymbolTable { .find_usable_symbol(concrete_use_symbol.borrow().fqn_parts()) { 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) => { // 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() { 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) => { star_use_symbol_ref_mut.set_resolved_symbols(usable_symbols); } diff --git a/src/name_analysis/symbol_table/scope.rs b/src/name_analysis/symbol_table/scope.rs index 7cb37e7..e272733 100644 --- a/src/name_analysis/symbol_table/scope.rs +++ b/src/name_analysis/symbol_table/scope.rs @@ -69,11 +69,11 @@ impl Scope { pub fn id(&self) -> usize { self.id } - + pub fn concrete_use_symbols(&self) -> impl Iterator>> { self.concrete_use_symbols.values() } - + pub fn star_use_symbols(&self) -> impl Iterator>> { 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 // 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. - // !! 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. self.class_symbols .get(declared_name) @@ -255,16 +255,14 @@ impl Scope { .or_else(|| { if let Some(concrete_use_symbol) = self.concrete_use_symbols.get(declared_name) { return match concrete_use_symbol.borrow().resolved_symbol().unwrap() { - UsableSymbol::Interface(_) => { - None - } + UsableSymbol::Interface(_) => None, UsableSymbol::Class(class_symbol) => { Some(ExpressibleSymbol::Class(class_symbol.clone())) } UsableSymbol::Function(function_symbol) => { Some(ExpressibleSymbol::Function(function_symbol.clone())) } - } + }; } None }) @@ -279,7 +277,9 @@ impl Scope { } UsableSymbol::Function(function_symbol) => { if function_symbol.borrow().declared_name() == declared_name { - return Some(ExpressibleSymbol::Function(function_symbol.clone())); + return Some(ExpressibleSymbol::Function( + function_symbol.clone(), + )); } } _ => continue, diff --git a/src/type_analysis/kinds/class_kind.rs b/src/type_analysis/kinds/class_kind.rs index b278736..edf3621 100644 --- a/src/type_analysis/kinds/class_kind.rs +++ b/src/type_analysis/kinds/class_kind.rs @@ -3,18 +3,18 @@ use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Clone)] pub struct ClassKind { - fqn: Rc + fqn: Rc, } impl ClassKind { pub fn new(fqn: &str) -> Self { Self { fqn: fqn.into() } } - + pub fn fqn(&self) -> &str { &self.fqn } - + pub fn fqn_owned(&self) -> Rc { self.fqn.clone() } @@ -24,4 +24,4 @@ impl Display for ClassKind { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { write!(f, "{}", self.fqn) } -} \ No newline at end of file +} diff --git a/src/type_analysis/kinds/primitive_kind.rs b/src/type_analysis/kinds/primitive_kind.rs index 3ed9504..ae37583 100644 --- a/src/type_analysis/kinds/primitive_kind.rs +++ b/src/type_analysis/kinds/primitive_kind.rs @@ -1,5 +1,5 @@ -use std::fmt::Display; use crate::type_analysis::kinds::Kind; +use std::fmt::Display; #[derive(Debug, Eq, PartialEq, Clone)] pub enum PrimitiveKind { diff --git a/src/type_analysis/mod.rs b/src/type_analysis/mod.rs index e1c3a8a..77b29ca 100644 --- a/src/type_analysis/mod.rs +++ b/src/type_analysis/mod.rs @@ -200,11 +200,10 @@ fn ta_additive_expression( "Incompatible types for additive expression: {} vs. {}", left_kind, right_kind )) - .with_label(Label::primary( - *additive_expression.file_id(), - *additive_expression.range(), - ) - .with_message("Incompatible types here.")), + .with_label( + Label::primary(*additive_expression.file_id(), *additive_expression.range()) + .with_message("Incompatible types here."), + ), ); } additive_expression.set_analyzed_kind(left_kind); diff --git a/src/vm/mem/mod.rs b/src/vm/mem/mod.rs index 8793b1f..852bc0b 100644 --- a/src/vm/mem/mod.rs +++ b/src/vm/mem/mod.rs @@ -394,7 +394,9 @@ impl Drop for GcHeap { let mut current = self.head().take(); while let Some(gc_any) = &mut current { let next = gc_any.next(); - unsafe { gc_any.dealloc(); } + unsafe { + gc_any.dealloc(); + } current = next; } } @@ -464,7 +466,9 @@ fn collect_garbage(stack: &Vec, heap: &mut GcHeap) { } heap.subtract_current_size(current_gc.allocated_size()); collected_size += current_gc.dynamic_size(); - unsafe { current_gc.dealloc(); } + unsafe { + current_gc.dealloc(); + } } else { current_gc.set_color(GcColor::White); previous = Some(current_gc.clone()); diff --git a/src/vm/mod.rs b/src/vm/mod.rs index 3b8b9ed..59b5ecd 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -344,7 +344,7 @@ fn constant_to_value(constant: &DvmConstant) -> DvmValue { fn immediate_to_value(immediate: &Immediate) -> DvmValue { match immediate { - _ => todo!() + _ => todo!(), } }