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