New AST
This commit is contained in:
82
print.c
82
print.c
@@ -12,45 +12,6 @@ token_print(Token *token){
|
||||
lex_print("%.*s", (S32)token->len, token->str);
|
||||
}
|
||||
|
||||
function Type *type_pointer(Parser *p, Type *base);
|
||||
function void expr_print(Expr *expr);
|
||||
|
||||
function void
|
||||
type_print(Type *type){
|
||||
switch(type->kind) {
|
||||
case TK_S64: case TK_U64:
|
||||
case TK_SizeU: case TK_Void: {
|
||||
lex_print("%s", type_kind_string[type->kind].str);
|
||||
} break;
|
||||
case TK_Pointer:{
|
||||
type_print(type->pointer);
|
||||
lex_print("*");
|
||||
} break;
|
||||
case TK_Function:{
|
||||
type_print(type->decl->func_val.return_type);
|
||||
lex_print("(");
|
||||
for(Decl *n = type->decl->func_val.first; n; n=n->next){
|
||||
token_print(n->token); // @Todo(Krzosa):
|
||||
}
|
||||
lex_print(")");
|
||||
} break;
|
||||
case TK_Array:{
|
||||
type_print(type->array.pointer);
|
||||
lex_print("[");
|
||||
expr_print(type->array.size);
|
||||
lex_print("]");
|
||||
} break;
|
||||
default: {invalid_codepath;} break;
|
||||
}
|
||||
}
|
||||
|
||||
function void
|
||||
type_test(Parser *p){
|
||||
Type *t = type_pointer(p, type_s64);
|
||||
t = type_pointer(p, t);
|
||||
type_print(t);
|
||||
}
|
||||
|
||||
function void
|
||||
expr_print(Expr *expr){
|
||||
switch(expr->kind) {
|
||||
@@ -93,7 +54,7 @@ expr_print(Expr *expr){
|
||||
case EK_Cast:{
|
||||
lex_print("(");
|
||||
lex_print("(");
|
||||
type_print(expr->cast.type);
|
||||
//type_print(expr->cast.type);
|
||||
lex_print(")");
|
||||
expr_print(expr->cast.expr);
|
||||
lex_print(")");
|
||||
@@ -113,44 +74,3 @@ expr_print(Expr *expr){
|
||||
default: {invalid_codepath;} break;
|
||||
}
|
||||
}
|
||||
|
||||
function void
|
||||
decl_print(Decl *decl){
|
||||
switch(decl->kind) {
|
||||
|
||||
case DK_Union: lex_print("union");
|
||||
case DK_Struct:{
|
||||
lex_print("struct %s{\n", decl->name.s.str);
|
||||
for(Decl *n = decl->aggregate_val.first; n; n=n->next){
|
||||
decl_print(n);
|
||||
lex_print(";\n");
|
||||
}
|
||||
lex_print("}\n");
|
||||
} break;
|
||||
|
||||
case DK_Variable:{
|
||||
type_print(decl->var_val.type);
|
||||
lex_print(" %s", decl->name.s.str);
|
||||
if(decl->var_val.expr){
|
||||
lex_print(" = ");
|
||||
expr_print(decl->var_val.expr);
|
||||
}
|
||||
} break;
|
||||
|
||||
case DK_Enum: {
|
||||
lex_print("enum %s{\n", decl->name.s.str);
|
||||
for(Decl_Enum_Child *n = decl->enum_val.first; n; n=n->next){
|
||||
lex_print(" ");
|
||||
token_print(n->token);
|
||||
if(n->expr){
|
||||
lex_print(" = ");
|
||||
expr_print(n->expr);
|
||||
}
|
||||
lex_print(",");
|
||||
lex_new_line();
|
||||
}
|
||||
lex_print("};\n");
|
||||
} break;
|
||||
default: {invalid_codepath;} break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user