-> Operator has very low precedence, size_of, align_of, length_of expressions
This commit is contained in:
26
ccodegen.cpp
26
ccodegen.cpp
@@ -256,6 +256,7 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){
|
||||
CASE(INDEX, Index){
|
||||
gen("(");
|
||||
gen_expr(node->expr);
|
||||
if(node->expr->resolved_type == type_string) gen(".str");
|
||||
gen("[");
|
||||
gen_expr(node->index);
|
||||
gen("]");
|
||||
@@ -310,19 +311,15 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(CALL, Call){
|
||||
if(node->name->kind == AST_IDENT){
|
||||
auto ident = (Ast_Atom *)node->name;
|
||||
if(ident->intern_val == pctx->intern("len"_s)){
|
||||
if(is_slice(ident->type)){
|
||||
Ast_Call_Item *arg = node->exprs[0];
|
||||
gen_expr(arg->item);
|
||||
gen(".len");
|
||||
return true;
|
||||
} else invalid_codepath;
|
||||
}
|
||||
}
|
||||
CASE(LENGTH_OF, Builtin){
|
||||
gen_expr(node->expr);
|
||||
if(is_pointer(node->expr->resolved_type))
|
||||
gen("->len");
|
||||
else gen(".len");
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(CALL, Call){
|
||||
gen_expr(node->name);
|
||||
gen("(");
|
||||
For(node->exprs){
|
||||
@@ -680,10 +677,7 @@ typedef struct String{
|
||||
#endif
|
||||
For(pctx->ordered_decls){
|
||||
if(it->kind == AST_STRUCT){
|
||||
genln("typedef struct struct %s;", it->name.str);
|
||||
} else if(it->kind == AST_LAMBDA){
|
||||
genln("");
|
||||
gen_lambda(it->name, it->lambda, false);
|
||||
genln("typedef struct %s %s;", it->name.str, it->name.str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user