Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/modules/builtin/nameof.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::docs::module::DocumentationModule;
use crate::modules::function::invocation_utils::handle_function_parameters;
use crate::modules::types::{Type, Typed};
use crate::modules::variable::variable_name_extensions;
use crate::translate::module::TranslateModule;
Expand Down Expand Up @@ -28,18 +29,23 @@ impl SyntaxModule<ParserMetadata> for Nameof {
fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult {
token(meta, "nameof")?;
let name = variable(meta, variable_name_extensions())?;
match meta.get_var(&name) {
Some(var_decl) => {
self.name.clone_from(&var_decl.name);
if let Some(id) = var_decl.global_id {
self.name = format!("__{id}_{}", self.name);
}
Ok(())
}
None => {
let tok = meta.get_current_token();
error!(meta, tok, format!("Variable '{name}' not found"))
}
if let Some(var_decl) = meta.get_var(&name) {
self.name = if let Some(id) = var_decl.global_id {
format!("__{id}_{}", var_decl.name)
} else {
var_decl.name.clone()
};
Ok(())
} else if let Some(fun_decl) = meta.get_fun_declaration(&name) {
self.name = format!("{}__{}_v0", fun_decl.name, fun_decl.id);
Copy link
Member

@b1ek b1ek Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ph0enixKM is there even a way to properly select a variation of a function? i honestly have no idea how to go around this. hardcoding is definitely not the way for obvious reasons

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Now since we're on a different architecture, we can slowly start to build centralized system that names these functions a certain way and only ask the system for the appropriate name here


// Create an empty call to ensure referenced function gets built
let fun_decl = fun_decl.clone();
let _ = handle_function_parameters(meta, fun_decl.id, fun_decl.clone(), &fun_decl.arg_types, &[], None);
Ok(())
} else {
let tok = meta.get_current_token();
error!(meta, tok, format!("Variable or function '{name}' not found"))
}
}
}
Expand Down