dynamic strings in include statements
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 13 Dec 2021 03:21:07 +0000 (21:21 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 13 Dec 2021 03:21:07 +0000 (21:21 -0600)
include/astnodes.h
modules/glfw3/onyx_glfw3.so
modules/opengles/onyx_opengles.so
src/entities.c
src/onyx.c
src/symres.c

index ac9499a42d4212283faeaa8499f8be439f0ac000..7690e5a9d6bb59d8f31f8ad31aa149a1b74a936a 100644 (file)
@@ -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;
index 8b87e8c11431637f9a85e41c41cc7b48503b4c35..f41064aa2453daa874cc96e54dc8504913ed0b44 100755 (executable)
Binary files a/modules/glfw3/onyx_glfw3.so and b/modules/glfw3/onyx_glfw3.so differ
index 532c064c3de5788b048b21f7328710746b5e5a69..8500f5b362fc0a3c64ab45e1b2259504d236a2d6 100755 (executable)
Binary files a/modules/opengles/onyx_opengles.so and b/modules/opengles/onyx_opengles.so differ
index 1176a8e6de17aa9bc517083328b9328c6799ee69..172e809990d7acbfe27998c9d25c9cbe2ecc0fd9 100644 (file)
@@ -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);
index 024840e60b6da5fe8207bb5a71fbc7096daef35d..d091f884da1069ac767750c85cfe791370a6b20f 100644 (file)
@@ -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;
index 9c99f22a36e82e6a300204987f6ee8c54912effc..84e5ff43c72ba1e93a7d688fda3dc353afda30f0 100644 (file)
@@ -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;