+ ast_expression *left,
+ ast_expression *right);
+
+/* Binstore
+ *
+ * An assignment including a binary expression with the source as left operand.
+ * Eg. a += b; is a binstore { INSTR_STORE, INSTR_ADD, a, b }
+ */
+struct ast_binstore_s
+{
+ ast_expression expression;
+
+ int opstore;
+ int opbin;
+ ast_expression *dest;
+ ast_expression *source;
+ /* for &~= which uses the destination in a binary in source we can use this */
+ bool keep_dest;
+};
+ast_binstore* ast_binstore_new(lex_ctx_t ctx,
+ int storeop,
+ int op,
+ ast_expression *left,
+ ast_expression *right);
+
+/* Unary
+ *
+ * Regular unary expressions: not,neg
+ */
+struct ast_unary_s
+{
+ ast_expression expression;
+
+ int op;
+ ast_expression *operand;
+};
+ast_unary* ast_unary_new(lex_ctx_t ctx,
+ int op,
+ ast_expression *expr);
+
+/* Return
+ *
+ * Make sure 'return' only happens at the end of a block, otherwise the IR
+ * will refuse to create further instructions.
+ * This should be honored by the parser.
+ */
+struct ast_return_s
+{
+ ast_expression expression;
+ ast_expression *operand;
+};
+ast_return* ast_return_new(lex_ctx_t ctx,
+ ast_expression *expr);
+
+/* Entity-field
+ *
+ * This must do 2 things:
+ * -) Provide a way to fetch an entity field value. (Rvalue)
+ * -) Provide a pointer to an entity field. (Lvalue)
+ * The problem:
+ * In original QC, there's only a STORE via pointer, but
+ * no LOAD via pointer.
+ * So we must know beforehand if we are going to read or assign
+ * the field.
+ * For this we will have to extend the codegen() functions with
+ * a flag saying whether or not we need an L or an R-value.
+ */
+struct ast_entfield_s
+{
+ ast_expression expression;
+ /* The entity can come from an expression of course. */
+ ast_expression *entity;
+ /* As can the field, it just must result in a value of TYPE_FIELD */
+ ast_expression *field;
+};
+ast_entfield* ast_entfield_new(lex_ctx_t ctx, ast_expression *entity, ast_expression *field);
+ast_entfield* ast_entfield_new_force(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype);
+
+/* Member access:
+ *
+ * For now used for vectors. If we get structs or unions
+ * we can have them handled here as well.
+ */
+struct ast_member_s
+{
+ ast_expression expression;
+ ast_expression *owner;
+ unsigned int field;
+ const char *name;
+ bool rvalue;
+};
+ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const char *name);
+void ast_member_delete(ast_member*);
+bool ast_member_set_name(ast_member*, const char *name);
+
+
+/* Array index access:
+ *
+ * QC forces us to take special action on arrays:
+ * an ast_store on an ast_array_index must not codegen the index,
+ * but call its setter - unless we have an instruction set which supports
+ * what we need.
+ * Any other array index access will be codegened to a call to the getter.
+ * In any case, accessing an element via a compiletime-constant index will
+ * result in quick access to that variable.
+ */
+struct ast_array_index_s
+{
+ ast_expression expression;
+ ast_expression *array;
+ ast_expression *index;
+};
+ast_array_index* ast_array_index_new(lex_ctx_t ctx, ast_expression *array, ast_expression *index);
+
+/* Vararg pipe node:
+ *
+ * copy all varargs starting from a specific index
+ */
+struct ast_argpipe_s
+{
+ ast_expression expression;
+ ast_expression *index;
+};
+ast_argpipe* ast_argpipe_new(lex_ctx_t ctx, ast_expression *index);
+
+/* Store
+ *
+ * Stores left<-right and returns left.
+ * Specialized binary expression node
+ */
+struct ast_store_s
+{
+ ast_expression expression;
+ int op;
+ ast_expression *dest;
+ ast_expression *source;
+};
+ast_store* ast_store_new(lex_ctx_t ctx, int op,
+ ast_expression *d, ast_expression *s);
+
+/* If
+ *
+ * A general 'if then else' statement, either side can be NULL and will
+ * thus be omitted. It is an error for *both* cases to be NULL at once.
+ *
+ * During its 'codegen' it'll be changing the ast_function's block.
+ *
+ * An if is also an "expression". Its codegen will put NULL into the
+ * output field though. For ternary expressions an ast_ternary will be
+ * added.
+ */
+struct ast_ifthen_s
+{
+ ast_expression expression;
+ ast_expression *cond;
+ /* It's all just 'expressions', since an ast_block is one too. */
+ ast_expression *on_true;
+ ast_expression *on_false;
+};
+ast_ifthen* ast_ifthen_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
+
+/* Ternary expressions...
+ *
+ * Contrary to 'if-then-else' nodes, ternary expressions actually
+ * return a value, otherwise they behave the very same way.
+ * The difference in 'codegen' is that it'll return the value of
+ * a PHI node.
+ *
+ * The other difference is that in an ast_ternary, NEITHER side
+ * must be NULL, there's ALWAYS an else branch.
+ *
+ * This is the only ast_node beside ast_value which contains
+ * an ir_value. Theoretically we don't need to remember it though.
+ */
+struct ast_ternary_s
+{
+ ast_expression expression;
+ ast_expression *cond;
+ /* It's all just 'expressions', since an ast_block is one too. */
+ ast_expression *on_true;
+ ast_expression *on_false;
+};
+ast_ternary* ast_ternary_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
+
+/* A general loop node
+ *
+ * For convenience it contains 4 parts:
+ * -) (ini) = initializing expression
+ * -) (pre) = pre-loop condition
+ * -) (pst) = post-loop condition
+ * -) (inc) = "increment" expression
+ * The following is a psudo-representation of this loop
+ * note that '=>' bears the logical meaning of "implies".
+ * (a => b) equals (!a || b)
+
+{ini};
+while (has_pre => {pre})
+{
+ {body};
+
+continue: // a 'continue' will jump here
+ if (has_pst => {pst})
+ break;
+
+ {inc};
+}
+ */
+struct ast_loop_s
+{
+ ast_expression expression;
+ ast_expression *initexpr;
+ ast_expression *precond;
+ ast_expression *postcond;
+ ast_expression *increment;
+ ast_expression *body;
+ /* For now we allow a seperate flag on whether or not the condition
+ * is supposed to be true or false.
+ * That way, the parser can generate a 'while not(!x)' for `while(x)`
+ * if desired, which is useful for the new -f{true,false}-empty-strings
+ * flag.
+ */
+ bool pre_not;
+ bool post_not;
+};
+ast_loop* ast_loop_new(lex_ctx_t ctx,
+ ast_expression *initexpr,
+ ast_expression *precond, bool pre_not,
+ ast_expression *postcond, bool post_not,
+ ast_expression *increment,
+ ast_expression *body);
+
+/* Break/Continue
+ */
+struct ast_breakcont_s
+{
+ ast_expression expression;
+ bool is_continue;
+ unsigned int levels;
+};
+ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels);
+
+/* Switch Statements
+ *
+ * A few notes about this: with the original QCVM, no real optimization
+ * is possible. The SWITCH instruction set isn't really helping a lot, since
+ * it only collapes the EQ and IF instructions into one.
+ * Note: Declaring local variables inside caseblocks is normal.
+ * Since we don't have to deal with a stack there's no unnatural behaviour to
+ * be expected from it.
+ * TODO: Ticket #20
+ */
+typedef struct {
+ ast_expression *value; /* #20 will replace this */
+ ast_expression *code;
+} ast_switch_case;
+struct ast_switch_s
+{
+ ast_expression expression;
+
+ ast_expression *operand;
+ ast_switch_case *cases;
+};
+
+ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op);