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