Skip to content

Commit 175d46e

Browse files
author
acceptthis
committed
So I can define globals/functions as static.
git-svn-id: https://fteqw.svn.sourceforge.net/svnroot/fteqw/trunk/engine/qclib@3147 fa7d4b81-6910-0410-8d11-a3360c2baa62
1 parent efbc571 commit 175d46e

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

qcc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ typedef struct QCC_def_s
346346
int arraysize;
347347
pbool shared;
348348
pbool saved;
349+
pbool isstatic;
349350

350351
temp_t *temp;
351352
} QCC_def_t;
@@ -825,6 +826,9 @@ extern QCC_type_t *qcc_typeinfo;
825826
extern int numtypeinfos;
826827
extern int maxtypeinfos;
827828

829+
extern int ForcedCRC;
830+
extern pbool defaultstatic;
831+
828832
extern int *qcc_tempofs;
829833
extern int max_temps;
830834
//extern int qcc_functioncalled; //unuse temps if this is true - don't want to reuse the same space.

qcc_pr_comp.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7619,6 +7619,7 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
76197619
QCC_def_t *def;
76207620
// char element[MAX_NAME];
76217621
unsigned int i;
7622+
QCC_def_t *foundstatic = NULL;
76227623

76237624
if (scope)
76247625
{
@@ -7658,6 +7659,13 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
76587659
continue; // in a different function
76597660
}
76607661

7662+
if (def->isstatic && def->s_file != s_file)
7663+
{ //warn? or would that be pointless?
7664+
foundstatic = def;
7665+
def = Hash_GetNext(&globalstable, name, def);
7666+
continue; // in a different function
7667+
}
7668+
76617669
if (type && typecmp(def->type, type))
76627670
{
76637671
if (!pr_scope)
@@ -7721,6 +7729,13 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
77217729
continue; // in a different function
77227730
}
77237731

7732+
if (def->isstatic && def->s_file != s_file)
7733+
{ //warn? or would that be pointless?
7734+
foundstatic = def;
7735+
def = Hash_GetNext(&globalstable, name, def);
7736+
continue; // in a different function
7737+
}
7738+
77247739
if (type && typecmp(def->type, type))
77257740
{
77267741
if (!pr_scope)
@@ -7745,8 +7760,15 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
77457760
}
77467761
}
77477762

7763+
if (foundstatic && !allocate)
7764+
{
7765+
QCC_PR_ParseWarning (WARN_DUPLICATEDEFINITION, "%s defined static", name);
7766+
QCC_PR_ParsePrintDef(WARN_DUPLICATEDEFINITION, foundstatic);
7767+
}
7768+
77487769
if (!allocate)
77497770
return NULL;
7771+
77507772
if (arraysize < 1)
77517773
{
77527774
QCC_PR_ParseError (ERR_ARRAYNEEDSSIZE, "First declaration of array %s with no size",name);
@@ -7945,7 +7967,9 @@ void QCC_PR_ParseDefs (char *classname)
79457967
QCC_function_t *f;
79467968
QCC_dfunction_t *df;
79477969
int i;
7970+
extern pbool defaultstatic;
79487971
pbool shared=false;
7972+
pbool isstatic=defaultstatic;
79497973
pbool externfnc=false;
79507974
pbool isconstant = false;
79517975
pbool isvar = false;
@@ -8184,7 +8208,6 @@ void QCC_PR_ParseDefs (char *classname)
81848208
char *oldp;
81858209
if (QCC_PR_CheckKeyword (keyword_codesys, "CodeSys")) //reacc support.
81868210
{
8187-
extern int ForcedCRC;
81888211
if (ForcedCRC)
81898212
QCC_PR_ParseError(ERR_BADEXTENSION, "progs crc was already specified - only one is allowed");
81908213
ForcedCRC = (int)pr_immediate._float;
@@ -8328,6 +8351,10 @@ void QCC_PR_ParseDefs (char *classname)
83288351
isconstant = true;
83298352
else if (QCC_PR_CheckKeyword(keyword_var, "var"))
83308353
isvar = true;
8354+
else if (!pr_scope && QCC_PR_CheckKeyword(keyword_var, "static"))
8355+
isstatic = true;
8356+
else if (!pr_scope && QCC_PR_CheckKeyword(keyword_var, "nonstatic"))
8357+
isstatic = false;
83318358
else if (QCC_PR_CheckKeyword(keyword_noref, "noref"))
83328359
noref=true;
83338360
else if (QCC_PR_CheckKeyword(keyword_nosave, "nosave"))
@@ -8402,6 +8429,7 @@ void QCC_PR_ParseDefs (char *classname)
84028429
f = QCC_PR_ParseImmediateStatements (type);
84038430
pr_scope = NULL;
84048431
def->initialized = 1;
8432+
def->isstatic = isstatic;
84058433
G_FUNCTION(def->ofs) = numfunctions;
84068434
f->def = def;
84078435
// if (pr_dumpasm)
@@ -8592,6 +8620,14 @@ void QCC_PR_ParseDefs (char *classname)
85928620
if (externfnc)
85938621
def->initialized = 2;
85948622

8623+
if (isstatic)
8624+
{
8625+
if (def->s_file == s_file)
8626+
def->isstatic = isstatic;
8627+
else //if (type->type != ev_function && defaultstatic) //functions don't quite consitiute a definition
8628+
QCC_PR_ParseErrorPrintDef (ERR_REDECLARATION, def, "can't redefine non-static as static");
8629+
}
8630+
85958631
// check for an initialization
85968632
if (type->type == ev_function && (pr_scope))
85978633
{

qcc_pr_lex.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ void QCC_FindBestInclude(char *newfile, char *currentfile, char *rootpath)
218218
QCC_Include(fullname);
219219
}
220220

221+
pbool defaultstatic;
221222
int ForcedCRC;
222223
int QCC_PR_LexInteger (void);
223224
void QCC_AddFile (char *filename);
@@ -809,6 +810,10 @@ pbool QCC_PR_Precompiler(void)
809810
{
810811
ForcedCRC = atoi(msg);
811812
}
813+
else if (!strncmp(qcc_token, "defaultstatic", 13))
814+
{
815+
defaultstatic = atoi(msg);
816+
}
812817
else if (!strncmp(qcc_token, "sourcefile", 10))
813818
{
814819
#define MAXSOURCEFILESLIST 8

qccmain.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,6 @@ void inline Add3(char *p, unsigned short *crc, char *file)
17311731

17321732
unsigned short QCC_PR_WriteProgdefs (char *filename)
17331733
{
1734-
extern int ForcedCRC;
17351734
#define ADD2(p) strncat(file, p, PROGDEFS_MAX_SIZE-1 - strlen(file)) //no crc (later changes)
17361735
char file[PROGDEFS_MAX_SIZE];
17371736
QCC_def_t *d;
@@ -2501,13 +2500,13 @@ void SetEndian(void);
25012500

25022501
void QCC_SetDefaultProperties (void)
25032502
{
2504-
extern int ForcedCRC;
25052503
int level;
25062504
int i;
25072505

25082506
Hash_InitTable(&compconstantstable, MAX_CONSTANTS, qccHunkAlloc(Hash_BytesForBuckets(MAX_CONSTANTS)));
25092507

25102508
ForcedCRC = 0;
2509+
defaultstatic = 0;
25112510

25122511
QCC_PR_DefineName("FTEQCC");
25132512

0 commit comments

Comments
 (0)