aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/fwd/ast.h10
-rw-r--r--include/fwd/conts.h8
-rw-r--r--include/fwd/sptree.h10
3 files changed, 21 insertions, 7 deletions
diff --git a/include/fwd/ast.h b/include/fwd/ast.h
index 1da5b88..f8ad67a 100644
--- a/include/fwd/ast.h
+++ b/include/fwd/ast.h
@@ -47,6 +47,9 @@ struct type {
/* next */
struct type *n;
+ /* opt group */
+ long group;
+
struct src_loc loc;
};
@@ -141,6 +144,10 @@ struct ast {
struct type *t;
enum ast_flag flags;
+
+ /* optional group */
+ struct ast *ol;
+ struct ast *or;
};
static inline bool ast_flags(struct ast *node, enum ast_flag flags)
@@ -325,7 +332,6 @@ static inline bool is_const(struct ast *x)
#define var_id(x) return_s(x, AST_VAR_DEF)
#define var_type(x) return_t2(x, AST_VAR_DEF)
-#define var_init(x) return_a0(x, AST_VAR_DEF)
#define gen_var(id, type, loc) \
gen_ast(AST_VAR_DEF, NULL, NULL, NULL, NULL, type, id, 0, 0., loc)
@@ -467,4 +473,6 @@ static inline struct type *callable_types(struct type *t)
return tcallable_args(t);
}
+void opt_group(struct ast *a, struct ast *b);
+
#endif /* AST_H */
diff --git a/include/fwd/conts.h b/include/fwd/conts.h
index 862bd31..c1e4d24 100644
--- a/include/fwd/conts.h
+++ b/include/fwd/conts.h
@@ -7,8 +7,8 @@
#define CONTAINER_OF(ptr, type, member) \
(type *)((char *)(ptr) - offsetof(type, member))
-#define foreach(name, i, s)\
- for (auto i = CONTS_JOIN(name, begin)(s);\
- !CONTS_JOIN(name, end)(s, i);\
- i = CONTS_JOIN(name, next)(i))
+#define foreach(name, i, s) \
+ for (auto i = CONTS_JOIN(name, begin)(s); \
+ !CONTS_JOIN(name, end)(s, i); \
+ i = CONTS_JOIN(name, next)(i))
#endif /* CONTS_H */
diff --git a/include/fwd/sptree.h b/include/fwd/sptree.h
index 75b88fc..e305c0f 100644
--- a/include/fwd/sptree.h
+++ b/include/fwd/sptree.h
@@ -400,12 +400,18 @@ static inline void SPTREE(remove)(struct SPROOT *s, SPTREE_TYPE data)
return;
SPTREE(remove_found)(s, found);
+ struct SPNODE *del = CONTAINER_OF(found, struct SPNODE, data);
+ free(del);
}
static inline void SPTREE(destroy)(struct SPROOT *s)
{
- while (s->root)
- SPTREE(remove_found)(s, &s->root->data);
+ while (s->root) {
+ SPTREE_TYPE *top = &s->root->data;
+ SPTREE(remove_found)(s, top);
+ struct SPNODE *del = CONTAINER_OF(top, struct SPNODE, data);
+ free(del);
+ }
}
#undef SPTREE