mem_d(self);
}
-static ftepp_t* ftepp_init()
+static ftepp_t* ftepp_new()
{
ftepp_t *ftepp;
ftepp->output_string = old_string_flag;
ftepp->lex = inlex;
if (!ftepp_preprocess(ftepp)) {
+ lex_close(ftepp->lex);
retval = false;
goto cleanup;
}
return newline;
}
+/* Like in parser.c - files keep the previous state so we have one global
+ * preprocessor. Except here we will want to warn about dangling #ifs.
+ */
+static ftepp_t *ftepp;
+
+static bool ftepp_preprocess_done()
+{
+ bool retval = true;
+ lex_close(ftepp->lex);
+ ftepp->lex = NULL;
+ if (vec_size(ftepp->conditions)) {
+ if (ftepp_warn(ftepp, WARN_MULTIFILE_IF, "#if spanning multiple files, is this intended?"))
+ retval = false;
+ }
+ return retval;
+}
+
bool ftepp_preprocess_file(const char *filename)
{
- ftepp_t *ftepp = ftepp_init();
ftepp->lex = lex_open(filename);
if (!ftepp->lex) {
con_out("failed to open file \"%s\"\n", filename);
ftepp_delete(ftepp);
return false;
}
- ftepp_delete(ftepp);
- return true;
+ return ftepp_preprocess_done();
}
bool ftepp_preprocess_string(const char *name, const char *str)
{
- ftepp_t *ftepp = ftepp_init();
+ ftepp_t *ftepp = ftepp_new();
ftepp->lex = lex_open_string(str, strlen(str), name);
if (!ftepp->lex) {
con_out("failed to create lexer for string \"%s\"\n", name);
ftepp_delete(ftepp);
return false;
}
+ return ftepp_preprocess_done();
+}
+
+bool ftepp_init()
+{
+ ftepp = ftepp_new();
+ return !!ftepp;
+}
+
+void ftepp_finish()
+{
ftepp_delete(ftepp);
- return true;
}
/*===================================================================*/
/*====================== ftepp.c commandline ========================*/
/*===================================================================*/
+bool ftepp_init ();
bool ftepp_preprocess_file (const char *filename);
bool ftepp_preprocess_string(const char *name, const char *str);
+void ftepp_finish ();
/*===================================================================*/
/*======================= main.c commandline ========================*/
options_set(opts_warn, WARN_END_SYS_FIELDS, true);
options_set(opts_warn, WARN_ASSIGN_FUNCTION_TYPES, true);
options_set(opts_warn, WARN_PREPROCESSOR, true);
+ options_set(opts_warn, WARN_MULTIFILE_IF, true);
options_set(opts_flags, ADJUST_VECTOR_FIELDS, true);
con_out("standard = %i\n", opts_standard);
}
- if (!parser_init()) {
- con_out("failed to initialize parser\n");
- retval = 1;
- goto cleanup;
+ if (!opts_pp_only) {
+ if (!parser_init()) {
+ con_err("failed to initialize parser\n");
+ retval = 1;
+ goto cleanup;
+ }
+ }
+ if (opts_pp_only || opts_standard == COMPILER_FTEQCC) {
+ if (!ftepp_init()) {
+ con_err("failed to initialize parser\n");
+ retval = 1;
+ goto cleanup;
+ }
}
util_debug("COM", "starting ...\n");
GMQCC_DEFINE_FLAG(END_SYS_FIELDS)
GMQCC_DEFINE_FLAG(ASSIGN_FUNCTION_TYPES)
GMQCC_DEFINE_FLAG(PREPROCESSOR)
+ GMQCC_DEFINE_FLAG(MULTIFILE_IF)
#endif
/* some cleanup so we don't have to */