diff --git a/engine/qclib/qcc.h b/engine/qclib/qcc.h index 883275c6c..2b1a11ee1 100644 --- a/engine/qclib/qcc.h +++ b/engine/qclib/qcc.h @@ -944,7 +944,7 @@ static void inline QCC_PR_Expect (char *string) #endif void editbadfile(char *fname, int line); -char *TypeName(QCC_type_t *type); +char *TypeName(QCC_type_t *type, char *buffer, int buffersize); void QCC_PR_IncludeChunk (char *data, pbool duplicate, char *filename); void QCC_PR_IncludeChunkEx(char *data, pbool duplicate, char *filename, CompilerConstant_t *cnst); void QCC_PR_CloseProcessor(void); diff --git a/engine/qclib/qcc_pr_comp.c b/engine/qclib/qcc_pr_comp.c index 0d0aad023..27a16780d 100644 --- a/engine/qclib/qcc_pr_comp.c +++ b/engine/qclib/qcc_pr_comp.c @@ -1464,15 +1464,16 @@ static void QCC_fprintfLocals(FILE *f, gofs_t paramstart, gofs_t paramend) QCC_def_t *var; temp_t *t; int i; + char typebuf[1024]; for (var = pr.localvars; var; var = var->nextlocal) { if (var->ofs >= paramstart && var->ofs < paramend) continue; if (var->arraysize) - fprintf(f, "local %s %s[%i];\n", TypeName(var->type), var->name, var->arraysize); + fprintf(f, "local %s %s[%i];\n", TypeName(var->type, typebuf, sizeof(typebuf)), var->name, var->arraysize); else - fprintf(f, "local %s %s;\n", TypeName(var->type), var->name); + fprintf(f, "local %s %s;\n", TypeName(var->type, typebuf, sizeof(typebuf)), var->name); } for (t = functemps, i = 0; t; t = t->next, i++) @@ -3864,13 +3865,16 @@ QCC_def_t *QCC_PR_ParseFunctionCall (QCC_def_t *func) //warning, the func could } if (!inh) { + char typebuf1[1024]; + char typebuf2[1024]; if (flag_laxcasts || (p->type == ev_function && e->type->type == ev_function)) { - QCC_PR_ParseWarning(WARN_LAXCAST, "type mismatch on parm %i - (%s should be %s)", arg+1, TypeName(e->type), TypeName(p)); + + QCC_PR_ParseWarning(WARN_LAXCAST, "type mismatch on parm %i - (%s should be %s)", arg+1, TypeName(e->type, typebuf1, sizeof(typebuf1)), TypeName(p, typebuf2, sizeof(typebuf2))); QCC_PR_ParsePrintDef(WARN_LAXCAST, func); } else - QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i - (%s should be %s)", arg+1, TypeName(e->type), TypeName(p)); + QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i - (%s should be %s)", arg+1, TypeName(e->type, typebuf1, sizeof(typebuf1)), TypeName(p, typebuf2, sizeof(typebuf2))); } } } @@ -7688,12 +7692,13 @@ void QCC_WriteAsmFunction(QCC_def_t *sc, unsigned int firststatement, gofs_t fir gofs_t o; QCC_type_t *type; QCC_def_t *param; + char typebuf[512]; if (!asmfile) return; type = sc->type; - fprintf(asmfile, "%s(", TypeName(type->aux_type)); + fprintf(asmfile, "%s(", TypeName(type->aux_type, typebuf, sizeof(typebuf))); p = type->num_parms; for (o = firstparm, i = 0, type = type->param; i < p; i++, type = type->next) { @@ -7706,9 +7711,9 @@ void QCC_WriteAsmFunction(QCC_def_t *sc, unsigned int firststatement, gofs_t fir break; } if (param) - fprintf(asmfile, "%s %s", TypeName(type), param->name); + fprintf(asmfile, "%s %s", TypeName(type, typebuf, sizeof(typebuf)), param->name); else - fprintf(asmfile, "%s", TypeName(type)); + fprintf(asmfile, "%s", TypeName(type, typebuf, sizeof(typebuf))); o += type->size; } @@ -8407,6 +8412,7 @@ QCC_def_t *QCC_PR_DummyDef(QCC_type_t *type, char *name, QCC_def_t *scope, int a char newname[256]; int a; QCC_def_t *def, *first=NULL; + char typebuf[1024]; #define KEYWORD(x) if (!STRCMP(name, #x) && keyword_##x) {if (keyword_##x)QCC_PR_ParseWarning(WARN_KEYWORDDISABLED, "\""#x"\" keyword used as variable name%s", keywords_coexist?" - coexisting":" - disabling");keyword_##x=keywords_coexist;} if (name) @@ -8558,7 +8564,7 @@ QCC_def_t *QCC_PR_DummyDef(QCC_type_t *type, char *name, QCC_def_t *scope, int a pHash_Add(&globalstable, first->name, first, qccHunkAlloc(sizeof(bucket_t))); if (!scope && asmfile) - fprintf(asmfile, "%s %s;\n", TypeName(first->type), first->name); + fprintf(asmfile, "%s %s;\n", TypeName(first->type, typebuf, sizeof(typebuf)), first->name); } return first; @@ -8582,6 +8588,7 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool QCC_def_t *def; // char element[MAX_NAME]; QCC_def_t *foundstatic = NULL; + char typebuf1[1024], typebuf2[1024]; if (!allocate) arraysize = -1; @@ -8599,7 +8606,7 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool } if (type && typecmp(def->type, type)) - QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHREDEC, def, "Type mismatch on redeclaration of %s. %s, should be %s",name, TypeName(type), TypeName(def->type)); + QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHREDEC, def, "Type mismatch on redeclaration of %s. %s, should be %s",name, TypeName(type, typebuf1, sizeof(typebuf1)), TypeName(def->type, typebuf2, sizeof(typebuf2))); if (def->arraysize != arraysize && arraysize>=0) QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHARRAYSIZE, def, "Array sizes for redecleration of %s do not match",name); if (allocate && scope) @@ -8638,10 +8645,10 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool if (typecmp_lax(def->type, type)) { //unequal even when we're lax - QCC_PR_ParseError (ERR_TYPEMISMATCHREDEC, "Type mismatch on redeclaration of %s. %s, should be %s",name, TypeName(type), TypeName(def->type)); + QCC_PR_ParseError (ERR_TYPEMISMATCHREDEC, "Type mismatch on redeclaration of %s. %s, should be %s",name, TypeName(type, typebuf1, sizeof(typebuf1)), TypeName(def->type, typebuf2, sizeof(typebuf2))); } else - QCC_PR_ParseWarning (WARN_LAXCAST, "Optional arguments differ on redeclaration of %s. %s, should be %s",name, TypeName(type), TypeName(def->type)); + QCC_PR_ParseWarning (WARN_LAXCAST, "Optional arguments differ on redeclaration of %s. %s, should be %s",name, TypeName(type, typebuf1, sizeof(typebuf1)), TypeName(def->type, typebuf2, sizeof(typebuf2))); } } if (def->arraysize != arraysize && arraysize>=0) @@ -8677,7 +8684,7 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool } if (type && typecmp(def->type, type)) - QCC_PR_ParseError (ERR_TYPEMISMATCHREDEC, "Type mismatch on redeclaration of %s. %s, should be %s",name, TypeName(type), TypeName(def->type)); + QCC_PR_ParseError (ERR_TYPEMISMATCHREDEC, "Type mismatch on redeclaration of %s. %s, should be %s",name, TypeName(type, typebuf1, sizeof(typebuf1)), TypeName(def->type, typebuf2, sizeof(typebuf2))); if (def->arraysize != arraysize && arraysize>=0) QCC_PR_ParseError (ERR_TYPEMISMATCHARRAYSIZE, "Array sizes for redecleration of %s do not match",name); if (allocate && scope) @@ -8713,13 +8720,14 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool { if (!pr_scope) { + char typebuf1[1024], typebuf2[1024]; if (typecmp_lax(def->type, type)) { //unequal even when we're lax - QCC_PR_ParseError (ERR_TYPEMISMATCHREDEC, "Type mismatch on redeclaration of %s. %s, should be %s",name, TypeName(type), TypeName(def->type)); + QCC_PR_ParseError (ERR_TYPEMISMATCHREDEC, "Type mismatch on redeclaration of %s. %s, should be %s",name, TypeName(type, typebuf1, sizeof(typebuf1)), TypeName(def->type, typebuf2, sizeof(typebuf2))); } else - QCC_PR_ParseWarning (WARN_LAXCAST, "Optional arguments differ on redeclaration of %s. %s, should be %s",name, TypeName(type), TypeName(def->type)); + QCC_PR_ParseWarning (WARN_LAXCAST, "Optional arguments differ on redeclaration of %s. %s, should be %s",name, TypeName(type, typebuf1, sizeof(typebuf1)), TypeName(def->type, typebuf2, sizeof(typebuf2))); } } if (def->arraysize != arraysize && arraysize>=0) @@ -9759,11 +9767,12 @@ void QCC_PR_ParseDefs (char *classname) if (classname) { + char typebuf[1024]; char *membername = name; name = qccHunkAlloc(strlen(classname) + strlen(name) + 3); sprintf(name, "%s::"MEMBERFIELDNAME, classname, membername); if (!QCC_PR_GetDef(NULL, name, NULL, false, 0, false)) - QCC_PR_ParseError(ERR_NOTANAME, "%s %s is not a member of class %s\n", TypeName(type), membername, classname); + QCC_PR_ParseError(ERR_NOTANAME, "%s %s is not a member of class %s\n", TypeName(type, typebuf, sizeof(typebuf)), membername, classname); sprintf(name, "%s::%s", classname, membername); pr_classtype = QCC_TypeForName(classname); diff --git a/engine/qclib/qcc_pr_lex.c b/engine/qclib/qcc_pr_lex.c index 3039df4ef..61e0e261b 100644 --- a/engine/qclib/qcc_pr_lex.c +++ b/engine/qclib/qcc_pr_lex.c @@ -3360,15 +3360,18 @@ QCC_type_t *QCC_PR_DuplicateType(QCC_type_t *in) return out; } -char *TypeName(QCC_type_t *type) +char *TypeName(QCC_type_t *type, char *buffer, int buffersize) { - static char buffer[2][512]; - static int op; char *ret; + if (type->type == ev_pointer) + { + TypeName(type->aux_type, buffer, buffersize-2); + strcat(buffer, " *"); + return buffer; + } - op++; - ret = buffer[op&1]; + ret = buffer; if (type->type == ev_field) { type = type->aux_type; @@ -3410,7 +3413,7 @@ char *TypeName(QCC_type_t *type) } else if (type->type == ev_entity && type->parentclass) { - ret = buffer[op&1]; + ret = buffer; *ret = 0; strcat(ret, "class "); strcat(ret, type->name); @@ -3430,7 +3433,7 @@ char *TypeName(QCC_type_t *type) else strcpy(ret, type->name); - return buffer[op&1]; + return buffer; } //#define typecmp(a, b) (a && ((a)->type==(b)->type) && !STRCMP((a)->name, (b)->name)) diff --git a/engine/qclib/qccgui.c b/engine/qclib/qccgui.c index f530710a1..fddc481b7 100644 --- a/engine/qclib/qccgui.c +++ b/engine/qclib/qccgui.c @@ -477,11 +477,12 @@ char *GetTooltipText(editor_t *editor) if (def) { static char buffer[1024]; + char typebuf[1024]; //note function argument names do not persist beyond the function def. we might be able to read the function's localdefs for them, but that's unreliable/broken with builtins where they're most needed. if (def->comment) - _snprintf(buffer, sizeof(buffer)-1, "%s %s\r\n%s", TypeName(def->type), def->name, def->comment); + _snprintf(buffer, sizeof(buffer)-1, "%s %s\r\n%s", TypeName(def->type, typebuf, sizeof(typebuf)), def->name, def->comment); else - _snprintf(buffer, sizeof(buffer)-1, "%s %s", TypeName(def->type), def->name); + _snprintf(buffer, sizeof(buffer)-1, "%s %s", TypeName(def->type, typebuf, sizeof(typebuf)), def->name); return buffer; } return NULL; @@ -1190,7 +1191,7 @@ int EditorSave(editor_t *edit) MessageBox(NULL, "Save failed - not enough mem", "Error", 0); return false; } - Edit_GetText(edit->editpane, file, len); + Edit_GetText(edit->editpane, file, len+1); if (!QCC_WriteFile(edit->filename, file, len)) { MessageBox(NULL, "Save failed\nCheck path and ReadOnly flags", "Failure", 0);