static ast_expression* parser_expression_leave(parser_t *parser, bool stopatcomma);
static ast_expression* parser_expression(parser_t *parser, bool stopatcomma);
-void parseerror(parser_t *parser, const char *fmt, ...)
+static void parseerror(parser_t *parser, const char *fmt, ...)
{
va_list ap;
}
/* returns true if it counts as an error */
-bool GMQCC_WARN parsewarning(parser_t *parser, int warntype, const char *fmt, ...)
+static bool GMQCC_WARN parsewarning(parser_t *parser, int warntype, const char *fmt, ...)
{
va_list ap;
int lvl = LVL_WARNING;
return opts_werror;
}
+static bool GMQCC_WARN genwarning(lex_ctx ctx, int warntype, const char *fmt, ...)
+{
+ va_list ap;
+ int lvl = LVL_WARNING;
+
+ if (!OPTS_WARN(warntype))
+ return false;
+
+ if (opts_werror)
+ lvl = LVL_ERROR;
+
+ va_start(ap, fmt);
+ vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
+ va_end(ap);
+
+ return opts_werror;
+}
+
/**********************************************************************
* some maths used for constant folding
*/
{
size_t i;
ir_builder *ir;
+ bool retval = true;
if (!parser->errors)
{
}
}
for (i = 0; i < parser->globals_count; ++i) {
+ ast_value *asvalue;
if (!ast_istype(parser->globals[i].var, ast_value))
continue;
- if (!ast_global_codegen((ast_value*)(parser->globals[i].var), ir)) {
+ asvalue = (ast_value*)(parser->globals[i].var);
+ if (!asvalue->uses && !asvalue->isconst && asvalue->expression.vtype != TYPE_FUNCTION) {
+ retval = retval && !genwarning(ast_ctx(asvalue), WARN_UNUSED_VARIABLE,
+ "unused global: `%s`", asvalue->name);
+ }
+ if (!ast_global_codegen(asvalue, ir)) {
printf("failed to generate global %s\n", parser->globals[i].name);
ir_builder_delete(ir);
return false;
}
}
- if (opts_dump)
- ir_builder_dump(ir, printf);
+ if (retval) {
+ if (opts_dump)
+ ir_builder_dump(ir, printf);
- if (!ir_builder_generate(ir, output)) {
- printf("*** failed to generate output file\n");
- ir_builder_delete(ir);
- return false;
+ if (!ir_builder_generate(ir, output)) {
+ printf("*** failed to generate output file\n");
+ ir_builder_delete(ir);
+ return false;
+ }
}
ir_builder_delete(ir);
- return true;
+ return retval;
}
printf("*** there were compile errors\n");