From 1364bff91b939472af0fc7695e7d81f76d6dcc08 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 14 Jul 2012 16:32:48 +0900 Subject: [PATCH] Add an extended mode to qfcc. Extended mode allows extra keywords (switch, for, etc) that are compatible with v6 progs. --- tools/qfcc/doc/man/qfcc.1 | 3 +++ tools/qfcc/include/options.h | 2 +- tools/qfcc/source/options.c | 16 ++++++++++++--- tools/qfcc/source/qc-lex.l | 38 ++++++++++++++++++------------------ 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/tools/qfcc/doc/man/qfcc.1 b/tools/qfcc/doc/man/qfcc.1 index 3f009f4ac..de49c35c5 100644 --- a/tools/qfcc/doc/man/qfcc.1 +++ b/tools/qfcc/doc/man/qfcc.1 @@ -68,6 +68,9 @@ Define a symbol for the preprocessor, if it is in use. Only preprocess. No compilation or linking is done. .TP +.B \-\-extended +Allow extended keywords in traditional mode. +.TP .B \-F, \-\-files Generate \fIfiles.dat\fP. This list is created by checking the parameters to the precache_* functions. diff --git a/tools/qfcc/include/options.h b/tools/qfcc/include/options.h index 3ebf156a8..4dc5e0bd6 100644 --- a/tools/qfcc/include/options.h +++ b/tools/qfcc/include/options.h @@ -89,7 +89,7 @@ typedef struct { qboolean files_dat; // generate files.dat qboolean progdefs_h; // generate progdefs.h qboolean qccx_escapes; // use qccx escapes instead of standard C - qboolean traditional; // behave more like qcc + int traditional; // behave more like qcc qboolean advanced; // behold the power of Ruamoko qboolean compile; // serparate compilation mode qboolean partial_link; // partial linking diff --git a/tools/qfcc/source/options.c b/tools/qfcc/source/options.c index 499ff1b88..f843c560c 100644 --- a/tools/qfcc/source/options.c +++ b/tools/qfcc/source/options.c @@ -62,6 +62,7 @@ enum { OPT_ADVANCED, OPT_BLOCK_DOT, OPT_CPP, + OPT_EXTENDED, OPT_INCLUDE, OPT_NO_DEFAULT_PATHS, OPT_PROGDEFS, @@ -75,6 +76,7 @@ static struct option const long_options[] = { {"code", required_argument, 0, 'C'}, {"cpp", required_argument, 0, OPT_CPP}, {"define", required_argument, 0, 'D'}, + {"extended", no_argument, 0, OPT_EXTENDED}, {"files", no_argument, 0, 'F'}, {"help", no_argument, 0, 'h'}, {"include", required_argument, 0, OPT_INCLUDE}, @@ -139,6 +141,7 @@ usage (int status) " --cpp CPPSPEC cpp execution command line\n" " -D, --define SYMBOL[=VAL] Define symbols for the preprocessor\n" " -E Only preprocess\n" +" --extended Allow extended keywords in traditional mode\n" " -F, --files Generate files.dat\n" " -g Generate debugging info\n" " -h, --help Display this help and exit\n" @@ -351,13 +354,18 @@ DecodeArgs (int argc, char **argv) case 'g': // debug options.code.debug = true; break; + case OPT_EXTENDED: + options.traditional = 1; + options.advanced = false; + options.code.progsversion = PROG_ID_VERSION; + break; case OPT_TRADITIONAL: - options.traditional = true; + options.traditional = 2; options.advanced = false; options.code.progsversion = PROG_ID_VERSION; break; case OPT_ADVANCED: - options.traditional = false; + options.traditional = 0; options.advanced = true; options.code.progsversion = PROG_VERSION; break; @@ -593,7 +601,9 @@ DecodeArgs (int argc, char **argv) options.preprocess_only = 0; if (!source_files && !options.advanced) { // progs.src mode without --advanced implies --traditional - options.traditional = true; + // but --extended overrides + if (!options.traditional) + options.traditional = 2; options.advanced = false; if (!options.code.progsversion) options.code.progsversion = PROG_ID_VERSION; diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index 647257947..9b5c0e1fa 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -256,17 +256,17 @@ typedef struct { const char *name; int value; type_t *type; - unsigned int traditional; - unsigned int version; + int traditional; + unsigned version; int objc; } keyword_t; static keyword_t keywords[] = { - {"void", TYPE, &type_void, 1, PROG_ID_VERSION, 0}, - {"float", TYPE, &type_float, 1, PROG_ID_VERSION, 0}, - {"string", TYPE, &type_string, 1, PROG_ID_VERSION, 0}, - {"vector", TYPE, &type_vector, 1, PROG_ID_VERSION, 0}, - {"entity", TYPE, &type_entity, 1, PROG_ID_VERSION, 0}, + {"void", TYPE, &type_void, 2, PROG_ID_VERSION, 0}, + {"float", TYPE, &type_float, 2, PROG_ID_VERSION, 0}, + {"string", TYPE, &type_string, 2, PROG_ID_VERSION, 0}, + {"vector", TYPE, &type_vector, 2, PROG_ID_VERSION, 0}, + {"entity", TYPE, &type_entity, 2, PROG_ID_VERSION, 0}, {"quaternion", TYPE, &type_quaternion, 0, PROG_VERSION, 0}, {"int", TYPE, &type_integer, 0, PROG_VERSION, 0}, {"unsigned", TYPE, &type_integer, 0, PROG_VERSION, 0},//FIXME @@ -278,18 +278,18 @@ static keyword_t keywords[] = { {"Super", TYPE, &type_Super, 0, PROG_VERSION, 1}, {"SEL", TYPE, &type_SEL, 0, PROG_VERSION, 1}, {"IMP", TYPE, &type_IMP, 0, PROG_VERSION, 1}, - {"local", LOCAL, 0, 1, PROG_ID_VERSION, 0}, - {"return", RETURN, 0, 1, PROG_ID_VERSION, 0}, - {"while", WHILE, 0, 1, PROG_ID_VERSION, 0}, - {"do", DO, 0, 1, PROG_ID_VERSION, 0}, - {"if", IF, 0, 1, PROG_ID_VERSION, 0}, - {"else", ELSE, 0, 1, PROG_ID_VERSION, 0}, - {"for", FOR, 0, 0, PROG_ID_VERSION, 0}, - {"break", BREAK, 0, 1, PROG_ID_VERSION, 0}, - {"continue", CONTINUE, 0, 0, PROG_ID_VERSION, 0}, - {"switch", SWITCH, 0, 0, PROG_ID_VERSION, 0}, - {"case", CASE, 0, 0, PROG_ID_VERSION, 0}, - {"default", DEFAULT, 0, 0, PROG_ID_VERSION, 0}, + {"local", LOCAL, 0, 2, PROG_ID_VERSION, 0}, + {"return", RETURN, 0, 2, PROG_ID_VERSION, 0}, + {"while", WHILE, 0, 2, PROG_ID_VERSION, 0}, + {"do", DO, 0, 2, PROG_ID_VERSION, 0}, + {"if", IF, 0, 2, PROG_ID_VERSION, 0}, + {"else", ELSE, 0, 2, PROG_ID_VERSION, 0}, + {"for", FOR, 0, 1, PROG_ID_VERSION, 0}, + {"break", BREAK, 0, 2, PROG_ID_VERSION, 0}, + {"continue", CONTINUE, 0, 1, PROG_ID_VERSION, 0}, + {"switch", SWITCH, 0, 1, PROG_ID_VERSION, 0}, + {"case", CASE, 0, 1, PROG_ID_VERSION, 0}, + {"default", DEFAULT, 0, 1, PROG_ID_VERSION, 0}, {"nil", NIL, 0, 0, PROG_ID_VERSION, 0}, {"struct", STRUCT, 0, 0, PROG_VERSION, 0}, {"union", STRUCT, 0, 0, PROG_VERSION, 0},