@@ -7619,6 +7619,7 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
7619
7619
QCC_def_t * def ;
7620
7620
// char element[MAX_NAME];
7621
7621
unsigned int i ;
7622
+ QCC_def_t * foundstatic = NULL ;
7622
7623
7623
7624
if (scope )
7624
7625
{
@@ -7658,6 +7659,13 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
7658
7659
continue ; // in a different function
7659
7660
}
7660
7661
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
+
7661
7669
if (type && typecmp (def -> type , type ))
7662
7670
{
7663
7671
if (!pr_scope )
@@ -7721,6 +7729,13 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
7721
7729
continue ; // in a different function
7722
7730
}
7723
7731
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
+
7724
7739
if (type && typecmp (def -> type , type ))
7725
7740
{
7726
7741
if (!pr_scope )
@@ -7745,8 +7760,15 @@ QCC_def_t *QCC_PR_GetDef (QCC_type_t *type, char *name, QCC_def_t *scope, pbool
7745
7760
}
7746
7761
}
7747
7762
7763
+ if (foundstatic && !allocate )
7764
+ {
7765
+ QCC_PR_ParseWarning (WARN_DUPLICATEDEFINITION , "%s defined static" , name );
7766
+ QCC_PR_ParsePrintDef (WARN_DUPLICATEDEFINITION , foundstatic );
7767
+ }
7768
+
7748
7769
if (!allocate )
7749
7770
return NULL ;
7771
+
7750
7772
if (arraysize < 1 )
7751
7773
{
7752
7774
QCC_PR_ParseError (ERR_ARRAYNEEDSSIZE , "First declaration of array %s with no size" ,name );
@@ -7945,7 +7967,9 @@ void QCC_PR_ParseDefs (char *classname)
7945
7967
QCC_function_t * f ;
7946
7968
QCC_dfunction_t * df ;
7947
7969
int i ;
7970
+ extern pbool defaultstatic ;
7948
7971
pbool shared = false;
7972
+ pbool isstatic = defaultstatic ;
7949
7973
pbool externfnc = false;
7950
7974
pbool isconstant = false;
7951
7975
pbool isvar = false;
@@ -8184,7 +8208,6 @@ void QCC_PR_ParseDefs (char *classname)
8184
8208
char * oldp ;
8185
8209
if (QCC_PR_CheckKeyword (keyword_codesys , "CodeSys" )) //reacc support.
8186
8210
{
8187
- extern int ForcedCRC ;
8188
8211
if (ForcedCRC )
8189
8212
QCC_PR_ParseError (ERR_BADEXTENSION , "progs crc was already specified - only one is allowed" );
8190
8213
ForcedCRC = (int )pr_immediate ._float ;
@@ -8328,6 +8351,10 @@ void QCC_PR_ParseDefs (char *classname)
8328
8351
isconstant = true;
8329
8352
else if (QCC_PR_CheckKeyword (keyword_var , "var" ))
8330
8353
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;
8331
8358
else if (QCC_PR_CheckKeyword (keyword_noref , "noref" ))
8332
8359
noref = true;
8333
8360
else if (QCC_PR_CheckKeyword (keyword_nosave , "nosave" ))
@@ -8402,6 +8429,7 @@ void QCC_PR_ParseDefs (char *classname)
8402
8429
f = QCC_PR_ParseImmediateStatements (type );
8403
8430
pr_scope = NULL ;
8404
8431
def -> initialized = 1 ;
8432
+ def -> isstatic = isstatic ;
8405
8433
G_FUNCTION (def -> ofs ) = numfunctions ;
8406
8434
f -> def = def ;
8407
8435
// if (pr_dumpasm)
@@ -8592,6 +8620,14 @@ void QCC_PR_ParseDefs (char *classname)
8592
8620
if (externfnc )
8593
8621
def -> initialized = 2 ;
8594
8622
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
+
8595
8631
// check for an initialization
8596
8632
if (type -> type == ev_function && (pr_scope ))
8597
8633
{
0 commit comments