From: Brendan Hansen Date: Mon, 11 Oct 2021 15:49:12 +0000 (-0500) Subject: fixed aliases resolving to self X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=be7d4e251e3f1dbd0a94d6d131e915d73cba5499;p=onyx.git fixed aliases resolving to self --- diff --git a/bin/onyx b/bin/onyx index 2570cf38..00f961ef 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/container/map.onyx b/core/container/map.onyx index c97d44ad..a1acf621 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -24,14 +24,14 @@ Map :: struct (K: type_expr, V: type_expr) { value : V; } - has :: (package core.map).has - get :: (package core.map).get - get_ptr :: (package core.map).get_ptr - put :: (package core.map).put - delete :: (package core.map).delete - update :: (package core.map).update - clear :: (package core.map).clear - empty :: (package core.map).empty + has :: has + get :: get + get_ptr :: get_ptr + put :: put + delete :: delete + update :: update + clear :: clear + empty :: empty } make :: ($Key: type_expr, $Value: type_expr, default := __zero_value(Value)) -> Map(Key, Value) { diff --git a/core/container/set.onyx b/core/container/set.onyx index d4fb02bf..551e537c 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -21,13 +21,13 @@ Set :: struct (T: type_expr) { value : T; } - has :: (package core.set).has - get :: (package core.set).get - insert :: (package core.set).insert - remove :: (package core.set).remove - clear :: (package core.set).clear - empty :: (package core.set).empty - iterator :: (package core.set).iterator + has :: has + get :: get + insert :: insert + remove :: remove + clear :: clear + empty :: empty + iterator :: iterator } make :: ($T: type_expr, default := __zero_value(T)) -> Set(T) { diff --git a/include/astnodes.h b/include/astnodes.h index bea7e3d5..c6da2856 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -263,6 +263,8 @@ typedef enum AstFlags { // :TEMPORARY Ast_Flag_Params_Introduced = BH_BIT(29), + + Ast_Flag_Symbol_Invisible = BH_BIT(30), } AstFlags; typedef enum UnaryOp { diff --git a/src/symres.c b/src/symres.c index e1d1232d..40e0201c 100644 --- a/src/symres.c +++ b/src/symres.c @@ -227,7 +227,9 @@ static SymresStatus symres_type(AstType** type) { case Ast_Kind_Alias: { AstAlias* alias = (AstAlias *) *type; + alias->flags |= Ast_Flag_Symbol_Invisible; SYMRES(type, (AstType **) &alias->alias); + alias->flags &= ~Ast_Flag_Symbol_Invisible; break; } @@ -436,7 +438,12 @@ static SymresStatus symres_expression(AstTyped** expr) { case Ast_Kind_Method_Call: SYMRES(method_call, (AstBinaryOp **) expr); break; case Ast_Kind_Size_Of: SYMRES(size_of, (AstSizeOf *)*expr); break; case Ast_Kind_Align_Of: SYMRES(align_of, (AstAlignOf *)*expr); break; - case Ast_Kind_Alias: SYMRES(expression, &((AstAlias *) *expr)->alias); break; + case Ast_Kind_Alias: { + (*expr)->flags |= Ast_Flag_Symbol_Invisible; + SYMRES(expression, &((AstAlias *) *expr)->alias); + (*expr)->flags &= ~Ast_Flag_Symbol_Invisible; + break; + } case Ast_Kind_Range_Literal: SYMRES(expression, &((AstRangeLiteral *)(*expr))->low); diff --git a/src/utils.c b/src/utils.c index eac3beca..52fbb2cf 100644 --- a/src/utils.c +++ b/src/utils.c @@ -132,18 +132,21 @@ void symbol_subpackage_introduce(Scope* scope, char* sym, AstPackage* package) { } AstNode* symbol_raw_resolve(Scope* start_scope, char* sym) { - AstNode* res = NULL; Scope* scope = start_scope; - while (res == NULL && scope != NULL) { + while (scope != NULL) { if (bh_table_has(AstNode *, scope->symbols, sym)) { - res = bh_table_get(AstNode *, scope->symbols, sym); - } else { - scope = scope->parent; + AstNode* res = bh_table_get(AstNode *, scope->symbols, sym); + + if ((res->flags & Ast_Flag_Symbol_Invisible) == 0) { + return res; + } } + + scope = scope->parent; } - return res; + return NULL; } AstNode* symbol_resolve(Scope* start_scope, OnyxToken* tkn) {