Initial add parent_ast to scopes
This commit is contained in:
@@ -116,6 +116,7 @@ ast_lambda(Token *pos, Array<Ast_Decl *> params, Array<Ast_Expr *> ret, Ast_Scop
|
||||
result->args = params.tight_copy(pctx->perm);
|
||||
result->ret = ret.tight_copy(pctx->perm);
|
||||
result->scope = scope;
|
||||
scope->parent_ast = result;
|
||||
|
||||
For(params) {
|
||||
if (is_flag_set(it->flags, AST_POLYMORPH)) {
|
||||
@@ -141,6 +142,7 @@ ast_for(Token *pos, Ast_Expr *init, Ast_Expr *cond, Ast_Expr *iter, Ast_Scope *s
|
||||
result->cond = cond;
|
||||
result->iter = iter;
|
||||
result->scope = scope;
|
||||
scope->parent_ast = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -178,6 +180,7 @@ ast_if_node(Token *pos, Ast_Expr *init, Ast_Expr *expr, Ast_Scope *scope) {
|
||||
result->scope = scope;
|
||||
result->expr = expr;
|
||||
result->init = (Ast_Binary *)init;
|
||||
scope->parent_ast = result;
|
||||
if (result->init) {
|
||||
assert(init->kind == AST_VAR);
|
||||
}
|
||||
@@ -233,6 +236,7 @@ ast_struct(Token *pos, Ast_Scope *scope, Ast_Kind kind, Array<Ast_Decl *> polymo
|
||||
AST_NEW(Decl, STRUCT, pos, AST_DECL | AST_AGGREGATE);
|
||||
result->kind = kind;
|
||||
result->scope = scope;
|
||||
scope->parent_decl = result;
|
||||
if (polymorph_parameters.len) {
|
||||
result->polymorph_parameters = polymorph_parameters;
|
||||
set_flag(result->flags, AST_POLYMORPH);
|
||||
@@ -246,6 +250,7 @@ ast_enum(Token *pos, Ast_Expr *typespec, Ast_Scope *scope) {
|
||||
AST_NEW(Decl, ENUM, pos, AST_DECL);
|
||||
result->scope = scope;
|
||||
result->typespec = typespec;
|
||||
scope->parent_decl = result;
|
||||
set_flag_typespec(typespec);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -567,25 +567,6 @@ struct Ast_Switch : Ast {
|
||||
Ast_Scope *default_scope;
|
||||
};
|
||||
|
||||
/*
|
||||
How does current declaration order resolver works:
|
||||
* First we put all the global declarations into the global scope (when parsing) all unresolved
|
||||
* All the types are declared INCOMPLETE and RESOLVED
|
||||
* We descent the tree by resolving each of the named declarations, we resolve by their name
|
||||
When we start resolving we set RESOLVING flag and when we complete RESOLVED flag
|
||||
and put into ordered list
|
||||
* When we meet a symbol (named declaration) while descending the tree,
|
||||
we resolve that symbol instead before resolving current declaration.
|
||||
* When we meet a declaration that requires size of a type - field access, var assignment,
|
||||
we need to call "complete_type", it sets COMPLETING flag.
|
||||
This call resolves all the dependencies of that type,
|
||||
sets size of type and marks it as COMPLETE and puts into ordered list.
|
||||
If it detects COMPLETING while
|
||||
resolving, we got a circular dependency. That might happen when we have
|
||||
that struct without pointer inside itself.
|
||||
|
||||
*/
|
||||
|
||||
struct Ast_Scope : Ast {
|
||||
String debug_name; // Only for debug purposes, dont depend on it
|
||||
List<Ast_Scope *> implicit_imports;
|
||||
@@ -595,7 +576,10 @@ struct Ast_Scope : Ast {
|
||||
uint32_t scope_id;
|
||||
Ast_Scope *file; // Self referential for file and module
|
||||
Ast_Module *module;
|
||||
Ast_Decl *parent_decl; // @language_todo: add parent decl
|
||||
union {
|
||||
Ast *parent_ast; // @language_todo: add parent decl
|
||||
Ast_Decl *parent_decl;
|
||||
};
|
||||
};
|
||||
|
||||
enum Ast_Module_State {
|
||||
|
||||
@@ -937,22 +937,23 @@ parse_decl(B32 is_global) {
|
||||
// implementing actual parse_lambda or something. Probably needs less
|
||||
// ambigious syntax.
|
||||
if (expr->kind == AST_LAMBDA_EXPR) {
|
||||
auto a = (Ast_Lambda *)expr;
|
||||
if (a->scope || is_flag_set(flags, AST_FOREIGN)) {
|
||||
auto lambda = (Ast_Lambda *)expr;
|
||||
if (lambda->scope || is_flag_set(flags, AST_FOREIGN)) {
|
||||
result->kind = AST_LAMBDA;
|
||||
if (is_flag_set(a->flags, AST_POLYMORPH)) {
|
||||
lambda->scope->parent_decl = result;
|
||||
if (is_flag_set(lambda->flags, AST_POLYMORPH)) {
|
||||
set_flag(result->flags, AST_POLYMORPH);
|
||||
set_flag(result->flags, AST_PARENT_POLYMORPH);
|
||||
|
||||
int polymorph_count = 0;
|
||||
For(a->args) {
|
||||
For(lambda->args) {
|
||||
if (it->flags & AST_POLYMORPH) {
|
||||
polymorph_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
result->polymorph_parameters.init(pctx->perm, polymorph_count);
|
||||
For(a->args) {
|
||||
For(lambda->args) {
|
||||
if (it->flags & AST_POLYMORPH) {
|
||||
result->polymorph_parameters.add(it);
|
||||
}
|
||||
@@ -967,8 +968,7 @@ parse_decl(B32 is_global) {
|
||||
else if (token_match(TK_StringLit, TK_DoubleColon)) {
|
||||
|
||||
// @cleanup: consider simplifying lambdas, removing AST_LAMBDA_EXPR and
|
||||
// implementing actual parse_lambda or something. Probably needs less
|
||||
// ambigious syntax.
|
||||
// implementing actual parse_lambda or something.
|
||||
Ast_Lambda *expr = (Ast_Lambda *)parse_expr();
|
||||
if (expr->kind != AST_LAMBDA_EXPR) {
|
||||
compiler_error(tname, "Operator overload is required to be a lambda function");
|
||||
|
||||
Reference in New Issue
Block a user