More order independent globals
This commit is contained in:
27
new_ast.cpp
27
new_ast.cpp
@@ -211,9 +211,11 @@ struct Ast_Array: Ast_Expr{
|
||||
Ast_Expr *expr;
|
||||
};
|
||||
|
||||
struct Ast_Resolved_Type;
|
||||
struct Ast_Struct: Ast_Expr{
|
||||
// Required to be Ast_Struct or Ast_Var or Ast_Const
|
||||
Array<Ast *> members;
|
||||
Ast_Resolved_Type *type;
|
||||
};
|
||||
|
||||
struct Ast_Named:Ast{
|
||||
@@ -469,11 +471,20 @@ ast_package(Token *pos, String name, Array<Ast_Named *> decls){
|
||||
// Utillities
|
||||
//-----------------------------------------------------------------------------
|
||||
function Ast_Struct *
|
||||
const_get_struct(Ast *ast){
|
||||
const_try_getting_struct(Ast *ast){
|
||||
assert(ast->kind == AST_CONST);
|
||||
Ast_Const *constant = (Ast_Const *)ast;
|
||||
assert(constant->value->kind == AST_STRUCT);
|
||||
return (Ast_Struct *)constant->value;
|
||||
if(constant->value->kind == AST_STRUCT){
|
||||
return (Ast_Struct *)constant->value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function Ast_Struct *
|
||||
const_get_struct(Ast *ast){
|
||||
auto result = const_try_getting_struct(ast);
|
||||
assert(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Intern_String
|
||||
@@ -482,3 +493,13 @@ ast_get_name(Ast *ast){
|
||||
auto constant = (Ast_Named *)ast;
|
||||
return constant->name;
|
||||
}
|
||||
|
||||
function B32
|
||||
ast_is_struct(Ast *ast){
|
||||
if(ast->kind == AST_CONST){
|
||||
auto a = (Ast_Const *)ast;
|
||||
B32 result = a->agg->kind == AST_STRUCT;
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user