mirror of
https://github.com/nzp-team/fteqw.git
synced 2025-01-19 15:01:13 +00:00
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:
parent
2e768fe44c
commit
262bc69548
4 changed files with 47 additions and 3 deletions
|
@ -346,6 +346,7 @@ typedef struct QCC_def_s
|
|||
int arraysize;
|
||||
pbool shared;
|
||||
pbool saved;
|
||||
pbool isstatic;
|
||||
|
||||
temp_t *temp;
|
||||
} QCC_def_t;
|
||||
|
@ -825,6 +826,9 @@ extern QCC_type_t *qcc_typeinfo;
|
|||
extern int numtypeinfos;
|
||||
extern int maxtypeinfos;
|
||||
|
||||
extern int ForcedCRC;
|
||||
extern pbool defaultstatic;
|
||||
|
||||
extern int *qcc_tempofs;
|
||||
extern int max_temps;
|
||||
//extern int qcc_functioncalled; //unuse temps if this is true - don't want to reuse the same space.
|
||||
|
|
|
@ -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;
|
||||
// char element[MAX_NAME];
|
||||
unsigned int i;
|
||||
QCC_def_t *foundstatic = NULL;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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 (!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
|
||||
}
|
||||
|
||||
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 (!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)
|
||||
return NULL;
|
||||
|
||||
if (arraysize < 1)
|
||||
{
|
||||
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_dfunction_t *df;
|
||||
int i;
|
||||
extern pbool defaultstatic;
|
||||
pbool shared=false;
|
||||
pbool isstatic=defaultstatic;
|
||||
pbool externfnc=false;
|
||||
pbool isconstant = false;
|
||||
pbool isvar = false;
|
||||
|
@ -8184,7 +8208,6 @@ void QCC_PR_ParseDefs (char *classname)
|
|||
char *oldp;
|
||||
if (QCC_PR_CheckKeyword (keyword_codesys, "CodeSys")) //reacc support.
|
||||
{
|
||||
extern int ForcedCRC;
|
||||
if (ForcedCRC)
|
||||
QCC_PR_ParseError(ERR_BADEXTENSION, "progs crc was already specified - only one is allowed");
|
||||
ForcedCRC = (int)pr_immediate._float;
|
||||
|
@ -8328,6 +8351,10 @@ void QCC_PR_ParseDefs (char *classname)
|
|||
isconstant = true;
|
||||
else if (QCC_PR_CheckKeyword(keyword_var, "var"))
|
||||
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"))
|
||||
noref=true;
|
||||
else if (QCC_PR_CheckKeyword(keyword_nosave, "nosave"))
|
||||
|
@ -8402,6 +8429,7 @@ void QCC_PR_ParseDefs (char *classname)
|
|||
f = QCC_PR_ParseImmediateStatements (type);
|
||||
pr_scope = NULL;
|
||||
def->initialized = 1;
|
||||
def->isstatic = isstatic;
|
||||
G_FUNCTION(def->ofs) = numfunctions;
|
||||
f->def = def;
|
||||
// if (pr_dumpasm)
|
||||
|
@ -8592,6 +8620,14 @@ void QCC_PR_ParseDefs (char *classname)
|
|||
if (externfnc)
|
||||
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
|
||||
if (type->type == ev_function && (pr_scope))
|
||||
{
|
||||
|
|
|
@ -218,6 +218,7 @@ void QCC_FindBestInclude(char *newfile, char *currentfile, char *rootpath)
|
|||
QCC_Include(fullname);
|
||||
}
|
||||
|
||||
pbool defaultstatic;
|
||||
int ForcedCRC;
|
||||
int QCC_PR_LexInteger (void);
|
||||
void QCC_AddFile (char *filename);
|
||||
|
@ -809,6 +810,10 @@ pbool QCC_PR_Precompiler(void)
|
|||
{
|
||||
ForcedCRC = atoi(msg);
|
||||
}
|
||||
else if (!strncmp(qcc_token, "defaultstatic", 13))
|
||||
{
|
||||
defaultstatic = atoi(msg);
|
||||
}
|
||||
else if (!strncmp(qcc_token, "sourcefile", 10))
|
||||
{
|
||||
#define MAXSOURCEFILESLIST 8
|
||||
|
|
|
@ -1731,7 +1731,6 @@ void inline Add3(char *p, unsigned short *crc, char *file)
|
|||
|
||||
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)
|
||||
char file[PROGDEFS_MAX_SIZE];
|
||||
QCC_def_t *d;
|
||||
|
@ -2501,13 +2500,13 @@ void SetEndian(void);
|
|||
|
||||
void QCC_SetDefaultProperties (void)
|
||||
{
|
||||
extern int ForcedCRC;
|
||||
int level;
|
||||
int i;
|
||||
|
||||
Hash_InitTable(&compconstantstable, MAX_CONSTANTS, qccHunkAlloc(Hash_BytesForBuckets(MAX_CONSTANTS)));
|
||||
|
||||
ForcedCRC = 0;
|
||||
defaultstatic = 0;
|
||||
|
||||
QCC_PR_DefineName("FTEQCC");
|
||||
|
||||
|
|
Loading…
Reference in a new issue