/* collected information */
size_t max_param_count;
+
+ /* code generator */
+ code_t *code;
} parser_t;
static ast_expression * const intrinsic_debug_typestring = (ast_expression*)0x1;
return out;
}
+/* not to be exposed */
+extern bool ftepp_predef_exists(const char *name);
+
static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
{
if (OPTS_FLAG(TRANSLATABLE_STRINGS) &&
* i've done this thousands of times already myself. Lets check for
* it in the predef table. And diagnose it better :)
*/
- if (!OPTS_FLAG(FTEPP_PREDEFS)) {
- for (i = 0; i < sizeof(ftepp_predefs)/sizeof(*ftepp_predefs); i++) {
- if (!strcmp(ftepp_predefs[i].name, parser_tokval(parser))) {
- parseerror(parser, "unexpected ident: %s (use -fftepp-predef to enable pre-defined macros)", parser_tokval(parser));
- return false;
- }
- }
+ if (!OPTS_FLAG(FTEPP_PREDEFS) && ftepp_predef_exists(parser_tokval(parser))) {
+ parseerror(parser, "unexpected ident: %s (use -fftepp-predef to enable pre-defined macros)", parser_tokval(parser));
+ return false;
}
/*
}
}
- if (parser->tok != '{') {
+ if (parser->tok != '{' || var->expression.vtype != TYPE_FUNCTION) {
if (parser->tok != '=') {
parseerror(parser, "missing semicolon or initializer, got: `%s`", parser_tokval(parser));
break;
}
if (parser->tok == '#') {
- ast_function *func = NULL;
+ ast_function *func = NULL;
+ ast_value *number = NULL;
+ float fractional;
+ float integral;
+ int builtin_num;
if (localblock) {
parseerror(parser, "cannot declare builtins within functions");
parseerror(parser, "expected builtin number");
break;
}
- if (parser->tok != TOKEN_INTCONST) {
- parseerror(parser, "builtin number must be an integer constant");
- break;
- }
- if (parser_token(parser)->constval.i < 0) {
- parseerror(parser, "builtin number must be an integer greater than zero");
+
+ if (OPTS_FLAG(EXPRESSIONS_FOR_BUILTINS)) {
+ number = (ast_value*)parse_expression_leave(parser, true, false, false);
+ if (!number) {
+ parseerror(parser, "builtin number expected");
+ break;
+ }
+ if (!ast_istype(number, ast_value) || !number->hasvalue || number->cvq != CV_CONST)
+ {
+ ast_unref(number);
+ parseerror(parser, "builtin number must be a compile time constant");
+ break;
+ }
+ if (number->expression.vtype == TYPE_INTEGER)
+ builtin_num = number->constval.vint;
+ else if (number->expression.vtype == TYPE_FLOAT)
+ builtin_num = number->constval.vfloat;
+ else {
+ ast_unref(number);
+ parseerror(parser, "builtin number must be an integer constant");
+ break;
+ }
+ ast_unref(number);
+
+ fractional = modff(builtin_num, &integral);
+ if (builtin_num < 0 || fractional != 0) {
+ parseerror(parser, "builtin number must be an integer greater than zero");
+ break;
+ }
+
+ /* we only want the integral part anyways */
+ builtin_num = integral;
+ } else if (parser->tok == TOKEN_INTCONST) {
+ builtin_num = parser_token(parser)->constval.i;
+ } else {
+ parseerror(parser, "builtin number must be a compile time constant");
break;
}
}
vec_push(parser->functions, func);
- func->builtin = -parser_token(parser)->constval.i-1;
+ func->builtin = -builtin_num-1;
}
- if (!parser_next(parser)) {
+ if (OPTS_FLAG(EXPRESSIONS_FOR_BUILTINS)
+ ? (parser->tok != ',' && parser->tok != ';')
+ : (!parser_next(parser)))
+ {
parseerror(parser, "expected comma or semicolon");
if (func)
ast_function_delete(func);
break;
}
}
- else if (parser->tok == '{' || parser->tok == '[')
+ else if (var->expression.vtype == TYPE_ARRAY && parser->tok == '{')
+ {
+ if (localblock) {
+ /* Note that fteqcc and most others don't even *have*
+ * local arrays, so this is not a high priority.
+ */
+ parseerror(parser, "TODO: initializers for local arrays");
+ break;
+ }
+ /*
+static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels);
+*/
+ parseerror(parser, "TODO: initializing global arrays is not supported yet!");
+ break;
+ }
+ else if (var->expression.vtype == TYPE_FUNCTION && (parser->tok == '{' || parser->tok == '['))
{
if (localblock) {
parseerror(parser, "cannot declare functions within functions");
}
crc = progdefs_crc_both(crc, "} entvars_t;\n\n");
- code_crc = crc;
+ parser->code->crc = crc;
}
parser_t *parser_create()
memset(parser, 0, sizeof(*parser));
+ if (!(parser->code = code_init())) {
+ mem_d(parser);
+ return NULL;
+ }
+
+
for (i = 0; i < operator_count; ++i) {
if (operators[i].id == opid1('=')) {
parser->assign_op = operators+i;
generate_checksum(parser);
- if (!ir_builder_generate(ir, output)) {
+ if (!ir_builder_generate(parser->code, ir, output)) {
con_out("*** failed to generate output file\n");
ir_builder_delete(ir);
return false;