More work on modules, Ast_Module, Ast_File and Ast_Scope got unified
This commit is contained in:
20
ast.cpp
20
ast.cpp
@@ -205,7 +205,8 @@ struct Ast_Scope: Ast{
|
||||
Array<Ast_Decl *> decls;
|
||||
Array<Ast *> stmts;
|
||||
|
||||
Ast_File *file; // Null for module scope, file scope
|
||||
Ast_Scope *file; // Self referential for scope and module
|
||||
Ast_Module *module;
|
||||
};
|
||||
|
||||
|
||||
@@ -216,7 +217,6 @@ struct Ast_Module: Ast_Scope{
|
||||
|
||||
struct Ast_File: Ast_Scope{
|
||||
Intern_String filename;
|
||||
Ast_Module *module;
|
||||
|
||||
B32 global_implicit_load;
|
||||
String filecontent;
|
||||
@@ -414,6 +414,7 @@ begin_decl_scope(Allocator *scratch, Token *pos){
|
||||
AST_NEW(Scope, SCOPE, pos, AST_DECL);
|
||||
result->decls = {scratch};
|
||||
result->file = pctx->currently_parsed_file;
|
||||
result->module = pctx->currently_parsed_file->module;
|
||||
assert(result->file);
|
||||
pctx->currently_parsed_scope = result;
|
||||
return result;
|
||||
@@ -431,6 +432,7 @@ begin_stmt_scope(Allocator *scratch, Token *pos){
|
||||
result->stmts = {scratch};
|
||||
result->decls = {pctx->heap};
|
||||
result->file = pctx->currently_parsed_file;
|
||||
result->module = pctx->currently_parsed_file->module;
|
||||
assert(result->file);
|
||||
pctx->currently_parsed_scope = result;
|
||||
return result;
|
||||
@@ -516,6 +518,20 @@ ast_module_namespace(Token *pos, Ast_Module *module, Intern_String name){
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Module *
|
||||
ast_module(Intern_String filename){
|
||||
AST_NEW(Module, MODULE, 0, 0);
|
||||
result->kind = AST_MODULE;
|
||||
result->name = filename;
|
||||
result->module = result;
|
||||
result->file = result;
|
||||
result->all_loaded_files = {pctx->heap};
|
||||
result->implicit_loads = {pctx->heap};
|
||||
result->implicit_imports = {pctx->heap};
|
||||
result->decls = {pctx->heap};
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Value
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user