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