-> Operator has very low precedence, size_of, align_of, length_of expressions

This commit is contained in:
Krzosa Karol
2022-06-14 13:50:59 +02:00
parent 17e342c4da
commit f885abe3f5
7 changed files with 121 additions and 58 deletions

34
ast.cpp
View File

@@ -20,6 +20,10 @@ enum Ast_Kind: U32{
AST_CALL_ITEM,
AST_CALL,
AST_SIZE_OF,
AST_LENGTH_OF,
AST_ALIGN_OF,
AST_COMPOUND,
AST_TYPE,
AST_VAR,
@@ -56,7 +60,7 @@ enum{
};
struct Ast{
U64 id;
U64 di; // Debug id, shouldn't ever be used in the program
Token *pos;
Ast_Kind kind;
@@ -119,13 +123,12 @@ struct Ast_Binary: Ast_Expr{
Token_Kind op;
Ast_Expr *left;
Ast_Expr *right;
// Ast_Type *type; // For casts after_type
Ast_Type *before_type;
};
struct Ast_Len: Ast_Expr{
struct Ast_Builtin: Ast_Expr{
Ast_Expr *expr;
U64 padding[3]; // For folding constants into atoms
};
// Problem: We are parsing out of order, in the middle of parsing a function
@@ -236,7 +239,7 @@ struct Ast_Decl: Ast{
result->kind = AST_##ikind; \
result->parent_scope = pctx->currently_parsed_scope; \
result->pos = ipos; \
result->id = ++pctx->unique_ids
result->di = ++pctx->unique_ids
function Ast_Atom *
ast_str(Token *pos, Intern_String string){
@@ -513,6 +516,27 @@ ast_module(Intern_String filename){
return result;
}
function Ast_Builtin *
ast_sizeof(Token *pos, Ast_Expr *expr){
AST_NEW(Builtin, SIZE_OF, pos, AST_EXPR);
result->expr = expr;
return result;
}
function Ast_Builtin *
ast_len(Token *pos, Ast_Expr *expr){
AST_NEW(Builtin, LENGTH_OF, pos, AST_EXPR);
result->expr = expr;
return result;
}
function Ast_Builtin *
ast_alignof(Token *pos, Ast_Expr *expr){
AST_NEW(Builtin, ALIGN_OF, pos, AST_EXPR);
result->expr = expr;
return result;
}
//-----------------------------------------------------------------------------
// Value
//-----------------------------------------------------------------------------