From: Wolfgang (Blub) Bumiller Date: Thu, 23 Aug 2012 17:01:15 +0000 (+0200) Subject: the -std=qcc set of operators, still have to verify if it's the original X-Git-Tag: 0.1-rc1~68 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=19391bb1907c1727b50a32c2766fb9ee6b215b61;p=xonotic%2Fgmqcc.git the -std=qcc set of operators, still have to verify if it's the original --- diff --git a/lexer.h b/lexer.h index a2f06ac..c84b208 100644 --- 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 853941d..5445303 100644 --- 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));