Add parent_scope on all nodes
This commit is contained in:
41
ccodegen.cpp
41
ccodegen.cpp
@@ -536,24 +536,53 @@ compile_files(Array<String> filename){
|
||||
parse_init(&ctx, scratch, &heap);
|
||||
|
||||
F64 parse_begin = os_time();
|
||||
Array<Ast_Package> packages = {&heap};
|
||||
Array<Ast_Package *> packages = {&heap};
|
||||
For(files){
|
||||
parse_file(&it);
|
||||
Scratch file_scratch;
|
||||
lex_restream(pctx, it.filecontent, it.filename);
|
||||
|
||||
// Figure out package name
|
||||
// by default it's name of the file
|
||||
// but if you add [package name] then it's overwritten
|
||||
Token *token = token_get();
|
||||
it.name = token->file;
|
||||
|
||||
if(token_is(SAME_SCOPE) && token_is_keyword(keyword_package, 1)){
|
||||
token_next(); token_next();
|
||||
Token *package_token = token_expect(TK_Identifier);
|
||||
it.name = package_token->intern_val;
|
||||
}
|
||||
|
||||
Ast_Package *package = find_package(it.name, &packages);
|
||||
if(package){
|
||||
package->decls.add(it.decls);
|
||||
} else {
|
||||
Ast_Package p = ast_package(&heap, it.name, it.decls);
|
||||
insert_builtin_types_into_package(&p);
|
||||
packages.add(p);
|
||||
package = ast_package(token, &heap, it.name);
|
||||
insert_builtin_types_into_package(package);
|
||||
packages.add(package);
|
||||
|
||||
}
|
||||
|
||||
pctx->currently_parsed_scope = package;
|
||||
while(token_expect(SAME_SCOPE)){
|
||||
Ast_Decl *decl = parse_decl(true);
|
||||
if(!decl) break;
|
||||
|
||||
if(decl->kind == AST_STRUCT){
|
||||
decl->type = type_type;
|
||||
decl->type_val = type_incomplete(decl);
|
||||
decl->state = DECL_RESOLVED;
|
||||
}
|
||||
|
||||
package->decls.add(decl);
|
||||
}
|
||||
pctx->currently_parsed_scope = 0;
|
||||
|
||||
}
|
||||
F64 parse_end = os_time();
|
||||
|
||||
For(packages){
|
||||
resolve_package(&it);
|
||||
resolve_package(it);
|
||||
}
|
||||
|
||||
For(pctx->ordered_decls){
|
||||
|
||||
Reference in New Issue
Block a user