diff --git a/gmqcc.h b/gmqcc.h index b1e0cde..9223e4f 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -175,13 +175,7 @@ typedef struct { char _fail : 0; } int64_t; typedef struct { char _fail : 0; } uint64_t; #endif -#ifdef _LP64 /* long pointer == 64 */ - typedef unsigned long uintptr_t; - typedef long intptr_t; -#else - typedef unsigned int uintptr_t; - typedef int intptr_t; -#endif + /* Ensure type sizes are correct: */ typedef char uint8_size_is_correct [sizeof(uint8_t) == 1?1:-1]; typedef char uint16_size_is_correct [sizeof(uint16_t) == 2?1:-1]; @@ -190,10 +184,6 @@ typedef char uint64_size_is_correct [sizeof(uint64_t) == 8?1:-1]; typedef char int16_size_if_correct [sizeof(int16_t) == 2?1:-1]; typedef char int32_size_is_correct [sizeof(int32_t) == 4?1:-1]; typedef char int64_size_is_correct [sizeof(int64_t) >= 8?1:-1]; -/* intptr_t / uintptr_t correct size check */ -typedef char uintptr_size_is_correct[sizeof(intptr_t) == sizeof(int*)?1:-1]; -typedef char intptr_size_is_correct [sizeof(uintptr_t)== sizeof(int*)?1:-1]; - /*===================================================================*/ /*=========================== util.c ================================*/ /*===================================================================*/ diff --git a/ir.c b/ir.c index 48cc067..ea7476b 100644 --- a/ir.c +++ b/ir.c @@ -3542,8 +3542,8 @@ bool ir_builder_generate(ir_builder *self, const char *filename) #define IND_BUFSZ 1024 -#ifdef WIN32 -# define strncat(dst, src, sz) strncat_s(dst, sz, src, _TRUNCATE) +#ifdef _MSC_VER +# define strncat(dst, src, sz) strncat_s(dst, sz, src, _TRUNCATE) #endif const char *qc_opname(int op) diff --git a/opts.def b/opts.def index 157f80f..f1adc7a 100644 --- a/opts.def +++ b/opts.def @@ -39,7 +39,6 @@ GMQCC_DEFINE_FLAG(ASSIGN_FUNCTION_TYPES) GMQCC_DEFINE_FLAG(LNO) GMQCC_DEFINE_FLAG(CORRECT_TERNARY) - GMQCC_DEFINE_FLAG(SINGLE_VECTOR_DEFS) #endif /* warning flags */ diff --git a/parser.c b/parser.c index 6f2ddd8..852da53 100644 --- a/parser.c +++ b/parser.c @@ -98,8 +98,6 @@ typedef struct { bool noref; } parser_t; -static const ast_expression *intrinsic_debug_typestring = (ast_expression*)0x10; - static void parser_enterblock(parser_t *parser); static bool parser_leaveblock(parser_t *parser); static void parser_addlocal(parser_t *parser, const char *name, ast_expression *e); @@ -837,19 +835,13 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) return false; } #endif + if (opts.standard == COMPILER_GMQCC) + con_out("TODO: early out logic\n"); if (CanConstFold(exprs[0], exprs[1])) out = (ast_expression*)parser_const_float(parser, (generated_op == INSTR_OR ? (ConstF(0) || ConstF(1)) : (ConstF(0) && ConstF(1)))); else - { - if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) { - ast_type_to_string(exprs[0], ty1, sizeof(ty1)); - ast_type_to_string(exprs[1], ty2, sizeof(ty2)); - parseerror(parser, "invalid types for logical operation with -fperl-logic: %s and %s", ty1, ty2); - return false; - } out = (ast_expression*)ast_binary_new(ctx, generated_op, exprs[0], exprs[1]); - } break; case opid2('?',':'): @@ -1200,25 +1192,9 @@ static bool parser_close_call(parser_t *parser, shunt *sy) fun = sy->out[fid].out; - if (fun == intrinsic_debug_typestring) { - char ty[1024]; - if (fid+2 != vec_size(sy->out) || - vec_last(sy->out).block) - { - parseerror(parser, "intrinsic __builtin_debug_typestring requires exactly 1 parameter"); - return false; - } - ast_type_to_string(vec_last(sy->out).out, ty, sizeof(ty)); - ast_unref(vec_last(sy->out).out); - sy->out[fid] = syexp(ast_ctx(vec_last(sy->out).out), - (ast_expression*)parser_const_string(parser, ty, false)); - vec_shrinkby(sy->out, 1); - return true; - } - call = ast_call_new(sy->ops[vec_size(sy->ops)].ctx, fun); if (!call) { - parseerror(parser, "internal error: failed to create ast_call node"); + parseerror(parser, "out of memory"); return false; } @@ -1275,9 +1251,9 @@ static bool parser_close_call(parser_t *parser, shunt *sy) fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line); else parseerror(parser, "too %s parameters for function call: expected %i, got %i\n" - " -> it has been declared here: %s:%i", - fewmany, (int)vec_size(fun->expression.params), (int)paramcount, - ast_ctx(fun).file, (int)ast_ctx(fun).line); + " -> `%s` has been declared here: %s:%i", + fewmany, fval->name, (int)vec_size(fun->expression.params), (int)paramcount, + fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line); return false; } else @@ -1291,9 +1267,9 @@ static bool parser_close_call(parser_t *parser, shunt *sy) else return !parsewarning(parser, WARN_TOO_FEW_PARAMETERS, "too %s parameters for function call: expected %i, got %i\n" - " -> it has been declared here: %s:%i", - fewmany, (int)vec_size(fun->expression.params), (int)paramcount, - ast_ctx(fun).file, (int)ast_ctx(fun).line); + " -> `%s` has been declared here: %s:%i", + fewmany, fval->name, (int)vec_size(fun->expression.params), (int)paramcount, + fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line); } } } @@ -1456,27 +1432,16 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma var = parser_find_field(parser, parser_tokval(parser)); } if (!var) { - /* intrinsics */ - if (!strcmp(parser_tokval(parser), "__builtin_debug_typestring")) { - var = (ast_expression*)intrinsic_debug_typestring; - - } - else - { - parseerror(parser, "unexpected ident: %s", parser_tokval(parser)); - goto onerr; - } + parseerror(parser, "unexpected ident: %s", parser_tokval(parser)); + goto onerr; } - else - { - if (ast_istype(var, ast_value)) { - ((ast_value*)var)->uses++; - } - else if (ast_istype(var, ast_member)) { - ast_member *mem = (ast_member*)var; - if (ast_istype(mem->owner, ast_value)) - ((ast_value*)(mem->owner))->uses++; - } + if (ast_istype(var, ast_value)) { + ((ast_value*)var)->uses++; + } + else if (ast_istype(var, ast_member)) { + ast_member *mem = (ast_member*)var; + if (ast_istype(mem->owner, ast_value)) + ((ast_value*)(mem->owner))->uses++; } vec_push(sy.out, syexp(parser_ctx(parser), var)); DEBUGSHUNTDO(con_out("push %s\n", parser_tokval(parser))); @@ -1698,6 +1663,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma vec_push(sy.ops, syparen(parser_ctx(parser), SY_PAREN_INDEX, 0)); wantop = false; } else if (op->id == opid2('?',':')) { + wantop = false; vec_push(sy.ops, syop(parser_ctx(parser), op)); vec_push(sy.ops, syparen(parser_ctx(parser), SY_PAREN_TERNARY, 0)); wantop = false; @@ -2342,7 +2308,8 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou return false; } if (!OPTS_FLAG(RELAXED_SWITCH)) { - if (!ast_istype(swcase.value, ast_value)) { /* || ((ast_value*)swcase.value)->cvq != CV_CONST) { */ + opval = (ast_value*)swcase.value; + if (!ast_istype(swcase.value, ast_value)) { /* || opval->cvq != CV_CONST) { */ parseerror(parser, "case on non-constant values need to be explicitly enabled via -frelaxed-switch"); ast_unref(operand); return false; diff --git a/util.c b/util.c index 15db97c..2ad2880 100644 --- a/util.c +++ b/util.c @@ -495,7 +495,7 @@ size_t util_strtononcmd(const char *in, char *out, size_t outsz) { FILE *util_fopen(const char *filename, const char *mode) { -#ifdef WIN32 +#ifdef _MSC_VER FILE *out; if (fopen_s(&out, filename, mode) != 0) return NULL;