bool output_on;
ppcondition *conditions;
/*ppmacro **macros;*/
- ht macros; /* hashtable<string, ppmacro*> */
-
+ ht macros; /* hashtable<string, ppmacro*> */
char *output_string;
char *itemname;
return value;
}
-const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT] = {
+typedef struct {
+ const char *name;
+ char *(*func)(lex_file *);
+} ftepp_predef_t;
+
+static const ftepp_predef_t ftepp_predefs[] = {
{ "__LINE__", &ftepp_predef_line },
{ "__FILE__", &ftepp_predef_file },
{ "__COUNTER__", &ftepp_predef_counter },
{ "__TIME_STAMP__", &ftepp_predef_timestamp }
};
+static GMQCC_INLINE int ftepp_predef_index(const char *name) {
+ /* no hashtable here, we simply check for one to exist the naive way */
+ int i;
+ for(i = 0; i < (int)(sizeof(ftepp_predefs)/sizeof(*ftepp_predefs)); i++)
+ if (!strcmp(ftepp_predefs[i].name, name))
+ return i;
+ return -1;
+}
+
+bool ftepp_predef_exists(const char *name) {
+ return ftepp_predef_index(name) != -1;
+}
+
+/* singleton because we're allowed */
+static GMQCC_INLINE char *(*ftepp_predef(const char *name))(lex_file *context) {
+ int i = ftepp_predef_index(name);
+ return (i != -1) ? ftepp_predefs[i].func : NULL;
+}
+
#define ftepp_tokval(f) ((f)->lex->tok.value)
#define ftepp_ctx(f) ((f)->lex->tok.ctx)
/* predef stuff */
char *expand = NULL;
- size_t i;
ftepp->lex->flags.preprocessing = true;
ftepp->lex->flags.mergelines = false;
case TOKEN_TYPENAME:
/* is it a predef? */
if (OPTS_FLAG(FTEPP_PREDEFS)) {
- for (i = 0; i < sizeof(ftepp_predefs) / sizeof (*ftepp_predefs); i++) {
- if (!strcmp(ftepp_predefs[i].name, ftepp_tokval(ftepp))) {
- expand = ftepp_predefs[i].func(ftepp->lex);
- ftepp_out(ftepp, expand, false);
- ftepp_next(ftepp); /* skip */
-
- mem_d(expand); /* free memory */
- break;
- }
+ char *(*predef)(lex_file*) = ftepp_predef(ftepp_tokval(ftepp));
+ if (predef) {
+ expand = predef(ftepp->lex);
+ ftepp_out (ftepp, expand, false);
+ ftepp_next(ftepp);
+
+ mem_d(expand);
+ break;
}
}
struct lex_file_s;
struct ftepp_s;
-typedef struct {
- const char *name;
- char *(*func)(struct lex_file_s *);
-} ftepp_predef_t;
-
/*
* line, file, counter, counter_last, random, random_last, date, time
* time_stamp.
void ftepp_add_define (struct ftepp_s *ftepp, const char *source, const char *name);
void ftepp_add_macro (struct ftepp_s *ftepp, const char *name, const char *value);
-extern const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT];
-
/*===================================================================*/
/*======================= main.c commandline ========================*/
/*===================================================================*/
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;
}
/*