MEM_VEC_FUNCTIONS(parser_t, ast_function*, functions)
static bool GMQCC_WARN parser_pop_local(parser_t *parser);
-static bool parser_variable(parser_t *parser, ast_block *localblock);
-static ast_block* parser_parse_block(parser_t *parser, bool warnreturn);
-static bool parser_parse_block_into(parser_t *parser, ast_block *block, bool warnreturn);
-static ast_expression* parser_parse_statement_or_block(parser_t *parser);
-static ast_expression* parser_expression_leave(parser_t *parser, bool stopatcomma);
-static ast_expression* parser_expression(parser_t *parser, bool stopatcomma);
+static bool parse_variable(parser_t *parser, ast_block *localblock);
+static ast_block* parse_block(parser_t *parser, bool warnreturn);
+static bool parse_block_into(parser_t *parser, ast_block *block, bool warnreturn);
+static ast_expression* parse_statement_or_block(parser_t *parser);
+static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma);
+static ast_expression* parse_expression(parser_t *parser, bool stopatcomma);
static void parseerror(parser_t *parser, const char *fmt, ...)
{
} paramlist_t;
MEM_VEC_FUNCTIONS(paramlist_t, ast_value*, p)
-static ast_value *parser_parse_type(parser_t *parser, int basetype, bool *isfunc)
+static ast_value *parse_type(parser_t *parser, int basetype, bool *isfunc)
{
paramlist_t params;
ast_value *var;
if (!parser_next(parser))
goto on_error;
- param = parser_parse_type(parser, temptype, &isfuncparam);
+ param = parse_type(parser, temptype, &isfuncparam);
if (!param)
goto on_error;
}
}
-static ast_expression* parser_expression_leave(parser_t *parser, bool stopatcomma)
+static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma)
{
ast_expression *expr = NULL;
shunt sy;
return NULL;
}
-static ast_expression* parser_expression(parser_t *parser, bool stopatcomma)
+static ast_expression* parse_expression(parser_t *parser, bool stopatcomma)
{
- ast_expression *e = parser_expression_leave(parser, stopatcomma);
+ ast_expression *e = parse_expression_leave(parser, stopatcomma);
if (!e)
return NULL;
if (!parser_next(parser)) {
return e;
}
-static bool parser_parse_if(parser_t *parser, ast_block *block, ast_expression **out)
+static bool parse_if(parser_t *parser, ast_block *block, ast_expression **out)
{
ast_ifthen *ifthen;
ast_expression *cond, *ontrue, *onfalse = NULL;
return false;
}
/* parse the condition */
- cond = parser_expression_leave(parser, false);
+ cond = parse_expression_leave(parser, false);
if (!cond)
return false;
/* closing paren */
ast_delete(cond);
return false;
}
- ontrue = parser_parse_statement_or_block(parser);
+ ontrue = parse_statement_or_block(parser);
if (!ontrue) {
ast_delete(cond);
return false;
ast_delete(cond);
return false;
}
- onfalse = parser_parse_statement_or_block(parser);
+ onfalse = parse_statement_or_block(parser);
if (!onfalse) {
ast_delete(ontrue);
ast_delete(cond);
return true;
}
-static bool parser_parse_while(parser_t *parser, ast_block *block, ast_expression **out)
+static bool parse_while(parser_t *parser, ast_block *block, ast_expression **out)
{
ast_loop *aloop;
ast_expression *cond, *ontrue;
return false;
}
/* parse the condition */
- cond = parser_expression_leave(parser, false);
+ cond = parse_expression_leave(parser, false);
if (!cond)
return false;
/* closing paren */
ast_delete(cond);
return false;
}
- ontrue = parser_parse_statement_or_block(parser);
+ ontrue = parse_statement_or_block(parser);
if (!ontrue) {
ast_delete(cond);
return false;
return true;
}
-static bool parser_parse_dowhile(parser_t *parser, ast_block *block, ast_expression **out)
+static bool parse_dowhile(parser_t *parser, ast_block *block, ast_expression **out)
{
ast_loop *aloop;
ast_expression *cond, *ontrue;
parseerror(parser, "expected loop body");
return false;
}
- ontrue = parser_parse_statement_or_block(parser);
+ ontrue = parse_statement_or_block(parser);
if (!ontrue)
return false;
return false;
}
/* parse the condition */
- cond = parser_expression_leave(parser, false);
+ cond = parse_expression_leave(parser, false);
if (!cond)
return false;
/* closing paren */
return true;
}
-static bool parser_parse_for(parser_t *parser, ast_block *block, ast_expression **out)
+static bool parse_for(parser_t *parser, ast_block *block, ast_expression **out)
{
ast_loop *aloop;
ast_expression *initexpr, *cond, *increment, *ontrue;
parseerror(parser, "TODO: assignment of new variables to be non-const");
goto onerr;
- if (!parser_variable(parser, block))
+ if (!parse_variable(parser, block))
goto onerr;
}
else if (parser->tok != ';')
{
- initexpr = parser_expression_leave(parser, false);
+ initexpr = parse_expression_leave(parser, false);
if (!initexpr)
goto onerr;
}
/* parse the condition */
if (parser->tok != ';') {
- cond = parser_expression_leave(parser, false);
+ cond = parse_expression_leave(parser, false);
if (!cond)
goto onerr;
}
/* parse the incrementor */
if (parser->tok != ')') {
- increment = parser_expression_leave(parser, false);
+ increment = parse_expression_leave(parser, false);
if (!increment)
goto onerr;
if (!ast_istype(increment, ast_store) &&
parseerror(parser, "expected for-loop body");
goto onerr;
}
- ontrue = parser_parse_statement_or_block(parser);
+ ontrue = parse_statement_or_block(parser);
if (!ontrue) {
goto onerr;
}
return false;
}
-static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expression **out)
+static bool parse_statement(parser_t *parser, ast_block *block, ast_expression **out)
{
if (parser->tok == TOKEN_TYPENAME)
{
if (parsewarning(parser, WARN_EXTENSIONS, "missing 'local' keyword when declaring a local variable"))
return false;
}
- if (!parser_variable(parser, block))
+ if (!parse_variable(parser, block))
return false;
*out = NULL;
return true;
parseerror(parser, "expected variable declaration");
return false;
}
- if (!parser_variable(parser, block))
+ if (!parse_variable(parser, block))
return false;
*out = NULL;
return true;
}
if (parser->tok != ';') {
- exp = parser_expression(parser, false);
+ exp = parse_expression(parser, false);
if (!exp)
return false;
}
else if (!strcmp(parser_tokval(parser), "if"))
{
- return parser_parse_if(parser, block, out);
+ return parse_if(parser, block, out);
}
else if (!strcmp(parser_tokval(parser), "while"))
{
- return parser_parse_while(parser, block, out);
+ return parse_while(parser, block, out);
}
else if (!strcmp(parser_tokval(parser), "do"))
{
- return parser_parse_dowhile(parser, block, out);
+ return parse_dowhile(parser, block, out);
}
else if (!strcmp(parser_tokval(parser), "for"))
{
if (parsewarning(parser, WARN_EXTENSIONS, "for loops are not recognized in the original Quake C standard, to enable try an alternate standard --std=?"))
return false;
}
- return parser_parse_for(parser, block, out);
+ return parse_for(parser, block, out);
}
parseerror(parser, "Unexpected keyword");
return false;
else if (parser->tok == '{')
{
ast_block *inner;
- inner = parser_parse_block(parser, false);
+ inner = parse_block(parser, false);
if (!inner)
return false;
*out = (ast_expression*)inner;
}
else
{
- ast_expression *exp = parser_expression(parser, false);
+ ast_expression *exp = parse_expression(parser, false);
if (!exp)
return false;
*out = exp;
return true;
}
-static bool parser_parse_block_into(parser_t *parser, ast_block *block, bool warnreturn)
+static bool parse_block_into(parser_t *parser, ast_block *block, bool warnreturn)
{
size_t oldblocklocal;
bool retval = true;
if (parser->tok == '}')
break;
- if (!parser_parse_statement(parser, block, &expr)) {
+ if (!parse_statement(parser, block, &expr)) {
parseerror(parser, "parse error");
block = NULL;
goto cleanup;
return !!block;
}
-static ast_block* parser_parse_block(parser_t *parser, bool warnreturn)
+static ast_block* parse_block(parser_t *parser, bool warnreturn)
{
ast_block *block;
block = ast_block_new(parser_ctx(parser));
if (!block)
return NULL;
- if (!parser_parse_block_into(parser, block, warnreturn)) {
+ if (!parse_block_into(parser, block, warnreturn)) {
ast_block_delete(block);
return NULL;
}
return block;
}
-static ast_expression* parser_parse_statement_or_block(parser_t *parser)
+static ast_expression* parse_statement_or_block(parser_t *parser)
{
ast_expression *expr = NULL;
if (parser->tok == '{')
- return (ast_expression*)parser_parse_block(parser, false);
- if (!parser_parse_statement(parser, NULL, &expr))
+ return (ast_expression*)parse_block(parser, false);
+ if (!parse_statement(parser, NULL, &expr))
return NULL;
return expr;
}
return false;
}
-static bool parser_variable(parser_t *parser, ast_block *localblock)
+static bool parse_variable(parser_t *parser, ast_block *localblock)
{
bool isfunc = false;
lex_ctx ctx;
return false;
}
- typevar = parser_parse_type(parser, basetype, &isfunc);
+ typevar = parse_type(parser, basetype, &isfunc);
if (!typevar)
return false;
return false;
}
- framenum = parser_expression_leave(parser, true);
+ framenum = parse_expression_leave(parser, true);
if (!framenum) {
parseerror(parser, "expected a framenumber constant in[frame,think] notation");
ast_value_delete(typevar);
nextthink = (ast_expression*)thinkfunc;
} else {
- nextthink = parser_expression_leave(parser, true);
+ nextthink = parse_expression_leave(parser, true);
if (!nextthink) {
ast_unref(framenum);
parseerror(parser, "expected a think-function in [frame,think] notation");
}
parser->function = func;
- if (!parser_parse_block_into(parser, block, true)) {
+ if (!parse_block_into(parser, block, true)) {
ast_block_delete(block);
parser->function = old;
ast_value_delete(typevar);
ast_expression *cexp;
ast_value *cval;
- cexp = parser_expression_leave(parser, true);
+ cexp = parse_expression_leave(parser, true);
if (!cexp) {
ast_value_delete(typevar);
return false;
}
}
-static bool parser_do(parser_t *parser)
+static bool parser_global_statement(parser_t *parser)
{
if (parser->tok == TOKEN_TYPENAME)
{
- return parser_variable(parser, NULL);
+ return parse_variable(parser, NULL);
}
else if (parser->tok == TOKEN_KEYWORD)
{
}
/* parse the field type fully */
- typevar = var = parser_parse_type(parser, basetype, &isfunc);
+ typevar = var = parse_type(parser, basetype, &isfunc);
if (!var)
return false;
{
while (parser->tok != TOKEN_EOF && parser->tok < TOKEN_ERROR)
{
- if (!parser_do(parser)) {
+ if (!parser_global_statement(parser)) {
if (parser->tok == TOKEN_EOF)
parseerror(parser, "unexpected eof");
else if (!parser->errors)