From 2faf4af5e5473a64a986ce274d5ce52ff3cc43f7 Mon Sep 17 00:00:00 2001 From: Robert-M-Lucas Date: Wed, 5 Jun 2024 10:05:07 +0100 Subject: [PATCH] Improved name evaluation --- .idea/workspace.xml | 30 +-- main.why | 2 +- src/root/builtin/int.rs | 2 +- src/root/builtin/mod.rs | 10 +- src/root/compiler/compile.rs | 4 +- src/root/compiler/compile_evaluable.rs | 7 +- src/root/compiler/compile_function.rs | 30 +-- src/root/errors/name_resolver_errors.rs | 8 +- src/root/name_resolver/name_resolvers.rs | 220 ++++++------------ .../resolve_function_signatures.rs | 9 +- src/root/name_resolver/resolve_names.rs | 25 +- src/root/name_resolver/resolve_type_sizes.rs | 7 +- src/root/shared/types.rs | 2 +- 13 files changed, 131 insertions(+), 225 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5908c69..0a71e90 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -8,27 +8,13 @@ - - - + + - - - - - - - - - - - - - diff --git a/main.why b/main.why index 3102473..761d81c 100644 --- a/main.why +++ b/main.why @@ -3,6 +3,6 @@ struct A { b: int } -fn main() !-> int { +fn main() -> int { return 12; } diff --git a/src/root/builtin/int.rs b/src/root/builtin/int.rs index 2960116..39f2894 100644 --- a/src/root/builtin/int.rs +++ b/src/root/builtin/int.rs @@ -1,7 +1,7 @@ use unique_type_id::UniqueTypeId; use crate::root::compiler::assembly::utils::get_qword_stack_pointer; use crate::root::parser::parse_function::parse_literal::{LiteralToken, LiteralTokens}; -use crate::root::shared::common::{AddressedTypeRef, ByteSize, LocalAddress, TypeID}; +use crate::root::shared::common::{AddressedTypeRef, ByteSize, FunctionID, LocalAddress, TypeID}; use crate::root::shared::types::Type; #[derive(UniqueTypeId)] diff --git a/src/root/builtin/mod.rs b/src/root/builtin/mod.rs index c988f12..c88c275 100644 --- a/src/root/builtin/mod.rs +++ b/src/root/builtin/mod.rs @@ -1,15 +1,15 @@ pub mod int; use crate::root::builtin::int::IntType; -use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, ImplNode}; +use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable}; use crate::root::shared::types::Type; pub fn register_builtin(global_table: &mut GlobalDefinitionTable) { - let types: [(String, Box, ImplNode); 1] = [ - ("int".to_string(), Box::new(IntType{}), ImplNode::default()) + let types: [(String, Box); 1] = [ + ("int".to_string(), Box::new(IntType{})) ]; - for (n, t, i) in types { - global_table.register_builtin_type(n, t, i); + for (n, t) in types { + global_table.register_builtin_type(n, t); } } diff --git a/src/root/compiler/compile.rs b/src/root/compiler/compile.rs index 33dc182..d4cdf67 100644 --- a/src/root/compiler/compile.rs +++ b/src/root/compiler/compile.rs @@ -5,7 +5,7 @@ use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; use crate::root::parser::parse_function::FunctionToken; use crate::root::shared::common::FunctionID; -pub fn compile(global_table: GlobalDefinitionTable, unprocessed_functions: HashMap) -> Result { +pub fn compile(mut global_table: GlobalDefinitionTable, unprocessed_functions: HashMap) -> Result { let mut unprocessed_functions = unprocessed_functions; let mut compiled_functions = HashMap::new(); let mut compiled_len = 0usize; @@ -18,7 +18,7 @@ pub fn compile(global_table: GlobalDefinitionTable, unprocessed_functions: HashM let current_function_token = unprocessed_functions.remove(¤t_function).unwrap(); - let (compiled, called_functions) = compile_function(current_function, current_function_token, &global_table)?; + let (compiled, called_functions) = compile_function(current_function, current_function_token, &mut global_table)?; compiled_len += compiled.len() + 10; compiled_functions.insert(current_function, compiled); diff --git a/src/root/compiler/compile_evaluable.rs b/src/root/compiler/compile_evaluable.rs index 7ac9623..e8da345 100644 --- a/src/root/compiler/compile_evaluable.rs +++ b/src/root/compiler/compile_evaluable.rs @@ -9,7 +9,7 @@ pub fn compile_evaluable(fid: FunctionID, et: &EvaluableToken, target: Option todo!(), + EvaluableTokens::Name(_, _) => todo!(), EvaluableTokens::Literal(literal) => { let (address, t, tid) = if let Some(target) = target { let (address, tid) = target.dissolve(); @@ -32,6 +32,9 @@ pub fn compile_evaluable(fid: FunctionID, et: &EvaluableToken, target: Option todo!(), - EvaluableTokens::PrefixOperator(_, _) => todo!() + EvaluableTokens::PrefixOperator(_, _) => todo!(), + EvaluableTokens::DynamicAccess(_, _) => todo!(), + EvaluableTokens::StaticAccess(_, _) => todo!(), + EvaluableTokens::FunctionCall(_, _, _) => todo!() } } \ No newline at end of file diff --git a/src/root/compiler/compile_function.rs b/src/root/compiler/compile_function.rs index 25afda4..58cd5fd 100644 --- a/src/root/compiler/compile_function.rs +++ b/src/root/compiler/compile_function.rs @@ -9,24 +9,15 @@ use crate::root::parser::parse_function::parse_line::LineTokens; use crate::root::shared::common::{FunctionID, LocalAddress}; use crate::root::shared::common::AddressedTypeRef; -pub fn compile_function(fid: FunctionID, function: FunctionToken, global_table: &GlobalDefinitionTable) -> Result<(String, HashSet), WError> { +pub fn compile_function(fid: FunctionID, function: FunctionToken, global_table: &mut GlobalDefinitionTable) -> Result<(String, HashSet), WError> { let mut local_variables = Box::new(LocalVariableTable::default()); let (_location, _name, return_type, parameters, lines) = function.dissolve(); let return_type = if fid.is_main() { None } else { return_type }; - let return_type = if let Some((t, loc)) = return_type { - Some(match global_table.resolve_global_name_to_id(&t, &loc)? { - NameResultId::Function(_) => todo!(), - NameResultId::Type(type_ref) => { - if type_ref.indirection().has_indirection() { - todo!() - } - type_ref - } - NameResultId::NotFound => todo!() - }) + let return_type = if let Some(t) = return_type { + Some(global_table.resolve_to_type_ref(&t)?) } else { None @@ -34,20 +25,11 @@ pub fn compile_function(fid: FunctionID, function: FunctionToken, global_table: let mut param_address = LocalAddress(8); - for ((param_name, param_name_loc), (param_type, param_type_loc)) in parameters { - let type_ref = match global_table.resolve_global_name_to_id(¶m_type, ¶m_type_loc)? { - NameResultId::Function(_) => todo!(), - NameResultId::Type(type_ref) => { - if type_ref.indirection().has_indirection() { - todo!() - } - type_ref - } - NameResultId::NotFound => todo!() - }; + for (param_name, param_type) in parameters { + let type_ref = global_table.resolve_to_type_ref(¶m_type)?; let size = global_table.type_definitions().get(type_ref.type_id()).unwrap().size(); - local_variables.add_existing(param_name, AddressedTypeRef::new(param_address, type_ref)); + local_variables.add_existing(param_name.name().clone(), AddressedTypeRef::new(param_address, type_ref)); param_address += LocalAddress(size.0 as isize); } diff --git a/src/root/errors/name_resolver_errors.rs b/src/root/errors/name_resolver_errors.rs index 4bb543e..0de7b10 100644 --- a/src/root/errors/name_resolver_errors.rs +++ b/src/root/errors/name_resolver_errors.rs @@ -15,5 +15,11 @@ pub enum NRErrors { #[error("Function reference cannot have indirection here")] FunctionIndirectionError, #[error("Identifier ({0}) not found")] - IdentifierNotFound(String) + IdentifierNotFound(String), + #[error("Expected type ({0}), found function of same name")] + FoundFunctionNotType(String), + #[error("Type ({0}) not found")] + TypeNotFound(String), + #[error("Expected type, not method or attribute")] + ExpectedTypeNotMethodOrAttribute } diff --git a/src/root/name_resolver/name_resolvers.rs b/src/root/name_resolver/name_resolvers.rs index 6e80623..f99466f 100644 --- a/src/root/name_resolver/name_resolvers.rs +++ b/src/root/name_resolver/name_resolvers.rs @@ -1,7 +1,9 @@ +use std::collections::hash_map::{Iter, IterMut}; use std::collections::HashMap; use std::path::PathBuf; use std::rc::Rc; use derive_getters::Getters; +use either::{Either, Left, Right}; use crate::root::compiler::local_variable_table::LocalVariableTable; use crate::root::errors::name_resolver_errors::NRErrors; use crate::root::errors::name_resolver_errors::NRErrors::IdentifierNotFound; @@ -10,75 +12,45 @@ use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; use crate::root::parser::parse::Location; use crate::root::shared::types::Type; use crate::root::parser::parse_function::FunctionToken; -use crate::root::parser::parse_function::parse_evaluable::FullNameWithIndirectionToken; +use crate::root::parser::parse_function::parse_evaluable::{FullNameToken, FullNameTokens, FullNameWithIndirectionToken}; +use crate::root::parser::parse_name::SimpleNameToken; use crate::root::parser::parse_struct::StructToken; use crate::root::shared::common::{AddressedTypeRef, FunctionID, TypeID, TypeRef}; -#[derive(Default)] -pub struct ImplNode { - functions: HashMap +#[derive(Debug)] +enum NameTreeEntry { + Type(TypeID), + Function(FunctionID) } -/// Contents of a `DefinitionTable` -enum FileLevelTreeNode { - Function(FunctionID), - Type(TypeID, ImplNode), +#[derive(Default, Debug)] +struct NameTree { + table: HashMap } -/// Recursive tree containing all named objects/functions/types -#[derive(Default)] -struct FileLevelTree { - table: HashMap -} - -impl FileLevelTree { - pub fn add_type(&mut self, name: String, id: TypeID) { - // TODO: Handle collision - self.table.insert(name, FileLevelTreeNode::Type(id, ImplNode::default())); +impl NameTree { + pub fn add_entry(&mut self, name: String, entry: NameTreeEntry) { + self.table.insert(name, entry); } - pub fn add_function_impl(&mut self, name: String, id: FunctionID, containing_class: TypeID) -> bool { - for (_, n) in &mut self.table { - match n { - FileLevelTreeNode::Function(_) => {} - FileLevelTreeNode::Type(type_id, i) => { - if containing_class != *type_id { - continue; - } - - i.functions.insert(name, id); - - return true; - } - } - } - - return false; - } - - pub fn add_function(&mut self, name: String, id: FunctionID) { - self.table.insert(name, FileLevelTreeNode::Function(id)); + pub fn get_entry(&self, name: &str) -> Option<&NameTreeEntry> { + self.table.get(name) } } /// Top level of recursive tree containing all named objects/functions/types #[derive(Default)] struct TopLevelNameTree { - table: HashMap, Box> + table: HashMap, NameTree> } impl TopLevelNameTree { - pub fn get_path_tree(&mut self, path: &Rc) -> &mut Box { - // ! Inefficient, done to make borrow checker happy - if !self.table.contains_key(path) { - self.table.insert(path.clone(), Box::new(FileLevelTree::default())); + pub fn get_tree_mut(&mut self, path: Rc) -> &mut NameTree { + if !self.table.contains_key(&path) { + self.table.insert(path.clone(), Default::default()); } - self.table.get_mut(path).unwrap() - } - - pub fn get_path_tree_fallible(&self, path: &Rc) -> Option<&Box> { - self.table.get(path) + self.table.get_mut(&path).unwrap() } } @@ -86,9 +58,10 @@ impl TopLevelNameTree { pub struct GlobalDefinitionTable { id_counter: isize, type_definitions: HashMap>, + impl_definitions: HashMap>, function_signatures: HashMap, name_table: TopLevelNameTree, - builtin_type_name_table: HashMap, + builtin_type_name_table: HashMap, builtin_function_name_table: HashMap } @@ -105,16 +78,17 @@ impl GlobalDefinitionTable { GlobalDefinitionTable { id_counter: 1, type_definitions: Default::default(), + impl_definitions: Default::default(), function_signatures: Default::default(), name_table: Default::default(), builtin_type_name_table: Default::default(), builtin_function_name_table: Default::default(), } } - pub fn register_builtin_type(&mut self, name: String, t: Box, impl_node: ImplNode) { + pub fn register_builtin_type(&mut self, name: String, t: Box) { let id = t.id(); self.type_definitions.insert(id, t); - self.builtin_type_name_table.insert(name, (id, impl_node)); + self.builtin_type_name_table.insert(name, id); } pub fn register_builtin_function(&mut self, name: String, t: FunctionSignature, id: FunctionID) { @@ -123,17 +97,17 @@ impl GlobalDefinitionTable { } pub fn add_from_struct_token(&mut self, st: &StructToken) -> TypeID { - let file_level_tree = self.name_table.get_path_tree(st.location().path()); + let file_level_tree = self.name_table.get_tree_mut(st.location().path().clone()); self.id_counter += 1; let id = TypeID(self.id_counter - 1); - file_level_tree.add_type(st.name().clone(), id); + file_level_tree.add_entry(st.name().name().clone(), NameTreeEntry::Type(id)); id } pub fn add_from_function_token(&mut self, ft: &FunctionToken, containing_class: Option) -> FunctionID { - let id = if ft.name() == "main" { + let id = if ft.name().name() == "main" { FunctionID(0) } else { self.id_counter += 1; @@ -142,16 +116,15 @@ impl GlobalDefinitionTable { if let Some(containing_class) = containing_class { - for (_, file_level_tree) in &mut self.name_table.table { - if file_level_tree.add_function_impl(ft.name().clone(), id, containing_class) { - return id; - } + if !self.impl_definitions.contains_key(&containing_class) { + self.impl_definitions.insert(containing_class, Default::default()); } - panic!("Class for impl not found"); + + self.impl_definitions.get_mut(&containing_class).unwrap().insert(ft.name().name().clone(), id); } else { - let file_level_tree = self.name_table.get_path_tree(ft.location().path()); - file_level_tree.add_function(ft.name().clone(), id); + let file_level_tree = self.name_table.get_tree_mut(ft.location().path().clone()); + file_level_tree.add_entry(ft.name().name().clone(), NameTreeEntry::Function(id)); } id @@ -165,111 +138,56 @@ impl GlobalDefinitionTable { self.type_definitions.insert(given_id, definition); } - pub fn resolve_name(&self, name: &UnresolvedNameToken, local_variable_table: &LocalVariableTable) -> NameResult { - todo!() - } - - pub fn resolve_global_name(&self, name: &UnresolvedNameToken) -> NameResult { - todo!() - } - pub fn resolve_global_name_to_id(&self, name: &FullNameWithIndirectionToken) -> Result { + pub fn resolve_to_type_ref(&mut self, name: &FullNameWithIndirectionToken) -> Result { let (indirection, full_name) = (name.indirection(), name.inner()); - let path = name.location().path(); - - fn search_file_level_tree(tree: &Box, name: &UnresolvedNameToken, location: &Location) -> Result, WError> { - let base = name.base(); - let Some(base) = tree.table.get(base) else { return Ok(None) }; - let mut name_iter = name.names().iter(); - - match base { - FileLevelTreeNode::Function(fid) => { - if let Some((_, next)) = name_iter.next() { - return Err(WError::n(NRErrors::FunctionSubname(next.clone(), name.base().clone()), location.clone())); - } - if name.indirection().has_indirection() { - return Err(WError::n(NRErrors::FunctionIndirectionError, name.location().clone())); - } - Ok(Some(NameResultId::Function(*fid))) - } - FileLevelTreeNode::Type(tid, imp) => { - Ok(Some(if let Some((connector, method_name)) = name_iter.next() { - let Some(function) = imp.functions.get(method_name) else { - return Err(WError::n(NRErrors::CannotFindMethod(method_name.clone(), name.base().clone()), location.clone())); - }; - - if let Some((_, next)) = name_iter.next() { - return Err(WError::n(NRErrors::FunctionSubname(next.clone(), method_name.clone()), location.clone())); - } - - NameResultId::Function(*function) - } - else { - NameResultId::Type(TypeRef::new(*tid, *name.indirection())) - })) - } + fn find_error_point(name: &FullNameToken, prev_location: &Location) -> Location { + match name.token() { + FullNameTokens::Name(_, _) => prev_location.clone(), + FullNameTokens::StaticAccess(n, _) => find_error_point(n, name.location()), + FullNameTokens::DynamicAccess(n, _) => find_error_point(n, name.location()), } } - let tree = self.name_table.get_path_tree_fallible(path); - - // * Search current file then others - if let Some(tree) = tree { - if let Some(found) = search_file_level_tree(tree, name, location)? { - return Ok(found); - } - } - - for (c_path, tree) in &self.name_table.table { - if path == c_path { - continue; - } + let (name, containing) = match full_name.token() { + FullNameTokens::Name(n, c) => (n, c), + _ => Err(WError::n(NRErrors::ExpectedTypeNotMethodOrAttribute, find_error_point(full_name, full_name.location())))? + }; - if let Some(found) = search_file_level_tree(tree, name, location)? { - return Ok(found); - } - } + let name = if name.name() == "Self" && containing.is_some() { + containing.as_ref().unwrap() + } else { name }; - if let Some((id, impl_node)) = self.builtin_type_name_table.get(name.base()) { - let mut name_iter = name.names().iter(); - if let Some((connector, method_name)) = name_iter.next() { - let Some(function) = impl_node.functions.get(method_name) else { - return Err(WError::n(NRErrors::CannotFindMethod(method_name.clone(), name.base().clone()), location.clone())); - }; - - if let Some((_, next)) = name_iter.next() { - return Err(WError::n(NRErrors::FunctionSubname(next.clone(), method_name.clone()), location.clone())); - } - - // match connector { - // NameConnectors::NonStatic => { - // if !*function_signatures.get(function).unwrap().has_self() { - // - // return Err(()); - // } - // } - // NameConnectors::Static => {} - // } - - return Ok(NameResultId::Function(*function)); + let process_tree = |tree: &NameTree| -> Option<_> { + if let Some(val) = tree.get_entry(name.name()) { + Some(match val { + NameTreeEntry::Type(t) => Ok(TypeRef::new(*t, *indirection)), + NameTreeEntry::Function(_) => { + Err(WError::n(NRErrors::FoundFunctionNotType(name.name().clone()), full_name.location().clone())) + } + }) } else { - return Ok(NameResultId::Type(TypeRef::new(*id, *name.indirection()))); + None } + }; + + if let Some(r) = process_tree(self.name_table.get_tree_mut(full_name.location().path().clone())) { + return r; } - if let Some(id) = self.builtin_function_name_table.get(name.base()) { - if let Some((_, next)) = name.names().iter().next() { - return Err(WError::n(NRErrors::FunctionSubname(next.clone(), name.base().clone()), location.clone())); - } - if name.indirection().has_indirection() { - return Err(WError::n(NRErrors::FunctionIndirectionError, name.location().clone())); + for (_, tree) in self.name_table.table.iter().filter(|(p, _)| *p != full_name.location().path()) { + if let Some(r) = process_tree(tree) { + return r; } + } - return Ok(NameResultId::Function(*id)) + if let Some(r) = self.builtin_type_name_table.get(name.name()) { + return Ok(TypeRef::new(*r, *indirection)) } - Err(WError::n(IdentifierNotFound(name.base().clone()), name.location().clone())) + + Err(WError::n(NRErrors::TypeNotFound(name.name().clone()), full_name.location().clone())) } } diff --git a/src/root/name_resolver/resolve_function_signatures.rs b/src/root/name_resolver/resolve_function_signatures.rs index 99d6f6d..6eb7c7d 100644 --- a/src/root/name_resolver/resolve_function_signatures.rs +++ b/src/root/name_resolver/resolve_function_signatures.rs @@ -11,12 +11,11 @@ pub struct FunctionSignature { return_type: Option } -pub fn resolve_function_signature(function_token: &FunctionToken, global_table: &GlobalDefinitionTable) -> Result { +pub fn resolve_function_signature(function_token: &FunctionToken, global_table: &mut GlobalDefinitionTable) -> Result { let mut args = Vec::new(); - let return_type = if let Some((type_name, location)) = function_token.return_type() { - // TODO - Some(global_table.resolve_global_name_to_id(type_name)?) + let return_type = if let Some(type_name) = function_token.return_type() { + Some(global_table.resolve_to_type_ref(type_name)?) } else { None }; @@ -24,7 +23,7 @@ pub fn resolve_function_signature(function_token: &FunctionToken, global_table: for (arg_name, arg_type) in function_token.parameters() { args.push(( arg_name.clone(), - global_table.resolve_global_name_to_id(arg_type)? + global_table.resolve_to_type_ref(arg_type)? )) } diff --git a/src/root/name_resolver/resolve_names.rs b/src/root/name_resolver/resolve_names.rs index 7c1d0ce..7d0cd61 100644 --- a/src/root/name_resolver/resolve_names.rs +++ b/src/root/name_resolver/resolve_names.rs @@ -13,6 +13,7 @@ use crate::root::parser::parse::Location; use crate::root::parser::parse_function::FunctionToken; use crate::root::parser::parse_function::parse_evaluable::{FullNameToken, FullNameTokens}; use crate::root::parser::parse_function::parse_literal::LiteralToken; +use crate::root::parser::parse_name::SimpleNameToken; use crate::root::parser::parse_toplevel::TopLevelTokens; use crate::root::shared::common::{LocalAddress, TypeRef}; use crate::root::shared::common::{ByteSize, FunctionID, TypeID}; @@ -62,12 +63,12 @@ use crate::root::shared::types::Type; pub struct UserType { id: TypeID, size: ByteSize, - attributes: Vec<(usize, String, TypeRef)>, + attributes: Vec<(usize, SimpleNameToken, TypeRef)>, location: Location } impl UserType { - pub fn new(id: TypeID, size: ByteSize, attributes: Vec<(usize, String, TypeRef)>, location: Location) -> UserType { + pub fn new(id: TypeID, size: ByteSize, attributes: Vec<(usize, SimpleNameToken, TypeRef)>, location: Location) -> UserType { UserType { id, size, attributes, location } } } @@ -117,13 +118,13 @@ pub fn resolve_names(ast: Vec, global_table: &mut GlobalDefiniti let (location, _, attributes, id) = st.dissolve(); let id = id.unwrap(); - let mut p_attributes = Vec::new(); - for ((name, name_loc), (type_name, type_name_loc)) in attributes { - let type_ref = global_table.resolve_global_name_to_id(&type_name)?; + let mut p_attributes: Vec<(SimpleNameToken, TypeRef)> = Vec::new(); + for (name, type_name) in attributes { + let type_ref = global_table.resolve_to_type_ref(&type_name)?; for (e_name, _) in &p_attributes { - if e_name == &name { - return Err(WError::n(NRErrors::SameAttributeName(name), name_loc)); + if e_name.name() == name.name() { + return Err(WError::n(NRErrors::SameAttributeName(name.name().clone()), name.location().clone())); } } p_attributes.push((name, type_ref)) @@ -132,20 +133,22 @@ pub fn resolve_names(ast: Vec, global_table: &mut GlobalDefiniti } TopLevelTokens::Impl(it) => { let (location, name, functions) = it.dissolve(); - let type_id = *global_table.resolve_global_name_to_id(FullNameToken::new( + let type_id = *global_table.resolve_to_type_ref(&FullNameToken::new( location.clone(), FullNameTokens::Name(name, None) ).with_no_indirection())?.type_id(); - for ft in it.dissolve().2 { + for ft in functions { let function_id = global_table.add_from_function_token(&ft, Some(type_id)); - global_table.add_function_signature(function_id, resolve_function_signature(&ft, &global_table)?); + let signature = resolve_function_signature(&ft, global_table)?; + global_table.add_function_signature(function_id, signature); unprocessed_functions.insert(function_id, ft); } } TopLevelTokens::Function(ft) => { let function_id = global_table.add_from_function_token(&ft, None); - global_table.add_function_signature(function_id, resolve_function_signature(&ft, &global_table)?); + let signature = resolve_function_signature(&ft, global_table)?; + global_table.add_function_signature(function_id, signature); unprocessed_functions.insert(function_id, ft); } }; diff --git a/src/root/name_resolver/resolve_type_sizes.rs b/src/root/name_resolver/resolve_type_sizes.rs index ed29a5d..914e840 100644 --- a/src/root/name_resolver/resolve_type_sizes.rs +++ b/src/root/name_resolver/resolve_type_sizes.rs @@ -4,18 +4,19 @@ use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; use crate::root::shared::common::TypeRef; use crate::root::name_resolver::resolve_names::UserType; use crate::root::parser::parse::Location; +use crate::root::parser::parse_name::SimpleNameToken; use crate::root::POINTER_SIZE; use crate::root::shared::common::{ByteSize, TypeID}; #[derive(Dissolve)] pub struct UnsizedUserType { id: TypeID, - attributes: Vec<(String, TypeRef)>, + attributes: Vec<(SimpleNameToken, TypeRef)>, location: Location } impl UnsizedUserType { - pub fn new(id: TypeID, attributes: Vec<(String, TypeRef)>, location: Location) -> UnsizedUserType { + pub fn new(id: TypeID, attributes: Vec<(SimpleNameToken, TypeRef)>, location: Location) -> UnsizedUserType { UnsizedUserType { id, attributes, location } } } @@ -36,7 +37,7 @@ pub fn resolve_type_sizes( path.push(id); let mut size: ByteSize = ByteSize(0); - let mut processed_attributes: Vec<(usize, String, TypeRef)> = Vec::new(); + let mut processed_attributes: Vec<(usize, SimpleNameToken, TypeRef)> = Vec::new(); for (attribute_name, attribute_type) in attributes { let offset = size; diff --git a/src/root/shared/types.rs b/src/root/shared/types.rs index a40cea0..a11e646 100644 --- a/src/root/shared/types.rs +++ b/src/root/shared/types.rs @@ -1,5 +1,5 @@ use crate::root::parser::parse_function::parse_literal::LiteralToken; -use crate::root::shared::common::{AddressedTypeRef, ByteSize, LocalAddress, TypeID}; +use crate::root::shared::common::{AddressedTypeRef, ByteSize, FunctionID, LocalAddress, TypeID}; pub trait Type { fn id(&self) -> TypeID;