]>
Commit | Line | Data |
---|---|---|
616915dd | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
c59f5181 | 3 | ** Copyright (C) 1994-2003 University of Virginia, |
616915dd | 4 | ** Massachusetts Institute of Technology |
5 | ** | |
6 | ** This program is free software; you can redistribute it and/or modify it | |
7 | ** under the terms of the GNU General Public License as published by the | |
8 | ** Free Software Foundation; either version 2 of the License, or (at your | |
9 | ** option) any later version. | |
10 | ** | |
11 | ** This program is distributed in the hope that it will be useful, but | |
12 | ** WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | ** General Public License for more details. | |
15 | ** | |
16 | ** The GNU General Public License is available from http://www.gnu.org/ or | |
17 | ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
18 | ** MA 02111-1307, USA. | |
19 | ** | |
155af98d | 20 | ** For information on splint: info@splint.org |
21 | ** To report a bug: splint-bug@splint.org | |
11db3170 | 22 | ** For more information: http://www.splint.org |
616915dd | 23 | */ |
24 | /* | |
25 | ** context.c | |
26 | */ | |
27 | /* | |
28 | * Modified by Herbert 04/19/97: | |
29 | * - added include for new header portab.h containing OS dependent stuff. | |
30 | * - changed occurrances of '/' as path delimiters to macro from portab.h | |
31 | * - changed the handling of the tmp directory -- will no longer always be | |
32 | * ".", if possible, environment variables "TMP" or, if not set, "TMP", | |
33 | * or, if not set "." will be used. | |
34 | */ | |
35 | ||
1b8ae690 | 36 | # include "splintMacros.nf" |
b73d1009 | 37 | # include "basic.h" |
616915dd | 38 | |
616915dd | 39 | # include "usymtab_interface.h" |
616915dd | 40 | # include "exprChecks.h" |
41 | # include "filelocStack.h" | |
616915dd | 42 | # include "llmain.h" |
43 | # include "intSet.h" | |
44 | # include "osd.h" | |
616915dd | 45 | |
46 | extern /*@external@*/ int yydebug; | |
28bf4b0b | 47 | extern /*@external@*/ int mtdebug; |
616915dd | 48 | |
49 | typedef struct | |
50 | { | |
51 | cstring file; | |
6fcd0b1e | 52 | typeIdSet daccess; |
616915dd | 53 | } maccesst; |
54 | ||
55 | typedef enum { | |
28bf4b0b | 56 | CX_ERROR, |
57 | ||
616915dd | 58 | CX_GLOBAL, CX_INNER, |
d9a28762 | 59 | CX_FUNCTION, CX_FCNDECLARATION, |
616915dd | 60 | CX_MACROFCN, CX_MACROCONST, CX_UNKNOWNMACRO, |
7ebcc5bb | 61 | CX_ITERDEF, CX_ITEREND, |
62 | CX_OLDSTYLESCOPE, /* Parsing old-style parameter declarations */ | |
28bf4b0b | 63 | CX_LCL, CX_LCLLIB, CX_MT |
616915dd | 64 | } kcontext; |
65 | ||
28bf4b0b | 66 | static struct |
616915dd | 67 | { |
68 | int linesprocessed; | |
69 | int speclinesprocessed; | |
70 | ||
71 | flagMarkerList markers; | |
72 | ||
73 | /* | |
74 | ** used to record state where a macro must match a function name | |
75 | ** (i.e., no params were listed in the macro definition | |
76 | */ | |
77 | ||
78 | bool macroMissingParams BOOLBITS; | |
79 | bool preprocessing BOOLBITS; | |
80 | bool incommandline BOOLBITS; | |
81 | bool insuppressregion BOOLBITS; | |
82 | bool inDerivedFile BOOLBITS; | |
83 | bool instandardlib BOOLBITS; | |
84 | bool inimport BOOLBITS; | |
85 | bool inheader BOOLBITS; | |
86 | bool inmacrocache BOOLBITS; | |
87 | bool protectVars BOOLBITS; | |
88 | bool neednl BOOLBITS; | |
89 | bool showfunction BOOLBITS; | |
90 | bool savedFlags BOOLBITS; | |
91 | bool justpopped BOOLBITS; | |
92 | bool anyExports BOOLBITS; | |
d9a28762 | 93 | bool inFunctionHeader BOOLBITS; |
616915dd | 94 | |
95 | flagcode library; | |
96 | ||
97 | ynm isNullGuarded; | |
98 | fileloc saveloc; | |
99 | fileloc pushloc; | |
100 | ||
101 | clauseStack clauses; | |
102 | clause inclause; | |
103 | ||
104 | int numerrors; | |
909cf5eb | 105 | int numbugs; |
616915dd | 106 | |
107 | filelocStack locstack; | |
108 | fileTable ftab; | |
109 | cstring msgAnnote; | |
110 | /*@observer@*/ sRef aliasAnnote; | |
111 | /*@observer@*/ sRef aliasAnnoteAls; | |
112 | messageLog msgLog; | |
113 | ||
114 | macrocache mc; | |
115 | /*@observer@*/ sRefSet mods; | |
116 | ||
117 | /* file access types */ | |
118 | typeIdSet facct; | |
119 | ||
120 | /* local access types (this function) */ | |
121 | typeIdSet acct; | |
122 | ||
123 | /* no access types (@noaccess) */ | |
124 | typeIdSet nacct; | |
125 | ||
126 | /*@observer@*/ globSet globs; | |
127 | /*@only@*/ globSet globs_used; | |
128 | ||
129 | int nmods; | |
130 | int maxmods; | |
131 | /*@reldef@*/ maccesst *moduleaccess; /* Not defined is nmods == 0. */ | |
132 | ||
133 | kcontext kind; | |
134 | ||
135 | ctype boolType; | |
136 | ||
137 | bool flags[NUMFLAGS]; | |
138 | bool saveflags[NUMFLAGS]; | |
139 | bool setGlobally[NUMFLAGS]; | |
140 | bool setLocally[NUMFLAGS]; | |
141 | ||
142 | int values[NUMVALUEFLAGS]; | |
143 | int counters[NUMVALUEFLAGS]; | |
144 | ||
145 | o_cstring strings[NUMSTRINGFLAGS]; | |
b73d1009 | 146 | sRefSetList modrecs; /* Keep track of file static symbols modified. */ |
616915dd | 147 | |
28bf4b0b | 148 | metaStateTable stateTable; /* User-defined state information. */ |
149 | annotationTable annotTable; /* User-defined annotations table. */ | |
b7e84605 | 150 | union u_cont |
616915dd | 151 | { |
152 | bool glob; | |
153 | int cdepth; | |
154 | /*@dependent@*/ /*@exposed@*/ uentry fcn; | |
155 | } cont; | |
b7e84605 | 156 | |
157 | kcontext savekind; | |
158 | union u_cont savecont; | |
616915dd | 159 | } gc; |
160 | ||
161 | static /*@exposed@*/ cstring context_exposeString (flagcode p_flag) ; | |
162 | static void context_restoreFlagSettings (void) /*@modifies gc@*/ ; | |
163 | static void context_saveFlagSettings (void) /*@modifies gc@*/ ; | |
164 | static void context_exitClauseAux (exprNode p_pred, exprNode p_tbranch) | |
165 | /*@modifies gc@*/ ; | |
166 | static void context_exitClauseSimp (void) /*@modifies gc@*/ ; | |
167 | static void context_exitClausePlain (void) /*@modifies gc@*/ ; | |
168 | static void context_setJustPopped (void) /*@modifies gc.justpopped@*/ ; | |
169 | static void context_setValue (flagcode p_flag, int p_val) /*@modifies gc.flags@*/ ; | |
abd7f895 | 170 | static void context_setFlag (flagcode p_f, bool p_b, fileloc p_loc) |
616915dd | 171 | /*@modifies gc.flags@*/ ; |
172 | ||
173 | static void | |
abd7f895 | 174 | context_setFlagAux (flagcode p_f, bool p_b, bool p_inFile, |
175 | bool p_isRestore, fileloc p_loc) | |
616915dd | 176 | /*@modifies gc.flags@*/ ; |
177 | ||
abd7f895 | 178 | static void context_restoreFlag (flagcode p_f, fileloc p_loc) |
179 | /*@modifies gc.flags@*/ ; | |
616915dd | 180 | |
181 | /*@+enumindex@*/ | |
182 | ||
183 | cstring context_unparseFlagMarkers () | |
184 | { | |
185 | return (flagMarkerList_unparse (gc.markers)); | |
186 | } | |
187 | ||
188 | void context_setPreprocessing (void) | |
189 | { | |
190 | llassert (!gc.preprocessing); | |
191 | gc.preprocessing = TRUE; | |
192 | } | |
193 | ||
194 | void context_clearPreprocessing (void) | |
195 | { | |
196 | llassert (gc.preprocessing); | |
197 | gc.preprocessing = FALSE; | |
198 | } | |
199 | ||
200 | bool context_isPreprocessing (void) | |
201 | { | |
202 | return gc.preprocessing; | |
203 | } | |
204 | ||
990ec868 | 205 | bool context_loadingLibrary (void) |
206 | { | |
207 | return (fileloc_isLib (g_currentloc)); | |
208 | } | |
209 | ||
28bf4b0b | 210 | bool context_inXHFile (void) |
211 | { | |
212 | return (fileloc_isXHFile (g_currentloc)); | |
213 | } | |
214 | ||
616915dd | 215 | void context_setInCommandLine (void) |
216 | { | |
217 | llassert (!gc.incommandline); | |
218 | gc.incommandline = TRUE; | |
219 | } | |
220 | ||
221 | void context_clearInCommandLine (void) | |
222 | { | |
223 | llassert (gc.incommandline); | |
224 | gc.incommandline = FALSE; | |
225 | } | |
226 | ||
227 | bool context_isInCommandLine (void) | |
228 | { | |
229 | return gc.incommandline; | |
230 | } | |
231 | ||
232 | static | |
233 | void pushClause (clause c) /*@modifies gc.clauses, gc.inclause@*/ | |
234 | { | |
235 | gc.inclause = c; | |
236 | clauseStack_push (gc.clauses, c); | |
237 | ||
238 | if (clause_isConditional (c) | |
239 | && context_getFlag (FLG_CONTROLNESTDEPTH)) | |
240 | { | |
241 | int maxdepth = context_getValue (FLG_CONTROLNESTDEPTH); | |
242 | int depth = clauseStack_controlDepth (gc.clauses); | |
243 | ||
244 | if (depth == maxdepth + 1) | |
245 | { | |
246 | voptgenerror | |
247 | (FLG_CONTROLNESTDEPTH, | |
248 | message ("Maximum control nesting depth " | |
249 | "(%d) exceeded", | |
250 | maxdepth), | |
251 | g_currentloc); | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | static | |
257 | clause topClause (clauseStack s) /*@*/ | |
258 | { | |
259 | if (clauseStack_isEmpty (s)) return NOCLAUSE; | |
260 | return ((clause) clauseStack_top (s)); | |
261 | } | |
262 | ||
263 | void | |
264 | context_addMacroCache (/*@only@*/ cstring def) | |
265 | { | |
28bf4b0b | 266 | DPRINTF (("macro cache: %s", def)); |
267 | macrocache_addEntry (gc.mc, fileloc_copy (g_currentloc), def); | |
616915dd | 268 | } |
269 | ||
270 | void | |
abd7f895 | 271 | context_addComment (/*@only@*/ cstring def, fileloc loc) |
616915dd | 272 | { |
abd7f895 | 273 | macrocache_addComment (gc.mc, fileloc_copy (loc), def); |
616915dd | 274 | } |
275 | ||
276 | /* | |
277 | ** returns TRUE is fl is in ignore region, or region where -code | |
278 | ** | |
279 | ** the logic is fuzzy... | |
280 | */ | |
281 | ||
282 | static bool | |
283 | context_inSuppressFlagZone (fileloc fl, flagcode code) | |
284 | { | |
285 | ynm ret = flagMarkerList_suppressError (gc.markers, code, fl); | |
286 | bool res = FALSE; | |
287 | ||
288 | if (ynm_isMaybe (ret)) | |
289 | { | |
290 | /* | |
291 | ** whas is dis? | |
292 | */ | |
293 | ||
294 | if (gc.savedFlags) | |
295 | { | |
296 | res = !gc.saveflags[code]; | |
297 | } | |
298 | else | |
299 | { | |
300 | res = !context_getFlag (code); | |
301 | } | |
302 | } | |
303 | else | |
304 | { | |
305 | res = ynm_toBoolStrict (ret); | |
306 | } | |
307 | ||
308 | return res; | |
309 | } | |
310 | ||
311 | static bool | |
312 | context_suppressSystemMsg (fileloc fl) | |
313 | { | |
314 | if (context_getFlag (FLG_SYSTEMDIRERRORS)) | |
315 | { | |
316 | return FALSE; | |
317 | } | |
318 | else | |
319 | { | |
320 | return (fileloc_isSystemFile (fl)); | |
321 | } | |
322 | } | |
323 | ||
324 | bool | |
325 | context_suppressFlagMsg (flagcode flag, fileloc fl) | |
326 | { | |
327 | if (context_suppressSystemMsg (fl)) | |
328 | { | |
329 | return TRUE; | |
330 | } | |
331 | ||
60eced23 | 332 | DPRINTF (("Checking suppress: %s / %s", fileloc_unparse (fl), fileloc_unparse (g_currentloc))); |
333 | ||
616915dd | 334 | /* want same object compare here */ |
335 | ||
336 | if (fileloc_equal (fl, g_currentloc) || gc.inDerivedFile) | |
337 | { | |
60eced23 | 338 | DPRINTF (("In derived file: %s", bool_unparse (gc.inDerivedFile))); |
339 | ||
616915dd | 340 | return (!context_getFlag (flag) |
341 | || context_inSuppressRegion () | |
342 | || context_inSuppressZone (fl) | |
517a2db3 | 343 | || (context_inSuppressFlagZone (fl, flag))); /* removed gc.inDerivedFile from this */ |
616915dd | 344 | } |
345 | else | |
346 | { | |
28bf4b0b | 347 | return (context_inSuppressFlagZone (fl, flag)); |
616915dd | 348 | } |
349 | } | |
350 | ||
351 | bool | |
352 | context_suppressNotFlagMsg (flagcode flag, fileloc fl) | |
353 | { | |
354 | ||
355 | if (context_suppressSystemMsg (fl)) | |
356 | { | |
357 | return TRUE; | |
358 | } | |
359 | ||
360 | /*@access fileloc@*/ | |
361 | if (fl == g_currentloc) | |
362 | /*@noaccess fileloc@*/ | |
363 | { | |
364 | return (context_getFlag (flag) || context_inSuppressRegion ()); | |
365 | } | |
366 | else | |
367 | { | |
368 | /* for now... */ | |
369 | return (context_getFlag (flag) || context_inSuppressRegion ()); | |
370 | } | |
371 | } | |
372 | ||
373 | bool | |
374 | context_inSuppressZone (fileloc fl) | |
375 | { | |
376 | if (context_suppressSystemMsg (fl)) | |
377 | { | |
378 | return TRUE; | |
379 | } | |
380 | ||
381 | return (flagMarkerList_inIgnore (gc.markers, fl)); | |
382 | } | |
383 | ||
384 | bool | |
385 | context_inSuppressRegion (void) | |
386 | { | |
387 | return (gc.insuppressregion); | |
388 | } | |
389 | ||
390 | void | |
abd7f895 | 391 | context_enterSuppressRegion (fileloc loc) |
616915dd | 392 | { |
393 | if (gc.insuppressregion) | |
394 | { | |
395 | gc.insuppressregion = FALSE; /* get this msg! */ | |
396 | llmsg (message | |
397 | ("%q: New ignore errors region entered while in ignore errors region", | |
abd7f895 | 398 | fileloc_unparse (loc))); |
616915dd | 399 | } |
400 | ||
401 | gc.insuppressregion = TRUE; | |
abd7f895 | 402 | (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOn (loc)); |
616915dd | 403 | } |
404 | ||
405 | static void | |
abd7f895 | 406 | context_addFlagMarker (flagcode code, ynm set, fileloc loc) |
616915dd | 407 | { |
abd7f895 | 408 | (void) flagMarkerList_add (gc.markers, |
409 | flagMarker_createLocalSet (code, set, loc)); | |
616915dd | 410 | } |
411 | ||
412 | void | |
abd7f895 | 413 | context_enterSuppressLine (int count, fileloc loc) |
616915dd | 414 | { |
abd7f895 | 415 | if (context_processingMacros ()) |
416 | { | |
417 | return; | |
418 | } | |
616915dd | 419 | |
abd7f895 | 420 | if (flagMarkerList_add |
421 | (gc.markers, | |
422 | flagMarker_createIgnoreCount (count, loc))) | |
423 | { | |
424 | fileloc nextline = fileloc_copy (loc); | |
425 | fileloc_nextLine (nextline); | |
426 | fileloc_setColumn (nextline, 0); | |
616915dd | 427 | |
abd7f895 | 428 | check (flagMarkerList_add (gc.markers, |
429 | flagMarker_createIgnoreOff (nextline))); | |
430 | fileloc_free (nextline); | |
431 | } | |
616915dd | 432 | } |
433 | ||
434 | void context_checkSuppressCounts (void) | |
435 | { | |
436 | if (context_getFlag (FLG_SUPCOUNTS)) | |
437 | { | |
438 | flagMarkerList_checkSuppressCounts (gc.markers); | |
439 | } | |
440 | } | |
441 | ||
442 | void context_incLineno (void) | |
443 | { | |
444 | gc.linesprocessed++; | |
445 | incLine (); | |
446 | } | |
447 | ||
448 | void | |
abd7f895 | 449 | context_exitSuppressRegion (fileloc loc) |
616915dd | 450 | { |
451 | if (!gc.insuppressregion) | |
452 | { | |
abd7f895 | 453 | voptgenerror |
454 | (FLG_SYNTAX, | |
455 | message ("End ignore errors in region while not ignoring errors"), | |
456 | loc); | |
616915dd | 457 | } |
abd7f895 | 458 | |
459 | gc.insuppressregion = FALSE; | |
460 | (void) flagMarkerList_add (gc.markers, flagMarker_createIgnoreOff (loc)); | |
616915dd | 461 | } |
462 | ||
28bf4b0b | 463 | void |
464 | context_enterMTfile (void) | |
465 | { | |
466 | gc.kind = CX_MT; | |
467 | } | |
468 | ||
469 | void | |
470 | context_exitMTfile (void) | |
471 | { | |
472 | llassert (gc.kind == CX_MT); | |
473 | gc.kind = CX_GLOBAL; | |
474 | } | |
475 | ||
616915dd | 476 | void |
477 | context_enterLCLfile (void) | |
478 | { | |
479 | gc.kind = CX_LCL; | |
480 | gc.facct = typeIdSet_emptySet (); | |
481 | } | |
616915dd | 482 | |
483 | static void | |
484 | addModuleAccess (/*@only@*/ cstring fname, typeIdSet mods) | |
485 | { | |
486 | int i; | |
487 | ||
488 | for (i = 0; i < gc.nmods; i++) | |
489 | { | |
490 | if (cstring_equal (gc.moduleaccess[i].file, fname)) | |
491 | { | |
492 | gc.moduleaccess[i].daccess = typeIdSet_union (gc.moduleaccess[i].daccess, mods); | |
493 | cstring_free (fname); | |
494 | return; | |
495 | } | |
496 | } | |
497 | ||
498 | if (gc.nmods == gc.maxmods) | |
499 | { | |
500 | maccesst *oldmods; | |
501 | ||
502 | gc.maxmods = gc.maxmods + DEFAULTMAXMODS; | |
503 | oldmods = gc.moduleaccess; | |
504 | ||
505 | gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods)); | |
506 | ||
507 | for (i = 0; i < gc.nmods; i++) | |
508 | { | |
509 | gc.moduleaccess[i] = oldmods[i]; | |
510 | } | |
511 | ||
512 | sfree (oldmods); | |
513 | } | |
514 | ||
515 | gc.moduleaccess[gc.nmods].file = fname; | |
516 | gc.moduleaccess[gc.nmods].daccess = mods; | |
517 | ||
518 | gc.nmods++; | |
519 | } | |
520 | ||
521 | static void | |
522 | insertModuleAccess (cstring fname, typeId t) | |
523 | { | |
524 | int i; | |
525 | ||
526 | for (i = 0; i < gc.nmods; i++) | |
527 | { | |
528 | if (cstring_equal (gc.moduleaccess[i].file, fname)) | |
529 | { | |
530 | gc.moduleaccess[i].daccess = typeIdSet_insert (gc.moduleaccess[i].daccess, t); | |
531 | break; | |
532 | } | |
533 | } | |
534 | ||
535 | addModuleAccess (cstring_copy (fname), typeIdSet_single (t)); | |
536 | } | |
537 | ||
616915dd | 538 | void |
539 | context_exitLCLfile (void) | |
540 | { | |
541 | if (gc.kind != CX_LCLLIB) | |
542 | { | |
28bf4b0b | 543 | cstring lclname = |
4dd72714 | 544 | fileLib_withoutExtension (fileTable_fileName (currentFile ()), LCL_EXTENSION); |
616915dd | 545 | |
28bf4b0b | 546 | addModuleAccess (fileLib_removePath (lclname), gc.facct); |
547 | cstring_free (lclname); | |
616915dd | 548 | } |
549 | ||
550 | gc.kind = CX_LCL; | |
551 | gc.kind = CX_GLOBAL; | |
552 | gc.facct = typeIdSet_emptySet (); | |
553 | } | |
616915dd | 554 | |
555 | void | |
556 | context_dumpModuleAccess (FILE *fout) | |
557 | { | |
558 | int i = 0; | |
559 | ||
560 | for (i = 0; i < gc.nmods; i++) | |
561 | { | |
562 | cstring td = typeIdSet_dump (gc.moduleaccess[i].daccess); | |
563 | ||
564 | fprintf (fout, "%s#%s@\n", | |
565 | cstring_toCharsSafe (gc.moduleaccess[i].file), | |
566 | cstring_toCharsSafe (td)); | |
567 | ||
568 | cstring_free (td); | |
569 | } | |
570 | } | |
571 | ||
572 | bool context_usingPosixLibrary () | |
573 | { | |
574 | return (gc.library == FLG_POSIXLIB | |
575 | || gc.library == FLG_POSIXSTRICTLIB | |
576 | || gc.library == FLG_UNIXLIB | |
577 | || gc.library == FLG_UNIXSTRICTLIB); | |
578 | } | |
579 | ||
580 | bool context_usingAnsiLibrary () | |
581 | { | |
582 | return (gc.library != FLG_NOLIB); | |
583 | } | |
584 | ||
585 | flagcode context_getLibrary () | |
586 | { | |
587 | return gc.library; | |
588 | } | |
589 | ||
590 | void context_setLibrary (flagcode code) | |
591 | { | |
592 | gc.library = code; | |
593 | } | |
594 | ||
28bf4b0b | 595 | /*@observer@*/ cstring context_selectedLibrary () |
616915dd | 596 | { |
597 | switch (gc.library) | |
598 | { | |
599 | case FLG_STRICTLIB: | |
28bf4b0b | 600 | return cstring_makeLiteralTemp (LLSTRICTLIBS_NAME); |
616915dd | 601 | case FLG_POSIXLIB: |
28bf4b0b | 602 | return cstring_makeLiteralTemp (LLPOSIXLIBS_NAME); |
616915dd | 603 | case FLG_POSIXSTRICTLIB: |
28bf4b0b | 604 | return cstring_makeLiteralTemp (LLPOSIXSTRICTLIBS_NAME); |
616915dd | 605 | case FLG_UNIXLIB: |
28bf4b0b | 606 | return cstring_makeLiteralTemp (LLUNIXLIBS_NAME); |
616915dd | 607 | case FLG_UNIXSTRICTLIB: |
28bf4b0b | 608 | return cstring_makeLiteralTemp (LLUNIXSTRICTLIBS_NAME); |
616915dd | 609 | case FLG_ANSILIB: |
28bf4b0b | 610 | return cstring_makeLiteralTemp (LLSTDLIBS_NAME); |
616915dd | 611 | BADDEFAULT; |
612 | } | |
613 | } | |
614 | ||
615 | ||
616 | void | |
617 | context_loadModuleAccess (FILE *in) | |
618 | { | |
619 | char *s = mstring_create (MAX_DUMP_LINE_LENGTH); | |
620 | char *lasts = s; | |
621 | char *name = mstring_create (MAX_NAME_LENGTH); | |
622 | char *oname = name; | |
623 | # ifndef NOFREE | |
624 | char *os = s; | |
625 | # endif | |
626 | ||
28bf4b0b | 627 | while ((reader_readLine (in, s, MAX_DUMP_LINE_LENGTH) != NULL ) |
616915dd | 628 | && *s == ';') |
629 | { | |
630 | ; | |
631 | } | |
632 | ||
633 | while (s != NULL && *s != ';' && *s != '\0') | |
634 | { | |
635 | name = oname; | |
636 | ||
637 | while (*s != '#' && *s != '\0') | |
638 | { | |
639 | *name++ = *s++; | |
640 | } | |
641 | ||
642 | *name = '\0'; | |
643 | ||
644 | if (*s != '#') | |
645 | { | |
646 | llcontbug (message ("context_loadModuleAccess: bad library line: %s\n", | |
647 | cstring_fromChars (s))); | |
648 | break; | |
649 | } | |
650 | ||
651 | s++; | |
652 | ||
653 | addModuleAccess (cstring_copy (cstring_fromChars (oname)), | |
654 | typeIdSet_undump (&s)); | |
655 | ||
28bf4b0b | 656 | (void) reader_readLine (in, s, MAX_DUMP_LINE_LENGTH); |
616915dd | 657 | llassert (s != lasts); |
658 | lasts = s; | |
659 | } | |
660 | ||
661 | sfree (oname); | |
662 | # ifndef NOFREE | |
663 | sfree (os); | |
664 | # endif | |
665 | } | |
666 | ||
667 | typeIdSet context_fileAccessTypes (void) | |
668 | { | |
669 | return gc.facct; | |
670 | } | |
671 | ||
672 | void | |
673 | context_resetModeFlags (void) | |
abd7f895 | 674 | { |
616915dd | 675 | allFlagCodes (code) |
676 | { | |
677 | if (flagcode_isModeFlag (code)) | |
678 | { | |
abd7f895 | 679 | context_setFlag (code, FALSE, g_currentloc); |
616915dd | 680 | } |
982cc10b | 681 | } end_allFlagCodes; |
682 | } | |
616915dd | 683 | |
684 | /* | |
685 | ** resetAllFlags | |
686 | ** | |
687 | ** Set all flags to FALSE, except for a few which are | |
688 | ** true by default. | |
689 | ** | |
690 | ** Set all values and strings to appropriate defaults. | |
691 | ** Set all counters to 0. | |
692 | */ | |
693 | ||
694 | static void | |
695 | conext_resetAllCounters (void) | |
696 | { | |
697 | int i; | |
698 | ||
699 | for (i = 0; i < NUMVALUEFLAGS; i++) | |
700 | { | |
701 | gc.counters[i] = 0; | |
702 | } | |
703 | } | |
704 | ||
705 | void | |
3120b462 | 706 | context_resetAllFlags (void) |
616915dd | 707 | { |
982cc10b | 708 | DPRINTF (("******** Reset all flags")); |
709 | ||
616915dd | 710 | allFlagCodes (code) |
711 | { | |
712 | gc.flags[code] = FALSE; | |
713 | ||
4f43223c | 714 | if (flagcode_hasNumber (code)) |
616915dd | 715 | { |
716 | int val = 0; | |
717 | ||
718 | /*@-loopswitchbreak@*/ | |
719 | switch (code) | |
720 | { | |
721 | case FLG_LIMIT: | |
722 | val = DEFAULT_LIMIT; break; | |
28bf4b0b | 723 | case FLG_BUGSLIMIT: |
724 | val = DEFAULT_BUGSLIMIT; break; | |
616915dd | 725 | case FLG_LINELEN: |
726 | val = DEFAULT_LINELEN; break; | |
28bf4b0b | 727 | case FLG_INDENTSPACES: |
728 | val = DEFAULT_INDENTSPACES; break; | |
16c024b5 | 729 | case FLG_LOCINDENTSPACES: |
730 | val = DEFAULT_LOCINDENTSPACES; break; | |
616915dd | 731 | case FLG_EXTERNALNAMELEN: |
27c9e640 | 732 | val = ISO99_EXTERNALNAMELEN; break; |
616915dd | 733 | case FLG_INTERNALNAMELEN: |
27c9e640 | 734 | val = ISO99_INTERNALNAMELEN; break; |
616915dd | 735 | case FLG_COMMENTCHAR: |
736 | val = (int) DEFAULT_COMMENTCHAR; break; | |
737 | case FLG_CONTROLNESTDEPTH: | |
27c9e640 | 738 | val = (int) ISO99_CONTROLNESTDEPTH; break; |
616915dd | 739 | case FLG_STRINGLITERALLEN: |
27c9e640 | 740 | val = (int) ISO99_STRINGLITERALLEN; break; |
616915dd | 741 | case FLG_INCLUDENEST: |
27c9e640 | 742 | val = (int) ISO99_INCLUDENEST; break; |
616915dd | 743 | case FLG_NUMSTRUCTFIELDS: |
27c9e640 | 744 | val = (int) ISO99_NUMSTRUCTFIELDS; break; |
616915dd | 745 | case FLG_NUMENUMMEMBERS: |
27c9e640 | 746 | val = (int) ISO99_NUMENUMMEMBERS; break; |
616915dd | 747 | case FLG_EXPECT: |
748 | case FLG_LCLEXPECT: | |
749 | break; | |
750 | default: | |
751 | llbug (message ("Bad value flag: %s", flagcode_unparse (code))); | |
752 | } | |
753 | /*@=loopswitchbreak@*/ | |
754 | ||
982cc10b | 755 | DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), val)); |
616915dd | 756 | context_setValue (code, val); |
982cc10b | 757 | DPRINTF (("Set value: [%s] / %d", flagcode_unparse (code), context_getValue (code))); |
758 | llassert (context_getValue (code) == val); | |
616915dd | 759 | } |
4f43223c | 760 | else if (flagcode_hasChar (code)) |
761 | { | |
762 | llassert (code == FLG_COMMENTCHAR); | |
763 | context_setCommentMarkerChar (DEFAULT_COMMENTCHAR); | |
4f43223c | 764 | } |
616915dd | 765 | else if (flagcode_hasString (code)) |
766 | { | |
767 | cstring val = cstring_undefined; | |
768 | ||
769 | switch (code) | |
770 | { /*@-loopswitchbreak@*/ | |
771 | case FLG_LARCHPATH: | |
772 | { | |
28bf4b0b | 773 | cstring larchpath = osd_getEnvironmentVariable (LARCH_PATH); |
616915dd | 774 | |
28bf4b0b | 775 | if (cstring_isDefined (larchpath)) |
616915dd | 776 | { |
28bf4b0b | 777 | val = cstring_copy (larchpath); |
616915dd | 778 | } |
779 | else | |
780 | { | |
781 | val = cstring_makeLiteral (DEFAULT_LARCHPATH); | |
782 | } | |
783 | ||
784 | break; | |
785 | } | |
786 | case FLG_LCLIMPORTDIR: | |
787 | { | |
28bf4b0b | 788 | val = cstring_copy (osd_getEnvironment (cstring_makeLiteralTemp (LCLIMPORTDIR), cstring_makeLiteralTemp (DEFAULT_LCLIMPORTDIR))); |
616915dd | 789 | break; |
790 | } | |
791 | case FLG_TMPDIR: | |
792 | # if defined(OS2) || defined(MSDOS) || defined(WIN32) | |
793 | { | |
794 | char *env = osd_getEnvironmentVariable ("TMP"); | |
795 | ||
796 | if (env == NULL) | |
797 | { | |
798 | env = osd_getEnvironmentVariable ("TEMP"); | |
799 | } | |
800 | ||
801 | val = cstring_makeLiteral (env != NULL ? env : DEFAULT_TMPDIR); | |
802 | } | |
803 | # else | |
804 | val = cstring_makeLiteral (DEFAULT_TMPDIR); | |
805 | # endif /* !defined(OS2) && !defined(MSDOS) */ | |
806 | ||
807 | break; | |
808 | case FLG_BOOLTYPE: | |
809 | val = cstring_makeLiteral (DEFAULT_BOOLTYPE); break; | |
810 | case FLG_BOOLFALSE: | |
0bd4c301 | 811 | val = cstring_makeLiteral ("false"); break; |
616915dd | 812 | case FLG_BOOLTRUE: |
0bd4c301 | 813 | val = cstring_makeLiteral ("true"); break; |
616915dd | 814 | case FLG_MACROVARPREFIX: |
815 | val = cstring_makeLiteral ("m_"); break; | |
816 | case FLG_SYSTEMDIRS: | |
817 | val = cstring_makeLiteral (DEFAULT_SYSTEMDIR); break; | |
818 | default: | |
819 | break; | |
820 | } /*@=loopswitchbreak@*/ | |
80489f0a | 821 | |
616915dd | 822 | context_setString (code, val); |
823 | } | |
824 | else | |
825 | { | |
826 | ; /* nothing to set */ | |
827 | } | |
828 | } end_allFlagCodes; | |
829 | ||
830 | /* | |
831 | ** These flags are true by default. | |
832 | */ | |
833 | ||
b73d1009 | 834 | /* eventually, move this into flags.def */ |
28bf4b0b | 835 | |
80489f0a | 836 | gc.flags[FLG_STREAMOVERWRITE] = TRUE; |
3e3ec469 | 837 | gc.flags[FLG_OBVIOUSLOOPEXEC] = TRUE; |
616915dd | 838 | gc.flags[FLG_MODIFIES] = TRUE; |
839 | gc.flags[FLG_NESTCOMMENT] = TRUE; | |
840 | gc.flags[FLG_GLOBALS] = TRUE; | |
841 | gc.flags[FLG_FULLINITBLOCK] = TRUE; | |
7534721d | 842 | gc.flags[FLG_INITSIZE] = TRUE; |
843 | gc.flags[FLG_INITALLELEMENTS] = TRUE; | |
b73d1009 | 844 | gc.flags[FLG_NULLINIT] = TRUE; |
7534721d | 845 | |
846 | gc.flags[FLG_STRINGLITTOOLONG] = TRUE; | |
210066f9 | 847 | gc.flags[FLG_MACROCONSTDIST] = TRUE; |
616915dd | 848 | gc.flags[FLG_LIKELYBOOL] = TRUE; |
849 | gc.flags[FLG_ZEROPTR] = TRUE; | |
850 | gc.flags[FLG_NUMLITERAL] = TRUE; | |
851 | gc.flags[FLG_DUPLICATEQUALS] = TRUE; | |
abd7f895 | 852 | gc.flags[FLG_SKIPISOHEADERS] = TRUE; |
419f7a7a | 853 | gc.flags[FLG_SKIPPOSIXHEADERS] = FALSE; |
616915dd | 854 | gc.flags[FLG_SYSTEMDIREXPAND] = TRUE; |
855 | gc.flags[FLG_UNRECOGCOMMENTS] = TRUE; | |
990ec868 | 856 | gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE; |
616915dd | 857 | gc.flags[FLG_CASTFCNPTR] = TRUE; |
858 | gc.flags[FLG_DOLCS] = TRUE; | |
859 | gc.flags[FLG_USEVARARGS] = TRUE; | |
860 | gc.flags[FLG_MAINTYPE] = TRUE; | |
861 | gc.flags[FLG_SPECMACROS] = TRUE; | |
862 | gc.flags[FLG_REDEF] = TRUE; | |
863 | gc.flags[FLG_MACRONEXTLINE] = TRUE; | |
864 | ||
865 | gc.flags[FLG_SIZEOFFORMALARRAY] = TRUE; | |
866 | gc.flags[FLG_FIXEDFORMALARRAY] = TRUE; | |
867 | ||
4c9767b3 | 868 | gc.flags[FLG_UNRECOGDIRECTIVE] = TRUE; |
28bf4b0b | 869 | gc.flags[FLG_WARNUSE] = TRUE; |
616915dd | 870 | gc.flags[FLG_PREDASSIGN] = TRUE; |
871 | gc.flags[FLG_MODOBSERVER] = TRUE; | |
872 | gc.flags[FLG_MACROVARPREFIXEXCLUDE] = TRUE; | |
873 | gc.flags[FLG_EXTERNALNAMECASEINSENSITIVE] = TRUE; | |
874 | ||
875 | gc.flags[FLG_PARAMIMPTEMP] = TRUE; | |
876 | gc.flags[FLG_RETIMPONLY] = TRUE; | |
877 | gc.flags[FLG_GLOBIMPONLY] = TRUE; | |
878 | gc.flags[FLG_STRUCTIMPONLY] = TRUE; | |
879 | gc.flags[FLG_PREPROC] = TRUE; | |
880 | gc.flags[FLG_NAMECHECKS] = TRUE; | |
881 | gc.flags[FLG_FORMATCODE] = TRUE; | |
882 | gc.flags[FLG_FORMATTYPE] = TRUE; | |
883 | gc.flags[FLG_BADFLAG] = TRUE; | |
884 | gc.flags[FLG_WARNFLAGS] = TRUE; | |
60868d40 | 885 | gc.flags[FLG_WARNRC] = TRUE; |
28bf4b0b | 886 | gc.flags[FLG_FILEEXTENSIONS] = TRUE; |
35e8712d | 887 | gc.flags[FLG_WARNUNIXLIB] = FALSE; |
616915dd | 888 | gc.flags[FLG_WARNPOSIX] = TRUE; |
889 | gc.flags[FLG_SHOWCOL] = TRUE; | |
16c024b5 | 890 | gc.flags[FLG_SHOWDEEPHISTORY] = FALSE; /* TRUE; */ |
616915dd | 891 | gc.flags[FLG_SHOWFUNC] = TRUE; |
892 | gc.flags[FLG_SUPCOUNTS] = TRUE; | |
893 | gc.flags[FLG_HINTS] = TRUE; | |
894 | gc.flags[FLG_SYNTAX] = TRUE; | |
895 | gc.flags[FLG_TYPE] = TRUE; | |
896 | gc.flags[FLG_INCOMPLETETYPE] = TRUE; | |
897 | gc.flags[FLG_ABSTRACT] = TRUE; | |
e5081f8c | 898 | gc.flags[FLG_NUMABSTRACT] = TRUE; |
bb7c2085 | 899 | gc.flags[FLG_ITERBALANCE] = TRUE; |
900 | gc.flags[FLG_ITERYIELD] = TRUE; | |
901 | gc.flags[FLG_DUPLICATECASES] = TRUE; | |
902 | gc.flags[FLG_ALWAYSEXITS] = TRUE; | |
903 | gc.flags[FLG_EMPTYRETURN] = TRUE; | |
904 | gc.flags[FLG_MACRORETURN] = TRUE; | |
616915dd | 905 | gc.flags[FLG_UNRECOG] = TRUE; |
906 | gc.flags[FLG_SYSTEMUNRECOG] = TRUE; | |
907 | gc.flags[FLG_LINTCOMMENTS] = TRUE; | |
908 | gc.flags[FLG_ACCESSCZECH] = TRUE; | |
909 | gc.flags[FLG_ACCESSMODULE] = TRUE; | |
910 | gc.flags[FLG_ACCESSFILE] = TRUE; | |
911 | gc.flags[FLG_MACROVARPREFIX] = TRUE; | |
912 | ||
28bf4b0b | 913 | gc.flags[FLG_ANNOTATIONERROR] = TRUE; |
914 | gc.flags[FLG_COMMENTERROR] = TRUE; | |
915 | ||
616915dd | 916 | /* |
917 | ** Changed for version 2.4. | |
918 | */ | |
919 | ||
920 | gc.flags[FLG_GNUEXTENSIONS] = TRUE; | |
921 | ||
4a689c7f | 922 | /* |
923 | Changed for 3.0.0.19 | |
924 | */ | |
9276a168 | 925 | |
926 | /* commenting ou until some output issues are fixed */ | |
d9daf826 | 927 | gc.flags[FLG_ORCONSTRAINT] = TRUE; |
9276a168 | 928 | |
4a689c7f | 929 | gc.flags[FLG_CONSTRAINTLOCATION] = TRUE; |
e55c0c6d | 930 | |
931 | /*drl 1/18/2002*/ | |
932 | gc.flags[FLG_WARNSYSFILES] = TRUE; | |
933 | ||
616915dd | 934 | /* |
2cecdaff | 935 | ** On by default for Win32, but not Unix |
616915dd | 936 | */ |
937 | ||
6ee276d2 | 938 | # if defined (WIN32) || defined (OS2) |
616915dd | 939 | gc.flags[FLG_PARENFILEFORMAT] = TRUE; |
2cecdaff | 940 | gc.flags[FLG_CASEINSENSITIVEFILENAMES] = TRUE; |
616915dd | 941 | # endif |
942 | } | |
943 | ||
944 | /* | |
945 | ** C is way-lame, and you can initialize an array to a constant except where | |
946 | ** it is declared. Hence, a macro is used to set the modeflags. | |
947 | */ | |
948 | ||
949 | /*@notfunction@*/ | |
950 | # define SETFLAGS() \ | |
951 | { int i = 0; while (modeflags[i] != INVALID_FLAG) { \ | |
952 | if (!flagcode_isModeFlag (modeflags[i])) \ | |
953 | { llbug (message ("not a mode flag: %s", \ | |
954 | flagcode_unparse (modeflags[i]))); } \ | |
abd7f895 | 955 | else { context_setFlag (modeflags[i], TRUE, g_currentloc); } i++; }} |
616915dd | 956 | |
982cc10b | 957 | static void context_setModeAux (cstring p_s, bool p_warn) ; |
958 | ||
616915dd | 959 | void |
960 | context_setMode (cstring s) | |
982cc10b | 961 | { |
962 | context_setModeAux (s, TRUE); | |
963 | } | |
964 | ||
965 | void | |
966 | context_setModeNoWarn (cstring s) | |
967 | { | |
968 | context_setModeAux (s, FALSE); | |
969 | } | |
970 | ||
971 | void | |
972 | context_setModeAux (cstring s, bool warn) | |
616915dd | 973 | { |
974 | intSet setflags = intSet_new (); | |
975 | ||
976 | allFlagCodes (code) | |
977 | { | |
978 | if (flagcode_isModeFlag (code)) | |
979 | { | |
980 | if (gc.setGlobally[code]) | |
981 | { | |
982 | (void) intSet_insert (setflags, (int) code); | |
983 | } | |
984 | } | |
985 | } end_allFlagCodes; | |
986 | ||
987 | if (!intSet_isEmpty (setflags)) | |
988 | { | |
989 | cstring rflags = cstring_undefined; | |
990 | int num = 0; | |
991 | ||
992 | intSet_elements (setflags, el) | |
993 | { | |
994 | if (cstring_isUndefined (rflags)) | |
995 | { | |
996 | rflags = cstring_copy (flagcode_unparse ((flagcode) (el))); | |
997 | } | |
998 | else | |
999 | { | |
1000 | rflags = message ("%q, %s", rflags, | |
1001 | flagcode_unparse ((flagcode) el)); | |
1002 | } | |
1003 | ||
1004 | num++; | |
1005 | if (num > 4 && intSet_size (setflags) > 6) | |
1006 | { | |
1007 | rflags = message ("%q, (%d others) ...", rflags, | |
1008 | intSet_size (setflags) - num); | |
1009 | break; | |
1010 | } | |
1011 | } end_intSet_elements ; | |
1012 | ||
982cc10b | 1013 | if (warn) |
1014 | { | |
1015 | voptgenerror (FLG_WARNFLAGS, | |
1016 | message ("Setting mode %s after setting mode flags will " | |
1017 | "override set values of flags: %s", | |
1018 | s, rflags), | |
1019 | g_currentloc); | |
1020 | } | |
616915dd | 1021 | |
1022 | cstring_free (rflags); | |
1023 | } | |
1024 | ||
1025 | intSet_free (setflags); | |
1026 | ||
1027 | context_resetModeFlags (); | |
1028 | ||
1029 | if (cstring_equalLit (s, "standard")) | |
1030 | { | |
1031 | flagcode modeflags[] = | |
1032 | { | |
1033 | FLG_ENUMINT, FLG_MACROMATCHNAME, | |
e5081f8c | 1034 | FLG_STRINGLITNOROOM, |
37ae0b5e | 1035 | FLG_STRINGLITNOROOMFINALNULL, |
616915dd | 1036 | FLG_MACROUNDEF, FLG_RELAXQUALS, |
1037 | FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS, | |
1038 | FLG_CHECKSTRICTGLOBALIAS, | |
1039 | FLG_CHECKEDGLOBALIAS, | |
1040 | FLG_CHECKMODGLOBALIAS, | |
1041 | FLG_PREDBOOLOTHERS, FLG_PREDBOOLINT, | |
1d239d69 | 1042 | FLG_UNSIGNEDCOMPARE, |
616915dd | 1043 | FLG_PARAMUNUSED, FLG_VARUNUSED, FLG_FUNCUNUSED, |
1044 | FLG_TYPEUNUSED, | |
16c024b5 | 1045 | FLG_ABSTRACTCOMPARE, |
616915dd | 1046 | FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, FLG_FIELDUNUSED, |
1d239d69 | 1047 | FLG_PTRNUMCOMPARE, FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE, |
01a8227e | 1048 | FLG_MUTREP, FLG_NOEFFECT, FLG_IMPTYPE, |
616915dd | 1049 | FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT, |
28bf4b0b | 1050 | FLG_SPECUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, FLG_MISPLACEDSHAREQUAL, |
616915dd | 1051 | FLG_MATCHFIELDS, |
28bf4b0b | 1052 | FLG_FORMATCONST, |
616915dd | 1053 | FLG_MACROPARAMS, FLG_MACROASSIGN, FLG_SEFPARAMS, |
1054 | FLG_MACROSTMT, FLG_MACROPARENS, | |
1055 | FLG_MACROFCNDECL, | |
1056 | FLG_MACROCONSTDECL, | |
1057 | FLG_MACROREDEF, FLG_INFLOOPS, FLG_UNREACHABLE, | |
1058 | FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF, | |
1059 | FLG_FIRSTCASE, | |
1060 | FLG_NESTEDEXTERN, | |
1061 | FLG_NUMLITERAL, | |
1062 | FLG_ZEROBOOL, | |
ae133592 | 1063 | |
616915dd | 1064 | /* memchecks flags */ |
1065 | FLG_NULLDEREF, | |
1066 | FLG_NULLSTATE, FLG_NULLASSIGN, | |
1067 | FLG_NULLPASS, FLG_NULLRET, | |
ae133592 | 1068 | FLG_ALLOCMISMATCH, |
616915dd | 1069 | |
1070 | FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, | |
1071 | FLG_RETSTACK, | |
1072 | ||
1073 | /* memtrans flags */ | |
1074 | FLG_EXPOSETRANS, | |
1075 | FLG_OBSERVERTRANS, | |
1076 | FLG_DEPENDENTTRANS, | |
1077 | FLG_NEWREFTRANS, | |
1078 | FLG_ONLYTRANS, | |
1079 | FLG_OWNEDTRANS, | |
1080 | FLG_FRESHTRANS, | |
1081 | FLG_SHAREDTRANS, | |
1082 | FLG_TEMPTRANS, | |
1083 | FLG_KEPTTRANS, | |
1084 | FLG_REFCOUNTTRANS, | |
1085 | FLG_STATICTRANS, | |
1086 | FLG_UNKNOWNTRANS, | |
1087 | FLG_KEEPTRANS, | |
1088 | FLG_IMMEDIATETRANS, | |
e5081f8c | 1089 | FLG_NUMABSTRACTCAST, |
616915dd | 1090 | FLG_EXPORTLOCAL, |
1091 | ||
1092 | FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE, | |
2e127cb8 | 1093 | FLG_MUSTFREEONLY, |
1094 | FLG_MUSTFREEFRESH, | |
1095 | FLG_MUSTDEFINE, FLG_GLOBSTATE, | |
616915dd | 1096 | FLG_COMPDESTROY, FLG_MUSTNOTALIAS, |
1097 | FLG_MEMIMPLICIT, | |
1098 | FLG_BRANCHSTATE, | |
28bf4b0b | 1099 | FLG_STATETRANSFER, FLG_STATEMERGE, |
616915dd | 1100 | FLG_EVALORDER, FLG_SHADOW, FLG_READONLYSTRINGS, |
1101 | FLG_EXITARG, | |
1102 | FLG_IMPCHECKEDSPECGLOBALS, | |
1103 | FLG_MODGLOBS, FLG_WARNLINTCOMMENTS, | |
1104 | FLG_IFEMPTY, FLG_REALCOMPARE, | |
1105 | FLG_BOOLOPS, FLG_PTRNEGATE, | |
a956d444 | 1106 | FLG_SHIFTNEGATIVE, |
1107 | FLG_SHIFTIMPLEMENTATION, | |
28bf4b0b | 1108 | FLG_BUFFEROVERFLOWHIGH, |
1109 | FLG_BUFFEROVERFLOW, | |
1110 | INVALID_FLAG | |
1111 | } ; | |
616915dd | 1112 | |
1113 | SETFLAGS (); | |
1114 | } | |
1115 | else if (cstring_equalLit (s, "weak")) | |
1116 | { | |
1117 | flagcode modeflags[] = | |
1118 | { | |
81fc136a | 1119 | FLG_BOOLINT, FLG_CHARINT, FLG_FLOATDOUBLE, FLG_LONGINT, FLG_SHORTINT, |
616915dd | 1120 | FLG_ENUMINT, FLG_RELAXQUALS, FLG_FORWARDDECL, |
b73d1009 | 1121 | FLG_CHARINDEX, FLG_NUMABSTRACTINDEX, FLG_ABSTVOIDP, FLG_USEALLGLOBS, |
616915dd | 1122 | FLG_CHARUNSIGNEDCHAR, |
1123 | FLG_PREDBOOLOTHERS, | |
e5081f8c | 1124 | FLG_NUMABSTRACTLIT, |
616915dd | 1125 | FLG_VARUNUSED, FLG_FUNCUNUSED, |
1126 | FLG_TYPEUNUSED, | |
1127 | FLG_CHECKSTRICTGLOBALS, FLG_MACROMATCHNAME, | |
1128 | FLG_RETVALOTHER, | |
1129 | FLG_IFEMPTY, | |
1d239d69 | 1130 | FLG_BUFFEROVERFLOWHIGH, |
616915dd | 1131 | FLG_RETSTACK, FLG_PTRNEGATE, |
28bf4b0b | 1132 | FLG_STATETRANSFER, FLG_STATEMERGE, |
616915dd | 1133 | FLG_LONGUNSIGNEDINTEGRAL, |
1134 | FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL, | |
1135 | FLG_NUMLITERAL, | |
1136 | FLG_CHARINTLITERAL, | |
1137 | FLG_ZEROBOOL, | |
28bf4b0b | 1138 | FLG_BUFFEROVERFLOWHIGH, |
37ae0b5e | 1139 | FLG_STRINGLITNOROOM, |
1140 | FLG_STRINGLITNOROOMFINALNULL, | |
616915dd | 1141 | INVALID_FLAG |
1142 | } ; | |
1143 | ||
1144 | SETFLAGS (); | |
1145 | } | |
1146 | else if (cstring_equalLit (s, "checks")) | |
1147 | { | |
1148 | flagcode modeflags[] = | |
1149 | { | |
e5081f8c | 1150 | FLG_EXPORTLOCAL, FLG_IMPTYPE, |
1151 | FLG_NUMABSTRACTCAST, | |
16c024b5 | 1152 | FLG_ABSTRACTCOMPARE, |
28bf4b0b | 1153 | FLG_STATETRANSFER, FLG_STATEMERGE, |
616915dd | 1154 | FLG_CHECKSTRICTGLOBALIAS, |
1155 | FLG_CHECKEDGLOBALIAS, | |
1156 | FLG_CHECKMODGLOBALIAS, | |
1157 | FLG_UNCHECKEDGLOBALIAS, | |
28bf4b0b | 1158 | FLG_FORMATCONST, |
7534721d | 1159 | FLG_STRINGLITNOROOM, |
1810fe2a | 1160 | FLG_STRINGLITNOROOMFINALNULL, |
7534721d | 1161 | FLG_STRINGLITSMALLER, |
616915dd | 1162 | FLG_EXITARG, FLG_PTRNUMCOMPARE, |
1d239d69 | 1163 | FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE, |
1164 | FLG_MACROUNDEF, FLG_MUSTMOD, FLG_ALLGLOBALS, | |
616915dd | 1165 | FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT, |
1166 | FLG_USEALLGLOBS, FLG_MUTREP, FLG_RETALIAS, | |
1167 | FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE, | |
1168 | FLG_FUNCUNUSED, FLG_GLOBALSIMPMODIFIESNOTHING, | |
1169 | FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_VARUNUSED, | |
1170 | FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, | |
1171 | FLG_NOEFFECT, FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR, | |
1172 | FLG_RETVALOTHER, FLG_RETVALBOOL, FLG_RETVALINT, | |
1173 | FLG_SPECUNDEF, FLG_IMPCHECKMODINTERNALS, | |
1174 | FLG_DECLUNDEF, FLG_INCONDEFS, FLG_INCONDEFSLIB, | |
28bf4b0b | 1175 | FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL, |
b73d1009 | 1176 | FLG_NUMABSTRACTPRINT, |
616915dd | 1177 | FLG_MATCHFIELDS, |
1178 | FLG_MACROPARAMS, | |
1179 | FLG_MACROASSIGN, | |
1180 | FLG_DECLPARAMMATCH, | |
1181 | FLG_FCNDEREF, | |
1182 | FLG_FIRSTCASE, | |
1183 | FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS, | |
1184 | FLG_MACROCONSTDECL, | |
1185 | FLG_MACROFCNDECL, | |
1186 | FLG_MACROREDEF, | |
1187 | FLG_INFLOOPS, FLG_INFLOOPSUNCON, | |
1188 | FLG_UNREACHABLE, | |
1189 | FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, | |
1190 | FLG_EVALORDER, FLG_USEDEF, | |
616915dd | 1191 | FLG_NESTEDEXTERN, |
1192 | ||
1d239d69 | 1193 | /* warn use flags */ |
1194 | FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL, | |
1195 | FLG_BUFFEROVERFLOWHIGH, | |
1196 | ||
616915dd | 1197 | /* memchecks flags */ |
1198 | ||
1199 | FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN, | |
1200 | FLG_NULLPASS, FLG_NULLRET, | |
ae133592 | 1201 | FLG_ALLOCMISMATCH, |
616915dd | 1202 | |
1203 | FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, FLG_RETSTACK, | |
1204 | ||
1205 | /* memtrans flags */ | |
1206 | FLG_EXPOSETRANS, | |
1207 | FLG_OBSERVERTRANS, | |
1208 | FLG_DEPENDENTTRANS, | |
1209 | FLG_NEWREFTRANS, | |
1210 | FLG_ONLYTRANS, | |
1211 | FLG_OWNEDTRANS, | |
1212 | FLG_FRESHTRANS, | |
1213 | FLG_SHAREDTRANS, | |
1214 | FLG_TEMPTRANS, | |
1215 | FLG_KEPTTRANS, | |
1216 | FLG_REFCOUNTTRANS, | |
1217 | FLG_STATICTRANS, | |
1218 | FLG_UNKNOWNTRANS, | |
1219 | FLG_STATICINITTRANS, | |
1220 | FLG_UNKNOWNINITTRANS, | |
1221 | FLG_KEEPTRANS, | |
1222 | FLG_IMMEDIATETRANS, | |
1223 | FLG_ONLYUNQGLOBALTRANS, | |
1224 | FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE, | |
2e127cb8 | 1225 | FLG_MUSTFREEONLY, |
1226 | FLG_MUSTFREEFRESH, | |
1227 | FLG_MUSTDEFINE, FLG_GLOBSTATE, | |
616915dd | 1228 | FLG_COMPDESTROY, FLG_MUSTNOTALIAS, |
1229 | FLG_MEMIMPLICIT, | |
1230 | FLG_BRANCHSTATE, | |
1231 | FLG_NULLPOINTERARITH, | |
1232 | FLG_SHADOW, FLG_DEPARRAYS, | |
1233 | FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS, | |
1234 | FLG_LOOPLOOPBREAK, FLG_SWITCHLOOPBREAK, FLG_MODGLOBS, | |
1235 | FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS, | |
1236 | FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS, | |
abd7f895 | 1237 | FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES, |
419f7a7a | 1238 | FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE, FLG_REALRELATECOMPARE, |
a956d444 | 1239 | FLG_BOOLOPS, FLG_SHIFTNEGATIVE, |
1240 | FLG_SHIFTIMPLEMENTATION, | |
28bf4b0b | 1241 | FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW, |
616915dd | 1242 | INVALID_FLAG } ; |
1243 | ||
1244 | SETFLAGS (); | |
1245 | } | |
1246 | else if (cstring_equalLit (s, "strict")) | |
1247 | { | |
1248 | flagcode modeflags[] = | |
1249 | { | |
16c024b5 | 1250 | FLG_ABSTRACTCOMPARE, |
e5081f8c | 1251 | FLG_CHECKSTRICTGLOBALIAS, |
1252 | FLG_NUMABSTRACTCAST, | |
616915dd | 1253 | FLG_CHECKEDGLOBALIAS, |
1254 | FLG_CHECKMODGLOBALIAS, | |
1255 | FLG_UNCHECKEDGLOBALIAS, | |
1256 | FLG_MODFILESYSTEM, | |
1257 | FLG_MACROMATCHNAME, | |
28bf4b0b | 1258 | FLG_FORMATCONST, |
b73d1009 | 1259 | FLG_NUMABSTRACTPRINT, |
7534721d | 1260 | FLG_STRINGLITNOROOM, |
1810fe2a | 1261 | FLG_STRINGLITNOROOMFINALNULL, |
7534721d | 1262 | FLG_STRINGLITSMALLER, |
28bf4b0b | 1263 | FLG_STATETRANSFER, FLG_STATEMERGE, |
616915dd | 1264 | FLG_MACROUNDEF, FLG_MUTREP, FLG_MUSTMOD, |
1265 | FLG_ALLGLOBALS, FLG_IMPTYPE, | |
1266 | FLG_MODNOMODS, FLG_MODGLOBSUNSPEC, FLG_MODSTRICTGLOBSUNSPEC, | |
1267 | FLG_GLOBUNSPEC, FLG_SIZEOFTYPE, | |
1268 | FLG_EXPORTHEADER, FLG_EXPORTHEADERVAR, | |
1269 | FLG_NOPARAMS, FLG_OLDSTYLE, FLG_EXITARG, | |
1270 | FLG_RETSTACK, | |
1271 | FLG_FCNDEREF, | |
1272 | FLG_ONLYUNQGLOBALTRANS, | |
1273 | FLG_GLOBALSIMPMODIFIESNOTHING, | |
1274 | FLG_PREDBOOLOTHERS, FLG_PREDBOOLPTR, FLG_PREDBOOLINT, | |
1275 | FLG_INTERNALGLOBS, FLG_INTERNALGLOBSNOGLOBS, | |
1276 | FLG_USEALLGLOBS, FLG_RETALIAS, | |
1277 | FLG_MODGLOBS, FLG_MODGLOBSUNSPEC, FLG_MODGLOBSUNCHECKED, | |
1278 | FLG_RETEXPOSE, FLG_ASSIGNEXPOSE, FLG_CASTEXPOSE, | |
1279 | FLG_NOEFFECTUNCON, FLG_EVALORDERUNCON, | |
1280 | FLG_FUNCUNUSED, | |
1281 | FLG_EXPORTITER, FLG_EXPORTCONST, | |
1282 | FLG_TYPEUNUSED, FLG_FIELDUNUSED, FLG_PARAMUNUSED, FLG_TOPUNUSED, | |
1283 | FLG_CONSTUNUSED, FLG_ENUMMEMUNUSED, | |
1284 | FLG_VARUNUSED, | |
1285 | FLG_NULLPOINTERARITH, FLG_POINTERARITH, | |
1286 | FLG_PTRNUMCOMPARE, | |
1d239d69 | 1287 | FLG_BOOLCOMPARE, FLG_UNSIGNEDCOMPARE, |
1288 | FLG_NOEFFECT, FLG_RETVALINT, FLG_RETVALBOOL, FLG_RETVALOTHER, | |
abd7f895 | 1289 | FLG_ISORESERVED, FLG_ISORESERVEDLOCAL, FLG_CPPNAMES, |
616915dd | 1290 | FLG_RETVALBOOL, FLG_RETVALINT, FLG_SPECUNDEF, |
1291 | FLG_DECLUNDEF, FLG_STRICTOPS, FLG_INCONDEFS, | |
28bf4b0b | 1292 | FLG_MISPLACEDSHAREQUAL, FLG_REDUNDANTSHAREQUAL, |
616915dd | 1293 | FLG_INCONDEFSLIB, FLG_MATCHFIELDS, FLG_EXPORTMACRO, FLG_EXPORTVAR, |
1294 | FLG_EXPORTFCN, FLG_EXPORTTYPE, FLG_EXPORTLOCAL, FLG_MACROPARAMS, | |
1295 | FLG_MACROASSIGN, | |
1296 | FLG_SEFPARAMS, FLG_SEFUNSPEC, FLG_MACROSTMT, FLG_MACROPARENS, | |
1297 | FLG_MACROFCNDECL, | |
1298 | FLG_MACROCONSTDECL, | |
1299 | FLG_MACROREDEF, FLG_MACROEMPTY, | |
1300 | FLG_INFLOOPS, FLG_INFLOOPSUNCON, | |
1301 | FLG_UNREACHABLE, | |
1302 | FLG_NORETURN, FLG_CASEBREAK, FLG_MISSCASE, FLG_USEDEF, | |
1303 | FLG_EVALORDER, | |
1304 | FLG_MODUNCON, FLG_MODUNCONNOMODS, FLG_MODINTERNALSTRICT, | |
1305 | FLG_MODOBSERVERUNCON, | |
1306 | ||
1307 | FLG_NESTEDEXTERN, | |
1308 | FLG_FIRSTCASE, | |
1309 | ||
1d239d69 | 1310 | /* warn use flags */ |
1311 | FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL, | |
1312 | FLG_BUFFEROVERFLOWHIGH, | |
1313 | FLG_BUFFEROVERFLOW, FLG_TOCTOU, | |
1314 | ||
616915dd | 1315 | /* memchecks flags */ |
1316 | FLG_NULLSTATE, FLG_NULLDEREF, FLG_NULLASSIGN, | |
1317 | FLG_NULLPASS, FLG_NULLRET, | |
ae133592 | 1318 | FLG_ALLOCMISMATCH, |
616915dd | 1319 | FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF, |
1320 | ||
ae133592 | 1321 | /* memory checking flags */ |
1322 | FLG_BOUNDSREAD, FLG_BOUNDSWRITE, | |
1323 | FLG_LIKELYBOUNDSREAD, FLG_LIKELYBOUNDSWRITE, | |
1324 | FLG_CHECKPOST, | |
1325 | ||
616915dd | 1326 | /* memtrans flags */ |
1327 | FLG_EXPOSETRANS, | |
1328 | FLG_OBSERVERTRANS, | |
1329 | FLG_DEPENDENTTRANS, | |
1330 | FLG_NEWREFTRANS, | |
1331 | FLG_ONLYTRANS, | |
1332 | FLG_OWNEDTRANS, | |
1333 | FLG_FRESHTRANS, | |
1334 | FLG_SHAREDTRANS, | |
1335 | FLG_TEMPTRANS, | |
1336 | FLG_KEPTTRANS, | |
1337 | FLG_REFCOUNTTRANS, | |
1338 | FLG_STATICTRANS, | |
1339 | FLG_UNKNOWNTRANS, | |
1340 | FLG_KEEPTRANS, | |
1341 | FLG_IMMEDIATETRANS, | |
1342 | FLG_STATICINITTRANS, | |
1343 | FLG_UNKNOWNINITTRANS, | |
1344 | ||
1345 | FLG_USERELEASED, FLG_ALIASUNIQUE, FLG_MAYALIASUNIQUE, | |
2e127cb8 | 1346 | FLG_MUSTFREEONLY, |
1347 | FLG_MUSTFREEFRESH, | |
1348 | FLG_MUSTDEFINE, FLG_GLOBSTATE, | |
616915dd | 1349 | FLG_COMPDESTROY, FLG_MUSTNOTALIAS, |
1350 | FLG_MEMIMPLICIT, | |
1351 | FLG_BRANCHSTATE, | |
1352 | ||
1353 | FLG_DECLPARAMNAME, FLG_DECLPARAMMATCH, | |
1354 | ||
1355 | FLG_SHADOW, FLG_DEPARRAYS, | |
1356 | FLG_STRICTDESTROY, FLG_STRICTUSERELEASED, FLG_STRICTBRANCHSTATE, | |
1357 | FLG_REDECL, FLG_READONLYSTRINGS, FLG_READONLYTRANS, | |
1358 | FLG_LOOPLOOPBREAK, FLG_LOOPSWITCHBREAK, FLG_SWITCHLOOPBREAK, | |
1359 | FLG_SWITCHSWITCHBREAK, FLG_LOOPLOOPCONTINUE, | |
1360 | FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS, | |
1361 | FLG_ALLGLOBALS, FLG_IMPCHECKEDSTRICTGLOBALS, | |
1362 | FLG_IMPCHECKEDSTRICTSTATICS, | |
1363 | FLG_IMPCHECKEDSTRICTSPECGLOBALS, | |
1364 | FLG_IMPCHECKMODINTERNALS, | |
1365 | FLG_WARNMISSINGGLOBALS, FLG_WARNMISSINGGLOBALSNOGLOBS, | |
abd7f895 | 1366 | FLG_WARNLINTCOMMENTS, FLG_ISORESERVEDLOCAL, |
616915dd | 1367 | FLG_INCLUDENEST, FLG_STRINGLITERALLEN, |
1368 | FLG_NUMSTRUCTFIELDS, FLG_NUMENUMMEMBERS, | |
1369 | FLG_CONTROLNESTDEPTH, | |
1370 | FLG_FORBLOCK, FLG_WHILEBLOCK, | |
1371 | FLG_FOREMPTY, FLG_WHILEEMPTY, | |
1372 | FLG_IFEMPTY, FLG_IFBLOCK, | |
1373 | FLG_ELSEIFCOMPLETE, | |
419f7a7a | 1374 | FLG_REALCOMPARE, FLG_BOOLOPS, FLG_REALRELATECOMPARE, |
616915dd | 1375 | FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL, |
1376 | ||
a956d444 | 1377 | FLG_SHIFTNEGATIVE, |
1378 | FLG_SHIFTIMPLEMENTATION, | |
1379 | FLG_BITWISEOPS, | |
28bf4b0b | 1380 | FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW, |
1381 | INVALID_FLAG | |
1382 | } ; | |
616915dd | 1383 | |
1384 | SETFLAGS (); | |
1385 | } | |
1386 | else | |
1387 | { | |
1388 | llcontbug (message ("context_setMode: bad mode: %s", s)); | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | bool | |
1393 | context_isSpecialFile (cstring fname) | |
1394 | { | |
28bf4b0b | 1395 | cstring ext = fileLib_getExtension (fname); |
616915dd | 1396 | |
28bf4b0b | 1397 | return (cstring_equalLit (ext, ".y") |
1398 | || cstring_equalLit (ext, ".l") | |
616915dd | 1399 | || cstring_equalLit (fname, "lex.yy.c")); |
1400 | } | |
1401 | ||
1402 | bool | |
1403 | context_isSystemDir (cstring dir) | |
1404 | { | |
68de3f33 | 1405 | cstring thisdir = cstring_copy (context_getString (FLG_SYSTEMDIRS)); |
1406 | cstring savedir = thisdir; | |
1407 | cstring nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR); | |
1408 | ||
1409 | if (cstring_isDefined (nextdir)) | |
616915dd | 1410 | { |
68de3f33 | 1411 | /*@access cstring@*/ |
1412 | *nextdir = '\0'; /* closes thisdir */ | |
616915dd | 1413 | nextdir += 1; |
68de3f33 | 1414 | /*@noaccess cstring@*/ |
616915dd | 1415 | } |
1416 | ||
68de3f33 | 1417 | /* 2001-09-09: added thisdir[0] != '\0' |
1418 | ** herbert: don't compare with an empty name! | |
1419 | ** should return false for empty directory path | |
1420 | */ | |
1421 | ||
1422 | while (!cstring_isEmpty (thisdir)) | |
616915dd | 1423 | { |
1424 | DPRINTF (("Test: %s / %s", dir, thisdir)); | |
1425 | ||
68de3f33 | 1426 | if (osd_equalCanonicalPrefix (dir, thisdir)) |
616915dd | 1427 | { |
68de3f33 | 1428 | cstring_free (savedir); |
616915dd | 1429 | return TRUE; |
1430 | } | |
1431 | ||
68de3f33 | 1432 | if (cstring_isDefined (nextdir)) |
616915dd | 1433 | { |
1434 | thisdir = nextdir; | |
68de3f33 | 1435 | nextdir = cstring_afterChar (thisdir, PATH_SEPARATOR); |
616915dd | 1436 | |
68de3f33 | 1437 | if (cstring_isDefined (nextdir)) |
616915dd | 1438 | { |
68de3f33 | 1439 | /*@access cstring@*/ |
616915dd | 1440 | *nextdir = '\0'; |
1441 | nextdir += 1; | |
68de3f33 | 1442 | /*@noaccess cstring@*/ |
616915dd | 1443 | } |
1444 | } | |
1445 | else | |
1446 | { | |
1447 | break; | |
1448 | } | |
1449 | } | |
1450 | ||
1451 | DPRINTF (("Returns FALSE")); | |
68de3f33 | 1452 | cstring_free (savedir); |
616915dd | 1453 | return FALSE; |
1454 | } | |
1455 | ||
1456 | void | |
1457 | context_addFileAccessType (typeId t) | |
1458 | { | |
1459 | cstring base; | |
1460 | ||
28bf4b0b | 1461 | if (context_inFunctionLike ()) |
616915dd | 1462 | { |
1463 | gc.acct = typeIdSet_insert (gc.acct, t); | |
1464 | } | |
1465 | ||
1466 | gc.facct = typeIdSet_insert (gc.facct, t); | |
1467 | ||
1468 | base = fileloc_getBase (g_currentloc); | |
1469 | insertModuleAccess (base, t); | |
1470 | DPRINTF (("Add file access: %s / %s", typeIdSet_unparse (gc.facct), | |
1471 | typeIdSet_unparse (gc.acct))); | |
1472 | } | |
1473 | ||
1474 | void | |
1475 | context_removeFileAccessType (typeId t) | |
1476 | { | |
1477 | if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN | |
1478 | || gc.kind == CX_UNKNOWNMACRO) | |
1479 | { | |
1480 | gc.acct = typeIdSet_removeFresh (gc.acct, t); | |
1481 | } | |
1482 | ||
1483 | gc.facct = typeIdSet_removeFresh (gc.facct, t); | |
1484 | gc.nacct = typeIdSet_insert (gc.nacct, t); | |
1485 | } | |
1486 | ||
28bf4b0b | 1487 | void context_enterFunctionHeader (void) |
616915dd | 1488 | { |
b7e84605 | 1489 | if (context_getFlag (FLG_GRAMMAR)) |
1490 | { | |
1491 | lldiagmsg (message ("Enter function header: %q", context_unparse ())); | |
1492 | } | |
1493 | ||
ba45e1e4 | 1494 | if (gc.kind != CX_GLOBAL) |
1495 | { | |
1496 | llparseerror (cstring_makeLiteral | |
1497 | ("Likely parse error. Function header outside global context.")); | |
1498 | } | |
1499 | else | |
1500 | { | |
1501 | llassert (gc.kind == CX_GLOBAL); | |
1502 | DPRINTF (("Enter function header!")); | |
1503 | gc.inFunctionHeader = TRUE; | |
1504 | } | |
616915dd | 1505 | } |
1506 | ||
28bf4b0b | 1507 | void context_exitFunctionHeader (void) |
616915dd | 1508 | { |
b7e84605 | 1509 | if (context_getFlag (FLG_GRAMMAR)) |
1510 | { | |
1511 | lldiagmsg (message ("Exit function header: %q", context_unparse ())); | |
1512 | } | |
1513 | ||
d9a28762 | 1514 | DPRINTF (("Exit function header!")); |
1515 | gc.inFunctionHeader = FALSE; | |
616915dd | 1516 | } |
1517 | ||
28bf4b0b | 1518 | bool context_inFunctionHeader (void) |
1519 | { | |
d9a28762 | 1520 | return (gc.inFunctionHeader); |
28bf4b0b | 1521 | } |
1522 | ||
1523 | void context_enterFunctionDeclaration (uentry e) | |
1524 | { | |
b7e84605 | 1525 | if (context_getFlag (FLG_GRAMMAR)) |
1526 | { | |
1527 | lldiagmsg (message ("Enter function declaration: %q", context_unparse ())); | |
1528 | } | |
1529 | ||
28bf4b0b | 1530 | DPRINTF (("Enter function decl")); |
1531 | llassert (gc.savekind == CX_ERROR); | |
1532 | gc.savekind = gc.kind; | |
b7e84605 | 1533 | gc.savecont = gc.cont; |
28bf4b0b | 1534 | gc.kind = CX_FCNDECLARATION; |
1535 | gc.cont.fcn = e; | |
1536 | } | |
1537 | ||
1538 | void context_exitFunctionDeclaration (void) | |
616915dd | 1539 | { |
b7e84605 | 1540 | if (context_getFlag (FLG_GRAMMAR)) |
1541 | { | |
1542 | lldiagmsg (message ("Exit function declaration: %q", context_unparse ())); | |
1543 | } | |
1544 | ||
28bf4b0b | 1545 | DPRINTF (("Exit function decl")); |
1546 | llassert (gc.savekind != CX_ERROR); | |
1547 | llassert (gc.kind == CX_FCNDECLARATION); | |
1548 | gc.kind = gc.savekind; | |
b7e84605 | 1549 | gc.cont = gc.savecont; |
1550 | ||
28bf4b0b | 1551 | gc.savekind = CX_ERROR; |
b7e84605 | 1552 | |
1553 | if (context_getFlag (FLG_GRAMMAR)) | |
1554 | { | |
1555 | lldiagmsg (message ("After exit function declaration: %q", context_unparse ())); | |
1556 | } | |
616915dd | 1557 | } |
1558 | ||
28bf4b0b | 1559 | bool context_inFunctionDeclaration (void) |
1560 | { | |
1561 | return (gc.kind == CX_FCNDECLARATION); | |
1562 | } | |
1563 | ||
1564 | ||
616915dd | 1565 | void |
1566 | context_enterMacro (/*@observer@*/ uentry e) | |
1567 | { | |
1568 | context_enterFunction (e); | |
1569 | gc.kind = CX_MACROFCN; | |
1570 | } | |
1571 | ||
1572 | void | |
1573 | context_enterUnknownMacro (/*@dependent@*/ uentry e) | |
1574 | { | |
1575 | llassert (uentry_isFunction (e)); | |
1576 | context_enterFunction (e); | |
1577 | gc.kind = CX_UNKNOWNMACRO; | |
1578 | } | |
1579 | ||
1580 | void context_enterAndClause (exprNode e) | |
1581 | { | |
10fac4bc | 1582 | DPRINTF (("enter and clause: %s", exprNode_unparse (e))); |
616915dd | 1583 | usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e))); |
1584 | pushClause (ANDCLAUSE); | |
1585 | } | |
1586 | ||
1587 | void context_enterOrClause (exprNode e) | |
1588 | { | |
1589 | usymtab_trueBranch (guardSet_invert (exprNode_getGuards (e))); | |
1590 | pushClause (ORCLAUSE); | |
1591 | } | |
1592 | ||
1593 | bool context_inDeepLoop (void) | |
1594 | { | |
1595 | bool inLoop = FALSE; | |
1596 | ||
1597 | clauseStack_elements (gc.clauses, el) | |
1598 | { | |
1599 | if (clause_isLoop (el)) | |
1600 | { | |
1601 | if (inLoop) | |
1602 | { | |
1603 | return TRUE; | |
1604 | } | |
1605 | ||
1606 | inLoop = TRUE; | |
1607 | } | |
1608 | } end_clauseStack_elements; | |
1609 | ||
1610 | return FALSE; | |
1611 | } | |
1612 | ||
1613 | bool context_inDeepSwitch (void) | |
1614 | { | |
1615 | bool inLoop = FALSE; | |
1616 | ||
1617 | clauseStack_elements (gc.clauses, el) | |
1618 | { | |
1619 | if (clause_isSwitch (el)) | |
1620 | { | |
1621 | if (inLoop) | |
1622 | { | |
1623 | return TRUE; | |
1624 | } | |
1625 | ||
1626 | inLoop = TRUE; | |
1627 | } | |
1628 | } end_clauseStack_elements; | |
1629 | ||
1630 | return FALSE; | |
1631 | } | |
1632 | ||
1633 | bool context_inDeepLoopSwitch (void) | |
1634 | { | |
1635 | bool inLoop = FALSE; | |
1636 | ||
1637 | clauseStack_elements (gc.clauses, el) | |
1638 | { | |
1639 | if (clause_isBreakable (el)) | |
1640 | { | |
1641 | if (inLoop) | |
1642 | { | |
1643 | return TRUE; | |
1644 | } | |
1645 | ||
1646 | inLoop = TRUE; | |
1647 | } | |
1648 | } end_clauseStack_elements; | |
1649 | ||
1650 | return FALSE; | |
1651 | } | |
1652 | ||
1653 | clause context_breakClause (void) | |
1654 | { | |
1655 | clauseStack_elements (gc.clauses, el) | |
1656 | { | |
1657 | if (clause_isSwitch (el)) | |
1658 | { | |
1659 | return el; | |
1660 | } | |
1661 | else if (clause_isLoop (el)) | |
1662 | { | |
1663 | return el; | |
1664 | } | |
1665 | else | |
1666 | { | |
1667 | ; | |
1668 | } | |
1669 | } end_clauseStack_elements; | |
1670 | ||
1671 | return NOCLAUSE; | |
1672 | } | |
1673 | ||
1674 | clause context_nextBreakClause (void) | |
1675 | { | |
1676 | bool hasOne = FALSE; | |
1677 | ||
1678 | clauseStack_elements (gc.clauses, el) | |
1679 | { | |
1680 | if (clause_isBreakable (el)) | |
1681 | { | |
1682 | if (hasOne) | |
1683 | { | |
1684 | return el; | |
1685 | } | |
1686 | else | |
1687 | { | |
1688 | hasOne = TRUE; | |
1689 | } | |
1690 | } | |
1691 | } end_clauseStack_elements; | |
1692 | ||
1693 | return NOCLAUSE; | |
1694 | } | |
1695 | ||
1696 | bool context_inConditional (void) | |
1697 | { | |
1698 | clauseStack_elements (gc.clauses, el) | |
1699 | { | |
1700 | /* | |
1701 | ** Should also include TRUECLAUSE and FALSECLAUSE, but need | |
1702 | ** to distinguish if from ? for this | |
1703 | */ | |
1704 | ||
1705 | if (clause_isBreakable (el) && (el != DOWHILECLAUSE)) | |
1706 | { | |
1707 | return TRUE; | |
1708 | } | |
1709 | } end_clauseStack_elements; | |
1710 | ||
1711 | return FALSE; | |
1712 | } | |
1713 | ||
1714 | void context_exitAndClause (exprNode pred, exprNode tbranch) | |
1715 | { | |
1716 | context_setJustPopped (); | |
1717 | ||
1718 | llassert (gc.inclause == ANDCLAUSE); | |
1719 | ||
1720 | usymtab_popAndBranch (pred, tbranch); | |
1721 | clauseStack_pop (gc.clauses); | |
1722 | gc.inclause = topClause (gc.clauses); | |
1723 | } | |
1724 | ||
1725 | void context_exitOrClause (exprNode pred, exprNode tbranch) | |
1726 | { | |
1727 | context_setJustPopped (); | |
1728 | ||
1729 | llassert (gc.inclause == ORCLAUSE); | |
1730 | ||
1731 | usymtab_popOrBranch (pred, tbranch); | |
1732 | clauseStack_pop (gc.clauses); | |
1733 | gc.inclause = topClause (gc.clauses); | |
1734 | } | |
1735 | ||
1736 | static void context_enterCondClauseAux (clause cl) | |
1737 | /*@modifies gc@*/ | |
1738 | { | |
1739 | pushClause (cl); | |
1740 | } | |
1741 | ||
1742 | static void context_enterTrueAux (exprNode e, clause cl) | |
1743 | /*@modifies gc@*/ | |
1744 | { | |
1745 | usymtab_trueBranch (guardSet_copy (exprNode_getGuards (e))); | |
1746 | pushClause (cl); | |
1747 | } | |
1748 | ||
1749 | void context_enterIterClause (void) | |
1750 | { | |
1751 | context_enterTrueAux (exprNode_undefined, ITERCLAUSE); | |
1752 | } | |
1753 | ||
1754 | void context_enterDoWhileClause (void) | |
1755 | { | |
1756 | pushClause (DOWHILECLAUSE); | |
1757 | } | |
1758 | ||
1759 | void context_enterWhileClause (exprNode e) | |
1760 | { | |
1761 | context_enterTrueAux (e, WHILECLAUSE); | |
1762 | } | |
1763 | ||
1764 | void context_enterForClause (exprNode e) | |
1765 | { | |
1766 | context_enterTrueAux (e, FORCLAUSE); | |
1767 | } | |
1768 | ||
1769 | void context_enterTrueClause (exprNode e) | |
1770 | { | |
1771 | context_enterTrueAux (e, TRUECLAUSE); | |
1772 | } | |
1773 | ||
1774 | void context_enterSwitch (exprNode e) | |
1775 | { | |
7ac543fa | 1776 | DPRINTF (("Enter switch: %s", exprNode_unparse (e))); |
616915dd | 1777 | usymtab_switchBranch (e); |
1778 | context_enterCondClauseAux (SWITCHCLAUSE); | |
1779 | } | |
1780 | ||
1781 | void context_exitSwitch (exprNode e, bool allpaths) | |
1782 | { | |
7ac543fa | 1783 | usymtab_exitSwitch (e, allpaths); |
616915dd | 1784 | |
1785 | while (clause_isCase (clauseStack_top (gc.clauses))) | |
1786 | { | |
1787 | clauseStack_pop (gc.clauses); | |
1788 | } | |
1789 | ||
1790 | context_exitClauseSimp (); | |
1791 | } | |
1792 | ||
1793 | void context_enterCaseClause (exprNode e) | |
1794 | { | |
1795 | bool branch = FALSE; | |
1796 | ||
1797 | DPRINTF (("Enter case clause!")); | |
1798 | ||
1799 | branch = usymtab_newCase (exprNode_undefined, e); | |
1800 | ||
1801 | if (branch) | |
1802 | { | |
1803 | context_enterCondClauseAux (CASECLAUSE); | |
1804 | } | |
1805 | } | |
1806 | ||
1807 | static void context_enterFalseClauseAux (exprNode e, clause cl) | |
1808 | /*@modifies gc@*/ | |
1809 | { | |
1810 | usymtab_altBranch (guardSet_invert (exprNode_getGuards (e))); | |
1811 | gc.inclause = cl; | |
1812 | clauseStack_switchTop (gc.clauses, cl); | |
1813 | } | |
1814 | ||
1815 | void context_enterFalseClause (exprNode e) | |
1816 | { | |
1817 | ||
1818 | context_enterFalseClauseAux (e, FALSECLAUSE); | |
1819 | } | |
1820 | ||
1821 | void | |
1822 | context_enterConstantMacro (/*@exposed@*/ /*@dependent@*/ uentry e) | |
1823 | { | |
1824 | gc.kind = CX_MACROCONST; | |
1825 | gc.cont.fcn = e; | |
1826 | gc.showfunction = context_getFlag (FLG_SHOWFUNC); | |
1827 | ||
1828 | gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)), | |
1829 | gc.nacct); | |
1830 | ||
1831 | ||
1832 | usymtab_enterScope (); | |
1833 | sRef_enterFunctionScope (); | |
1834 | ||
1835 | gc.globs = globSet_undefined; | |
1836 | globSet_clear (gc.globs_used); | |
1837 | gc.mods = sRefSet_undefined; | |
1838 | } | |
1839 | ||
1840 | uentry context_getHeader (void) | |
1841 | { | |
1842 | if (!(context_inFunctionLike () || (gc.kind == CX_MACROCONST))) | |
1843 | { | |
1844 | llfatalbug (message ("context_getHeader: bad call: %q", | |
1845 | context_unparse ())); | |
1846 | } | |
1847 | ||
1848 | return (gc.cont.fcn); | |
1849 | } | |
1850 | ||
1851 | void | |
1852 | context_setFunctionDefined (fileloc loc) | |
1853 | { | |
1854 | switch (gc.kind) | |
1855 | { | |
1856 | case CX_UNKNOWNMACRO: | |
1857 | case CX_FUNCTION: | |
1858 | case CX_MACROFCN: | |
1859 | uentry_setFunctionDefined (gc.cont.fcn, loc); | |
1860 | break; | |
1861 | default: | |
1862 | /* (not a bug because of parse errors) */ | |
1863 | break; | |
1864 | } | |
1865 | } | |
1866 | ||
1867 | void | |
1868 | context_enterFunction (/*@exposed@*/ uentry e) | |
1869 | { | |
1870 | gc.kind = CX_FUNCTION; | |
1871 | gc.cont.fcn = e; | |
1872 | ||
28bf4b0b | 1873 | DPRINTF (("Enter function: %s", uentry_unparse (e))); |
1874 | ||
616915dd | 1875 | if (uentry_hasAccessType (e)) |
1876 | { | |
1877 | gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)), | |
1878 | gc.nacct); | |
1879 | } | |
1880 | else | |
1881 | { | |
1882 | gc.acct = gc.facct; | |
1883 | } | |
1884 | ||
1885 | DPRINTF (("Enter function: %s / %s", uentry_unparse (e), | |
1886 | typeIdSet_unparse (gc.acct))); | |
1887 | ||
1888 | gc.showfunction = context_getFlag (FLG_SHOWFUNC); | |
1889 | ||
1890 | gc.globs = uentry_getGlobs (e); | |
1891 | globSet_clear (gc.globs_used); | |
1892 | gc.mods = uentry_getMods (e); | |
1893 | ||
1894 | usymtab_enterFunctionScope (e); | |
1895 | sRef_enterFunctionScope (); | |
1896 | } | |
1897 | ||
c3be2604 | 1898 | bool context_inOldStyleScope(void) |
c21b4c87 | 1899 | { |
c3be2604 | 1900 | return (gc.kind == CX_OLDSTYLESCOPE); |
c21b4c87 | 1901 | } |
1902 | ||
7ebcc5bb | 1903 | void |
1904 | context_enterOldStyleScope (void) | |
1905 | { | |
1906 | gc.kind = CX_OLDSTYLESCOPE; | |
1907 | DPRINTF (("Enter old style scope!")); | |
1908 | usymtab_enterFunctionScope (uentry_undefined); | |
1909 | } | |
1910 | ||
1911 | void | |
1912 | context_completeOldStyleFunction (uentry e) | |
1913 | { | |
1914 | llassert (gc.kind == CX_OLDSTYLESCOPE); | |
1915 | ||
1916 | gc.kind = CX_FUNCTION; | |
1917 | gc.cont.fcn = e; | |
1918 | ||
1919 | DPRINTF (("Enter function: %s", uentry_unparse (e))); | |
1920 | ||
1921 | if (uentry_hasAccessType (e)) | |
1922 | { | |
1923 | gc.acct = typeIdSet_subtract (typeIdSet_union (gc.facct, uentry_accessType (e)), | |
1924 | gc.nacct); | |
1925 | } | |
1926 | else | |
1927 | { | |
1928 | gc.acct = gc.facct; | |
1929 | } | |
1930 | ||
1931 | DPRINTF (("Enter function: %s / %s", uentry_unparse (e), | |
1932 | typeIdSet_unparse (gc.acct))); | |
1933 | ||
1934 | gc.showfunction = context_getFlag (FLG_SHOWFUNC); | |
1935 | ||
1936 | if (!globSet_isEmpty (uentry_getGlobs (e))) | |
1937 | { | |
1938 | llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q", | |
1939 | fileloc_unparse (g_currentloc), uentry_unparse (e))); | |
1940 | } | |
1941 | ||
1942 | gc.showfunction = context_getFlag (FLG_SHOWFUNC); | |
1943 | ||
1944 | gc.globs = uentry_getGlobs (e); | |
1945 | globSet_clear (gc.globs_used); | |
1946 | ||
1947 | gc.mods = uentry_getMods (e); | |
1948 | ||
1949 | if (!sRefSet_isEmpty (gc.mods)) | |
1950 | { | |
1951 | llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q", | |
1952 | fileloc_unparse (g_currentloc), uentry_unparse (e))); | |
1953 | } | |
1954 | ||
1955 | sRef_enterFunctionScope (); | |
1956 | } | |
1957 | ||
616915dd | 1958 | static bool context_checkStrictGlobals (void) |
1959 | { | |
1960 | return (context_getFlag (FLG_CHECKSTRICTGLOBALS)); | |
1961 | } | |
1962 | ||
1963 | static bool context_hasGlobs (void) | |
1964 | { | |
1965 | if (context_inFunctionLike ()) | |
1966 | { | |
1967 | return (uentry_hasGlobs (gc.cont.fcn)); | |
1968 | } | |
1969 | else | |
1970 | { | |
1971 | return (FALSE); | |
1972 | } | |
1973 | } | |
1974 | ||
1975 | static bool context_checkCheckedGlobals (void) | |
1976 | { | |
1977 | return (context_getFlag (FLG_GLOBALS) | |
1978 | && (context_getFlag (FLG_GLOBUNSPEC) | |
1979 | || context_hasGlobs ())); | |
1980 | } | |
1981 | ||
1982 | static bool context_checkUnknownGlobals (void) | |
1983 | { | |
1984 | /* should be uentry_hasGlobs ? */ | |
1985 | ||
1986 | return (context_getFlag (FLG_ALLGLOBALS) | |
1987 | && (context_getFlag (FLG_GLOBUNSPEC) | |
1988 | || context_hasGlobs ())); | |
1989 | } | |
1990 | ||
1991 | static bool context_checkUncheckedGlobals (void) | |
1992 | { | |
1993 | return (FALSE); | |
1994 | } | |
1995 | ||
1996 | bool | |
1997 | context_checkExport (uentry e) | |
1998 | { | |
1999 | if (!gc.anyExports) return FALSE; | |
2000 | ||
2001 | if (uentry_isFunction (e) | |
2002 | || (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e)))) | |
2003 | { | |
2004 | return context_maybeSet (FLG_EXPORTFCN); | |
2005 | } | |
2006 | else if (uentry_isExpandedMacro (e)) | |
2007 | { | |
2008 | return context_maybeSet (FLG_EXPORTMACRO); | |
2009 | } | |
2010 | else if (uentry_isVariable (e)) | |
2011 | { | |
2012 | return context_maybeSet (FLG_EXPORTVAR); | |
2013 | } | |
2014 | else if (uentry_isEitherConstant (e)) | |
2015 | { | |
2016 | return context_maybeSet (FLG_EXPORTCONST); | |
2017 | } | |
2018 | else if (uentry_isIter (e) || uentry_isEndIter (e)) | |
2019 | { | |
2020 | return context_maybeSet (FLG_EXPORTITER); | |
2021 | } | |
2022 | else if (uentry_isDatatype (e)) | |
2023 | { | |
2024 | return context_maybeSet (FLG_EXPORTTYPE); | |
2025 | } | |
2026 | else | |
2027 | { | |
2028 | BADEXIT; | |
2029 | } | |
2030 | } | |
2031 | ||
2032 | bool | |
2033 | context_checkGlobUse (uentry glob) | |
2034 | { | |
2035 | ||
2036 | if (uentry_isCheckedStrict (glob)) | |
2037 | { | |
2038 | return context_checkStrictGlobals (); | |
2039 | } | |
2040 | else if (uentry_isChecked (glob)) | |
2041 | { | |
2042 | return context_checkCheckedGlobals (); | |
2043 | } | |
2044 | else if (uentry_isCheckedUnknown (glob) || uentry_isCheckMod (glob)) | |
2045 | { | |
2046 | return context_checkUnknownGlobals (); | |
2047 | } | |
2048 | else | |
2049 | { | |
2050 | llassert (uentry_isUnchecked (glob)); | |
2051 | ||
2052 | return context_checkUncheckedGlobals (); | |
2053 | } | |
2054 | } | |
2055 | ||
2056 | bool | |
2057 | context_checkAliasGlob (uentry glob) | |
2058 | { | |
2059 | if (uentry_isCheckedStrict (glob)) | |
2060 | { | |
2061 | return gc.flags[FLG_CHECKSTRICTGLOBALIAS]; | |
2062 | } | |
2063 | else if (uentry_isChecked (glob)) | |
2064 | { | |
2065 | return gc.flags[FLG_CHECKEDGLOBALIAS]; | |
2066 | } | |
2067 | else if (uentry_isCheckMod (glob)) | |
2068 | { | |
2069 | return gc.flags[FLG_CHECKMODGLOBALIAS]; | |
2070 | } | |
2071 | else | |
2072 | { | |
2073 | llassert (uentry_isUnchecked (glob) || uentry_isCheckedUnknown (glob)); | |
2074 | ||
2075 | return gc.flags[FLG_UNCHECKEDGLOBALIAS]; | |
2076 | } | |
2077 | } | |
2078 | ||
2079 | bool context_checkInternalUse (void) | |
2080 | { | |
2081 | if (context_hasGlobs ()) | |
2082 | { | |
2083 | return (gc.flags[FLG_INTERNALGLOBS]); | |
2084 | } | |
2085 | else | |
2086 | { | |
2087 | return (gc.flags[FLG_INTERNALGLOBSNOGLOBS]); | |
2088 | } | |
2089 | } | |
2090 | ||
2091 | bool | |
2092 | context_checkGlobMod (sRef el) | |
2093 | { | |
2094 | uentry ue = sRef_getUentry (el); | |
2095 | ||
28bf4b0b | 2096 | /* no: llassert (sRef_isFileOrGlobalScope (el)); also check local statics */ |
616915dd | 2097 | |
2098 | if (uentry_isCheckedModify (ue) | |
2099 | || (!uentry_isUnchecked (ue) && (gc.flags[FLG_ALLGLOBALS]))) | |
2100 | { | |
2101 | if (context_hasMods ()) | |
2102 | { | |
2103 | return (gc.flags[FLG_MODGLOBS]); | |
2104 | } | |
2105 | else | |
2106 | { | |
2107 | if (uentry_isCheckedStrict (ue)) | |
2108 | { | |
2109 | return (gc.flags[FLG_MODGLOBSUNSPEC]); | |
2110 | } | |
2111 | else | |
2112 | { | |
2113 | return (gc.flags[FLG_MODSTRICTGLOBSUNSPEC]); | |
2114 | } | |
2115 | } | |
2116 | } | |
2117 | else | |
2118 | { | |
2119 | if (context_hasMods ()) | |
2120 | { | |
2121 | return (gc.flags[FLG_MODGLOBSUNCHECKED]); | |
2122 | } | |
2123 | else | |
2124 | { | |
2125 | return FALSE; | |
2126 | } | |
2127 | } | |
2128 | } | |
2129 | ||
2130 | void | |
28bf4b0b | 2131 | context_usedGlobal (/*@exposed@*/ sRef el) |
616915dd | 2132 | { |
2133 | if (!globSet_member (gc.globs_used, el)) | |
2134 | { | |
2135 | /* | |
2136 | ** The first time a global is used in a function, we need | |
2137 | ** to clear the derived sRefs, since they were set for the | |
2138 | ** previous function. | |
2139 | */ | |
2140 | ||
2141 | sRef_clearDerived (el); | |
2142 | gc.globs_used = globSet_insert (gc.globs_used, el); | |
2143 | } | |
2144 | } | |
2145 | ||
2146 | /*@observer@*/ sRefSet | |
2147 | context_modList (void) | |
2148 | { | |
2149 | return gc.mods; | |
2150 | } | |
2151 | ||
2152 | bool | |
2153 | context_globAccess (sRef s) | |
2154 | { | |
28bf4b0b | 2155 | llassert (sRef_isFileOrGlobalScope (s) || sRef_isKindSpecial (s)); |
616915dd | 2156 | return (globSet_member (gc.globs, s)); |
2157 | } | |
2158 | ||
2159 | bool | |
2160 | context_hasAccess (typeId t) | |
2161 | { | |
2162 | if (context_inFunctionLike ()) | |
2163 | { | |
28bf4b0b | 2164 | DPRINTF (("Access %d / %s", |
2165 | t, typeIdSet_unparse (gc.acct))); | |
616915dd | 2166 | return (typeIdSet_member (gc.acct, t)); |
2167 | } | |
2168 | else | |
2169 | { | |
2170 | return (context_hasFileAccess (t)); | |
2171 | } | |
2172 | } | |
2173 | ||
2174 | bool | |
2175 | context_hasFileAccess (typeId t) | |
2176 | { | |
2177 | return (typeIdSet_member (gc.facct, t)); | |
2178 | } | |
2179 | ||
2180 | /*@only@*/ cstring | |
2181 | context_unparseAccess (void) | |
2182 | { | |
2183 | return (message ("%q / %q", typeIdSet_unparse (gc.acct), | |
2184 | typeIdSet_unparse (gc.facct))); | |
2185 | } | |
2186 | ||
2187 | /*@only@*/ cstring | |
2188 | context_unparseClauses (void) | |
2189 | { | |
2190 | return (clauseStack_unparse (gc.clauses)); | |
2191 | } | |
2192 | ||
2193 | bool | |
2194 | context_couldHaveAccess (typeId t) | |
2195 | { | |
2196 | if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO) | |
2197 | { | |
2198 | return (typeIdSet_member (gc.acct, t)); | |
2199 | } | |
2200 | else | |
2201 | { | |
2202 | return (typeIdSet_member (gc.facct, t)); | |
2203 | } | |
2204 | } | |
2205 | ||
2206 | ctype | |
2207 | context_getRetType (void) | |
2208 | { | |
2209 | ctype f = ctype_undefined; | |
2210 | ||
2211 | if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN) | |
2212 | { | |
2213 | f = uentry_getType (gc.cont.fcn); | |
2214 | } | |
2215 | else if (gc.kind == CX_UNKNOWNMACRO) | |
2216 | { | |
2217 | return ctype_unknown; | |
2218 | } | |
2219 | else | |
2220 | { | |
2221 | llcontbuglit ("context_getRetType: not in a function context"); | |
2222 | return ctype_unknown; | |
2223 | } | |
2224 | ||
2225 | if (!ctype_isFunction (f)) | |
2226 | { | |
2227 | if (ctype_isKnown (f)) | |
2228 | { | |
2229 | llbuglit ("context_getRetType: not a function"); | |
2230 | } | |
2231 | ||
2232 | return ctype_unknown; | |
2233 | } | |
28bf4b0b | 2234 | return (ctype_getReturnType (f)); |
616915dd | 2235 | } |
2236 | ||
2237 | bool | |
2238 | context_hasMods (void) | |
2239 | { | |
2240 | if (context_inFunctionLike ()) | |
2241 | { | |
2242 | return (uentry_hasMods (gc.cont.fcn)); | |
2243 | } | |
2244 | else | |
2245 | { | |
2246 | return FALSE; | |
2247 | } | |
2248 | } | |
2249 | ||
2250 | void | |
2251 | context_exitAllClauses (void) | |
28bf4b0b | 2252 | { |
616915dd | 2253 | while (!clauseStack_isEmpty (gc.clauses)) |
2254 | { | |
2255 | clause el = clauseStack_top (gc.clauses); | |
616915dd | 2256 | gc.inclause = el; |
2257 | ||
2258 | if (clause_isNone (el)) | |
2259 | { | |
2260 | usymtab_quietExitScope (g_currentloc); | |
2261 | clauseStack_pop (gc.clauses); | |
2262 | } | |
2263 | else | |
2264 | { | |
2265 | context_exitClausePlain (); | |
2266 | } | |
2267 | } | |
2268 | ||
28bf4b0b | 2269 | clauseStack_clear (gc.clauses); |
2270 | gc.inclause = NOCLAUSE; | |
2271 | } | |
616915dd | 2272 | |
28bf4b0b | 2273 | void |
2274 | context_exitAllClausesQuiet (void) | |
2275 | { | |
2276 | while (!clauseStack_isEmpty (gc.clauses)) | |
2277 | { | |
2278 | clause el = clauseStack_top (gc.clauses); | |
2279 | gc.inclause = el; | |
2280 | ||
2281 | usymtab_quietExitScope (g_currentloc); | |
2282 | clauseStack_pop (gc.clauses); | |
2283 | } | |
2284 | ||
2285 | clauseStack_clear (gc.clauses); | |
616915dd | 2286 | gc.inclause = NOCLAUSE; |
2287 | } | |
2288 | ||
2289 | static | |
2290 | void context_exitClauseSimp (void) | |
2291 | { | |
2292 | ||
2293 | context_setJustPopped (); | |
2294 | clauseStack_pop (gc.clauses); | |
2295 | gc.inclause = topClause (gc.clauses); | |
2296 | } | |
2297 | ||
2298 | static | |
2299 | void context_exitCaseClause (void) | |
2300 | { | |
2301 | context_setJustPopped (); | |
2302 | usymtab_popCaseBranch (); | |
2303 | clauseStack_pop (gc.clauses); | |
2304 | gc.inclause = topClause (gc.clauses); | |
2305 | } | |
2306 | ||
2307 | static | |
2308 | void context_exitClauseAux (exprNode pred, exprNode tbranch) | |
2309 | { | |
2310 | context_setJustPopped (); | |
b73d1009 | 2311 | usymtab_popTrueBranch (pred, tbranch, gc.inclause); /* evans 2003-02-02?: was makeAlt */ |
616915dd | 2312 | clauseStack_pop (gc.clauses); |
2313 | gc.inclause = topClause (gc.clauses); | |
2314 | } | |
2315 | ||
2316 | void context_exitTrueClause (exprNode pred, exprNode tbranch) | |
2317 | { | |
28bf4b0b | 2318 | DPRINTF (("Exit true clause: %s", exprNode_unparse (tbranch))); |
2319 | ||
616915dd | 2320 | if (gc.inclause != TRUECLAUSE) |
2321 | { | |
2322 | llparseerror (cstring_makeLiteral | |
2323 | ("Likely parse error. Conditional clauses are inconsistent.")); | |
2324 | return; | |
2325 | } | |
28bf4b0b | 2326 | |
2327 | context_setJustPopped (); | |
616915dd | 2328 | usymtab_popTrueBranch (pred, tbranch, TRUECLAUSE); |
2329 | clauseStack_pop (gc.clauses); | |
28bf4b0b | 2330 | gc.inclause = topClause (gc.clauses); |
2331 | } | |
616915dd | 2332 | |
2333 | void context_exitIterClause (exprNode body) | |
2334 | { | |
2335 | llassert (gc.inclause == ITERCLAUSE); | |
2336 | ||
2337 | context_setJustPopped (); | |
2338 | ||
3e3ec469 | 2339 | if (context_getFlag (FLG_ITERLOOPEXEC)) |
616915dd | 2340 | { |
2341 | usymtab_popTrueExecBranch (exprNode_undefined, body, ITERCLAUSE); | |
2342 | } | |
2343 | else | |
2344 | { | |
2345 | usymtab_popTrueBranch (exprNode_undefined, body, ITERCLAUSE); | |
2346 | } | |
2347 | ||
2348 | clauseStack_pop (gc.clauses); | |
2349 | gc.inclause = topClause (gc.clauses); | |
2350 | } | |
2351 | ||
2352 | static void context_popCase (void) { | |
2353 | /* | |
2354 | ** If we are exiting an outer clause, sometimes still in a switch case. | |
2355 | ** | |
2356 | ** e.g.: | |
2357 | ** | |
2358 | ** switch(a) | |
2359 | ** { | |
2360 | ** case 1: | |
2361 | ** while (c>3) | |
2362 | ** { | |
2363 | ** case 3: ++c; | |
2364 | ** } | |
2365 | ** } | |
2366 | */ | |
2367 | ||
2368 | DPRINTF (("Popping case clause: %s", | |
2369 | clauseStack_unparse (gc.clauses))); | |
28bf4b0b | 2370 | |
616915dd | 2371 | if (gc.inclause == CASECLAUSE) { |
2372 | context_exitCaseClause (); | |
2373 | } | |
2374 | } | |
2375 | ||
2376 | void context_exitWhileClause (exprNode pred, exprNode body) | |
2377 | { | |
2378 | guardSet invGuards = guardSet_invert (exprNode_getGuards (pred)); | |
2379 | ||
2380 | context_popCase (); | |
2381 | ||
2382 | if (gc.inclause != WHILECLAUSE) { | |
2383 | DPRINTF (("Clause: %s / %s", clause_unparse (gc.inclause), | |
2384 | clauseStack_unparse (gc.clauses))); | |
2385 | } | |
2386 | ||
2387 | llassert (gc.inclause == WHILECLAUSE); | |
2388 | ||
2389 | context_setJustPopped (); | |
2390 | ||
2391 | ||
2392 | /* | |
2393 | ** predicate must be false after while loop (unless there are breaks) | |
2394 | */ | |
2395 | ||
3e3ec469 | 2396 | if (context_getFlag (FLG_WHILELOOPEXEC)) |
616915dd | 2397 | { |
2398 | usymtab_popTrueExecBranch (pred, body, WHILECLAUSE); | |
2399 | } | |
2400 | else | |
2401 | { | |
2402 | usymtab_popTrueBranch (pred, body, WHILECLAUSE); | |
2403 | } | |
2404 | ||
2405 | ||
2406 | usymtab_addGuards (invGuards); | |
2407 | guardSet_free (invGuards); | |
2408 | ||
2409 | clauseStack_pop (gc.clauses); | |
2410 | gc.inclause = topClause (gc.clauses); | |
2411 | } | |
2412 | ||
2413 | void context_exitDoWhileClause (exprNode pred) | |
2414 | { | |
2415 | guardSet invGuards = guardSet_invert (exprNode_getGuards (pred)); | |
2416 | ||
2417 | if (gc.inclause == CASECLAUSE) { | |
2418 | /* handle Duff's device */ | |
2419 | clauseStack_pop (gc.clauses); | |
2420 | gc.inclause = topClause (gc.clauses); | |
2421 | } | |
2422 | ||
2423 | llassert (gc.inclause == DOWHILECLAUSE); | |
2424 | ||
2425 | context_setJustPopped (); | |
2426 | ||
2427 | ||
2428 | usymtab_addGuards (invGuards); | |
2429 | guardSet_free (invGuards); | |
2430 | ||
2431 | clauseStack_pop (gc.clauses); | |
2432 | gc.inclause = topClause (gc.clauses); | |
2433 | } | |
2434 | ||
2435 | void context_exitForClause (exprNode forPred, exprNode body) | |
2436 | { | |
2437 | guardSet invGuards = guardSet_invert (exprNode_getForGuards (forPred)); | |
2438 | ||
2439 | llassert (gc.inclause == FORCLAUSE); | |
2440 | context_setJustPopped (); | |
2441 | ||
3e3ec469 | 2442 | DPRINTF (("Exit for: %s / %s", exprNode_unparse (forPred), exprNode_unparse (body))); |
2443 | ||
616915dd | 2444 | /* |
3e3ec469 | 2445 | ** Predicate must be false after for loop (unless there are breaks) |
616915dd | 2446 | */ |
2447 | ||
3e3ec469 | 2448 | if (context_getFlag (FLG_FORLOOPEXEC)) |
616915dd | 2449 | { |
3e3ec469 | 2450 | DPRINTF (("Here: for loop exec")); |
28bf4b0b | 2451 | usymtab_popTrueExecBranch (forPred, body, FORCLAUSE); |
616915dd | 2452 | } |
2453 | else | |
2454 | { | |
3e3ec469 | 2455 | if (context_getFlag (FLG_OBVIOUSLOOPEXEC) |
2456 | && exprNode_loopMustExec (forPred)) | |
2457 | { | |
2458 | DPRINTF (("Here: loop must exec")); | |
2459 | usymtab_popTrueExecBranch (forPred, body, FORCLAUSE); | |
2460 | } | |
2461 | else | |
2462 | { | |
2463 | DPRINTF (("Pop true branch:")); | |
2464 | usymtab_popTrueBranch (forPred, body, FORCLAUSE); | |
2465 | } | |
616915dd | 2466 | } |
2467 | ||
2468 | usymtab_addGuards (invGuards); | |
2469 | guardSet_free (invGuards); | |
2470 | clauseStack_pop (gc.clauses); | |
2471 | gc.inclause = topClause (gc.clauses); | |
2472 | } | |
2473 | ||
2474 | static void context_exitClausePlain (void) | |
2475 | { | |
2476 | llassert (gc.inclause != NOCLAUSE); | |
2477 | ||
2478 | if (gc.inclause == FALSECLAUSE) | |
2479 | { | |
2480 | context_exitClause (exprNode_undefined, exprNode_undefined, exprNode_undefined); | |
2481 | } | |
2482 | else | |
2483 | { | |
2484 | context_exitClauseAux (exprNode_undefined, exprNode_undefined); | |
2485 | } | |
616915dd | 2486 | } |
2487 | ||
2488 | void context_exitClause (exprNode pred, exprNode tbranch, exprNode fbranch) | |
2489 | { | |
616915dd | 2490 | context_setJustPopped (); |
28bf4b0b | 2491 | |
616915dd | 2492 | if (gc.inclause == FALSECLAUSE) |
2493 | { | |
2494 | usymtab_popBranches (pred, tbranch, fbranch, FALSE, FALSECLAUSE); | |
28bf4b0b | 2495 | |
616915dd | 2496 | llassert (clauseStack_top (gc.clauses) == FALSECLAUSE); |
2497 | ||
2498 | clauseStack_pop (gc.clauses); | |
2499 | gc.inclause = topClause (gc.clauses); | |
2500 | } | |
2501 | else | |
2502 | { | |
28bf4b0b | 2503 | context_exitTrueClause (pred, tbranch); |
616915dd | 2504 | } |
2505 | } | |
2506 | ||
2507 | void | |
2508 | context_returnFunction (void) | |
2509 | { | |
2510 | usymtab_checkFinalScope (TRUE); | |
2511 | } | |
2512 | ||
2513 | void | |
2514 | context_exitFunction (void) | |
2515 | { | |
b7e84605 | 2516 | DPRINTF (("Exit function: %s", context_unparse ())); |
2517 | ||
616915dd | 2518 | if (!context_inFunction () && !context_inMacroConstant () |
b7e84605 | 2519 | && !context_inUnknownMacro () |
616915dd | 2520 | && !context_inIterDef () && !context_inIterEnd ()) |
2521 | { | |
2522 | /* | |
2523 | ** not a bug because of parse errors | |
2524 | */ | |
b7e84605 | 2525 | |
2526 | BADBRANCH; | |
616915dd | 2527 | } |
2528 | else | |
2529 | { | |
2530 | if (context_inMacro () && usymtab_inFunctionScope ()) | |
2531 | { | |
2532 | usymtab_exitScope (exprNode_undefined); | |
2533 | } | |
2534 | ||
2535 | if (uentry_hasGlobs (gc.cont.fcn)) | |
2536 | { | |
2537 | exprChecks_checkUsedGlobs (gc.globs, gc.globs_used); | |
2538 | } | |
2539 | ||
2540 | ||
2541 | if (uentry_hasMods (gc.cont.fcn)) | |
2542 | { | |
2543 | if (context_getFlag (FLG_MUSTMOD)) | |
2544 | { | |
2545 | exprNode_checkAllMods (gc.mods, gc.cont.fcn); | |
2546 | } | |
2547 | } | |
2548 | ||
28bf4b0b | 2549 | DPRINTF (("Exit function: %s", uentry_unparse (gc.cont.fcn))); |
2550 | ||
616915dd | 2551 | /* |
2552 | ** clear file static modifies | |
2553 | */ | |
2554 | ||
2555 | /* do this first to get unused error messages */ | |
2556 | ||
2557 | usymtab_exitScope (exprNode_undefined); | |
2558 | sRef_exitFunctionScope (); | |
2559 | ||
2560 | gc.showfunction = FALSE; | |
2561 | gc.kind = CX_GLOBAL; | |
2562 | gc.cont.glob = TRUE; | |
2563 | gc.acct = gc.facct; | |
2564 | gc.globs = globSet_new (); | |
2565 | globSet_clear (gc.globs_used); | |
2566 | gc.mods = sRefSet_new (); | |
2567 | } | |
2568 | ||
2569 | llassert (clauseStack_isEmpty (gc.clauses)); | |
2570 | llassert (gc.inclause == NOCLAUSE); | |
b7e84605 | 2571 | DPRINTF (("After exit function: %s", context_unparse ())); |
616915dd | 2572 | } |
2573 | ||
2574 | void | |
2575 | context_quietExitFunction (void) | |
2576 | { | |
2577 | while (gc.kind == CX_INNER) | |
2578 | { | |
2579 | context_exitInnerPlain (); | |
2580 | } | |
2581 | ||
b7e84605 | 2582 | if (!context_inFunction () && !context_inMacroConstant () && !context_inUnknownMacro () |
616915dd | 2583 | && !context_inIterDef () && !context_inIterEnd ()) |
2584 | { | |
2585 | } | |
2586 | else | |
2587 | { | |
2588 | usymtab_quietExitScope (g_currentloc); | |
2589 | ||
2590 | gc.showfunction = FALSE; | |
2591 | gc.kind = CX_GLOBAL; | |
2592 | gc.cont.glob = TRUE; | |
2593 | gc.acct = gc.facct; | |
2594 | gc.globs = globSet_new (); | |
2595 | globSet_clear (gc.globs_used); | |
2596 | gc.mods = sRefSet_new (); | |
2597 | ||
2598 | sRef_exitFunctionScope (); | |
2599 | } | |
2600 | } | |
2601 | ||
2602 | /*@observer@*/ uentryList | |
2603 | context_getParams (void) | |
2604 | { | |
2605 | if (context_inFunctionLike ()) | |
2606 | { | |
2607 | return (uentry_getParams (gc.cont.fcn)); | |
2608 | } | |
2609 | else | |
2610 | { | |
2611 | llcontbug (message ("context_getParams: not in function: %q", context_unparse ())); | |
2612 | return uentryList_undefined; | |
2613 | } | |
2614 | } | |
2615 | ||
2616 | /*@observer@*/ globSet | |
2617 | context_getUsedGlobs (void) | |
2618 | { | |
2619 | llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN | |
2620 | || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF); | |
2621 | ||
2622 | return (gc.globs_used); | |
2623 | } | |
2624 | ||
2625 | cstring | |
2626 | context_moduleName () | |
2627 | { | |
2628 | return (fileloc_getBase (g_currentloc)); | |
2629 | } | |
2630 | ||
2631 | /*@observer@*/ globSet | |
2632 | context_getGlobs (void) | |
2633 | { | |
2634 | llassert (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN | |
2635 | || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF); | |
2636 | ||
2637 | return (gc.globs); | |
2638 | } | |
2639 | ||
2640 | void | |
2641 | context_addBoolAccess (void) | |
2642 | { | |
2643 | cstring bname = context_getString (FLG_BOOLTYPE); | |
2644 | typeIdSet boolt = typeIdSet_single (usymtab_getTypeId (bname)); | |
2645 | ||
2646 | addModuleAccess (cstring_copy (bname), boolt); | |
2647 | ||
2648 | /* for sys/types (perhaps, this is bogus!) */ | |
2649 | addModuleAccess (cstring_makeLiteral ("types"), boolt); | |
2650 | } | |
2651 | ||
2652 | # if 0 | |
2653 | bool | |
2654 | context_canAccessBool (void) | |
2655 | { | |
2656 | return TRUE; | |
2657 | } | |
2658 | # endif | |
2659 | ||
2660 | /* | |
2661 | static typeId boolType = typeId_invalid; | |
2662 | ||
2663 | if (typeId_isInvalid (boolType)) | |
2664 | { | |
2665 | boolType = usymtab_getTypeId (context_getBoolName ()); | |
2666 | } | |
2667 | ||
2668 | if (typeId_isInvalid (boolType)) { | |
2669 | return FALSE; | |
2670 | } else { | |
2671 | return (typeIdSet_member (gc.acct, boolType)); | |
2672 | } | |
2673 | } | |
2674 | */ | |
2675 | ||
2676 | /* evs 2000-07-25: old version - replaced */ | |
2677 | ||
2678 | ctype | |
2679 | context_boolImplementationType () { | |
2680 | /* For now, this is bogus! */ | |
2681 | return ctype_int; | |
2682 | } | |
2683 | ||
2684 | bool | |
2685 | context_canAccessBool (void) | |
2686 | { | |
2687 | static typeId boolType = typeId_invalid; | |
2688 | ||
2689 | if (typeId_isInvalid (boolType)) | |
2690 | { | |
2691 | boolType = usymtab_getTypeId (context_getBoolName ()); | |
2692 | } | |
2693 | ||
2694 | if (!typeId_isInvalid (boolType)) | |
2695 | { | |
2696 | return context_hasAccess (boolType); | |
2697 | } | |
2698 | else | |
2699 | { | |
2700 | ; | |
2701 | } | |
2702 | ||
2703 | return FALSE; | |
2704 | } | |
2705 | ||
2706 | void | |
2707 | context_setMessageAnnote (/*@only@*/ cstring s) | |
2708 | { | |
2709 | llassert (cstring_isUndefined (gc.msgAnnote)); | |
2710 | gc.msgAnnote = s; | |
2711 | } | |
2712 | ||
2713 | bool | |
2714 | context_hasMessageAnnote (void) | |
2715 | { | |
2716 | return (cstring_isDefined (gc.msgAnnote)); | |
2717 | } | |
2718 | ||
2719 | void | |
2720 | context_clearMessageAnnote (void) | |
2721 | { | |
2722 | if (cstring_isDefined (gc.msgAnnote)) | |
2723 | { | |
2724 | cstring_free (gc.msgAnnote); | |
2725 | gc.msgAnnote = cstring_undefined; | |
2726 | } | |
2727 | } | |
2728 | ||
2729 | /*@only@*/ cstring | |
2730 | context_getMessageAnnote (void) | |
2731 | { | |
2732 | cstring st = gc.msgAnnote; | |
2733 | ||
2734 | gc.msgAnnote = cstring_undefined; | |
2735 | return st; | |
2736 | } | |
2737 | ||
2738 | void | |
2739 | context_setAliasAnnote (/*@observer@*/ sRef s, /*@observer@*/ sRef t) | |
2740 | { | |
2741 | llassert (sRef_isInvalid (gc.aliasAnnote)); | |
2742 | llassert (!sRef_sameName (s, t)); | |
2743 | gc.aliasAnnote = s; | |
2744 | gc.aliasAnnoteAls = t; | |
2745 | } | |
2746 | ||
2747 | bool | |
2748 | context_hasAliasAnnote (void) | |
2749 | { | |
2750 | return (sRef_isValid (gc.aliasAnnote)); | |
2751 | } | |
2752 | ||
2753 | void | |
2754 | context_clearAliasAnnote (void) | |
2755 | { | |
2756 | gc.aliasAnnote = sRef_undefined; | |
2757 | } | |
2758 | ||
2759 | cstring | |
2760 | context_getAliasAnnote (void) | |
2761 | { | |
2762 | sRef ret = gc.aliasAnnote; | |
2763 | sRef als = gc.aliasAnnoteAls; | |
2764 | ||
2765 | llassert (sRef_isValid (ret) && sRef_isValid (als)); | |
2766 | ||
2767 | gc.aliasAnnote = sRef_undefined; | |
2768 | return (message ("%q aliases %q", sRef_unparse (als), sRef_unparse (ret))); | |
2769 | } | |
2770 | ||
2771 | void | |
2772 | context_recordFileModifies (sRefSet mods) | |
2773 | { | |
28bf4b0b | 2774 | gc.modrecs = sRefSetList_add (gc.modrecs, mods); |
616915dd | 2775 | } |
2776 | ||
2777 | void | |
2778 | context_recordFileGlobals (globSet mods) | |
2779 | { | |
28bf4b0b | 2780 | DPRINTF (("Recording file globals: %s", globSet_unparse (mods))); |
2781 | /*@access globSet@*/ context_recordFileModifies (mods); /*@noaccess globSet@*/ | |
616915dd | 2782 | } |
2783 | ||
2784 | void | |
2785 | context_setCommentMarkerChar (char c) | |
2786 | { | |
2787 | llassert (c != '\0'); | |
2788 | ||
2789 | context_setValue (FLG_COMMENTCHAR, (int) c); | |
2790 | } | |
2791 | ||
2792 | char | |
2793 | context_getCommentMarkerChar (void) | |
2794 | { | |
2795 | return ((char) context_getValue (FLG_COMMENTCHAR)); | |
2796 | } | |
2797 | ||
2798 | static void | |
2799 | context_setValue (flagcode flag, int val) | |
2800 | { | |
2801 | int index = flagcode_valueIndex (flag); | |
2802 | ||
2803 | llassert (index >= 0 && index <= NUMVALUEFLAGS); | |
2804 | ||
28bf4b0b | 2805 | switch (flag) |
616915dd | 2806 | { |
28bf4b0b | 2807 | case FLG_LINELEN: |
2808 | if (val <= 0) | |
616915dd | 2809 | { |
28bf4b0b | 2810 | |
abb1cb43 | 2811 | llerror_flagWarning (message ("Value for %s must be a positive " |
abd7f895 | 2812 | "number (given %d)", |
2813 | flagcode_unparse (flag), val)); | |
616915dd | 2814 | return; |
616915dd | 2815 | } |
28bf4b0b | 2816 | if (flag == FLG_LINELEN && val < MINLINELEN) |
2817 | { | |
abb1cb43 | 2818 | llerror_flagWarning (message ("Value for %s must be at least %d (given %d)", |
abd7f895 | 2819 | flagcode_unparse (flag), |
2820 | MINLINELEN, val)); | |
28bf4b0b | 2821 | val = MINLINELEN; |
2822 | } | |
2823 | break; | |
616915dd | 2824 | |
28bf4b0b | 2825 | case FLG_INCLUDENEST: |
2826 | case FLG_CONTROLNESTDEPTH: | |
2827 | case FLG_STRINGLITERALLEN: | |
2828 | case FLG_NUMSTRUCTFIELDS: | |
2829 | case FLG_NUMENUMMEMBERS: | |
2830 | case FLG_INDENTSPACES: | |
2831 | if (val < 0) | |
2832 | { | |
abb1cb43 | 2833 | llerror_flagWarning (message ("Value for %s must be a non-negative " |
a956d444 | 2834 | "number (given %d)", |
2835 | flagcode_unparse (flag), val)); | |
28bf4b0b | 2836 | return; |
2837 | } | |
616915dd | 2838 | |
28bf4b0b | 2839 | break; |
2840 | default: | |
2841 | break; | |
2842 | } | |
982cc10b | 2843 | |
2844 | DPRINTF (("Set value [%s] %d = %d", flagcode_unparse (flag), index, val)); | |
28bf4b0b | 2845 | gc.values[index] = val; |
616915dd | 2846 | } |
2847 | ||
2848 | void | |
2849 | context_setValueAndFlag (flagcode flag, int val) | |
2850 | { | |
2851 | gc.flags[flag] = TRUE; | |
2852 | context_setValue (flag, val); | |
2853 | } | |
2854 | ||
2855 | int | |
2856 | context_getValue (flagcode flag) | |
2857 | { | |
2858 | int index = flagcode_valueIndex (flag); | |
2859 | ||
2860 | llassert (index >= 0 && index <= NUMVALUEFLAGS); | |
982cc10b | 2861 | DPRINTF (("Get value [%s] %d = %d", flagcode_unparse (flag), index, gc.values[index])); |
616915dd | 2862 | return (gc.values[index]); |
2863 | } | |
2864 | ||
2865 | int | |
2866 | context_getCounter (flagcode flag) | |
2867 | { | |
2868 | int index = flagcode_valueIndex (flag); | |
2869 | ||
2870 | llassert (index >= 0 && index <= NUMVALUEFLAGS); | |
2871 | return (gc.counters[index]); | |
2872 | } | |
2873 | ||
2874 | void | |
2875 | context_incCounter (flagcode flag) | |
2876 | { | |
2877 | int index = flagcode_valueIndex (flag); | |
2878 | ||
2879 | llassert (index >= 0 && index <= NUMVALUEFLAGS); | |
2880 | /* check limit */ | |
2881 | gc.counters[index]++; | |
2882 | } | |
2883 | ||
2884 | void | |
2885 | context_decCounter (flagcode flag) | |
2886 | { | |
2887 | int index = flagcode_valueIndex (flag); | |
2888 | ||
2889 | llassert (index >= 0 && index <= NUMVALUEFLAGS); | |
2890 | gc.counters[index]--; | |
2891 | } | |
2892 | ||
2893 | bool context_showFunction (void) | |
2894 | { | |
2895 | return (gc.showfunction); | |
2896 | } | |
2897 | ||
2898 | void | |
2899 | context_setString (flagcode flag, cstring val) | |
2900 | { | |
2901 | int index = flagcode_stringIndex (flag); | |
2902 | ||
2903 | llassert (index >= 0 && index <= NUMSTRINGFLAGS); | |
2904 | ||
80489f0a | 2905 | DPRINTF (("set string: %s", flagcode_unparse (flag))); |
2906 | ||
2907 | switch (flag) | |
616915dd | 2908 | { |
80489f0a | 2909 | case FLG_MESSAGESTREAM: |
2910 | case FLG_WARNINGSTREAM: | |
2911 | case FLG_ERRORSTREAM: | |
2912 | { | |
2913 | if (cstring_isDefined (val)) | |
2914 | { | |
2915 | FILE *fstream; | |
616915dd | 2916 | |
80489f0a | 2917 | if (osd_fileExists (val)) |
2918 | { | |
2919 | if (context_getFlag (FLG_STREAMOVERWRITE)) | |
2920 | { | |
2921 | llfatalerror (message | |
2922 | ("Output stream file %s would overwrite existing file. " | |
2923 | "Use -streamoverwrite if you want to allow this.", | |
2924 | val)); | |
2925 | } | |
2926 | } | |
2927 | ||
2928 | fstream = fopen (cstring_toCharsSafe (val), "w"); | |
616915dd | 2929 | |
80489f0a | 2930 | if (fstream == NULL) |
2931 | { | |
2932 | llfatalerror (message ("Unable to open output stream file %s for writing", | |
2933 | val)); | |
2934 | } | |
616915dd | 2935 | |
80489f0a | 2936 | /* |
2937 | ** This ensures fstream will be closed on exit. | |
2938 | */ | |
616915dd | 2939 | |
80489f0a | 2940 | fileTable_addStreamFile (gc.ftab, fstream, cstring_copy (val)); |
2941 | ||
2942 | switch (flag) | |
2943 | { | |
2944 | case FLG_MESSAGESTREAM: | |
2945 | g_messagestream = fstream; | |
2946 | /*@innerbreak@*/ break; | |
2947 | case FLG_WARNINGSTREAM: | |
2948 | g_warningstream = fstream; | |
2949 | /*@innerbreak@*/ break; | |
2950 | case FLG_ERRORSTREAM: | |
2951 | g_errorstream = fstream; | |
2952 | /*@innerbreak@*/ break; | |
2953 | BADDEFAULT; | |
2954 | } | |
2955 | /*@-statetransfer@*/ | |
2956 | } /*@=statetransfer@*/ /* fstream not closed, but will be on exit */ | |
2957 | break; | |
2958 | } | |
2959 | case FLG_SYSTEMDIRS: | |
2960 | { | |
2961 | llassert (cstring_isDefined (val)); | |
2962 | ||
2963 | if (cstring_firstChar (val) == '\"') | |
2964 | { | |
2965 | cstring oval = val; | |
2966 | cstring tval = cstring_copy (cstring_suffix (val, 1)); | |
2967 | ||
2968 | if (cstring_lastChar (tval) != '\"') | |
2969 | { | |
e5081f8c | 2970 | int n = size_toInt (cstring_length (tval) - 1); |
80489f0a | 2971 | |
2972 | while (isspace ((int) cstring_getChar (tval, size_fromInt (n)))) | |
2973 | { | |
2974 | n--; | |
2975 | } | |
2976 | ||
2977 | if (cstring_getChar (tval, size_fromInt (n)) != '\"') | |
2978 | { | |
2979 | llerror_flagWarning | |
2980 | (message ("Setting -systemdirs to string with unmatching quotes: %s", val)); | |
2981 | } | |
2982 | else | |
2983 | { | |
2984 | cstring otval = tval; | |
2985 | tval = cstring_prefix (tval, size_fromInt (n)); | |
2986 | cstring_free (otval); | |
2987 | } | |
2988 | } | |
2989 | ||
2990 | val = cstring_copy (cstring_clip (tval, cstring_length (tval) - 1)); | |
2991 | DPRINTF (("val = %s", val)); | |
2992 | cstring_free (tval); | |
2993 | cstring_free (oval); | |
2994 | } | |
2995 | ||
2996 | break; | |
2997 | } | |
2998 | case FLG_TMPDIR: | |
2999 | { | |
3000 | llassert (cstring_isDefined (val)); | |
3001 | ||
3002 | if (cstring_length (val) == 0) | |
3003 | { | |
3004 | cstring_free (val); | |
3005 | val = message (".%s", cstring_makeLiteralTemp (CONNECTSTR)); | |
3006 | } | |
3007 | else if (cstring_lastChar (val) != CONNECTCHAR) | |
3008 | { | |
3009 | val = cstring_appendChar (val, CONNECTCHAR); | |
3010 | } | |
3011 | else | |
3012 | { | |
3013 | ; | |
3014 | } | |
3015 | break; | |
3016 | } | |
3017 | default: | |
3018 | { | |
3019 | ; /* Okay not handle everything in this switch */ | |
3020 | } | |
b73d1009 | 3021 | /*@-branchstate@*/ |
3022 | } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */ | |
3023 | /*@=branchstate@*/ | |
3024 | ||
616915dd | 3025 | if (cstring_length (val) >= 1 |
ee229125 | 3026 | && cstring_firstChar (val) == '\"') |
616915dd | 3027 | { |
abb1cb43 | 3028 | llerror_flagWarning (message |
140c27a8 | 3029 | ("Setting %s to string beginning with \". You probably " |
80489f0a | 3030 | "don't meant to have the \"'s.", |
3031 | flagcode_unparse (flag))); | |
616915dd | 3032 | } |
80489f0a | 3033 | |
616915dd | 3034 | gc.strings[index] = val; |
3035 | } | |
3036 | ||
3037 | static /*@exposed@*/ cstring | |
3038 | context_exposeString (flagcode flag) | |
3039 | { | |
3040 | int index = flagcode_stringIndex (flag); | |
3041 | ||
3042 | llassert (index >= 0 && index <= NUMSTRINGFLAGS); | |
3043 | return (gc.strings[index]); | |
3044 | } | |
3045 | ||
3046 | cstring | |
3047 | context_getString (flagcode flag) | |
3048 | { | |
3049 | return (context_exposeString (flag)); | |
3050 | } | |
3051 | ||
3052 | void | |
3053 | context_resetErrors (void) | |
3054 | { | |
3055 | gc.numerrors = 0; | |
3056 | } | |
3057 | ||
909cf5eb | 3058 | void |
3059 | context_recordBug (void) | |
3060 | { | |
3061 | gc.numbugs++; | |
3062 | } | |
3063 | ||
3064 | int | |
3065 | context_numBugs (void) | |
3066 | { | |
3067 | return gc.numbugs; | |
3068 | } | |
3069 | ||
616915dd | 3070 | void context_initMod (void) |
3071 | /*@globals undef gc; @*/ | |
3072 | { | |
3073 | gc.kind = CX_GLOBAL; | |
b7e84605 | 3074 | |
28bf4b0b | 3075 | gc.savekind = CX_ERROR; |
b7e84605 | 3076 | gc.savecont.glob = FALSE; |
3077 | ||
616915dd | 3078 | gc.instandardlib = FALSE; |
3079 | gc.numerrors = 0; | |
909cf5eb | 3080 | gc.numbugs = 0; |
616915dd | 3081 | gc.neednl = FALSE; |
3082 | gc.linesprocessed = 0; | |
3083 | gc.speclinesprocessed = 0; | |
3084 | gc.insuppressregion = FALSE; | |
3085 | gc.macroMissingParams = FALSE; | |
3086 | gc.preprocessing = FALSE; | |
3087 | gc.incommandline = FALSE; | |
3088 | gc.mc = macrocache_create (); | |
3089 | gc.nmods = 0; | |
3090 | gc.maxmods = DEFAULTMAXMODS; | |
28bf4b0b | 3091 | gc.moduleaccess = (maccesst *) dmalloc (sizeof (*gc.moduleaccess) * (gc.maxmods)); |
3092 | ||
616915dd | 3093 | gc.library = FLG_ANSILIB; |
3094 | ||
3095 | gc.locstack = filelocStack_new (); | |
3096 | gc.modrecs = sRefSetList_undefined; | |
3097 | gc.anyExports = FALSE; | |
3098 | ||
3099 | gc.ftab = fileTable_create (); | |
3100 | gc.msgLog = messageLog_new (); | |
3101 | gc.inimport = FALSE; | |
3102 | gc.inDerivedFile = FALSE; | |
3103 | gc.inheader = FALSE; | |
3104 | gc.markers = flagMarkerList_new (); | |
3105 | gc.cont.glob = TRUE; | |
3106 | gc.showfunction = FALSE; | |
3107 | gc.msgAnnote = cstring_undefined; | |
3108 | gc.aliasAnnote = sRef_undefined; | |
3109 | gc.aliasAnnoteAls = sRef_undefined; | |
3110 | gc.boolType = ctype_bool; | |
3111 | gc.mods = sRefSet_new (); | |
3112 | ||
3113 | gc.saveloc = fileloc_undefined; | |
3114 | ||
3115 | gc.inmacrocache = FALSE; | |
3116 | gc.inclause = NOCLAUSE; | |
3117 | gc.clauses = clauseStack_new (); | |
3118 | gc.globs = globSet_new (); | |
3119 | gc.nacct = typeIdSet_emptySet (); | |
3120 | gc.acct = typeIdSet_emptySet (); | |
3121 | gc.facct = typeIdSet_emptySet (); | |
3122 | gc.savedFlags = FALSE; | |
3123 | gc.pushloc = fileloc_undefined; | |
3124 | gc.protectVars = FALSE; | |
3125 | gc.justpopped = FALSE; | |
3126 | gc.isNullGuarded = NO; | |
3127 | gc.globs_used = globSet_undefined; | |
3128 | ||
3129 | allFlagCodes (code) | |
3130 | { | |
3131 | gc.setGlobally[code] = FALSE; | |
3132 | gc.setLocally[code] = FALSE; | |
982cc10b | 3133 | } |
3134 | end_allFlagCodes ; | |
3135 | ||
616915dd | 3136 | usymtab_initMod (); |
616915dd | 3137 | context_resetAllFlags (); |
982cc10b | 3138 | |
3120b462 | 3139 | assertSet (gc.flags); /* Can't use global in defines */ |
3140 | assertSet (gc.saveflags); | |
3141 | assertSet (gc.values); | |
3142 | assertSet (gc.strings); | |
982cc10b | 3143 | |
616915dd | 3144 | conext_resetAllCounters (); |
3120b462 | 3145 | assertSet (gc.counters); |
3146 | ||
616915dd | 3147 | context_setMode (DEFAULT_MODE); |
28bf4b0b | 3148 | |
3149 | gc.stateTable = metaStateTable_create (); | |
3150 | gc.annotTable = annotationTable_create (); | |
3151 | ||
d9a28762 | 3152 | gc.inFunctionHeader = FALSE; |
3153 | ||
28bf4b0b | 3154 | DPRINTF (("Annotations: \n%s", |
3155 | cstring_toCharsSafe (annotationTable_unparse (gc.annotTable)))); | |
3156 | DPRINTF (("State: \n%s", | |
3157 | cstring_toCharsSafe (metaStateTable_unparse (gc.stateTable)))); | |
3158 | ||
616915dd | 3159 | } |
3160 | ||
3161 | ctype | |
3162 | context_typeofZero (void) | |
3163 | { | |
3164 | ctype ct = ctype_int; | |
3165 | ||
3166 | if (context_getFlag (FLG_ZEROPTR)) | |
3167 | { | |
3168 | ct = ctype_makeConj (ct, ctype_voidPointer); | |
3169 | } | |
3170 | ||
3171 | if (context_getFlag (FLG_ZEROBOOL)) { | |
3172 | ct = ctype_makeConj (ct, ctype_bool); | |
3173 | } | |
3174 | ||
3175 | return ct; | |
3176 | } | |
3177 | ||
3178 | ctype | |
3179 | context_typeofOne (void) | |
3180 | { | |
3181 | ctype ct = ctype_int; | |
3182 | ||
3183 | /* 1 is on longer a bool (was before 2.4) | |
3184 | if (!context_getFlag (FLG_ABSTRACTBOOL)) | |
3185 | { | |
3186 | ct = ctype_makeConj (ct, ctype_bool); | |
3187 | } | |
3188 | */ | |
3189 | ||
3190 | return (ct); | |
3191 | } | |
3192 | ||
3193 | /*@only@*/ cstring | |
3194 | context_unparse (void) | |
3195 | { | |
3196 | cstring s; | |
3197 | ||
3198 | switch (gc.kind) | |
3199 | { | |
3200 | case CX_LCL: | |
3201 | s = message ("LCL File: %q", fileloc_unparse (g_currentloc)); | |
3202 | break; | |
3203 | case CX_LCLLIB: | |
3204 | s = message ("LCL Lib File: %q", fileloc_unparse (g_currentloc)); | |
3205 | break; | |
3206 | case CX_GLOBAL: | |
3207 | s = message ("Global Context:%q", fileloc_unparse (g_currentloc)); | |
3208 | break; | |
3209 | case CX_INNER: | |
b7e84605 | 3210 | s = message ("Inner Context [%d] : %q", |
3211 | gc.cont.cdepth, | |
3212 | fileloc_unparse (g_currentloc)); | |
616915dd | 3213 | break; |
3214 | case CX_FUNCTION: | |
3215 | s = message ("Function %q :%q \n\taccess %q\n\tmodifies %q", | |
3216 | uentry_unparse (gc.cont.fcn), | |
3217 | fileloc_unparse (g_currentloc), | |
3218 | typeIdSet_unparse (gc.acct), | |
3219 | sRefSet_unparse (gc.mods)); | |
3220 | break; | |
3221 | case CX_MACROFCN: | |
3222 | s = message ("Function Macro %q", uentry_unparse (gc.cont.fcn)); | |
3223 | break; | |
3224 | case CX_UNKNOWNMACRO: | |
3225 | s = message ("Forward Specified Macro %q", uentry_unparse (gc.cont.fcn)); | |
3226 | break; | |
3227 | case CX_MACROCONST: | |
3228 | s = message ("Constant Macro %q", uentry_unparse (gc.cont.fcn)); | |
3229 | break; | |
3230 | case CX_ITERDEF: | |
3231 | s = message ("Iter definition %q", uentry_unparse (gc.cont.fcn)); | |
3232 | break; | |
3233 | case CX_ITEREND: | |
3234 | s = message ("Iter end %q", uentry_unparse (gc.cont.fcn)); | |
3235 | break; | |
b7e84605 | 3236 | case CX_FCNDECLARATION: |
3237 | s = message ("Function declaration %q", uentry_unparse (gc.cont.fcn)); | |
3238 | break; | |
616915dd | 3239 | default: |
3240 | s = message ("Un-unparseable context: %d", (int) gc.kind); | |
3241 | break; | |
3242 | } | |
3243 | ||
3244 | s = message ("%q\naccess: %q", s, context_unparseAccess ()); | |
3245 | return (s); | |
3246 | } | |
3247 | ||
3248 | extern ctype | |
3249 | context_currentFunctionType (void) | |
3250 | { | |
3251 | if (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN) | |
3252 | { | |
3253 | return (uentry_getType (gc.cont.fcn)); | |
3254 | } | |
3255 | else if (gc.kind == CX_INNER) | |
3256 | { | |
3257 | llcontbuglit ("context_currentFunctionType: inner context"); | |
3258 | do { context_exitInnerPlain (); } while (gc.kind == CX_INNER); | |
3259 | return (context_currentFunctionType ()); | |
3260 | } | |
3261 | else | |
3262 | { | |
3263 | llcontbuglit ("context_currentFunctionType: not in function"); | |
3264 | return (ctype_undefined); | |
3265 | } | |
3266 | } | |
3267 | ||
3268 | void | |
3269 | context_enterInnerContext (void) | |
3270 | { | |
b7e84605 | 3271 | if (context_getFlag (FLG_GRAMMAR)) |
3272 | { | |
3273 | lldiagmsg (message ("Enter inner context: %q", context_unparse ())); | |
3274 | } | |
3275 | ||
616915dd | 3276 | if (gc.kind == CX_GLOBAL) |
3277 | { | |
3278 | gc.kind = CX_INNER; | |
3279 | gc.cont.cdepth = 1; | |
3280 | } | |
3281 | else if (gc.kind == CX_INNER) | |
3282 | { | |
3283 | gc.cont.cdepth++; | |
3284 | } | |
3285 | else | |
3286 | { | |
3287 | ; | |
3288 | } | |
3289 | ||
616915dd | 3290 | usymtab_enterScope (); |
3291 | pushClause (NOCLAUSE); | |
3292 | } | |
3293 | ||
3294 | void | |
3295 | context_exitInnerPlain (void) /*@modifies gc;@*/ | |
3296 | { | |
3297 | context_exitInner (exprNode_undefined); | |
3298 | } | |
3299 | ||
3300 | void | |
3301 | context_exitInner (exprNode exp) | |
3302 | { | |
b7e84605 | 3303 | if (context_getFlag (FLG_GRAMMAR)) |
3304 | { | |
3305 | lldiagmsg (message ("Enter inner context: %q", context_unparse ())); | |
3306 | } | |
3307 | ||
616915dd | 3308 | llassertprint (gc.inclause == NOCLAUSE || gc.inclause == CASECLAUSE, |
3309 | ("inclause = %s", clause_nameTaken (gc.inclause))); | |
3310 | ||
3311 | clauseStack_removeFirst (gc.clauses, NOCLAUSE); | |
3312 | gc.inclause = topClause (gc.clauses); | |
3313 | ||
3314 | if (gc.kind == CX_INNER) | |
3315 | { | |
3316 | if (--gc.cont.cdepth == 0) | |
3317 | { | |
3318 | gc.kind = CX_GLOBAL; | |
3319 | gc.cont.glob = TRUE; | |
3320 | } | |
3321 | } | |
3322 | else | |
3323 | { | |
3324 | if (gc.kind == CX_GLOBAL) | |
3325 | { | |
3326 | llcontbuglit ("Attempt to exit global context"); | |
3327 | return; | |
3328 | } | |
3329 | } | |
3330 | ||
3331 | usymtab_exitScope (exp); | |
3332 | } | |
3333 | ||
3334 | ||
3335 | void | |
3336 | context_enterStructInnerContext (void) | |
3337 | { | |
b7e84605 | 3338 | if (context_getFlag (FLG_GRAMMAR)) |
3339 | { | |
3340 | lldiagmsg (message ("Enter struct inner context: %q", context_unparse ())); | |
3341 | } | |
3342 | ||
616915dd | 3343 | if (gc.kind == CX_GLOBAL) |
3344 | { | |
3345 | gc.kind = CX_INNER; | |
3346 | gc.cont.cdepth = 1; | |
3347 | } | |
3348 | else if (gc.kind == CX_INNER) | |
3349 | { | |
3350 | gc.cont.cdepth++; | |
3351 | } | |
3352 | else | |
3353 | { | |
3354 | ; | |
3355 | } | |
3356 | ||
3357 | usymtab_enterScope (); | |
b7e84605 | 3358 | |
3359 | if (context_getFlag (FLG_GRAMMAR)) | |
3360 | { | |
3361 | lldiagmsg (message ("Enter struct inner context: %q", context_unparse ())); | |
3362 | } | |
616915dd | 3363 | } |
3364 | ||
3365 | void | |
3366 | context_exitStructInnerContext (void) | |
3367 | { | |
b7e84605 | 3368 | if (context_getFlag (FLG_GRAMMAR)) |
3369 | { | |
3370 | lldiagmsg (message ("Exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth)); | |
3371 | } | |
3372 | ||
616915dd | 3373 | if (gc.kind == CX_INNER) |
3374 | { | |
b7e84605 | 3375 | if (gc.cont.cdepth <= 0) |
616915dd | 3376 | { |
b7e84605 | 3377 | llcontbuglit ("Attempt to exit inner context with no depth"); |
616915dd | 3378 | gc.kind = CX_GLOBAL; |
3379 | gc.cont.glob = TRUE; | |
b7e84605 | 3380 | gc.cont.cdepth = 0; |
616915dd | 3381 | } |
b7e84605 | 3382 | else { |
3383 | gc.cont.cdepth--; | |
3384 | ||
3385 | if (gc.cont.cdepth == 0) | |
3386 | { | |
3387 | gc.kind = CX_GLOBAL; | |
3388 | gc.cont.glob = TRUE; | |
3389 | } | |
3390 | } | |
616915dd | 3391 | } |
3392 | else | |
3393 | { | |
3394 | if (gc.kind == CX_GLOBAL) | |
3395 | { | |
3396 | llcontbuglit ("Attempt to exit global context"); | |
3397 | return; | |
3398 | } | |
3399 | } | |
3400 | ||
3401 | usymtab_exitScope (exprNode_undefined); | |
b7e84605 | 3402 | |
3403 | if (context_getFlag (FLG_GRAMMAR)) | |
3404 | { | |
3405 | lldiagmsg (message ("After exit struct inner context: %q [%d]", context_unparse (), gc.cont.cdepth)); | |
3406 | } | |
616915dd | 3407 | } |
3408 | ||
3409 | void | |
3410 | context_exitInnerSafe (void) | |
3411 | { | |
b7e84605 | 3412 | if (context_getFlag (FLG_GRAMMAR)) |
3413 | { | |
3414 | lldiagmsg (message ("Exit inner safe: %q", context_unparse ())); | |
3415 | } | |
3416 | ||
616915dd | 3417 | if (gc.kind == CX_INNER) |
3418 | { | |
b7e84605 | 3419 | if (--gc.cont.cdepth <= 0) |
616915dd | 3420 | { |
b7e84605 | 3421 | gc.cont.cdepth = 0; |
616915dd | 3422 | } |
3423 | } | |
3424 | else if (gc.kind == CX_GLOBAL) | |
3425 | { | |
3426 | llcontbuglit ("Attempt to exit global context"); | |
3427 | return; | |
3428 | } | |
3429 | else | |
3430 | { | |
3431 | if (usymtab_inDeepScope ()) | |
3432 | { | |
3433 | usymtab_exitScope (exprNode_undefined); | |
3434 | } | |
3435 | } | |
3436 | } | |
3437 | ||
3438 | static | |
3439 | void setModuleAccess (void) | |
3440 | { | |
3441 | gc.facct = typeIdSet_emptySet (); | |
3442 | ||
3443 | if (fileId_isValid (currentFile ())) | |
3444 | { | |
3445 | cstring baseName = fileloc_getBase (g_currentloc); | |
3446 | ||
3447 | if (context_getFlag (FLG_ACCESSFILE)) | |
3448 | { | |
3449 | if (usymtab_existsType (baseName)) | |
3450 | { | |
3451 | gc.facct = typeIdSet_insert (gc.facct, | |
3452 | usymtab_getTypeId (baseName)); | |
3453 | } | |
3454 | else | |
3455 | { | |
3456 | ; | |
3457 | } | |
3458 | } | |
3459 | ||
3460 | if (context_getFlag (FLG_ACCESSMODULE)) | |
3461 | { | |
3462 | int i; | |
3463 | bool hasaccess = FALSE; | |
3464 | ||
3465 | for (i = 0; i < gc.nmods; i++) | |
3466 | { | |
3467 | if (cstring_equal (baseName, gc.moduleaccess[i].file)) | |
3468 | { | |
3469 | gc.facct = typeIdSet_union (gc.facct, gc.moduleaccess[i].daccess); | |
3470 | ||
3471 | hasaccess = TRUE; | |
3472 | break; | |
3473 | } | |
3474 | } | |
3475 | } | |
3476 | ||
3477 | gc.acct = gc.facct; | |
3478 | gc.inheader = fileId_isHeader (currentFile ()); | |
3479 | } | |
3480 | else | |
3481 | { | |
3482 | llcontbuglit ("Current file not defined\n"); | |
3483 | gc.facct = typeIdSet_emptySet (); | |
3484 | gc.acct = gc.facct; | |
3485 | gc.inheader = FALSE; | |
3486 | } | |
3487 | ||
3488 | /* 17 Jan 1995: forgot to clear nacct */ | |
3489 | ||
3490 | gc.nacct = typeIdSet_emptySet (); | |
3491 | } | |
3492 | ||
3493 | static void | |
3494 | context_enterFileAux (void) | |
3495 | { | |
3496 | setModuleAccess (); | |
3497 | } | |
3498 | ||
3499 | void | |
3500 | context_enterFile (void) | |
3501 | { | |
3502 | context_enterFileAux (); | |
3503 | usymtab_enterFile (); | |
3504 | } | |
3505 | ||
3506 | void | |
3507 | context_enterMacroFile (void) | |
3508 | { | |
3509 | context_enterFileAux (); | |
3510 | } | |
3511 | ||
3512 | bool | |
3513 | context_inFunction (void) | |
3514 | { | |
3515 | kcontext ck = gc.kind; | |
3516 | ||
3517 | return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN) || (ck == CX_INNER)); | |
3518 | } | |
3519 | ||
3520 | bool | |
3521 | context_inFunctionLike (void) | |
3522 | { | |
3523 | return (gc.kind == CX_FUNCTION || gc.kind == CX_MACROFCN | |
28bf4b0b | 3524 | || gc.kind == CX_FCNDECLARATION |
616915dd | 3525 | || gc.kind == CX_UNKNOWNMACRO || gc.kind == CX_ITERDEF); |
3526 | } | |
3527 | ||
3528 | bool | |
3529 | context_inRealFunction (void) | |
3530 | { | |
3531 | kcontext ck = gc.kind; | |
3532 | ||
3533 | return ((ck == CX_FUNCTION) || (ck == CX_MACROFCN)); | |
3534 | } | |
3535 | ||
3536 | void | |
3537 | context_processAllMacros (void) | |
3538 | { | |
3539 | usymtab_enterFile (); | |
3540 | ||
3541 | gc.inmacrocache = TRUE; | |
3542 | macrocache_processUndefinedElements (gc.mc); | |
3543 | cleanupMessages (); | |
3544 | usymtab_exitFile (); | |
3545 | ||
3546 | gc.inmacrocache = FALSE; | |
3547 | macrocache_finalize (); | |
3548 | } | |
3549 | ||
3550 | /* | |
3551 | ** this happens once at the end of each C file | |
3552 | ** | |
3553 | ** check each Macro that was defined in current file.c or current file.h | |
3554 | ** | |
3555 | */ | |
3556 | ||
3557 | static void | |
3558 | context_processMacros (void) | |
3559 | { | |
3560 | if (fileId_isValid (currentFile ())) | |
3561 | { | |
3562 | fileloc lastfl; | |
4dd72714 | 3563 | cstring cbase = fileLib_removePathFree (fileLib_removeAnyExtension (fileTable_fileName (currentFile ()))); |
616915dd | 3564 | |
3565 | gc.inmacrocache = TRUE; | |
3566 | ||
3567 | DPRINTF (("Processing macros: %s", cbase)); | |
3568 | lastfl = macrocache_processFileElements (gc.mc, cbase); | |
3569 | DPRINTF (("Processing macros: %s", fileloc_unparse (lastfl))); | |
3570 | ||
3571 | cstring_free (cbase); | |
3572 | ||
3573 | if (fileloc_isDefined (lastfl)) | |
3574 | { | |
3575 | g_currentloc = fileloc_update (g_currentloc, lastfl); | |
3576 | cleanupMessages (); | |
3577 | } | |
3578 | ||
3579 | gc.inmacrocache = FALSE; | |
3580 | } | |
3581 | } | |
3582 | ||
3583 | bool | |
3584 | context_processingMacros (void) | |
3585 | { | |
3586 | return (gc.inmacrocache); | |
3587 | } | |
3588 | ||
3589 | void | |
28bf4b0b | 3590 | context_exitCFile (void) |
616915dd | 3591 | { |
3592 | if (gc.kind != CX_GLOBAL) | |
3593 | { | |
3594 | llfatalerrorLoc | |
3595 | (cstring_makeLiteral ("File ended outside global scope")); | |
3596 | } | |
3597 | ||
3598 | if (gc.insuppressregion) | |
3599 | { | |
3600 | /* gack...don't reverse the order of these lines! ;-> */ | |
3601 | gc.insuppressregion = FALSE; | |
3602 | llerrorlit (FLG_SYNTAX, | |
3603 | "File ended in ignore errors region, " | |
3604 | "possible missing /*@end*/"); | |
3605 | } | |
3606 | ||
3607 | /* fix up parse errors */ | |
3608 | ||
3609 | while (!usymtab_inFileScope ()) | |
3610 | { | |
3611 | usymtab_quietExitScope (g_currentloc); | |
3612 | } | |
3613 | ||
3614 | /* | |
3615 | ** Clear the file-specific modifies information. | |
3616 | */ | |
3617 | ||
3618 | sRefSetList_elements (gc.modrecs, mods) | |
3619 | { | |
3620 | sRefSet_clearStatics (mods); | |
28bf4b0b | 3621 | } end_sRefSetList_elements ; |
616915dd | 3622 | |
3623 | sRefSetList_clear (gc.modrecs); | |
28bf4b0b | 3624 | |
616915dd | 3625 | context_processMacros (); |
3626 | cleanupMessages (); | |
28bf4b0b | 3627 | |
616915dd | 3628 | usymtab_exitFile (); |
28bf4b0b | 3629 | |
616915dd | 3630 | gc.inDerivedFile = FALSE; |
3631 | filelocStack_clear (gc.locstack); | |
28bf4b0b | 3632 | |
616915dd | 3633 | gc.nacct = typeIdSet_emptySet (); /* empty noaccess */ |
28bf4b0b | 3634 | |
616915dd | 3635 | gc.cont.glob = TRUE; |
3636 | ||
3637 | if (gc.savedFlags) | |
3638 | { | |
3639 | context_restoreFlagSettings (); | |
3640 | gc.savedFlags = FALSE; | |
3641 | } | |
28bf4b0b | 3642 | |
3643 | /* | |
3644 | DPRINTF (("After exiting file: ")); | |
3645 | usymtab_printAll (); | |
3646 | */ | |
616915dd | 3647 | } |
3648 | ||
3649 | void | |
3650 | context_exitMacroCache (void) | |
3651 | { | |
3652 | if (gc.kind != CX_GLOBAL) | |
3653 | { | |
28bf4b0b | 3654 | if (context_inMacro ()) |
3655 | /* this is okay, file could end without newline in macro */ | |
616915dd | 3656 | { |
28bf4b0b | 3657 | DPRINTF (("Still in macro: %s", |
3658 | context_unparse ())); | |
616915dd | 3659 | context_exitFunction (); |
3660 | } | |
3661 | else | |
3662 | { | |
3663 | llcontbug (message ("context_exitMacroCache: outside global scope: %q", | |
3664 | context_unparse ())); | |
3665 | gc.kind = CX_GLOBAL; | |
3666 | } | |
3667 | } | |
3668 | ||
3669 | /* | |
3670 | ** no longer valid here | |
3671 | ** if (gc.insuppressregion) | |
3672 | ** { | |
3673 | ** gc.insuppressregion = FALSE; | |
3674 | ** llerror ("File ended in ignore errors region, possible missing @"); | |
3675 | ** } | |
3676 | */ | |
3677 | ||
3678 | gc.cont.glob = TRUE; | |
3679 | } | |
3680 | ||
3681 | void | |
3682 | context_saveLocation (void) | |
3683 | { | |
3684 | /* was llassert (fileloc_isUndefined (gc.saveloc)) */ | |
6970c11b | 3685 | fileloc_free (gc.saveloc); |
616915dd | 3686 | gc.saveloc = fileloc_copy (g_currentloc); |
6970c11b | 3687 | } |
616915dd | 3688 | |
3689 | fileloc | |
3690 | context_getSaveLocation (void) | |
3691 | { | |
3692 | fileloc fl = gc.saveloc; | |
6970c11b | 3693 | gc.saveloc = fileloc_undefined; |
616915dd | 3694 | return fl; |
3695 | } | |
3696 | ||
3697 | /*@observer@*/ cstring | |
3698 | context_inFunctionName (void) | |
3699 | { | |
3700 | if (gc.kind == CX_FUNCTION | |
3701 | || gc.kind == CX_MACROFCN || gc.kind == CX_UNKNOWNMACRO | |
3702 | || gc.kind == CX_MACROCONST | |
3703 | || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND) | |
3704 | { | |
3705 | return (uentry_rawName (gc.cont.fcn)); | |
3706 | } | |
3707 | else | |
3708 | { | |
3709 | llcontbuglit ("context_inFunctionName: not in function"); | |
3710 | return (cstring_undefined); | |
3711 | } | |
3712 | } | |
3713 | ||
3714 | void | |
3715 | context_userSetFlag (flagcode f, bool b) | |
3716 | { | |
140c27a8 | 3717 | DPRINTF (("set flag: %s / %s", |
3718 | flagcode_unparse (f), | |
3719 | bool_unparse (context_getFlag (f)))); | |
616915dd | 3720 | |
3721 | if (f == FLG_NEVERINCLUDE && b) | |
3722 | { | |
3723 | if (gc.flags[FLG_EXPORTHEADER]) | |
3724 | { | |
abd7f895 | 3725 | llerror_flagWarning |
3726 | (cstring_makeLiteral | |
140c27a8 | 3727 | ("Setting +neverinclude after +exportheader. " |
abd7f895 | 3728 | "Turning off exportheader, since headers are not checked " |
3729 | "when +neverinclude is used.")); | |
616915dd | 3730 | |
3731 | gc.flags[FLG_EXPORTHEADER] = FALSE; | |
3732 | } | |
3733 | } | |
3734 | else | |
3735 | { | |
3736 | if (f == FLG_EXPORTHEADER && b) | |
3737 | { | |
3738 | if (gc.flags[FLG_NEVERINCLUDE]) | |
3739 | { | |
abd7f895 | 3740 | llerror_flagWarning |
3741 | (cstring_makeLiteral | |
140c27a8 | 3742 | ("Setting +exportheader after +neverinclude. " |
abd7f895 | 3743 | "Not setting exportheader, since headers are not checked " |
3744 | "when +neverinclude is used.")); | |
616915dd | 3745 | gc.flags[FLG_EXPORTHEADER] = FALSE; |
3746 | return; | |
3747 | } | |
3748 | } | |
3749 | } | |
3750 | ||
3751 | if (context_getFlag (FLG_WARNFLAGS) && f != FLG_NOF && f != FLG_OPTF) | |
3752 | { | |
3753 | bool lastsetting = context_getFlag (f); | |
3754 | ||
3755 | if (bool_equal (lastsetting, b) | |
3756 | && !flagcode_isSpecialFlag (f) | |
3757 | && !flagcode_isIdemFlag (f) | |
3758 | && !flagcode_hasArgument (f)) | |
3759 | { | |
abd7f895 | 3760 | llerror_flagWarning |
140c27a8 | 3761 | (message ("Setting %s%s redundant with current value", |
abd7f895 | 3762 | cstring_makeLiteralTemp (b ? "+" : "-"), |
3763 | flagcode_unparse (f))); | |
28bf4b0b | 3764 | } |
3765 | } | |
3766 | ||
3767 | if (flagcode_isWarnUseFlag (f) && b) | |
3768 | { | |
3769 | if (!context_getFlag (FLG_WARNUSE)) | |
3770 | { | |
abd7f895 | 3771 | llerror_flagWarning |
140c27a8 | 3772 | (message ("Flag +%s is canceled by -warnuse", |
abd7f895 | 3773 | flagcode_unparse (f))); |
616915dd | 3774 | } |
3775 | } | |
3776 | ||
28bf4b0b | 3777 | |
616915dd | 3778 | if (flagcode_isLibraryFlag (f)) |
3779 | { | |
3780 | if (gc.library != FLG_ANSILIB | |
3781 | && gc.library != f) | |
3782 | { | |
abd7f895 | 3783 | llerror_flagWarning |
140c27a8 | 3784 | (message ("Selecting library %s after library %s was " |
abd7f895 | 3785 | "selected (only one library may be used)", |
3786 | flagcode_unparse (f), | |
3787 | flagcode_unparse (gc.library))); | |
616915dd | 3788 | } |
abd7f895 | 3789 | |
616915dd | 3790 | if (f == FLG_UNIXLIB) |
3791 | { | |
3792 | if (context_getFlag (FLG_WARNUNIXLIB)) | |
3793 | { | |
abd7f895 | 3794 | llerror_flagWarning |
3795 | (cstring_makeLiteral | |
140c27a8 | 3796 | ("Selecting unix library. Unix library is " |
35e8712d | 3797 | "based on the Single Unix Specification, Version 2. Not all " |
3798 | "Unix implementations are consistend with this specification. " | |
abd7f895 | 3799 | "Use -warnunixlib to suppress this message.")); |
616915dd | 3800 | } |
3801 | } | |
3802 | ||
3803 | gc.library = f; | |
3804 | } | |
abd7f895 | 3805 | |
abb1cb43 | 3806 | if (flagcode_isNameChecksFlag (f) && b && !context_maybeSet (FLG_NAMECHECKS)) |
3807 | { | |
abd7f895 | 3808 | llerror_flagWarning |
3809 | (message | |
140c27a8 | 3810 | ("Setting +%s will not produce warnings with -namechecks. " |
abd7f895 | 3811 | "Must set +namechecks also.", |
3812 | flagcode_unparse (f))); | |
abb1cb43 | 3813 | } |
abd7f895 | 3814 | |
616915dd | 3815 | gc.setGlobally[f] = TRUE; |
abd7f895 | 3816 | context_setFlag (f, b, g_currentloc); |
616915dd | 3817 | } |
3818 | ||
3819 | void | |
abd7f895 | 3820 | context_fileSetFlag (flagcode f, ynm set, fileloc loc) |
616915dd | 3821 | { |
3822 | if (!gc.savedFlags) | |
3823 | { | |
3824 | context_saveFlagSettings (); | |
3825 | } | |
3826 | ||
3827 | if (ynm_isOff (set)) | |
3828 | { | |
abd7f895 | 3829 | context_setFlagAux (f, FALSE, TRUE, FALSE, loc); |
616915dd | 3830 | } |
3831 | else if (ynm_isOn (set)) | |
3832 | { | |
abd7f895 | 3833 | context_setFlagAux (f, TRUE, TRUE, FALSE, loc); |
616915dd | 3834 | gc.setLocally[f] = TRUE; |
3835 | } | |
3836 | else | |
3837 | { | |
abd7f895 | 3838 | context_restoreFlag (f, loc); |
616915dd | 3839 | } |
3840 | } | |
3841 | ||
3842 | static void | |
abd7f895 | 3843 | context_restoreFlag (flagcode f, fileloc loc) |
616915dd | 3844 | { |
616915dd | 3845 | if (!gc.savedFlags) |
3846 | { | |
3847 | voptgenerror | |
3848 | (FLG_SYNTAX, | |
3849 | message ("Attempt to restore flag %s when no file scope flags " | |
3850 | "have been set.", | |
3851 | flagcode_unparse (f)), | |
abd7f895 | 3852 | loc); |
616915dd | 3853 | } |
3854 | else | |
3855 | { | |
abd7f895 | 3856 | context_addFlagMarker (f, MAYBE, loc); |
3857 | context_setFlagAux (f, gc.saveflags[f], FALSE, TRUE, loc); | |
616915dd | 3858 | } |
3859 | ||
3860 | } | |
3861 | ||
28bf4b0b | 3862 | static void |
abd7f895 | 3863 | context_setFlag (flagcode f, bool b, fileloc loc) |
616915dd | 3864 | { |
abd7f895 | 3865 | context_setFlagAux (f, b, FALSE, FALSE, loc); |
616915dd | 3866 | } |
3867 | ||
3868 | void | |
3869 | context_setFlagTemp (flagcode f, bool b) | |
3870 | { | |
3871 | DPRINTF (("Set flag temp: %s / %s", flagcode_unparse (f), bool_unparse (b))); | |
3872 | gc.flags[f] = b; | |
3873 | } | |
3874 | ||
3875 | /*@notfunction@*/ | |
3876 | # define DOSET(ff,b) \ | |
3877 | do { if (inFile) { gc.setLocally[ff] = TRUE; \ | |
abd7f895 | 3878 | context_addFlagMarker (ff, ynm_fromBool (b), loc); } \ |
28bf4b0b | 3879 | DPRINTF (("set flag: %s / %s", flagcode_unparse (ff), bool_unparse (b))); \ |
616915dd | 3880 | gc.flags[ff] = b; } while (FALSE) |
3881 | ||
3882 | static void | |
3e3ec469 | 3883 | context_setFlagAux (flagcode f, bool b, bool inFile, |
abd7f895 | 3884 | /*@unused@*/ bool isRestore, fileloc loc) |
616915dd | 3885 | { |
3e3ec469 | 3886 | DPRINTF (("Set flag: %s / %s", flagcode_unparse (f), bool_unparse (b))); |
616915dd | 3887 | |
28bf4b0b | 3888 | /* |
3889 | ** Removed test for special flags. | |
3890 | */ | |
616915dd | 3891 | |
28bf4b0b | 3892 | if (flagcode_isIdemFlag (f)) |
3893 | { | |
3894 | DOSET (f, TRUE); | |
3895 | } | |
3896 | else | |
3897 | { | |
3898 | DOSET (f, b); | |
3899 | } | |
616915dd | 3900 | |
28bf4b0b | 3901 | if (f >= FLG_ITS4MOSTRISKY && f <= FLG_ITS4LOWRISK) |
3902 | { | |
3903 | if (b) /* Turing higher level on, turns on all lower levels */ | |
3904 | { | |
3905 | switch (f) | |
616915dd | 3906 | { |
28bf4b0b | 3907 | case FLG_ITS4MOSTRISKY: |
3908 | DOSET (FLG_ITS4VERYRISKY, b); | |
3909 | /*@fallthrough@*/ | |
3910 | case FLG_ITS4VERYRISKY: | |
3911 | DOSET (FLG_ITS4RISKY, b); | |
3912 | /*@fallthrough@*/ | |
3913 | case FLG_ITS4RISKY: | |
3914 | DOSET (FLG_ITS4MODERATERISK, b); | |
3915 | /*@fallthrough@*/ | |
3916 | case FLG_ITS4MODERATERISK: | |
3917 | DOSET (FLG_ITS4LOWRISK, b); | |
3918 | /*@fallthrough@*/ | |
3919 | case FLG_ITS4LOWRISK: | |
3920 | break; | |
3921 | BADDEFAULT; | |
616915dd | 3922 | } |
28bf4b0b | 3923 | } |
3924 | else /* Turning level off, turns off all higher levels */ | |
3925 | { | |
3926 | switch (f) | |
616915dd | 3927 | { |
28bf4b0b | 3928 | case FLG_ITS4LOWRISK: |
3929 | DOSET (FLG_ITS4MODERATERISK, b); | |
3930 | /*@fallthrough@*/ | |
3931 | case FLG_ITS4MODERATERISK: | |
3932 | DOSET (FLG_ITS4RISKY, b); | |
3933 | /*@fallthrough@*/ | |
3934 | case FLG_ITS4RISKY: | |
3935 | DOSET (FLG_ITS4VERYRISKY, b); | |
3936 | /*@fallthrough@*/ | |
3937 | case FLG_ITS4VERYRISKY: | |
3938 | DOSET (FLG_ITS4MOSTRISKY, b); | |
3939 | /*@fallthrough@*/ | |
3940 | case FLG_ITS4MOSTRISKY: | |
3941 | break; | |
3942 | BADDEFAULT; | |
616915dd | 3943 | } |
616915dd | 3944 | } |
3945 | } | |
28bf4b0b | 3946 | |
3947 | switch (f) | |
3948 | { | |
80489f0a | 3949 | case FLG_MESSAGESTREAMSTDOUT: |
3950 | g_messagestream = stdout; | |
3951 | break; | |
3952 | case FLG_MESSAGESTREAMSTDERR: | |
3953 | g_messagestream = stderr; | |
3954 | break; | |
3955 | case FLG_WARNINGSTREAMSTDOUT: | |
3956 | g_warningstream = stdout; | |
3957 | break; | |
3958 | case FLG_WARNINGSTREAMSTDERR: | |
3959 | g_warningstream = stderr; | |
3960 | break; | |
3961 | case FLG_ERRORSTREAMSTDOUT: | |
3962 | g_errorstream = stdout; | |
3963 | break; | |
3964 | case FLG_ERRORSTREAMSTDERR: | |
3965 | g_errorstream = stderr; | |
3966 | break; | |
28bf4b0b | 3967 | case FLG_ALLEMPTY: |
3968 | DOSET (FLG_ALLEMPTY, b); | |
3969 | DOSET (FLG_IFEMPTY, b); | |
3970 | DOSET (FLG_WHILEEMPTY, b); | |
3971 | DOSET (FLG_FOREMPTY, b); | |
3972 | break; | |
3973 | case FLG_PREDBOOL: | |
3974 | DOSET (FLG_PREDBOOL, b); | |
3975 | DOSET (FLG_PREDBOOLINT, b); | |
3976 | DOSET (FLG_PREDBOOLPTR, b); | |
3977 | DOSET (FLG_PREDBOOLOTHERS, b); | |
3978 | break; | |
3979 | case FLG_GLOBALIAS: | |
3980 | DOSET (FLG_CHECKSTRICTGLOBALIAS, b); | |
3981 | DOSET (FLG_CHECKEDGLOBALIAS, b); | |
3982 | DOSET (FLG_CHECKMODGLOBALIAS, b); | |
3983 | DOSET (FLG_UNCHECKEDGLOBALIAS, b); | |
3984 | break; | |
3985 | case FLG_ALLBLOCK: | |
3986 | DOSET (FLG_ALLBLOCK, b); | |
3987 | DOSET (FLG_IFBLOCK, b); | |
3988 | DOSET (FLG_WHILEBLOCK, b); | |
3989 | DOSET (FLG_FORBLOCK, b); | |
3990 | break; | |
3991 | case FLG_GRAMMAR: | |
3992 | if (b) | |
616915dd | 3993 | { |
28bf4b0b | 3994 | yydebug = 1; |
3995 | mtdebug = 1; | |
616915dd | 3996 | } |
3997 | else | |
3998 | { | |
28bf4b0b | 3999 | yydebug = 0; |
4000 | mtdebug = 0; | |
4001 | } | |
4002 | ||
4003 | DOSET (FLG_GRAMMAR, b); | |
4004 | break; | |
4005 | case FLG_CODEIMPONLY: | |
4006 | DOSET (FLG_CODEIMPONLY, b); | |
4007 | DOSET (FLG_GLOBIMPONLY, b); | |
4008 | DOSET (FLG_RETIMPONLY, b); | |
4009 | DOSET (FLG_STRUCTIMPONLY, b); | |
4010 | break; | |
4011 | case FLG_SPECALLIMPONLY: | |
4012 | DOSET (FLG_SPECALLIMPONLY, b); | |
4013 | DOSET (FLG_SPECGLOBIMPONLY, b); | |
4014 | DOSET (FLG_SPECRETIMPONLY, b); | |
4015 | DOSET (FLG_SPECSTRUCTIMPONLY, b); | |
4016 | break; | |
4017 | case FLG_ALLIMPONLY: | |
4018 | DOSET (FLG_ALLIMPONLY, b); | |
4019 | DOSET (FLG_GLOBIMPONLY, b); | |
4020 | DOSET (FLG_RETIMPONLY, b); | |
4021 | DOSET (FLG_STRUCTIMPONLY, b); | |
4022 | DOSET (FLG_SPECGLOBIMPONLY, b); | |
4023 | DOSET (FLG_SPECRETIMPONLY, b); | |
4024 | DOSET (FLG_SPECSTRUCTIMPONLY, b); | |
4025 | break; | |
27c9e640 | 4026 | case FLG_ANSI89LIMITS: |
4027 | DOSET (FLG_ANSI89LIMITS, b); | |
28bf4b0b | 4028 | DOSET (FLG_CONTROLNESTDEPTH, b); |
4029 | DOSET (FLG_STRINGLITERALLEN, b); | |
4030 | DOSET (FLG_INCLUDENEST, b); | |
4031 | DOSET (FLG_NUMSTRUCTFIELDS, b); | |
4032 | DOSET (FLG_NUMENUMMEMBERS, b); | |
4033 | ||
4034 | if (b) | |
4035 | { | |
27c9e640 | 4036 | context_setValue (FLG_CONTROLNESTDEPTH, ANSI89_CONTROLNESTDEPTH); |
4037 | context_setValue (FLG_STRINGLITERALLEN, ANSI89_STRINGLITERALLEN); | |
4038 | context_setValue (FLG_INCLUDENEST, ANSI89_INCLUDENEST); | |
4039 | context_setValue (FLG_NUMSTRUCTFIELDS, ANSI89_NUMSTRUCTFIELDS); | |
4040 | context_setValue (FLG_NUMENUMMEMBERS, ANSI89_NUMENUMMEMBERS); | |
4041 | context_setValue (FLG_EXTERNALNAMELEN, ANSI89_EXTERNALNAMELEN); | |
4042 | context_setValue (FLG_INTERNALNAMELEN, ANSI89_INTERNALNAMELEN); | |
4043 | } | |
4044 | break; | |
4045 | case FLG_ISO99LIMITS: | |
4046 | DOSET (FLG_ISO99LIMITS, b); | |
4047 | DOSET (FLG_CONTROLNESTDEPTH, b); | |
4048 | DOSET (FLG_STRINGLITERALLEN, b); | |
4049 | DOSET (FLG_INCLUDENEST, b); | |
4050 | DOSET (FLG_NUMSTRUCTFIELDS, b); | |
4051 | DOSET (FLG_NUMENUMMEMBERS, b); | |
4052 | ||
4053 | if (b) | |
4054 | { | |
4055 | context_setValue (FLG_CONTROLNESTDEPTH, ISO99_CONTROLNESTDEPTH); | |
4056 | context_setValue (FLG_STRINGLITERALLEN, ISO99_STRINGLITERALLEN); | |
4057 | context_setValue (FLG_INCLUDENEST, ISO99_INCLUDENEST); | |
4058 | context_setValue (FLG_NUMSTRUCTFIELDS, ISO99_NUMSTRUCTFIELDS); | |
4059 | context_setValue (FLG_NUMENUMMEMBERS, ISO99_NUMENUMMEMBERS); | |
4060 | context_setValue (FLG_EXTERNALNAMELEN, ISO99_EXTERNALNAMELEN); | |
4061 | context_setValue (FLG_INTERNALNAMELEN, ISO99_INTERNALNAMELEN); | |
28bf4b0b | 4062 | } |
4063 | break; | |
4064 | case FLG_EXTERNALNAMELEN: | |
4065 | DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE); | |
4066 | DOSET (FLG_EXTERNALNAMELEN, TRUE); | |
4067 | break; | |
4068 | case FLG_INTERNALNAMELEN: | |
4069 | DOSET (FLG_DISTINCTINTERNALNAMES, TRUE); | |
4070 | DOSET (FLG_INTERNALNAMELEN, TRUE); | |
4071 | break; | |
4072 | case FLG_EXTERNALNAMECASEINSENSITIVE: | |
4073 | DOSET (FLG_EXTERNALNAMECASEINSENSITIVE, b); | |
4074 | ||
4075 | if (b && !gc.flags[FLG_DISTINCTEXTERNALNAMES]) | |
4076 | { | |
4077 | DOSET (FLG_DISTINCTEXTERNALNAMES, TRUE); | |
4078 | context_setValue (FLG_EXTERNALNAMELEN, 0); | |
4079 | } | |
4080 | break; | |
4081 | case FLG_INTERNALNAMECASEINSENSITIVE: | |
4082 | DOSET (FLG_INTERNALNAMECASEINSENSITIVE, b); | |
4083 | ||
4084 | if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES]) | |
4085 | { | |
4086 | DOSET (FLG_DISTINCTINTERNALNAMES, TRUE); | |
4087 | context_setValue (FLG_INTERNALNAMELEN, 0); | |
4088 | } | |
4089 | break; | |
4090 | case FLG_INTERNALNAMELOOKALIKE: | |
4091 | DOSET (FLG_INTERNALNAMELOOKALIKE, b); | |
4092 | ||
4093 | if (b && !gc.flags[FLG_DISTINCTINTERNALNAMES]) | |
4094 | { | |
4095 | DOSET (FLG_DISTINCTINTERNALNAMES, TRUE); | |
4096 | context_setValue (FLG_INTERNALNAMELEN, 0); | |
616915dd | 4097 | } |
28bf4b0b | 4098 | break; |
4099 | case FLG_MODUNSPEC: | |
4100 | DOSET (FLG_MODNOMODS, b); | |
4101 | DOSET (FLG_MODGLOBSUNSPEC, b); | |
4102 | DOSET (FLG_MODSTRICTGLOBSUNSPEC, b); | |
4103 | break; | |
4104 | case FLG_EXPORTANY: | |
4105 | DOSET (FLG_EXPORTVAR, b); | |
4106 | DOSET (FLG_EXPORTFCN, b); | |
4107 | DOSET (FLG_EXPORTTYPE, b); | |
4108 | DOSET (FLG_EXPORTMACRO, b); | |
4109 | DOSET (FLG_EXPORTCONST, b); | |
4110 | gc.anyExports = TRUE; | |
4111 | break; | |
4112 | case FLG_REPEXPOSE: | |
4113 | DOSET (FLG_RETEXPOSE, b); | |
4114 | DOSET (FLG_ASSIGNEXPOSE, b); | |
4115 | DOSET (FLG_CASTEXPOSE, b); | |
4116 | break; | |
4117 | case FLG_RETVAL: | |
4118 | DOSET (FLG_RETVALBOOL, b); | |
4119 | DOSET (FLG_RETVALINT, b); | |
4120 | DOSET (FLG_RETVALOTHER, b); | |
4121 | break; | |
4122 | case FLG_PARTIAL: | |
4123 | if (b) | |
4124 | { | |
4125 | DOSET (FLG_EXPORTLOCAL, FALSE); | |
4126 | DOSET (FLG_DECLUNDEF, FALSE); | |
4127 | DOSET (FLG_SPECUNDEF, FALSE); | |
4128 | DOSET (FLG_TOPUNUSED, FALSE); | |
4129 | } | |
4130 | break; | |
4131 | case FLG_DEEPBREAK: | |
4132 | DOSET (FLG_LOOPLOOPBREAK, b); | |
4133 | DOSET (FLG_LOOPSWITCHBREAK, b); | |
4134 | DOSET (FLG_SWITCHLOOPBREAK, b); | |
4135 | DOSET (FLG_SWITCHSWITCHBREAK, b); | |
4136 | DOSET (FLG_LOOPLOOPCONTINUE, b); | |
4137 | DOSET (FLG_DEEPBREAK, b); | |
4138 | break; | |
3e3ec469 | 4139 | case FLG_LOOPEXEC: |
4140 | DOSET (FLG_FORLOOPEXEC, b); | |
4141 | DOSET (FLG_WHILELOOPEXEC, b); | |
4142 | DOSET (FLG_ITERLOOPEXEC, b); | |
4143 | break; | |
28bf4b0b | 4144 | case FLG_ACCESSALL: |
4145 | DOSET (FLG_ACCESSMODULE, b); | |
4146 | DOSET (FLG_ACCESSFILE, b); | |
4147 | DOSET (FLG_ACCESSCZECH, b); | |
4148 | break; | |
4149 | case FLG_ALLMACROS: | |
4150 | DOSET (FLG_ALLMACROS, b); | |
4151 | DOSET (FLG_FCNMACROS, b); | |
4152 | DOSET (FLG_CONSTMACROS, b); | |
fba0ed37 | 4153 | break; |
bb7c2085 | 4154 | case FLG_BOUNDS: |
4155 | DOSET (FLG_BOUNDSREAD, b); | |
4156 | DOSET (FLG_BOUNDSWRITE, b); | |
fba0ed37 | 4157 | DOSET (FLG_LIKELYBOUNDSREAD, b); |
4158 | DOSET (FLG_LIKELYBOUNDSWRITE, b); | |
4159 | break; | |
4160 | case FLG_BOUNDSREAD: | |
4161 | DOSET (FLG_LIKELYBOUNDSREAD, b); | |
4162 | break; | |
4163 | case FLG_BOUNDSWRITE: | |
4164 | DOSET (FLG_LIKELYBOUNDSWRITE, b); | |
bb7c2085 | 4165 | break; |
fba0ed37 | 4166 | case FLG_LIKELYBOUNDS: |
4167 | DOSET (FLG_LIKELYBOUNDSREAD, b); | |
4168 | DOSET (FLG_LIKELYBOUNDSWRITE, b); | |
4169 | break; | |
4170 | ||
28bf4b0b | 4171 | case FLG_CZECH: |
4172 | if (b) { DOSET (FLG_ACCESSCZECH, b); } | |
4173 | DOSET (FLG_CZECHFUNCTIONS, b); | |
4174 | DOSET (FLG_CZECHVARS, b); | |
4175 | DOSET (FLG_CZECHCONSTANTS, b); | |
4176 | DOSET (FLG_CZECHTYPES, b); | |
4177 | break; | |
4178 | case FLG_SLOVAK: | |
4179 | if (b) { DOSET (FLG_ACCESSSLOVAK, b); } | |
4180 | DOSET (FLG_SLOVAKFUNCTIONS, b); | |
4181 | DOSET (FLG_SLOVAKVARS, b); | |
4182 | DOSET (FLG_SLOVAKCONSTANTS, b); | |
4183 | DOSET (FLG_SLOVAKTYPES, b); | |
4184 | break; | |
4185 | case FLG_CZECHOSLOVAK: | |
4186 | if (b) { DOSET (FLG_ACCESSCZECHOSLOVAK, b); } | |
4187 | DOSET (FLG_CZECHOSLOVAKFUNCTIONS, b); | |
4188 | DOSET (FLG_CZECHOSLOVAKVARS, b); | |
4189 | DOSET (FLG_CZECHOSLOVAKCONSTANTS, b); | |
4190 | DOSET (FLG_CZECHOSLOVAKTYPES, b); | |
4191 | break; | |
4192 | case FLG_NULL: | |
4193 | DOSET (FLG_NULLSTATE, b); | |
4194 | DOSET (FLG_NULLDEREF, b); | |
4195 | DOSET (FLG_NULLASSIGN, b); | |
4196 | DOSET (FLG_NULLPASS, b); | |
4197 | DOSET (FLG_NULLRET, b); | |
4198 | break; | |
2e127cb8 | 4199 | case FLG_MUSTFREE: |
4200 | DOSET (FLG_MUSTFREEONLY, b); | |
4201 | DOSET (FLG_MUSTFREEFRESH, b); | |
4202 | break; | |
28bf4b0b | 4203 | case FLG_MEMCHECKS: |
4204 | DOSET (FLG_NULLSTATE, b); | |
4205 | DOSET (FLG_NULLDEREF, b); | |
4206 | DOSET (FLG_NULLASSIGN, b); | |
4207 | DOSET (FLG_NULLPASS, b); | |
4208 | DOSET (FLG_NULLRET, b); | |
4209 | DOSET (FLG_COMPDEF, b); | |
4210 | DOSET (FLG_COMPMEMPASS, b); | |
4211 | DOSET (FLG_UNIONDEF, b); | |
4212 | DOSET (FLG_MEMTRANS, b); | |
4213 | DOSET (FLG_USERELEASED, b); | |
4214 | DOSET (FLG_ALIASUNIQUE, b); | |
4215 | DOSET (FLG_MAYALIASUNIQUE, b); | |
2e127cb8 | 4216 | DOSET (FLG_MUSTFREEONLY, b); |
4217 | DOSET (FLG_MUSTFREEFRESH, b); | |
28bf4b0b | 4218 | DOSET (FLG_MUSTDEFINE, b); |
4219 | DOSET (FLG_GLOBSTATE, b); | |
4220 | DOSET (FLG_COMPDESTROY, b); | |
4221 | DOSET (FLG_MUSTNOTALIAS, b); | |
4222 | DOSET (FLG_MEMIMPLICIT, b); | |
4223 | DOSET (FLG_BRANCHSTATE, b); | |
4224 | /*@fallthrough@*/ /* also sets memtrans flags */ | |
4225 | case FLG_MEMTRANS: | |
4226 | DOSET (FLG_MEMTRANS, b); | |
4227 | DOSET (FLG_EXPOSETRANS, b); | |
4228 | DOSET (FLG_OBSERVERTRANS, b); | |
4229 | DOSET (FLG_DEPENDENTTRANS, b); | |
4230 | DOSET (FLG_NEWREFTRANS, b); | |
4231 | DOSET (FLG_ONLYTRANS, b); | |
4232 | DOSET (FLG_OWNEDTRANS, b); | |
4233 | DOSET (FLG_FRESHTRANS, b); | |
4234 | DOSET (FLG_SHAREDTRANS, b); | |
4235 | DOSET (FLG_TEMPTRANS, b); | |
4236 | DOSET (FLG_KEPTTRANS, b); | |
4237 | DOSET (FLG_REFCOUNTTRANS, b); | |
4238 | DOSET (FLG_STATICTRANS, b); | |
4239 | DOSET (FLG_UNKNOWNTRANS, b); | |
4240 | DOSET (FLG_KEEPTRANS, b); | |
4241 | DOSET (FLG_IMMEDIATETRANS, b); | |
4242 | break; | |
4243 | ||
4244 | default: | |
4245 | break; | |
4246 | } | |
4247 | ||
4248 | if (b && !gc.anyExports | |
4249 | && (f == FLG_EXPORTVAR || f == FLG_EXPORTFCN | |
4250 | || f == FLG_EXPORTTYPE || f == FLG_EXPORTMACRO | |
4251 | || f == FLG_EXPORTCONST | |
4252 | || f == FLG_EXPORTANY)) | |
4253 | { | |
4254 | gc.anyExports = TRUE; | |
616915dd | 4255 | } |
4256 | } | |
4257 | ||
4258 | bool | |
4259 | context_maybeSet (flagcode d) | |
4260 | { | |
4261 | return (gc.flags[d] || gc.setLocally[d]); | |
4262 | } | |
4263 | ||
4264 | bool | |
4265 | context_getFlag (flagcode d) | |
4266 | { | |
4267 | return (gc.flags[d]); | |
4268 | } | |
4269 | ||
28bf4b0b | 4270 | bool |
4271 | context_flagOn (flagcode f, fileloc loc) | |
4272 | { | |
4273 | return (!context_suppressFlagMsg (f, loc)); | |
4274 | } | |
4275 | ||
616915dd | 4276 | static void context_saveFlagSettings (void) |
4277 | { | |
4278 | gc.savedFlags = TRUE; | |
4279 | llassert (sizeof (gc.saveflags) == sizeof (gc.flags)); | |
4280 | memcpy (gc.saveflags, gc.flags, sizeof (gc.flags)); | |
4281 | } | |
4282 | ||
4283 | static void context_restoreFlagSettings (void) | |
4284 | { | |
4285 | llassert (sizeof (gc.saveflags) == sizeof (gc.flags)); | |
4286 | memcpy (gc.flags, gc.saveflags, sizeof (gc.flags)); | |
4287 | gc.savedFlags = FALSE; | |
4288 | } | |
4289 | ||
4290 | void context_setFilename (fileId fid, int lineno) | |
4291 | /*@globals fileloc g_currentloc;@*/ | |
4292 | /*@modifies g_currentloc@*/ | |
4293 | { | |
4294 | if (fileId_baseEqual (currentFile (), fid)) | |
4295 | { | |
4296 | setLine (lineno); | |
4297 | return; | |
4298 | } | |
4299 | else | |
4300 | { | |
4301 | fileloc_setColumn (g_currentloc, 0); | |
4302 | ||
4303 | if (fileloc_isSpecialFile (g_currentloc)) | |
4304 | { | |
4305 | gc.inDerivedFile = TRUE; | |
4306 | } | |
4307 | ||
4308 | if (filelocStack_popPushFile (gc.locstack, g_currentloc)) | |
4309 | { | |
4310 | int maxdepth = context_getValue (FLG_INCLUDENEST); | |
4311 | ||
4312 | if (filelocStack_size (gc.locstack) > maxdepth) | |
4313 | { | |
4314 | int depth = filelocStack_includeDepth (gc.locstack); | |
4315 | ||
4316 | if (depth > maxdepth) | |
4317 | { | |
4318 | if (optgenerror | |
4319 | (FLG_INCLUDENEST, | |
4320 | message ("Maximum include nesting depth " | |
4321 | "(%d, current depth %d) exceeded", | |
4322 | maxdepth, | |
4323 | depth), | |
4324 | filelocStack_nextTop (gc.locstack))) | |
4325 | { | |
4326 | filelocStack_printIncludes (gc.locstack); | |
4327 | } | |
4328 | } | |
4329 | } | |
4330 | } | |
4331 | ||
4332 | g_currentloc = fileloc_create (fid, lineno, 1); | |
4333 | gc.inheader = fileId_isHeader (currentFile ()); | |
4334 | ||
4335 | context_enterFileAux (); | |
4336 | } | |
4337 | } | |
4338 | ||
4339 | void context_enterIterDef (/*@observer@*/ uentry le) | |
4340 | { | |
b7e84605 | 4341 | context_enterMacro (le); |
616915dd | 4342 | gc.acct = typeIdSet_subtract (gc.facct, gc.nacct); |
4343 | gc.kind = CX_ITERDEF; | |
4344 | } | |
4345 | ||
4346 | void context_enterIterEnd (/*@observer@*/ uentry le) | |
4347 | { | |
b7e84605 | 4348 | context_enterMacro (le); |
616915dd | 4349 | gc.kind = CX_ITEREND; |
4350 | } | |
4351 | ||
4352 | void | |
4353 | context_destroyMod (void) | |
4354 | /*@globals killed gc@*/ | |
4355 | { | |
6fcd0b1e | 4356 | int i; |
616915dd | 4357 | setCodePoint (); |
4358 | ctype_destroyMod (); | |
6fcd0b1e | 4359 | /* |
616915dd | 4360 | setCodePoint (); |
4361 | usymtab_free (); | |
4362 | setCodePoint (); | |
6fcd0b1e | 4363 | */ |
4364 | ||
616915dd | 4365 | fileTable_free (gc.ftab); |
6fcd0b1e | 4366 | gc.ftab = fileTable_undefined; |
4367 | ||
616915dd | 4368 | filelocStack_free (gc.locstack); |
4369 | setCodePoint (); | |
616915dd | 4370 | |
4371 | macrocache_free (gc.mc); | |
6fcd0b1e | 4372 | |
4373 | /* evans 2002-07-12: not reported because of reldef */ | |
4374 | for (i = 0; i < gc.nmods; i++) | |
4375 | { | |
4376 | cstring_free (gc.moduleaccess[i].file); | |
4377 | } | |
4378 | ||
616915dd | 4379 | sfree (gc.moduleaccess); |
4380 | setCodePoint (); | |
4381 | ||
4382 | fileloc_free (gc.saveloc); gc.saveloc = fileloc_undefined; | |
4383 | fileloc_free (gc.pushloc); gc.pushloc = fileloc_undefined; | |
4384 | ||
4385 | setCodePoint (); | |
4386 | sRefSetList_free (gc.modrecs); | |
4387 | setCodePoint (); | |
4388 | flagMarkerList_free (gc.markers); | |
4389 | setCodePoint (); | |
4390 | messageLog_free (gc.msgLog); | |
4391 | setCodePoint (); | |
4392 | clauseStack_free (gc.clauses); | |
4393 | setCodePoint (); | |
4394 | ||
4395 | cstring_free (gc.msgAnnote); | |
4396 | globSet_free (gc.globs_used); | |
28bf4b0b | 4397 | metaStateTable_free (gc.stateTable); |
4398 | annotationTable_free (gc.annotTable); | |
4399 | } | |
616915dd | 4400 | |
4401 | /* | |
81fc136a | 4402 | ** Flag shortcuts |
616915dd | 4403 | */ |
4404 | ||
4405 | bool context_msgBoolInt (void) | |
4406 | { | |
81fc136a | 4407 | return context_flagOn (FLG_BOOLINT, g_currentloc); |
616915dd | 4408 | } |
4409 | ||
4410 | bool context_msgCharInt (void) | |
4411 | { | |
81fc136a | 4412 | return context_flagOn (FLG_CHARINT, g_currentloc); |
616915dd | 4413 | } |
4414 | ||
4415 | bool context_msgEnumInt (void) | |
4416 | { | |
81fc136a | 4417 | return context_flagOn (FLG_ENUMINT, g_currentloc); |
4418 | } | |
4419 | ||
4420 | bool context_msgLongInt (void) | |
4421 | { | |
4422 | return context_flagOn (FLG_LONGINT, g_currentloc); | |
4423 | } | |
4424 | ||
4425 | bool context_msgShortInt (void) | |
4426 | { | |
4427 | return context_flagOn (FLG_SHORTINT, g_currentloc); | |
616915dd | 4428 | } |
4429 | ||
4430 | bool context_msgPointerArith (void) | |
4431 | { | |
81fc136a | 4432 | return context_flagOn (FLG_POINTERARITH, g_currentloc); |
616915dd | 4433 | } |
4434 | ||
4435 | bool context_msgStrictOps (void) | |
4436 | { | |
81fc136a | 4437 | return context_flagOn (FLG_STRICTOPS, g_currentloc); |
616915dd | 4438 | } |
4439 | ||
616915dd | 4440 | bool context_msgLh (void) |
4441 | { | |
4442 | return gc.flags [FLG_DOLH]; | |
4443 | } | |
616915dd | 4444 | |
4445 | void context_pushLoc (void) | |
4446 | { | |
4447 | fileloc_free (gc.pushloc); | |
4448 | gc.pushloc = gc.saveloc; | |
4449 | gc.saveloc = fileloc_undefined; | |
4450 | } | |
4451 | ||
4452 | void context_popLoc (void) | |
4453 | { | |
4454 | gc.saveloc = fileloc_update (gc.saveloc, gc.pushloc); | |
4455 | } | |
4456 | ||
4457 | bool context_inGlobalScope (void) | |
4458 | { | |
4459 | return (usymtab_inFileScope() || usymtab_inGlobalScope ()); | |
4460 | } | |
4461 | ||
4462 | bool context_inInnerScope (void) | |
4463 | { | |
4464 | return (gc.kind == CX_INNER); | |
4465 | } | |
4466 | ||
4467 | void context_setProtectVars (void) | |
4468 | { | |
4469 | gc.protectVars = TRUE; | |
4470 | } | |
4471 | ||
4472 | bool context_anyErrors (void) | |
4473 | { | |
4474 | return (gc.numerrors > 0); | |
4475 | } | |
4476 | ||
4477 | void context_hasError (void) | |
4478 | { | |
4479 | gc.numerrors++; | |
ccf0a4a8 | 4480 | DPRINTF (("num errors: %d", gc.numerrors)); |
616915dd | 4481 | } |
4482 | ||
4483 | int context_numErrors (void) | |
4484 | { | |
4485 | return gc.numerrors; | |
4486 | } | |
4487 | ||
4488 | bool context_neednl (void) | |
4489 | { | |
4490 | return gc.neednl; | |
4491 | } | |
4492 | ||
4493 | void context_setNeednl (void) | |
4494 | { | |
4495 | gc.neednl = TRUE; | |
4496 | } | |
4497 | ||
4498 | int context_getExpect (void) | |
4499 | { | |
4500 | return (context_getValue (FLG_EXPECT)); | |
4501 | } | |
4502 | ||
616915dd | 4503 | int context_getLCLExpect (void) |
4504 | { | |
4505 | return (context_getValue (FLG_LCLEXPECT)); | |
4506 | } | |
616915dd | 4507 | |
4508 | int context_getLimit (void) | |
4509 | { | |
4510 | return (context_getValue (FLG_LIMIT)); | |
4511 | } | |
4512 | ||
4513 | bool context_unlimitedMessages (void) | |
4514 | { | |
4515 | return (context_getLimit () < 0); | |
4516 | } | |
4517 | ||
4518 | void context_releaseVars (void) | |
4519 | { | |
4520 | llassert (gc.protectVars); | |
4521 | gc.protectVars = FALSE; | |
4522 | } | |
4523 | ||
4524 | void context_sizeofReleaseVars (void) | |
4525 | { | |
4526 | /* If there is a nested sizeof, this might not hold: | |
4527 | llassert (gc.protectVars); | |
4528 | */ | |
4529 | ||
4530 | gc.protectVars = FALSE; | |
4531 | } | |
4532 | ||
4533 | bool context_inProtectVars (void) | |
4534 | { | |
4535 | return (gc.protectVars); | |
4536 | } | |
4537 | ||
4538 | void context_hideShowscan (void) | |
4539 | { | |
4540 | gc.flags[FLG_SHOWSCAN] = FALSE; | |
4541 | } | |
4542 | ||
4543 | void context_unhideShowscan (void) | |
4544 | { | |
4545 | gc.flags[FLG_SHOWSCAN] = TRUE; | |
4546 | } | |
4547 | ||
4548 | bool context_inHeader (void) | |
4549 | { | |
4550 | return (gc.inheader); | |
4551 | } | |
4552 | ||
4553 | fileTable context_fileTable (void) | |
4554 | { | |
4555 | return gc.ftab; | |
4556 | } | |
4557 | ||
4558 | cstring context_tmpdir (void) | |
4559 | { | |
4560 | return (context_getString (FLG_TMPDIR)); | |
4561 | } | |
4562 | ||
4563 | messageLog context_messageLog (void) | |
4564 | { | |
4565 | return gc.msgLog; | |
4566 | } | |
4567 | ||
4568 | bool context_inMacroFunction (void) | |
4569 | { | |
4570 | return (gc.kind == CX_MACROFCN); | |
4571 | } | |
4572 | ||
4573 | bool context_inMacroConstant (void) | |
4574 | { | |
4575 | return (gc.kind == CX_MACROCONST); | |
4576 | } | |
4577 | ||
b7e84605 | 4578 | bool context_inUnknownMacro (void) |
616915dd | 4579 | { |
4580 | return (gc.kind == CX_UNKNOWNMACRO); | |
4581 | } | |
4582 | ||
4583 | void context_setShownFunction (void) | |
4584 | { | |
4585 | gc.showfunction = FALSE; | |
4586 | } | |
4587 | ||
4588 | bool context_doDump (void) | |
4589 | { | |
4590 | return cstring_isNonEmpty (context_getString (FLG_DUMP)); | |
4591 | } | |
4592 | ||
4593 | bool context_doMerge (void) | |
4594 | { | |
4595 | return cstring_isNonEmpty (context_getString (FLG_MERGE)); | |
4596 | } | |
4597 | ||
4598 | cstring context_getDump (void) | |
4599 | { | |
4600 | return context_getString (FLG_DUMP); | |
4601 | } | |
4602 | ||
4603 | cstring context_getMerge (void) | |
4604 | { | |
4605 | return context_getString (FLG_MERGE); | |
4606 | } | |
4607 | ||
616915dd | 4608 | bool context_inLCLLib (void) |
4609 | { | |
4610 | return (gc.kind == CX_LCLLIB); | |
4611 | } | |
4612 | ||
edad9a7f | 4613 | |
4614 | /*drl add these 3/5/2003*/ | |
4615 | static bool inSizeof = FALSE; | |
4616 | ||
4617 | bool context_inSizeof (void) | |
4618 | { | |
4619 | return (inSizeof); | |
4620 | } | |
4621 | ||
4622 | void context_enterSizeof (void) | |
4623 | { | |
4624 | DPRINTF((message("context_enterSizeof ") ) ); | |
4625 | inSizeof = TRUE; | |
4626 | } | |
4627 | ||
4628 | void context_leaveSizeof (void) | |
4629 | { | |
4630 | DPRINTF((message("context_leaveSizeof ") )); | |
4631 | inSizeof = FALSE; | |
4632 | } | |
4633 | /*end function added 3/5/2003*/ | |
4634 | ||
4635 | ||
616915dd | 4636 | bool context_inImport (void) |
4637 | { | |
4638 | return (gc.inimport); | |
4639 | } | |
4640 | ||
4641 | void context_enterImport (void) | |
4642 | { | |
4643 | gc.inimport = TRUE; | |
4644 | } | |
4645 | ||
4646 | void context_leaveImport (void) | |
4647 | { | |
4648 | gc.inimport = FALSE; | |
4649 | } | |
616915dd | 4650 | |
4651 | bool context_inMacro (void) | |
4652 | { | |
4653 | return (gc.kind == CX_MACROFCN || gc.kind == CX_MACROCONST | |
4654 | || gc.kind == CX_UNKNOWNMACRO | |
4655 | || gc.kind == CX_ITERDEF || gc.kind == CX_ITEREND); | |
4656 | } | |
4657 | ||
4658 | bool context_inIterDef (void) | |
4659 | { | |
4660 | return (gc.kind == CX_ITERDEF); | |
4661 | } | |
4662 | ||
4663 | bool context_inIterEnd (void) | |
4664 | { | |
4665 | return (gc.kind == CX_ITEREND); | |
4666 | } | |
4667 | ||
4668 | int context_getLinesProcessed (void) | |
4669 | { | |
4670 | return (gc.linesprocessed); | |
4671 | } | |
4672 | ||
4673 | int context_getSpecLinesProcessed (void) | |
4674 | { | |
4675 | return (gc.speclinesprocessed); | |
4676 | } | |
4677 | ||
616915dd | 4678 | void context_processedSpecLine (void) |
4679 | { | |
4680 | gc.speclinesprocessed++; | |
4681 | } | |
4682 | ||
4683 | void context_resetSpecLines (void) | |
4684 | { | |
4685 | gc.speclinesprocessed = 0; | |
6fcd0b1e | 4686 | |
616915dd | 4687 | } |
616915dd | 4688 | |
4689 | bool context_inGlobalContext (void) | |
4690 | { | |
4691 | return (gc.kind == CX_GLOBAL); | |
4692 | } | |
4693 | ||
b7e84605 | 4694 | static void context_quietExitScopes (void) |
4695 | { | |
4696 | /* | |
4697 | ** Try to restore the global scope (after an error). | |
4698 | */ | |
4699 | ||
4700 | while (!usymtab_inFileScope ()) | |
4701 | { | |
4702 | usymtab_quietExitScope (g_currentloc); | |
4703 | } | |
4704 | ||
4705 | gc.cont.glob = TRUE; | |
4706 | gc.kind = CX_GLOBAL; | |
4707 | } | |
4708 | ||
4709 | void context_checkGlobalScope (void) | |
4710 | { | |
4711 | if (gc.kind != CX_GLOBAL) | |
4712 | { | |
a469ccf0 | 4713 | if (context_inMacro ()) |
4714 | { | |
4715 | ; /* evans 2001-10-14: Okay to be in a macro here! */ | |
4716 | } | |
4717 | else | |
4718 | { | |
4719 | llcontbug (message ("Not in global scope as expected: %q", context_unparse ())); | |
4720 | context_quietExitScopes (); | |
4721 | } | |
b7e84605 | 4722 | } |
4723 | } | |
4724 | ||
616915dd | 4725 | void context_setFileId (fileId s) |
4726 | { | |
4727 | g_currentloc = fileloc_updateFileId (g_currentloc, s); | |
4728 | } | |
4729 | ||
4730 | bool context_setBoolName (void) | |
4731 | { | |
4732 | return (!cstring_equalLit (context_getString (FLG_BOOLTYPE), | |
4733 | DEFAULT_BOOLTYPE)); | |
4734 | } | |
4735 | ||
4736 | cstring context_printBoolName (void) | |
4737 | { | |
4738 | if (context_setBoolName ()) | |
4739 | { | |
4740 | return context_getBoolName (); | |
4741 | } | |
4742 | else | |
4743 | { | |
4744 | return cstring_makeLiteralTemp ("boolean"); | |
4745 | } | |
4746 | } | |
4747 | ||
4748 | cstring context_getBoolName (void) | |
4749 | { | |
4750 | return (context_getString (FLG_BOOLTYPE)); | |
4751 | } | |
4752 | ||
4753 | cstring context_getFalseName (void) | |
4754 | { | |
4755 | return (context_getString (FLG_BOOLFALSE)); | |
4756 | } | |
4757 | ||
4758 | cstring context_getTrueName (void) | |
4759 | { | |
4760 | return (context_getString (FLG_BOOLTRUE)); | |
4761 | } | |
4762 | ||
4763 | cstring context_getLarchPath (void) | |
4764 | { | |
4765 | return (context_getString (FLG_LARCHPATH)); | |
4766 | } | |
4767 | ||
4768 | cstring context_getLCLImportDir (void) | |
4769 | { | |
4770 | return (context_getString (FLG_LCLIMPORTDIR)); | |
4771 | } | |
4772 | ||
4773 | static void context_setJustPopped (void) | |
4774 | { | |
4775 | gc.justpopped = TRUE; | |
4776 | } | |
4777 | ||
4778 | void context_clearJustPopped (void) | |
4779 | { | |
4780 | gc.justpopped = FALSE; | |
4781 | } | |
4782 | ||
4783 | bool context_justPopped (void) | |
4784 | { | |
4785 | return (gc.justpopped); | |
4786 | } | |
4787 | ||
4788 | void context_setMacroMissingParams (void) | |
4789 | { | |
4790 | gc.macroMissingParams = TRUE; | |
4791 | } | |
4792 | ||
4793 | void context_resetMacroMissingParams (void) | |
4794 | { | |
4795 | gc.macroMissingParams = FALSE; | |
4796 | } | |
4797 | ||
4798 | bool context_isMacroMissingParams (void) | |
4799 | { | |
4800 | return (gc.macroMissingParams); | |
4801 | } | |
4802 | ||
4803 | void context_showFilelocStack (void) | |
4804 | { | |
4805 | filelocStack_printIncludes (gc.locstack); | |
4806 | } | |
4807 | ||
28bf4b0b | 4808 | metaStateTable context_getMetaStateTable (void) |
4809 | { | |
4810 | return gc.stateTable; | |
4811 | } | |
4812 | ||
4813 | metaStateInfo context_lookupMetaStateInfo (cstring key) | |
4814 | { | |
4815 | return metaStateTable_lookup (gc.stateTable, key); | |
4816 | } | |
4817 | ||
4818 | /*@null@*/ annotationInfo context_lookupAnnotation (cstring annot) | |
4819 | { | |
6d43e86c | 4820 | return annotationTable_lookup (gc.annotTable, annot); |
28bf4b0b | 4821 | } |
4822 | ||
6d43e86c | 4823 | void context_addAnnotation (annotationInfo info) |
28bf4b0b | 4824 | { |
6d43e86c | 4825 | if (annotationTable_contains (gc.annotTable, annotationInfo_getName (info))) |
28bf4b0b | 4826 | { |
4827 | voptgenerror | |
4828 | (FLG_SYNTAX, | |
6d43e86c | 4829 | message ("Duplicate annotation declaration: %s", annotationInfo_getName (info)), |
4830 | annotationInfo_getLoc (info)); | |
28bf4b0b | 4831 | |
6d43e86c | 4832 | annotationInfo_free (info); |
28bf4b0b | 4833 | } |
4834 | else | |
4835 | { | |
6d43e86c | 4836 | annotationTable_insert (gc.annotTable, info); |
28bf4b0b | 4837 | } |
4838 | } | |
4839 | ||
4840 | void context_addMetaState (cstring mname, metaStateInfo msinfo) | |
4841 | { | |
4842 | if (metaStateTable_contains (gc.stateTable, mname)) | |
4843 | { | |
4844 | voptgenerror | |
4845 | (FLG_SYNTAX, | |
4846 | message ("Duplicate metastate declaration: %s", mname), | |
4847 | metaStateInfo_getLoc (msinfo)); | |
4848 | cstring_free (mname); | |
4849 | metaStateInfo_free (msinfo); | |
4850 | } | |
4851 | else | |
4852 | { | |
990ec868 | 4853 | DPRINTF (("Adding meta state: %s", mname)); |
28bf4b0b | 4854 | metaStateTable_insert (gc.stateTable, mname, msinfo); |
4855 | } | |
4856 | } | |
616915dd | 4857 | |
6d43e86c | 4858 | valueTable context_createValueTable (sRef s, stateInfo info) |
28bf4b0b | 4859 | { |
4860 | if (metaStateTable_size (gc.stateTable) > 0) | |
4861 | { | |
4862 | valueTable res = valueTable_create (metaStateTable_size (gc.stateTable)); | |
b73d1009 | 4863 | /* should use smaller value... */ |
28bf4b0b | 4864 | DPRINTF (("Value table for: %s", sRef_unparse (s))); |
990ec868 | 4865 | |
28bf4b0b | 4866 | metaStateTable_elements (gc.stateTable, msname, msi) |
4867 | { | |
4868 | mtContextNode context = metaStateInfo_getContext (msi); | |
616915dd | 4869 | |
28bf4b0b | 4870 | if (mtContextNode_matchesRefStrict (context, s)) |
4871 | { | |
4872 | DPRINTF (("Create: %s", metaStateInfo_unparse (msi))); | |
4873 | llassert (cstring_equal (msname, metaStateInfo_getName (msi))); | |
4874 | ||
990ec868 | 4875 | valueTable_insert |
4876 | (res, | |
4877 | cstring_copy (metaStateInfo_getName (msi)), | |
6970c11b | 4878 | stateValue_createImplicit (metaStateInfo_getDefaultValue (msi, s), |
6d43e86c | 4879 | stateInfo_copy (info))); |
28bf4b0b | 4880 | } |
4881 | else | |
4882 | { | |
4883 | DPRINTF (("No match: %s", metaStateInfo_unparse (msi))); | |
4884 | } | |
4885 | } | |
4886 | end_metaStateTable_elements ; | |
4887 | ||
6d43e86c | 4888 | stateInfo_free (info); |
28bf4b0b | 4889 | DPRINTF (("Value table: %s", valueTable_unparse (res))); |
4890 | return res; | |
4891 | } | |
4892 | else | |
4893 | { | |
6d43e86c | 4894 | stateInfo_free (info); |
28bf4b0b | 4895 | return valueTable_undefined; |
4896 | } | |
4897 | } | |
616915dd | 4898 | |
6d43e86c | 4899 | valueTable context_createGlobalMarkerValueTable (stateInfo info) |
28bf4b0b | 4900 | { |
4901 | if (metaStateTable_size (gc.stateTable) > 0) | |
4902 | { | |
4903 | valueTable res = valueTable_create (metaStateTable_size (gc.stateTable)); | |
b73d1009 | 4904 | /* should use smaller value... */ |
28bf4b0b | 4905 | |
4906 | metaStateTable_elements (gc.stateTable, msname, msi) | |
4907 | { | |
b73d1009 | 4908 | /* only add global...*/ |
28bf4b0b | 4909 | DPRINTF (("Create: %s", metaStateInfo_unparse (msi))); |
4910 | llassert (cstring_equal (msname, metaStateInfo_getName (msi))); | |
4911 | ||
4912 | valueTable_insert (res, | |
4913 | cstring_copy (metaStateInfo_getName (msi)), | |
4914 | stateValue_create (metaStateInfo_getDefaultGlobalValue (msi), | |
6d43e86c | 4915 | stateInfo_copy (info))); |
28bf4b0b | 4916 | } |
4917 | end_metaStateTable_elements ; | |
4918 | ||
6d43e86c | 4919 | stateInfo_free (info); |
28bf4b0b | 4920 | DPRINTF (("Value table: %s", valueTable_unparse (res))); |
4921 | return res; | |
4922 | } | |
4923 | else | |
4924 | { | |
6d43e86c | 4925 | stateInfo_free (info); |
28bf4b0b | 4926 | return valueTable_undefined; |
4927 | } | |
4928 | } | |
616915dd | 4929 | |
6317f163 | 4930 | constraintList context_getImplicitFcnConstraints (uentry ue) |
86d93ed3 | 4931 | { |
6317f163 | 4932 | constraintList ret = constraintList_makeNew (); |
4933 | uentryList params = uentry_getParams (ue); | |
86d93ed3 | 4934 | |
6317f163 | 4935 | uentryList_elements (params, el) |
86d93ed3 | 4936 | { |
6317f163 | 4937 | DPRINTF (("setImplicitfcnConstraints doing: %s", uentry_unparse(el))); |
86d93ed3 | 4938 | |
6317f163 | 4939 | if (uentry_isElipsisMarker (el)) |
86d93ed3 | 4940 | { |
6317f163 | 4941 | ; |
86d93ed3 | 4942 | } |
6317f163 | 4943 | else |
4944 | { | |
4945 | sRef s = uentry_getSref (el); | |
4946 | ||
4947 | DPRINTF (("Trying: %s", sRef_unparse (s))); | |
86d93ed3 | 4948 | |
6317f163 | 4949 | if (ctype_isPointer (sRef_getType (s))) |
4950 | { | |
4951 | constraint c = constraint_makeSRefWriteSafeInt (s, 0); | |
4952 | ret = constraintList_add (ret, c); | |
4953 | ||
4954 | /*drl 10/23/2002 added support for out*/ | |
4955 | ||
4956 | if (!uentry_isOut(el)) | |
4957 | { | |
4958 | c = constraint_makeSRefReadSafeInt (s, 0); | |
4959 | ret = constraintList_add (ret , c); | |
4960 | } | |
4961 | } | |
4962 | else | |
4963 | { | |
4964 | DPRINTF (("%s is NOT a pointer", sRef_unparseFull (s))); | |
4965 | } | |
4966 | } | |
4967 | } end_uentryList_elements; | |
86d93ed3 | 4968 | |
6317f163 | 4969 | DPRINTF (("Returns ==> %s", constraintList_unparse (ret))); |
4970 | return ret; | |
86d93ed3 | 4971 | } |
2f2892c2 | 4972 |