Add error messages when file not found + error position
This commit is contained in:
4
ast.cpp
4
ast.cpp
@@ -510,8 +510,8 @@ ast_module_namespace(Token *pos, Ast_Module *module, Intern_String name){
|
||||
}
|
||||
|
||||
function Ast_Module *
|
||||
ast_module(Intern_String filename){
|
||||
AST_NEW(Module, MODULE, 0, 0);
|
||||
ast_module(Token *pos, Intern_String filename){
|
||||
AST_NEW(Module, MODULE, pos, 0);
|
||||
result->parent_scope = 0;
|
||||
result->kind = AST_MODULE;
|
||||
result->name = filename;
|
||||
|
||||
14
ccodegen.cpp
14
ccodegen.cpp
@@ -597,11 +597,13 @@ gen_ast(Ast *ast){
|
||||
|
||||
function void
|
||||
parse_file(Ast_File *file){
|
||||
assert(file);
|
||||
|
||||
Scratch scratch;
|
||||
file->filecontent = os_read_file(pctx->perm, file->filename.s);
|
||||
assert(file);
|
||||
assert(file->filecontent.len);
|
||||
assert(file->filename.len);
|
||||
if(file->filecontent.len == 0){
|
||||
compiler_error(file->pos, "Failed to open file \"%Q\"", file->filename);
|
||||
}
|
||||
|
||||
|
||||
pctx->currently_parsed_file = file;
|
||||
@@ -685,7 +687,7 @@ parse_all_modules(){
|
||||
}
|
||||
|
||||
function Ast_Module *
|
||||
add_module(Intern_String filename){
|
||||
add_module(Token *pos, Intern_String filename){
|
||||
For(pctx->modules){
|
||||
if(it->name == filename){
|
||||
log_info("Returning registered module: %Q\n", filename);
|
||||
@@ -694,8 +696,8 @@ add_module(Intern_String filename){
|
||||
}
|
||||
|
||||
log_info("Adding module: %Q\n", filename);
|
||||
Ast_Module *result = ast_module(filename);
|
||||
register_ast_file(result->name, result, true);
|
||||
Ast_Module *result = ast_module(pos, filename);
|
||||
register_ast_file(pos, result->name, result, true);
|
||||
pctx->modules.add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ struct Ast_File_Namespace;
|
||||
struct Ast_File;
|
||||
struct Ast_Module;
|
||||
struct Ast_Type;
|
||||
function Ast_Module *ast_module(Intern_String filename);
|
||||
function Ast_Module *ast_module(Token *pos, Intern_String filename);
|
||||
function void insert_builtin_types_into_scope(Ast_Scope *p);
|
||||
|
||||
enum Token_Kind{
|
||||
@@ -246,7 +246,7 @@ parse_init(Parse_Ctx *ctx, Allocator *perm_allocator, Allocator *heap_allocator)
|
||||
arena_init(&ctx->stage_arena, "Compiler stage arena"_s);
|
||||
|
||||
lex_init(ctx->perm, ctx->heap, ctx);
|
||||
ctx->builtins = ast_module(ctx->intern("builtins"_s));
|
||||
ctx->builtins = ast_module(0, ctx->intern("builtins"_s));
|
||||
insert_builtin_types_into_scope((Ast_Scope *)ctx->builtins);
|
||||
|
||||
init_type();
|
||||
|
||||
4
main.cpp
4
main.cpp
@@ -176,8 +176,8 @@ int main(int argument_count, char **arguments){
|
||||
|
||||
F64 total_time = os_time();
|
||||
begin_compilation();
|
||||
|
||||
Ast_Module *module = add_module(pctx->intern(program_name));
|
||||
|
||||
Ast_Module *module = add_module(0, pctx->intern(program_name));
|
||||
parse_all_modules();
|
||||
assert(module);
|
||||
resolve_everything_in_module(module);
|
||||
|
||||
@@ -671,7 +671,7 @@ add_implicit_import(Ast_Scope *scope, Ast_Scope *add){
|
||||
}
|
||||
|
||||
function Ast_File *
|
||||
register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implicit_load){
|
||||
register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 global_implicit_load){
|
||||
Ast_File *file = 0;
|
||||
For(module->all_loaded_files){
|
||||
if(it->filename == filename){
|
||||
@@ -691,6 +691,7 @@ register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implici
|
||||
file->decls = {pctx->heap};
|
||||
file->implicit_imports = {pctx->heap};
|
||||
file->module->all_loaded_files.add(file);
|
||||
file->pos = pos;
|
||||
}
|
||||
|
||||
if(global_implicit_load) {
|
||||
@@ -703,15 +704,15 @@ register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implici
|
||||
function Ast_File *
|
||||
parse_load(B32 global_implicit_load){
|
||||
Token *file = token_expect(TK_StringLit);
|
||||
Ast_File *result = register_ast_file(file->intern_val, pctx->currently_parsed_file->module, global_implicit_load);
|
||||
Ast_File *result = register_ast_file(file, file->intern_val, pctx->currently_parsed_file->module, global_implicit_load);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Module *add_module(Intern_String filename);
|
||||
function Ast_Module *add_module(Token *pos, Intern_String filename);
|
||||
function Ast_Module *
|
||||
parse_import(B32 global_implicit_import){
|
||||
Token *file = token_expect(TK_StringLit);
|
||||
Ast_Module *result = add_module(file->intern_val);
|
||||
Ast_Module *result = add_module(file, file->intern_val);
|
||||
if(global_implicit_import){
|
||||
add_implicit_import(pctx->currently_parsed_file->module, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user