/*
** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** Copyright (C) 1994-2003 University of Virginia,
** Massachusetts Institute of Technology
**
** This program is free software; you can redistribute it and/or modify it
# include <time.h>
# else
# ifndef VMS
-# ifndef USG
+/*
+** evans 2002-07-03: exception for WATCOM 10.6 compiler suggest by Adam Clarke
+*/
+# if !defined (USG) && !defined (__WATCOMC__)
# include <time.h> /* Reported by Paul Smith */
# include <sys/time.h>
# include <sys/resource.h>
# include <errno.h>
# include "splintMacros.nf"
-# include "llbasic.h"
+# include "basic.h"
# include "lcllib.h"
# include "cpplib.h"
# include "cpperror.h"
# include "cpphash.h"
# include "cppexp.h"
# include "version.h"
-# include "portab.h"
# include "osd.h"
/*
/*@+boolint@*/
/*@+charint@*/
+/* Warnings for using sprintf - suppress them all for now... */
+/*@-bufferoverflowhigh@*/
+/*@-bounds@*/
+
#define NO_SHORTNAMES
# ifdef open
# define cppBuffer_get(BUFFER) \
((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur++ : EOF)
+/*@function static int cppBuffer_reachedEOF (sef cppBuffer *p_b) modifies nothing; @*/
+# define cppBuffer_reachedEOF(b) \
+ ((b)->cur < (b)->rlimit ? FALSE : TRUE)
+
/* Append string STR (of length N) to PFILE's output buffer. Make space. */
/*@function static void cppReader_puts (sef cppReader *p_file, char *p_str, sef size_t p_n)
modifies *p_file; @*/
/*@function static void cppReader_putCharQ (cppReader *p_file, char p_ch)
modifies *p_file; @*/
# define cppReader_putCharQ(PFILE, CH) (*(PFILE)->limit++ = (CH))
-
+/*
+static void cppReader_putCharQ (cppReader *p_file, char p_ch)
+{
+ fprintf (stderr, "put char: %c\n", p_ch);
+ (*(p_file)->limit++ = (p_ch));
+}
+*/
/* Append character CH to PFILE's output buffer. Make space if need be. */
/*@function static void cppReader_putChar (sef cppReader *p_file, char p_ch)
/*@function static int cppReader_getC (cppReader *p_pfile) modifies *p_pfile; @*/
# define cppReader_getC(pfile) (cppBuffer_get (cppReader_getBufferSafe (pfile)))
+/*@function static int cppReader_reachedEOF (sef cppReader *p_pfile) modifies *p_pfile; @*/
+# define cppReader_reachedEOF(pfile) (cppBuffer_reachedEOF (cppReader_getBufferSafe (pfile)))
+
/*@function static int cppReader_peekC (cppReader *) modifies nothing;@*/
# define cppReader_peekC(pfile) (cpplib_bufPeek (cppReader_getBufferSafe (pfile)))
opts->first_bracket_include = first;
for (dir = first; ; dir = dir->next) {
- int len = cstring_length (dir->fname) + INCLUDE_LEN_FUDGE;
+ size_t len = cstring_length (dir->fname) + INCLUDE_LEN_FUDGE;
+
if (len > pfile->max_include_len)
- pfile->max_include_len = len;
+ {
+ pfile->max_include_len = len;
+ }
+
if (dir == last)
- break;
+ {
+ break;
+ }
}
}
}
void
-cppReader_addIncludeChain (cppReader *pfile, struct file_name_list *dir)
+cppReader_addIncludeChain (cppReader *pfile, /*@only@*/ struct file_name_list *dir)
{
struct cppOptions *opts = CPPOPTIONS (pfile);
- if (dir == 0)
+ if (dir == NULL)
{
return;
}
if (opts->first_bracket_include == 0)
{
- int len = cstring_length (dir->fname) + INCLUDE_LEN_FUDGE;
+ size_t len = cstring_length (dir->fname) + INCLUDE_LEN_FUDGE;
opts->first_bracket_include = dir;
+
if (len > pfile->max_include_len)
{
pfile->max_include_len = len;
opts->warn_comments = 0;
opts->warnings_are_errors = 0;
+ /* Added 2003-07-10: */
+ opts->traditional = FALSE;
+ opts->c89 = TRUE;
initialize_char_syntax (opts);
}
void
cppReader_nullCleanup (/*@unused@*/ cppBuffer *pbuf,
- /*@unused@*/ cppReader *pfile)
+ /*@unused@*/ cppReader *pfile)
{
;
}
llassert (pfile->buffer != NULL);
c = cppReader_getC (pfile);
+
switch (c)
{
case EOF:
** Patch from Brian St. Pierre for handling MS-DOS files.
*/
+ DPRINTF (("Reading directive: %d", (int) c));
+
if (cppReader_peekC (pfile) == '\n'
|| cppReader_peekC (pfile) == '\r')
{
+ DPRINTF (("Reading directive..."));
if (cppReader_peekC (pfile) == '\r')
{
+ DPRINTF (("Reading directive..."));
cppReader_forward (pfile, 1);
}
+ DPRINTF (("Reading directive..."));
cppReader_forward (pfile, 1);
continue;
}
+ DPRINTF (("Falling..."));
/*@fallthrough@*/ case '\'': case '\"':
goto scan_directive_token;
if (!is_idstart[(int) *bp])
{
cppReader_pedwarnLit (pfile,
- cstring_makeLiteralTemp ("invalid character in macro parameter name"));
+ cstring_makeLiteralTemp ("Invalid character in macro parameter name"));
}
/* Find the end of the arg name. */
if (a1 != a2)
return TRUE;
- if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
- p2, d2->length - (p2 - d2->expansion), 1))
+ if (comp_def_part (first, p1, size_toInt (d1->length - (p1 - d1->expansion)),
+ p2, size_toInt (d2->length - (p2 - d2->expansion)), 1))
return TRUE;
return FALSE;
}
-/* Return TRUE if two parts of two macro definitions are effectively different.
- One of the parts starts at BEG1 and has LEN1 chars;
- the other has LEN2 chars at BEG2.
- Any sequence of whitespace matches any other sequence of whitespace.
- FIRST means these parts are the first of a macro definition;
- so ignore leading whitespace entirely.
- LAST means these parts are the last of a macro definition;
- so ignore trailing whitespace entirely. */
- /*@i2@*/
+/*
+** Return TRUE if two parts of two macro definitions are effectively different.
+** One of the parts starts at BEG1 and has LEN1 chars;
+** the other has LEN2 chars at BEG2.
+** Any sequence of whitespace matches any other sequence of whitespace.
+** FIRST means these parts are the first of a macro definition;
+** so ignore leading whitespace entirely.
+** LAST means these parts are the last of a macro definition;
+** so ignore trailing whitespace entirely.
+*/
+
static bool
comp_def_part (bool first, char *beg1, int len1, char *beg2, int len2, bool last)
{
return (beg1 != end1) || (beg2 != end2);
}
-/* Process a #define command.
- BUF points to the contents of the #define command, as a contiguous string.
- LIMIT points to the first character past the end of the definition.
- KEYWORD is the keyword-table entry for #define,
- or NULL for a "predefined" macro. */
- /*@i2@*/
+/*
+** Process a #define command.
+** BUF points to the contents of the #define command, as a contiguous string.
+** LIMIT points to the first character past the end of the definition.
+** KEYWORD is the keyword-table entry for #define,
+** or NULL for a "predefined" macro.
+*/
+
static int
do_defineAux (cppReader *pfile, struct directive *keyword,
/*@exposed@*/ char *buf, char *limit, bool noExpand)
int hashcode;
macroDef mdef;
hashNode hp;
- /*@i2@*/
- DPRINTF (("Define aux: %d", noExpand));
- /*@i2@*/
+
mdef = create_definition (buf, limit, pfile, keyword == NULL, noExpand);
if (mdef.defn == 0)
goto nope;
- /*@i2@*/
+
hashcode = cpphash_hashCode (mdef.symnam, mdef.symlen, CPP_HASHSIZE);
- /*@i2@*/
- DPRINTF (("Macro: %s / %s",
- cstring_copyLength (mdef.symnam, mdef.symlen),
- bool_unparse (noExpand)));
- /*@i2@*/
+
if ((hp = cpphash_lookup (mdef.symnam, size_toInt (mdef.symlen), hashcode)) != NULL)
{
bool ok = FALSE;
else {
BADBRANCH;
}
- /*@i2@*/
+
/* Print the warning if it's not ok. */
if (!ok)
{
}
cpp_setLocation (pfile);
- /*@i2@*/
+
if (hp->type == T_MACRO)
{
if (hp->value.defn->noExpand)
message ("Macro %q already defined",
cstring_copyLength (mdef.symnam,
mdef.symlen)));
- /*@i2@*/
}
}
*/
hashNode hn;
- /*@i2@*/
+
if (CPPOPTIONS (pfile)->debug_output && (keyword != NULL))
{
pass_thru_directive (buf, limit, pfile, keyword);
} /*@=branchstate@*/
return 0;
- /*@i2@*/
+
nope:
- /*@i2@*/
return 1;
}
DPRINTF (("Regular do define"));
return do_defineAux (pfile, keyword, buf, limit, FALSE);
}
- /*@i2@*/
-/* This structure represents one parsed argument in a macro call.
- `raw' points to the argument text as written (`raw_length' is its length).
- `expanded' points to the argument's macro-expansion
- (its length is `expand_length').
- `stringified_length' is the length the argument would have
- if stringified.
- `use_count' is the number of times this macro arg is substituted
- into the macro. If the actual use count exceeds 10,
- the value stored is 10. */
- /*@i2@*/
+
+/*
+** This structure represents one parsed argument in a macro call.
+** `raw' points to the argument text as written (`raw_length' is its length).
+** `expanded' points to the argument's macro-expansion
+** (its length is `expand_length').
+** `stringified_length' is the length the argument would have
+** if stringified.
+** `use_count' is the number of times this macro arg is substituted
+** into the macro. If the actual use count exceeds 10,
+** the value stored is 10.
+*/
+
/* raw and expanded are relative to ARG_BASE */
/*@notfunction@*/
#define ARG_BASE ((pfile)->token_buffer)
- /*@i2@*/
+
struct argdata {
/* Strings relative to pfile->token_buffer */
long raw;
int use_count;
};
-/* Allocate a new cppBuffer for PFILE, and push it on the input buffer stack.
- If BUFFER != NULL, then use the LENGTH characters in BUFFER
- as the new input buffer.
- Return the new buffer, or NULL on failure. */
- /*@i2@*/
+/*
+** Allocate a new cppBuffer for PFILE, and push it on the input buffer stack.
+** If BUFFER != NULL, then use the LENGTH characters in BUFFER
+** as the new input buffer.
+** Return the new buffer, or NULL on failure.
+*/
+
/*@null@*/ /*@exposed@*/ cppBuffer *
cppReader_pushBuffer (cppReader *pfile, char *buffer, size_t length)
{
buf--;
memset ((char *) buf, 0, sizeof (*buf));
+ DPRINTF (("Pushing buffer: %s", cstring_copyLength (buffer, length)));
CPPBUFFER (pfile) = buf;
buf->if_stack = pfile->if_stack;
return buf;
}
- /*@i2@*/
+
cppBuffer *
cppReader_popBuffer (cppReader *pfile)
{
return ++CPPBUFFER (pfile);
}
-/* Scan until CPPBUFFER (PFILE) is exhausted into PFILE->token_buffer.
- Pop the buffer when done. */
- /*@i2@*/
+/*
+** Scan until CPPBUFFER (PFILE) is exhausted into PFILE->token_buffer.
+** Pop the buffer when done.
+*/
+
void
cppReader_scanBuffer (cppReader *pfile)
{
}
}
}
- /*@i2@*/
/*
* Rescan a string (which may have escape marks) into pfile's buffer.
char *limit = buf + length;
char *buf1, *p1, *p2;
+ DPRINTF (("Expand to buffer: %s", cstring_copyLength (buf, length)));
+
/* evans - 2001-08-26
** length is unsigned - this doesn't make sense
if (length < 0)
void
cppBuffer_getLineAndColumn (/*@null@*/ cppBuffer *pbuf, /*@out@*/ int *linep,
- /*@null@*/ /*@out@*/ int *colp)
+ /*@null@*/ /*@out@*/ int *colp)
{
int dummy;
}
}
- cpplib_reserve (pfile,
- size_fromInt (4 * cstring_length (ip->nominal_fname) + 50));
+ cpplib_reserve (pfile, 4 * cstring_length (ip->nominal_fname) + 50);
{
#ifdef OUTPUT_LINE_COMMANDS
quote_string (pfile, string);
return;
}
+ case T_FUNC: /* added in ISO C99 */
+ {
+ /* We don't know the actual name of the function, but it doesn't matter */
+ char *string = "** function-name **";
+ cpplib_reserve (pfile, 3 + 4 * strlen (string));
+ quote_string (pfile, string);
+ return;
+ }
case T_INCLUDE_LEVEL:
true_indepth = 0;
if (!usymtab_existsTypeEither (sname))
{
uentry ue = uentry_makeDatatype (sname, ctyp,
- NO, NO,
+ NO, qual_createConcrete (),
fileloc_createBuiltin ());
llassert (!usymtab_existsEither (sname));
usymtab_addGlobalEntry (ue);
cpplib_installBuiltin ("__DATE__", ctype_string, -1, T_DATE, 0, NULL, -1);
cpplib_installBuiltin ("__FILE__", ctype_string, -1, T_FILE, 0, NULL, -1);
cpplib_installBuiltin ("__BASE_FILE__", ctype_string, -1, T_BASE_FILE, 0, NULL, -1);
+ cpplib_installBuiltin ("__func__", ctype_string, -1, T_FUNC, 0, NULL, -1);
cpplib_installBuiltin ("__INCLUDE_LEVEL__", ctype_int, -1, T_INCLUDE_LEVEL, 0, NULL, -1);
cpplib_installBuiltin ("__VERSION__", ctype_string, -1, T_VERSION, 0, NULL, -1);
#ifndef NO_BUILTIN_SIZE_TYPE
cpplib_installBuiltin ("__REGISTER_PREFIX__", ctype_string, -1, T_REGISTER_PREFIX_TYPE, 0, NULL, -1);
cpplib_installBuiltin ("__TIME__", ctype_string, -1, T_TIME, 0, NULL, -1);
- /*
- ** No, don't define __STDC__
- **
-
if (!cppReader_isTraditional (pfile))
{
cpplib_installBuiltin ("__STDC__", ctype_int, -1, T_CONST, STDC_VALUE, NULL, -1);
}
- **
- */
-
# ifdef WIN32
cpplib_installBuiltin ("_WIN32", ctype_int, -1, T_CONST, STDC_VALUE, NULL, -1);
# endif
args[i].raw = size_toLong (cpplib_getWritten (pfile));
token = macarg (pfile, rest_args);
- args[i].raw_length = cpplib_getWritten (pfile) - args[i].raw;
+ args[i].raw_length = size_toInt (cpplib_getWritten (pfile) - args[i].raw);
args[i].newlines = FALSE; /* FIXME */
}
else
cppBuffer_getLineAndColumn (cppReader_fileBuffer (pfile), &end_line, &end_column);
DPRINTF (("Expand macro: %d:%d", end_line, end_column));
-
+
/* If macro wants zero args, we parsed the arglist for checking only.
Read directly from the macro definition. */
}
else if (ap->raw_before || ap->raw_after || cppReader_isTraditional (pfile))
{
- /* Add 4 for two newline-space markers to prevent
- token concatenation. */
- assertSet (args); /*@i534 shouldn't need this */
+ /* Add 4 for two newline-space markers to prevent token concatenation. */
+ assertSet (args); /* Splint shouldn't need this */
xbuf_len += args[ap->argno].raw_length + 4;
}
else
/* We have an ordinary (expanded) occurrence of the arg.
So compute its expansion, if we have not already. */
- assertSet (args); /*@i534 shouldn't need this */
+ assertSet (args); /* shouldn't need this */
if (args[ap->argno].expand_length < 0)
{
/* Now put the expansion on the input stack
so our caller will commence reading from it. */
DPRINTF (("Pushing expansion: %s", cstring_copyLength (xbuf, xbuf_len)));
-
+
if (end_line != start_line)
{
/* xbuf must have enough newlines */
DPRINTF (("Pushing expansion: %s", cstring_copyLength (xbuf, xbuf_len)));
push_macro_expansion (pfile, xbuf, xbuf_len, hp);
+ DPRINTF (("After pushing expansion: %s", cstring_copyLength (xbuf, xbuf_len)));
cppReader_getBufferSafe (pfile)->has_escapes = 1;
/* Pop the space we've used in the token_buffer for argument expansion. */
cppReader_setWritten (pfile, old_written);
-
+ DPRINTF (("Done set written"));
+
/* Recursive macro use sometimes works traditionally.
#define foo(x,y) bar (x (y,0), y)
foo (foo, baz) */
|| xbuf[2] == '\"'))
{
llassert (mbuf->cur != NULL);
+ DPRINTF (("Eating: %c", xbuf[2]));
mbuf->cur += 2;
}
+
}
/*@=onlytrans@*/
nam[n] = save;
- if (n + INCLUDE_LEN_FUDGE > pfile->max_include_len)
- pfile->max_include_len = n + INCLUDE_LEN_FUDGE;
+ if (n + INCLUDE_LEN_FUDGE > size_toInt (pfile->max_include_len))
+ pfile->max_include_len = size_fromInt (n + INCLUDE_LEN_FUDGE);
}
else
{
if (f == IMPORT_FOUND)
{
- return 0; /* Already included this file */
+ return 0; /* Already included this file */
}
#ifdef EACCES
else if (f == IMPORT_NOT_FOUND && errno == EACCES)
if (start_of_file && !skip)
{
DPRINTF (("Not skipping!"));
- control_macro = (char *) dmalloc (size_fromInt (ident_length + 1));
- memcpy (control_macro, ident, size_fromInt (ident_length + 1));
+ control_macro = (char *) dmalloc (ident_length + 1);
+ memcpy (control_macro, ident, ident_length + 1);
}
}
else
cppBuffer_getLineAndColumn (cppReader_fileBuffer (pfile),
&start_line, &start_column);
c = skip_comment (pfile, &newlines);
-
+ DPRINTF (("c = %c", c));
if (opts->put_out_comments && (c == '/' || c == EOF))
{
assertSet (&start_mark);
&start_line, &start_column);
old_written = cpplib_getWritten (pfile);
string:
+ DPRINTF (("Reading string: %c", c));
cppReader_putChar (pfile, c);
while (TRUE)
{
- int cc = cppReader_getC (pfile);
- if (cc == EOF)
+ /* evans-2003-06-07
+ ** Because of ISO8859-1 characters in string literals, we need a special test here.
+ */
+
+ if (cppReader_reachedEOF (pfile))
{
+
+ DPRINTF (("Matches EOF!"));
if (cppBuffer_isMacro (CPPBUFFER (pfile)))
{
/* try harder: this string crosses a macro expansion
CPPBUFFER (pfile) = next_buf;
continue;
}
+
if (!cppReader_isTraditional (pfile))
{
cpp_setLocation (pfile);
setLine (long_toInt (start_line));
setColumn (long_toInt (start_column));
-
+
if (pfile->multiline_string_line != long_toInt (start_line)
&& pfile->multiline_string_line != 0)
{
message ("Unterminated string or character constant"));
}
}
- /*@loopbreak@*/ break;
- }
- cppReader_putChar (pfile, cc);
- switch (cc)
+ /*@loopbreak@*/ break;
+ }
+ else
{
- case '\n':
- /* Traditionally, end of line ends a string constant with
- no error. So exit the loop and record the new line. */
- if (cppReader_isTraditional (pfile))
- goto while2end;
- if (c == '\'')
- {
- goto while2end;
- }
- if (cppReader_isPedantic (pfile)
- && pfile->multiline_string_line == 0)
- {
- cppReader_pedwarnWithLine
- (pfile, long_toInt (start_line),
- long_toInt (start_column),
- cstring_makeLiteral ("String constant runs past end of line"));
- }
- if (pfile->multiline_string_line == 0)
+ int cc = cppReader_getC (pfile);
+ DPRINTF (("cc: %c [%d] [%d]", cc, cc, EOF));
+ DPRINTF (("putting char: %c", cc));
+ cppReader_putChar (pfile, cc);
+ switch (cc)
{
- pfile->multiline_string_line = start_line;
- }
-
- /*@switchbreak@*/ break;
-
- case '\\':
- cc = cppReader_getC (pfile);
- if (cc == '\n')
- {
- /* Backslash newline is replaced by nothing at all. */
- cppReader_adjustWritten (pfile, -1);
- pfile->lineno++;
- }
- else
- {
- /* ANSI stupidly requires that in \\ the second \
- is *not* prevented from combining with a newline. */
- NEWLINE_FIX1(cc);
- if (cc != EOF)
- cppReader_putChar (pfile, cc);
+ case '\n':
+ /* Traditionally, end of line ends a string constant with
+ no error. So exit the loop and record the new line. */
+ if (cppReader_isTraditional (pfile))
+ goto while2end;
+ if (c == '\'')
+ {
+ goto while2end;
+ }
+ if (cppReader_isPedantic (pfile)
+ && pfile->multiline_string_line == 0)
+ {
+ cppReader_pedwarnWithLine
+ (pfile, long_toInt (start_line),
+ long_toInt (start_column),
+ cstring_makeLiteral ("String constant runs past end of line"));
+ }
+ if (pfile->multiline_string_line == 0)
+ {
+ pfile->multiline_string_line = start_line;
+ }
+
+ /*@switchbreak@*/ break;
+
+ case '\\':
+ cc = cppReader_getC (pfile);
+ if (cc == '\n')
+ {
+ /* Backslash newline is replaced by nothing at all. */
+ cppReader_adjustWritten (pfile, -1);
+ pfile->lineno++;
+ }
+ else
+ {
+ /* ANSI stupidly requires that in \\ the second \
+ is *not* prevented from combining with a newline. */
+ NEWLINE_FIX1(cc);
+ if (cc != EOF)
+ cppReader_putChar (pfile, cc);
+ }
+ /*@switchbreak@*/ break;
+
+ case '\"':
+ case '\'':
+ if (cc == c)
+ goto while2end;
+ /*@switchbreak@*/ break;
}
- /*@switchbreak@*/ break;
-
- case '\"':
- case '\'':
- if (cc == c)
- goto while2end;
- /*@switchbreak@*/ break;
}
}
while2end:
return CPP_OTHER;
case '@':
+ DPRINTF (("Macro @!"));
if (cppReader_getBufferSafe (pfile)->has_escapes)
{
c = cppReader_getC (pfile);
+ DPRINTF (("got c: %c", c));
if (c == '-')
{
if (pfile->output_escapes)
struct parse_marker macro_mark;
int is_macro_call;
+ DPRINTF (("Arglist macro!"));
+
+ /*
+ ** evans 2002-07-03: Moved this here (from below).
+ ** This bug caused necessary whitespace to be lost
+ ** when parsing parameterized macros without parameters.
+ */
+
+ parseSetMark (¯o_mark, pfile);
+
while (cppBuffer_isMacro (CPPBUFFER (pfile)))
{
cppBuffer *next_buf;
cppSkipHspace (pfile);
if (cppReader_peekC (pfile) != EOF)
{
+ DPRINTF (("Peeking!"));
/*@loopbreak@*/ break;
}
CPPBUFFER (pfile) = next_buf;
}
- parseSetMark (¯o_mark, pfile);
+ /* parseSetMark (¯o_mark, pfile); */
for (;;)
{
cppSkipHspace (pfile);
c = cppReader_peekC (pfile);
+ DPRINTF (("c: %c", c));
is_macro_call = c == '(';
if (c != '\n')
/*@loopbreak@*/ break;
if (!is_macro_call)
{
+ DPRINTF (("not macro call!"));
return CPP_NAME;
}
}
+
/* This is now known to be a macro call. */
/* it might not actually be a macro. */
struct file_name_map_list
{
- struct file_name_map_list *map_list_next;
- cstring map_list_name;
+ /*@only@*/ struct file_name_map_list *map_list_next;
+ /*@only@*/ cstring map_list_name;
/*@null@*/ struct file_name_map *map_list_map;
};
else if (S_ISDIR (st_mode))
{
cppReader_error (pfile,
- message ("Directory specified in #include: %s", fname));
+ message ("Directory specified where file is expected: %s", fname));
check (close (f) == 0);
return 0;
}
This is the cppReader 'finalizer' or 'destructor' (in C++ terminology). */
void
-cppCleanup (cppReader *pfile)
+cppCleanup (/*@special@*/ cppReader *pfile)
+ /*@uses pfile@*/
+ /*@releases pfile@*/
{
+ DPRINTF (("cppCleanup!"));
+
while (CPPBUFFER (pfile) != cppReader_nullBuffer (pfile))
{
(void) cppReader_popBuffer (pfile);
sfree (temp);
}
+ /* evans 2002-07-12 */
+ while (pfile->opts->map_list != NULL)
+ {
+ struct file_name_map_list *temp = pfile->opts->map_list;
+ pfile->opts->map_list = pfile->opts->map_list->map_list_next;
+ cstring_free (temp->map_list_name);
+ sfree (temp);
+ }
+
+ while (pfile->opts->include != NULL)
+ {
+ struct file_name_list *temp = pfile->opts->include;
+ pfile->opts->include = pfile->opts->include->next;
+ /* cstring_free (temp->fname); */
+ sfree (temp);
+ }
+
+ sfree (pfile->opts);
+ pfile->opts = NULL;
cppReader_hashCleanup ();
}
pmark->buf = pbuf;
pmark->position = pbuf->cur - pbuf->buf;
+ DPRINTF (("set mark: %d / %s", pmark->position, pbuf->cur));
}
/* Cleanup PMARK - we no longer need it. */
llassert (pbuf->buf != NULL);
pbuf->cur = pbuf->buf + pmark->position;
+ DPRINTF (("goto mark: %d / %s", pmark->position, pbuf->cur));
}
/* Reset PMARK to point to the current position of PFILE. (Same
}
pmark->position = pbuf->cur - pbuf->buf;
+ DPRINTF (("move mark: %s", pmark->position));
}
void cpplib_initializeReader (cppReader *pfile) /* Must be done after library is loaded. */
cppReader_appendIncludeChain (pfile, opts->before_system,
opts->last_before_system);
+
opts->first_system_include = opts->before_system;
/* Unless -fnostdinc,
struct default_include *p = include_defaults;
char *specd_prefix = opts->include_prefix;
char *default_prefix = mstring_copy (GCC_INCLUDE_DIR);
- int default_len = 0;
+ size_t default_len = 0;
/* Remove the `include' from /usr/local/lib/gcc.../include. */
if (default_prefix != NULL) {
/* Does this dir start with the prefix? */
llassert (default_prefix != NULL);
- if (!strncmp (cstring_toCharsSafe (p->fname), default_prefix,
- size_fromInt (default_len)))
+ if (!strncmp (cstring_toCharsSafe (p->fname), default_prefix, default_len))
{
/* Yes; change prefix and add to search list. */
struct file_name_list *nlist
nlist->c_system_include_path = !p->cxx_aware;
nlist->got_name_map = 0;
- cppReader_addIncludeChain (pfile, nlist);
if (opts->first_system_include == 0)
{
opts->first_system_include = nlist;
}
+
+ cppReader_addIncludeChain (pfile, nlist);
}
}
}
-
+
/* Search ordinary names for GNU include directories. */
for (p = include_defaults; p->fname != NULL; p++)
nlist->got_name_map = 0;
nlist->next = NULL;
- cppReader_addIncludeChain (pfile, nlist);
-
- if (opts->first_system_include == 0)
+ /* Spurious warning reported for opts->first_system_include */
+ /*@-usereleased@*/ if (opts->first_system_include == NULL)
{
opts->first_system_include = nlist;
}
+ /*@=usereleased@*/
+
+ cppReader_addIncludeChain (pfile, nlist);
}
}
sfree (default_prefix);
cppReader_appendIncludeChain (pfile, opts->after_include,
opts->last_after_include);
- if (opts->first_system_include == 0)
+ /* Spurious warnings for opts->first_system_include */
+ /*@-usereleased@*/
+ if (opts->first_system_include == NULL)
{
opts->first_system_include = opts->after_include;
}
-
+ /*@=usereleased@*/
+
/* With -v, print the list of dirs to search. */
if (opts->verbose) {
struct file_name_list *p;
if (context_getFlag (FLG_SKIPSYSHEADERS))
{
- DPRINTF (("Skip include TRUE: %s", fname));
- return TRUE;
+ /*
+ ** 2003-04-18: Patch from Randal Parsons
+ */
+
+ /*
+ ** Don't skip include file unless the file actually exists.
+ ** It may be in a different directory.
+ */
+
+ int f = open (cstring_toCharsSafe (fname), O_RDONLY, 0666);
+
+ if (f >= 0)
+ {
+ check (close (f) == 0);
+ DPRINTF (("Skip include TRUE: %s", fname));
+ return TRUE;
+ }
+ else
+ {
+ /* Keep looking... */
+ }
}
}
llassert (buf->cur != NULL);
buf->cur += n;
}
+
+/*@=bufferoverflowhigh@*/
+/*@=bounds@*/