size_t *_blocklocals;
ast_value **_typedefs;
size_t *_blocktypedefs;
+ lex_ctx *_block_ctx;
size_t errors;
static bool parser_leaveblock(parser_t *parser);
static void parser_addlocal(parser_t *parser, const char *name, ast_expression *e);
static bool parse_typedef(parser_t *parser);
-static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofields, int is_const_var, ast_value *cached_typedef);
+static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofields, int qualifier, ast_value *cached_typedef);
static ast_block* parse_block(parser_t *parser);
static bool parse_block_into(parser_t *parser, ast_block *block);
static ast_expression* parse_statement_or_block(parser_t *parser);
parseerror(parser, "unexpected ident: %s", parser_tokval(parser));
goto onerr;
}
- if (ast_istype(var, ast_value))
+ if (ast_istype(var, ast_value)) {
((ast_value*)var)->uses++;
+ }
+ else if (ast_istype(var, ast_member)) {
+ ast_member *mem = (ast_member*)var;
+ if (ast_istype(mem->owner, ast_value))
+ ((ast_value*)(mem->owner))->uses++;
+ }
vec_push(sy.out, syexp(parser_ctx(parser), var));
DEBUGSHUNTDO(con_out("push %s\n", parser_tokval(parser)));
}
vec_push(parser->_blocklocals, vec_size(parser->_locals));
vec_push(parser->typedefs, util_htnew(TYPEDEF_HT_SIZE));
vec_push(parser->_blocktypedefs, vec_size(parser->_typedefs));
+ vec_push(parser->_block_ctx, parser_ctx(parser));
}
static bool parser_leaveblock(parser_t *parser)
ast_value *v = (ast_value*)e;
vec_pop(parser->_locals);
if (ast_istype(e, ast_value) && !v->uses) {
- if (parsewarning(parser, WARN_UNUSED_VARIABLE, "unused variable: `%s`", v->name))
+ if (compile_warning(ast_ctx(v), WARN_UNUSED_VARIABLE, "unused variable: `%s`", v->name)) {
+ parser->errors++;
rv = false;
+ }
}
}
util_htdel(vec_last(parser->typedefs));
vec_pop(parser->typedefs);
+ vec_pop(parser->_block_ctx);
return rv;
}
ast_return *ret = NULL;
ast_value *expected = parser->function->vtype;
+ lex_ctx ctx = parser_ctx(parser);
+
(void)block; /* not touching */
if (!parser_next(parser)) {
else
parseerror(parser, "return without value");
}
- ret = ast_return_new(parser_ctx(parser), NULL);
+ ret = ast_return_new(ctx, NULL);
}
*out = (ast_expression*)ret;
return true;
return true;
}
-static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofields, int is_const_var, ast_value *cached_typedef)
+static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofields, int qualifier, ast_value *cached_typedef)
{
ast_value *var;
ast_value *proto;
}
}
- if (is_const_var == CV_CONST)
- var->cvq = CV_CONST;
+ var->cvq = qualifier;
/* Part 1:
* check for validity: (end_sys_..., multiple-definitions, prototypes, ...)
{
if (opts_standard != COMPILER_GMQCC &&
!OPTS_FLAG(INITIALIZED_NONCONSTANTS) &&
- is_const_var != CV_VAR)
+ qualifier != CV_VAR)
{
var->cvq = CV_CONST;
}
vec_free(parser->typedefs);
vec_free(parser->_blocktypedefs);
+ vec_free(parser->_block_ctx);
+
vec_free(parser->labels);
vec_free(parser->gotos);