]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.cpp
more c++ migration for ast/ir/code; reached a working condition here
[xonotic/gmqcc.git] / parser.cpp
index 86535fbf0f5d15179eca79fec9b06d06538a0598..75f9312fc4bcd5ba61305e39889af8c46deb71d5 100644 (file)
@@ -1,6 +1,9 @@
 #include <string.h>
 #include <math.h>
 
+#include "intrin.h"
+#include "fold.h"
+#include "ast.h"
 #include "parser.h"
 
 #define PARSER_HT_LOCALS  2
@@ -98,13 +101,13 @@ static ast_expression* parser_find_param(parser_t *parser, const char *name)
 {
     ast_value *fun;
     if (!parser->function)
-        return NULL;
-    fun = parser->function->vtype;
-    for (auto &it : fun->expression.params) {
+        return nullptr;
+    fun = parser->function->function_type;
+    for (auto &it : fun->type_params) {
         if (!strcmp(it->name, name))
             return (ast_expression*)it;
     }
-    return NULL;
+    return nullptr;
 }
 
 static ast_expression* parser_find_local(parser_t *parser, const char *name, size_t upto, bool *isparam)
@@ -144,7 +147,7 @@ static ast_value* parser_find_typedef(parser_t *parser, const char *name, size_t
         if ( (e = (ast_value*)util_htgeth(parser->typedefs[i], name, hash)) )
             return e;
     }
-    return NULL;
+    return nullptr;
 }
 
 struct sy_elem {
@@ -165,10 +168,10 @@ enum {
 };
 
 struct shunt {
-    sy_elem        *out;
-    sy_elem        *ops;
-    size_t         *argc;
-    unsigned int   *paren;
+    std::vector<sy_elem> out;
+    std::vector<sy_elem> ops;
+    std::vector<size_t> argc;
+    std::vector<unsigned int> paren;
 };
 
 static sy_elem syexp(lex_ctx_t ctx, ast_expression *v) {
@@ -176,7 +179,7 @@ static sy_elem syexp(lex_ctx_t ctx, ast_expression *v) {
     e.etype = 0;
     e.off   = 0;
     e.out   = v;
-    e.block = NULL;
+    e.block = nullptr;
     e.ctx   = ctx;
     e.isparen = false;
     return e;
@@ -197,8 +200,8 @@ static sy_elem syop(lex_ctx_t ctx, const oper_info *op) {
     sy_elem e;
     e.etype = 1 + (op - operators);
     e.off   = 0;
-    e.out   = NULL;
-    e.block = NULL;
+    e.out   = nullptr;
+    e.block = nullptr;
     e.ctx   = ctx;
     e.isparen = false;
     return e;
@@ -208,8 +211,8 @@ static sy_elem syparen(lex_ctx_t ctx, size_t off) {
     sy_elem e;
     e.etype = 0;
     e.off   = off;
-    e.out   = NULL;
-    e.block = NULL;
+    e.out   = nullptr;
+    e.block = nullptr;
     e.ctx   = ctx;
     e.isparen = true;
     return e;
@@ -250,8 +253,8 @@ static bool rotate_entfield_array_index_nodes(ast_expression **out)
     entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
     *out = (ast_expression*)entfield;
 
-    oldindex->array = NULL;
-    oldindex->index = NULL;
+    oldindex->array = nullptr;
+    oldindex->index = nullptr;
     ast_delete(oldindex);
 
     return true;
@@ -284,7 +287,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
 {
     const oper_info *op;
     lex_ctx_t ctx;
-    ast_expression *out = NULL;
+    ast_expression *out = nullptr;
     ast_expression *exprs[3];
     ast_block      *blocks[3];
     ast_binstore   *asbinstore;
@@ -294,20 +297,20 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
     char ty1[1024];
     char ty2[1024];
 
-    if (!vec_size(sy->ops)) {
+    if (sy->ops.empty()) {
         parseerror(parser, "internal error: missing operator");
         return false;
     }
 
-    if (vec_last(sy->ops).isparen) {
+    if (sy->ops.back().isparen) {
         parseerror(parser, "unmatched parenthesis");
         return false;
     }
 
-    op = &operators[vec_last(sy->ops).etype - 1];
-    ctx = vec_last(sy->ops).ctx;
+    op = &operators[sy->ops.back().etype - 1];
+    ctx = sy->ops.back().ctx;
 
-    if (vec_size(sy->out) < op->operands) {
+    if (sy->out.size() < op->operands) {
         if (op->flags & OP_PREFIX)
             compile_error(ctx, "expected expression after unary operator `%s`", op->op, (int)op->id);
         else /* this should have errored previously already */
@@ -315,16 +318,16 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
         return false;
     }
 
-    vec_shrinkby(sy->ops, 1);
+    sy->ops.pop_back();
 
     /* op(:?) has no input and no output */
     if (!op->operands)
         return true;
 
-    vec_shrinkby(sy->out, op->operands);
+    sy->out.erase(sy->out.end() - op->operands, sy->out.end());
     for (i = 0; i < op->operands; ++i) {
-        exprs[i]  = sy->out[vec_size(sy->out)+i].out;
-        blocks[i] = sy->out[vec_size(sy->out)+i].block;
+        exprs[i]  = sy->out[sy->out.size()+i].out;
+        blocks[i] = sy->out[sy->out.size()+i].block;
 
         if (exprs[i]->vtype == TYPE_NOEXPR &&
             !(i != 0 && op->id == opid2('?',':')) &&
@@ -358,11 +361,11 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 exprs[1]->vtype == TYPE_NOEXPR)
             {
                 if      (exprs[1] == (ast_expression*)parser->const_vec[0])
-                    out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, NULL);
+                    out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, nullptr);
                 else if (exprs[1] == (ast_expression*)parser->const_vec[1])
-                    out = (ast_expression*)ast_member_new(ctx, exprs[0], 1, NULL);
+                    out = (ast_expression*)ast_member_new(ctx, exprs[0], 1, nullptr);
                 else if (exprs[1] == (ast_expression*)parser->const_vec[2])
-                    out = (ast_expression*)ast_member_new(ctx, exprs[0], 2, NULL);
+                    out = (ast_expression*)ast_member_new(ctx, exprs[0], 2, nullptr);
                 else {
                     compile_error(ctx, "access to invalid vector component");
                     return false;
@@ -404,10 +407,10 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             break;
 
         case opid1(','):
-            if (vec_size(sy->paren) && vec_last(sy->paren) == PAREN_FUNC) {
-                vec_push(sy->out, syexp(ctx, exprs[0]));
-                vec_push(sy->out, syexp(ctx, exprs[1]));
-                vec_last(sy->argc)++;
+            if (sy->paren.size() && sy->paren.back() == PAREN_FUNC) {
+                sy->out.push_back(syexp(ctx, exprs[0]));
+                sy->out.push_back(syexp(ctx, exprs[1]));
+                sy->argc.back()++;
                 return true;
             }
             if (blocks[0]) {
@@ -423,14 +426,14 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             }
             ast_block_set_type(blocks[0], exprs[1]);
 
-            vec_push(sy->out, syblock(ctx, blocks[0]));
+            sy->out.push_back(syblock(ctx, blocks[0]));
             return true;
 
         case opid2('+','P'):
             out = exprs[0];
             break;
         case opid2('-','P'):
-            if ((out = fold_op(parser->fold, op, exprs)))
+            if ((out = parser->m_fold.op(op, exprs)))
                 break;
 
             if (exprs[0]->vtype != TYPE_FLOAT &&
@@ -446,7 +449,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             break;
 
         case opid2('!','P'):
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 switch (exprs[0]->vtype) {
                     case TYPE_FLOAT:
                         out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, exprs[0]);
@@ -484,13 +487,13 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                               type_name[exprs[1]->vtype]);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 switch (exprs[0]->vtype) {
                     case TYPE_FLOAT:
-                        out = fold_binary(ctx, INSTR_ADD_F, exprs[0], exprs[1]);
+                        out = fold::binary(ctx, INSTR_ADD_F, exprs[0], exprs[1]);
                         break;
                     case TYPE_VECTOR:
-                        out = fold_binary(ctx, INSTR_ADD_V, exprs[0], exprs[1]);
+                        out = fold::binary(ctx, INSTR_ADD_V, exprs[0], exprs[1]);
                         break;
                     default:
                         compile_error(ctx, "invalid types used in expression: cannot add type %s and %s",
@@ -509,13 +512,13 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                               type_name[exprs[0]->vtype]);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 switch (exprs[0]->vtype) {
                     case TYPE_FLOAT:
-                        out = fold_binary(ctx, INSTR_SUB_F, exprs[0], exprs[1]);
+                        out = fold::binary(ctx, INSTR_SUB_F, exprs[0], exprs[1]);
                         break;
                     case TYPE_VECTOR:
-                        out = fold_binary(ctx, INSTR_SUB_V, exprs[0], exprs[1]);
+                        out = fold::binary(ctx, INSTR_SUB_V, exprs[0], exprs[1]);
                         break;
                     default:
                         compile_error(ctx, "invalid types used in expression: cannot subtract type %s from %s",
@@ -538,19 +541,19 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                               type_name[exprs[0]->vtype]);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 switch (exprs[0]->vtype) {
                     case TYPE_FLOAT:
                         if (exprs[1]->vtype == TYPE_VECTOR)
-                            out = fold_binary(ctx, INSTR_MUL_FV, exprs[0], exprs[1]);
+                            out = fold::binary(ctx, INSTR_MUL_FV, exprs[0], exprs[1]);
                         else
-                            out = fold_binary(ctx, INSTR_MUL_F, exprs[0], exprs[1]);
+                            out = fold::binary(ctx, INSTR_MUL_F, exprs[0], exprs[1]);
                         break;
                     case TYPE_VECTOR:
                         if (exprs[1]->vtype == TYPE_FLOAT)
-                            out = fold_binary(ctx, INSTR_MUL_VF, exprs[0], exprs[1]);
+                            out = fold::binary(ctx, INSTR_MUL_VF, exprs[0], exprs[1]);
                         else
-                            out = fold_binary(ctx, INSTR_MUL_V, exprs[0], exprs[1]);
+                            out = fold::binary(ctx, INSTR_MUL_V, exprs[0], exprs[1]);
                         break;
                     default:
                         compile_error(ctx, "invalid types used in expression: cannot multiply types %s and %s",
@@ -568,9 +571,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 compile_error(ctx, "invalid types used in expression: cannot divide types %s and %s", ty1, ty2);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 if (exprs[0]->vtype == TYPE_FLOAT)
-                    out = fold_binary(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
+                    out = fold::binary(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
                 else {
                     ast_type_to_string(exprs[0], ty1, sizeof(ty1));
                     ast_type_to_string(exprs[1], ty2, sizeof(ty2));
@@ -586,10 +589,10 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                     type_name[exprs[0]->vtype],
                     type_name[exprs[1]->vtype]);
                 return false;
-            } else if (!(out = fold_op(parser->fold, op, exprs))) {
+            } else if (!(out = parser->m_fold.op(op, exprs))) {
                 /* generate a call to __builtin_mod */
-                ast_expression *mod  = intrin_func(parser->intrin, "mod");
-                ast_call       *call = NULL;
+                ast_expression *mod  = parser->m_intrin.func("mod");
+                ast_call       *call = nullptr;
                 if (!mod) return false; /* can return null for missing floor */
 
                 call = ast_call_new(parser_ctx(parser), mod);
@@ -617,13 +620,13 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 return false;
             }
 
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 /*
                  * IF the first expression is float, the following will be too
                  * since scalar ^ vector is not allowed.
                  */
                 if (exprs[0]->vtype == TYPE_FLOAT) {
-                    out = fold_binary(ctx,
+                    out = fold::binary(ctx,
                         (op->id == opid1('^') ? VINSTR_BITXOR : op->id == opid1('|') ? INSTR_BITOR : INSTR_BITAND),
                         exprs[0], exprs[1]);
                 } else {
@@ -636,11 +639,11 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                          * Bitop all the values of the vector components against the
                          * vectors components in question.
                          */
-                        out = fold_binary(ctx,
+                        out = fold::binary(ctx,
                             (op->id == opid1('^') ? VINSTR_BITXOR_V : op->id == opid1('|') ? VINSTR_BITOR_V : VINSTR_BITAND_V),
                             exprs[0], exprs[1]);
                     } else {
-                        out = fold_binary(ctx,
+                        out = fold::binary(ctx,
                             (op->id == opid1('^') ? VINSTR_BITXOR_VF : op->id == opid1('|') ? VINSTR_BITOR_VF : VINSTR_BITAND_VF),
                             exprs[0], exprs[1]);
                     }
@@ -657,9 +660,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 return false;
             }
 
-            if (!(out = fold_op(parser->fold, op, exprs))) {
-                ast_expression *shift = intrin_func(parser->intrin, (op->id == opid2('<','<')) ? "__builtin_lshift" : "__builtin_rshift");
-                ast_call       *call  = ast_call_new(parser_ctx(parser), shift);
+            if (!(out = parser->m_fold.op(op, exprs))) {
+                ast_expression *shift = parser->m_intrin.func((op->id == opid2('<','<')) ? "__builtin_lshift" : "__builtin_rshift");
+                ast_call *call  = ast_call_new(parser_ctx(parser), shift);
                 call->params.push_back(exprs[0]);
                 call->params.push_back(exprs[1]);
                 out = (ast_expression*)call;
@@ -675,9 +678,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 return false;
             }
 
-            if(!(out = fold_op(parser->fold, op, exprs))) {
-                ast_expression *shift = intrin_func(parser->intrin, (op->id == opid3('<','<','=')) ? "__builtin_lshift" : "__builtin_rshift");
-                ast_call       *call  = ast_call_new(parser_ctx(parser), shift);
+            if(!(out = parser->m_fold.op(op, exprs))) {
+                ast_expression *shift = parser->m_intrin.func((op->id == opid3('<','<','=')) ? "__builtin_lshift" : "__builtin_rshift");
+                ast_call *call  = ast_call_new(parser_ctx(parser), shift);
                 call->params.push_back(exprs[0]);
                 call->params.push_back(exprs[1]);
                 out = (ast_expression*)ast_store_new(
@@ -694,7 +697,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             generated_op += 1; /* INSTR_OR */
         case opid2('&','&'):
             generated_op += INSTR_AND;
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) {
                     ast_type_to_string(exprs[0], ty1, sizeof(ty1));
                     ast_type_to_string(exprs[1], ty2, sizeof(ty2));
@@ -707,7 +710,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                         if (!out) break;
                         out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, out);
                         if (!out) break;
-                        exprs[i] = out; out = NULL;
+                        exprs[i] = out; out = nullptr;
                         if (OPTS_FLAG(PERL_LOGIC)) {
                             /* here we want to keep the right expressions' type */
                             break;
@@ -718,30 +721,30 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                         if (!out) break;
                         out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, out);
                         if (!out) break;
-                        exprs[i] = out; out = NULL;
+                        exprs[i] = out; out = nullptr;
                         if (OPTS_FLAG(PERL_LOGIC)) {
                             /* here we want to keep the right expressions' type */
                             break;
                         }
                     }
                 }
-                out = fold_binary(ctx, generated_op, exprs[0], exprs[1]);
+                out = fold::binary(ctx, generated_op, exprs[0], exprs[1]);
             }
             break;
 
         case opid2('?',':'):
-            if (vec_last(sy->paren) != PAREN_TERNARY2) {
+            if (sy->paren.back() != PAREN_TERNARY2) {
                 compile_error(ctx, "mismatched parenthesis/ternary");
                 return false;
             }
-            vec_pop(sy->paren);
+            sy->paren.pop_back();
             if (!ast_compare_type(exprs[1], exprs[2])) {
                 ast_type_to_string(exprs[1], ty1, sizeof(ty1));
                 ast_type_to_string(exprs[2], ty2, sizeof(ty2));
                 compile_error(ctx, "operands of ternary expression must have the same type, got %s and %s", ty1, ty2);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs)))
+            if (!(out = parser->m_fold.op(op, exprs)))
                 out = (ast_expression*)ast_ternary_new(ctx, exprs[0], exprs[1], exprs[2]);
             break;
 
@@ -754,8 +757,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 return false;
             }
 
-            if (!(out = fold_op(parser->fold, op, exprs))) {
-                ast_call *gencall = ast_call_new(parser_ctx(parser), intrin_func(parser->intrin, "pow"));
+            if (!(out = parser->m_fold.op(op, exprs))) {
+                ast_call *gencall = ast_call_new(parser_ctx(parser), parser->m_intrin.func("pow"));
                 gencall->params.push_back(exprs[0]);
                 gencall->params.push_back(exprs[1]);
                 out = (ast_expression*)gencall;
@@ -771,12 +774,12 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 return false;
             }
 
-            if (!(out = fold_op(parser->fold, op, exprs))) {
-                out = fold_binary(
-                        parser_ctx(parser),
-                        VINSTR_CROSS,
-                        exprs[0],
-                        exprs[1]
+            if (!(out = parser->m_fold.op(op, exprs))) {
+                out = fold::binary(
+                    parser_ctx(parser),
+                    VINSTR_CROSS,
+                    exprs[0],
+                    exprs[1]
                 );
             }
 
@@ -792,7 +795,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 return false;
             }
 
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 /* This whole block is NOT fold_binary safe */
                 ast_binary *eq = ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]);
 
@@ -802,15 +805,15 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 out = (ast_expression*)ast_ternary_new(ctx,
                         (ast_expression*)ast_binary_new(ctx, INSTR_LT, exprs[0], exprs[1]),
                         /* out = -1 */
-                        (ast_expression*)parser->fold->imm_float[2],
+                        (ast_expression*)parser->m_fold.imm_float(2),
                     /* } else { */
                         /* if (eq) { */
                         (ast_expression*)ast_ternary_new(ctx, (ast_expression*)eq,
                             /* out = 0 */
-                            (ast_expression*)parser->fold->imm_float[0],
+                            (ast_expression*)parser->m_fold.imm_float(0),
                         /* } else { */
                             /* out = 1 */
-                            (ast_expression*)parser->fold->imm_float[1]
+                            (ast_expression*)parser->m_fold.imm_float(1)
                         /* } */
                         )
                     /* } */
@@ -833,8 +836,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                               type_name[exprs[1]->vtype]);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs)))
-                out = fold_binary(ctx, generated_op, exprs[0], exprs[1]);
+            if (!(out = parser->m_fold.op(op, exprs)))
+                out = fold::binary(ctx, generated_op, exprs[0], exprs[1]);
             break;
         case opid2('!', '='):
             if (exprs[0]->vtype != exprs[1]->vtype) {
@@ -843,8 +846,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                               type_name[exprs[1]->vtype]);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs)))
-                out = fold_binary(ctx, type_ne_instr[exprs[0]->vtype], exprs[0], exprs[1]);
+            if (!(out = parser->m_fold.op(op, exprs)))
+                out = fold::binary(ctx, type_ne_instr[exprs[0]->vtype], exprs[0], exprs[1]);
             break;
         case opid2('=', '='):
             if (exprs[0]->vtype != exprs[1]->vtype) {
@@ -853,8 +856,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                               type_name[exprs[1]->vtype]);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs)))
-                out = fold_binary(ctx, type_eq_instr[exprs[0]->vtype], exprs[0], exprs[1]);
+            if (!(out = parser->m_fold.op(op, exprs)))
+                out = fold::binary(ctx, type_eq_instr[exprs[0]->vtype], exprs[0], exprs[1]);
             break;
 
         case opid1('='):
@@ -937,11 +940,11 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             if (ast_istype(exprs[0], ast_entfield)) {
                 out = (ast_expression*)ast_binstore_new(ctx, INSTR_STOREP_F, addop,
                                                         exprs[0],
-                                                        (ast_expression*)parser->fold->imm_float[1]);
+                                                        (ast_expression*)parser->m_fold.imm_float(1));
             } else {
                 out = (ast_expression*)ast_binstore_new(ctx, INSTR_STORE_F, addop,
                                                         exprs[0],
-                                                        (ast_expression*)parser->fold->imm_float[1]);
+                                                        (ast_expression*)parser->m_fold.imm_float(1));
             }
             break;
         case opid3('S','+','+'):
@@ -963,17 +966,17 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             if (ast_istype(exprs[0], ast_entfield)) {
                 out = (ast_expression*)ast_binstore_new(ctx, INSTR_STOREP_F, addop,
                                                         exprs[0],
-                                                        (ast_expression*)parser->fold->imm_float[1]);
+                                                        (ast_expression*)parser->m_fold.imm_float(1));
             } else {
                 out = (ast_expression*)ast_binstore_new(ctx, INSTR_STORE_F, addop,
                                                         exprs[0],
-                                                        (ast_expression*)parser->fold->imm_float[1]);
+                                                        (ast_expression*)parser->m_fold.imm_float(1));
             }
             if (!out)
                 return false;
-            out = fold_binary(ctx, subop,
+            out = fold::binary(ctx, subop,
                               out,
-                              (ast_expression*)parser->fold->imm_float[1]);
+                              (ast_expression*)parser->m_fold.imm_float(1));
 
             break;
         case opid2('+','='):
@@ -1038,8 +1041,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                         out = (ast_expression*)ast_binstore_new(ctx, assignop, INSTR_MUL_VF,
                                                                 exprs[0], exprs[1]);
                     } else {
-                        out = fold_binary(ctx, INSTR_DIV_F,
-                                         (ast_expression*)parser->fold->imm_float[1],
+                        out = fold::binary(ctx, INSTR_DIV_F,
+                                         (ast_expression*)parser->m_fold.imm_float(1),
                                          exprs[1]);
                         if (!out) {
                             compile_error(ctx, "internal error: failed to generate division");
@@ -1097,9 +1100,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             else
                 assignop = type_store_instr[exprs[0]->vtype];
             if (exprs[0]->vtype == TYPE_FLOAT)
-                out = fold_binary(ctx, INSTR_BITAND, exprs[0], exprs[1]);
+                out = fold::binary(ctx, INSTR_BITAND, exprs[0], exprs[1]);
             else
-                out = fold_binary(ctx, VINSTR_BITAND_V, exprs[0], exprs[1]);
+                out = fold::binary(ctx, VINSTR_BITAND_V, exprs[0], exprs[1]);
             if (!out)
                 return false;
             (void)check_write_to(ctx, exprs[0]);
@@ -1124,7 +1127,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 compile_error(ast_ctx(exprs[0]), "operand of length operator not a valid constant expression");
                 return false;
             }
-            out = fold_op(parser->fold, op, exprs);
+            out = parser->m_fold.op(op, exprs);
             break;
 
         case opid2('~', 'P'):
@@ -1133,11 +1136,11 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 compile_error(ast_ctx(exprs[0]), "invalid type for bit not: %s", ty1);
                 return false;
             }
-            if (!(out = fold_op(parser->fold, op, exprs))) {
+            if (!(out = parser->m_fold.op(op, exprs))) {
                 if (exprs[0]->vtype == TYPE_FLOAT) {
-                    out = fold_binary(ctx, INSTR_SUB_F, (ast_expression*)parser->fold->imm_float[2], exprs[0]);
+                    out = fold::binary(ctx, INSTR_SUB_F, (ast_expression*)parser->m_fold.imm_float(2), exprs[0]);
                 } else {
-                    out = fold_binary(ctx, INSTR_SUB_V, (ast_expression*)parser->fold->imm_vector[1], exprs[0]);
+                    out = fold::binary(ctx, INSTR_SUB_V, (ast_expression*)parser->m_fold.imm_vector(1), exprs[0]);
                 }
             }
             break;
@@ -1148,7 +1151,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
         return false;
     }
 
-    vec_push(sy->out, syexp(ctx, out));
+    sy->out.push_back(syexp(ctx, out));
     return true;
 }
 
@@ -1156,32 +1159,32 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
 {
     /* was a function call */
     ast_expression *fun;
-    ast_value      *funval = NULL;
+    ast_value      *funval = nullptr;
     ast_call       *call;
 
     size_t          fid;
     size_t          paramcount, i;
     bool            fold = true;
 
-    fid = vec_last(sy->ops).off;
-    vec_shrinkby(sy->ops, 1);
+    fid = sy->ops.back().off;
+    sy->ops.pop_back();
 
     /* out[fid] is the function
      * everything above is parameters...
      */
-    if (!vec_size(sy->argc)) {
+    if (sy->argc.empty()) {
         parseerror(parser, "internal error: no argument counter available");
         return false;
     }
 
-    paramcount = vec_last(sy->argc);
-    vec_pop(sy->argc);
+    paramcount = sy->argc.back();
+    sy->argc.pop_back();
 
-    if (vec_size(sy->out) < fid) {
-        parseerror(parser, "internal error: broken function call%lu < %lu+%lu\n",
-                   (unsigned long)vec_size(sy->out),
-                   (unsigned long)fid,
-                   (unsigned long)paramcount);
+    if (sy->out.size() < fid) {
+        parseerror(parser, "internal error: broken function call %zu < %zu+%zu\n",
+                   sy->out.size(),
+                   fid,
+                   paramcount);
         return false;
     }
 
@@ -1189,19 +1192,17 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
      * TODO handle this at the intrinsic level with an ast_intrinsic
      * node and codegen.
      */
-    if ((fun = sy->out[fid].out) == intrin_debug_typestring(parser->intrin)) {
+    if ((fun = sy->out[fid].out) == parser->m_intrin.debug_typestring()) {
         char ty[1024];
-        if (fid+2 != vec_size(sy->out) ||
-            vec_last(sy->out).block)
-        {
+        if (fid+2 != sy->out.size() || sy->out.back().block) {
             parseerror(parser, "intrinsic __builtin_debug_typestring requires exactly 1 parameter");
             return false;
         }
-        ast_type_to_string(vec_last(sy->out).out, ty, sizeof(ty));
-        ast_unref(vec_last(sy->out).out);
-        sy->out[fid] = syexp(ast_ctx(vec_last(sy->out).out),
-                             (ast_expression*)fold_constgen_string(parser->fold, ty, false));
-        vec_shrinkby(sy->out, 1);
+        ast_type_to_string(sy->out.back().out, ty, sizeof(ty));
+        ast_unref(sy->out.back().out);
+        sy->out[fid] = syexp(ast_ctx(sy->out.back().out),
+                             (ast_expression*)parser->m_fold.constgen_string(ty, false));
+        sy->out.pop_back();
         return true;
     }
 
@@ -1214,7 +1215,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
     (ast_istype(((ast_expression*)(X)), ast_value) && (X)->hasvalue && ((X)->cvq == CV_CONST) && \
                 ((ast_expression*)(X))->vtype != TYPE_FUNCTION)
 
-    if (fid + 1 < vec_size(sy->out))
+    if (fid + 1 < sy->out.size())
         ++paramcount;
 
     for (i = 0; i < paramcount; ++i) {
@@ -1229,13 +1230,13 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
      * intrinsic call and just evaluate it i.e constant fold it.
      */
     if (fold && ast_istype(fun, ast_value) && ((ast_value*)fun)->intrinsic) {
-        ast_expression **exprs  = NULL;
-        ast_expression *foldval = NULL;
+        ast_expression **exprs  = nullptr;
+        ast_expression *foldval = nullptr;
 
         for (i = 0; i < paramcount; i++)
             vec_push(exprs, sy->out[fid+1 + i].out);
 
-        if (!(foldval = intrin_fold(parser->intrin, (ast_value*)fun, exprs))) {
+        if (!(foldval = parser->m_intrin.do_fold((ast_value*)fun, exprs))) {
             vec_free(exprs);
             goto fold_leave;
         }
@@ -1244,29 +1245,31 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
          * Blub: what sorts of unreffing and resizing of
          * sy->out should I be doing here?
          */
-        sy->out[fid] = syexp(foldval->node.context, foldval);
-        vec_shrinkby(sy->out, paramcount);
+        sy->out[fid] = syexp(foldval->context, foldval);
+        sy->out.erase(sy->out.end() - paramcount, sy->out.end());
         vec_free(exprs);
 
         return true;
     }
 
     fold_leave:
-    call = ast_call_new(sy->ops[vec_size(sy->ops)].ctx, fun);
+    call = ast_call_new(sy->ops[sy->ops.size()].ctx, fun);
 
     if (!call)
         return false;
 
-    if (fid+1 + paramcount != vec_size(sy->out)) {
-        parseerror(parser, "internal error: parameter count mismatch: (%lu+1+%lu), %lu",
-                   (unsigned long)fid, (unsigned long)paramcount, (unsigned long)vec_size(sy->out));
+    if (fid+1 + paramcount != sy->out.size()) {
+        parseerror(parser, "internal error: parameter count mismatch: (%zu+1+%zu), %zu",
+                   fid,
+                   paramcount,
+                   sy->out.size());
         return false;
     }
 
     for (i = 0; i < paramcount; ++i)
         call->params.push_back(sy->out[fid+1 + i].out);
-    vec_shrinkby(sy->out, paramcount);
-    (void)!ast_call_check_types(call, parser->function->vtype->expression.varparam);
+    sy->out.erase(sy->out.end() - paramcount, sy->out.end());
+    (void)!ast_call_check_types(call, parser->function->function_type->varparam);
     if (parser->max_param_count < paramcount)
         parser->max_param_count = paramcount;
 
@@ -1275,12 +1278,12 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
         if ((fun->flags & AST_FLAG_VARIADIC) &&
             !(/*funval->cvq == CV_CONST && */ funval->hasvalue && funval->constval.vfunc->builtin))
         {
-            call->va_count = (ast_expression*)fold_constgen_float(parser->fold, (qcfloat_t)paramcount, false);
+            call->va_count = (ast_expression*)parser->m_fold.constgen_float((qcfloat_t)paramcount, false);
         }
     }
 
     /* overwrite fid, the function, with a call */
-    sy->out[fid] = syexp(call->expression.node.context, (ast_expression*)call);
+    sy->out[fid] = syexp(call->context, (ast_expression*)call);
 
     if (fun->vtype != TYPE_FUNCTION) {
         parseerror(parser, "not a function (%s)", type_name[fun->vtype]);
@@ -1291,7 +1294,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
         parseerror(parser, "could not determine function return type");
         return false;
     } else {
-        ast_value *fval = (ast_istype(fun, ast_value) ? ((ast_value*)fun) : NULL);
+        ast_value *fval = (ast_istype(fun, ast_value) ? ((ast_value*)fun) : nullptr);
 
         if (fun->flags & AST_FLAG_DEPRECATED) {
             if (!fval) {
@@ -1313,22 +1316,22 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
                     ast_ctx(fun).line);
         }
 
-        if (fun->params.size() != paramcount &&
+        if (fun->type_params.size() != paramcount &&
             !((fun->flags & AST_FLAG_VARIADIC) &&
-              fun->params.size() < paramcount))
+              fun->type_params.size() < paramcount))
         {
-            const char *fewmany = (fun->params.size() > paramcount) ? "few" : "many";
+            const char *fewmany = (fun->type_params.size() > paramcount) ? "few" : "many";
             if (fval)
                 return !parsewarning(parser, WARN_INVALID_PARAMETER_COUNT,
                                      "too %s parameters for call to %s: expected %i, got %i\n"
                                      " -> `%s` has been declared here: %s:%i",
-                                     fewmany, fval->name, (int)fun->params.size(), (int)paramcount,
+                                     fewmany, fval->name, (int)fun->type_params.size(), (int)paramcount,
                                      fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line);
             else
                 return !parsewarning(parser, WARN_INVALID_PARAMETER_COUNT,
                                      "too %s parameters for function call: expected %i, got %i\n"
                                      " -> it has been declared here: %s:%i",
-                                     fewmany, (int)fun->params.size(), (int)paramcount,
+                                     fewmany, (int)fun->type_params.size(), (int)paramcount,
                                      ast_ctx(fun).file, (int)ast_ctx(fun).line);
         }
     }
@@ -1338,45 +1341,45 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
 
 static bool parser_close_paren(parser_t *parser, shunt *sy)
 {
-    if (!vec_size(sy->ops)) {
+    if (sy->ops.empty()) {
         parseerror(parser, "unmatched closing paren");
         return false;
     }
 
-    while (vec_size(sy->ops)) {
-        if (vec_last(sy->ops).isparen) {
-            if (vec_last(sy->paren) == PAREN_FUNC) {
-                vec_pop(sy->paren);
+    while (sy->ops.size()) {
+        if (sy->ops.back().isparen) {
+            if (sy->paren.back() == PAREN_FUNC) {
+                sy->paren.pop_back();
                 if (!parser_close_call(parser, sy))
                     return false;
                 break;
             }
-            if (vec_last(sy->paren) == PAREN_EXPR) {
-                vec_pop(sy->paren);
-                if (!vec_size(sy->out)) {
-                    compile_error(vec_last(sy->ops).ctx, "empty paren expression");
-                    vec_shrinkby(sy->ops, 1);
+            if (sy->paren.back() == PAREN_EXPR) {
+                sy->paren.pop_back();
+                if (sy->out.empty()) {
+                    compile_error(sy->ops.back().ctx, "empty paren expression");
+                    sy->ops.pop_back();
                     return false;
                 }
-                vec_shrinkby(sy->ops, 1);
+                sy->ops.pop_back();
                 break;
             }
-            if (vec_last(sy->paren) == PAREN_INDEX) {
-                vec_pop(sy->paren);
-                /* pop off the parenthesis */
-                vec_shrinkby(sy->ops, 1);
+            if (sy->paren.back() == PAREN_INDEX) {
+                sy->paren.pop_back();
+                // pop off the parenthesis
+                sy->ops.pop_back();
                 /* then apply the index operator */
                 if (!parser_sy_apply_operator(parser, sy))
                     return false;
                 break;
             }
-            if (vec_last(sy->paren) == PAREN_TERNARY1) {
-                vec_last(sy->paren) = PAREN_TERNARY2;
-                /* pop off the parenthesis */
-                vec_shrinkby(sy->ops, 1);
+            if (sy->paren.back() == PAREN_TERNARY1) {
+                sy->paren.back() = PAREN_TERNARY2;
+                // pop off the parenthesis
+                sy->ops.pop_back();
                 break;
             }
-            compile_error(vec_last(sy->ops).ctx, "invalid parenthesis");
+            compile_error(sy->ops.back().ctx, "invalid parenthesis");
             return false;
         }
         if (!parser_sy_apply_operator(parser, sy))
@@ -1402,32 +1405,32 @@ static ast_expression* parse_vararg_do(parser_t *parser)
 {
     ast_expression *idx, *out;
     ast_value      *typevar;
-    ast_value      *funtype = parser->function->vtype;
+    ast_value      *funtype = parser->function->function_type;
     lex_ctx_t         ctx     = parser_ctx(parser);
 
     if (!parser->function->varargs) {
         parseerror(parser, "function has no variable argument list");
-        return NULL;
+        return nullptr;
     }
 
     if (!parser_next(parser) || parser->tok != '(') {
         parseerror(parser, "expected parameter index and type in parenthesis");
-        return NULL;
+        return nullptr;
     }
     if (!parser_next(parser)) {
         parseerror(parser, "error parsing parameter index");
-        return NULL;
+        return nullptr;
     }
 
     idx = parse_expression_leave(parser, true, false, false);
     if (!idx)
-        return NULL;
+        return nullptr;
 
     if (parser->tok != ',') {
         if (parser->tok != ')') {
             ast_unref(idx);
             parseerror(parser, "expected comma after parameter index");
-            return NULL;
+            return nullptr;
         }
         /* vararg piping: ...(start) */
         out = (ast_expression*)ast_argpipe_new(ctx, idx);
@@ -1437,29 +1440,29 @@ static ast_expression* parse_vararg_do(parser_t *parser)
     if (!parser_next(parser) || (parser->tok != TOKEN_IDENT && parser->tok != TOKEN_TYPENAME)) {
         ast_unref(idx);
         parseerror(parser, "expected typename for vararg");
-        return NULL;
+        return nullptr;
     }
 
-    typevar = parse_typename(parser, NULL, NULL, NULL);
+    typevar = parse_typename(parser, nullptr, nullptr, nullptr);
     if (!typevar) {
         ast_unref(idx);
-        return NULL;
+        return nullptr;
     }
 
     if (parser->tok != ')') {
         ast_unref(idx);
         ast_delete(typevar);
         parseerror(parser, "expected closing paren");
-        return NULL;
+        return nullptr;
     }
 
-    if (funtype->expression.varparam &&
-        !ast_compare_type((ast_expression*)typevar, (ast_expression*)funtype->expression.varparam))
+    if (funtype->varparam &&
+        !ast_compare_type((ast_expression*)typevar, (ast_expression*)funtype->varparam))
     {
         char ty1[1024];
         char ty2[1024];
         ast_type_to_string((ast_expression*)typevar, ty1, sizeof(ty1));
-        ast_type_to_string((ast_expression*)funtype->expression.varparam, ty2, sizeof(ty2));
+        ast_type_to_string((ast_expression*)funtype->varparam, ty2, sizeof(ty2));
         compile_error(ast_ctx(typevar),
                       "function was declared to take varargs of type `%s`, requested type is: %s",
                       ty2, ty1);
@@ -1505,10 +1508,10 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
             parseerror(parser, "expected a constant string in translatable-string extension");
             return false;
         }
-        val = (ast_value*)fold_constgen_string(parser->fold, parser_tokval(parser), true);
+        val = (ast_value*)parser->m_fold.constgen_string(parser_tokval(parser), true);
         if (!val)
             return false;
-        vec_push(sy->out, syexp(parser_ctx(parser), (ast_expression*)val));
+        sy->out.push_back(syexp(parser_ctx(parser), (ast_expression*)val));
 
         if (!parser_next(parser) || parser->tok != ')') {
             parseerror(parser, "expected closing paren after translatable string");
@@ -1526,49 +1529,49 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
         va = parse_vararg(parser);
         if (!va)
             return false;
-        vec_push(sy->out, syexp(parser_ctx(parser), va));
+        sy->out.push_back(syexp(parser_ctx(parser), va));
         return true;
     }
     else if (parser->tok == TOKEN_FLOATCONST) {
-        ast_expression *val = fold_constgen_float(parser->fold, (parser_token(parser)->constval.f), false);
+        ast_expression *val = parser->m_fold.constgen_float((parser_token(parser)->constval.f), false);
         if (!val)
             return false;
-        vec_push(sy->out, syexp(parser_ctx(parser), val));
+        sy->out.push_back(syexp(parser_ctx(parser), val));
         return true;
     }
     else if (parser->tok == TOKEN_INTCONST || parser->tok == TOKEN_CHARCONST) {
-        ast_expression *val = fold_constgen_float(parser->fold, (qcfloat_t)(parser_token(parser)->constval.i), false);
+        ast_expression *val = parser->m_fold.constgen_float((qcfloat_t)(parser_token(parser)->constval.i), false);
         if (!val)
             return false;
-        vec_push(sy->out, syexp(parser_ctx(parser), val));
+        sy->out.push_back(syexp(parser_ctx(parser), val));
         return true;
     }
     else if (parser->tok == TOKEN_STRINGCONST) {
-        ast_expression *val = fold_constgen_string(parser->fold, parser_tokval(parser), false);
+        ast_expression *val = parser->m_fold.constgen_string(parser_tokval(parser), false);
         if (!val)
             return false;
-        vec_push(sy->out, syexp(parser_ctx(parser), val));
+        sy->out.push_back(syexp(parser_ctx(parser), val));
         return true;
     }
     else if (parser->tok == TOKEN_VECTORCONST) {
-        ast_expression *val = fold_constgen_vector(parser->fold, parser_token(parser)->constval.v);
+        ast_expression *val = parser->m_fold.constgen_vector(parser_token(parser)->constval.v);
         if (!val)
             return false;
-        vec_push(sy->out, syexp(parser_ctx(parser), val));
+        sy->out.push_back(syexp(parser_ctx(parser), val));
         return true;
     }
     else if (parser->tok == TOKEN_IDENT)
     {
         const char     *ctoken = parser_tokval(parser);
-        ast_expression *prev = vec_size(sy->out) ? vec_last(sy->out).out : NULL;
+        ast_expression *prev = sy->out.size() ? sy->out.back().out : nullptr;
         ast_expression *var;
         /* a_vector.{x,y,z} */
-        if (!vec_size(sy->ops) ||
-            !vec_last(sy->ops).etype ||
-            operators[vec_last(sy->ops).etype-1].id != opid1('.'))
+        if (sy->ops.empty() ||
+            !sy->ops.back().etype ||
+            operators[sy->ops.back().etype-1].id != opid1('.'))
         {
             /* When adding more intrinsics, fix the above condition */
-            prev = NULL;
+            prev = nullptr;
         }
         if (prev && prev->vtype == TYPE_VECTOR && ctoken[0] >= 'x' && ctoken[0] <= 'z' && !ctoken[1])
         {
@@ -1587,7 +1590,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
             }
         }
         if (!var && !strcmp(parser_tokval(parser), "__FUNC__"))
-            var = (ast_expression*)fold_constgen_string(parser->fold, parser->function->name, false);
+            var = (ast_expression*)parser->m_fold.constgen_string(parser->function->name, false);
         if (!var) {
             /*
              * now we try for the real intrinsic hashtable. If the string
@@ -1595,7 +1598,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
              * use the identifier as is.
              */
             if (!strncmp(parser_tokval(parser), "__builtin_", 10)) {
-                var = intrin_func(parser->intrin, parser_tokval(parser));
+                var = parser->m_intrin.func(parser_tokval(parser));
             }
 
             /*
@@ -1603,7 +1606,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
              * the first one masks for __builtin though, we emit warning here.
              */
             if (!var) {
-                if ((var = intrin_func(parser->intrin, parser_tokval(parser)))) {
+                if ((var = parser->m_intrin.func(parser_tokval(parser)))) {
                     (void)!compile_warning(
                         parser_ctx(parser),
                         WARN_BUILTINS,
@@ -1641,7 +1644,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
                     ((ast_value*)(mem->owner))->uses++;
             }
         }
-        vec_push(sy->out, syexp(parser_ctx(parser), var));
+        sy->out.push_back(syexp(parser_ctx(parser), var));
         return true;
     }
     parseerror(parser, "unexpected token `%s`", parser_tokval(parser));
@@ -1650,9 +1653,8 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
 
 static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels)
 {
-    ast_expression *expr = NULL;
+    ast_expression *expr = nullptr;
     shunt sy;
-    size_t i;
     bool wantop = false;
     /* only warn once about an assignment in a truth value because the current code
      * would trigger twice on: if(a = b && ...), once for the if-truth-value, once for the && part
@@ -1681,7 +1683,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
         {
             /* classify the operator */
             const oper_info *op;
-            const oper_info *olast = NULL;
+            const oper_info *olast = nullptr;
             size_t o;
             for (o = 0; o < operator_count; ++o) {
                 if (((!(operators[o].flags & OP_PREFIX) == !!wantop)) &&
@@ -1699,7 +1701,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             op = &operators[o];
 
             /* when declaring variables, a comma starts a new variable */
-            if (op->id == opid1(',') && !vec_size(sy.paren) && stopatcomma) {
+            if (op->id == opid1(',') && sy.paren.empty() && stopatcomma) {
                 /* fixup the token */
                 parser->tok = ',';
                 break;
@@ -1712,23 +1714,23 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             }
 
             if (op->id == opid1(',')) {
-                if (vec_size(sy.paren) && vec_last(sy.paren) == PAREN_TERNARY2) {
+                if (sy.paren.size() && sy.paren.back() == PAREN_TERNARY2) {
                     (void)!parsewarning(parser, WARN_TERNARY_PRECEDENCE, "suggesting parenthesis around ternary expression");
                 }
             }
 
-            if (vec_size(sy.ops) && !vec_last(sy.ops).isparen)
-                olast = &operators[vec_last(sy.ops).etype-1];
+            if (sy.ops.size() && !sy.ops.back().isparen)
+                olast = &operators[sy.ops.back().etype-1];
 
             /* first only apply higher precedences, assoc_left+equal comes after we warn about precedence rules */
             while (olast && op->prec < olast->prec)
             {
                 if (!parser_sy_apply_operator(parser, &sy))
                     goto onerr;
-                if (vec_size(sy.ops) && !vec_last(sy.ops).isparen)
-                    olast = &operators[vec_last(sy.ops).etype-1];
+                if (sy.ops.size() && !sy.ops.back().isparen)
+                    olast = &operators[sy.ops.back().etype-1];
                 else
-                    olast = NULL;
+                    olast = nullptr;
             }
 
 #define IsAssignOp(x) (\
@@ -1745,7 +1747,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             if (warn_parenthesis) {
                 if ( (olast && IsAssignOp(olast->id) && (op->id == opid2('&','&') || op->id == opid2('|','|'))) ||
                      (olast && IsAssignOp(op->id) && (olast->id == opid2('&','&') || olast->id == opid2('|','|'))) ||
-                     (truthvalue && !vec_size(sy.paren) && IsAssignOp(op->id))
+                     (truthvalue && sy.paren.empty() && IsAssignOp(op->id))
                    )
                 {
                     (void)!parsewarning(parser, WARN_PARENTHESIS, "suggesting parenthesis around assignment used as truth value");
@@ -1774,22 +1776,22 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             {
                 if (!parser_sy_apply_operator(parser, &sy))
                     goto onerr;
-                if (vec_size(sy.ops) && !vec_last(sy.ops).isparen)
-                    olast = &operators[vec_last(sy.ops).etype-1];
+                if (sy.ops.size() && !sy.ops.back().isparen)
+                    olast = &operators[sy.ops.back().etype-1];
                 else
-                    olast = NULL;
+                    olast = nullptr;
             }
 
             if (op->id == opid1('(')) {
                 if (wantop) {
-                    size_t sycount = vec_size(sy.out);
+                    size_t sycount = sy.out.size();
                     /* we expected an operator, this is the function-call operator */
-                    vec_push(sy.paren, PAREN_FUNC);
-                    vec_push(sy.ops, syparen(parser_ctx(parser), sycount-1));
-                    vec_push(sy.argc, 0);
+                    sy.paren.push_back(PAREN_FUNC);
+                    sy.ops.push_back(syparen(parser_ctx(parser), sycount-1));
+                    sy.argc.push_back(0);
                 } else {
-                    vec_push(sy.paren, PAREN_EXPR);
-                    vec_push(sy.ops, syparen(parser_ctx(parser), 0));
+                    sy.paren.push_back(PAREN_EXPR);
+                    sy.ops.push_back(syparen(parser_ctx(parser), 0));
                 }
                 wantop = false;
             } else if (op->id == opid1('[')) {
@@ -1797,45 +1799,45 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
                     parseerror(parser, "unexpected array subscript");
                     goto onerr;
                 }
-                vec_push(sy.paren, PAREN_INDEX);
+                sy.paren.push_back(PAREN_INDEX);
                 /* push both the operator and the paren, this makes life easier */
-                vec_push(sy.ops, syop(parser_ctx(parser), op));
-                vec_push(sy.ops, syparen(parser_ctx(parser), 0));
+                sy.ops.push_back(syop(parser_ctx(parser), op));
+                sy.ops.push_back(syparen(parser_ctx(parser), 0));
                 wantop = false;
             } else if (op->id == opid2('?',':')) {
-                vec_push(sy.ops, syop(parser_ctx(parser), op));
-                vec_push(sy.ops, syparen(parser_ctx(parser), 0));
+                sy.ops.push_back(syop(parser_ctx(parser), op));
+                sy.ops.push_back(syparen(parser_ctx(parser), 0));
                 wantop = false;
                 ++ternaries;
-                vec_push(sy.paren, PAREN_TERNARY1);
+                sy.paren.push_back(PAREN_TERNARY1);
             } else if (op->id == opid2(':','?')) {
-                if (!vec_size(sy.paren)) {
+                if (sy.paren.empty()) {
                     parseerror(parser, "unexpected colon outside ternary expression (missing parenthesis?)");
                     goto onerr;
                 }
-                if (vec_last(sy.paren) != PAREN_TERNARY1) {
+                if (sy.paren.back() != PAREN_TERNARY1) {
                     parseerror(parser, "unexpected colon outside ternary expression (missing parenthesis?)");
                     goto onerr;
                 }
                 if (!parser_close_paren(parser, &sy))
                     goto onerr;
-                vec_push(sy.ops, syop(parser_ctx(parser), op));
+                sy.ops.push_back(syop(parser_ctx(parser), op));
                 wantop = false;
                 --ternaries;
             } else {
-                vec_push(sy.ops, syop(parser_ctx(parser), op));
+                sy.ops.push_back(syop(parser_ctx(parser), op));
                 wantop = !!(op->flags & OP_SUFFIX);
             }
         }
         else if (parser->tok == ')') {
-            while (vec_size(sy.paren) && vec_last(sy.paren) == PAREN_TERNARY2) {
+            while (sy.paren.size() && sy.paren.back() == PAREN_TERNARY2) {
                 if (!parser_sy_apply_operator(parser, &sy))
                     goto onerr;
             }
-            if (!vec_size(sy.paren))
+            if (sy.paren.empty())
                 break;
             if (wantop) {
-                if (vec_last(sy.paren) == PAREN_TERNARY1) {
+                if (sy.paren.back() == PAREN_TERNARY1) {
                     parseerror(parser, "mismatched parentheses (closing paren in ternary expression?)");
                     goto onerr;
                 }
@@ -1843,7 +1845,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
                     goto onerr;
             } else {
                 /* must be a function call without parameters */
-                if (vec_last(sy.paren) != PAREN_FUNC) {
+                if (sy.paren.back() != PAREN_FUNC) {
                     parseerror(parser, "closing paren in invalid position");
                     goto onerr;
                 }
@@ -1861,13 +1863,13 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             goto onerr;
         }
         else if (parser->tok == ']') {
-            while (vec_size(sy.paren) && vec_last(sy.paren) == PAREN_TERNARY2) {
+            while (sy.paren.size() && sy.paren.back() == PAREN_TERNARY2) {
                 if (!parser_sy_apply_operator(parser, &sy))
                     goto onerr;
             }
-            if (!vec_size(sy.paren))
+            if (sy.paren.empty())
                 break;
-            if (vec_last(sy.paren) != PAREN_INDEX) {
+            if (sy.paren.back() != PAREN_INDEX) {
                 parseerror(parser, "mismatched parentheses, unexpected ']'");
                 goto onerr;
             }
@@ -1883,16 +1885,16 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
         else {
             /* in this case we might want to allow constant string concatenation */
             bool concatenated = false;
-            if (parser->tok == TOKEN_STRINGCONST && vec_size(sy.out)) {
-                ast_expression *lexpr = vec_last(sy.out).out;
+            if (parser->tok == TOKEN_STRINGCONST && sy.out.size()) {
+                ast_expression *lexpr = sy.out.back().out;
                 if (ast_istype(lexpr, ast_value)) {
                     ast_value *last = (ast_value*)lexpr;
                     if (last->isimm == true && last->cvq == CV_CONST &&
-                        last->hasvalue && last->expression.vtype == TYPE_STRING)
+                        last->hasvalue && last->vtype == TYPE_STRING)
                     {
-                        char *newstr = NULL;
+                        char *newstr = nullptr;
                         util_asprintf(&newstr, "%s%s", last->constval.vstring, parser_tokval(parser));
-                        vec_last(sy.out).out = (ast_expression*)fold_constgen_string(parser->fold, newstr, false);
+                        sy.out.back().out = (ast_expression*)parser->m_fold.constgen_string(newstr, false);
                         mem_d(newstr);
                         concatenated = true;
                     }
@@ -1908,60 +1910,50 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             goto onerr;
         }
         if (parser->tok == ';' ||
-            ((!vec_size(sy.paren) || (vec_size(sy.paren) == 1 && vec_last(sy.paren) == PAREN_TERNARY2)) &&
+            ((sy.paren.empty() || (sy.paren.size() == 1 && sy.paren.back() == PAREN_TERNARY2)) &&
             (parser->tok == ']' || parser->tok == ')' || parser->tok == '}')))
         {
             break;
         }
     }
 
-    while (vec_size(sy.ops)) {
+    while (sy.ops.size()) {
         if (!parser_sy_apply_operator(parser, &sy))
             goto onerr;
     }
 
     parser->lex->flags.noops = true;
-    if (vec_size(sy.out) != 1) {
+    if (sy.out.size() != 1) {
         parseerror(parser, "expression expected");
-        expr = NULL;
+        expr = nullptr;
     } else
         expr = sy.out[0].out;
-    vec_free(sy.out);
-    vec_free(sy.ops);
-    if (vec_size(sy.paren)) {
-        parseerror(parser, "internal error: vec_size(sy.paren) = %lu", (unsigned long)vec_size(sy.paren));
-        return NULL;
-    }
-    vec_free(sy.paren);
-    vec_free(sy.argc);
+    if (sy.paren.size()) {
+        parseerror(parser, "internal error: sy.paren.size() = %zu", sy.paren.size());
+        return nullptr;
+    }
     return expr;
 
 onerr:
     parser->lex->flags.noops = true;
-    for (i = 0; i < vec_size(sy.out); ++i) {
-        if (sy.out[i].out)
-            ast_unref(sy.out[i].out);
-    }
-    vec_free(sy.out);
-    vec_free(sy.ops);
-    vec_free(sy.paren);
-    vec_free(sy.argc);
-    return NULL;
+    for (auto &it : sy.out)
+        if (it.out) ast_unref(it.out);
+    return nullptr;
 }
 
 static ast_expression* parse_expression(parser_t *parser, bool stopatcomma, bool with_labels)
 {
     ast_expression *e = parse_expression_leave(parser, stopatcomma, false, with_labels);
     if (!e)
-        return NULL;
+        return nullptr;
     if (parser->tok != ';') {
         parseerror(parser, "semicolon expected after expression");
         ast_unref(e);
-        return NULL;
+        return nullptr;
     }
     if (!parser_next(parser)) {
         ast_unref(e);
-        return NULL;
+        return nullptr;
     }
     return e;
 }
@@ -2049,7 +2041,7 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond,
         if (!cond) {
             ast_unref(prev);
             parseerror(parser, "internal error: failed to process condition");
-            return NULL;
+            return nullptr;
         }
         ifnot = !ifnot;
     }
@@ -2065,7 +2057,7 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond,
             if (!cond) {
                 ast_unref(prev);
                 parseerror(parser, "internal error: failed to process condition");
-                return NULL;
+                return nullptr;
             }
             ifnot = !ifnot;
         }
@@ -2076,7 +2068,7 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond,
     while (cond && ast_istype(cond, ast_unary) && unary->op == INSTR_NOT_F)
     {
         cond = unary->operand;
-        unary->operand = NULL;
+        unary->operand = nullptr;
         ast_delete(unary);
         ifnot = !ifnot;
         unary = (ast_unary*)cond;
@@ -2092,7 +2084,7 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond,
 static bool parse_if(parser_t *parser, ast_block *block, ast_expression **out)
 {
     ast_ifthen *ifthen;
-    ast_expression *cond, *ontrue = NULL, *onfalse = NULL;
+    ast_expression *cond, *ontrue = nullptr, *onfalse = nullptr;
     bool ifnot = false;
 
     lex_ctx_t ctx = parser_ctx(parser);
@@ -2177,7 +2169,7 @@ static bool parse_while_go(parser_t *parser, ast_block *block, ast_expression **
 static bool parse_while(parser_t *parser, ast_block *block, ast_expression **out)
 {
     bool rv;
-    char *label = NULL;
+    char *label = nullptr;
 
     /* skip the 'while' and get the body */
     if (!parser_next(parser)) {
@@ -2218,7 +2210,7 @@ static bool parse_while(parser_t *parser, ast_block *block, ast_expression **out
         parseerror(parser, "internal error: label stack corrupted");
         rv = false;
         ast_delete(*out);
-        *out = NULL;
+        *out = nullptr;
     }
     else {
         parser->breaks.pop_back();
@@ -2269,7 +2261,7 @@ static bool parse_while_go(parser_t *parser, ast_block *block, ast_expression **
         ast_unref(ontrue);
         return false;
     }
-    aloop = ast_loop_new(ctx, NULL, cond, ifnot, NULL, false, NULL, ontrue);
+    aloop = ast_loop_new(ctx, nullptr, cond, ifnot, nullptr, false, nullptr, ontrue);
     *out = (ast_expression*)aloop;
     return true;
 }
@@ -2278,7 +2270,7 @@ static bool parse_dowhile_go(parser_t *parser, ast_block *block, ast_expression
 static bool parse_dowhile(parser_t *parser, ast_block *block, ast_expression **out)
 {
     bool rv;
-    char *label = NULL;
+    char *label = nullptr;
 
     /* skip the 'do' and get the body */
     if (!parser_next(parser)) {
@@ -2314,12 +2306,12 @@ static bool parse_dowhile(parser_t *parser, ast_block *block, ast_expression **o
         parseerror(parser, "internal error: label stack corrupted");
         rv = false;
         /*
-         * Test for NULL otherwise ast_delete dereferences null pointer
+         * Test for nullptr otherwise ast_delete dereferences null pointer
          * and boom.
          */
         if (*out)
             ast_delete(*out);
-        *out = NULL;
+        *out = nullptr;
     }
     else {
         parser->breaks.pop_back();
@@ -2394,7 +2386,7 @@ static bool parse_dowhile_go(parser_t *parser, ast_block *block, ast_expression
         ast_delete(ontrue);
         return false;
     }
-    aloop = ast_loop_new(ctx, NULL, NULL, false, cond, ifnot, NULL, ontrue);
+    aloop = ast_loop_new(ctx, nullptr, nullptr, false, cond, ifnot, nullptr, ontrue);
     *out = (ast_expression*)aloop;
     return true;
 }
@@ -2403,7 +2395,7 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou
 static bool parse_for(parser_t *parser, ast_block *block, ast_expression **out)
 {
     bool rv;
-    char *label = NULL;
+    char *label = nullptr;
 
     /* skip the 'for' and check for opening paren */
     if (!parser_next(parser)) {
@@ -2444,7 +2436,7 @@ static bool parse_for(parser_t *parser, ast_block *block, ast_expression **out)
         parseerror(parser, "internal error: label stack corrupted");
         rv = false;
         ast_delete(*out);
-        *out = NULL;
+        *out = nullptr;
     }
     else {
         parser->breaks.pop_back();
@@ -2464,10 +2456,10 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou
 
     parser_enterblock(parser);
 
-    initexpr  = NULL;
-    cond      = NULL;
-    increment = NULL;
-    ontrue    = NULL;
+    initexpr  = nullptr;
+    cond      = nullptr;
+    increment = nullptr;
+    ontrue    = nullptr;
 
     /* parse into the expression */
     if (!parser_next(parser)) {
@@ -2475,12 +2467,12 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou
         goto onerr;
     }
 
-    typevar = NULL;
+    typevar = nullptr;
     if (parser->tok == TOKEN_IDENT)
         typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
 
     if (typevar || parser->tok == TOKEN_TYPENAME) {
-        if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, NULL))
+        if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, nullptr))
             goto onerr;
     }
     else if (parser->tok != ';')
@@ -2548,7 +2540,7 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou
         if (!cond)
             goto onerr;
     }
-    aloop = ast_loop_new(ctx, initexpr, cond, ifnot, NULL, false, increment, ontrue);
+    aloop = ast_loop_new(ctx, initexpr, cond, ifnot, nullptr, false, increment, ontrue);
     *out = (ast_expression*)aloop;
 
     if (!parser_leaveblock(parser)) {
@@ -2566,11 +2558,11 @@ onerr:
 
 static bool parse_return(parser_t *parser, ast_block *block, ast_expression **out)
 {
-    ast_expression *exp      = NULL;
-    ast_expression *var      = NULL;
-    ast_return     *ret      = NULL;
+    ast_expression *exp      = nullptr;
+    ast_expression *var      = nullptr;
+    ast_return     *ret      = nullptr;
     ast_value      *retval   = parser->function->return_value;
-    ast_value      *expected = parser->function->vtype;
+    ast_value      *expected = parser->function->function_type;
 
     lex_ctx_t ctx = parser_ctx(parser);
 
@@ -2588,9 +2580,9 @@ static bool parse_return(parser_t *parser, ast_block *block, ast_expression **ou
             return false;
         }
 
-        if (type_store_instr[expected->expression.next->vtype] == VINSTR_END) {
+        if (type_store_instr[expected->next->vtype] == VINSTR_END) {
             char ty1[1024];
-            ast_type_to_string(expected->expression.next, ty1, sizeof(ty1));
+            ast_type_to_string(expected->next, ty1, sizeof(ty1));
             parseerror(parser, "invalid return type: `%s'", ty1);
             return false;
         }
@@ -2606,21 +2598,21 @@ static bool parse_return(parser_t *parser, ast_block *block, ast_expression **ou
         /* prepare the return value */
         if (!retval) {
             retval = ast_value_new(ctx, "#LOCAL_RETURN", TYPE_VOID);
-            ast_type_adopt(retval, expected->expression.next);
+            ast_type_adopt(retval, expected->next);
             parser->function->return_value = retval;
         }
 
         if (!ast_compare_type(exp, (ast_expression*)retval)) {
             char ty1[1024], ty2[1024];
             ast_type_to_string(exp, ty1, sizeof(ty1));
-            ast_type_to_string(&retval->expression, ty2, sizeof(ty2));
+            ast_type_to_string(retval, ty2, sizeof(ty2));
             parseerror(parser, "invalid type for return value: `%s', expected `%s'", ty1, ty2);
         }
 
         /* store to 'return' local variable */
         var = (ast_expression*)ast_store_new(
             ctx,
-            type_store_instr[expected->expression.next->vtype],
+            type_store_instr[expected->next->vtype],
             (ast_expression*)retval, exp);
 
         if (!var) {
@@ -2657,7 +2649,7 @@ static bool parse_return(parser_t *parser, ast_block *block, ast_expression **ou
         if (!parser_next(parser))
             parseerror(parser, "parse error");
 
-        if (!retval && expected->expression.next->vtype != TYPE_VOID)
+        if (!retval && expected->next->vtype != TYPE_VOID)
         {
             (void)!parsewarning(parser, WARN_MISSING_RETURN_VALUES, "return without value");
         }
@@ -2785,7 +2777,7 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool *
             }
             else if (!strcmp(parser_tokval(parser), "alias") && !(flags & AST_FLAG_ALIAS)) {
                 flags   |= AST_FLAG_ALIAS;
-                *message = NULL;
+                *message = nullptr;
 
                 if (!parser_next(parser)) {
                     parseerror(parser, "parse error in attribute");
@@ -2823,7 +2815,7 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool *
             }
             else if (!strcmp(parser_tokval(parser), "deprecated") && !(flags & AST_FLAG_DEPRECATED)) {
                 flags   |= AST_FLAG_DEPRECATED;
-                *message = NULL;
+                *message = nullptr;
 
                 if (!parser_next(parser)) {
                     parseerror(parser, "parse error in attribute");
@@ -2859,7 +2851,7 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool *
 
                     argerr: /* ugly */
                     if (*message) mem_d(*message);
-                    *message = NULL;
+                    *message = nullptr;
                     *cvq     = CV_WRONG;
                     return false;
                 }
@@ -2958,7 +2950,7 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression *
 static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **out)
 {
     bool rv;
-    char *label = NULL;
+    char *label = nullptr;
 
     /* skip the 'while' and get the body */
     if (!parser_next(parser)) {
@@ -2998,7 +2990,7 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou
         parseerror(parser, "internal error: label stack corrupted");
         rv = false;
         ast_delete(*out);
-        *out = NULL;
+        *out = nullptr;
     }
     else {
         parser->breaks.pop_back();
@@ -3058,23 +3050,23 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression *
     /* new block; allow some variables to be declared here */
     parser_enterblock(parser);
     while (true) {
-        typevar = NULL;
+        typevar = nullptr;
         if (parser->tok == TOKEN_IDENT)
             typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
         if (typevar || parser->tok == TOKEN_TYPENAME) {
-            if (!parse_variable(parser, block, true, CV_NONE, typevar, false, false, 0, NULL)) {
+            if (!parse_variable(parser, block, true, CV_NONE, typevar, false, false, 0, nullptr)) {
                 ast_delete(switchnode);
                 return false;
             }
             continue;
         }
-        if (parse_qualifiers(parser, true, &cvq, &noref, &is_static, &qflags, NULL))
+        if (parse_qualifiers(parser, true, &cvq, &noref, &is_static, &qflags, nullptr))
         {
             if (cvq == CV_WRONG) {
                 ast_delete(switchnode);
                 return false;
             }
-            if (!parse_variable(parser, block, true, cvq, NULL, noref, is_static, qflags, NULL)) {
+            if (!parse_variable(parser, block, true, cvq, nullptr, noref, is_static, qflags, nullptr)) {
                 ast_delete(switchnode);
                 return false;
             }
@@ -3108,7 +3100,7 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression *
             }
         }
         else if (!strcmp(parser_tokval(parser), "default")) {
-            swcase.value = NULL;
+            swcase.value = nullptr;
             if (!parser_next(parser)) {
                 ast_delete(switchnode);
                 parseerror(parser, "expected colon");
@@ -3191,7 +3183,7 @@ static ast_expression *parse_goto_computed(parser_t *parser, ast_expression **si
     ast_expression *cond;
 
     if (!*side)
-        return NULL;
+        return nullptr;
 
     if (ast_istype(*side, ast_ternary)) {
         ast_ternary *tern = (ast_ternary*)*side;
@@ -3202,26 +3194,26 @@ static ast_expression *parse_goto_computed(parser_t *parser, ast_expression **si
             parseerror(parser, "expected label or expression in ternary");
             if (on_true) ast_unref(on_true);
             if (on_false) ast_unref(on_false);
-            return NULL;
+            return nullptr;
         }
 
         cond = tern->cond;
-        tern->cond = NULL;
+        tern->cond = nullptr;
         ast_delete(tern);
-        *side = NULL;
+        *side = nullptr;
         return (ast_expression*)ast_ifthen_new(parser_ctx(parser), cond, on_true, on_false);
     } else if (ast_istype(*side, ast_label)) {
         ast_goto *gt = ast_goto_new(parser_ctx(parser), ((ast_label*)*side)->name);
         ast_goto_set_label(gt, ((ast_label*)*side));
-        *side = NULL;
+        *side = nullptr;
         return (ast_expression*)gt;
     }
-    return NULL;
+    return nullptr;
 }
 
 static bool parse_goto(parser_t *parser, ast_expression **out)
 {
-    ast_goto       *gt = NULL;
+    ast_goto       *gt = nullptr;
     ast_expression *lbl;
 
     if (!parser_next(parser))
@@ -3355,10 +3347,10 @@ static bool parse_statement(parser_t *parser, ast_block *block, ast_expression *
     bool       noref, is_static;
     int        cvq     = CV_NONE;
     uint32_t   qflags  = 0;
-    ast_value *typevar = NULL;
-    char      *vstring = NULL;
+    ast_value *typevar = nullptr;
+    char      *vstring = nullptr;
 
-    *out = NULL;
+    *out = nullptr;
 
     if (parser->tok == TOKEN_IDENT)
         typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
@@ -3374,7 +3366,7 @@ static bool parse_statement(parser_t *parser, ast_block *block, ast_expression *
             if (parsewarning(parser, WARN_EXTENSIONS, "missing 'local' keyword when declaring a local variable"))
                 return false;
         }
-        if (!parse_variable(parser, block, false, CV_NONE, typevar, false, false, 0, NULL))
+        if (!parse_variable(parser, block, false, CV_NONE, typevar, false, false, 0, nullptr))
             return false;
         return true;
     }
@@ -3382,7 +3374,7 @@ static bool parse_statement(parser_t *parser, ast_block *block, ast_expression *
     {
         if (cvq == CV_WRONG)
             return false;
-        return parse_variable(parser, block, false, cvq, NULL, noref, is_static, qflags, vstring);
+        return parse_variable(parser, block, false, cvq, nullptr, noref, is_static, qflags, vstring);
     }
     else if (parser->tok == TOKEN_KEYWORD)
     {
@@ -3554,8 +3546,8 @@ static bool parse_enum(parser_t *parser)
     bool        flag = false;
     bool        reverse = false;
     qcfloat_t     num = 0;
-    ast_value **values = NULL;
-    ast_value  *var = NULL;
+    ast_value **values = nullptr;
+    ast_value  *var = nullptr;
     ast_value  *asvalue;
 
     ast_expression *old;
@@ -3698,26 +3690,26 @@ static bool parse_block_into(parser_t *parser, ast_block *block)
 
     while (parser->tok != TOKEN_EOF && parser->tok < TOKEN_ERROR)
     {
-        ast_expression *expr = NULL;
+        ast_expression *expr = nullptr;
         if (parser->tok == '}')
             break;
 
         if (!parse_statement(parser, block, &expr, false)) {
             /* parseerror(parser, "parse error"); */
-            block = NULL;
+            block = nullptr;
             goto cleanup;
         }
         if (!expr)
             continue;
         if (!ast_block_add_expr(block, expr)) {
             ast_delete(block);
-            block = NULL;
+            block = nullptr;
             goto cleanup;
         }
     }
 
     if (parser->tok != '}') {
-        block = NULL;
+        block = nullptr;
     } else {
         (void)parser_next(parser);
     }
@@ -3733,10 +3725,10 @@ static ast_block* parse_block(parser_t *parser)
     ast_block *block;
     block = ast_block_new(parser_ctx(parser));
     if (!block)
-        return NULL;
+        return nullptr;
     if (!parse_block_into(parser, block)) {
         ast_block_delete(block);
-        return NULL;
+        return nullptr;
     }
     return block;
 }
@@ -3747,7 +3739,7 @@ static bool parse_statement_or_block(parser_t *parser, ast_expression **out)
         *out = (ast_expression*)parse_block(parser);
         return !!*out;
     }
-    return parse_statement(parser, NULL, out, false);
+    return parse_statement(parser, nullptr, out, false);
 }
 
 static bool create_vector_members(ast_value *var, ast_member **me)
@@ -3776,15 +3768,15 @@ static bool create_vector_members(ast_value *var, ast_member **me)
 
 static bool parse_function_body(parser_t *parser, ast_value *var)
 {
-    ast_block *block = NULL;
+    ast_block *block = nullptr;
     ast_function *func;
     ast_function *old;
 
-    ast_expression *framenum  = NULL;
-    ast_expression *nextthink = NULL;
+    ast_expression *framenum  = nullptr;
+    ast_expression *nextthink = nullptr;
     /* None of the following have to be deleted */
-    ast_expression *fld_think = NULL, *fld_nextthink = NULL, *fld_frame = NULL;
-    ast_expression *gbl_time = NULL, *gbl_self = NULL;
+    ast_expression *fld_think = nullptr, *fld_nextthink = nullptr, *fld_frame = nullptr;
+    ast_expression *gbl_time = nullptr, *gbl_self = nullptr;
     bool has_frame_think;
 
     bool retval = true;
@@ -3792,7 +3784,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
     has_frame_think = false;
     old = parser->function;
 
-    if (var->expression.flags & AST_FLAG_ALIAS) {
+    if (var->flags & AST_FLAG_ALIAS) {
         parseerror(parser, "function aliases cannot have bodies");
         return false;
     }
@@ -3802,7 +3794,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
         return false;
     }
 
-    if (!OPTS_FLAG(VARIADIC_ARGS) && var->expression.flags & AST_FLAG_VARIADIC) {
+    if (!OPTS_FLAG(VARIADIC_ARGS) && var->flags & AST_FLAG_VARIADIC) {
         if (parsewarning(parser, WARN_VARIADIC_FUNCTION,
                          "variadic function with implementation will not be able to access additional parameters (try -fvariadic-args)"))
         {
@@ -3817,7 +3809,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
          * self.nextthink = time + 0.1;
          * self.think = nextthink;
          */
-        nextthink = NULL;
+        nextthink = nullptr;
 
         fld_think     = parser_find_field(parser, "think");
         fld_nextthink = parser_find_field(parser, "nextthink");
@@ -3962,7 +3954,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
             self_think     = (ast_expression*)ast_entfield_new(ctx, gbl_self, fld_think);
 
             time_plus_1    = (ast_expression*)ast_binary_new(ctx, INSTR_ADD_F,
-                             gbl_time, (ast_expression*)fold_constgen_float(parser->fold, frame_delta, false));
+                             gbl_time, (ast_expression*)parser->m_fold.constgen_float(frame_delta, false));
 
             if (!self_frame || !self_nextthink || !self_think || !time_plus_1) {
                 if (self_frame)     ast_delete(self_frame);
@@ -4015,7 +4007,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
     }
 
     if (var->hasvalue) {
-        if (!(var->expression.flags & AST_FLAG_ACCUMULATE)) {
+        if (!(var->flags & AST_FLAG_ACCUMULATE)) {
             parseerror(parser, "function `%s` declared with multiple bodies", var->name);
             ast_block_delete(block);
             goto enderr;
@@ -4023,7 +4015,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
         func = var->constval.vfunc;
 
         if (!func) {
-            parseerror(parser, "internal error: NULL function: `%s`", var->name);
+            parseerror(parser, "internal error: nullptr function: `%s`", var->name);
             ast_block_delete(block);
             goto enderr;
         }
@@ -4040,13 +4032,13 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
 
     parser_enterblock(parser);
 
-    for (auto &it : var->expression.params) {
+    for (auto &it : var->type_params) {
         size_t e;
         ast_member *me[3];
 
-        if (it->expression.vtype != TYPE_VECTOR &&
-            (it->expression.vtype != TYPE_FIELD ||
-             it->expression.next->vtype != TYPE_VECTOR))
+        if (it->vtype != TYPE_VECTOR &&
+            (it->vtype != TYPE_FIELD ||
+             it->next->vtype != TYPE_VECTOR))
         {
             continue;
         }
@@ -4068,12 +4060,12 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
         func->argc = argc;
     }
 
-    if (OPTS_FLAG(VARIADIC_ARGS) && var->expression.flags & AST_FLAG_VARIADIC && !func->varargs) {
+    if (OPTS_FLAG(VARIADIC_ARGS) && var->flags & AST_FLAG_VARIADIC && !func->varargs) {
         char name[1024];
         ast_value *varargs = ast_value_new(ast_ctx(var), "reserved:va_args", TYPE_ARRAY);
-        varargs->expression.flags |= AST_FLAG_IS_VARARG;
-        varargs->expression.next = (ast_expression*)ast_value_new(ast_ctx(var), NULL, TYPE_VECTOR);
-        varargs->expression.count = 0;
+        varargs->flags |= AST_FLAG_IS_VARARG;
+        varargs->next = (ast_expression*)ast_value_new(ast_ctx(var), nullptr, TYPE_VECTOR);
+        varargs->count = 0;
         util_snprintf(name, sizeof(name), "%s##va##SET", var->name);
         if (!parser_create_array_setter_proto(parser, varargs, name)) {
             ast_delete(varargs);
@@ -4081,13 +4073,13 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
             goto enderrfn;
         }
         util_snprintf(name, sizeof(name), "%s##va##GET", var->name);
-        if (!parser_create_array_getter_proto(parser, varargs, varargs->expression.next, name)) {
+        if (!parser_create_array_getter_proto(parser, varargs, varargs->next, name)) {
             ast_delete(varargs);
             ast_block_delete(block);
             goto enderrfn;
         }
         func->varargs     = varargs;
-        func->fixedparams = (ast_value*)fold_constgen_float(parser->fold, var->expression.params.size(), false);
+        func->fixedparams = (ast_value*)parser->m_fold.constgen_float(var->type_params.size(), false);
     }
 
     parser->function = func;
@@ -4096,7 +4088,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
         goto enderrfn;
     }
 
-    func->blocks.push_back(block);
+    func->blocks.emplace_back(block);
 
     parser->function = old;
     if (!parser_leaveblock(parser))
@@ -4116,7 +4108,7 @@ enderrfn:
     (void)!parser_leaveblock(parser);
     parser->functions.pop_back();
     ast_function_delete(func);
-    var->constval.vfunc = NULL;
+    var->constval.vfunc = nullptr;
 
 enderr:
     parser->function = old;
@@ -4140,24 +4132,24 @@ static ast_expression *array_accessor_split(
     if (!left || !right) {
         if (left)  ast_delete(left);
         if (right) ast_delete(right);
-        return NULL;
+        return nullptr;
     }
 
     cmp = ast_binary_new(ctx, INSTR_LT,
                          (ast_expression*)index,
-                         (ast_expression*)fold_constgen_float(parser->fold, middle, false));
+                         (ast_expression*)parser->m_fold.constgen_float(middle, false));
     if (!cmp) {
         ast_delete(left);
         ast_delete(right);
         parseerror(parser, "internal error: failed to create comparison for array setter");
-        return NULL;
+        return nullptr;
     }
 
     ifthen = ast_ifthen_new(ctx, (ast_expression*)cmp, left, right);
     if (!ifthen) {
         ast_delete(cmp); /* will delete left and right */
         parseerror(parser, "internal error: failed to create conditional jump for array setter");
-        return NULL;
+        return nullptr;
     }
 
     return (ast_expression*)ifthen;
@@ -4173,41 +4165,41 @@ static ast_expression *array_setter_node(parser_t *parser, ast_value *array, ast
         ast_return      *ret;
         ast_array_index *subscript;
         ast_store       *st;
-        int assignop = type_store_instr[value->expression.vtype];
+        int assignop = type_store_instr[value->vtype];
 
-        if (value->expression.vtype == TYPE_FIELD && value->expression.next->vtype == TYPE_VECTOR)
+        if (value->vtype == TYPE_FIELD && value->next->vtype == TYPE_VECTOR)
             assignop = INSTR_STORE_V;
 
-        subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false));
+        subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)parser->m_fold.constgen_float(from, false));
         if (!subscript)
-            return NULL;
+            return nullptr;
 
         st = ast_store_new(ctx, assignop, (ast_expression*)subscript, (ast_expression*)value);
         if (!st) {
             ast_delete(subscript);
-            return NULL;
+            return nullptr;
         }
 
         block = ast_block_new(ctx);
         if (!block) {
             ast_delete(st);
-            return NULL;
+            return nullptr;
         }
 
         if (!ast_block_add_expr(block, (ast_expression*)st)) {
             ast_delete(block);
-            return NULL;
+            return nullptr;
         }
 
-        ret = ast_return_new(ctx, NULL);
+        ret = ast_return_new(ctx, nullptr);
         if (!ret) {
             ast_delete(block);
-            return NULL;
+            return nullptr;
         }
 
         if (!ast_block_add_expr(block, (ast_expression*)ret)) {
             ast_delete(block);
-            return NULL;
+            return nullptr;
         }
 
         return (ast_expression*)block;
@@ -4239,17 +4231,17 @@ static ast_expression *array_field_setter_node(
         ast_entfield    *entfield;
         ast_array_index *subscript;
         ast_store       *st;
-        int assignop = type_storep_instr[value->expression.vtype];
+        int assignop = type_storep_instr[value->vtype];
 
-        if (value->expression.vtype == TYPE_FIELD && value->expression.next->vtype == TYPE_VECTOR)
+        if (value->vtype == TYPE_FIELD && value->next->vtype == TYPE_VECTOR)
             assignop = INSTR_STOREP_V;
 
-        subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false));
+        subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)parser->m_fold.constgen_float(from, false));
         if (!subscript)
-            return NULL;
+            return nullptr;
 
-        subscript->expression.next = ast_type_copy(ast_ctx(subscript), (ast_expression*)subscript);
-        subscript->expression.vtype = TYPE_FIELD;
+        subscript->next = ast_type_copy(ast_ctx(subscript), (ast_expression*)subscript);
+        subscript->vtype = TYPE_FIELD;
 
         entfield = ast_entfield_new_force(ctx,
                                           (ast_expression*)entity,
@@ -4257,35 +4249,35 @@ static ast_expression *array_field_setter_node(
                                           (ast_expression*)subscript);
         if (!entfield) {
             ast_delete(subscript);
-            return NULL;
+            return nullptr;
         }
 
         st = ast_store_new(ctx, assignop, (ast_expression*)entfield, (ast_expression*)value);
         if (!st) {
             ast_delete(entfield);
-            return NULL;
+            return nullptr;
         }
 
         block = ast_block_new(ctx);
         if (!block) {
             ast_delete(st);
-            return NULL;
+            return nullptr;
         }
 
         if (!ast_block_add_expr(block, (ast_expression*)st)) {
             ast_delete(block);
-            return NULL;
+            return nullptr;
         }
 
-        ret = ast_return_new(ctx, NULL);
+        ret = ast_return_new(ctx, nullptr);
         if (!ret) {
             ast_delete(block);
-            return NULL;
+            return nullptr;
         }
 
         if (!ast_block_add_expr(block, (ast_expression*)ret)) {
             ast_delete(block);
-            return NULL;
+            return nullptr;
         }
 
         return (ast_expression*)block;
@@ -4307,14 +4299,14 @@ static ast_expression *array_getter_node(parser_t *parser, ast_value *array, ast
         ast_return      *ret;
         ast_array_index *subscript;
 
-        subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false));
+        subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)parser->m_fold.constgen_float(from, false));
         if (!subscript)
-            return NULL;
+            return nullptr;
 
         ret = ast_return_new(ctx, (ast_expression*)subscript);
         if (!ret) {
             ast_delete(subscript);
-            return NULL;
+            return nullptr;
         }
 
         return (ast_expression*)ret;
@@ -4330,16 +4322,16 @@ static ast_expression *array_getter_node(parser_t *parser, ast_value *array, ast
 
 static bool parser_create_array_accessor(parser_t *parser, ast_value *array, const char *funcname, ast_value **out)
 {
-    ast_function   *func = NULL;
-    ast_value      *fval = NULL;
-    ast_block      *body = NULL;
+    ast_function   *func = nullptr;
+    ast_value      *fval = nullptr;
+    ast_block      *body = nullptr;
 
     fval = ast_value_new(ast_ctx(array), funcname, TYPE_FUNCTION);
     if (!fval) {
         parseerror(parser, "failed to create accessor function value");
         return false;
     }
-    fval->expression.flags &= ~(AST_FLAG_COVERAGE_MASK);
+    fval->flags &= ~(AST_FLAG_COVERAGE_MASK);
 
     func = ast_function_new(ast_ctx(array), funcname, fval);
     if (!func) {
@@ -4356,7 +4348,7 @@ static bool parser_create_array_accessor(parser_t *parser, ast_value *array, con
         return false;
     }
 
-    func->blocks.push_back(body);
+    func->blocks.emplace_back(body);
     *out = fval;
 
     parser->accessors.push_back(fval);
@@ -4366,31 +4358,31 @@ static bool parser_create_array_accessor(parser_t *parser, ast_value *array, con
 
 static ast_value* parser_create_array_setter_proto(parser_t *parser, ast_value *array, const char *funcname)
 {
-    ast_value      *index = NULL;
-    ast_value      *value = NULL;
+    ast_value      *index = nullptr;
+    ast_value      *value = nullptr;
     ast_function   *func;
     ast_value      *fval;
 
-    if (!ast_istype(array->expression.next, ast_value)) {
+    if (!ast_istype(array->next, ast_value)) {
         parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type");
-        return NULL;
+        return nullptr;
     }
 
     if (!parser_create_array_accessor(parser, array, funcname, &fval))
-        return NULL;
+        return nullptr;
     func = fval->constval.vfunc;
-    fval->expression.next = (ast_expression*)ast_value_new(ast_ctx(array), "<void>", TYPE_VOID);
+    fval->next = (ast_expression*)ast_value_new(ast_ctx(array), "<void>", TYPE_VOID);
 
     index = ast_value_new(ast_ctx(array), "index", TYPE_FLOAT);
-    value = ast_value_copy((ast_value*)array->expression.next);
+    value = ast_value_copy((ast_value*)array->next);
 
     if (!index || !value) {
         parseerror(parser, "failed to create locals for array accessor");
         goto cleanup;
     }
     (void)!ast_value_set_name(value, "value"); /* not important */
-    fval->expression.params.push_back(index);
-    fval->expression.params.push_back(value);
+    fval->type_params.push_back(index);
+    fval->type_params.push_back(value);
 
     array->setter = fval;
     return fval;
@@ -4399,21 +4391,21 @@ cleanup:
     if (value) ast_delete(value);
     ast_delete(func);
     ast_delete(fval);
-    return NULL;
+    return nullptr;
 }
 
 static bool parser_create_array_setter_impl(parser_t *parser, ast_value *array)
 {
-    ast_expression *root = NULL;
+    ast_expression *root = nullptr;
     root = array_setter_node(parser, array,
-                             array->setter->expression.params[0],
-                             array->setter->expression.params[1],
-                             0, array->expression.count);
+                             array->setter->type_params[0],
+                             array->setter->type_params[1],
+                             0, array->count);
     if (!root) {
         parseerror(parser, "failed to build accessor search tree");
         return false;
     }
-    if (!ast_block_add_expr(array->setter->constval.vfunc->blocks[0], root)) {
+    if (!ast_block_add_expr(array->setter->constval.vfunc->blocks[0].get(), root)) {
         ast_delete(root);
         return false;
     }
@@ -4429,14 +4421,14 @@ static bool parser_create_array_setter(parser_t *parser, ast_value *array, const
 
 static bool parser_create_array_field_setter(parser_t *parser, ast_value *array, const char *funcname)
 {
-    ast_expression *root = NULL;
-    ast_value      *entity = NULL;
-    ast_value      *index = NULL;
-    ast_value      *value = NULL;
+    ast_expression *root = nullptr;
+    ast_value      *entity = nullptr;
+    ast_value      *index = nullptr;
+    ast_value      *value = nullptr;
     ast_function   *func;
     ast_value      *fval;
 
-    if (!ast_istype(array->expression.next, ast_value)) {
+    if (!ast_istype(array->next, ast_value)) {
         parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type");
         return false;
     }
@@ -4444,28 +4436,28 @@ static bool parser_create_array_field_setter(parser_t *parser, ast_value *array,
     if (!parser_create_array_accessor(parser, array, funcname, &fval))
         return false;
     func = fval->constval.vfunc;
-    fval->expression.next = (ast_expression*)ast_value_new(ast_ctx(array), "<void>", TYPE_VOID);
+    fval->next = (ast_expression*)ast_value_new(ast_ctx(array), "<void>", TYPE_VOID);
 
     entity = ast_value_new(ast_ctx(array), "entity", TYPE_ENTITY);
     index  = ast_value_new(ast_ctx(array), "index",  TYPE_FLOAT);
-    value  = ast_value_copy((ast_value*)array->expression.next);
+    value  = ast_value_copy((ast_value*)array->next);
     if (!entity || !index || !value) {
         parseerror(parser, "failed to create locals for array accessor");
         goto cleanup;
     }
     (void)!ast_value_set_name(value, "value"); /* not important */
-    fval->expression.params.push_back(entity);
-    fval->expression.params.push_back(index);
-    fval->expression.params.push_back(value);
+    fval->type_params.push_back(entity);
+    fval->type_params.push_back(index);
+    fval->type_params.push_back(value);
 
-    root = array_field_setter_node(parser, array, entity, index, value, 0, array->expression.count);
+    root = array_field_setter_node(parser, array, entity, index, value, 0, array->count);
     if (!root) {
         parseerror(parser, "failed to build accessor search tree");
         goto cleanup;
     }
 
     array->setter = fval;
-    return ast_block_add_expr(func->blocks[0], root);
+    return ast_block_add_expr(func->blocks[0].get(), root);
 cleanup:
     if (entity) ast_delete(entity);
     if (index)  ast_delete(index);
@@ -4478,22 +4470,22 @@ cleanup:
 
 static ast_value* parser_create_array_getter_proto(parser_t *parser, ast_value *array, const ast_expression *elemtype, const char *funcname)
 {
-    ast_value      *index = NULL;
+    ast_value      *index = nullptr;
     ast_value      *fval;
     ast_function   *func;
 
-    /* NOTE: checking array->expression.next rather than elemtype since
+    /* NOTE: checking array->next rather than elemtype since
      * for fields elemtype is a temporary fieldtype.
      */
-    if (!ast_istype(array->expression.next, ast_value)) {
+    if (!ast_istype(array->next, ast_value)) {
         parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type");
-        return NULL;
+        return nullptr;
     }
 
     if (!parser_create_array_accessor(parser, array, funcname, &fval))
-        return NULL;
+        return nullptr;
     func = fval->constval.vfunc;
-    fval->expression.next = ast_type_copy(ast_ctx(array), elemtype);
+    fval->next = ast_type_copy(ast_ctx(array), elemtype);
 
     index = ast_value_new(ast_ctx(array), "index", TYPE_FLOAT);
 
@@ -4501,7 +4493,7 @@ static ast_value* parser_create_array_getter_proto(parser_t *parser, ast_value *
         parseerror(parser, "failed to create locals for array accessor");
         goto cleanup;
     }
-    fval->expression.params.push_back(index);
+    fval->type_params.push_back(index);
 
     array->getter = fval;
     return fval;
@@ -4509,19 +4501,19 @@ cleanup:
     if (index) ast_delete(index);
     ast_delete(func);
     ast_delete(fval);
-    return NULL;
+    return nullptr;
 }
 
 static bool parser_create_array_getter_impl(parser_t *parser, ast_value *array)
 {
-    ast_expression *root = NULL;
+    ast_expression *root = nullptr;
 
-    root = array_getter_node(parser, array, array->getter->expression.params[0], 0, array->expression.count);
+    root = array_getter_node(parser, array, array->getter->type_params[0], 0, array->count);
     if (!root) {
         parseerror(parser, "failed to build accessor search tree");
         return false;
     }
-    if (!ast_block_add_expr(array->getter->constval.vfunc->blocks[0], root)) {
+    if (!ast_block_add_expr(array->getter->constval.vfunc->blocks[0].get(), root)) {
         ast_delete(root);
         return false;
     }
@@ -4542,14 +4534,14 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
     ast_value *fval;
     bool first = true;
     bool variadic = false;
-    ast_value *varparam = NULL;
-    char *argcounter = NULL;
+    ast_value *varparam = nullptr;
+    char *argcounter = nullptr;
 
     /* for the sake of less code we parse-in in this function */
     if (!parser_next(parser)) {
         ast_delete(var);
         parseerror(parser, "expected parameter list");
-        return NULL;
+        return nullptr;
     }
 
     /* parse variables until we hit a closing paren */
@@ -4569,7 +4561,7 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
         }
         first = false;
 
-        ast_value *param = parse_typename(parser, NULL, NULL, &is_varargs);
+        ast_value *param = parse_typename(parser, nullptr, nullptr, &is_varargs);
         if (!param && !is_varargs)
             goto on_error;
         if (is_varargs) {
@@ -4588,7 +4580,7 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
             }
         } else {
             params.push_back(param);
-            if (param->expression.vtype >= TYPE_VARIANT) {
+            if (param->vtype >= TYPE_VARIANT) {
                 char tname[1024]; /* typename is reserved in C++ */
                 ast_type_to_string((ast_expression*)param, tname, sizeof(tname));
                 parseerror(parser, "type not supported as part of a parameter list: %s", tname);
@@ -4619,7 +4611,7 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
         }
     }
 
-    if (params.size() == 1 && params[0]->expression.vtype == TYPE_VOID)
+    if (params.size() == 1 && params[0]->vtype == TYPE_VOID)
         params.clear();
 
     /* sanity check */
@@ -4634,13 +4626,13 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
 
     /* now turn 'var' into a function type */
     fval = ast_value_new(ctx, "<type()>", TYPE_FUNCTION);
-    fval->expression.next = (ast_expression*)var;
+    fval->next = (ast_expression*)var;
     if (variadic)
-        fval->expression.flags |= AST_FLAG_VARIADIC;
+        fval->flags |= AST_FLAG_VARIADIC;
     var = fval;
 
-    var->expression.params = params;
-    var->expression.varparam = (ast_expression*)varparam;
+    var->type_params = move(params);
+    var->varparam = (ast_expression*)varparam;
     var->argcounter = argcounter;
 
     return var;
@@ -4653,7 +4645,7 @@ on_error:
     ast_delete(var);
     for (auto &it : params)
         ast_delete(it);
-    return NULL;
+    return nullptr;
 }
 
 static ast_value *parse_arraysize(parser_t *parser, ast_value *var)
@@ -4667,7 +4659,7 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var)
     if (!parser_next(parser)) {
         ast_delete(var);
         parseerror(parser, "expected array-size");
-        return NULL;
+        return nullptr;
     }
 
     if (parser->tok != ']') {
@@ -4678,58 +4670,58 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var)
                 ast_unref(cexp);
             ast_delete(var);
             parseerror(parser, "expected array-size as constant positive integer");
-            return NULL;
+            return nullptr;
         }
         cval = (ast_value*)cexp;
     }
     else {
-        cexp = NULL;
-        cval = NULL;
+        cexp = nullptr;
+        cval = nullptr;
     }
 
     tmp = ast_value_new(ctx, "<type[]>", TYPE_ARRAY);
-    tmp->expression.next = (ast_expression*)var;
+    tmp->next = (ast_expression*)var;
     var = tmp;
 
     if (cval) {
-        if (cval->expression.vtype == TYPE_INTEGER)
-            tmp->expression.count = cval->constval.vint;
-        else if (cval->expression.vtype == TYPE_FLOAT)
-            tmp->expression.count = cval->constval.vfloat;
+        if (cval->vtype == TYPE_INTEGER)
+            tmp->count = cval->constval.vint;
+        else if (cval->vtype == TYPE_FLOAT)
+            tmp->count = cval->constval.vfloat;
         else {
             ast_unref(cexp);
             ast_delete(var);
             parseerror(parser, "array-size must be a positive integer constant");
-            return NULL;
+            return nullptr;
         }
 
         ast_unref(cexp);
     } else {
-        var->expression.count = -1;
-        var->expression.flags |= AST_FLAG_ARRAY_INIT;
+        var->count = -1;
+        var->flags |= AST_FLAG_ARRAY_INIT;
     }
 
     if (parser->tok != ']') {
         ast_delete(var);
         parseerror(parser, "expected ']' after array-size");
-        return NULL;
+        return nullptr;
     }
     if (!parser_next(parser)) {
         ast_delete(var);
         parseerror(parser, "error after parsing array size");
-        return NULL;
+        return nullptr;
     }
     return var;
 }
 
 /* Parse a complete typename.
- * for single-variables (ie. function parameters or typedefs) storebase should be NULL
+ * for single-variables (ie. function parameters or typedefs) storebase should be nullptr
  * but when parsing variables separated by comma
  * 'storebase' should point to where the base-type should be kept.
  * The base type makes up every bit of type information which comes *before* the
  * variable name.
  *
- * NOTE: The value must either be named, have a NULL name, or a name starting
+ * NOTE: The value must either be named, have a nullptr name, or a name starting
  *       with '<'. In the first case, this will be the actual variable or type
  *       name, in the other cases it is assumed that the name will appear
  *       later, and an error is generated otherwise.
@@ -4746,7 +4738,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
     ast_value *var, *tmp;
     lex_ctx_t    ctx;
 
-    const char *name = NULL;
+    const char *name = nullptr;
     bool        isfield  = false;
     bool        wasarray = false;
     size_t      morefields = 0;
@@ -4763,7 +4755,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
         /* if we parsed a dot we need a typename now */
         if (!parser_next(parser)) {
             parseerror(parser, "expected typename for field definition");
-            return NULL;
+            return nullptr;
         }
 
         /* Further dots are handled seperately because they won't be part of the
@@ -4779,7 +4771,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
             vararg = false;
             if (!parser_next(parser)) {
                 parseerror(parser, "expected typename for field definition");
-                return NULL;
+                return nullptr;
             }
         }
     }
@@ -4788,10 +4780,10 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
     if (!cached_typedef && parser->tok != TOKEN_TYPENAME) {
         if (vararg && is_vararg) {
             *is_vararg = true;
-            return NULL;
+            return nullptr;
         }
         parseerror(parser, "expected typename");
-        return NULL;
+        return nullptr;
     }
 
     /* generate the basic type value */
@@ -4803,7 +4795,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
 
     for (; morefields; --morefields) {
         tmp = ast_value_new(ctx, "<.type>", TYPE_FIELD);
-        tmp->expression.next = (ast_expression*)var;
+        tmp->next = (ast_expression*)var;
         var = tmp;
     }
 
@@ -4816,7 +4808,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
     if (!parser_next(parser)) {
         ast_delete(var);
         parseerror(parser, "parse error after typename");
-        return NULL;
+        return nullptr;
     }
 
     /* an opening paren now starts the parameter-list of a function
@@ -4827,7 +4819,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
     if (parser->tok == '(') {
         var = parse_parameter_list(parser, var);
         if (!var)
-            return NULL;
+            return nullptr;
     }
 
     /* store the base if requested */
@@ -4835,7 +4827,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
         *storebase = ast_value_copy(var);
         if (isfield) {
             tmp = ast_value_new(ctx, "<type:f>", TYPE_FIELD);
-            tmp->expression.next = (ast_expression*)*storebase;
+            tmp->next = (ast_expression*)*storebase;
             *storebase = tmp;
         }
     }
@@ -4854,7 +4846,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
             ast_delete(var);
             mem_d(name);
             parseerror(parser, "error after variable or field declaration");
-            return NULL;
+            return nullptr;
         }
     }
 
@@ -4865,7 +4857,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
         var = parse_arraysize(parser, var);
         if (!var) {
             if (name) mem_d(name);
-            return NULL;
+            return nullptr;
         }
     }
 
@@ -4873,7 +4865,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
     if (isfield) {
         /* turn it into a field if desired */
         tmp = ast_value_new(ctx, "<type:f>", TYPE_FIELD);
-        tmp->expression.next = (ast_expression*)var;
+        tmp->next = (ast_expression*)var;
         var = tmp;
     }
 
@@ -4886,7 +4878,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
         var = parse_parameter_list(parser, var);
         if (!var) {
             if (name) mem_d(name);
-            return NULL;
+            return nullptr;
         }
     }
 
@@ -4896,7 +4888,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
             ast_delete(var);
             mem_d(name);
             parseerror(parser, "internal error: failed to set name");
-            return NULL;
+            return nullptr;
         }
         /* free the name, ast_value_set_name duplicates */
         mem_d(name);
@@ -4910,7 +4902,7 @@ static bool parse_typedef(parser_t *parser)
     ast_value      *typevar, *oldtype;
     ast_expression *old;
 
-    typevar = parse_typename(parser, NULL, NULL, NULL);
+    typevar = parse_typename(parser, nullptr, nullptr, nullptr);
 
     if (!typevar)
         return false;
@@ -4977,8 +4969,8 @@ static bool parser_check_qualifiers(parser_t *parser, const ast_value *var, cons
                                  cvq_to_str(proto->cvq));
         }
     }
-    av = (var  ->expression.flags & AST_FLAG_NORETURN);
-    ao = (proto->expression.flags & AST_FLAG_NORETURN);
+    av = (var  ->flags & AST_FLAG_NORETURN);
+    ao = (proto->flags & AST_FLAG_NORETURN);
     if (!av != !ao) {
         return !parsewarning(parser, WARN_DIFFERENT_ATTRIBUTES,
                              "`%s` declared with different attributes%s\n"
@@ -4997,7 +4989,7 @@ static bool create_array_accessors(parser_t *parser, ast_value *var)
     if (!parser_create_array_setter(parser, var, name))
         return false;
     util_snprintf(name, sizeof(name), "%s##GET", var->name);
-    if (!parser_create_array_getter(parser, var, var->expression.next, name))
+    if (!parser_create_array_getter(parser, var, var->next, name))
         return false;
     return true;
 }
@@ -5024,7 +5016,7 @@ static bool parse_array(parser_t *parser, ast_value *array)
             return false;
         }
         array->initlist.push_back(v->constval);
-        if (v->expression.vtype == TYPE_STRING) {
+        if (v->vtype == TYPE_STRING) {
             array->initlist[i].vstring = util_strdupe(array->initlist[i].vstring);
             ++i;
         }
@@ -5047,12 +5039,12 @@ static bool parse_array(parser_t *parser, ast_value *array)
     }
     */
 
-    if (array->expression.flags & AST_FLAG_ARRAY_INIT) {
-        if (array->expression.count != (size_t)-1) {
+    if (array->flags & AST_FLAG_ARRAY_INIT) {
+        if (array->count != (size_t)-1) {
             parseerror(parser, "array `%s' has already been initialized with %u elements",
-                       array->name, (unsigned)array->expression.count);
+                       array->name, (unsigned)array->count);
         }
-        array->expression.count = array->initlist.size();
+        array->count = array->initlist.size();
         if (!create_array_accessors(parser, array))
             return false;
     }
@@ -5067,21 +5059,21 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
     bool       was_end;
     size_t     i;
 
-    ast_value *basetype = NULL;
+    ast_value *basetype = nullptr;
     bool      retval    = true;
     bool      isparam   = false;
     bool      isvector  = false;
     bool      cleanvar  = true;
     bool      wasarray  = false;
 
-    ast_member *me[3] = { NULL, NULL, NULL };
-    ast_member *last_me[3] = { NULL, NULL, NULL };
+    ast_member *me[3] = { nullptr, nullptr, nullptr };
+    ast_member *last_me[3] = { nullptr, nullptr, nullptr };
 
     if (!localblock && is_static)
         parseerror(parser, "`static` qualifier is not supported in global scope");
 
     /* get the first complete variable */
-    var = parse_typename(parser, &basetype, cached_typedef, NULL);
+    var = parse_typename(parser, &basetype, cached_typedef, nullptr);
     if (!var) {
         if (basetype)
             ast_delete(basetype);
@@ -5097,7 +5089,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
     }
 
     while (true) {
-        proto = NULL;
+        proto = nullptr;
         wasarray = false;
 
         /* Part 0: finish the type */
@@ -5136,18 +5128,18 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
 
         var->cvq = qualifier;
         if (qflags & AST_FLAG_COVERAGE) /* specified in QC, drop our default */
-            var->expression.flags &= ~(AST_FLAG_COVERAGE_MASK);
-        var->expression.flags |= qflags;
+            var->flags &= ~(AST_FLAG_COVERAGE_MASK);
+        var->flags |= qflags;
 
         /*
          * store the vstring back to var for alias and
          * deprecation messages.
          */
-        if (var->expression.flags & AST_FLAG_DEPRECATED ||
-            var->expression.flags & AST_FLAG_ALIAS)
+        if (var->flags & AST_FLAG_DEPRECATED ||
+            var->flags & AST_FLAG_ALIAS)
             var->desc = vstring;
 
-        if (parser_find_global(parser, var->name) && var->expression.flags & AST_FLAG_ALIAS) {
+        if (parser_find_global(parser, var->name) && var->flags & AST_FLAG_ALIAS) {
             parseerror(parser, "function aliases cannot be forward declared");
             retval = false;
             goto cleanup;
@@ -5179,7 +5171,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                 parser->crc_fields = parser->fields.size();
                 was_end = true;
             }
-            if (was_end && var->expression.vtype == TYPE_FIELD) {
+            if (was_end && var->vtype == TYPE_FIELD) {
                 if (parsewarning(parser, WARN_END_SYS_FIELDS,
                                  "global '%s' hint should not be a field",
                                  parser_tokval(parser)))
@@ -5189,7 +5181,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                 }
             }
 
-            if (!nofields && var->expression.vtype == TYPE_FIELD)
+            if (!nofields && var->vtype == TYPE_FIELD)
             {
                 /* deal with field declarations */
                 old = parser_find_field(parser, var->name);
@@ -5201,7 +5193,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                         goto cleanup;
                     }
                     ast_delete(var);
-                    var = NULL;
+                    var = nullptr;
                     goto skipvar;
                     /*
                     parseerror(parser, "field `%s` already declared here: %s:%i",
@@ -5224,7 +5216,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
             {
                 /* deal with other globals */
                 old = parser_find_global(parser, var->name);
-                if (old && var->expression.vtype == TYPE_FUNCTION && old->vtype == TYPE_FUNCTION)
+                if (old && var->vtype == TYPE_FUNCTION && old->vtype == TYPE_FUNCTION)
                 {
                     /* This is a function which had a prototype */
                     if (!ast_istype(old, ast_value)) {
@@ -5242,16 +5234,16 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                         goto cleanup;
                     }
                     /* we need the new parameter-names */
-                    for (i = 0; i < proto->expression.params.size(); ++i)
-                        ast_value_set_name(proto->expression.params[i], var->expression.params[i]->name);
+                    for (i = 0; i < proto->type_params.size(); ++i)
+                        ast_value_set_name(proto->type_params[i], var->type_params[i]->name);
                     if (!parser_check_qualifiers(parser, var, proto)) {
                         retval = false;
                         if (proto->desc)
                             mem_d(proto->desc);
-                        proto = NULL;
+                        proto = nullptr;
                         goto cleanup;
                     }
-                    proto->expression.flags |= var->expression.flags;
+                    proto->flags |= var->flags;
                     ast_delete(var);
                     var = proto;
                 }
@@ -5276,19 +5268,19 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                         if (!ast_istype(old, ast_value)) {
                             parseerror(parser, "internal error: not an ast_value");
                             retval = false;
-                            proto = NULL;
+                            proto = nullptr;
                             goto cleanup;
                         }
                         if (!parser_check_qualifiers(parser, var, proto)) {
                             retval = false;
-                            proto = NULL;
+                            proto = nullptr;
                             goto cleanup;
                         }
-                        proto->expression.flags |= var->expression.flags;
+                        proto->flags |= var->flags;
                         /* copy the context for finals,
                          * so the error can show where it was actually made 'final'
                          */
-                        if (proto->expression.flags & AST_FLAG_FINAL_DECL)
+                        if (proto->flags & AST_FLAG_FINAL_DECL)
                             ast_ctx(old) = ast_ctx(var);
                         ast_delete(var);
                         var = proto;
@@ -5330,7 +5322,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                     if (ast_istype(old, ast_value))
                         var = proto = (ast_value*)old;
                     else {
-                        var = NULL;
+                        var = nullptr;
                         goto skipvar;
                     }
                 }
@@ -5345,10 +5337,10 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
          * Create the global/local, and deal with vector types.
          */
         if (!proto) {
-            if (var->expression.vtype == TYPE_VECTOR)
+            if (var->vtype == TYPE_VECTOR)
                 isvector = true;
-            else if (var->expression.vtype == TYPE_FIELD &&
-                     var->expression.next->vtype == TYPE_VECTOR)
+            else if (var->vtype == TYPE_FIELD &&
+                     var->next->vtype == TYPE_VECTOR)
                 isvector = true;
 
             if (isvector) {
@@ -5360,7 +5352,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
 
             if (!localblock) {
                 /* deal with global variables, fields, functions */
-                if (!nofields && var->expression.vtype == TYPE_FIELD && parser->tok != '=') {
+                if (!nofields && var->vtype == TYPE_FIELD && parser->tok != '=') {
                     var->isfield = true;
                     parser->fields.push_back((ast_expression*)var);
                     util_htset(parser->htfields, var->name, var);
@@ -5372,7 +5364,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                     }
                 }
                 else {
-                    if (!(var->expression.flags & AST_FLAG_ALIAS)) {
+                    if (!(var->flags & AST_FLAG_ALIAS)) {
                         parser_addglobal(parser, var->name, (ast_expression*)var);
                         if (isvector) {
                             for (i = 0; i < 3; ++i) {
@@ -5425,7 +5417,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                     /* a static adds itself to be generated like any other global
                      * but is added to the local namespace instead
                      */
-                    char   *defname = NULL;
+                    char   *defname = nullptr;
                     size_t  prefix_len, ln;
                     size_t  sn, sn_size;
 
@@ -5446,19 +5438,19 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                      * counter value.
                      * The counter is incremented either way.
                      */
-                    sn_size = vec_size(parser->function->static_names);
+                    sn_size = parser->function->static_names.size();
                     for (sn = 0; sn != sn_size; ++sn) {
                         if (strcmp(parser->function->static_names[sn], var->name) == 0)
                             break;
                     }
                     if (sn != sn_size) {
-                        char *num = NULL;
+                        char *num = nullptr;
                         int   len = util_asprintf(&num, "#%u", parser->function->static_count);
                         vec_append(defname, len, num);
                         mem_d(num);
                     }
                     else
-                        vec_push(parser->function->static_names, util_strdup(var->name));
+                        parser->function->static_names.push_back(util_strdup(var->name));
                     parser->function->static_count++;
                     ast_value_set_name(var, defname);
 
@@ -5492,27 +5484,27 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
             }
         }
         memcpy(last_me, me, sizeof(me));
-        me[0] = me[1] = me[2] = NULL;
+        me[0] = me[1] = me[2] = nullptr;
         cleanvar = false;
         /* Part 2.2
          * deal with arrays
          */
-        if (var->expression.vtype == TYPE_ARRAY) {
-            if (var->expression.count != (size_t)-1) {
+        if (var->vtype == TYPE_ARRAY) {
+            if (var->count != (size_t)-1) {
                 if (!create_array_accessors(parser, var))
                     goto cleanup;
             }
         }
         else if (!localblock && !nofields &&
-                 var->expression.vtype == TYPE_FIELD &&
-                 var->expression.next->vtype == TYPE_ARRAY)
+                 var->vtype == TYPE_FIELD &&
+                 var->next->vtype == TYPE_ARRAY)
         {
             char name[1024];
             ast_expression *telem;
             ast_value      *tfield;
-            ast_value      *array = (ast_value*)var->expression.next;
+            ast_value      *array = (ast_value*)var->next;
 
-            if (!ast_istype(var->expression.next, ast_value)) {
+            if (!ast_istype(var->next, ast_value)) {
                 parseerror(parser, "internal error: field element type must be an ast_value");
                 goto cleanup;
             }
@@ -5521,9 +5513,9 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
             if (!parser_create_array_field_setter(parser, array, name))
                 goto cleanup;
 
-            telem = ast_type_copy(ast_ctx(var), array->expression.next);
+            telem = ast_type_copy(ast_ctx(var), array->next);
             tfield = ast_value_new(ast_ctx(var), "<.type>", TYPE_FIELD);
-            tfield->expression.next = telem;
+            tfield->next = telem;
             util_snprintf(name, sizeof(name), "%s##GETFP", var->name);
             if (!parser_create_array_getter(parser, array, (ast_expression*)tfield, name)) {
                 ast_delete(tfield);
@@ -5546,7 +5538,7 @@ skipvar:
             goto another;
 
         /*
-        if (!var || (!localblock && !nofields && basetype->expression.vtype == TYPE_FIELD)) {
+        if (!var || (!localblock && !nofields && basetype->vtype == TYPE_FIELD)) {
         */
         if (!var) {
             parseerror(parser, "missing comma or semicolon while parsing variables");
@@ -5562,7 +5554,7 @@ skipvar:
             }
         }
 
-        if (parser->tok != '{' || var->expression.vtype != TYPE_FUNCTION) {
+        if (parser->tok != '{' || var->vtype != TYPE_FUNCTION) {
             if (parser->tok != '=') {
                 parseerror(parser, "missing semicolon or initializer, got: `%s`", parser_tokval(parser));
                 break;
@@ -5578,8 +5570,8 @@ skipvar:
         }
 
         if (parser->tok == '#') {
-            ast_function *func   = NULL;
-            ast_value    *number = NULL;
+            ast_function *func   = nullptr;
+            ast_value    *number = nullptr;
             float         fractional;
             float         integral;
             int           builtin_num;
@@ -5588,7 +5580,7 @@ skipvar:
                 parseerror(parser, "cannot declare builtins within functions");
                 break;
             }
-            if (var->expression.vtype != TYPE_FUNCTION) {
+            if (var->vtype != TYPE_FUNCTION) {
                 parseerror(parser, "unexpected builtin number, '%s' is not a function", var->name);
                 break;
             }
@@ -5609,9 +5601,9 @@ skipvar:
                     parseerror(parser, "builtin number must be a compile time constant");
                     break;
                 }
-                if (number->expression.vtype == TYPE_INTEGER)
+                if (number->vtype == TYPE_INTEGER)
                     builtin_num = number->constval.vint;
-                else if (number->expression.vtype == TYPE_FLOAT)
+                else if (number->vtype == TYPE_FLOAT)
                     builtin_num = number->constval.vfloat;
                 else {
                     ast_unref(number);
@@ -5660,11 +5652,11 @@ skipvar:
                 parseerror(parser, "expected comma or semicolon");
                 if (func)
                     ast_function_delete(func);
-                var->constval.vfunc = NULL;
+                var->constval.vfunc = nullptr;
                 break;
             }
         }
-        else if (var->expression.vtype == TYPE_ARRAY && parser->tok == '{')
+        else if (var->vtype == TYPE_ARRAY && parser->tok == '{')
         {
             if (localblock) {
                 /* Note that fteqcc and most others don't even *have*
@@ -5678,7 +5670,7 @@ skipvar:
             if (!parse_array(parser, var))
                 break;
         }
-        else if (var->expression.vtype == TYPE_FUNCTION && (parser->tok == '{' || parser->tok == '['))
+        else if (var->vtype == TYPE_FUNCTION && (parser->tok == '{' || parser->tok == '['))
         {
             if (localblock) {
                 parseerror(parser, "cannot declare functions within functions");
@@ -5702,7 +5694,7 @@ skipvar:
             cexp = parse_expression_leave(parser, true, false, false);
             if (!cexp)
                 break;
-            cval = ast_istype(cexp, ast_value) ? (ast_value*)cexp : NULL;
+            cval = ast_istype(cexp, ast_value) ? (ast_value*)cexp : nullptr;
 
             /* deal with foldable constants: */
             if (localblock &&
@@ -5748,13 +5740,13 @@ skipvar:
                         var->cvq = CV_CONST;
                     }
                     if (cval == parser->nil)
-                        var->expression.flags |= AST_FLAG_INITIALIZED;
+                        var->flags |= AST_FLAG_INITIALIZED;
                     else
                     {
                         var->hasvalue = true;
-                        if (cval->expression.vtype == TYPE_STRING)
+                        if (cval->vtype == TYPE_STRING)
                             var->constval.vstring = parser_strdup(cval->constval.vstring);
-                        else if (cval->expression.vtype == TYPE_FIELD)
+                        else if (cval->vtype == TYPE_FIELD)
                             var->constval.vfield = cval;
                         else
                             memcpy(&var->constval, &cval->constval, sizeof(var->constval));
@@ -5763,29 +5755,26 @@ skipvar:
                 }
             } else {
                 int cvq;
-                shunt sy = { NULL, NULL, NULL, NULL };
+                shunt sy;
                 cvq = var->cvq;
                 var->cvq = CV_NONE;
-                vec_push(sy.out, syexp(ast_ctx(var), (ast_expression*)var));
-                vec_push(sy.out, syexp(ast_ctx(cexp), (ast_expression*)cexp));
-                vec_push(sy.ops, syop(ast_ctx(var), parser->assign_op));
+                sy.out.push_back(syexp(ast_ctx(var), (ast_expression*)var));
+                sy.out.push_back(syexp(ast_ctx(cexp), (ast_expression*)cexp));
+                sy.ops.push_back(syop(ast_ctx(var), parser->assign_op));
                 if (!parser_sy_apply_operator(parser, &sy))
                     ast_unref(cexp);
                 else {
-                    if (vec_size(sy.out) != 1 && vec_size(sy.ops) != 0)
+                    if (sy.out.size() != 1 && sy.ops.size() != 0)
                         parseerror(parser, "internal error: leaked operands");
                     if (!ast_block_add_expr(localblock, (ast_expression*)sy.out[0].out))
                         break;
                 }
-                vec_free(sy.out);
-                vec_free(sy.ops);
-                vec_free(sy.argc);
                 var->cvq = cvq;
             }
             /* a constant initialized to an inexact value should be marked inexact:
              * const float x = <inexact>; should propagate the inexact flag
              */
-            if (var->cvq == CV_CONST && var->expression.vtype == TYPE_FLOAT) {
+            if (var->cvq == CV_CONST && var->vtype == TYPE_FLOAT) {
                 if (cval && cval->hasvalue && cval->cvq == CV_CONST)
                     var->inexact = cval->inexact;
             }
@@ -5847,21 +5836,21 @@ static bool parser_global_statement(parser_t *parser)
     bool       noref     = false;
     bool       is_static = false;
     uint32_t   qflags    = 0;
-    ast_value *istype    = NULL;
-    char      *vstring   = NULL;
+    ast_value *istype    = nullptr;
+    char      *vstring   = nullptr;
 
     if (parser->tok == TOKEN_IDENT)
         istype = parser_find_typedef(parser, parser_tokval(parser), 0);
 
     if (istype || parser->tok == TOKEN_TYPENAME || parser->tok == '.' || parser->tok == TOKEN_DOTS)
     {
-        return parse_variable(parser, NULL, false, CV_NONE, istype, false, false, 0, NULL);
+        return parse_variable(parser, nullptr, false, CV_NONE, istype, false, false, 0, nullptr);
     }
     else if (parse_qualifiers(parser, false, &cvq, &noref, &is_static, &qflags, &vstring))
     {
         if (cvq == CV_WRONG)
             return false;
-        return parse_variable(parser, NULL, false, cvq, NULL, noref, is_static, qflags, vstring);
+        return parse_variable(parser, nullptr, false, cvq, nullptr, noref, is_static, qflags, vstring);
     }
     else if (parser->tok == TOKEN_IDENT && !strcmp(parser_tokval(parser), "enum"))
     {
@@ -5940,7 +5929,7 @@ static void generate_checksum(parser_t *parser, ir_builder *ir)
         if (!ast_istype(parser->globals[i], ast_value))
             continue;
         value = (ast_value*)(parser->globals[i]);
-        switch (value->expression.vtype) {
+        switch (value->vtype) {
             case TYPE_FLOAT:    crc = progdefs_crc_both(crc, "\tfloat\t"); break;
             case TYPE_VECTOR:   crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
             case TYPE_STRING:   crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
@@ -5957,7 +5946,7 @@ static void generate_checksum(parser_t *parser, ir_builder *ir)
         if (!ast_istype(parser->fields[i], ast_value))
             continue;
         value = (ast_value*)(parser->fields[i]);
-        switch (value->expression.next->vtype) {
+        switch (value->next->vtype) {
             case TYPE_FLOAT:    crc = progdefs_crc_both(crc, "\tfloat\t"); break;
             case TYPE_VECTOR:   crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
             case TYPE_STRING:   crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
@@ -5981,7 +5970,7 @@ parser_t *parser_create()
 
     parser = (parser_t*)mem_a(sizeof(parser_t));
     if (!parser)
-        return NULL;
+        return nullptr;
 
     memset(parser, 0, sizeof(*parser));
 
@@ -5997,7 +5986,7 @@ parser_t *parser_create()
     if (!parser->assign_op) {
         con_err("internal error: initializing parser: failed to find assign operator\n");
         mem_d(parser);
-        return NULL;
+        return nullptr;
     }
 
     vec_push(parser->variables, parser->htfields  = util_htnew(PARSER_HT_SIZE));
@@ -6025,14 +6014,14 @@ parser_t *parser_create()
         parser->reserved_version = ast_value_new(empty_ctx, "reserved:version", TYPE_STRING);
         parser->reserved_version->cvq = CV_CONST;
         parser->reserved_version->hasvalue = true;
-        parser->reserved_version->expression.flags |= AST_FLAG_INCLUDE_DEF;
+        parser->reserved_version->flags |= AST_FLAG_INCLUDE_DEF;
         parser->reserved_version->constval.vstring = util_strdup(GMQCC_FULL_VERSION_STRING);
     } else {
-        parser->reserved_version = NULL;
+        parser->reserved_version = nullptr;
     }
 
-    parser->fold   = fold_init  (parser);
-    parser->intrin = intrin_init(parser);
+    parser->m_fold = fold(parser);
+    parser->m_intrin = intrin(parser);
     return parser;
 }
 
@@ -6051,19 +6040,19 @@ static bool parser_compile(parser_t *parser)
                 else if (compile_errors)
                     parseerror(parser, "there have been errors, bailing out");
                 lex_close(parser->lex);
-                parser->lex = NULL;
+                parser->lex = nullptr;
                 return false;
             }
         }
     } else {
         parseerror(parser, "parse error");
         lex_close(parser->lex);
-        parser->lex = NULL;
+        parser->lex = nullptr;
         return false;
     }
 
     lex_close(parser->lex);
-    parser->lex = NULL;
+    parser->lex = nullptr;
 
     return !compile_errors;
 }
@@ -6129,13 +6118,12 @@ static void parser_remove_ast(parser_t *parser)
         ast_value_delete(parser->reserved_version);
 
     util_htdel(parser->aliases);
-    fold_cleanup(parser->fold);
-    intrin_cleanup(parser->intrin);
 }
 
 void parser_cleanup(parser_t *parser)
 {
     parser_remove_ast(parser);
+    parser->~parser_t();
     mem_d(parser);
 }
 
@@ -6157,20 +6145,20 @@ static bool parser_set_coverage_func(parser_t *parser, ir_builder *ir) {
     if (!func) {
         if (OPTS_OPTION_BOOL(OPTION_COVERAGE)) {
             con_out("coverage support requested but no coverage() builtin declared\n");
-            ir_builder_delete(ir);
+            delete ir;
             return false;
         }
         return true;
     }
 
-    cov  = func->vtype;
+    cov  = func->function_type;
     expr = (ast_expression*)cov;
 
-    if (expr->vtype != TYPE_FUNCTION || expr->params.size()) {
+    if (expr->vtype != TYPE_FUNCTION || expr->type_params.size()) {
         char ty[1024];
         ast_type_to_string(expr, ty, sizeof(ty));
         con_out("invalid type for coverage(): %s\n", ty);
-        ir_builder_delete(ir);
+        delete ir;
         return false;
     }
 
@@ -6188,7 +6176,7 @@ bool parser_finish(parser_t *parser, const char *output)
         return false;
     }
 
-    ir = ir_builder_new("gmqcc_out");
+    ir = new ir_builder("gmqcc_out");
     if (!ir) {
         con_out("failed to allocate builder\n");
         return false;
@@ -6203,14 +6191,14 @@ bool parser_finish(parser_t *parser, const char *output)
         field->hasvalue = false;
         if (!ast_global_codegen((ast_value*)field, ir, true)) {
             con_out("failed to generate field %s\n", field->name);
-            ir_builder_delete(ir);
+            delete ir;
             return false;
         }
         if (hasvalue) {
             ir_value *ifld;
             ast_expression *subtype;
             field->hasvalue = true;
-            subtype = field->expression.next;
+            subtype = field->next;
             ifld = ir_builder_create_field(ir, field->name, subtype->vtype);
             if (subtype->vtype == TYPE_FIELD)
                 ifld->fieldtype = subtype->next->vtype;
@@ -6224,13 +6212,13 @@ bool parser_finish(parser_t *parser, const char *output)
         if (!ast_istype(it, ast_value))
             continue;
         asvalue = (ast_value*)it;
-        if (!asvalue->uses && !asvalue->hasvalue && asvalue->expression.vtype != TYPE_FUNCTION) {
+        if (!asvalue->uses && !asvalue->hasvalue && asvalue->vtype != TYPE_FUNCTION) {
             retval = retval && !compile_warning(ast_ctx(asvalue), WARN_UNUSED_VARIABLE,
                                                 "unused global: `%s`", asvalue->name);
         }
         if (!ast_global_codegen(asvalue, ir, false)) {
             con_out("failed to generate global %s\n", asvalue->name);
-            ir_builder_delete(ir);
+            delete ir;
             return false;
         }
     }
@@ -6239,26 +6227,26 @@ bool parser_finish(parser_t *parser, const char *output)
      */
     for (auto &f : parser->functions) {
         if (f->varargs) {
-            if (parser->max_param_count > f->vtype->expression.params.size()) {
-                f->varargs->expression.count = parser->max_param_count - f->vtype->expression.params.size();
+            if (parser->max_param_count > f->function_type->type_params.size()) {
+                f->varargs->count = parser->max_param_count - f->function_type->type_params.size();
                 if (!parser_create_array_setter_impl(parser, f->varargs)) {
                     con_out("failed to generate vararg setter for %s\n", f->name);
-                    ir_builder_delete(ir);
+                    delete ir;
                     return false;
                 }
                 if (!parser_create_array_getter_impl(parser, f->varargs)) {
                     con_out("failed to generate vararg getter for %s\n", f->name);
-                    ir_builder_delete(ir);
+                    delete ir;
                     return false;
                 }
             } else {
                 ast_delete(f->varargs);
-                f->varargs = NULL;
+                f->varargs = nullptr;
             }
         }
     }
     /* Now we can generate immediates */
-    if (!fold_generate(parser->fold, ir))
+    if (!parser->m_fold.generate(ir))
         return false;
 
     /* before generating any functions we need to set the coverage_func */
@@ -6268,7 +6256,7 @@ bool parser_finish(parser_t *parser, const char *output)
         if (!ast_istype(it, ast_value))
             continue;
         ast_value *asvalue = (ast_value*)it;
-        if (!(asvalue->expression.flags & AST_FLAG_INITIALIZED))
+        if (!(asvalue->flags & AST_FLAG_INITIALIZED))
         {
             if (asvalue->cvq == CV_CONST && !asvalue->hasvalue)
                 (void)!compile_warning(ast_ctx(asvalue), WARN_UNINITIALIZED_CONSTANT,
@@ -6280,7 +6268,7 @@ bool parser_finish(parser_t *parser, const char *output)
                                        asvalue->name);
         }
         if (!ast_generate_accessors(asvalue, ir)) {
-            ir_builder_delete(ir);
+            delete ir;
             return false;
         }
     }
@@ -6288,10 +6276,10 @@ bool parser_finish(parser_t *parser, const char *output)
         ast_value *asvalue = (ast_value*)it->next;
         if (!ast_istype((ast_expression*)asvalue, ast_value))
             continue;
-        if (asvalue->expression.vtype != TYPE_ARRAY)
+        if (asvalue->vtype != TYPE_ARRAY)
             continue;
         if (!ast_generate_accessors(asvalue, ir)) {
-            ir_builder_delete(ir);
+            delete ir;
             return false;
         }
     }
@@ -6299,13 +6287,13 @@ bool parser_finish(parser_t *parser, const char *output)
         !ast_global_codegen(parser->reserved_version, ir, false))
     {
         con_out("failed to generate reserved::version");
-        ir_builder_delete(ir);
+        delete ir;
         return false;
     }
     for (auto &f : parser->functions) {
         if (!ast_function_codegen(f, ir)) {
             con_out("failed to generate function %s\n", f->name);
-            ir_builder_delete(ir);
+            delete ir;
             return false;
         }
     }
@@ -6317,7 +6305,7 @@ bool parser_finish(parser_t *parser, const char *output)
     for (auto &it : parser->functions) {
         if (!ir_function_finalize(it->ir_func)) {
             con_out("failed to finalize function %s\n", it->name);
-            ir_builder_delete(ir);
+            delete ir;
             return false;
         }
     }
@@ -6335,10 +6323,10 @@ bool parser_finish(parser_t *parser, const char *output)
 
         if (!ir_builder_generate(ir, output)) {
             con_out("*** failed to generate output file\n");
-            ir_builder_delete(ir);
+            delete ir;
             return false;
         }
     }
-    ir_builder_delete(ir);
+    delete ir;
     return retval;
 }