diff --git a/src/dev_aid/lsp.rs b/src/dev_aid/lsp.rs index f9214c8..11d9bde 100644 --- a/src/dev_aid/lsp.rs +++ b/src/dev_aid/lsp.rs @@ -6,7 +6,7 @@ use lsp_server::{Response, Message, Connection}; use lsp_types::notification::Notification; -use crate::{parser::perform_full_semantic_parse, dev_aid::syntax_highlighting::create_token_ide_info, ast::{IdentifierType, Span}, errors::{ErrorCollector, CompileError, ErrorLevel}, linker::{PreLinker, FileUUIDMarker, Linker, FileUUID, FileData, Links}, arena_alloc::ArenaVector}; +use crate::{parser::perform_full_semantic_parse, dev_aid::syntax_highlighting::create_token_ide_info, ast::{IdentifierType, Span}, errors::{ErrorCollector, CompileError, ErrorLevel}, linker::{FileUUIDMarker, Linker, FileUUID, FileData, Links}, arena_alloc::ArenaVector}; use super::syntax_highlighting::{IDETokenType, IDEIdentifierType, IDEToken}; @@ -299,8 +299,7 @@ fn main_loop( params: serde_json::Value, ) -> Result<(), Box> { - let prelinker = PreLinker::new(); - let mut file_cache = LoadedFileCache::new(prelinker.link(), ArenaVector::new()); + let mut file_cache = LoadedFileCache::new(Linker::new(), ArenaVector::new()); let _params: InitializeParams = serde_json::from_value(params).unwrap(); println!("starting LSP main loop"); diff --git a/src/dev_aid/syntax_highlighting.rs b/src/dev_aid/syntax_highlighting.rs index 491ace1..bf822ed 100644 --- a/src/dev_aid/syntax_highlighting.rs +++ b/src/dev_aid/syntax_highlighting.rs @@ -1,7 +1,7 @@ use std::{ops::Range, path::PathBuf}; -use crate::{ast::*, tokenizer::*, parser::*, linker::{PreLinker, FileData, Links, NamedUUID, Named, Linkable, Linker, FileUUIDMarker, FileUUID}, arena_alloc::ArenaVector, flattening::{Instantiation, WireSource}}; +use crate::{ast::*, tokenizer::*, parser::*, linker::{FileData, Links, NamedUUID, Named, Linkable, Linker, FileUUIDMarker, FileUUID}, arena_alloc::ArenaVector, flattening::{Instantiation, WireSource}}; use ariadne::FileCache; use console::Style; @@ -226,10 +226,10 @@ fn generate_character_offsets(file_text : &str, tokens : &[Token]) -> Vec) -> (Linker, ArenaVector) { - let mut prelinker : PreLinker = PreLinker::new(); + let mut linker = Linker::new(); let mut paths_arena = ArenaVector::new(); for file_path in file_paths { - let uuid = prelinker.reserve_file(); + let uuid = linker.reserve_file(); let file_text = match std::fs::read_to_string(&file_path) { Ok(file_text) => file_text, Err(reason) => { @@ -242,12 +242,10 @@ pub fn compile_all(file_paths : Vec) -> (Linker, ArenaVector FlatteningContext<'inst, 'l, 'm> { if_stmt.else_end = else_end; } Statement::For{var : decl_id, range, code} => { - let loop_var_decl = self.flatten_declaration::(*decl_id, false); + let loop_var_decl = self.flatten_declaration::(*decl_id, true); let start = self.flatten_expr(&range.from); let end = self.flatten_expr(&range.to); diff --git a/src/linker.rs b/src/linker.rs index 4672b4c..0f87634 100644 --- a/src/linker.rs +++ b/src/linker.rs @@ -253,43 +253,6 @@ impl IndexMut for Links { } } -// This is a class that efficiently collects all files when initially starting, and links them together once all are present. -// Converts to a proper Linker using self.link() -pub struct PreLinker { - links : Links, - files : ArenaAllocator -} - -impl PreLinker { - pub fn new() -> PreLinker { - PreLinker { links: Links::new(), files: ArenaAllocator::new() } - } - pub fn reserve_file(&mut self) -> FileUUID { - self.files.reserve() - } - pub fn add_reserved_file(&mut self, file : FileUUID, parse_result : FullParseResult) { - let mut associated_values = Vec::new(); - for md in parse_result.ast.modules { - let module_name = md.link_info.name.clone(); - let new_module_uuid = self.links.globals.alloc(Named::Module(md)); - associated_values.push(new_module_uuid); - self.links.add_name(module_name, new_module_uuid); - } - self.files.alloc_reservation(file, FileData{file_text : parse_result.file_text, tokens: parse_result.tokens, token_hierarchy: parse_result.token_hierarchy, parsing_errors : parse_result.ast.errors, associated_values}); - } - - // This should be called once all modules have been added. Adds errors for globals it couldn't match - pub fn link(mut self) -> Linker { - for (_file_uuid, file) in &self.files { - for val_in_file in &file.associated_values { - let link_info = self.links.globals[*val_in_file].get_link_info_mut().unwrap(); - Links::resolve_dependencies(&self.links.global_namespace, &file, link_info); - } - } - Linker{links: self.links, files : self.files} - } -} - fn add_error(info_a: &LinkInfo, info_b: &LinkInfo, errors: &ErrorCollector) { let this_object_name = &info_a.name; errors.error_with_info(info_a.name_span, format!("Conflicting Declaration for the name '{this_object_name}'"), vec![ @@ -298,6 +261,9 @@ fn add_error(info_a: &LinkInfo, info_b: &LinkInfo, errors: &ErrorCollector) { } impl Linker { + pub fn new() -> Linker { + Linker{files : ArenaAllocator::new(), links : Links::new()} + } fn get_linking_errors(&self, file_uuid : FileUUID, errors : &ErrorCollector) { let file = &self.files[file_uuid]; diff --git a/src/typing.rs b/src/typing.rs index a24486b..ebe172f 100644 --- a/src/typing.rs +++ b/src/typing.rs @@ -30,14 +30,6 @@ impl Type { Type::Array(sub) => sub.deref().0.to_string(linker) + "[]", } } - pub fn get_root(&self) -> Option { - match self { - Type::Error => None, - Type::Unknown => None, - Type::Named(name) => Some(*name), - Type::Array(sub) => sub.0.get_root(), - } - } pub fn for_each_generative_input(&self, f : &mut F) { match self { Type::Error => {}