So I can define globals/functions as static.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3147 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2009-03-29 23:47:29 +00:00
parent 2e768fe44c
commit 262bc69548
4 changed files with 47 additions and 3 deletions

View file

@ -346,6 +346,7 @@ typedef struct QCC_def_s
int arraysize; int arraysize;
pbool shared; pbool shared;
pbool saved; pbool saved;
pbool isstatic;
temp_t *temp; temp_t *temp;
} QCC_def_t; } QCC_def_t;
@ -825,6 +826,9 @@ extern QCC_type_t *qcc_typeinfo;
extern int numtypeinfos; extern int numtypeinfos;
extern int maxtypeinfos; extern int maxtypeinfos;
extern int ForcedCRC;
extern pbool defaultstatic;
extern int *qcc_tempofs; extern int *qcc_tempofs;
extern int max_temps; extern int max_temps;
//extern int qcc_functioncalled; //unuse temps if this is true - don't want to reuse the same space. //extern int qcc_functioncalled; //unuse temps if this is true - don't want to reuse the same space.

View file

@ -7619,6 +7619,7 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
QCC_def_t *def; QCC_def_t *def;
// char element[MAX_NAME]; // char element[MAX_NAME];
unsigned int i; unsigned int i;
QCC_def_t *foundstatic = NULL;
if (scope) if (scope)
{ {
@ -7658,6 +7659,13 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
continue; // in a different function continue; // in a different function
} }
if (def->isstatic && def->s_file != s_file)
{ //warn? or would that be pointless?
foundstatic = def;
def = Hash_GetNext(&globalstable, name, def);
continue; // in a different function
}
if (type && typecmp(def->type, type)) if (type && typecmp(def->type, type))
{ {
if (!pr_scope) if (!pr_scope)
@ -7721,6 +7729,13 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
continue; // in a different function continue; // in a different function
} }
if (def->isstatic && def->s_file != s_file)
{ //warn? or would that be pointless?
foundstatic = def;
def = Hash_GetNext(&globalstable, name, def);
continue; // in a different function
}
if (type && typecmp(def->type, type)) if (type && typecmp(def->type, type))
{ {
if (!pr_scope) if (!pr_scope)
@ -7745,8 +7760,15 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
} }
} }
if (foundstatic && !allocate)
{
QCC_PR_ParseWarning (WARN_DUPLICATEDEFINITION, "%s defined static", name);
QCC_PR_ParsePrintDef(WARN_DUPLICATEDEFINITION, foundstatic);
}
if (!allocate) if (!allocate)
return NULL; return NULL;
if (arraysize < 1) if (arraysize < 1)
{ {
QCC_PR_ParseError (ERR_ARRAYNEEDSSIZE, "First declaration of array %s with no size",name); QCC_PR_ParseError (ERR_ARRAYNEEDSSIZE, "First declaration of array %s with no size",name);
@ -7945,7 +7967,9 @@ void QCC_PR_ParseDefs (char *classname)
QCC_function_t *f; QCC_function_t *f;
QCC_dfunction_t *df; QCC_dfunction_t *df;
int i; int i;
extern pbool defaultstatic;
pbool shared=false; pbool shared=false;
pbool isstatic=defaultstatic;
pbool externfnc=false; pbool externfnc=false;
pbool isconstant = false; pbool isconstant = false;
pbool isvar = false; pbool isvar = false;
@ -8184,7 +8208,6 @@ void QCC_PR_ParseDefs (char *classname)
char *oldp; char *oldp;
if (QCC_PR_CheckKeyword (keyword_codesys, "CodeSys")) //reacc support. if (QCC_PR_CheckKeyword (keyword_codesys, "CodeSys")) //reacc support.
{ {
extern int ForcedCRC;
if (ForcedCRC) if (ForcedCRC)
QCC_PR_ParseError(ERR_BADEXTENSION, "progs crc was already specified - only one is allowed"); QCC_PR_ParseError(ERR_BADEXTENSION, "progs crc was already specified - only one is allowed");
ForcedCRC = (int)pr_immediate._float; ForcedCRC = (int)pr_immediate._float;
@ -8328,6 +8351,10 @@ void QCC_PR_ParseDefs (char *classname)
isconstant = true; isconstant = true;
else if (QCC_PR_CheckKeyword(keyword_var, "var")) else if (QCC_PR_CheckKeyword(keyword_var, "var"))
isvar = true; isvar = true;
else if (!pr_scope && QCC_PR_CheckKeyword(keyword_var, "static"))
isstatic = true;
else if (!pr_scope && QCC_PR_CheckKeyword(keyword_var, "nonstatic"))
isstatic = false;
else if (QCC_PR_CheckKeyword(keyword_noref, "noref")) else if (QCC_PR_CheckKeyword(keyword_noref, "noref"))
noref=true; noref=true;
else if (QCC_PR_CheckKeyword(keyword_nosave, "nosave")) else if (QCC_PR_CheckKeyword(keyword_nosave, "nosave"))
@ -8402,6 +8429,7 @@ void QCC_PR_ParseDefs (char *classname)
f = QCC_PR_ParseImmediateStatements (type); f = QCC_PR_ParseImmediateStatements (type);
pr_scope = NULL; pr_scope = NULL;
def->initialized = 1; def->initialized = 1;
def->isstatic = isstatic;
G_FUNCTION(def->ofs) = numfunctions; G_FUNCTION(def->ofs) = numfunctions;
f->def = def; f->def = def;
// if (pr_dumpasm) // if (pr_dumpasm)
@ -8592,6 +8620,14 @@ void QCC_PR_ParseDefs (char *classname)
if (externfnc) if (externfnc)
def->initialized = 2; def->initialized = 2;
if (isstatic)
{
if (def->s_file == s_file)
def->isstatic = isstatic;
else //if (type->type != ev_function && defaultstatic) //functions don't quite consitiute a definition
QCC_PR_ParseErrorPrintDef (ERR_REDECLARATION, def, "can't redefine non-static as static");
}
// check for an initialization // check for an initialization
if (type->type == ev_function && (pr_scope)) if (type->type == ev_function && (pr_scope))
{ {

View file

@ -218,6 +218,7 @@ void QCC_FindBestInclude(char *newfile, char *currentfile, char *rootpath)
QCC_Include(fullname); QCC_Include(fullname);
} }
pbool defaultstatic;
int ForcedCRC; int ForcedCRC;
int QCC_PR_LexInteger (void); int QCC_PR_LexInteger (void);
void QCC_AddFile (char *filename); void QCC_AddFile (char *filename);
@ -809,6 +810,10 @@ pbool QCC_PR_Precompiler(void)
{ {
ForcedCRC = atoi(msg); ForcedCRC = atoi(msg);
} }
else if (!strncmp(qcc_token, "defaultstatic", 13))
{
defaultstatic = atoi(msg);
}
else if (!strncmp(qcc_token, "sourcefile", 10)) else if (!strncmp(qcc_token, "sourcefile", 10))
{ {
#define MAXSOURCEFILESLIST 8 #define MAXSOURCEFILESLIST 8

View file

@ -1731,7 +1731,6 @@ void inline Add3(char *p, unsigned short *crc, char *file)
unsigned short QCC_PR_WriteProgdefs (char *filename) unsigned short QCC_PR_WriteProgdefs (char *filename)
{ {
extern int ForcedCRC;
#define ADD2(p) strncat(file, p, PROGDEFS_MAX_SIZE-1 - strlen(file)) //no crc (later changes) #define ADD2(p) strncat(file, p, PROGDEFS_MAX_SIZE-1 - strlen(file)) //no crc (later changes)
char file[PROGDEFS_MAX_SIZE]; char file[PROGDEFS_MAX_SIZE];
QCC_def_t *d; QCC_def_t *d;
@ -2501,13 +2500,13 @@ void SetEndian(void);
void QCC_SetDefaultProperties (void) void QCC_SetDefaultProperties (void)
{ {
extern int ForcedCRC;
int level; int level;
int i; int i;
Hash_InitTable(&compconstantstable, MAX_CONSTANTS, qccHunkAlloc(Hash_BytesForBuckets(MAX_CONSTANTS))); Hash_InitTable(&compconstantstable, MAX_CONSTANTS, qccHunkAlloc(Hash_BytesForBuckets(MAX_CONSTANTS)));
ForcedCRC = 0; ForcedCRC = 0;
defaultstatic = 0;
QCC_PR_DefineName("FTEQCC"); QCC_PR_DefineName("FTEQCC");