diff options
author | Himbeer <himbeer@disroot.org> | 2025-05-05 15:55:03 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2025-05-05 15:57:51 +0200 |
commit | b49e96941fb9f07426d49adeef50cd8c1716bf15 (patch) | |
tree | 73a78dcbb8041065c841097186faacaa32bb9363 | |
parent | 828f7cfe05eec5547837867101fc662c3dea60f1 (diff) |
Add location fields to AST data structures that need it
-rw-r--r-- | include/expr.h | 38 | ||||
-rw-r--r-- | include/parse.h | 34 |
2 files changed, 72 insertions, 0 deletions
diff --git a/include/expr.h b/include/expr.h index 9d4d50a..a0242bb 100644 --- a/include/expr.h +++ b/include/expr.h @@ -11,6 +11,8 @@ enum valuekind { }; struct value_e { + struct location loc; + enum valuekind kind; union { struct literal lit; @@ -19,6 +21,8 @@ struct value_e { }; struct grp_e { + struct location loc; + int isgrouped; union { struct expr *grouped; @@ -27,6 +31,8 @@ struct grp_e { }; struct call_e { + struct location loc; + struct expr *args; int argsz, arglen; }; @@ -39,6 +45,8 @@ enum access { }; struct access_e { + struct location loc; + struct grp_e grp; enum access kind; union { @@ -50,6 +58,8 @@ struct access_e { }; struct tag_e { + struct location loc; + int dotagof; struct access_e access; }; @@ -61,6 +71,8 @@ enum signop { }; struct sign_e { + struct location loc; + enum signop op; struct tag_e tag; }; @@ -72,6 +84,8 @@ enum invop { }; struct inv_e { + struct location loc; + enum invop op; union { struct inv_e *inv; @@ -80,6 +94,8 @@ struct inv_e { }; struct deref_e { + struct location loc; + int doderef; union { struct deref_e *deref; @@ -88,26 +104,36 @@ struct deref_e { }; struct ref_e { + struct location loc; + int doref; struct deref_e inner; }; struct as_e { + struct location loc; + struct ref_e lhs; struct type *cast; }; struct bitand_e { + struct location loc; + struct as_e lhs; struct bitand_e *rhs; }; struct bitxor_e { + struct location loc; + struct bitand_e lhs; struct bitxor_e *rhs; }; struct bitor_e { + struct location loc; + struct bitxor_e lhs; struct bitor_e *rhs; }; @@ -120,6 +146,8 @@ enum productop { }; struct product_e { + struct location loc; + struct bitor_e lhs; enum productop op; struct product_e *rhs; @@ -132,6 +160,8 @@ enum sumop { }; struct sum_e { + struct location loc; + struct product_e lhs; enum sumop op; struct sum_e *rhs; @@ -144,6 +174,8 @@ enum shiftop { }; struct shift_e { + struct location loc; + struct sum_e lhs; enum shiftop op; struct shift_e *rhs; @@ -160,17 +192,23 @@ enum cmpop { }; struct cmp_e { + struct location loc; + struct shift_e lhs; enum cmpop op; struct shift_e *rhs; }; struct conjunction_e { + struct location loc; + struct cmp_e lhs; struct conjunction_e *rhs; }; struct expr { + struct location loc; + struct conjunction_e lhs; struct expr *rhs; }; diff --git a/include/parse.h b/include/parse.h index 64d1eac..aad1db9 100644 --- a/include/parse.h +++ b/include/parse.h @@ -3,12 +3,16 @@ #include "expr.h" struct ast_local { + struct location loc; + const char *name; struct type type; struct expr *init; }; struct ast_assign { + struct location loc; + struct expr lhs; struct expr rhs; }; @@ -24,6 +28,8 @@ struct ast_elsebody { }; struct ast_else { + struct location loc; + int cond; union { struct ast_if *conditional; @@ -32,6 +38,8 @@ struct ast_else { }; struct ast_if { + struct location loc; + struct expr cond; struct ast_stmt *stmts; int stmtsz, stmtlen; @@ -39,6 +47,8 @@ struct ast_if { }; struct ast_for { + struct location loc; + struct ast_stmt *init; struct expr cond; struct ast_stmt *step; @@ -47,6 +57,8 @@ struct ast_for { }; struct ast_return { + struct location loc; + struct expr *value; }; @@ -70,6 +82,8 @@ enum stmt { }; struct ast_stmt { + struct location loc; + enum stmt kind; union { struct ast_local localvar; @@ -83,10 +97,14 @@ struct ast_stmt { }; struct ast_include { + struct location loc; + const char *path; }; struct ast_global { + struct location loc; + const char *name; int ispub; int isextern; @@ -94,27 +112,37 @@ struct ast_global { }; struct ast_const { + struct location loc; + const char *name; struct expr value; }; struct ast_enumvar { + struct location loc; + const char *name; struct expr *override; }; struct ast_enum { + struct location loc; + struct expr init; struct ast_enumvar *variants; int variantsz, variantlen; }; struct ast_field { + struct location loc; + const char *name; struct type type; }; struct ast_struct { + struct location loc; + const char *name; int align; struct ast_field *fields; @@ -122,12 +150,16 @@ struct ast_struct { }; struct ast_union { + struct location loc; + const char *name; struct type *types; int typesz, typelen; }; struct ast_func { + struct location loc; + int ispub; int isextern; const char *name; @@ -149,6 +181,8 @@ enum toplevel { }; struct ast_toplevel { + struct location loc; + enum toplevel kind; union { struct ast_include include; |