-Wextra \
-fno-exceptions \
-fno-rtti \
- -MD
+ -MD \
+ -g3
CSRCS = \
ast.cpp \
+#include <new>
+
#include <stdlib.h>
#include <string.h>
if (!self) { \
return NULL; \
} \
+ new (self) T(); \
ast_node_init((ast_node*)self, ctx, TYPE_##T); \
( (ast_node*)self )->destroy = (ast_node_delete*)destroyfn
self->next = NULL;
self->outl = NULL;
self->outr = NULL;
- self->params = NULL;
self->count = 0;
self->varparam = NULL;
self->flags = 0;
static void ast_expression_delete(ast_expression *self)
{
- size_t i;
if (self->next)
ast_delete(self->next);
- for (i = 0; i < vec_size(self->params); ++i) {
- ast_delete(self->params[i]);
- }
- vec_free(self->params);
+ for (auto &it : self->params)
+ ast_delete(it);
if (self->varparam)
ast_delete(self->varparam);
}
ast_value* ast_value_copy(const ast_value *self)
{
- size_t i;
const ast_expression *fromex;
- ast_expression *selfex;
+ ast_expression *selfex;
ast_value *cp = ast_value_new(self->expression.node.context, self->name, self->expression.vtype);
if (self->expression.next) {
cp->expression.next = ast_type_copy(self->expression.node.context, self->expression.next);
}
- fromex = &self->expression;
+ fromex = &self->expression;
selfex = &cp->expression;
- selfex->count = fromex->count;
- selfex->flags = fromex->flags;
- for (i = 0; i < vec_size(fromex->params); ++i) {
- ast_value *v = ast_value_copy(fromex->params[i]);
- vec_push(selfex->params, v);
+ selfex->count = fromex->count;
+ selfex->flags = fromex->flags;
+ for (auto &it : fromex->params) {
+ ast_value *v = ast_value_copy(it);
+ selfex->params.push_back(v);
}
return cp;
}
void ast_type_adopt_impl(ast_expression *self, const ast_expression *other)
{
- size_t i;
const ast_expression *fromex;
- ast_expression *selfex;
+ ast_expression *selfex;
self->vtype = other->vtype;
if (other->next) {
self->next = (ast_expression*)ast_type_copy(ast_ctx(self), other->next);
}
fromex = other;
selfex = self;
- selfex->count = fromex->count;
- selfex->flags = fromex->flags;
- for (i = 0; i < vec_size(fromex->params); ++i) {
- ast_value *v = ast_value_copy(fromex->params[i]);
- vec_push(selfex->params, v);
+ selfex->count = fromex->count;
+ selfex->flags = fromex->flags;
+ for (auto &it : fromex->params) {
+ ast_value *v = ast_value_copy(it);
+ selfex->params.push_back(v);
}
}
ast_expression* ast_type_copy(lex_ctx_t ctx, const ast_expression *ex)
{
- size_t i;
const ast_expression *fromex;
ast_expression *selfex;
else
selfex->next = NULL;
- selfex->count = fromex->count;
- selfex->flags = fromex->flags;
- for (i = 0; i < vec_size(fromex->params); ++i) {
- ast_value *v = ast_value_copy(fromex->params[i]);
- vec_push(selfex->params, v);
+ selfex->count = fromex->count;
+ selfex->flags = fromex->flags;
+ for (auto &it : fromex->params) {
+ ast_value *v = ast_value_copy(it);
+ selfex->params.push_back(v);
}
return self;
return false;
if (!a->next != !b->next)
return false;
- if (vec_size(a->params) != vec_size(b->params))
+ if (a->params.size() != b->params.size())
return false;
if ((a->flags & AST_FLAG_TYPE_MASK) !=
(b->flags & AST_FLAG_TYPE_MASK) )
{
return false;
}
- if (vec_size(a->params)) {
+ if (a->params.size()) {
size_t i;
- for (i = 0; i < vec_size(a->params); ++i) {
+ for (i = 0; i < a->params.size(); ++i) {
if (!ast_compare_type((ast_expression*)a->params[i],
(ast_expression*)b->params[i]))
return false;
pos = ast_type_to_string_impl(e->next, buf, bufsize, pos);
if (pos + 2 >= bufsize)
goto full;
- if (!vec_size(e->params)) {
+ if (e->params.empty()) {
buf[pos++] = '(';
buf[pos++] = ')';
return pos;
}
buf[pos++] = '(';
pos = ast_type_to_string_impl((ast_expression*)(e->params[0]), buf, bufsize, pos);
- for (i = 1; i < vec_size(e->params); ++i) {
+ for (i = 1; i < e->params.size(); ++i) {
if (pos + 2 >= bufsize)
goto full;
buf[pos++] = ',';
void ast_value_params_add(ast_value *self, ast_value *p)
{
- vec_push(self->expression.params, p);
+ self->expression.params.push_back(p);
}
bool ast_value_set_name(ast_value *self, const char *name)
self->name = util_strdup(name);
self->irblock = NULL;
- self->gotos = NULL;
self->undefined = undefined;
return self;
void ast_label_delete(ast_label *self)
{
mem_d((void*)self->name);
- vec_free(self->gotos);
ast_expression_delete((ast_expression*)self);
mem_d(self);
}
static void ast_label_register_goto(ast_label *self, ast_goto *g)
{
- vec_push(self->gotos, g);
+ self->gotos.push_back(g);
}
ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name)
char texp[1024];
char tgot[1024];
size_t i;
- bool retval = true;
- const ast_expression *func = self->func;
+ bool retval = true;
+ const ast_expression *func = self->func;
size_t count = vec_size(self->params);
- if (count > vec_size(func->params))
- count = vec_size(func->params);
+ if (count > func->params.size())
+ count = func->params.size();
for (i = 0; i < count; ++i) {
if (ast_istype(self->params[i], ast_argpipe)) {
}
}
count = vec_size(self->params);
- if (count > vec_size(func->params) && func->varparam) {
+ if (count > func->params.size() && func->varparam) {
for (; i < count; ++i) {
if (ast_istype(self->params[i], ast_argpipe)) {
/* warn about type safety instead */
ast_instantiate(ast_block, ctx, ast_block_delete);
ast_expression_init((ast_expression*)self,
(ast_expression_codegen*)&ast_block_codegen);
-
- self->locals = NULL;
- self->exprs = NULL;
- self->collect = NULL;
-
return self;
}
bool ast_block_add_expr(ast_block *self, ast_expression *e)
{
ast_propagate_effects(self, e);
- vec_push(self->exprs, e);
+ self->exprs.push_back(e);
if (self->expression.next) {
ast_delete(self->expression.next);
self->expression.next = NULL;
void ast_block_collect(ast_block *self, ast_expression *expr)
{
- vec_push(self->collect, expr);
+ self->collect.push_back(expr);
expr->node.keep = true;
}
void ast_block_delete(ast_block *self)
{
- size_t i;
- for (i = 0; i < vec_size(self->exprs); ++i)
- ast_unref(self->exprs[i]);
- vec_free(self->exprs);
- for (i = 0; i < vec_size(self->locals); ++i)
- ast_delete(self->locals[i]);
- vec_free(self->locals);
- for (i = 0; i < vec_size(self->collect); ++i)
- ast_delete(self->collect[i]);
- vec_free(self->collect);
+ for (auto &it : self->exprs) ast_unref(it);
+ for (auto &it : self->locals) ast_delete(it);
+ for (auto &it : self->collect) ast_delete(it);
ast_expression_delete((ast_expression*)self);
mem_d(self);
}
/* fill the parameter list */
ec = &self->vtype->expression;
- for (i = 0; i < vec_size(ec->params); ++i)
- {
- if (ec->params[i]->expression.vtype == TYPE_FIELD)
- vec_push(irf->params, ec->params[i]->expression.next->vtype);
+ for (auto &it : ec->params) {
+ if (it->expression.vtype == TYPE_FIELD)
+ vec_push(irf->params, it->expression.next->vtype);
else
- vec_push(irf->params, ec->params[i]->expression.vtype);
+ vec_push(irf->params, it->expression.vtype);
if (!self->builtin) {
- if (!ast_local_codegen(ec->params[i], self->ir_func, true))
+ if (!ast_local_codegen(it, self->ir_func, true))
return false;
}
}
*/
bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_value **out)
{
- size_t i;
-
/* We don't use this
* Note: an ast-representation using the comma-operator
* of the form: (a, b, c) = x should not assign to c...
*out = NULL;
/* generate locals */
- for (i = 0; i < vec_size(self->locals); ++i)
- {
- if (!ast_local_codegen(self->locals[i], func->ir_func, false)) {
+ for (auto &it : self->locals) {
+ if (!ast_local_codegen(it, func->ir_func, false)) {
if (OPTS_OPTION_BOOL(OPTION_DEBUG))
- compile_error(ast_ctx(self), "failed to generate local `%s`", self->locals[i]->name);
+ compile_error(ast_ctx(self), "failed to generate local `%s`", it->name);
return false;
}
}
- for (i = 0; i < vec_size(self->exprs); ++i)
- {
+ for (auto &it : self->exprs) {
ast_expression_codegen *gen;
- if (func->curblock->final && !starts_a_label(self->exprs[i])) {
- if (compile_warning(ast_ctx(self->exprs[i]), WARN_UNREACHABLE_CODE, "unreachable statement"))
+ if (func->curblock->final && !starts_a_label(it)) {
+ if (compile_warning(ast_ctx(it), WARN_UNREACHABLE_CODE, "unreachable statement"))
return false;
continue;
}
- gen = self->exprs[i]->codegen;
- if (!(*gen)(self->exprs[i], func, false, out))
+ gen = it->codegen;
+ if (!(*gen)(it, func, false, out))
return false;
}
bool ast_label_codegen(ast_label *self, ast_function *func, bool lvalue, ir_value **out)
{
- size_t i;
ir_value *dummy;
if (self->undefined) {
func->curblock = self->irblock;
/* Generate all the leftover gotos */
- for (i = 0; i < vec_size(self->gotos); ++i) {
- if (!ast_goto_codegen(self->gotos[i], func, false, &dummy))
+ for (auto &it : self->gotos) {
+ if (!ast_goto_codegen(it, func, false, &dummy))
return false;
}
#ifndef GMQCC_AST_HDR
#define GMQCC_AST_HDR
+#include <vector>
#include "ir.h"
typedef uint16_t ast_flag_t;
* "main" ast node types for now.
*/
-typedef struct ast_node_common ast_node;
-typedef struct ast_expression_common ast_expression;
-
-typedef struct ast_value_s ast_value;
-typedef struct ast_function_s ast_function;
-typedef struct ast_block_s ast_block;
-typedef struct ast_binary_s ast_binary;
-typedef struct ast_store_s ast_store;
-typedef struct ast_binstore_s ast_binstore;
-typedef struct ast_entfield_s ast_entfield;
-typedef struct ast_ifthen_s ast_ifthen;
-typedef struct ast_ternary_s ast_ternary;
-typedef struct ast_loop_s ast_loop;
-typedef struct ast_call_s ast_call;
-typedef struct ast_unary_s ast_unary;
-typedef struct ast_return_s ast_return;
-typedef struct ast_member_s ast_member;
-typedef struct ast_array_index_s ast_array_index;
-typedef struct ast_breakcont_s ast_breakcont;
-typedef struct ast_switch_s ast_switch;
-typedef struct ast_label_s ast_label;
-typedef struct ast_goto_s ast_goto;
-typedef struct ast_argpipe_s ast_argpipe;
-typedef struct ast_state_s ast_state;
+struct ast_node;
+struct ast_expression;
+struct ast_value;
+struct ast_function;
+struct ast_block;
+struct ast_binary;
+struct ast_store;
+struct ast_binstore;
+struct ast_entfield;
+struct ast_ifthen;
+struct ast_ternary;
+struct ast_loop;
+struct ast_call;
+struct ast_unary;
+struct ast_return;
+struct ast_member;
+struct ast_array_index;
+struct ast_breakcont;
+struct ast_switch;
+struct ast_label;
+struct ast_goto;
+struct ast_argpipe;
+struct ast_state;
enum {
AST_FLAG_VARIADIC = 1 << 0,
/* Node interface with common components
*/
typedef void ast_node_delete(ast_node*);
-struct ast_node_common
+
+struct ast_node
{
- lex_ctx_t context;
+ lex_ctx_t context;
/* I don't feel comfortable using keywords like 'delete' as names... */
ast_node_delete *destroy;
int nodetype;
* type `expression`, so the ast_ident's codegen would search for
* variables through the environment (or functions, constants...).
*/
-struct ast_expression_common
-{
+struct ast_expression {
+ ast_expression() {}
+
ast_node node;
ast_expression_codegen *codegen;
int vtype;
ast_expression *next;
/* arrays get a member-count */
size_t count;
- ast_value* *params;
+ std::vector<ast_value*> params;
+
ast_flag_t flags;
/* void foo(string...) gets varparam set as a restriction
* for variadic parameters
* typedef float foo;
* is like creating a 'float foo', foo serving as the type's name.
*/
-typedef union {
+union basic_value_t {
qcfloat_t vfloat;
int vint;
vec3_t vvec;
int ventity;
ast_function *vfunc;
ast_value *vfield;
-} basic_value_t;
+};
-struct ast_value_s
+struct ast_value
{
- ast_expression expression;
+ ast_expression expression;
const char *name;
const char *desc;
const char *argcounter;
- int cvq; /* const/var qualifier */
+ int cvq; /* const/var qualifier */
bool isfield; /* this declares a field */
bool isimm; /* an immediate, not just const */
bool hasvalue;
ir_value *ir_v;
ir_value **ir_values;
- size_t ir_value_count;
+ size_t ir_value_count;
/* ONLY for arrays in progs version up to 6 */
ast_value *setter;
ast_value *getter;
- bool intrinsic; /* true if associated with intrinsic */
+ bool intrinsic; /* true if associated with intrinsic */
};
ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int qctype);
void ast_type_adopt_impl(ast_expression *self, const ast_expression *other);
void ast_type_to_string(ast_expression *e, char *buf, size_t bufsize);
-typedef enum ast_binary_ref_s {
+enum ast_binary_ref {
AST_REF_NONE = 0,
AST_REF_LEFT = 1 << 1,
AST_REF_RIGHT = 1 << 2,
AST_REF_ALL = (AST_REF_LEFT | AST_REF_RIGHT)
-} ast_binary_ref;
+};
/* Binary
*
* A value-returning binary expression.
*/
-struct ast_binary_s
+struct ast_binary
{
- ast_expression expression;
-
- int op;
+ ast_expression expression;
+ int op;
ast_expression *left;
ast_expression *right;
- ast_binary_ref refs;
- bool right_first;
+ ast_binary_ref refs;
+ bool right_first;
};
ast_binary* ast_binary_new(lex_ctx_t ctx,
int op,
* An assignment including a binary expression with the source as left operand.
* Eg. a += b; is a binstore { INSTR_STORE, INSTR_ADD, a, b }
*/
-struct ast_binstore_s
+struct ast_binstore
{
- ast_expression expression;
-
- int opstore;
- int opbin;
+ ast_expression expression;
+ int opstore;
+ int opbin;
ast_expression *dest;
ast_expression *source;
/* for &~= which uses the destination in a binary in source we can use this */
- bool keep_dest;
+ bool keep_dest;
};
ast_binstore* ast_binstore_new(lex_ctx_t ctx,
int storeop,
*
* Regular unary expressions: not,neg
*/
-struct ast_unary_s
+struct ast_unary
{
- ast_expression expression;
-
- int op;
+ ast_expression expression;
+ int op;
ast_expression *operand;
};
-ast_unary* ast_unary_new(lex_ctx_t ctx,
- int op,
+ast_unary* ast_unary_new(lex_ctx_t ctx,
+ int op,
ast_expression *expr);
/* Return
* will refuse to create further instructions.
* This should be honored by the parser.
*/
-struct ast_return_s
+struct ast_return
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *operand;
};
-ast_return* ast_return_new(lex_ctx_t ctx,
+ast_return* ast_return_new(lex_ctx_t ctx,
ast_expression *expr);
/* Entity-field
* For this we will have to extend the codegen() functions with
* a flag saying whether or not we need an L or an R-value.
*/
-struct ast_entfield_s
+struct ast_entfield
{
- ast_expression expression;
+ ast_expression expression;
/* The entity can come from an expression of course. */
ast_expression *entity;
/* As can the field, it just must result in a value of TYPE_FIELD */
* For now used for vectors. If we get structs or unions
* we can have them handled here as well.
*/
-struct ast_member_s
+struct ast_member
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *owner;
- unsigned int field;
- const char *name;
- bool rvalue;
+ unsigned int field;
+ const char *name;
+ bool rvalue;
};
ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const char *name);
void ast_member_delete(ast_member*);
* In any case, accessing an element via a compiletime-constant index will
* result in quick access to that variable.
*/
-struct ast_array_index_s
+struct ast_array_index
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *array;
ast_expression *index;
};
*
* copy all varargs starting from a specific index
*/
-struct ast_argpipe_s
+struct ast_argpipe
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *index;
};
ast_argpipe* ast_argpipe_new(lex_ctx_t ctx, ast_expression *index);
* Stores left<-right and returns left.
* Specialized binary expression node
*/
-struct ast_store_s
+struct ast_store
{
- ast_expression expression;
- int op;
+ ast_expression expression;
+ int op;
ast_expression *dest;
ast_expression *source;
};
* output field though. For ternary expressions an ast_ternary will be
* added.
*/
-struct ast_ifthen_s
+struct ast_ifthen
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *cond;
/* It's all just 'expressions', since an ast_block is one too. */
ast_expression *on_true;
* This is the only ast_node beside ast_value which contains
* an ir_value. Theoretically we don't need to remember it though.
*/
-struct ast_ternary_s
+struct ast_ternary
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *cond;
/* It's all just 'expressions', since an ast_block is one too. */
ast_expression *on_true;
{inc};
}
*/
-struct ast_loop_s
+struct ast_loop
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *initexpr;
ast_expression *precond;
ast_expression *postcond;
/* Break/Continue
*/
-struct ast_breakcont_s
+struct ast_breakcont
{
ast_expression expression;
- bool is_continue;
- unsigned int levels;
+ bool is_continue;
+ unsigned int levels;
};
ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels);
* be expected from it.
* TODO: Ticket #20
*/
-typedef struct {
+struct ast_switch_case {
ast_expression *value; /* #20 will replace this */
ast_expression *code;
-} ast_switch_case;
-struct ast_switch_s
-{
- ast_expression expression;
+};
- ast_expression *operand;
+struct ast_switch
+{
+ ast_expression expression;
+ ast_expression *operand;
ast_switch_case *cases;
};
*
* Introduce a label which can be used together with 'goto'
*/
-struct ast_label_s
+struct ast_label
{
- ast_expression expression;
- const char *name;
- ir_block *irblock;
- ast_goto **gotos;
+ ast_expression expression;
+ const char *name;
+ ir_block *irblock;
+ std::vector<ast_goto*> gotos;
/* means it has not yet been defined */
- bool undefined;
+ bool undefined;
};
ast_label* ast_label_new(lex_ctx_t ctx, const char *name, bool undefined);
*
* Go to a label, the label node is filled in at a later point!
*/
-struct ast_goto_s
+struct ast_goto
{
ast_expression expression;
- const char *name;
- ast_label *target;
- ir_block *irblock_from;
+ const char *name;
+ ast_label *target;
+ ir_block *irblock_from;
};
ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name);
*
* For frame/think state updates: void foo() [framenum, nextthink] {}
*/
-struct ast_state_s
+struct ast_state
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *framenum;
ast_expression *nextthink;
};
* Additionally it contains a list of ast_expressions as parameters.
* Since calls can return values, an ast_call is also an ast_expression.
*/
-struct ast_call_s
+struct ast_call
{
- ast_expression expression;
+ ast_expression expression;
ast_expression *func;
ast_expression **params;
ast_expression *va_count;
/* Blocks
*
*/
-struct ast_block_s
+struct ast_block
{
- ast_expression expression;
+ ast_expression expression;
- ast_value* *locals;
- ast_expression* *exprs;
- ast_expression* *collect;
+ std::vector<ast_value*> locals;
+ std::vector<ast_expression*> exprs;
+ std::vector<ast_expression*> collect;
};
ast_block* ast_block_new(lex_ctx_t ctx);
void ast_block_delete(ast_block*);
* pointers could just work with a name. However, this way could be
* more flexible, and adds no real complexity.
*/
-struct ast_function_s
+struct ast_function
{
ast_node node;
* here to use in ast_function_label.
*/
char labelbuf[64];
-
ast_block* *blocks;
-
- ast_value *varargs;
- ast_value *argc;
- ast_value *fixedparams;
- ast_value *return_value;
+ ast_value *varargs;
+ ast_value *argc;
+ ast_value *fixedparams;
+ ast_value *return_value;
};
ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype);
/* This will NOT delete the underlying ast_value */
static GMQCC_INLINE void intrin_reg(intrin_t *intrin, ast_value *const value, ast_function *const func) {
vec_push(intrin->parser->functions, func);
- vec_push(intrin->parser->globals, (ast_expression*)value);
+ vec_push(intrin->parser->globals, (ast_expression*)value);
}
#define QC_POW_EPSILON 0.00001f
ast_block *block = ast_block_new(intrin_ctx(intrin));
/* float x; */
- vec_push(value->expression.params, x);
+ value->expression.params.push_back(x);
/* <callisnan> = isnan(x); */
vec_push(callisnan->params, (ast_expression*)x);
vec_push(callisinf->params, (ast_expression*)x);
/* return (!<callisnan> || <callisinf>); */
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_unary_new(
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "isinf", TYPE_FLOAT);
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
)
);
- vec_push(value->expression.params, x);
+ value->expression.params.push_back(x);
vec_push(func->blocks, body);
intrin_reg(intrin, value, func);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "isnan", TYPE_FLOAT);
- vec_push(body->locals, local);
- vec_push(body->exprs,
+ body->locals.push_back(local);
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
)
);
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
)
);
- vec_push(value->expression.params, arg1);
+ value->expression.params.push_back(arg1);
vec_push(func->blocks, body);
intrin_reg(intrin, value, func);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "isnormal", TYPE_FLOAT);
- vec_push(value->expression.params, x);
+ value->expression.params.push_back(x);
vec_push(callisfinite->params, (ast_expression*)x);
/* return <callisfinite> */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)callisfinite
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "signbit", TYPE_FLOAT);
- vec_push(value->expression.params, x);
+ value->expression.params.push_back(x);
/* return (x < 0); */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_ternary_new(
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "acosh", TYPE_FLOAT);
- vec_push(value->expression.params, x);
+ value->expression.params.push_back(x);
/* <callsqrt> = sqrt((x * x) - 1); */
vec_push(callsqrt->params,
);
/* return <calllog>; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)calllog
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "asinh", TYPE_FLOAT);
- vec_push(value->expression.params, x);
+ value->expression.params.push_back(x);
/* <callsqrt> = sqrt((x * x) + 1); */
vec_push(callsqrt->params,
);
/* return <calllog>; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)calllog
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "atanh", TYPE_FLOAT);
- vec_push(value->expression.params, x);
+ value->expression.params.push_back(x);
/* <callog> = log((1 + x) / (1 - x)); */
vec_push(calllog->params,
);
/* return 0.5 * <calllog>; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
INSTR_MUL_F,
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "exp", TYPE_FLOAT);
- vec_push(value->expression.params, x);
- vec_push(body->locals, sum);
- vec_push(body->locals, acc);
- vec_push(body->locals, i);
+ value->expression.params.push_back(x);
+
+ body->locals.push_back(sum);
+ body->locals.push_back(acc);
+ body->locals.push_back(i);
/* sum = 1.0; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* acc = 1.0; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* for (i = 1; i < 200; ++i)
* sum += (acc *= x / i);
*/
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
/* i = 1; */
);
/* return sum; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)sum
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "exp2", TYPE_FLOAT);
- vec_push(value->expression.params, arg1);
+ value->expression.params.push_back(arg1);
vec_push(callpow->params, (ast_expression*)intrin->fold->imm_float[3]);
vec_push(callpow->params, (ast_expression*)arg1);
/* return <callpow> */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)callpow
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "expm1", TYPE_FLOAT);
- vec_push(value->expression.params, x);
+ value->expression.params.push_back(x);
/* <callexp> = exp(x); */
vec_push(callexp->params, (ast_expression*)x);
/* return <callexp> - 1; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
ast_value *square = ast_value_new(intrin_ctx(intrin), "square", TYPE_FLOAT);
ast_value *accumulate = ast_value_new(intrin_ctx(intrin), "accumulate", TYPE_FLOAT);
ast_value *mid = ast_value_new(intrin_ctx(intrin), "mid", TYPE_FLOAT);
- vec_push(body->locals, result);
- vec_push(body->locals, low);
- vec_push(body->locals, high);
- vec_push(body->locals, square);
- vec_push(body->locals, accumulate);
- vec_push(body->locals, mid);
+ body->locals.push_back(result);
+ body->locals.push_back(low);
+ body->locals.push_back(high);
+ body->locals.push_back(square);
+ body->locals.push_back(accumulate);
+ body->locals.push_back(mid);
- vec_push(value->expression.params, base);
- vec_push(value->expression.params, exp);
+ value->expression.params.push_back(base);
+ value->expression.params.push_back(exp);
/*
* if (exp == 0.0)
* return 1;
*/
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_ifthen_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
* if (exp == 1.0)
* return base;
*/
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_ifthen_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
* if (exp < 0)
* return 1.0 / <callpow1>;
*/
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_ifthen_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
* return result * result;
* }
*/
- vec_push(expgt1->exprs,
+ expgt1->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
(ast_expression*)callpow2
)
);
- vec_push(expgt1->exprs,
+ expgt1->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
* <expgt1>
* }
*/
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_ifthen_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
* accumulate = square;
* mid = high / 2.0f;
*/
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(intrin_ctx(intrin),
INSTR_STORE_F,
(ast_expression*)low,
(ast_expression*)intrin->fold->imm_float[0]
)
);
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
)
);
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
)
);
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
(ast_expression*)square
)
);
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* accumulate *= square;
* }
*/
- vec_push(midltexp->exprs,
+ midltexp->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
(ast_expression*)mid
)
);
- vec_push(midltexp->exprs,
+ midltexp->exprs.push_back(
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* accumulate *= (1.0 / square);
* }
*/
- vec_push(midltexpelse->exprs,
+ midltexpelse->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
(ast_expression*)mid
)
);
- vec_push(midltexpelse->exprs,
+ midltexpelse->exprs.push_back(
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* mid = (low + high) / 2;
* }
*/
- vec_push(whileblock->exprs,
+ whileblock->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
(ast_expression*)callsqrt2
)
);
- vec_push(whileblock->exprs,
+ whileblock->exprs.push_back(
(ast_expression*)ast_ifthen_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
(ast_expression*)midltexpelse
)
);
- vec_push(whileblock->exprs,
+ whileblock->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* while (<callfabs> > epsilon)
* <whileblock>
*/
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
/* init */
);
/* return accumulate */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)accumulate
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "mod", TYPE_FLOAT);
- vec_push(value->expression.params, a);
- vec_push(value->expression.params, b);
+ value->expression.params.push_back(a);
+ value->expression.params.push_back(b);
- vec_push(body->locals, div);
- vec_push(body->locals, sign);
+ body->locals.push_back(div);
+ body->locals.push_back(sign);
/* div = a / b; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* sign = (div < 0.0f) ? -1 : 1; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* return a - b * sign * <call> */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "fabs", TYPE_FLOAT);
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_ternary_new(
)
);
- vec_push(value->expression.params, arg1);
+ value->expression.params.push_back(arg1);
+
vec_push(func->blocks, body);
intrin_reg(intrin, value, func);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "epsilon", TYPE_FLOAT);
- vec_push(body->locals, eps);
+ body->locals.push_back(eps);
/* eps = 1.0f; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
)
);
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
NULL,
);
/* return eps; */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)eps
ast_function *func = intrin_value(intrin, &value, "nan", TYPE_FLOAT);
ast_block *block = ast_block_new(intrin_ctx(intrin));
- vec_push(block->locals, x);
+ block->locals.push_back(x);
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
)
);
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
ast_block *block = ast_block_new(intrin_ctx(intrin));
size_t i;
- vec_push(block->locals, x);
- vec_push(block->locals, y);
+ block->locals.push_back(x);
+ block->locals.push_back(y);
/* to keep code size down */
for (i = 0; i <= 1; i++) {
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
}
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
ast_function *func = intrin_value(intrin, &value, "ln", TYPE_FLOAT);
size_t i;
- vec_push(value->expression.params, power);
- vec_push(value->expression.params, base);
+ value->expression.params.push_back(power);
+ value->expression.params.push_back(base);
- vec_push(block->locals, whole);
- vec_push(block->locals, nth);
- vec_push(block->locals, sign);
- vec_push(block->locals, eps);
- vec_push(block->locals, A_i);
- vec_push(block->locals, B_i);
- vec_push(block->locals, A_iminus1);
- vec_push(block->locals, B_iminus1);
+ block->locals.push_back(whole);
+ block->locals.push_back(nth);
+ block->locals.push_back(sign);
+ block->locals.push_back(eps);
+ block->locals.push_back(A_i);
+ block->locals.push_back(B_i);
+ block->locals.push_back(A_iminus1);
+ block->locals.push_back(B_iminus1);
/* sign = 1.0f; */
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* eps = __builtin_epsilon(); */
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
for (i = 0; i <= 1; i++) {
int j;
for (j = 1; j >= 0; j--) {
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* }
*/
for (i = 0; i <= 1; i++) {
- vec_push(((i) ? blt1 : plt1)->exprs,
+ ((i) ? blt1 : plt1)->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
)
)
);
- vec_push(plt1->exprs,
+ plt1->exprs.push_back(
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* <blt1>
* }
*/
- vec_push(plt1orblt1->exprs,
+ plt1orblt1->exprs.push_back(
(ast_expression*)ast_ifthen_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
);
for (i = 0; i <= 1; i++) {
- vec_push(plt1orblt1->exprs,
+ plt1orblt1->exprs.push_back(
(ast_expression*)ast_ifthen_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
);
}
- vec_push(block->exprs, (ast_expression*)plt1orblt1);
+ block->exprs.push_back((ast_expression*)plt1orblt1);
/* whole = power; */
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* nth = 0.0f; */
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* base2 = base; */
- vec_push(whileloop->exprs,
+ whileloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* n2 = 1.0f; */
- vec_push(whileloop->exprs,
+ whileloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* newbase2 = base2 * base2; */
- vec_push(whileloop->exprs,
+ whileloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* while loop locals */
- vec_push(whileloop->locals, base2);
- vec_push(whileloop->locals, n2);
- vec_push(whileloop->locals, newbase2);
+ whileloop->locals.push_back(base2);
+ whileloop->locals.push_back(n2);
+ whileloop->locals.push_back(newbase2);
/* base2 = newbase2; */
- vec_push(nestwhile->exprs,
+ nestwhile->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* n2 *= 2; */
- vec_push(nestwhile->exprs,
+ nestwhile->exprs.push_back(
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* newbase2 *= newbase2; */
- vec_push(nestwhile->exprs,
+ nestwhile->exprs.push_back(
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* while (whole >= newbase2) */
- vec_push(whileloop->exprs,
+ whileloop->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
NULL,
);
/* whole /= base2; */
- vec_push(whileloop->exprs,
+ whileloop->exprs.push_back(
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* nth += n2; */
- vec_push(whileloop->exprs,
+ whileloop->exprs.push_back(
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
);
/* while (whole >= base) */
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
NULL,
)
);
- vec_push(forloop->locals, b_iplus1);
- vec_push(forloop->locals, A_iplus1);
- vec_push(forloop->locals, B_iplus1);
+ forloop->locals.push_back(b_iplus1);
+ forloop->locals.push_back(A_iplus1);
+ forloop->locals.push_back(B_iplus1);
/* b_iplus1 = nth; */
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* B_iplus1 = b_iplus1 * B_i + B_iminus1;
*/
for (i = 0; i <= 1; i++) {
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* B_iminus1 = B_i;
*/
for (i = 0; i <= 1; i++) {
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* B_i = B_iplus1;
*/
for (i = 0; i <= 1; i++) {
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* if (whole <= 1.0f + eps)
* break;
*/
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_ifthen_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
* base = whole;
*/
for (i = 0; i <= 1; i++) {
- vec_push(forloop->exprs,
+ forloop->exprs.push_back(
(ast_expression*)ast_store_new(
intrin_ctx(intrin),
INSTR_STORE_F,
}
/* add the for loop block */
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
NULL,
);
/* return sign * A_i / B_il */
- vec_push(block->exprs,
+ block->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)ast_binary_new(
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, name, TYPE_FLOAT);
- vec_push(value->expression.params, arg1);
+ value->expression.params.push_back(arg1);
vec_push(callln->params, (ast_expression*)arg1);
vec_push(callln->params, (ast_expression*)fold_constgen_float(intrin->fold, base, false));
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)callln
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, name, TYPE_FLOAT);
- vec_push(value->expression.params, a);
- vec_push(value->expression.params, b);
+ value->expression.params.push_back(a);
+ value->expression.params.push_back(b);
/* <callpow> = pow(2, b) */
vec_push(callpow->params, (ast_expression*)intrin->fold->imm_float[3]);
);
/* return <callfloor> */
- vec_push(body->exprs,
+ body->exprs.push_back(
(ast_expression*)ast_return_new(
intrin_ctx(intrin),
(ast_expression*)callfloor
static ast_expression* parser_find_label(parser_t *parser, const char *name)
{
- size_t i;
- for(i = 0; i < vec_size(parser->labels); i++)
- if (!strcmp(parser->labels[i]->name, name))
- return (ast_expression*)parser->labels[i];
- return NULL;
+ for (auto &it : parser->labels)
+ if (!strcmp(it->name, name))
+ return (ast_expression*)it;
+ return nullptr;
}
ast_expression* parser_find_global(parser_t *parser, const char *name)
static ast_expression* parser_find_param(parser_t *parser, const char *name)
{
- size_t i;
ast_value *fun;
if (!parser->function)
return NULL;
fun = parser->function->vtype;
- for (i = 0; i < vec_size(fun->expression.params); ++i) {
- if (!strcmp(fun->expression.params[i]->name, name))
- return (ast_expression*)(fun->expression.params[i]);
+ for (auto &it : fun->expression.params) {
+ if (!strcmp(it->name, name))
+ return (ast_expression*)it;
}
return NULL;
}
}
}
- if (blocks[0] && !vec_size(blocks[0]->exprs) && op->id != opid1(',')) {
+ if (blocks[0] && blocks[0]->exprs.empty() && op->id != opid1(',')) {
compile_error(ctx, "internal error: operator cannot be applied on empty blocks");
return false;
}
ast_ctx(fun).line);
}
- if (vec_size(fun->params) != paramcount &&
+ if (fun->params.size() != paramcount &&
!((fun->flags & AST_FLAG_VARIADIC) &&
- vec_size(fun->params) < paramcount))
+ fun->params.size() < paramcount))
{
- const char *fewmany = (vec_size(fun->params) > paramcount) ? "few" : "many";
+ const char *fewmany = (fun->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)vec_size(fun->params), (int)paramcount,
+ fewmany, fval->name, (int)fun->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)vec_size(fun->params), (int)paramcount,
+ fewmany, (int)fun->params.size(), (int)paramcount,
ast_ctx(fun).file, (int)ast_ctx(fun).line);
}
}
if (!with_labels) {
ast_label *lbl = ast_label_new(parser_ctx(parser), parser_tokval(parser), true);
var = (ast_expression*)lbl;
- vec_push(parser->labels, lbl);
+ parser->labels.push_back(lbl);
}
}
if (!var && !strcmp(parser_tokval(parser), "__FUNC__"))
return false;
}
- vec_push(parser->breaks, label);
- vec_push(parser->continues, label);
+ parser->breaks.push_back(label);
+ parser->continues.push_back(label);
rv = parse_while_go(parser, block, out);
if (label)
mem_d(label);
- if (vec_last(parser->breaks) != label || vec_last(parser->continues) != label) {
+ if (parser->breaks.back() != label || parser->continues.back() != label) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
*out = NULL;
}
else {
- vec_pop(parser->breaks);
- vec_pop(parser->continues);
+ parser->breaks.pop_back();
+ parser->continues.pop_back();
}
return rv;
}
}
}
- vec_push(parser->breaks, label);
- vec_push(parser->continues, label);
+ parser->breaks.push_back(label);
+ parser->continues.push_back(label);
rv = parse_dowhile_go(parser, block, out);
if (label)
mem_d(label);
- if (vec_last(parser->breaks) != label || vec_last(parser->continues) != label) {
+ if (parser->breaks.back() != label || parser->continues.back() != label) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
/*
*out = NULL;
}
else {
- vec_pop(parser->breaks);
- vec_pop(parser->continues);
+ parser->breaks.pop_back();
+ parser->continues.pop_back();
}
return rv;
}
return false;
}
- vec_push(parser->breaks, label);
- vec_push(parser->continues, label);
+ parser->breaks.push_back(label);
+ parser->continues.push_back(label);
rv = parse_for_go(parser, block, out);
if (label)
mem_d(label);
- if (vec_last(parser->breaks) != label || vec_last(parser->continues) != label) {
+ if (parser->breaks.back() != label || parser->continues.back() != label) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
*out = NULL;
}
else {
- vec_pop(parser->breaks);
- vec_pop(parser->continues);
+ parser->breaks.pop_back();
+ parser->continues.pop_back();
}
return rv;
}
static bool parse_break_continue(parser_t *parser, ast_block *block, ast_expression **out, bool is_continue)
{
- size_t i;
+ size_t i;
unsigned int levels = 0;
- lex_ctx_t ctx = parser_ctx(parser);
- const char **loops = (is_continue ? parser->continues : parser->breaks);
+ lex_ctx_t ctx = parser_ctx(parser);
+ auto &loops = (is_continue ? parser->continues : parser->breaks);
(void)block; /* not touching */
if (!parser_next(parser)) {
return false;
}
- if (!vec_size(loops)) {
+ if (loops.empty()) {
if (is_continue)
parseerror(parser, "`continue` can only be used inside loops");
else
if (parser->tok == TOKEN_IDENT) {
if (!OPTS_FLAG(LOOP_LABELS))
parseerror(parser, "labeled loops not activated, try using -floop-labels");
- i = vec_size(loops);
+ i = loops.size();
while (i--) {
if (loops[i] && !strcmp(loops[i], parser_tokval(parser)))
break;
return false;
}
- vec_push(parser->breaks, label);
+ parser->breaks.push_back(label);
rv = parse_switch_go(parser, block, out);
if (label)
mem_d(label);
- if (vec_last(parser->breaks) != label) {
+ if (parser->breaks.back() != label) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
*out = NULL;
}
else {
- vec_pop(parser->breaks);
+ parser->breaks.pop_back();
}
return rv;
}
ast_goto_set_label(gt, (ast_label*)lbl);
}
else
- vec_push(parser->gotos, gt);
+ parser->gotos.push_back(gt);
if (!parser_next(parser) || parser->tok != ';') {
parseerror(parser, "semicolon expected after goto label");
}
else {
label = ast_label_new(parser_ctx(parser), parser_tokval(parser), false);
- vec_push(parser->labels, label);
+ parser->labels.push_back(label);
}
*out = (ast_expression*)label;
if (!parser_next(parser)) {
parseerror(parser, "parse error after label");
return false;
}
- for (i = 0; i < vec_size(parser->gotos); ++i) {
+ for (i = 0; i < parser->gotos.size(); ++i) {
if (!strcmp(parser->gotos[i]->name, label->name)) {
ast_goto_set_label(parser->gotos[i], label);
- vec_remove(parser->gotos, i, 1);
+ parser->gotos.erase(parser->gotos.begin() + i);
--i;
}
}
static bool parse_function_body(parser_t *parser, ast_value *var)
{
- ast_block *block = NULL;
- ast_function *func;
- ast_function *old;
- size_t parami;
+ ast_block *block = NULL;
+ ast_function *func;
+ ast_function *old;
ast_expression *framenum = NULL;
ast_expression *nextthink = NULL;
/* 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;
- bool has_frame_think;
+ bool has_frame_think;
bool retval = true;
return false;
}
- if (vec_size(parser->gotos) || vec_size(parser->labels)) {
+ if (parser->gotos.size() || parser->labels.size()) {
parseerror(parser, "gotos/labels leaking");
return false;
}
parser_enterblock(parser);
- for (parami = 0; parami < vec_size(var->expression.params); ++parami) {
- size_t e;
- ast_value *param = var->expression.params[parami];
+ for (auto &it : var->expression.params) {
+ size_t e;
ast_member *me[3];
- if (param->expression.vtype != TYPE_VECTOR &&
- (param->expression.vtype != TYPE_FIELD ||
- param->expression.next->vtype != TYPE_VECTOR))
+ if (it->expression.vtype != TYPE_VECTOR &&
+ (it->expression.vtype != TYPE_FIELD ||
+ it->expression.next->vtype != TYPE_VECTOR))
{
continue;
}
- if (!create_vector_members(param, me)) {
+ if (!create_vector_members(it, me)) {
ast_block_delete(block);
goto enderrfn;
}
goto enderrfn;
}
func->varargs = varargs;
- func->fixedparams = (ast_value*)fold_constgen_float(parser->fold, vec_size(var->expression.params), false);
+ func->fixedparams = (ast_value*)fold_constgen_float(parser->fold, var->expression.params.size(), false);
}
parser->function = func;
goto cleanup;
}
(void)!ast_value_set_name(value, "value"); /* not important */
- vec_push(fval->expression.params, index);
- vec_push(fval->expression.params, value);
+ fval->expression.params.push_back(index);
+ fval->expression.params.push_back(value);
array->setter = fval;
return fval;
goto cleanup;
}
(void)!ast_value_set_name(value, "value"); /* not important */
- vec_push(fval->expression.params, entity);
- vec_push(fval->expression.params, index);
- vec_push(fval->expression.params, value);
+ fval->expression.params.push_back(entity);
+ fval->expression.params.push_back(index);
+ fval->expression.params.push_back(value);
root = array_field_setter_node(parser, array, entity, index, value, 0, array->expression.count);
if (!root) {
parseerror(parser, "failed to create locals for array accessor");
goto cleanup;
}
- vec_push(fval->expression.params, index);
+ fval->expression.params.push_back(index);
array->getter = fval;
return fval;
static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
{
- lex_ctx_t ctx;
- size_t i;
- ast_value **params;
- ast_value *param;
- ast_value *fval;
- bool first = true;
- bool variadic = false;
- ast_value *varparam = NULL;
- char *argcounter = NULL;
-
- ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
+ std::vector<ast_value *> params;
+ ast_value *fval;
+ bool first = true;
+ bool variadic = false;
+ ast_value *varparam = NULL;
+ char *argcounter = NULL;
/* for the sake of less code we parse-in in this function */
if (!parser_next(parser)) {
return NULL;
}
- params = NULL;
-
/* parse variables until we hit a closing paren */
while (parser->tok != ')') {
bool is_varargs = false;
}
first = false;
- param = parse_typename(parser, NULL, NULL, &is_varargs);
+ ast_value *param = parse_typename(parser, NULL, NULL, &is_varargs);
if (!param && !is_varargs)
goto on_error;
if (is_varargs) {
}
}
} else {
- vec_push(params, param);
+ params.push_back(param);
if (param->expression.vtype >= TYPE_VARIANT) {
char tname[1024]; /* typename is reserved in C++ */
ast_type_to_string((ast_expression*)param, tname, sizeof(tname));
/* type-restricted varargs */
if (parser->tok == TOKEN_DOTS) {
variadic = true;
- varparam = vec_last(params);
- vec_pop(params);
+ varparam = params.back();
+ params.pop_back();
if (!parser_next(parser) || (parser->tok != ')' && parser->tok != TOKEN_IDENT)) {
parseerror(parser, "`...` must be the last parameter of a variadic function declaration");
goto on_error;
}
}
- if (vec_size(params) == 1 && params[0]->expression.vtype == TYPE_VOID)
- vec_free(params);
+ if (params.size() == 1 && params[0]->expression.vtype == TYPE_VOID)
+ params.clear();
/* sanity check */
- if (vec_size(params) > 8 && OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCC)
+ if (params.size() > 8 && OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCC)
(void)!parsewarning(parser, WARN_EXTENSIONS, "more than 8 parameters are not supported by this standard");
/* parse-out */
/* now turn 'var' into a function type */
fval = ast_value_new(ctx, "<type()>", TYPE_FUNCTION);
- fval->expression.next = (ast_expression*)var;
+ fval->expression.next = (ast_expression*)var;
if (variadic)
fval->expression.flags |= AST_FLAG_VARIADIC;
var = fval;
- var->expression.params = params;
+ var->expression.params = params;
var->expression.varparam = (ast_expression*)varparam;
- var->argcounter = argcounter;
- params = NULL;
+ var->argcounter = argcounter;
return var;
if (varparam)
ast_delete(varparam);
ast_delete(var);
- for (i = 0; i < vec_size(params); ++i)
- ast_delete(params[i]);
- vec_free(params);
+ for (auto &it : params)
+ ast_delete(it);
return NULL;
}
goto cleanup;
}
/* we need the new parameter-names */
- for (i = 0; i < vec_size(proto->expression.params); ++i)
+ for (i = 0; i < proto->expression.params.size(); ++i)
ast_value_set_name(proto->expression.params[i], var->expression.params[i]->name);
if (!parser_check_qualifiers(parser, var, proto)) {
retval = false;
}
vec_free(defname);
} else {
- vec_push(localblock->locals, var);
+ localblock->locals.push_back(var);
parser_addlocal(parser, var->name, (ast_expression*)var);
if (isvector) {
for (i = 0; i < 3; ++i) {
if (!parse_function_body(parser, var))
break;
ast_delete(basetype);
- for (i = 0; i < vec_size(parser->gotos); ++i)
- parseerror(parser, "undefined label: `%s`", parser->gotos[i]->name);
- vec_free(parser->gotos);
- vec_free(parser->labels);
+ for (auto &it : parser->gotos)
+ parseerror(parser, "undefined label: `%s`", it->name);
return true;
} else {
ast_expression *cexp;
if (isvector) {
for (i = 0; i < 3; ++i) {
vec_pop(parser->_locals);
- vec_pop(localblock->collect);
+ localblock->collect.pop_back();
}
}
/* do sanity checking, this function really needs refactoring */
parseerror(parser, "internal error: unexpected change in local variable handling");
else
vec_pop(parser->_locals);
- if (vec_last(localblock->locals) != var)
+ if (localblock->locals.back() != var)
parseerror(parser, "internal error: unexpected change in local variable handling (2)");
else
- vec_pop(localblock->locals);
+ localblock->locals.pop_back();
/* push it to the to-be-generated globals */
vec_push(parser->globals, (ast_expression*)var);
if (isvector)
memset(parser, 0, sizeof(*parser));
+ // TODO: remove
+ new (parser) parser_t();
+
for (i = 0; i < operator_count; ++i) {
if (operators[i].id == opid1('=')) {
parser->assign_op = operators+i;
vec_free(parser->_block_ctx);
- vec_free(parser->labels);
- vec_free(parser->gotos);
- vec_free(parser->breaks);
- vec_free(parser->continues);
-
ast_value_delete(parser->nil);
ast_value_delete(parser->const_vec[0]);
cov = func->vtype;
expr = (ast_expression*)cov;
- if (expr->vtype != TYPE_FUNCTION || vec_size(expr->params) != 0) {
+ if (expr->vtype != TYPE_FUNCTION || expr->params.size()) {
char ty[1024];
ast_type_to_string(expr, ty, sizeof(ty));
con_out("invalid type for coverage(): %s\n", ty);
for (i = 0; i < vec_size(parser->functions); ++i) {
ast_function *f = parser->functions[i];
if (f->varargs) {
- if (parser->max_param_count > vec_size(f->vtype->expression.params)) {
- f->varargs->expression.count = parser->max_param_count - vec_size(f->vtype->expression.params);
+ 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_create_array_setter_impl(parser, f->varargs)) {
con_out("failed to generate vararg setter for %s\n", f->name);
ir_builder_delete(ir);
/* All the labels the function defined...
* Should they be in ast_function instead?
*/
- ast_label **labels;
- ast_goto **gotos;
- const char **breaks;
- const char **continues;
+ std::vector<ast_label*> labels;
+ std::vector<ast_goto*> gotos;
+ std::vector<const char *> breaks;
+ std::vector<const char *> continues;
/* A list of hashtables for each scope */
ht *variables;