Decleration identifier

This commit is contained in:
2026-04-17 12:04:44 +02:00
parent d0b7898ad7
commit 7996a3ffaa
3 changed files with 34 additions and 32 deletions
+6 -10
View File
@@ -97,6 +97,9 @@ impl TopLevelHirScope {
tlss: &TopLevelSymbolScope, tlss: &TopLevelSymbolScope,
symbol: &StructSymbol, symbol: &StructSymbol,
) -> Arc<TypeRef> { ) -> Arc<TypeRef> {
if let Some(rf) = self.variables.get(&symbol.name) {
rf.var_type.clone()
} else {
let name = self.get_name(symbol.export); let name = self.get_name(symbol.export);
let rf = Arc::new(TypeRef::Struct(StructRef { let rf = Arc::new(TypeRef::Struct(StructRef {
@@ -119,11 +122,12 @@ impl TopLevelHirScope {
rf rf
} }
}
pub fn var_ref(&mut self, tlss: &TopLevelSymbolScope, symbol: &VarSymbol) -> Arc<VarRef> { pub fn var_ref(&mut self, tlss: &TopLevelSymbolScope, symbol: &VarSymbol) -> Arc<VarRef> {
Arc::new(VarRef { Arc::new(VarRef {
var_type: self.type_ref(tlss, &symbol.var_type), var_type: self.type_ref(tlss, &symbol.var_type),
name: symbol.name.clone(), name: self.get_name(true),
}) })
} }
@@ -132,15 +136,7 @@ impl TopLevelHirScope {
var_ref.var_type.clone() var_ref.var_type.clone()
} else { } else {
if let Some(tlss_rf) = tlss.structs.get(&symbol.0) { if let Some(tlss_rf) = tlss.structs.get(&symbol.0) {
let struct_ref = self.struct_ref(tlss, tlss_rf); self.struct_ref(tlss, tlss_rf)
let var_ref = Arc::new(VarRef {
name: symbol.0.clone(),
var_type: struct_ref,
});
self.variables.insert(symbol.0.clone(), var_ref.clone());
var_ref.var_type.clone()
} else { } else {
match symbol.0.as_str() { match symbol.0.as_str() {
"int" => { "int" => {
+8 -2
View File
@@ -11,7 +11,11 @@ pub fn walk_ast(top_scope: Arc<Scope>, tl: &mut Vec<parser::ast::TopLevel>) {
match tl { match tl {
parser::ast::TopLevel::Import(_) => unimplemented!(), parser::ast::TopLevel::Import(_) => unimplemented!(),
parser::ast::TopLevel::FunctionDecl { params, body, .. } => { parser::ast::TopLevel::FunctionDecl {
params, body, name, ..
} => {
*name = top_scope.get_reference(name).unwrap().name.clone();
let scope = LocalScope::new(top_scope.clone()); let scope = LocalScope::new(top_scope.clone());
scope.with_params(params); scope.with_params(params);
@@ -19,7 +23,9 @@ pub fn walk_ast(top_scope: Arc<Scope>, tl: &mut Vec<parser::ast::TopLevel>) {
scope.with_block(body); scope.with_block(body);
} }
parser::ast::TopLevel::StructDecl { .. } => {} parser::ast::TopLevel::StructDecl { name, .. } => {
*name = top_scope.get_reference(name).unwrap().name.clone();
}
} }
} }
} }
+2 -2
View File
@@ -1,8 +1,8 @@
struct MyType { export struct MyType {
x: int, x: int,
} }
function test(): MyType { } export function test(): MyType { }
function add() { function add() {
let output = test().x; let output = test().x;