@@ -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 = FALSE;
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,12 +2271,14 @@ 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 {
2274
2278
ident = iVARIABLE ;
2275
2279
size = 1 ;
2276
2280
numdim = 0 ; /* no dimensions */
2281
+ explicit_init = FALSE;
2277
2282
tag = pc_addtag (NULL );
2278
2283
if (!needtoken (tSYMBOL )) {
2279
2284
lexclr (TRUE); /* drop the rest of the line... */
@@ -2318,7 +2323,7 @@ static int declloc(int fstatic)
2318
2323
sc_alignnext = FALSE;
2319
2324
} /* if */
2320
2325
cur_lit = litidx ; /* save current index in the literal table */
2321
- initials (ident ,tag ,& size ,dim ,numdim ,enumroot );
2326
+ initials (ident ,tag ,& size ,dim ,numdim ,enumroot , & explicit_init );
2322
2327
if (size == 0 )
2323
2328
return ident ; /* error message already given */
2324
2329
if (numdim == 1 )
@@ -2357,7 +2362,6 @@ static int declloc(int fstatic)
2357
2362
if (ident == iVARIABLE ) {
2358
2363
/* simple variable, also supports initialization */
2359
2364
int ctag = tag ; /* set to "tag" by default */
2360
- int explicit_init = FALSE;/* is the variable explicitly initialized? */
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 */
@@ -2379,10 +2383,13 @@ static int declloc(int fstatic)
2379
2383
stgout (staging_start );
2380
2384
stgset (FALSE);
2381
2385
check_tagmismatch (tag ,ctag ,TRUE,-1 );
2382
- /* if the variable was not explicitly initialized, reset the
2383
- * "uWRITTEN" flag that store() set */
2384
- if (!explicit_init )
2386
+ if (explicit_init ) {
2387
+ sym -> usage |= uEXPLINIT ;
2388
+ } else {
2389
+ /* if the variable was not explicitly initialized, reset the
2390
+ * "uWRITTEN" flag that store() set */
2385
2391
sym -> usage &= ~uWRITTEN ;
2392
+ } /* if */
2386
2393
} else {
2387
2394
/* an array */
2388
2395
assert (cur_lit >=0 && cur_lit <=litidx && litidx <=litmax );
@@ -2416,6 +2423,8 @@ static int declloc(int fstatic)
2416
2423
} /* if */
2417
2424
} /* if */
2418
2425
} /* if */
2426
+ if ((ident == iARRAY || fstatic ) && explicit_init )
2427
+ markinitialized (sym );
2419
2428
} while (matchtoken (',' )); /* enddo */ /* more? */
2420
2429
needtoken (tTERM ); /* if not comma, must be semicolumn */
2421
2430
return ident ;
@@ -2496,7 +2505,7 @@ static int base;
2496
2505
* Global references: litidx (altered)
2497
2506
*/
2498
2507
static void initials (int ident ,int tag ,cell * size ,int dim [],int numdim ,
2499
- constvalue_root * enumroot )
2508
+ constvalue_root * enumroot , int * explicit_init )
2500
2509
{
2501
2510
int ctag ;
2502
2511
cell tablesize ;
@@ -2534,6 +2543,8 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim,
2534
2543
return ;
2535
2544
} /* if */
2536
2545
2546
+ if (explicit_init != NULL )
2547
+ * explicit_init = TRUE;
2537
2548
if (ident == iVARIABLE ) {
2538
2549
assert (* size == 1 );
2539
2550
init (ident ,& ctag ,NULL );
@@ -4160,7 +4171,7 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
4160
4171
lexpush (); /* initials() needs the "=" token again */
4161
4172
assert (litidx == 0 ); /* at the start of a function, this is reset */
4162
4173
assert (numtags > 0 );
4163
- initials (ident ,tags [0 ],& size ,arg -> dim ,arg -> numdim ,enumroot );
4174
+ initials (ident ,tags [0 ],& size ,arg -> dim ,arg -> numdim ,enumroot , NULL );
4164
4175
assert (size >=litidx );
4165
4176
/* allocate memory to hold the initial values */
4166
4177
arg -> defvalue .array .data = (cell * )malloc (litidx * sizeof (cell ));
@@ -4237,14 +4248,15 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
4237
4248
assert (numtags > 0 );
4238
4249
argsym = addvariable (name ,offset ,ident ,sLOCAL ,tags [0 ],
4239
4250
arg -> dim ,arg -> numdim ,arg -> idxtag ,0 );
4251
+ markinitialized (argsym );
4240
4252
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
- }
4253
+ argsym -> usage |= uREAD ; /* arguments of public functions are always "used" */
4254
+ if (argsym -> ident == iREFARRAY || argsym -> ident == iREFERENCE )
4255
+ argsym -> usage |= uWRITTEN ;
4256
+ } /* if */
4245
4257
4246
4258
if (fconst )
4247
- argsym -> usage |= uCONST ;
4259
+ argsym -> usage |= uCONST ;
4248
4260
} /* if */
4249
4261
}
4250
4262
@@ -5240,9 +5252,9 @@ SC_FUNC symbol *add_builtin_string_constant(char *name,const char *val,
5240
5252
glb_declared += litidx ;
5241
5253
dumplits ();
5242
5254
litidx = 0 ;
5243
- }
5244
- sym -> usage |= uDEFINE ;
5245
- sym -> flags |= flagPREDEF ;
5255
+ } /* if */
5256
+ sym -> usage |= ( uDEFINE | uEXPLINIT ) ;
5257
+ sym -> flags |= flagPREDEF ;
5246
5258
return sym ;
5247
5259
}
5248
5260
@@ -6094,6 +6106,7 @@ static int SC_FASTCALL emit_getlval(int *identptr,emit_outval *p,int *islocal, r
6094
6106
error (17 ,str ); /* undefined symbol */
6095
6107
return FALSE;
6096
6108
} /* if */
6109
+ markinitialized (sym );
6097
6110
markusage (sym ,uREAD | uWRITTEN );
6098
6111
6099
6112
p -> type = eotNUMBER ;
@@ -6490,6 +6503,7 @@ static void SC_FASTCALL emit_param_data(emit_outval *p)
6490
6503
case tSYMBOL :
6491
6504
sym = findloc (str );
6492
6505
if (sym != NULL ) {
6506
+ markinitialized (sym );
6493
6507
markusage (sym ,uREAD | uWRITTEN );
6494
6508
if (sym -> ident == iLABEL ) {
6495
6509
tok = tLABEL ;
@@ -6508,6 +6522,7 @@ static void SC_FASTCALL emit_param_data(emit_outval *p)
6508
6522
error (17 ,str ); /* undefined symbol */
6509
6523
return ;
6510
6524
} /* if */
6525
+ markinitialized (sym );
6511
6526
markusage (sym ,(sym -> ident == iFUNCTN || sym -> ident == iREFFUNC ) ? uREAD : (uREAD | uWRITTEN ));
6512
6527
if (sym -> ident == iFUNCTN || sym -> ident == iREFFUNC ) {
6513
6528
tok = ((sym -> usage & uNATIVE )!= 0 ) ? teNATIVE : teFUNCTN ;
@@ -6548,6 +6563,7 @@ static void SC_FASTCALL emit_param_local(emit_outval *p,int allow_ref)
6548
6563
case tSYMBOL :
6549
6564
sym = findloc (str );
6550
6565
if (sym != NULL ) {
6566
+ markinitialized (sym );
6551
6567
markusage (sym ,uREAD | uWRITTEN );
6552
6568
if (sym -> ident == iLABEL ) {
6553
6569
tok = tLABEL ;
@@ -6571,6 +6587,7 @@ static void SC_FASTCALL emit_param_local(emit_outval *p,int allow_ref)
6571
6587
error (17 ,str ); /* undefined symbol */
6572
6588
return ;
6573
6589
} /* if */
6590
+ markinitialized (sym );
6574
6591
markusage (sym ,(sym -> ident == iFUNCTN || sym -> ident == iREFFUNC ) ? uREAD : (uREAD | uWRITTEN ));
6575
6592
if (sym -> ident != iCONSTEXPR ) {
6576
6593
if (sym -> ident == iFUNCTN || sym -> ident == iREFFUNC )
0 commit comments