@@ -95,7 +95,7 @@ static void decl_const(int table);
95
95
static void decl_enum (int table ,int fstatic );
96
96
static cell needsub (int * tag ,constvalue_root * * enumroot );
97
97
static void initials (int ident ,int tag ,cell * size ,int dim [],int numdim ,
98
- constvalue_root * enumroot );
98
+ constvalue_root * enumroot , int * explicit_init );
99
99
static cell initarray (int ident ,int tag ,int dim [],int numdim ,int cur ,
100
100
int startlit ,int counteddim [],constvalue_root * lastdim ,
101
101
constvalue_root * enumroot ,int * errorfound );
@@ -2004,6 +2004,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst
2004
2004
char * str ;
2005
2005
int dim [sDIMEN_MAX ];
2006
2006
int numdim ;
2007
+ int explicit_init ;
2007
2008
short filenum ;
2008
2009
symbol * sym ;
2009
2010
constvalue_root * enumroot = NULL ;
@@ -2108,7 +2109,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst
2108
2109
litidx = 0 ; /* global initial data is dumped, so restart at zero */
2109
2110
} /* if */
2110
2111
assert (litidx == 0 ); /* literal queue should be empty (again) */
2111
- initials (ident ,tag ,& size ,dim ,numdim ,enumroot );/* stores values in the literal queue */
2112
+ initials (ident ,tag ,& size ,dim ,numdim ,enumroot , & explicit_init );/* stores values in the literal queue */
2112
2113
assert (size >=litidx );
2113
2114
if (numdim == 1 )
2114
2115
dim [0 ]= (int )size ;
@@ -2232,6 +2233,8 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst
2232
2233
sym -> usage |=uSTOCK ;
2233
2234
if (fstatic )
2234
2235
sym -> fnumber = filenum ;
2236
+ if (explicit_init )
2237
+ markinitialized (sym );
2235
2238
sc_attachdocumentation (sym );/* attach any documenation to the variable */
2236
2239
if (sc_status == statSKIP ) {
2237
2240
sc_status = statWRITE ;
@@ -2268,6 +2271,7 @@ static int declloc(int fstatic)
2268
2271
int numdim ;
2269
2272
int fconst ;
2270
2273
int staging_start ;
2274
+ int explicit_init ; /* is the variable explicitly initialized? */
2271
2275
2272
2276
fconst = matchtoken (tCONST );
2273
2277
do {
@@ -2318,7 +2322,7 @@ static int declloc(int fstatic)
2318
2322
sc_alignnext = FALSE;
2319
2323
} /* if */
2320
2324
cur_lit = litidx ; /* save current index in the literal table */
2321
- initials (ident ,tag ,& size ,dim ,numdim ,enumroot );
2325
+ initials (ident ,tag ,& size ,dim ,numdim ,enumroot , & explicit_init );
2322
2326
if (size == 0 )
2323
2327
return ident ; /* error message already given */
2324
2328
if (numdim == 1 )
@@ -2357,7 +2361,7 @@ static int declloc(int fstatic)
2357
2361
if (ident == iVARIABLE ) {
2358
2362
/* simple variable, also supports initialization */
2359
2363
int ctag = tag ; /* set to "tag" by default */
2360
- int explicit_init = FALSE;/* is the variable explicitly initialized? */
2364
+ explicit_init = FALSE;
2361
2365
if (matchtoken ('=' )) {
2362
2366
sym -> usage &= ~uDEFINE ; /* temporarily mark the variable as undefined to prevent
2363
2367
* possible self-assignment through its initialization expression */
@@ -2416,6 +2420,8 @@ static int declloc(int fstatic)
2416
2420
} /* if */
2417
2421
} /* if */
2418
2422
} /* if */
2423
+ if (explicit_init )
2424
+ markinitialized (sym );
2419
2425
} while (matchtoken (',' )); /* enddo */ /* more? */
2420
2426
needtoken (tTERM ); /* if not comma, must be semicolumn */
2421
2427
return ident ;
@@ -2496,14 +2502,16 @@ static int base;
2496
2502
* Global references: litidx (altered)
2497
2503
*/
2498
2504
static void initials (int ident ,int tag ,cell * size ,int dim [],int numdim ,
2499
- constvalue_root * enumroot )
2505
+ constvalue_root * enumroot , int * explicit_init )
2500
2506
{
2501
2507
int ctag ;
2502
2508
cell tablesize ;
2503
2509
int curlit = litidx ;
2504
2510
int err = 0 ;
2505
2511
int i ;
2506
2512
2513
+ if (explicit_init != NULL )
2514
+ * explicit_init = FALSE;
2507
2515
if (!matchtoken ('=' )) {
2508
2516
assert (ident != iARRAY || numdim > 0 );
2509
2517
if (ident == iARRAY ) {
@@ -2534,6 +2542,8 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim,
2534
2542
return ;
2535
2543
} /* if */
2536
2544
2545
+ if (explicit_init != NULL )
2546
+ * explicit_init = TRUE;
2537
2547
if (ident == iVARIABLE ) {
2538
2548
assert (* size == 1 );
2539
2549
init (ident ,& ctag ,NULL );
@@ -4160,7 +4170,7 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
4160
4170
lexpush (); /* initials() needs the "=" token again */
4161
4171
assert (litidx == 0 ); /* at the start of a function, this is reset */
4162
4172
assert (numtags > 0 );
4163
- initials (ident ,tags [0 ],& size ,arg -> dim ,arg -> numdim ,enumroot );
4173
+ initials (ident ,tags [0 ],& size ,arg -> dim ,arg -> numdim ,enumroot , NULL );
4164
4174
assert (size >=litidx );
4165
4175
/* allocate memory to hold the initial values */
4166
4176
arg -> defvalue .array .data = (cell * )malloc (litidx * sizeof (cell ));
@@ -4237,14 +4247,15 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
4237
4247
assert (numtags > 0 );
4238
4248
argsym = addvariable (name ,offset ,ident ,sLOCAL ,tags [0 ],
4239
4249
arg -> dim ,arg -> numdim ,arg -> idxtag ,0 );
4250
+ markinitialized (argsym );
4240
4251
if (fpublic ) {
4241
- argsym -> usage |= uREAD ; /* arguments of public functions are always "used" */
4242
- if (argsym -> ident == iREFARRAY || argsym -> ident == iREFERENCE )
4243
- argsym -> usage |= uWRITTEN ;
4244
- }
4252
+ argsym -> usage |= uREAD ; /* arguments of public functions are always "used" */
4253
+ if (argsym -> ident == iREFARRAY || argsym -> ident == iREFERENCE )
4254
+ argsym -> usage |= uWRITTEN ;
4255
+ } /* if */
4245
4256
4246
4257
if (fconst )
4247
- argsym -> usage |= uCONST ;
4258
+ argsym -> usage |= uCONST ;
4248
4259
} /* if */
4249
4260
}
4250
4261
@@ -5240,9 +5251,9 @@ SC_FUNC symbol *add_builtin_string_constant(char *name,const char *val,
5240
5251
glb_declared += litidx ;
5241
5252
dumplits ();
5242
5253
litidx = 0 ;
5243
- }
5244
- sym -> usage |= uDEFINE ;
5245
- sym -> flags |= flagPREDEF ;
5254
+ } /* if */
5255
+ sym -> usage |= ( uDEFINE | uEXPLINIT ) ;
5256
+ sym -> flags |= flagPREDEF ;
5246
5257
return sym ;
5247
5258
}
5248
5259
@@ -6094,6 +6105,7 @@ static int SC_FASTCALL emit_getlval(int *identptr,emit_outval *p,int *islocal, r
6094
6105
error (17 ,str ); /* undefined symbol */
6095
6106
return FALSE;
6096
6107
} /* if */
6108
+ markinitialized (sym );
6097
6109
markusage (sym ,uREAD | uWRITTEN );
6098
6110
6099
6111
p -> type = eotNUMBER ;
@@ -6490,6 +6502,7 @@ static void SC_FASTCALL emit_param_data(emit_outval *p)
6490
6502
case tSYMBOL :
6491
6503
sym = findloc (str );
6492
6504
if (sym != NULL ) {
6505
+ markinitialized (sym );
6493
6506
markusage (sym ,uREAD | uWRITTEN );
6494
6507
if (sym -> ident == iLABEL ) {
6495
6508
tok = tLABEL ;
@@ -6508,6 +6521,7 @@ static void SC_FASTCALL emit_param_data(emit_outval *p)
6508
6521
error (17 ,str ); /* undefined symbol */
6509
6522
return ;
6510
6523
} /* if */
6524
+ markinitialized (sym );
6511
6525
markusage (sym ,(sym -> ident == iFUNCTN || sym -> ident == iREFFUNC ) ? uREAD : (uREAD | uWRITTEN ));
6512
6526
if (sym -> ident == iFUNCTN || sym -> ident == iREFFUNC ) {
6513
6527
tok = ((sym -> usage & uNATIVE )!= 0 ) ? teNATIVE : teFUNCTN ;
@@ -6548,6 +6562,7 @@ static void SC_FASTCALL emit_param_local(emit_outval *p,int allow_ref)
6548
6562
case tSYMBOL :
6549
6563
sym = findloc (str );
6550
6564
if (sym != NULL ) {
6565
+ markinitialized (sym );
6551
6566
markusage (sym ,uREAD | uWRITTEN );
6552
6567
if (sym -> ident == iLABEL ) {
6553
6568
tok = tLABEL ;
@@ -6571,6 +6586,7 @@ static void SC_FASTCALL emit_param_local(emit_outval *p,int allow_ref)
6571
6586
error (17 ,str ); /* undefined symbol */
6572
6587
return ;
6573
6588
} /* if */
6589
+ markinitialized (sym );
6574
6590
markusage (sym ,(sym -> ident == iFUNCTN || sym -> ident == iREFFUNC ) ? uREAD : (uREAD | uWRITTEN ));
6575
6591
if (sym -> ident != iCONSTEXPR ) {
6576
6592
if (sym -> ident == iFUNCTN || sym -> ident == iREFFUNC )
0 commit comments