Pretty printing, parsing structs
This commit is contained in:
54
new_ast.c
54
new_ast.c
@@ -164,6 +164,8 @@ typedef enum Decl_Kind{
|
||||
DECL_None,
|
||||
DECL_Struct,
|
||||
DECL_Union,
|
||||
DECL_SubStruct,
|
||||
DECL_SubUnion,
|
||||
DECL_Enum,
|
||||
DECL_Variable,
|
||||
DECL_Typedef,
|
||||
@@ -497,6 +499,54 @@ function void
|
||||
typespec_function_push(Typespec *func, Typespec *arg){
|
||||
SLLQueuePush(func->func.first, func->func.last, arg);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Notes
|
||||
//-----------------------------------------------------------------------------
|
||||
function void
|
||||
decl_pass_notes(Decl *a, Note *b){
|
||||
a->first_note = b->first;
|
||||
a->last_note = b->last;
|
||||
}
|
||||
|
||||
function Note *
|
||||
note_push_new(Arena *p, Note *parent, Token *pos, Intern_String name, Expr *expr){
|
||||
Note *result = arena_push_struct(p, Note);
|
||||
result->pos = pos;
|
||||
result->name = name;
|
||||
result->expr = expr;
|
||||
SLLQueuePush(parent->first, parent->last, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Note *
|
||||
find_note(Note *first, String string){
|
||||
for(Note *n = first; n; n=n->next){
|
||||
if(string_compare(string, n->name.s)){
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function String
|
||||
find_string_note(Note *first, String string, String default_string){
|
||||
Note *note = find_note(first, string);
|
||||
if(note){
|
||||
return note->expr->token->intern_val.s;
|
||||
}
|
||||
return default_string;
|
||||
}
|
||||
|
||||
function Note *
|
||||
decl_find_note(Decl *decl, String string){
|
||||
return find_note(decl->first_note, string);
|
||||
}
|
||||
|
||||
function String
|
||||
decl_find_string_note(Decl *decl, String string, String default_string){
|
||||
return find_string_note(decl->first_note, string, default_string);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Declarations
|
||||
@@ -512,7 +562,7 @@ decl_new(Arena *p, Decl_Kind kind, Token *pos, Intern_String name){
|
||||
|
||||
function Decl *
|
||||
decl_struct(Arena *p, Decl_Kind kind, Token *pos, Intern_String name){
|
||||
assert(kind == DECL_Struct || kind == DECL_Union);
|
||||
assert(kind == DECL_Struct || kind == DECL_Union || kind == DECL_SubUnion || kind == DECL_SubStruct);
|
||||
Decl *result = decl_new(p, kind, pos, name);
|
||||
return result;
|
||||
}
|
||||
@@ -570,7 +620,7 @@ decl_enum_push(Arena *p, Decl *parent, Token *pos, Intern_String name, Expr *exp
|
||||
|
||||
function void
|
||||
decl_struct_push(Decl *parent, Decl *child){
|
||||
assert(parent->kind == DECL_Struct || parent->kind == DECL_Union);
|
||||
assert(parent->kind == DECL_Struct || parent->kind == DECL_Union || parent->kind == DECL_SubUnion || parent->kind == DECL_SubStruct);
|
||||
SLLQueuePush(parent->struct_decl.first, parent->struct_decl.last, child);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user