code cleanup; warning and bug fixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 30 Sep 2022 03:33:14 +0000 (22:33 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 30 Sep 2022 03:33:14 +0000 (22:33 -0500)
compiler/src/checker.c
compiler/src/symres.c
compiler/src/wasm_emit.c

index 67b88746468ae45bdd7d23522a1db7d515ecf4a8..ed8674a7538c150f62be0d2168ed86dcb0369e60 100644 (file)
@@ -2469,7 +2469,11 @@ CheckStatus check_function_header(AstFunction* func) {
 
     if (func->constraints.constraints != NULL && func->constraints.constraints_met == 0) {
         func->constraints.produce_errors = (func->flags & Ast_Flag_Header_Check_No_Error) == 0;
-        CHECK(constraint_context, &func->constraints, func->scope, func->token->pos);
+
+        OnyxToken *tkn = func->token;
+        if (func->generated_from) tkn = func->generated_from;
+
+        CHECK(constraint_context, &func->constraints, func->scope, tkn->pos);
 
         // All constraints have been met. Return to symbol resolution to finish
         // looking up all symbols in the function.
index 54a14cf4bd5ce8f89798c2e6073e38fee0c7a1e3..e8433bd1a6d92963d225a9a08c5ce1020b8c6c4b 100644 (file)
@@ -768,75 +768,62 @@ static SymresStatus symres_switch(AstSwitch* switchnode) {
     return Symres_Success;
 }
 
-// CLEANUP: A lot of duplication going on in this function. A proper
-// "namespace" concept would be useful to remove a lot of the fluff
-// code here. There already is try_resolve_symbol_from_node which
-// may be able to do what is needed here?
 static SymresStatus symres_use(AstUse* use) {
     SYMRES(expression, &use->expr);
 
     AstTyped *use_expr = (AstTyped *) strip_aliases((AstNode *) use->expr);
 
+    Scope* used_scope = NULL;
+
     // :EliminatingSymres
     if (use_expr->kind == Ast_Kind_Package) {
         AstPackage* package = (AstPackage *) use_expr;
         SYMRES(package, package);
 
-        if (package->package->scope == curr_scope) return Symres_Success;
-
-        if (use->only == NULL) {
-            OnyxFilePos pos = { 0 };
-            if (use->token != NULL)
-                pos = use->token->pos;
-
-            scope_include(curr_scope, package->package->scope, pos);
-
-        } else {
-            bh_arr_each(QualifiedUse, qu, use->only) {
-                AstNode* thing = symbol_resolve(package->package->scope, qu->symbol_name);
-                if (thing == NULL) { // :SymresStall
-                    if (report_unresolved_symbols) {
-                        onyx_report_error(qu->symbol_name->pos, Error_Critical, 
-                                "The symbol '%b' was not found in this package.",
-                                qu->symbol_name->text, qu->symbol_name->length);
-                        return Symres_Error;
-                    } else {
-                        return Symres_Yield_Macro;
-                    }
-                }
-
-                symbol_introduce(curr_scope, qu->as_name, thing);
-            }
-        }
-
         if (!use->entity) {
             add_entities_for_node(NULL, (AstNode *) use, curr_scope, NULL);
         }
 
         package_track_use_package(package->package, use->entity);
-        return Symres_Success;
+        used_scope = package->package->scope;
     }
 
     if (use_expr->kind == Ast_Kind_Foreign_Block) {
         AstForeignBlock* fb = (AstForeignBlock *) use_expr;
         if (fb->entity->state <= Entity_State_Resolve_Symbols) return Symres_Yield_Macro;
 
-        if (fb->scope == curr_scope) return Symres_Success;
+        used_scope = fb->scope;
+    }
+
+    if (use_expr->kind == Ast_Kind_Enum_Type) {
+        AstEnumType* et = (AstEnumType *) use_expr;
+        used_scope = et->scope;
+    }
+
+    if (use_expr->kind == Ast_Kind_Struct_Type) {
+        AstStructType* st = (AstStructType *) use_expr;
+        if (!st->scope) return Symres_Success;
+
+        used_scope = st->scope;
+    }
+
+    if (used_scope) {
+        if (used_scope == curr_scope) return Symres_Success;
 
         if (use->only == NULL) {
             OnyxFilePos pos = { 0 };
             if (use->token != NULL)
                 pos = use->token->pos;
 
-            scope_include(curr_scope, fb->scope, pos);
+            scope_include(curr_scope, used_scope, pos);
 
         } else {
             bh_arr_each(QualifiedUse, qu, use->only) {
-                AstNode* thing = symbol_resolve(fb->scope, qu->symbol_name);
+                AstNode* thing = symbol_resolve(used_scope, qu->symbol_name);
                 if (thing == NULL) { // :SymresStall
                     if (report_unresolved_symbols) {
                         onyx_report_error(qu->symbol_name->pos, Error_Critical, 
-                                "The symbol '%b' was not found in this package.",
+                                "The symbol '%b' was not found in the used scope.",
                                 qu->symbol_name->text, qu->symbol_name->length);
                         return Symres_Error;
                     } else {
@@ -851,39 +838,6 @@ static SymresStatus symres_use(AstUse* use) {
         return Symres_Success;
     }
 
-    if (use_expr->kind == Ast_Kind_Enum_Type) {
-        AstEnumType* et = (AstEnumType *) use_expr;
-
-        bh_arr_each(AstEnumValue *, ev, et->values)
-            symbol_introduce(curr_scope, (*ev)->token, (AstNode *) *ev);
-
-        return Symres_Success;
-    }
-
-    if (use_expr->kind == Ast_Kind_Struct_Type) {
-        AstStructType* st = (AstStructType *) use_expr;
-        if (!st->scope) return Symres_Success;
-
-        if (use->only == NULL) {
-            scope_include(curr_scope, st->scope, use->token->pos);
-
-        } else {
-            bh_arr_each(QualifiedUse, qu, use->only) {
-                AstNode* thing = symbol_resolve(st->scope, qu->symbol_name);
-                if (thing == NULL) {
-                    onyx_report_error(qu->symbol_name->pos, Error_Critical, 
-                            "The symbol '%b' was not found in this scope.",
-                            qu->symbol_name->text, qu->symbol_name->length);
-                    return Symres_Error;
-                }
-
-                symbol_introduce(curr_scope, qu->as_name, thing);
-            }
-        }
-
-        return Symres_Success;
-    }
-
     if (use_expr->type_node == NULL && use_expr->type == NULL) goto cannot_use;
 
     // :EliminatingSymres
index c724a1361ba2d4ea66ff1be501de38a30e4a8651..17e981a5b399ad720b365a555fa71abdfcc3ba45 100644 (file)
@@ -2123,7 +2123,7 @@ EMIT_FUNC(method_call, AstBinaryOp *mcall) {
     // Do the common assignment pattern found everywhere else.
     if (!tmp_is_wasm_local) emit_local_location(mod, &code, tmp_local, &offset);
 
-    emit_expression(mod, &code, *object);
+    emit_expression(mod, &code, (AstTyped *) *object);
 
     if (!tmp_is_wasm_local) emit_store_instruction(mod, &code, tmp_local->type, offset);
     else                    WIL(mcall->token, WI_LOCAL_SET, tmp_local_idx);