]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
the -std=qcc set of operators, still have to verify if it's the original
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 23 Aug 2012 17:01:15 +0000 (19:01 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 23 Aug 2012 17:01:15 +0000 (19:01 +0200)
lexer.h
main.c

diff --git a/lexer.h b/lexer.h
index a2f06acf7cb189ebff47fcdbb10bea2698583d31..c84b2084ee57c0e854696b886b79f0132ce42d42 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -143,7 +143,7 @@ typedef struct {
 #define opid2(a,b) ((a<<8)|b)
 #define opid3(a,b,c) ((a<<16)|(b<<8)|c)
 
-static const oper_info operators[] = {
+static const oper_info c_operators[] = {
     { "(",   0, opid1('('),         ASSOC_LEFT,  99, OP_PREFIX}, /* paren expression - non function call */
 
     { "++",  1, opid3('S','+','+'), ASSOC_LEFT,  16, OP_SUFFIX},
@@ -204,7 +204,51 @@ static const oper_info operators[] = {
 
     { ",",   2, opid1(','),         ASSOC_LEFT,  1,  0 }
 };
-static const size_t operator_count = (sizeof(operators) / sizeof(operators[0]));
+static const size_t c_operator_count = (sizeof(c_operators) / sizeof(c_operators[0]));
+
+static const oper_info qcc_operators[] = {
+    { "(",   0, opid1('('),         ASSOC_LEFT,  99, OP_PREFIX}, /* paren expression - non function call */
+
+    { ".",   2, opid1('.'),         ASSOC_LEFT,  15, 0 },
+    { "(",   0, opid1('('),         ASSOC_LEFT,  15, 0 }, /* function call */
+
+    { "!",   1, opid2('!', 'P'),    ASSOC_RIGHT, 14, OP_PREFIX },
+    { "+",   1, opid2('+','P'),     ASSOC_RIGHT, 14, OP_PREFIX },
+    { "-",   1, opid2('-','P'),     ASSOC_RIGHT, 14, OP_PREFIX },
+
+    { "*",   2, opid1('*'),         ASSOC_LEFT,  13, 0 },
+    { "/",   2, opid1('/'),         ASSOC_LEFT,  13, 0 },
+    { "&",   2, opid1('&'),         ASSOC_LEFT,  13, 0 },
+    { "|",   2, opid1('|'),         ASSOC_LEFT,  13, 0 },
+
+    { "+",   2, opid1('+'),         ASSOC_LEFT,  12, 0 },
+    { "-",   2, opid1('-'),         ASSOC_LEFT,  12, 0 },
+
+    { "<",   2, opid1('<'),         ASSOC_LEFT,  10, 0 },
+    { ">",   2, opid1('>'),         ASSOC_LEFT,  10, 0 },
+    { "<=",  2, opid2('<','='),     ASSOC_LEFT,  10, 0 },
+    { ">=",  2, opid2('>','='),     ASSOC_LEFT,  10, 0 },
+    { "==",  2, opid2('=','='),     ASSOC_LEFT,  10,  0 },
+    { "!=",  2, opid2('!','='),     ASSOC_LEFT,  10,  0 },
+
+    { "=",   2, opid1('='),         ASSOC_RIGHT, 8,  0 },
+    { "+=",  2, opid2('+','='),     ASSOC_RIGHT, 8,  0 },
+    { "-=",  2, opid2('-','='),     ASSOC_RIGHT, 8,  0 },
+    { "*=",  2, opid2('*','='),     ASSOC_RIGHT, 8,  0 },
+    { "/=",  2, opid2('/','='),     ASSOC_RIGHT, 8,  0 },
+    { "%=",  2, opid2('%','='),     ASSOC_RIGHT, 8,  0 },
+    { "&=",  2, opid2('&','='),     ASSOC_RIGHT, 8,  0 },
+    { "|=",  2, opid2('|','='),     ASSOC_RIGHT, 8,  0 },
+
+    { "&&",  2, opid2('&','&'),     ASSOC_LEFT,  5,  0 },
+    { "||",  2, opid2('|','|'),     ASSOC_LEFT,  5,  0 },
+
+    { ",",   2, opid1(','),         ASSOC_LEFT,  1,  0 }
+};
+static const size_t qcc_operator_count = (sizeof(qcc_operators) / sizeof(qcc_operators[0]));
+
+extern const oper_info *operators;
+extern size_t           operator_count;
 
 typedef struct
 {
diff --git a/main.c b/main.c
index 853941debb97d6bb1f0c0c2b9f6079860dd8a30f..544530380b519118f1d2acee4bc99acb8525b084 100644 (file)
--- a/main.c
+++ b/main.c
@@ -39,6 +39,10 @@ uint16_t    opts_forced_crc;
 
 static bool opts_output_wasset = false;
 
+/* set by the standard */
+const oper_info *operators      = NULL;
+size_t           operator_count = 0;
+
 typedef struct { char *filename; int type; } argitem;
 VECTOR_MAKE(argitem, items);
 
@@ -401,6 +405,15 @@ int main(int argc, char **argv) {
         return usage();
     }
 
+    /* the standard decides which set of operators to use */
+    if (opts_standard == COMPILER_GMQCC) {
+        operators = c_operators;
+        operator_count = c_operator_count;
+    } else {
+        operators = qcc_operators;
+        operator_count = qcc_operator_count;
+    }
+
     if (opts_dump) {
         for (itr = 0; itr < COUNT_FLAGS; ++itr) {
             printf("Flag %s = %i\n", opts_flag_list[itr].name, OPTS_FLAG(itr));