From 26ea8f6dcb4f49565817fa5a06187e228c8ee693 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 15 Oct 2017 12:11:33 +0100 Subject: Syntax: Replace `foreign_system_library "kernel.lib"` to `foreign_library "system:kernel.lib"`; Remove keyword: `foreign_system_library` --- src/checker.cpp | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index 4b2ddef8a..ca2780f49 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1213,6 +1213,9 @@ void add_entity_use(Checker *c, AstNode *identifier, Entity *entity) { if (identifier->kind != AstNode_Ident) { return; } + if (entity == nullptr) { + return; + } if (entity->identifier == nullptr) { entity->identifier = identifier; } @@ -2604,33 +2607,37 @@ void check_add_foreign_library_decl(Checker *c, AstNode *decl) { Scope *parent_scope = c->context.scope; GB_ASSERT(parent_scope->is_file); - String file_str = fl->filepath.string; - String base_dir = fl->base_dir; + String fullpath = fl->fullpath; + String library_name = path_to_entity_name(fl->library_name.string, fullpath); + if (is_blank_ident(library_name)) { + error(fl->token, "File name, %.*s, cannot be as a library name as it is not a valid identifier", LIT(fl->library_name.string)); + return; + } - if (fl->token.kind == Token_foreign_library) { - gbAllocator a = heap_allocator(); // TODO(bill): Change this allocator + if (fl->collection_name != "system") { + char *c_str = gb_alloc_array(heap_allocator(), char, fullpath.len+1); + defer (gb_free(heap_allocator(), c_str)); + gb_memcopy(c_str, fullpath.text, fullpath.len); + c_str[fullpath.len] = '\0'; - String rel_path = get_fullpath_relative(a, base_dir, file_str); - String import_file = rel_path; - if (!gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated - String abs_path = get_fullpath_core(a, file_str); - if (gb_file_exists(cast(char *)abs_path.text)) { - import_file = abs_path; - } + gbFile f = {}; + gbFileError file_err = gb_file_open(&f, c_str); + + switch (file_err) { + case gbFileError_Invalid: + error(decl, "Invalid file or cannot be found (`%.*s`)", LIT(fullpath)); + return; + case gbFileError_NotExists: + error(decl, "File cannot be found (`%.*s`)", LIT(fullpath)); + return; } - file_str = import_file; } - String library_name = path_to_entity_name(fl->library_name.string, file_str); - if (is_blank_ident(library_name)) { - error(fl->token, "File name, %.*s, cannot be as a library name as it is not a valid identifier", LIT(fl->library_name.string)); - } else { - GB_ASSERT(fl->library_name.pos.line != 0); - fl->library_name.string = library_name; - Entity *e = make_entity_library_name(c->allocator, parent_scope, fl->library_name, t_invalid, - file_str, library_name); - add_entity(c, parent_scope, nullptr, e); - } + GB_ASSERT(fl->library_name.pos.line != 0); + fl->library_name.string = library_name; + Entity *e = make_entity_library_name(c->allocator, parent_scope, fl->library_name, t_invalid, + fl->fullpath, library_name); + add_entity(c, parent_scope, nullptr, e); } -- cgit v1.2.3