From deddf1d77e901725216974828c53df9cdf2cae80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Mon, 10 Jun 2024 20:32:10 +0200 Subject: [PATCH] fix problem with missing function generations when functions have same name in different files --- src/transpile/transpiler.rs | 39 +++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/transpile/transpiler.rs b/src/transpile/transpiler.rs index c71ca9d..3011c22 100644 --- a/src/transpile/transpiler.rs +++ b/src/transpile/transpiler.rs @@ -26,7 +26,7 @@ pub struct Transpiler { datapack: shulkerbox::datapack::Datapack, /// Key: (program identifier, function name) functions: RwLock>, - function_locations: RwLock>, + function_locations: RwLock>, } #[derive(Debug, Clone)] @@ -152,32 +152,29 @@ impl Transpiler { program_identifier: &str, handler: &impl Handler, ) -> TranspileResult { + let program_query = (program_identifier.to_string(), name.to_string()); let already_transpiled = { let locations = self.function_locations.read().unwrap(); - locations.get(name).is_some() + locations.get(&program_query).is_some() }; if !already_transpiled { let statements = { let functions = self.functions.read().unwrap(); - let function_data = functions - .get(&(program_identifier.to_string(), name.to_string())) - .ok_or_else(|| { - let error = TranspileError::MissingFunctionDeclaration(name.to_string()); - handler.receive(error.clone()); - error - })?; + let function_data = functions.get(&program_query).ok_or_else(|| { + let error = TranspileError::MissingFunctionDeclaration(name.to_string()); + handler.receive(error.clone()); + error + })?; function_data.statements.clone() }; let commands = self.transpile_function(&statements, program_identifier, handler)?; let functions = self.functions.read().unwrap(); - let function_data = functions - .get(&(program_identifier.to_string(), name.to_string())) - .ok_or_else(|| { - let error = TranspileError::MissingFunctionDeclaration(name.to_string()); - handler.receive(error.clone()); - error - })?; + let function_data = functions.get(&program_query).ok_or_else(|| { + let error = TranspileError::MissingFunctionDeclaration(name.to_string()); + handler.receive(error.clone()); + error + })?; let modified_name = function_data .annotations @@ -209,15 +206,15 @@ impl Transpiler { self.datapack.add_load(&function_location); } - self.function_locations - .write() - .unwrap() - .insert(name.to_string(), function_location); + self.function_locations.write().unwrap().insert( + (program_identifier.to_string(), name.to_string()), + function_location, + ); } let locations = self.function_locations.read().unwrap(); locations - .get(name) + .get(&program_query) .ok_or_else(|| { let error = TranspileError::MissingFunctionDeclaration(name.to_string()); handler.receive(error.clone());