From 052cba731da2cd6af083734d9df83b83e7ec4301 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 7 Feb 2015 18:07:30 +0000 Subject: [PATCH] prevent generation of statements outside functions (inlining to constants is okay). insert .qc files into tree view in .src order instead of alphabetically. make sure extra .src files appear at the root. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4837 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/qclib/gui.h | 2 +- engine/qclib/qcc.h | 2 ++ engine/qclib/qcc_pr_comp.c | 46 +++++++++++++++++++++++++------------- engine/qclib/qcc_pr_lex.c | 7 +++--- engine/qclib/qccgui.c | 39 +++++++++++++++++++++----------- engine/qclib/qccguistuff.c | 2 +- engine/qclib/qccmain.c | 2 ++ 7 files changed, 67 insertions(+), 33 deletions(-) diff --git a/engine/qclib/gui.h b/engine/qclib/gui.h index 1282d620f..3e3fb9294 100644 --- a/engine/qclib/gui.h +++ b/engine/qclib/gui.h @@ -6,7 +6,7 @@ void GUI_SetDefaultOpts(void); int GUI_BuildParms(char *args, char **argv, pbool quick); unsigned char *PDECL QCC_ReadFile (const char *fname, void *buffer, int len, size_t *sz); -int QCC_FileSize (const char *fname); +int QCC_RawFileSize (const char *fname); pbool QCC_WriteFile (const char *name, void *data, int len); void GUI_DialogPrint(char *title, char *text); diff --git a/engine/qclib/qcc.h b/engine/qclib/qcc.h index cd5a97f91..658b71284 100644 --- a/engine/qclib/qcc.h +++ b/engine/qclib/qcc.h @@ -941,6 +941,8 @@ extern int max_temps; extern int tempsstart; extern int numtemps; +extern char compilingrootfile[]; //.src file currently being compiled + typedef char PATHSTRING[MAX_DATA_PATH]; typedef struct diff --git a/engine/qclib/qcc_pr_comp.c b/engine/qclib/qcc_pr_comp.c index eeffc47a3..6522ea98c 100644 --- a/engine/qclib/qcc_pr_comp.c +++ b/engine/qclib/qcc_pr_comp.c @@ -174,7 +174,7 @@ enum QCC_def_t *QCC_PR_StatementFlags ( QCC_opcode_t *op, QCC_def_t *var_a, QCC_def_t *var_b, QCC_statement_t **outstatement, unsigned int flags); void QCC_PR_ParseState (void); -pbool expandedemptymacro; +pbool expandedemptymacro; //just inhibits warnings about hanging semicolons QCC_pr_info_t pr; //QCC_def_t **pr_global_defs/*[MAX_REGS]*/; // to find def for a global variable @@ -1693,7 +1693,7 @@ static void QCC_fprintfLocals(FILE *f, gofs_t paramstart, gofs_t paramend) { if (t->lastfunc == pr_scope) { - fprintf(f, "local %s temp_%i;\n", (t->size == 1)?"float":"vector", t->ofs); + fprintf(f, "local %s temp_%i;\n", (t->size == 1)?"float":"vector", t->ofs-FIRST_TEMP); } } } @@ -3381,6 +3381,9 @@ QCC_def_t *QCC_PR_StatementFlags (QCC_opcode_t *op, QCC_def_t *var_a, QCC_def_t } } + if (!pr_scope) + QCC_PR_ParseError(ERR_BADEXTENSION, "Unable to generate statements at global scope.\n"); + if (outstatement) *outstatement = statement; @@ -6324,7 +6327,7 @@ QCC_ref_t *QCC_PR_ParseRefValue (QCC_ref_t *refbuf, QCC_type_t *assumeclass, pbo } else if (pr_assumetermtype) { - d = QCC_PR_GetDef (pr_assumetermtype, name, pr_scope, true, 0, false); + d = QCC_PR_GetDef (pr_assumetermtype, name, NULL, true, 0, false); if (!d) QCC_PR_ParseError (ERR_UNKNOWNVALUE, "Unknown value \"%s\"", name); } @@ -7692,18 +7695,31 @@ QCC_ref_t *QCC_PR_RefExpression (QCC_ref_t *retbuf, int priority, int exprflags) QCC_def_t *val, *r; QCC_statement_t *fromj, *elsej; - //FIXME: use the correct conditional - QCC_FreeTemp(QCC_PR_Statement(&pr_opcodes[OP_IFNOT_I], QCC_RefToDef(lhsr, true), NULL, &fromj)); + if (QCC_PR_CheckToken(":")) + { + val = QCC_RefToDef(lhsr, true); + //FIXME: use the correct conditional + QCC_FreeTemp(QCC_PR_Statement(&pr_opcodes[OP_IFNOT_I], val, NULL, &fromj)); + QCC_UnFreeTemp(val); + r = QCC_GetTemp(val->type); + QCC_FreeTemp(QCC_PR_StatementFlags(&pr_opcodes[(r->type->size>=3)?OP_STORE_V:OP_STORE_F], val, r, NULL, 0)); + QCC_UnFreeTemp(r); + } + else + { + //FIXME: use the correct conditional + QCC_FreeTemp(QCC_PR_Statement(&pr_opcodes[OP_IFNOT_I], QCC_RefToDef(lhsr, true), NULL, &fromj)); - val = QCC_PR_Expression(TOP_PRIORITY, EXPR_DISALLOW_COMMA); - if (val->type->type == ev_integer && !QCC_OPCodeValid(&pr_opcodes[OP_STORE_I])) - val = QCC_SupplyConversion(val, ev_float, true); - r = QCC_GetTemp(val->type); - QCC_FreeTemp(QCC_PR_StatementFlags(&pr_opcodes[(r->type->size>=3)?OP_STORE_V:OP_STORE_F], val, r, NULL, 0)); - //r can be stomped upon until its reused anyway - QCC_UnFreeTemp(r); + val = QCC_PR_Expression(TOP_PRIORITY, EXPR_DISALLOW_COMMA); + if (val->type->type == ev_integer && !QCC_OPCodeValid(&pr_opcodes[OP_STORE_I])) + val = QCC_SupplyConversion(val, ev_float, true); + r = QCC_GetTemp(val->type); + QCC_FreeTemp(QCC_PR_StatementFlags(&pr_opcodes[(r->type->size>=3)?OP_STORE_V:OP_STORE_F], val, r, NULL, 0)); + //r can be stomped upon until its reused anyway + QCC_UnFreeTemp(r); - QCC_PR_Expect(":"); + QCC_PR_Expect(":"); + } QCC_PR_Statement(&pr_opcodes[OP_GOTO], NULL, NULL, &elsej); fromj->b = &statements[numstatements] - fromj; val = QCC_PR_Expression(TOP_PRIORITY, EXPR_DISALLOW_COMMA); @@ -9139,7 +9155,7 @@ void QCC_PR_ParseState (void) QCC_PR_Expect (","); - pr_scope = NULL; +// pr_scope = NULL; pr_assumetermtype = type_function; def = QCC_PR_Expression (TOP_PRIORITY, EXPR_DISALLOW_COMMA); if (typecmp(def->type, type_function)) @@ -9156,7 +9172,7 @@ void QCC_PR_ParseState (void) } } pr_assumetermtype = NULL; - pr_scope = sc; +// pr_scope = sc; QCC_PR_Expect ("]"); diff --git a/engine/qclib/qcc_pr_lex.c b/engine/qclib/qcc_pr_lex.c index 3200935b6..802571d11 100644 --- a/engine/qclib/qcc_pr_lex.c +++ b/engine/qclib/qcc_pr_lex.c @@ -2983,6 +2983,7 @@ int QCC_PR_CheckCompConst(void) QCC_PR_ExpandStrCat(&buffer, &bufferlen, &buffermax, "\0", 1); QCC_PR_IncludeChunkEx(buffer, true, NULL, c); } + expandedemptymacro = true; free(buffer); if (flag_debugmacros) @@ -2998,9 +2999,9 @@ int QCC_PR_CheckCompConst(void) } else { - if (!*c->value) - expandedemptymacro = true; - QCC_PR_IncludeChunkEx(c->value, false, NULL, c); + if (*c->value) + QCC_PR_IncludeChunkEx(c->value, false, NULL, c); + expandedemptymacro = true; } return true; } diff --git a/engine/qclib/qccgui.c b/engine/qclib/qccgui.c index cbb5679d8..a0423b428 100644 --- a/engine/qclib/qccgui.c +++ b/engine/qclib/qccgui.c @@ -260,7 +260,7 @@ unsigned char *PDECL QCC_ReadFile (const char *fname, void *buffer, int len, siz *sz = length; return buffer; } -int PDECL QCC_FileSize (const char *fname) +int PDECL QCC_RawFileSize (const char *fname) { long length; FILE *f; @@ -270,12 +270,21 @@ int PDECL QCC_FileSize (const char *fname) fseek(f, 0, SEEK_END); length = ftell(f); fclose(f); - - if (strcmp(progssrcname, fname)) - AddSourceFile("%s/%s", progssrcname, fname); - return length; } +int PDECL QCC_PopFileSize (const char *fname) +{ + extern int qcc_compileactive; + int len = QCC_RawFileSize(fname); + if (len >= 0 && qcc_compileactive) + { + if (strcmp(compilingrootfile, fname)) + AddSourceFile("%s/%s", compilingrootfile, fname); + else + AddSourceFile("%s", fname); + } + return len; +} #ifdef AVAIL_ZLIB #include "../libs/zlib.h" @@ -1598,7 +1607,7 @@ static void EditorReload(editor_t *editor) int flen; char *file; - flen = QCC_FileSize(editor->filename); + flen = QCC_RawFileSize(editor->filename); if (flen >= 0) { file = malloc(flen+1); @@ -1675,7 +1684,7 @@ void EditFile(char *name, int line) } } - if (QCC_FileSize(name) == -1) + if (QCC_RawFileSize(name) == -1) { QC_snprintfz(title, sizeof(title), "File not found.\n%s", name); MessageBox(NULL, title, "Error", 0); @@ -1890,7 +1899,7 @@ int GUIFileSize(const char *fname) return len; } } - return QCC_FileSize(fname); + return QCC_PopFileSize(fname); } /*checks if the file has been modified externally*/ @@ -3335,12 +3344,15 @@ static LRESULT CALLBACK MainWndProc(HWND hWnd,UINT message, { case NM_DBLCLK: item = TreeView_GetSelection(projecttree); + memset(&i, 0, sizeof(i)); i.hItem = item; - i.mask = TVIF_TEXT; + i.mask = TVIF_TEXT|TVIF_PARAM; i.pszText = itemtext; i.cchTextMax = sizeof(itemtext)-1; if (!TreeView_GetItem(projecttree, &i)) return 0; + if (!i.lParam) + return 0; strcpy(filename, i.pszText); while(item) { @@ -3836,11 +3848,11 @@ void AddSourceFile(char *format, ...) memset(&parent, 0, sizeof(parent)); pi = item.hParent = TVI_ROOT; - item.hInsertAfter = TVI_SORT; + item.hInsertAfter = TVI_LAST;//TVI_SORT; item.item.pszText = string; item.item.state = TVIS_EXPANDED; item.item.stateMask = TVIS_EXPANDED; - item.item.mask = TVIF_TEXT|TVIF_STATE; + item.item.mask = TVIF_TEXT|TVIF_STATE|TVIF_PARAM; while(item.item.pszText) { slash = strchr(item.item.pszText, '/'); @@ -3862,6 +3874,7 @@ void AddSourceFile(char *format, ...) if (!item.hParent) { //add a directory. item.hParent = pi; + item.item.lParam = !slash; pi = (HANDLE)SendMessage(projecttree,TVM_INSERTITEM,0,(LPARAM)&item); item.hParent = pi; } @@ -4003,9 +4016,9 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin if (!fl_acc && !*progssrcname) { strcpy(progssrcname, "preprogs.src"); - if (QCC_FileSize(progssrcname)==-1) + if (QCC_RawFileSize(progssrcname)==-1) strcpy(progssrcname, "progs.src"); - if (QCC_FileSize(progssrcname)==-1) + if (QCC_RawFileSize(progssrcname)==-1) { char *s, *s2; char filename[MAX_PATH]; diff --git a/engine/qclib/qccguistuff.c b/engine/qclib/qccguistuff.c index 3fd49bd9e..e923d60f8 100644 --- a/engine/qclib/qccguistuff.c +++ b/engine/qclib/qccguistuff.c @@ -27,7 +27,7 @@ int Grep(char *filename, char *string) char *buf; if (!filename) return foundcount; - sz = QCC_FileSize(filename); + sz = QCC_RawFileSize(filename); if (sz <= 0) return foundcount; buf = malloc(sz+1); diff --git a/engine/qclib/qccmain.c b/engine/qclib/qccmain.c index c93e87f28..65149133b 100644 --- a/engine/qclib/qccmain.c +++ b/engine/qclib/qccmain.c @@ -52,6 +52,7 @@ int sourcefilesnumdefs; int currentsourcefile; int numsourcefiles; extern char *compilingfile; +char compilingrootfile[1024]; void QCC_PR_ResetErrorScope(void); @@ -3410,6 +3411,7 @@ memset(pr_immediate_string, 0, sizeof(pr_immediate_string)); sprintf (qccmprogsdat, "%s%s", qccmsourcedir, sourcefileslist[currentsourcefile++]); printf ("Source file: %s\n", qccmprogsdat); + QC_strlcpy(compilingrootfile, qccmprogsdat, sizeof(compilingrootfile)); if (QCC_LoadFile (qccmprogsdat, (void *)&qccmsrc) == -1) { return true;