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