@@ -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,12 @@ 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
+ symbol * cursym = sym ;
2238
+ do {
2239
+ cursym -> usage |= uEXPLINIT ;
2240
+ } while ((cursym = cursym -> child )!= NULL );
2241
+ } /* if */
2235
2242
sc_attachdocumentation (sym );/* attach any documenation to the variable */
2236
2243
if (sc_status == statSKIP ) {
2237
2244
sc_status = statWRITE ;
@@ -2268,12 +2275,14 @@ static int declloc(int fstatic)
2268
2275
int numdim ;
2269
2276
int fconst ;
2270
2277
int staging_start ;
2278
+ int explicit_init ; /* is the variable explicitly initialized? */
2271
2279
2272
2280
fconst = matchtoken (tCONST );
2273
2281
do {
2274
2282
ident = iVARIABLE ;
2275
2283
size = 1 ;
2276
2284
numdim = 0 ; /* no dimensions */
2285
+ explicit_init = FALSE;
2277
2286
tag = pc_addtag (NULL );
2278
2287
if (!needtoken (tSYMBOL )) {
2279
2288
lexclr (TRUE); /* drop the rest of the line... */
@@ -2318,7 +2327,7 @@ static int declloc(int fstatic)
2318
2327
sc_alignnext = FALSE;
2319
2328
} /* if */
2320
2329
cur_lit = litidx ; /* save current index in the literal table */
2321
- initials (ident ,tag ,& size ,dim ,numdim ,enumroot );
2330
+ initials (ident ,tag ,& size ,dim ,numdim ,enumroot , & explicit_init );
2322
2331
if (size == 0 )
2323
2332
return ident ; /* error message already given */
2324
2333
if (numdim == 1 )
@@ -2357,7 +2366,6 @@ static int declloc(int fstatic)
2357
2366
if (ident == iVARIABLE ) {
2358
2367
/* simple variable, also supports initialization */
2359
2368
int ctag = tag ; /* set to "tag" by default */
2360
- int explicit_init = FALSE;/* is the variable explicitly initialized? */
2361
2369
if (matchtoken ('=' )) {
2362
2370
sym -> usage &= ~uDEFINE ; /* temporarily mark the variable as undefined to prevent
2363
2371
* possible self-assignment through its initialization expression */
@@ -2416,6 +2424,12 @@ static int declloc(int fstatic)
2416
2424
} /* if */
2417
2425
} /* if */
2418
2426
} /* if */
2427
+ if ((ident == iARRAY || fstatic ) && explicit_init ) {
2428
+ symbol * cursym = sym ;
2429
+ do {
2430
+ cursym -> usage |= uEXPLINIT ;
2431
+ } while ((cursym = cursym -> child )!= NULL );
2432
+ } /* if */
2419
2433
} while (matchtoken (',' )); /* enddo */ /* more? */
2420
2434
needtoken (tTERM ); /* if not comma, must be semicolumn */
2421
2435
return ident ;
@@ -2496,7 +2510,7 @@ static int base;
2496
2510
* Global references: litidx (altered)
2497
2511
*/
2498
2512
static void initials (int ident ,int tag ,cell * size ,int dim [],int numdim ,
2499
- constvalue_root * enumroot )
2513
+ constvalue_root * enumroot , int * explicit_init )
2500
2514
{
2501
2515
int ctag ;
2502
2516
cell tablesize ;
@@ -2533,7 +2547,9 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim,
2533
2547
} /* if */
2534
2548
return ;
2535
2549
} /* if */
2536
-
2550
+
2551
+ if (explicit_init != NULL )
2552
+ * explicit_init = TRUE;
2537
2553
if (ident == iVARIABLE ) {
2538
2554
assert (* size == 1 );
2539
2555
init (ident ,& ctag ,NULL );
@@ -4160,7 +4176,7 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
4160
4176
lexpush (); /* initials() needs the "=" token again */
4161
4177
assert (litidx == 0 ); /* at the start of a function, this is reset */
4162
4178
assert (numtags > 0 );
4163
- initials (ident ,tags [0 ],& size ,arg -> dim ,arg -> numdim ,enumroot );
4179
+ initials (ident ,tags [0 ],& size ,arg -> dim ,arg -> numdim ,enumroot , NULL );
4164
4180
assert (size >=litidx );
4165
4181
/* allocate memory to hold the initial values */
4166
4182
arg -> defvalue .array .data = (cell * )malloc (litidx * sizeof (cell ));
@@ -4231,20 +4247,25 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
4231
4247
if (argsym != NULL ) {
4232
4248
error (21 ,name ); /* symbol already defined */
4233
4249
} else {
4250
+ symbol * cursym ;
4234
4251
if (chkshadow && (argsym = findglb (name ,sSTATEVAR ))!= NULL && argsym -> ident != iFUNCTN )
4235
4252
error (219 ,name ); /* variable shadows another symbol */
4236
4253
/* add details of type and address */
4237
4254
assert (numtags > 0 );
4238
4255
argsym = addvariable (name ,offset ,ident ,sLOCAL ,tags [0 ],
4239
4256
arg -> dim ,arg -> numdim ,arg -> idxtag ,0 );
4257
+ cursym = argsym ;
4258
+ do {
4259
+ cursym -> usage |= uEXPLINIT ;
4260
+ } while ((cursym = cursym -> child )!= NULL );
4240
4261
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
- }
4262
+ argsym -> usage |= uREAD ; /* arguments of public functions are always "used" */
4263
+ if (argsym -> ident == iREFARRAY || argsym -> ident == iREFERENCE )
4264
+ argsym -> usage |= uWRITTEN ;
4265
+ } /* if */
4245
4266
4246
4267
if (fconst )
4247
- argsym -> usage |= uCONST ;
4268
+ argsym -> usage |= uCONST ;
4248
4269
} /* if */
4249
4270
}
4250
4271
@@ -5240,9 +5261,9 @@ SC_FUNC symbol *add_builtin_string_constant(char *name,const char *val,
5240
5261
glb_declared += litidx ;
5241
5262
dumplits ();
5242
5263
litidx = 0 ;
5243
- }
5244
- sym -> usage |= uDEFINE ;
5245
- sym -> flags |= flagPREDEF ;
5264
+ } /* if */
5265
+ sym -> usage |= ( uDEFINE | uEXPLINIT ) ;
5266
+ sym -> flags |= flagPREDEF ;
5246
5267
return sym ;
5247
5268
}
5248
5269
0 commit comments