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