Getting absolute paths, Ast_Files now compare absolute paths
This commit is contained in:
1
ast.cpp
1
ast.cpp
@@ -245,6 +245,7 @@ struct Ast_Module: Ast_Scope{
|
||||
};
|
||||
|
||||
struct Ast_File: Ast_Scope{
|
||||
String absolute_path;
|
||||
Intern_String filename;
|
||||
String filecontent;
|
||||
};
|
||||
|
||||
16
compiler.h
16
compiler.h
@@ -200,6 +200,10 @@ struct Parse_Ctx:Lexer{
|
||||
Ast_Scope *currently_parsed_scope;
|
||||
Ast_File *currently_parsed_file;
|
||||
|
||||
Array<String> module_folders;
|
||||
String module_folder;
|
||||
String exe_folder;
|
||||
|
||||
S64 indent;
|
||||
String_Builder gen;
|
||||
String_Builder helper_builder;
|
||||
@@ -261,6 +265,16 @@ 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);
|
||||
|
||||
init_type();
|
||||
|
||||
// Init paths
|
||||
ctx->exe_folder = os_get_exe_dir(ctx->perm);
|
||||
|
||||
ctx->module_folders = {ctx->heap};
|
||||
String main_module = string_fmt(ctx->perm, "%Q/modules", ctx->exe_folder);
|
||||
ctx->module_folders.add(main_module);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
6
main.cpp
6
main.cpp
@@ -221,12 +221,6 @@ int main(int argument_count, char **arguments){
|
||||
test_intern_table();
|
||||
test_bucket_arrays();
|
||||
|
||||
Scratch scratch;
|
||||
String a = os_get_working_dir(scratch);
|
||||
String b = os_get_exe_dir(scratch);
|
||||
Array<OS_File_Info> files = os_list_dir(scratch, ".."_s, LIST_RECURSE_INTO_DIRS);
|
||||
|
||||
|
||||
emit_line_directives = true;
|
||||
String program_name = "main.kl"_s;
|
||||
if(argument_count > 1){
|
||||
|
||||
21
parsing.cpp
21
parsing.cpp
@@ -719,10 +719,12 @@ enum{
|
||||
function Ast_File *
|
||||
register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 global_implicit_load){
|
||||
Ast_File *file = 0;
|
||||
String absolute_path = os_get_absolute_path(pctx->perm, filename.s);
|
||||
|
||||
For(pctx->files){
|
||||
if(it->filename == filename){
|
||||
if(string_compare(it->absolute_path, absolute_path)){
|
||||
if(module == it->module){
|
||||
log_info("%Q :: Returning registered file: %Q\n", module->name, filename);
|
||||
log_info("%Q :: Returning registered file: %Q\n", module->name, absolute_path);
|
||||
file = it;
|
||||
break;
|
||||
}
|
||||
@@ -735,16 +737,17 @@ register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 gl
|
||||
if(!file){
|
||||
log_info("%Q :: Registering file: %Q\n", module->name, filename);
|
||||
AST_NEW(File, FILE, 0, 0);
|
||||
file = result;
|
||||
file->filename = filename;
|
||||
file->module = module;
|
||||
file->parent_scope = 0;
|
||||
file->file = file; // @warning: self referential!
|
||||
file->decls = {pctx->heap};
|
||||
file = result;
|
||||
file->absolute_path = absolute_path;
|
||||
file->filename = filename;
|
||||
file->module = module;
|
||||
file->parent_scope = 0;
|
||||
file->file = file; // @warning: self referential!
|
||||
file->decls = {pctx->heap};
|
||||
file->implicit_imports = {pctx->heap};
|
||||
file->pos = pos;
|
||||
file->module->all_loaded_files.add(file);
|
||||
pctx->files.add(file);
|
||||
file->pos = pos;
|
||||
}
|
||||
|
||||
if(global_implicit_load) {
|
||||
|
||||
Reference in New Issue
Block a user