]> git.xonotic.org Git - xonotic/gmqcc.git/blob - ast.h
Merge branch 'master' into cleanup
[xonotic/gmqcc.git] / ast.h
1 #ifndef GMQCC_AST_HDR
2 #define GMQCC_AST_HDR
3 #include <vector>
4 #include "ir.h"
5
6 typedef uint16_t ast_flag_t;
7
8 /* Note: I will not be using a _t suffix for the
9  * "main" ast node types for now.
10  */
11
12 struct ast_node;
13 struct ast_expression;
14 struct ast_value;
15 struct ast_function;
16 struct ast_block;
17 struct ast_binary;
18 struct ast_store;
19 struct ast_binstore;
20 struct ast_entfield;
21 struct ast_ifthen;
22 struct ast_ternary;
23 struct ast_loop;
24 struct ast_call;
25 struct ast_unary;
26 struct ast_return;
27 struct ast_member;
28 struct ast_array_index;
29 struct ast_breakcont;
30 struct ast_switch;
31 struct ast_label;
32 struct ast_goto;
33 struct ast_argpipe;
34 struct ast_state;
35
36 enum {
37     AST_FLAG_VARIADIC       = 1 << 0,
38     AST_FLAG_NORETURN       = 1 << 1,
39     AST_FLAG_INLINE         = 1 << 2,
40     AST_FLAG_INITIALIZED    = 1 << 3,
41     AST_FLAG_DEPRECATED     = 1 << 4,
42     AST_FLAG_INCLUDE_DEF    = 1 << 5,
43     AST_FLAG_IS_VARARG      = 1 << 6,
44     AST_FLAG_ALIAS          = 1 << 7,
45     AST_FLAG_ERASEABLE      = 1 << 8,
46     AST_FLAG_ACCUMULATE     = 1 << 9,
47
48     /* An array declared as []
49      * so that the size is taken from the initializer
50      */
51     AST_FLAG_ARRAY_INIT     = 1 << 10,
52
53     AST_FLAG_FINAL_DECL     = 1 << 11,
54
55     /* Several coverage options
56      * AST_FLAG_COVERAGE means there was an explicit [[coverage]] attribute,
57      * which will overwrite the default set via the commandline switches.
58      * BLOCK_COVERAGE inserts coverage() calls into every basic block.
59      * In the future there might be more options like tracking variable access
60      * by creating get/set wrapper functions.
61      */
62     AST_FLAG_COVERAGE       = 1 << 12,
63     AST_FLAG_BLOCK_COVERAGE = 1 << 13,
64
65     AST_FLAG_LAST,
66     AST_FLAG_TYPE_MASK      = (AST_FLAG_VARIADIC | AST_FLAG_NORETURN),
67     AST_FLAG_COVERAGE_MASK  = (AST_FLAG_BLOCK_COVERAGE)
68 };
69
70 enum {
71     TYPE_ast_node,        /*  0 */
72     TYPE_ast_expression,  /*  1 */
73     TYPE_ast_value,       /*  2 */
74     TYPE_ast_function,    /*  3 */
75     TYPE_ast_block,       /*  4 */
76     TYPE_ast_binary,      /*  5 */
77     TYPE_ast_store,       /*  6 */
78     TYPE_ast_binstore,    /*  7 */
79     TYPE_ast_entfield,    /*  8 */
80     TYPE_ast_ifthen,      /*  9 */
81     TYPE_ast_ternary,     /* 10 */
82     TYPE_ast_loop,        /* 11 */
83     TYPE_ast_call,        /* 12 */
84     TYPE_ast_unary,       /* 13 */
85     TYPE_ast_return,      /* 14 */
86     TYPE_ast_member,      /* 15 */
87     TYPE_ast_array_index, /* 16 */
88     TYPE_ast_breakcont,   /* 17 */
89     TYPE_ast_switch,      /* 18 */
90     TYPE_ast_label,       /* 19 */
91     TYPE_ast_goto,        /* 20 */
92     TYPE_ast_argpipe,     /* 21 */
93     TYPE_ast_state        /* 22 */
94 };
95
96 #define ast_istype(x, t) ( (x)->m_node_type == (TYPE_##t) )
97
98 struct ast_node
99 {
100     ast_node() = delete;
101     ast_node(lex_ctx_t, int nodetype);
102     virtual ~ast_node();
103
104     lex_ctx_t m_context;
105     /* I don't feel comfortable using keywords like 'delete' as names... */
106     int              m_node_type;
107     /* keep_node: if a node contains this node, 'keep_node'
108      * prevents its dtor from destroying this node as well.
109      */
110     bool             m_keep_node;
111     bool             m_side_effects;
112
113     void propagateSideEffects(const ast_node *other);
114 };
115
116 #define ast_unref(x) do        \
117 {                              \
118     if (! (x)->m_keep_node ) { \
119         delete (x);            \
120     }                          \
121 } while(0)
122
123 enum class ast_copy_type_t { value };
124 static const ast_copy_type_t ast_copy_type = ast_copy_type_t::value;
125
126 /* TODO: the codegen function should take an output-type parameter
127  * indicating whether a variable, type, label etc. is expected, and
128  * an environment!
129  * Then later an ast_ident could have a codegen using this to figure
130  * out what to look for.
131  * eg. in code which uses a not-yet defined variable, the expression
132  * would take an ast_ident, and the codegen would be called with
133  * type `expression`, so the ast_ident's codegen would search for
134  * variables through the environment (or functions, constants...).
135  */
136 struct ast_expression : ast_node {
137     ast_expression() = delete;
138     ast_expression(lex_ctx_t ctx, int nodetype, qc_type vtype);
139     ast_expression(lex_ctx_t ctx, int nodetype);
140     ~ast_expression();
141
142     ast_expression(ast_copy_type_t, const ast_expression&);
143     ast_expression(ast_copy_type_t, lex_ctx_t ctx, const ast_expression&);
144     ast_expression(ast_copy_type_t, int nodetype, const ast_expression&);
145     ast_expression(ast_copy_type_t, int nodetype, lex_ctx_t ctx, const ast_expression&);
146
147     static ast_expression *shallowType(lex_ctx_t ctx, qc_type vtype);
148
149     bool compareType(const ast_expression &other) const;
150     void adoptType(const ast_expression &other);
151
152     qc_type                 m_vtype = TYPE_VOID;
153     ast_expression         *m_next = nullptr;
154     /* arrays get a member-count */
155     size_t                  m_count = 0;
156     std::vector<std::unique_ptr<ast_value>> m_type_params;
157
158     ast_flag_t              m_flags = 0;
159     /* void foo(string...) gets varparam set as a restriction
160      * for variadic parameters
161      */
162     ast_expression         *m_varparam = nullptr;
163     /* The codegen functions should store their output values
164      * so we can call it multiple times without re-evaluating.
165      * Store lvalue and rvalue seperately though. So that
166      * ast_entfield for example can generate both if required.
167      */
168     ir_value               *m_outl = nullptr;
169     ir_value               *m_outr = nullptr;
170
171     virtual bool codegen(ast_function *current, bool lvalue, ir_value **out);
172 };
173
174 /* Value
175  *
176  * Types are also values, both have a type and a name.
177  * especially considering possible constructs like typedefs.
178  * typedef float foo;
179  * is like creating a 'float foo', foo serving as the type's name.
180  */
181 union basic_value_t {
182     qcfloat_t     vfloat;
183     int           vint;
184     vec3_t        vvec;
185     const char   *vstring;
186     int           ventity;
187     ast_function *vfunc;
188     ast_value    *vfield;
189 };
190
191 struct ast_value : ast_expression
192 {
193     ast_value() = delete;
194     ast_value(lex_ctx_t ctx, const std::string &name, qc_type qctype);
195     ~ast_value();
196
197     ast_value(ast_copy_type_t, const ast_expression&, const std::string&);
198     ast_value(ast_copy_type_t, const ast_value&);
199     ast_value(ast_copy_type_t, const ast_value&, const std::string&);
200
201     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
202
203     void addParam(ast_value*);
204
205     bool generateGlobal(ir_builder*, bool isfield);
206     bool generateLocal(ir_function*, bool param);
207     bool generateAccessors(ir_builder*);
208
209     std::string m_name;
210     std::string m_desc;
211
212     const char *m_argcounter = nullptr;
213
214     int m_cvq = CV_NONE;     /* const/var qualifier */
215     bool m_isfield = false; /* this declares a field */
216     bool m_isimm = false;   /* an immediate, not just const */
217     bool m_hasvalue = false;
218     bool m_inexact = false; /* inexact coming from folded expression */
219     basic_value_t m_constval;
220     /* for TYPE_ARRAY we have an optional vector
221      * of constants when an initializer list
222      * was provided.
223      */
224     std::vector<basic_value_t> m_initlist;
225
226     /* usecount for the parser */
227     size_t m_uses = 0;
228
229     ir_value *m_ir_v = nullptr;
230     std::vector<ir_value*> m_ir_values;
231     size_t m_ir_value_count = 0;
232
233     /* ONLY for arrays in progs version up to 6 */
234     ast_value *m_setter = nullptr;
235     ast_value *m_getter = nullptr;
236
237     bool m_intrinsic = false; /* true if associated with intrinsic */
238
239 private:
240     bool generateGlobalFunction(ir_builder*);
241     bool generateGlobalField(ir_builder*);
242     ir_value *prepareGlobalArray(ir_builder*);
243     bool setGlobalArray();
244     bool checkArray(const ast_value &array) const;
245 };
246
247 void ast_type_to_string(const ast_expression *e, char *buf, size_t bufsize);
248
249 enum ast_binary_ref {
250     AST_REF_NONE  = 0,
251     AST_REF_LEFT  = 1 << 1,
252     AST_REF_RIGHT = 1 << 2,
253     AST_REF_ALL   = (AST_REF_LEFT | AST_REF_RIGHT)
254 };
255
256
257 /* Binary
258  *
259  * A value-returning binary expression.
260  */
261 struct ast_binary : ast_expression
262 {
263     ast_binary() = delete;
264     ast_binary(lex_ctx_t ctx, int op, ast_expression *l, ast_expression *r);
265     ~ast_binary();
266
267     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
268
269     int m_op;
270     ast_expression *m_left;
271     ast_expression *m_right;
272     ast_binary_ref m_refs;
273     bool m_right_first;
274 };
275
276 /* Binstore
277  *
278  * An assignment including a binary expression with the source as left operand.
279  * Eg. a += b; is a binstore { INSTR_STORE, INSTR_ADD, a, b }
280  */
281 struct ast_binstore : ast_expression
282 {
283     ast_binstore() = delete;
284     ast_binstore(lex_ctx_t ctx, int storeop, int mathop, ast_expression *l, ast_expression *r);
285     ~ast_binstore();
286
287     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
288
289     int m_opstore;
290     int m_opbin;
291     ast_expression *m_dest;
292     ast_expression *m_source;
293     /* for &~= which uses the destination in a binary in source we can use this */
294     bool m_keep_dest;
295 };
296
297 /* Unary
298  *
299  * Regular unary expressions: not,neg
300  */
301 struct ast_unary : ast_expression
302 {
303     ast_unary() = delete;
304     ~ast_unary();
305
306     static ast_unary* make(lex_ctx_t ctx, int op, ast_expression *expr);
307
308     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
309
310     int m_op;
311     ast_expression *m_operand;
312
313 private:
314     ast_unary(lex_ctx_t ctx, int op, ast_expression *expr);
315 };
316
317 /* Return
318  *
319  * Make sure 'return' only happens at the end of a block, otherwise the IR
320  * will refuse to create further instructions.
321  * This should be honored by the parser.
322  */
323 struct ast_return : ast_expression
324 {
325     ast_return() = delete;
326     ast_return(lex_ctx_t ctx, ast_expression *expr);
327     ~ast_return();
328
329     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
330
331     ast_expression *m_operand;
332 };
333
334 /* Entity-field
335  *
336  * This must do 2 things:
337  * -) Provide a way to fetch an entity field value. (Rvalue)
338  * -) Provide a pointer to an entity field. (Lvalue)
339  * The problem:
340  * In original QC, there's only a STORE via pointer, but
341  * no LOAD via pointer.
342  * So we must know beforehand if we are going to read or assign
343  * the field.
344  * For this we will have to extend the codegen() functions with
345  * a flag saying whether or not we need an L or an R-value.
346  */
347 struct ast_entfield : ast_expression
348 {
349     ast_entfield() = delete;
350     ast_entfield(lex_ctx_t ctx, ast_expression *entity, ast_expression *field);
351     ast_entfield(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype);
352     ~ast_entfield();
353
354     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
355
356     // The entity can come from an expression of course.
357     ast_expression *m_entity;
358     // As can the field, it just must result in a value of TYPE_FIELD
359     ast_expression *m_field;
360 };
361
362 /* Member access:
363  *
364  * For now used for vectors. If we get structs or unions
365  * we can have them handled here as well.
366  */
367 struct ast_member : ast_expression
368 {
369     static ast_member *make(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const std::string &name);
370     ~ast_member();
371
372     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
373
374     ast_expression *m_owner;
375     unsigned int m_field;
376     std::string m_name;
377     bool m_rvalue;
378
379 private:
380     ast_member() = delete;
381     ast_member(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const std::string &name);
382 };
383
384 /* Array index access:
385  *
386  * QC forces us to take special action on arrays:
387  * an ast_store on an ast_array_index must not codegen the index,
388  * but call its setter - unless we have an instruction set which supports
389  * what we need.
390  * Any other array index access will be codegened to a call to the getter.
391  * In any case, accessing an element via a compiletime-constant index will
392  * result in quick access to that variable.
393  */
394 struct ast_array_index : ast_expression
395 {
396     static ast_array_index* make(lex_ctx_t ctx, ast_expression *array, ast_expression *index);
397     ~ast_array_index();
398
399     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
400
401     ast_expression *m_array;
402     ast_expression *m_index;
403 private:
404     ast_array_index() = delete;
405     ast_array_index(lex_ctx_t ctx, ast_expression *array, ast_expression *index);
406 };
407
408 /* Vararg pipe node:
409  *
410  * copy all varargs starting from a specific index
411  */
412 struct ast_argpipe : ast_expression
413 {
414     ast_argpipe() = delete;
415     ast_argpipe(lex_ctx_t ctx, ast_expression *index);
416
417     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
418
419     ~ast_argpipe();
420     ast_expression *m_index;
421 };
422
423 /* Store
424  *
425  * Stores left<-right and returns left.
426  * Specialized binary expression node
427  */
428 struct ast_store : ast_expression
429 {
430     ast_store() = delete;
431     ast_store(lex_ctx_t ctx, int op, ast_expression *d, ast_expression *s);
432     ~ast_store();
433
434     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
435
436     int m_op;
437     ast_expression *m_dest;
438     ast_expression *m_source;
439 };
440
441 /* If
442  *
443  * A general 'if then else' statement, either side can be nullptr and will
444  * thus be omitted. It is an error for *both* cases to be nullptr at once.
445  *
446  * During its 'codegen' it'll be changing the ast_function's block.
447  *
448  * An if is also an "expression". Its codegen will put nullptr into the
449  * output field though. For ternary expressions an ast_ternary will be
450  * added.
451  */
452 struct ast_ifthen : ast_expression
453 {
454     ast_ifthen() = delete;
455     ast_ifthen(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
456     ~ast_ifthen();
457
458     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
459
460     ast_expression *m_cond;
461     /* It's all just 'expressions', since an ast_block is one too. */
462     ast_expression *m_on_true;
463     ast_expression *m_on_false;
464 };
465
466 /* Ternary expressions...
467  *
468  * Contrary to 'if-then-else' nodes, ternary expressions actually
469  * return a value, otherwise they behave the very same way.
470  * The difference in 'codegen' is that it'll return the value of
471  * a PHI node.
472  *
473  * The other difference is that in an ast_ternary, NEITHER side
474  * must be nullptr, there's ALWAYS an else branch.
475  *
476  * This is the only ast_node beside ast_value which contains
477  * an ir_value. Theoretically we don't need to remember it though.
478  */
479 struct ast_ternary : ast_expression
480 {
481     ast_ternary() = delete;
482     ast_ternary(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
483     ~ast_ternary();
484
485     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
486
487     ast_expression *m_cond;
488     /* It's all just 'expressions', since an ast_block is one too. */
489     ast_expression *m_on_true;
490     ast_expression *m_on_false;
491 };
492
493 /* A general loop node
494  *
495  * For convenience it contains 4 parts:
496  * -) (ini) = initializing expression
497  * -) (pre) = pre-loop condition
498  * -) (pst) = post-loop condition
499  * -) (inc) = "increment" expression
500  * The following is a psudo-representation of this loop
501  * note that '=>' bears the logical meaning of "implies".
502  * (a => b) equals (!a || b)
503
504 {ini};
505 while (has_pre => {pre})
506 {
507     {body};
508
509 continue:      // a 'continue' will jump here
510     if (has_pst => {pst})
511         break;
512
513     {inc};
514 }
515  */
516 struct ast_loop : ast_expression
517 {
518     ast_loop() = delete;
519     ast_loop(lex_ctx_t ctx,
520              ast_expression *initexpr,
521              ast_expression *precond, bool pre_not,
522              ast_expression *postcond, bool post_not,
523              ast_expression *increment,
524              ast_expression *body);
525     ~ast_loop();
526
527     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
528
529     ast_expression *m_initexpr;
530     ast_expression *m_precond;
531     ast_expression *m_postcond;
532     ast_expression *m_increment;
533     ast_expression *m_body;
534     /* For now we allow a seperate flag on whether or not the condition
535      * is supposed to be true or false.
536      * That way, the parser can generate a 'while not(!x)' for `while(x)`
537      * if desired, which is useful for the new -f{true,false}-empty-strings
538      * flag.
539      */
540     bool m_pre_not;
541     bool m_post_not;
542 };
543
544 /* Break/Continue
545  */
546 struct ast_breakcont : ast_expression
547 {
548     ast_breakcont() = delete;
549     ast_breakcont(lex_ctx_t ctx, bool iscont, unsigned int levels);
550     ~ast_breakcont();
551
552     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
553
554
555     bool         m_is_continue;
556     unsigned int m_levels;
557 };
558
559 /* Switch Statements
560  *
561  * A few notes about this: with the original QCVM, no real optimization
562  * is possible. The SWITCH instruction set isn't really helping a lot, since
563  * it only collapes the EQ and IF instructions into one.
564  * Note: Declaring local variables inside caseblocks is normal.
565  * Since we don't have to deal with a stack there's no unnatural behaviour to
566  * be expected from it.
567  * TODO: Ticket #20
568  */
569 struct ast_switch_case {
570     ast_expression *m_value; /* #20 will replace this */
571     ast_expression *m_code;
572 };
573
574 struct ast_switch : ast_expression
575 {
576     ast_switch() = delete;
577     ast_switch(lex_ctx_t ctx, ast_expression *op);
578     ~ast_switch();
579
580     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
581
582     ast_expression *m_operand;
583     std::vector<ast_switch_case> m_cases;
584 };
585
586
587 /* Label nodes
588  *
589  * Introduce a label which can be used together with 'goto'
590  */
591 struct ast_label : ast_expression
592 {
593     ast_label() = delete;
594     ast_label(lex_ctx_t ctx, const std::string &name, bool undefined);
595     ~ast_label();
596
597     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
598
599     std::string m_name;
600     ir_block *m_irblock;
601     std::vector<ast_goto*> m_gotos;
602
603     /* means it has not yet been defined */
604     bool m_undefined;
605
606 private:
607     void registerGoto(ast_goto*);
608     friend struct ast_goto;
609 };
610
611 /* GOTO nodes
612  *
613  * Go to a label, the label node is filled in at a later point!
614  */
615 struct ast_goto : ast_expression
616 {
617     ast_goto() = delete;
618     ast_goto(lex_ctx_t ctx, const std::string &name);
619     ~ast_goto();
620
621     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
622
623     void setLabel(ast_label*);
624
625     std::string m_name;
626     ast_label *m_target;
627     ir_block *m_irblock_from;
628 };
629
630 /* STATE node
631  *
632  * For frame/think state updates: void foo() [framenum, nextthink] {}
633  */
634 struct ast_state : ast_expression
635 {
636     ast_state() = delete;
637     ast_state(lex_ctx_t ctx, ast_expression *frame, ast_expression *think);
638     ~ast_state();
639
640     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
641
642     ast_expression *m_framenum;
643     ast_expression *m_nextthink;
644 };
645
646 /* CALL node
647  *
648  * Contains an ast_expression as target, rather than an ast_function/value.
649  * Since it's how QC works, every ast_function has an ast_value
650  * associated anyway - in other words, the VM contains function
651  * pointers for every function anyway. Thus, this node will call
652  * expression.
653  * Additionally it contains a list of ast_expressions as parameters.
654  * Since calls can return values, an ast_call is also an ast_expression.
655  */
656 struct ast_call : ast_expression
657 {
658     ast_call() = delete;
659     static ast_call *make(lex_ctx_t, ast_expression*);
660     ~ast_call();
661
662     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
663
664     bool checkTypes(ast_expression *this_func_va_type) const;
665
666     ast_expression *m_func;
667     std::vector<ast_expression *> m_params;
668     ast_expression *m_va_count;
669
670 private:
671     ast_call(lex_ctx_t ctx, ast_expression *funcexpr);
672     bool checkVararg(ast_expression *va_type, ast_expression *exp_type) const;
673 };
674
675 /* Blocks
676  *
677  */
678 struct ast_block : ast_expression
679 {
680     ast_block() = delete;
681     ast_block(lex_ctx_t ctx);
682     ~ast_block();
683
684     bool codegen(ast_function *current, bool lvalue, ir_value **out) override;
685
686     std::vector<ast_value*>      m_locals;
687     std::vector<ast_expression*> m_exprs;
688     std::vector<ast_expression*> m_collect;
689
690     void setType(const ast_expression &from);
691     bool GMQCC_WARN addExpr(ast_expression*);
692     void collect(ast_expression*);
693 };
694
695 /* Function
696  *
697  * Contains a list of blocks... at least in theory.
698  * Usually there's just the main block, other blocks are inside that.
699  *
700  * Technically, functions don't need to be an AST node, since we have
701  * neither functions inside functions, nor lambdas, and function
702  * pointers could just work with a name. However, this way could be
703  * more flexible, and adds no real complexity.
704  *
705  * The destructor will NOT delete the underlying ast_value
706  *
707  */
708 struct ast_function : ast_node
709 {
710     ast_function() = delete;
711     static ast_function *make(lex_ctx_t ctx, const std::string &name, ast_value *vtype);
712     ~ast_function();
713
714     const char* makeLabel(const char *prefix);
715     virtual bool generateFunction(ir_builder*);
716
717     ast_value  *m_function_type = nullptr;
718     std::string m_name;
719
720     int m_builtin = 0;
721
722     /* list of used-up names for statics without the count suffix */
723     std::vector<std::string> m_static_names;
724     /* number of static variables, by convention this includes the
725      * ones without the count-suffix - remember this when dealing
726      * with savegames. uint instead of size_t as %zu in printf is
727      * C99, so no windows support. */
728     unsigned int m_static_count = 0;
729
730     ir_function *m_ir_func = nullptr;
731     ir_block *m_curblock = nullptr;
732     std::vector<ir_block*> m_breakblocks;
733     std::vector<ir_block*> m_continueblocks;
734
735     size_t m_labelcount = 0;
736     /* in order for thread safety - for the optional
737      * channel abesed multithreading... keeping a buffer
738      * here to use in ast_function_label.
739      */
740     std::vector<std::unique_ptr<ast_block>> m_blocks;
741     std::unique_ptr<ast_value> m_varargs;
742     std::unique_ptr<ast_value> m_argc;
743     ast_value *m_fixedparams = nullptr; // these use unref()
744     ast_value *m_return_value = nullptr;
745
746 private:
747     ast_function(lex_ctx_t ctx, const std::string &name, ast_value *vtype);
748
749     char m_labelbuf[64];
750 };
751
752 /*
753  * If the condition creates a situation where this becomes -1 size it means there are
754  * more AST_FLAGs than the type ast_flag_t is capable of holding. So either eliminate
755  * the AST flag count or change the ast_flag_t typedef to a type large enough to accomodate
756  * all the flags.
757  */
758 typedef int static_assert_is_ast_flag_safe [((AST_FLAG_LAST) <= (ast_flag_t)(-1)) ? 1 : -1];
759 #endif