From f5f7249d716644715d229a361dd2cac1286158cb Mon Sep 17 00:00:00 2001 From: IsaacShelton Date: Sun, 6 Oct 2024 17:43:36 -0500 Subject: [PATCH] Refactored `ResolvedName` to use FsNodeId to identifiy which module it belongs to --- src/inflow/into_inflow/peeker.rs | 2 +- src/lower/mod.rs | 27 +++++++-- src/name.rs | 49 ++++++++++------ src/parser/parse_expr/post/member.rs | 8 ++- src/parser/parse_expr/primary/call.rs | 3 +- src/resolve/expr/call.rs | 4 +- src/resolve/expr/mod.rs | 3 +- src/resolve/expr/struct_literal.rs | 2 +- src/resolve/expr/variable.rs | 12 ++-- src/resolve/function_search_ctx.rs | 17 +++--- src/resolve/global_search_ctx.rs | 4 +- src/resolve/mod.rs | 82 ++++++++++++++++----------- src/resolve/type_search_ctx.rs | 23 +++++--- src/resolved/mod.rs | 9 ++- 14 files changed, 157 insertions(+), 88 deletions(-) diff --git a/src/inflow/into_inflow/peeker.rs b/src/inflow/into_inflow/peeker.rs index 0163d10f..188db9c3 100644 --- a/src/inflow/into_inflow/peeker.rs +++ b/src/inflow/into_inflow/peeker.rs @@ -12,7 +12,7 @@ impl InflowPeeker { pub fn new(stream: S) -> Self { Self { stream, - queue: VecDeque::new(), + queue: VecDeque::with_capacity(8), } } } diff --git a/src/lower/mod.rs b/src/lower/mod.rs index feca46b1..752089ee 100644 --- a/src/lower/mod.rs +++ b/src/lower/mod.rs @@ -81,10 +81,16 @@ fn lower_global( global: &resolved::GlobalVar, resolved_ast: &resolved::Ast, ) -> Result<(), LowerError> { + let mangled_name = if global.is_foreign { + global.name.plain().to_string() + } else { + global.name.display(resolved_ast.fs).to_string() + }; + ir_module.globals.insert( global_ref, Global { - mangled_name: global.name.to_string(), + mangled_name, ir_type: lower_type(&ir_module.target, &global.resolved_type, resolved_ast)?, is_foreign: global.is_foreign, is_thread_local: global.is_thread_local, @@ -161,7 +167,7 @@ fn lower_function( } else { return Err(LowerErrorKind::MustReturnValueOfTypeBeforeExitingFunction { return_type: function.return_type.to_string(), - function: function.name.to_string(), + function: function.name.display(resolved_ast.fs).to_string(), } .at(function.source)); } @@ -194,7 +200,7 @@ fn lower_function( } else if function.is_foreign { function.name.plain().to_string() } else { - function.name.to_string() + function.name.display(resolved_ast.fs).to_string() }; let is_main = mangled_name == "main"; @@ -890,7 +896,10 @@ fn lower_expr( .get(&enum_member_literal.variant_name) .ok_or_else(|| { LowerErrorKind::NoSuchEnumMember { - enum_name: enum_member_literal.enum_name.to_string(), + enum_name: enum_member_literal + .enum_name + .display(resolved_ast.fs) + .to_string(), variant_name: enum_member_literal.variant_name.clone(), } .at(enum_member_literal.source) @@ -907,7 +916,10 @@ fn lower_expr( let make_error = |_| { LowerErrorKind::CannotFit { value: value.to_string(), - expected_type: enum_member_literal.enum_name.to_string(), + expected_type: enum_member_literal + .enum_name + .display(resolved_ast.fs) + .to_string(), } .at(enum_definition.source) }; @@ -939,7 +951,10 @@ fn lower_expr( } _ => { return Err(LowerErrorKind::EnumBackingTypeMustBeInteger { - enum_name: enum_member_literal.enum_name.to_string(), + enum_name: enum_member_literal + .enum_name + .display(resolved_ast.fs) + .to_string(), } .at(enum_definition.source)) } diff --git a/src/name.rs b/src/name.rs index 9a76c29e..419047e9 100644 --- a/src/name.rs +++ b/src/name.rs @@ -1,3 +1,4 @@ +use crate::workspace::fs::{Fs, FsNodeId}; use std::fmt::Display; #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -56,33 +57,47 @@ impl Display for Name { } #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum ResolvedName { - Remote(Box), - Project(Box), +pub struct ResolvedName { + fs_node_id: FsNodeId, + name: Box, } impl ResolvedName { - pub fn new(name: &Name) -> Self { - Self::Project(name.fullname().into_boxed_str()) + pub fn new(fs_node_id: FsNodeId, name: &Name) -> Self { + Self { + fs_node_id, + name: name.fullname().into_boxed_str(), + } } - pub fn new_remote(name: &Name) -> Self { - Self::Remote(name.fullname().into_boxed_str()) + pub fn plain(&self) -> &str { + &*self.name } - pub fn plain(&self) -> &str { - match self { - ResolvedName::Remote(name) => &**name, - ResolvedName::Project(name) => &**name, - } + pub fn display<'a>(&'a self, fs: &'a Fs) -> DisplayResolvedName<'a> { + DisplayResolvedName { name: self, fs } } } -impl Display for ResolvedName { +pub struct DisplayResolvedName<'a> { + name: &'a ResolvedName, + fs: &'a Fs, +} + +impl Display for DisplayResolvedName<'_> { + #[allow(dead_code)] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - ResolvedName::Remote(name) => write!(f, "/{}", name), - ResolvedName::Project(name) => write!(f, "{}", name), - } + let filename = &self.fs.get(self.name.fs_node_id).filename; + let prefix = if cfg!(target_os = "windows") { "/" } else { "" }; + + write!( + f, + "{}{} ::: {}", + prefix, + filename.to_string_lossy(), + self.name.plain() + )?; + + Ok(()) } } diff --git a/src/parser/parse_expr/post/member.rs b/src/parser/parse_expr/post/member.rs index 4371a069..80fd0045 100644 --- a/src/parser/parse_expr/post/member.rs +++ b/src/parser/parse_expr/post/member.rs @@ -14,8 +14,12 @@ impl<'a, I: Inflow> Parser<'a, I> { let source = self.parse_token(TokenKind::Member, Some("for member expression"))?; let member_name = self.parse_name(Some("for member name"))?; - if self.input.peek_is(TokenKind::OpenParen) || self.input.peek_is(TokenKind::OpenAngle) { - let generics = self.parse_generics()?; + let generics = self.parse_generics()?; + + if !generics.is_empty() + || self.input.peek_is(TokenKind::OpenParen) + || self.input.peek_is(TokenKind::OpenAngle) + { self.parse_call_with(member_name, generics, vec![subject], source) } else { Ok(ExprKind::Member( diff --git a/src/parser/parse_expr/primary/call.rs b/src/parser/parse_expr/primary/call.rs index b0dd6280..5f52593f 100644 --- a/src/parser/parse_expr/primary/call.rs +++ b/src/parser/parse_expr/primary/call.rs @@ -28,13 +28,14 @@ impl<'a, I: Inflow> Parser<'a, I> { prefix_args: Vec, source: Source, ) -> Result { + let starting_args_len = prefix_args.len(); let mut args = prefix_args; self.parse_token(TokenKind::OpenParen, Some("to begin call argument list"))?; self.ignore_newlines(); while !self.input.peek_is_or_eof(TokenKind::CloseParen) { - if !args.is_empty() { + if args.len() > starting_args_len { self.parse_token(TokenKind::Comma, Some("to separate arguments"))?; self.ignore_newlines(); } diff --git a/src/resolve/expr/call.rs b/src/resolve/expr/call.rs index 42be3537..71c25032 100644 --- a/src/resolve/expr/call.rs +++ b/src/resolve/expr/call.rs @@ -69,7 +69,7 @@ pub fn resolve_call_expr( return Err(ResolveErrorKind::BadTypeForArgumentToFunction { expected: preferred_type.to_string(), got: argument.resolved_type.to_string(), - name: function.name.to_string(), + name: function.name.display(ctx.resolved_ast.fs).to_string(), i, } .at(source)); @@ -94,7 +94,7 @@ pub fn resolve_call_expr( if resolved_required_ty != return_type { return Err(ResolveErrorKind::FunctionMustReturnType { of: required_ty.to_string(), - function_name: function.name.to_string(), + function_name: function.name.display(ctx.resolved_ast.fs).to_string(), } .at(function.return_type.source)); } diff --git a/src/resolve/expr/mod.rs b/src/resolve/expr/mod.rs index 057ac459..1deff113 100644 --- a/src/resolve/expr/mod.rs +++ b/src/resolve/expr/mod.rs @@ -58,7 +58,8 @@ pub struct ResolveExprCtx<'a, 'b> { pub resolved_function_ref: resolved::FunctionRef, pub helper_exprs: &'b IndexMap, pub settings: &'b Settings, - pub public: &'b HashMap>>, + pub public_functions: &'b HashMap>>, + pub module_fs_node_id: FsNodeId, } impl<'a, 'b> ResolveExprCtx<'a, 'b> { diff --git a/src/resolve/expr/struct_literal.rs b/src/resolve/expr/struct_literal.rs index 8cf25101..1b444a93 100644 --- a/src/resolve/expr/struct_literal.rs +++ b/src/resolve/expr/struct_literal.rs @@ -117,7 +117,7 @@ pub fn resolve_struct_literal_expr( .is_some() { return Err(ResolveErrorKind::FieldSpecifiedMoreThanOnce { - struct_name: struct_name.to_string(), + struct_name: struct_name.display(ctx.resolved_ast.fs).to_string(), field_name: field_name.to_string(), } .at(ast_type.source)); diff --git a/src/resolve/expr/variable.rs b/src/resolve/expr/variable.rs index 4deabdd9..943197d2 100644 --- a/src/resolve/expr/variable.rs +++ b/src/resolve/expr/variable.rs @@ -13,7 +13,7 @@ use crate::{ }; pub fn resolve_variable_expr( - ctx: &mut ResolveExprCtx<'_, '_>, + ctx: &mut ResolveExprCtx, name: &Name, preferred_type: Option, initialized: Initialized, @@ -48,7 +48,7 @@ pub fn resolve_variable_expr( )); } - let resolved_name = ResolvedName::new(name); + let resolved_name = ResolvedName::new(ctx.module_fs_node_id, name); if let Some((resolved_type, reference)) = ctx.global_search_ctx.find_global(&resolved_name) { return Ok(resolve_global_variable(resolved_type, *reference, source)); @@ -64,10 +64,10 @@ pub fn resolve_variable_expr( .imported_namespaces .iter() .flat_map(|namespace| { - let resolved_name = ResolvedName::new(&Name::new( - Some(namespace.to_string()), - name.basename.to_string(), - )); + let resolved_name = ResolvedName::new( + ctx.module_fs_node_id, + &Name::new(Some(namespace.to_string()), name.basename.to_string()), + ); let global = ctx .global_search_ctx diff --git a/src/resolve/function_search_ctx.rs b/src/resolve/function_search_ctx.rs index 70f67ac4..987ce281 100644 --- a/src/resolve/function_search_ctx.rs +++ b/src/resolve/function_search_ctx.rs @@ -7,6 +7,7 @@ use crate::{ name::{Name, ResolvedName}, resolved::{self, TypedExpr}, source_files::Source, + workspace::fs::FsNodeId, }; use std::collections::HashMap; @@ -14,6 +15,7 @@ use std::collections::HashMap; pub struct FunctionSearchCtx { pub available: HashMap>, pub imported_namespaces: Vec>, + pub fs_node_id: FsNodeId, } #[derive(Clone, Debug)] @@ -23,10 +25,11 @@ pub enum FindFunctionError { } impl FunctionSearchCtx { - pub fn new(imported_namespaces: Vec>) -> Self { + pub fn new(imported_namespaces: Vec>, fs_node_id: FsNodeId) -> Self { Self { available: Default::default(), imported_namespaces, + fs_node_id, } } @@ -37,7 +40,7 @@ impl FunctionSearchCtx { arguments: &[TypedExpr], source: Source, ) -> Result { - let resolved_name = ResolvedName::new(name); + let resolved_name = ResolvedName::new(self.fs_node_id, name); let mut local_matches = self .available @@ -67,7 +70,7 @@ impl FunctionSearchCtx { ctx.settings .dependency_to_module .get(dependency) - .and_then(|module_fs_node_id| ctx.public.get(module_fs_node_id)) + .and_then(|module_fs_node_id| ctx.public_functions.get(module_fs_node_id)) .and_then(|public| public.get(name.basename.as_ref())) .into_iter() }) @@ -87,10 +90,10 @@ impl FunctionSearchCtx { .imported_namespaces .iter() .filter_map(|namespace| { - self.available.get(&ResolvedName::new(&Name::new( - Some(namespace.to_string()), - name.basename.clone(), - ))) + self.available.get(&ResolvedName::new( + self.fs_node_id, + &Name::new(Some(namespace.to_string()), name.basename.clone()), + )) }) .flatten() .filter(|f| Self::fits(ctx, **f, arguments, source)); diff --git a/src/resolve/global_search_ctx.rs b/src/resolve/global_search_ctx.rs index 302106c5..02918ac8 100644 --- a/src/resolve/global_search_ctx.rs +++ b/src/resolve/global_search_ctx.rs @@ -3,6 +3,7 @@ use crate::{ name::ResolvedName, resolved::{self, GlobalVarRef}, source_files::Source, + workspace::fs::Fs, }; use std::collections::HashMap; @@ -21,12 +22,13 @@ impl GlobalSearchCtx { pub fn find_global_or_error( &self, name: &ResolvedName, + fs: &Fs, source: Source, ) -> Result<(&resolved::Type, &GlobalVarRef), ResolveError> { match self.find_global(name) { Some(global) => Ok(global), None => Err(ResolveErrorKind::UndeclaredVariable { - name: name.to_string(), + name: name.display(fs).to_string(), } .at(source)), } diff --git a/src/resolve/mod.rs b/src/resolve/mod.rs index bbb3b275..035fe3ff 100644 --- a/src/resolve/mod.rs +++ b/src/resolve/mod.rs @@ -35,6 +35,7 @@ use std::{ borrow::Borrow, collections::{HashMap, HashSet, VecDeque}, }; +use type_search_ctx::TypeMapping; enum Job { Regular(FsNodeId, usize, resolved::FunctionRef), @@ -46,7 +47,8 @@ struct ResolveCtx<'a> { pub function_search_ctxs: IndexMap, pub global_search_ctxs: IndexMap, pub helper_exprs: IndexMap, - pub public: HashMap>>, + pub public_functions: HashMap>>, + pub public_types: HashMap>>>, } impl<'a> ResolveCtx<'a> { @@ -57,7 +59,8 @@ impl<'a> ResolveCtx<'a> { function_search_ctxs: Default::default(), global_search_ctxs: Default::default(), helper_exprs, - public: HashMap::new(), + public_functions: HashMap::new(), + public_types: HashMap::new(), } } } @@ -69,7 +72,11 @@ pub fn resolve<'a>( let mut helper_exprs = IndexMap::new(); // Unify helper expressions into single map - for file in ast_workspace.files.values() { + for (physical_file_id, file) in ast_workspace.files.iter() { + let file_id = ast_workspace + .get_owning_module(*physical_file_id) + .unwrap_or(*physical_file_id); + if let Some(settings) = file.settings.map(|id| &ast_workspace.settings[id.0]) { if settings.debug_skip_merging_helper_exprs { continue; @@ -78,19 +85,23 @@ pub fn resolve<'a>( for (name, helper_expr) in file.helper_exprs.iter() { if !helper_expr.is_file_local_only { - helper_exprs.try_insert(ResolvedName::new(name), helper_expr, |define_name| { - ResolveErrorKind::MultipleDefinesNamed { - name: define_name.to_string(), - } - .at(helper_expr.source) - })?; + helper_exprs.try_insert( + ResolvedName::new(file_id, name), + helper_expr, + |define_name| { + ResolveErrorKind::MultipleDefinesNamed { + name: define_name.display(&ast_workspace.fs).to_string(), + } + .at(helper_expr.source) + }, + )?; } } } let mut ctx = ResolveCtx::new(helper_exprs); let source_files = ast_workspace.source_files; - let mut resolved_ast = resolved::Ast::new(source_files); + let mut resolved_ast = resolved::Ast::new(source_files, &ast_workspace.fs); // Unify type aliases into single map for (real_file_id, file) in ast_workspace.files.iter() { @@ -101,12 +112,12 @@ pub fn resolve<'a>( let imported_namespaces = &ast_workspace.settings[file.settings.unwrap_or_default().0].imported_namespaces; - let type_aliases = ctx.type_search_ctxs.get_or_insert_with(file_id, || { - TypeSearchCtx::new(imported_namespaces.clone(), source_files) + let type_search_ctx = ctx.type_search_ctxs.get_or_insert_with(file_id, || { + TypeSearchCtx::new(imported_namespaces.clone(), source_files, file_id) }); for (alias_name, alias) in file.type_aliases.iter() { - type_aliases.put_type_alias(&alias_name, alias, alias.source)?; + type_search_ctx.put_type_alias(&alias_name, alias, alias.source)?; } } @@ -114,10 +125,10 @@ pub fn resolve<'a>( let mut used_aliases = HashSet::::new(); // Pre-compute resolved enum types - for (real_file_id, file) in ast_workspace.files.iter() { + for (physical_file_id, file) in ast_workspace.files.iter() { let file_id = ast_workspace - .get_owning_module(*real_file_id) - .unwrap_or(*real_file_id); + .get_owning_module(*physical_file_id) + .unwrap_or(*physical_file_id); let type_search_ctx = ctx.type_search_ctxs.get_mut(&file_id).unwrap(); @@ -132,7 +143,7 @@ pub fn resolve<'a>( let members = enum_definition.members.clone(); resolved_ast.enums.insert( - ResolvedName::new(enum_name), + ResolvedName::new(file_id, enum_name), Enum { resolved_type, source: enum_definition.source, @@ -142,17 +153,17 @@ pub fn resolve<'a>( type_search_ctx.put_type( enum_name, - resolved::TypeKind::Enum(ResolvedName::new(enum_name)), + resolved::TypeKind::Enum(ResolvedName::new(file_id, enum_name)), enum_definition.source, )?; } } // Precompute resolved struct types - for (real_file_id, file) in ast_workspace.files.iter() { + for (physical_file_id, file) in ast_workspace.files.iter() { let file_id = ast_workspace - .get_owning_module(*real_file_id) - .unwrap_or(*real_file_id); + .get_owning_module(*physical_file_id) + .unwrap_or(*physical_file_id); let type_search_ctx = ctx.type_search_ctxs.get_mut(&file_id).unwrap(); @@ -174,7 +185,7 @@ pub fn resolve<'a>( ); } - let resolved_name = ResolvedName::new(&structure.name); + let resolved_name = ResolvedName::new(file_id, &structure.name); let structure_key = resolved_ast.structures.insert(resolved::Structure { name: resolved_name.clone(), @@ -208,10 +219,10 @@ pub fn resolve<'a>( } // Resolve global variables - for (real_file_id, file) in ast_workspace.files.iter() { + for (physical_file_id, file) in ast_workspace.files.iter() { let file_id = ast_workspace - .get_owning_module(*real_file_id) - .unwrap_or(*real_file_id); + .get_owning_module(*physical_file_id) + .unwrap_or(*physical_file_id); let type_search_ctx = ctx.type_search_ctxs.get_mut(&file_id).unwrap(); @@ -223,7 +234,7 @@ pub fn resolve<'a>( let resolved_type = resolve_type(type_search_ctx, &global.ast_type, &mut Default::default())?; - let resolved_name = ResolvedName::new(&global.name); + let resolved_name = ResolvedName::new(file_id, &global.name); let global_ref = resolved_ast.globals.insert(resolved::GlobalVar { name: resolved_name.clone(), @@ -238,15 +249,15 @@ pub fn resolve<'a>( } // Create initial function jobs - for (real_file_id, file) in ast_workspace.files.iter() { + for (physical_file_id, file) in ast_workspace.files.iter() { let file_id = ast_workspace - .get_owning_module(*real_file_id) - .unwrap_or(*real_file_id); + .get_owning_module(*physical_file_id) + .unwrap_or(*physical_file_id); let type_search_ctx = ctx.type_search_ctxs.get_mut(&file_id).unwrap(); for (function_i, function) in file.functions.iter().enumerate() { - let name = ResolvedName::new(&function.name); + let name = ResolvedName::new(file_id, &function.name); let function_ref = resolved_ast.functions.insert(resolved::Function { name: name.clone(), @@ -271,10 +282,13 @@ pub fn resolve<'a>( }); ctx.jobs - .push_back(Job::Regular(*real_file_id, function_i, function_ref)); + .push_back(Job::Regular(*physical_file_id, function_i, function_ref)); if function.privacy.is_public() { - let public_of_module = ctx.public.entry(file_id).or_insert_with(HashMap::new); + let public_of_module = ctx + .public_functions + .entry(file_id) + .or_insert_with(HashMap::new); // TODO: Add proper error message let function_name = function @@ -301,6 +315,7 @@ pub fn resolve<'a>( imported_namespaces .map(|namespaces| namespaces.clone()) .unwrap_or_else(|| vec![]), + file_id, ) }); @@ -387,7 +402,8 @@ pub fn resolve<'a>( resolved_function_ref, helper_exprs: &ctx.helper_exprs, settings, - public: &ctx.public, + public_functions: &ctx.public_functions, + module_fs_node_id: file_id, }; resolve_stmts(&mut ctx, &ast_function.stmts)? diff --git a/src/resolve/type_search_ctx.rs b/src/resolve/type_search_ctx.rs index ef8526f2..b7323c7e 100644 --- a/src/resolve/type_search_ctx.rs +++ b/src/resolve/type_search_ctx.rs @@ -7,6 +7,7 @@ use crate::{ name::{Name, ResolvedName}, resolved, source_files::{Source, SourceFiles}, + workspace::fs::FsNodeId, }; use indexmap::IndexMap; use std::{borrow::Cow, collections::HashSet}; @@ -16,6 +17,7 @@ pub struct TypeSearchCtx<'a> { types: IndexMap>, imported_namespaces: Vec>, source_files: &'a SourceFiles, + fs_node_id: FsNodeId, } #[derive(Clone, Debug)] @@ -55,11 +57,16 @@ impl FindTypeError { } impl<'a> TypeSearchCtx<'a> { - pub fn new(imported_namespaces: Vec>, source_files: &'a SourceFiles) -> Self { + pub fn new( + imported_namespaces: Vec>, + source_files: &'a SourceFiles, + fs_node_id: FsNodeId, + ) -> Self { Self { types: Default::default(), imported_namespaces, source_files, + fs_node_id, } } @@ -68,7 +75,7 @@ impl<'a> TypeSearchCtx<'a> { name: &Name, used_aliases_stack: &mut HashSet, ) -> Result, FindTypeError> { - let resolved_name = ResolvedName::new(name); + let resolved_name = ResolvedName::new(self.fs_node_id, name); if let Some(mapping) = self.types.get(&resolved_name) { return self.resolve_mapping(&resolved_name, mapping, used_aliases_stack); @@ -76,8 +83,10 @@ impl<'a> TypeSearchCtx<'a> { if name.namespace.is_empty() { let mut matches = self.imported_namespaces.iter().filter_map(|namespace| { - let resolved_name = - ResolvedName::new(&Name::new(Some(namespace.clone()), name.basename.clone())); + let resolved_name = ResolvedName::new( + self.fs_node_id, + &Name::new(Some(namespace.clone()), name.basename.clone()), + ); self.types.get(&resolved_name) }); @@ -120,7 +129,7 @@ impl<'a> TypeSearchCtx<'a> { value: resolved::TypeKind, source: Source, ) -> Result<(), ResolveError> { - let resolved_name = ResolvedName::new(name); + let resolved_name = ResolvedName::new(self.fs_node_id, name); if self .types @@ -137,7 +146,7 @@ impl<'a> TypeSearchCtx<'a> { } pub fn override_type(&mut self, name: &Name, value: resolved::TypeKind) { - let resolved_name = ResolvedName::new(name); + let resolved_name = ResolvedName::new(self.fs_node_id, name); self.types.insert(resolved_name, TypeMapping::Normal(value)); } @@ -147,7 +156,7 @@ impl<'a> TypeSearchCtx<'a> { value: &'a ast::TypeAlias, source: Source, ) -> Result<(), ResolveError> { - let resolved_name = ResolvedName::new(&name); + let resolved_name = ResolvedName::new(self.fs_node_id, &name); if self .types diff --git a/src/resolved/mod.rs b/src/resolved/mod.rs index df549c78..d67aff3c 100644 --- a/src/resolved/mod.rs +++ b/src/resolved/mod.rs @@ -12,6 +12,7 @@ use crate::{ source_files::{Source, SourceFiles}, tag::Tag, target::Target, + workspace::fs::Fs, }; use derive_more::{IsVariant, Unwrap}; use indexmap::IndexMap; @@ -38,10 +39,11 @@ pub struct Ast<'a> { pub structures: SlotMap, pub globals: SlotMap, pub enums: IndexMap, + pub fs: &'a Fs, } impl<'a> Ast<'a> { - pub fn new(source_files: &'a SourceFiles) -> Self { + pub fn new(source_files: &'a SourceFiles, fs: &'a Fs) -> Self { Self { source_files, entry_point: None, @@ -49,6 +51,7 @@ impl<'a> Ast<'a> { structures: SlotMap::with_key(), globals: SlotMap::with_key(), enums: IndexMap::new(), + fs, } } } @@ -323,7 +326,7 @@ impl Display for TypeKind { write!(f, "ptr<{}>", inner.kind)?; } TypeKind::Void => f.write_str("void")?, - TypeKind::Structure(name, _) => write!(f, "{}", name)?, + TypeKind::Structure(name, _) => write!(f, "{}", name.plain())?, TypeKind::AnonymousStruct() => f.write_str("(anonymous struct)")?, TypeKind::AnonymousUnion() => f.write_str("(anonymous union)")?, TypeKind::AnonymousEnum(..) => f.write_str("(anonymous enum)")?, @@ -331,7 +334,7 @@ impl Display for TypeKind { write!(f, "array<{}, {}>", fixed_array.size, fixed_array.inner.kind)?; } TypeKind::FunctionPointer(..) => f.write_str("(function pointer type)")?, - TypeKind::Enum(enum_name) => write!(f, "(enum) {}", enum_name)?, + TypeKind::Enum(enum_name) => write!(f, "(enum) {}", enum_name.plain())?, } Ok(())