Bug Summary

File:src/include.c
Warning:line 541, column 7
Although the value stored to 's' is used in the enclosing expression, the value is never actually read from 's'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name include.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/kfp/aldor/aldor/aldor/src -fcoverage-compilation-dir=/home/kfp/aldor/aldor/aldor/src -resource-dir /usr/local/lib/clang/18 -D PACKAGE_NAME="aldor" -D PACKAGE_TARNAME="aldor" -D PACKAGE_VERSION="1.4.0" -D PACKAGE_STRING="aldor 1.4.0" -D PACKAGE_BUGREPORT="aldor@xinutec.org" -D PACKAGE_URL="" -D PACKAGE="aldor" -D VERSION="1.4.0" -D YYTEXT_POINTER=1 -D HAVE_STDIO_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDINT_H=1 -D HAVE_STRINGS_H=1 -D HAVE_SYS_STAT_H=1 -D HAVE_SYS_TYPES_H=1 -D HAVE_UNISTD_H=1 -D STDC_HEADERS=1 -D HAVE_LIBREADLINE=1 -D HAVE_READLINE_READLINE_H=1 -D HAVE_READLINE_HISTORY=1 -D HAVE_READLINE_HISTORY_H=1 -D USE_GLOOP_SHELL=1 -D GENERATOR_COROUTINES=0 -D HAVE_DLFCN_H=1 -D LT_OBJDIR=".libs/" -I . -D VCSVERSION="2c53e759f1e00e345f8b172e7139debda72fda13" -internal-isystem /usr/local/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-empty-body -Wno-enum-compare -Wno-missing-field-initializers -Wno-unused -Wno-unused-parameter -Wno-error=format -Wno-error=type-limits -Wno-error=strict-aliasing -Wno-sign-compare -Wno-error=shift-negative-value -Wno-error=clobbered -std=c99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2026-01-15-223856-845667-1 -x c include.c
1/*****************************************************************************
2 *
3 * include.c: The source file includer.
4 *
5 * Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
6 *
7 ****************************************************************************/
8
9/*
10 * This file contains functions for processing the source file directives
11 *
12 * #include fname
13 * #reinclude fname
14 *
15 * #assert property
16 * #unassert property
17 *
18 * #if property
19 * #elseif property
20 * #else
21 * #endif
22 *
23 * #line lno [fname]
24 *
25 * Other #xxx lines are passed on untouched.
26 */
27
28#include "file.h"
29#include "fluid.h"
30#include "include.h"
31#include "opsys.h"
32#include "syscmd.h"
33#include "util.h"
34#include "path.h"
35#include "srcline.h"
36#include "comsg.h"
37#include "strops.h"
38#include "ftype.h"
39
40/******************************************************************************
41 *
42 * :: Forward Declarations
43 *
44 *****************************************************************************/
45
46typedef enum {
47 NoIf,
48 ActiveIf,
49 InactiveIf,
50 FormerlyActiveIf
51} IfState;
52
53typedef struct {
54 String curDir; /* current directory of the file */
55 String curFile; /* current file name string */
56 FileName curFname; /* current file name */
57 FILE *infile; /* file being included */
58 HashList fileCodes; /* hash codes of active source files */
59 StringList fileNames; /* names of active source files */
60 int lineNumber; /* file line number */
61} FileState;
62
63/*
64 * Recursive file includer.
65 */
66localstatic FileName inclFind (String fn, String cwd);
67localstatic SrcLineList inclFile (String, Bool, Bool, long *pnlines);
68localstatic SrcLineList inclFileContents (void);
69localstatic Bool inclLine (SrcLineList *, InclIsContinuedFun);
70localstatic SrcLineList inclError (Msg, ...);
71
72/*
73 * Include directives.
74 */
75localstatic SrcLineList inclHandleDirective(void);
76
77/*
78 * Utilities
79 */
80# define DIRECTIVE_CHAR'#' '#' /* Character starting directives */
81
82# define INCLUDING(state)((state)==NoIf || (state)==ActiveIf) ((state)==NoIf || (state)==ActiveIf)
83
84localstatic Bool inclIsDirective (String line);
85localstatic String inclCalcIndentLevel (String line, int *indent);
86localstatic String inclGetLine (FILE *);
87localstatic String inclActiveFileChain (StringList, String);
88
89static struct SrcLineListCons EIFC = {0, 0};
90static SrcLineList EndifLine = &EIFC; /* )endif indicator */
91
92
93/******************************************************************************
94 *
95 * :: Includer state
96 *
97 *****************************************************************************/
98
99StringList globalAssertList = 0; /* Globally asserted properties */
100StringList localAssertList = 0; /* Per-entry asserted properties */
101long inclSerialLineNo = 0; /* The serial line number */
102long inclFileLineNo = 1; /* Filled in at end. */
103
104Buffer inclBuffer; /* Input buffer */
105String curLineString; /* The current line being processed */
106IfState ifState; /* State of current )if */
107FileState fileState; /* State of current file */
108HashList includedFileCodes = 0; /* Hash codes of all included files */
109
110
111/******************************************************************************
112 *
113 * :: Top-level entry points
114 *
115 *****************************************************************************/
116
117/*
118 * Call either include "includeFile" or "includeLine".
119 * If fin is stdin include one line. Otherwise include the whole file.
120 */
121SrcLineList
122include(FileName fn, FILE *fin, int *plineno, InclIsContinuedFun iscont)
123{
124 if (fnameIsStdin(fn) && fin)
125 return includeLine(fn, fin, plineno, iscont);
126 else
127 return includeFile(fn);
128}
129
130
131/*
132 * Return a processed source line list of the file contents.
133 */
134SrcLineList
135includeFile(FileName fname)
136{
137 String fnameString;
138 SrcLineList r;
139
140 inclSerialLineNo = 0;
141 fnameString = strCopy(fnameUnparseStatic(fname));
142 inclBuffer = bufNew();
143 includedFileCodes = 0;
144 localAssertList = listCopy(String)(String_listPointer->Copy)(globalAssertList);
145
146 fileState.curDir = osCurDirName();
147 fileState.fileCodes = 0;
148 fileState.fileNames = 0;
149
150 r = listNReverse(SrcLine)(SrcLine_listPointer->NReverse)(
151 inclFile(fnameString, false((int) 0), true1, &inclFileLineNo));
152
153 strFree(fnameString);
154 bufFree(inclBuffer);
155 listFree(String)(String_listPointer->Free)(localAssertList);
156 listFree(Hash)(Hash_listPointer->Free)(includedFileCodes);
157
158 return r;
159}
160
161/*
162 * Return a processed source line list for the next line of the file.
163 * The source line list may have several entries if the line is an
164 * includer directive or requires a continuation.
165 */
166SrcLineList
167includeLine(FileName fn, FILE *fin, int *plineno, InclIsContinuedFun iscont)
168{
169 SrcLineList r;
170
171 inclBuffer = bufNew();
172 localAssertList = globalAssertList;
173
174 fileState.curDir = osCurDirName();
175 fileState.curFile = strCopy(fnameUnparseStatic(fn));
176 fileState.curFname = fn;
177 fileState.infile = fin;
178 fileState.fileCodes = 0;
179 fileState.fileNames = 0;
180 fileState.lineNumber= *plineno;
181
182 ifState = NoIf;
183
184 r = 0;
185 inclLine(&r, iscont);
186 r = listNReverse(SrcLine)(SrcLine_listPointer->NReverse)(r);
187
188 /* Leave the assert list and included files for the next call. */
189 globalAssertList = localAssertList;
190
191 bufFree(inclBuffer);
192 /* strFree(fileState.curFile); !!This is held on to by the srclines.*/
193 listFree(Hash)(Hash_listPointer->Free) (fileState.fileCodes);
194 listFree(String)(String_listPointer->Free)(fileState.fileNames);
195
196 *plineno = fileState.lineNumber;
197 inclFileLineNo = fileState.lineNumber;
198
199 return r;
200}
201
202/*
203 * Return line counts from previous include.
204 */
205long
206inclTotalLineCount(void)
207{
208 return inclSerialLineNo;
209}
210
211long
212inclFileLineCount(void)
213{
214 return inclFileLineNo;
215}
216
217/*
218 * Write included lines in a form suitable for re-inclusion.
219 * The number of characters written is returned.
220 */
221int
222inclWrite(FILE *file, SrcLineList sll)
223{
224 int cc = 0;
225 FileName slfile, curfile = 0; /* Guarantee first line is #line ... */
226 Length slline, curline = 0;
227
228 for ( ; sll; sll = cdr(sll)((sll)->rest)) {
229 SrcLine sl = car(sll)((sll)->first);
230
231 if (sl->isSysCmd && sl->sysCmdHandled) continue;
232
233 slfile = sposFile(sl->spos);
234 slline = sposLine(sl->spos);
235 if (curline != slline - 1
236 || (curfile && !fnameEqual(curfile,slfile)))
237 {
238 if ((curfile && fnameEqual(curfile, slfile)))
239 cc += fprintf(file, "%cline %d\n",
240 DIRECTIVE_CHAR'#',
241 (int) slline);
242 else {
243 cc += fprintf(file, "%cline %d \"%s\"\n",
244 DIRECTIVE_CHAR'#',
245 (int) slline,
246 fnameUnparseStatic(slfile));
247 curfile = slfile;
248 }
249 }
250 curline = slline;
251
252 cc += fprintf(file, "%*s%s", sl->indentation, "", sl->text);
253 }
254 return cc;
255}
256
257/*
258 * Free a list of source lines.
259 */
260void
261inclFree(SrcLineList sll)
262{
263 listFreeDeeply(SrcLine)(SrcLine_listPointer->FreeDeeply)(sll, slineFree);
264}
265
266/*
267 * Assertions for conditional includes.
268 */
269# define INCL_Assert(pl, p)(*(pl)=(String_listPointer->Cons)((p), *(pl))) (*(pl)=listCons(String)(String_listPointer->Cons)((p), *(pl)))
270# define INCL_Unassert(pl, p)(*(pl)=(String_listPointer->NRemove)(*(pl),(p),strEqual)) (*(pl)=listNRemove(String)(String_listPointer->NRemove)(*(pl),(p),strEqual))
271# define INCL_IsAssert(pl, p)((String_listPointer->Member)(*(pl), (p), strEqual)) (listMember(String)(String_listPointer->Member)(*(pl), (p), strEqual))
272
273void
274inclGlobalAssert(String property)
275{
276 INCL_Assert(&globalAssertList, property)(*(&globalAssertList)=(String_listPointer->Cons)((property
), *(&globalAssertList)))
;
277}
278
279void
280inclGlobalUnassert(String property)
281{
282 INCL_Unassert(&globalAssertList, property)(*(&globalAssertList)=(String_listPointer->NRemove)(*(
&globalAssertList),(property),strEqual))
;
283}
284
285/******************************************************************************
286 *
287 * :: Recursive file inclusion
288 *
289 *****************************************************************************/
290
291#define SysCmdLine(isHandled)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, isHandled)
\
292 slineNewSysCmd(sposNew(fileState.curFname, \
293 fileState.lineNumber, \
294 inclSerialLineNo, \
295 1),\
296 0, curLineString, isHandled)
297
298#define addSysCmd(sll,sl)(SrcLine_listPointer->NConcat) ((sll),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
listNConcat(SrcLine)(SrcLine_listPointer->NConcat)\
299 ((sll),listCons(SrcLine)(SrcLine_listPointer->Cons)(sl, listNil(SrcLine)((SrcLineList) 0)))
300
301#define botchSysCmd(kind)(SrcLine_listPointer->NConcat) ((inclError(42, kind)),(SrcLine_listPointer
->Cons)(slineNewSysCmd(sposNew(fileState.curFname, fileState
.lineNumber, inclSerialLineNo, 1), 0, curLineString, 1), ((SrcLineList
) 0)))
addSysCmd(inclError(ALDOR_E_SysCmdBad, kind), \(SrcLine_listPointer->NConcat) ((inclError(42, kind)),(SrcLine_listPointer
->Cons)(slineNewSysCmd(sposNew(fileState.curFname, fileState
.lineNumber, inclSerialLineNo, 1), 0, curLineString, 1), ((SrcLineList
) 0)))
302 SysCmdLine(true))(SrcLine_listPointer->NConcat) ((inclError(42, kind)),(SrcLine_listPointer
->Cons)(slineNewSysCmd(sposNew(fileState.curFname, fileState
.lineNumber, inclSerialLineNo, 1), 0, curLineString, 1), ((SrcLineList
) 0)))
303
304#define isThisEndifLine(sll)(sll && (sll == EndifLine || (((SrcLine_listPointer->
LastCons)(sll))->first)->isEndifLine))
(sll && \
305 (sll == EndifLine || car(listLastCons(SrcLine)(sll))(((SrcLine_listPointer->LastCons)(sll))->first)->isEndifLine))
306
307
308localstatic SrcLineList
309inclFile(String fname, Bool reincluding, Bool top, long *pnlines)
310{
311 Scope("inclFile")String scopeName = ("inclFile"); int fluidLevel0 = (scopeLevel
++, fluidLevel)
;
312
313 SrcLineList sll;
314 Hash fhash;
315 FileName fn;
316 FileState o_fileState;
317 IfState fluid(ifState)fluidSave_ifState = ( fluidStack = (fluidLevel==fluidLimit) ?
fluidGrow() : fluidStack, fluidStack[fluidLevel].scopeName =
scopeName, fluidStack[fluidLevel].scopeLevel = scopeLevel, fluidStack
[fluidLevel].pglobal = (Pointer) &(ifState), fluidStack[fluidLevel
].pstack = (Pointer) &fluidSave_ifState, fluidStack[fluidLevel
].size = sizeof(ifState), fluidLevel++, (ifState) )
;
318 String curdir;
319
320 o_fileState = fileState; /* no fluid(struct) */
321 ifState = NoIf;
322 fileState.lineNumber = 0;
323
324 fn = inclFind(fname, fileState.curDir);
325
326 if (fn != 0) {
327 fileState.curDir = strCopy(fnameDir(fn)((fn)->partv[0]));
328 fileState.curFile = strCopy(fnameUnparseStatic(fn));
329 fileState.curFname = fn;
330 }
331 curdir = fileState.curDir;
332
333 if (fn == 0) {
334 fileState = o_fileState;
335 if (top) {
336 comsgFatal(NULL((void*)0), ALDOR_F_CantOpen358, fname);
337 NotReached(sll = 0){(void)bug("Not supposed to reach line %d in file: %s\n",337,
"include.c");}
;
338 }
339 else
340 sll = inclError(ALDOR_F_CantOpen358, fname);
341 }
342 else {
343 fhash = fileHash(fn);
344 fname = strCopy (fnameUnparseStatic(fn));
345
346 if (!reincluding && listMemq(Hash)(Hash_listPointer->Memq)(includedFileCodes, fhash)) {
347 sll = listNil(SrcLine)((SrcLineList) 0);
348 }
349 else if (listMemq(Hash)(Hash_listPointer->Memq)(fileState.fileCodes, fhash)) {
350 String s = inclActiveFileChain
351 (fileState.fileNames, "->");
352 fileState = o_fileState;
353 sll = inclError(ALDOR_E_InclInfinite34, s);
354 strFree(s);
355 }
356 else {
357 includedFileCodes =
358 listCons(Hash)(Hash_listPointer->Cons) (fhash,includedFileCodes);
359 fileState.fileCodes =
360 listCons(Hash)(Hash_listPointer->Cons) (fhash,fileState.fileCodes);
361 fileState.fileNames =
362 listCons(String)(String_listPointer->Cons)(fname,fileState.fileNames);
363 fileState.infile = fileRdOpen(fn)fileMustOpen(fn,osIoRdMode);
364
365 sll = inclFileContents();
366
367 listFreeCons(Hash)(Hash_listPointer->FreeCons) (fileState.fileCodes);
368 listFreeCons(String)(String_listPointer->FreeCons)(fileState.fileNames);
369 fclose(fileState.infile);
370 }
371 fnameFree(fn);
372 strFree(curdir);
373 /*!! curFile is used in src lines */
374 strFree(fname);
375 }
376 if (pnlines) *pnlines = fileState.lineNumber;
377 fileState = o_fileState;
378 Return(sll){ fluidUnwind(fluidLevel0, ((int) 0)); return sll;; };
379}
380
381/*
382 * Open a file, looking first in the current directory, then
383 * in the list of include directories.
384 */
385localstatic FileName
386inclFind(String fname, String curdir)
387{
388 StringList dl;
389 FileName fn;
390
391 dl = listCons(String)(String_listPointer->Cons)(curdir, incSearchPath());
392 fn = fileRdFind(dl, fname, FTYPE_SRC"as");
393 listFreeCons(String)(String_listPointer->FreeCons)(dl);
394 return fn;
395}
396
397/*
398 * Conses (reversed) lines for the file.
399 */
400localstatic SrcLineList
401inclFileContents(void)
402{
403 SrcLineList sll = listNil(SrcLine)((SrcLineList) 0);
404
405 while (inclLine(&sll, (InclIsContinuedFun) NULL((void*)0)))
406 ;
407
408 return sll;
409}
410
411/*
412 * Decide whether the line is an include or system command directive.
413 */
414localstatic Bool
415inclIsDirective(String line)
416{
417 return *line == DIRECTIVE_CHAR'#';
418}
419
420/*
421 * Conses (reversed) lines which arise from "including" this one line.
422 * Returns true if there may be more.
423 */
424localstatic Bool
425inclLine(SrcLineList *psll, InclIsContinuedFun isCont)
426{
427 int indent;
428 String s;
429 SrcLine sl;
430 SrcPos spos;
431 SrcLineList d_sll;
432
433 do {
434 curLineString = inclGetLine(fileState.infile);
435 if (!curLineString) {
436 if (ifState != NoIf)
437 *psll = listNConcat(SrcLine)(SrcLine_listPointer->NConcat)
438 (inclError(ALDOR_E_InclIfEof33), *psll);
439 return false((int) 0);
440 }
441 fileState.lineNumber++;
442 inclSerialLineNo++;
443 if (inclIsDirective(curLineString)) {
444 /*!! This may be too costly with deep nesting. */
445 d_sll = inclHandleDirective();
446 if (isThisEndifLine(d_sll)(d_sll && (d_sll == EndifLine || (((SrcLine_listPointer
->LastCons)(d_sll))->first)->isEndifLine))
) {
447 if (d_sll == EndifLine) return false((int) 0);
448 *psll = listNConcat(SrcLine)(SrcLine_listPointer->NConcat)(d_sll, *psll);
449 return false((int) 0);
450 }
451 *psll = listNConcat(SrcLine)(SrcLine_listPointer->NConcat)(d_sll, *psll);
452 }
453 else if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
454 s = inclCalcIndentLevel(curLineString, &indent);
455 spos = sposNew(fileState.curFname, fileState.lineNumber,
456 inclSerialLineNo, 1);
457 sl = slineNew(spos, indent, s);
458 *psll = listCons(SrcLine)(SrcLine_listPointer->Cons)(sl, *psll);
459 }
460
461 } while (isCont && (*isCont)(curLineString));
462
463 return true1;
464}
465
466localstatic SrcLineList
467inclError(Msg msg, ...)
468{
469 SrcPos spos;
470 va_list argp;
471
472 spos = sposNew(fileState.curFname,
473 fileState.lineNumber,
474 inclSerialLineNo,
475 1);
476
477 va_start(argp, msg)__builtin_va_start(argp, msg);
478 comsgVError(abNewNothing(spos)abNew(AB_Nothing, spos,0 ), msg, argp);
479 va_end(argp)__builtin_va_end(argp);
480
481 return listNil(SrcLine)((SrcLineList) 0);
482}
483
484/******************************************************************************
485 *
486 * :: Handle includer directives such as ")include file", etc.
487 *
488 *****************************************************************************/
489
490localstatic SrcLineList inclHandleReinclude (String fname);
491localstatic SrcLineList inclHandleInclude (String fname);
492localstatic SrcLineList inclHandleIncludeDir (String dname);
493localstatic SrcLineList inclHandleAssert (String property);
494localstatic SrcLineList inclHandleUnassert (String property);
495localstatic SrcLineList inclHandleIf (String property);
496localstatic SrcLineList inclHandleElseif (String property);
497localstatic SrcLineList inclHandleElse (void);
498localstatic SrcLineList inclHandleEndif (void);
499localstatic SrcLineList inclHandleLine (int lno, String fname);
500localstatic SrcLineList inclHandleUnknown (void);
501
502localstatic SrcLineList
503inclHandleDirective(void)
504{
505 String s, s0, fname, property;
506 int lno;
507
508 s = s0 = curLineString;
509
510 if ((s = scmdIsDirective(s0,"include")) != 0) {
511 if (!scmdScanFName(s, &fname)) return botchSysCmd("include")(SrcLine_listPointer->NConcat) ((inclError(42, "include"))
,(SrcLine_listPointer->Cons)(slineNewSysCmd(sposNew(fileState
.curFname, fileState.lineNumber, inclSerialLineNo, 1), 0, curLineString
, 1), ((SrcLineList) 0)))
;
512 return inclHandleInclude(fname);
513 }
514 if ((s = scmdIsDirective(s0,"reinclude")) != 0) {
515 if (!scmdScanFName(s, &fname)) return botchSysCmd("reinclude")(SrcLine_listPointer->NConcat) ((inclError(42, "reinclude"
)),(SrcLine_listPointer->Cons)(slineNewSysCmd(sposNew(fileState
.curFname, fileState.lineNumber, inclSerialLineNo, 1), 0, curLineString
, 1), ((SrcLineList) 0)))
;
516 return inclHandleReinclude(fname);
517 }
518 if ((s = scmdIsDirective(s0,"includeDir")) != 0) {
519 if (!scmdScanFName(s, &fname)) return botchSysCmd("includeDir")(SrcLine_listPointer->NConcat) ((inclError(42, "includeDir"
)),(SrcLine_listPointer->Cons)(slineNewSysCmd(sposNew(fileState
.curFname, fileState.lineNumber, inclSerialLineNo, 1), 0, curLineString
, 1), ((SrcLineList) 0)))
;
520 return inclHandleIncludeDir(fname);
521 }
522 if ((s = scmdIsDirective(s0,"assert")) != 0) {
523 if (!scmdScanId(s, &property)) return botchSysCmd("assert")(SrcLine_listPointer->NConcat) ((inclError(42, "assert")),
(SrcLine_listPointer->Cons)(slineNewSysCmd(sposNew(fileState
.curFname, fileState.lineNumber, inclSerialLineNo, 1), 0, curLineString
, 1), ((SrcLineList) 0)))
;
524 return inclHandleAssert(property);
525 }
526 if ((s = scmdIsDirective(s0,"unassert")) != 0) {
527 if (!scmdScanId(s, &property)) return botchSysCmd("unassert")(SrcLine_listPointer->NConcat) ((inclError(42, "unassert")
),(SrcLine_listPointer->Cons)(slineNewSysCmd(sposNew(fileState
.curFname, fileState.lineNumber, inclSerialLineNo, 1), 0, curLineString
, 1), ((SrcLineList) 0)))
;
528 return inclHandleUnassert(property);
529 }
530 if ((s = scmdIsDirective(s0,"if")) != 0) {
531 if (!scmdScanId(s, &property)) return botchSysCmd("if")(SrcLine_listPointer->NConcat) ((inclError(42, "if")),(SrcLine_listPointer
->Cons)(slineNewSysCmd(sposNew(fileState.curFname, fileState
.lineNumber, inclSerialLineNo, 1), 0, curLineString, 1), ((SrcLineList
) 0)))
;
532 return inclHandleIf(property);
533 }
534 if ((s = scmdIsDirective(s0,"elseif")) != 0) {
535 if (!scmdScanId(s, &property)) return botchSysCmd("elseif")(SrcLine_listPointer->NConcat) ((inclError(42, "elseif")),
(SrcLine_listPointer->Cons)(slineNewSysCmd(sposNew(fileState
.curFname, fileState.lineNumber, inclSerialLineNo, 1), 0, curLineString
, 1), ((SrcLineList) 0)))
;
536 return inclHandleElseif(property);
537 }
538 if ((s = scmdIsDirective(s0,"endif")) != 0) {
539 return inclHandleEndif();
540 }
541 if ((s = scmdIsDirective(s0,"else")) != 0) {
Although the value stored to 's' is used in the enclosing expression, the value is never actually read from 's'
542 return inclHandleElse();
543 }
544 if ((s = scmdIsDirective(s0,"line")) != 0) {
545 if ((s = scmdScanInteger(s, &lno)) == 0)
546 return botchSysCmd("line")(SrcLine_listPointer->NConcat) ((inclError(42, "line")),(SrcLine_listPointer
->Cons)(slineNewSysCmd(sposNew(fileState.curFname, fileState
.lineNumber, inclSerialLineNo, 1), 0, curLineString, 1), ((SrcLineList
) 0)))
;
547 if (!scmdScanFName(s, &fname)) fname = 0;
548 return inclHandleLine(lno, fname);
549 }
550
551 return inclHandleUnknown();
552}
553
554/*
555 * Handle the include directive if we are in an active section
556 */
557localstatic SrcLineList
558inclHandleReinclude(String fname)
559{
560 if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
561 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
562 return addSysCmd(inclFile(fname, true, false, NULL), sl)(SrcLine_listPointer->NConcat) ((inclFile(fname, 1, ((int)
0), ((void*)0))),(SrcLine_listPointer->Cons)(sl, ((SrcLineList
) 0)))
;
563 }
564 return listNil(SrcLine)((SrcLineList) 0);
565}
566
567/*
568 * Handle the include directive if we are in an active section
569 */
570localstatic SrcLineList
571inclHandleInclude(String fname)
572{
573 if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
574 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
575 return addSysCmd(inclFile(fname, false, false, NULL), sl)(SrcLine_listPointer->NConcat) ((inclFile(fname, ((int) 0)
, ((int) 0), ((void*)0))),(SrcLine_listPointer->Cons)(sl, (
(SrcLineList) 0)))
;
576 }
577 return listNil(SrcLine)((SrcLineList) 0);
578}
579
580localstatic SrcLineList
581inclHandleIncludeDir(String dname)
582{
583 if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
584 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
585 if (scmdHandleIncludeDir(dname) == -1)
586 return botchSysCmd("includeDir")(SrcLine_listPointer->NConcat) ((inclError(42, "includeDir"
)),(SrcLine_listPointer->Cons)(slineNewSysCmd(sposNew(fileState
.curFname, fileState.lineNumber, inclSerialLineNo, 1), 0, curLineString
, 1), ((SrcLineList) 0)))
;
587 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
588 }
589 return listNil(SrcLine)((SrcLineList) 0);
590}
591
592localstatic SrcLineList
593inclHandleAssert(String property)
594{
595 if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
596 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
597 INCL_Assert(&localAssertList, property)(*(&localAssertList)=(String_listPointer->Cons)((property
), *(&localAssertList)))
;
598 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
599 }
600 return listNil(SrcLine)((SrcLineList) 0);
601}
602
603localstatic SrcLineList
604inclHandleUnassert(String property)
605{
606 if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
607 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
608 INCL_Unassert(&localAssertList, property)(*(&localAssertList)=(String_listPointer->NRemove)(*(&
localAssertList),(property),strEqual))
;
609 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
610 }
611 return listNil(SrcLine)((SrcLineList) 0);
612}
613
614localstatic SrcLineList
615inclHandleIf(String property)
616{
617 Scope("inclHandleIf")String scopeName = ("inclHandleIf"); int fluidLevel0 = (scopeLevel
++, fluidLevel)
;
618
619 IfState fluid(ifState)fluidSave_ifState = ( fluidStack = (fluidLevel==fluidLimit) ?
fluidGrow() : fluidStack, fluidStack[fluidLevel].scopeName =
scopeName, fluidStack[fluidLevel].scopeLevel = scopeLevel, fluidStack
[fluidLevel].pglobal = (Pointer) &(ifState), fluidStack[fluidLevel
].pstack = (Pointer) &fluidSave_ifState, fluidStack[fluidLevel
].size = sizeof(ifState), fluidLevel++, (ifState) )
;
620 SrcLineList result = listNil(SrcLine)((SrcLineList) 0);
621
622 if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
623 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
624
625 if (INCL_IsAssert(&localAssertList, property)((String_listPointer->Member)(*(&localAssertList), (property
), strEqual))
) {
626 ifState = ActiveIf;
627 result = addSysCmd(inclFileContents(),sl)(SrcLine_listPointer->NConcat) ((inclFileContents()),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
628 }
629 else {
630 ifState = InactiveIf;
631 result = addSysCmd(inclFileContents(),sl)(SrcLine_listPointer->NConcat) ((inclFileContents()),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
632 }
633 }
634 else {
635 ifState = FormerlyActiveIf;
636 result = inclFileContents();
637 }
638 Return(result){ fluidUnwind(fluidLevel0, ((int) 0)); return result;; };
639}
640
641localstatic SrcLineList
642inclHandleElseif(String property)
643{
644 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
645 if (ifState == NoIf)
646 return addSysCmd(inclError(ALDOR_E_InclUnbalElseif), sl)(SrcLine_listPointer->NConcat) ((inclError(36)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
647 if (ifState == InactiveIf) {
648 if (INCL_IsAssert(&localAssertList, property)((String_listPointer->Member)(*(&localAssertList), (property
), strEqual))
)
649 ifState = ActiveIf;
650 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
651 }
652 else {
653 if (ifState == ActiveIf) {
654 ifState = FormerlyActiveIf;
655 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
656 }
657 ifState = FormerlyActiveIf;
658 }
659 return listNil(SrcLine)((SrcLineList) 0);
660}
661
662localstatic SrcLineList
663inclHandleElse(void)
664{
665 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
666 if (ifState == NoIf)
667 return addSysCmd(inclError(ALDOR_E_InclUnbalElse), sl)(SrcLine_listPointer->NConcat) ((inclError(35)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
668 else if (ifState == ActiveIf) {
669 ifState = InactiveIf;
670 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
671 }
672 else if (ifState == InactiveIf) {
673 ifState = ActiveIf;
674 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
675 }
676 return listNil(SrcLine)((SrcLineList) 0);
677}
678
679localstatic SrcLineList
680inclHandleEndif(void)
681{
682 SrcLine sl = SysCmdLine(true)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, 1)
;
683 sl->isEndifLine = true1;
684 if (ifState == NoIf)
685 return addSysCmd(inclError(ALDOR_E_InclUnbalEndif), sl)(SrcLine_listPointer->NConcat) ((inclError(37)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
686 if (ifState == ActiveIf || ifState == InactiveIf)
687 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
688 return EndifLine;
689}
690
691localstatic SrcLineList
692inclHandleLine(int lno, String fname)
693{
694 if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
695
696 fileState.lineNumber = lno - 1; /* The next line is 'lno' */
697
698 if (fname) {
699 fileState.curFile = fname;
700 /* rhx: We trust the programmer of the #line statement
701 in the .as file that the filename is correct.
702 If in an error case the file cannot be found the
703 compiler aborts with a (Fatal Error) message.
704
705 #1 (Fatal Error) Could not open file `dir/file.ext' with mode `r'.
706
707 It would actually be very helpful for a
708 programmer if we could abort the compilation
709 already here with an error message saying that
710 the filename appearing in the #line directive
711 cannot be found.
712 */
713 fileState.curFname = fnameParse(fname);
714 }
715 sposGrowGloLineTbl(fileState.curFname, fileState.lineNumber,
716 inclSerialLineNo);
717
718
719 return listNil(SrcLine)((SrcLineList) 0);
720 }
721 return listNil(SrcLine)((SrcLineList) 0);
722}
723
724localstatic SrcLineList
725inclHandleUnknown(void)
726{
727 if (INCLUDING(ifState)((ifState)==NoIf || (ifState)==ActiveIf)) {
728 SrcLine sl = SysCmdLine(false)slineNewSysCmd(sposNew(fileState.curFname, fileState.lineNumber
, inclSerialLineNo, 1), 0, curLineString, ((int) 0))
;
729 return addSysCmd(listNil(SrcLine), sl)(SrcLine_listPointer->NConcat) ((((SrcLineList) 0)),(SrcLine_listPointer
->Cons)(sl, ((SrcLineList) 0)))
;
730 }
731 else {
732 SrcPos spos = sposNew(fileState.curFname,
733 fileState.lineNumber,
734 inclSerialLineNo,
735 1);
736 scmdCheck(spos, curLineString);
737 }
738 return listNil(SrcLine)((SrcLineList) 0);
739}
740
741/******************************************************************************
742 *
743 * :: General Utilities
744 *
745 ****************************************************************************/
746
747localstatic String
748inclCalcIndentLevel(String ln, int *indent)
749{
750 String s;
751 int i;
752 for (s = ln, i = 0; ; s++) {
753 if (*s == ' ')
754 i++;
755 else if (*s == '\t') {
756 if (i % TABSTOP8 == 0) i += TABSTOP8;
757 else i = ROUND_UP(i, TABSTOP)((i) % (8) ? (i) + (8) - (i) % (8) : (i));
758 }
759 else
760 break;
761 }
762 *indent = i;
763 return s;
764}
765
766
767localstatic String
768inclGetLine(FILE *file)
769{
770 int c;
771 String s;
772
773 bufStart(inclBuffer);
774 while ((c = osGetc(file)) != EOF(-1)) {
775 bufAdd1(inclBuffer, c);
776 if (c == '\n') break;
777 }
778 bufAdd1(inclBuffer, char0((char) 0));
779
780 s = bufChars(inclBuffer);
781 if (c == EOF(-1) && *s == 0) return 0;
782 return s;
783}
784
785/*
786 * Given the list fnames [z,...,b,a] and punct "->",
787 * allocate the string "'a'->'b'->...->'z'".
788 */
789localstatic String
790inclActiveFileChain(StringList fnames, String punct)
791{
792 StringList sl0, sl;
793 Buffer buf;
794 String s;
795 int i;
796
797 buf = bufNew();
798 sl0 = listReverse(String)(String_listPointer->Reverse)(fnames);
799
800 for (sl = sl0, i = 0; sl; sl = cdr(sl)((sl)->rest), i++) {
801 if (i > 0) bufPuts(buf, punct);
802 bufPrintf(buf, "'%s'", car(sl)((sl)->first));
803 }
804 s = bufLiberate(buf);
805 listFree(String)(String_listPointer->Free)(sl0);
806
807 return s;
808}