From: Brendan Hansen Date: Mon, 13 Dec 2021 03:21:07 +0000 (-0600) Subject: dynamic strings in include statements X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=51a37d1e47c4ce2deab1b570d504bdde21c24adc;p=onyx.git dynamic strings in include statements --- diff --git a/include/astnodes.h b/include/astnodes.h index ac9499a4..7690e5a9 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -955,7 +955,7 @@ struct AstDistinctType { // Top level nodes struct AstBinding { AstTyped_base; AstNode* node; }; struct AstAlias { AstTyped_base; AstTyped* alias; }; -struct AstInclude { AstNode_base; AstNode* name_node; char* name; }; +struct AstInclude { AstNode_base; AstTyped* name_node; char* name; }; struct AstMemRes { AstTyped_base; u64 addr; diff --git a/modules/glfw3/onyx_glfw3.so b/modules/glfw3/onyx_glfw3.so index 8b87e8c1..f41064aa 100755 Binary files a/modules/glfw3/onyx_glfw3.so and b/modules/glfw3/onyx_glfw3.so differ diff --git a/modules/opengles/onyx_opengles.so b/modules/opengles/onyx_opengles.so index 532c064c..8500f5b3 100755 Binary files a/modules/opengles/onyx_opengles.so and b/modules/opengles/onyx_opengles.so differ diff --git a/src/entities.c b/src/entities.c index 1176a8e6..172e8099 100644 --- a/src/entities.c +++ b/src/entities.c @@ -162,7 +162,6 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s switch (node->kind) { case Ast_Kind_Load_File: { - ent.state = Entity_State_Parse; ent.type = Entity_Type_Load_File; ent.include = (AstInclude *) node; ENTITY_INSERT(ent); @@ -171,7 +170,6 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s case Ast_Kind_Library_Path: case Ast_Kind_Load_Path: { - ent.state = Entity_State_Parse; ent.type = Entity_Type_Load_Path; ent.include = (AstInclude *) node; ENTITY_INSERT(ent); diff --git a/src/onyx.c b/src/onyx.c index 024840e6..d091f884 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -283,7 +283,7 @@ static b32 process_source_file(char* filename, OnyxFilePos error_pos) { bh_arr_each(bh_file_contents, fc, context.loaded_files) { // Duplicates are detected here and since these filenames will be the full path, // string comparing them should be all that is necessary. - if (!strcmp(fc->filename, filename)) return; + if (!strcmp(fc->filename, filename)) return 1; } bh_file file; diff --git a/src/symres.c b/src/symres.c index 9c99f22a..84e5ff43 100644 --- a/src/symres.c +++ b/src/symres.c @@ -20,6 +20,7 @@ static Entity* waiting_on = NULL; typedef enum SymresStatus { Symres_Success, Symres_Complete, + Symres_Goto_Parse, Symres_Errors_Start, Symres_Yield_Macro, @@ -1390,6 +1391,26 @@ static SymresStatus symres_foreign_block(AstForeignBlock *fb) { return Symres_Complete; } +static SymresStatus symres_include(AstInclude* include) { + if (include->name != NULL) return Symres_Goto_Parse; + + SYMRES(expression, &include->name_node); + + if (include->name_node->kind != Ast_Kind_StrLit) { + onyx_report_error(include->token->pos, "Expected compile-time known string literal here. Got '%s'.", onyx_ast_node_kind_string(include->name_node->kind)); + return Symres_Error; + } + + OnyxToken* str_token = include->name_node->token; + if (str_token != NULL) { + token_toggle_end(str_token); + include->name = bh_strdup(context.ast_alloc, str_token->text); + token_toggle_end(str_token); + } + + return Symres_Goto_Parse; +} + void symres_entity(Entity* ent) { if (ent->scope) scope_enter(ent->scope); @@ -1408,6 +1429,9 @@ void symres_entity(Entity* ent) { case Entity_Type_Static_If: ss = symres_static_if(ent->static_if); break; + case Entity_Type_Load_Path: + case Entity_Type_Load_File: ss = symres_include(ent->include); break; + case Entity_Type_Foreign_Function_Header: case Entity_Type_Temp_Function_Header: case Entity_Type_Function_Header: ss = symres_function_header(ent->function); break; @@ -1444,6 +1468,7 @@ void symres_entity(Entity* ent) { if (ss == Symres_Yield_Macro) ent->macro_attempts++; if (ss == Symres_Yield_Micro) ent->micro_attempts++; if (ss == Symres_Complete) ent->state = Entity_State_Finalized; + if (ss == Symres_Goto_Parse) ent->state = Entity_State_Parse; if (ss == Symres_Success) { ent->macro_attempts = 0; ent->micro_attempts = 0;