# include "cgrammar.h"
# include "cgrammar_tokens.h"
-
-# include "fileIdList.h"
# include "portab.h"
static bool lastWasString = FALSE;
/*@notfunction@*/
# define yyinput() (incColumn (), getc (yyin))
-static /*@owned@*/ cstring lastidprocessed = cstring_undefined;
+static /*@owned@*/ cstring s_lastidprocessed = cstring_undefined;
static int lminput (void);
static int tokLength = 0;
-static bool inSpecPart = FALSE;
+static bool s_inSpecPart = FALSE;
+static int s_whichSpecPart;
static bool continueLine = FALSE;
static int ninput (void);
static long processHex (void);
static long processOctal (void);
static int processIdentifier (/*@only@*/ cstring)
- /*@globals undef lastidprocessed@*/ ;
+ /*@globals s_lastidprocessed@*/ ;
static bool processHashIdentifier (/*@only@*/ cstring)
- /*@globals undef lastidprocessed@*/ ;
+ /*@globals s_lastidprocessed@*/ ;
static int processSpec (int);
static bool handleSpecial (char *);
%%
-"/*" { llfatalbug (cstring_makeLiteral ("Comment in pre-processor output")); }
+"/*" { llfatalerror (cstring_makeLiteral ("Comment in pre-processor output")); }
"#"{Letter}({Letter}|{Digit})* {
context_saveLocation ();
"volatile" { setTokLength (8); RETURN_TOK (QVOLATILE); }
"const" { setTokLength (5); RETURN_TOK (QCONST); }
+"restrict" { setTokLength (8); RETURN_TOK (QRESTRICT); }
/* some systems expect this! [gack!] */
"__const" { setTokLength (7); RETURN_TOK (QCONST); }
if (context_inMacro ())
{
/* Don't use RETURN_TOK */
- yylval.tok = lltok_create (TENDMACRO, g_currentloc);
+ yylval.tok = lltok_create (TENDMACRO, fileloc_copy (g_currentloc)); /* !!! evans 2002-03-13 */
lastWasString = FALSE;
return (TENDMACRO);
}
}
"%}" { /* AFTER_COMMENT_MARKER */
setTokLength (2);
- inSpecPart = FALSE;
+ s_inSpecPart = FALSE;
+ s_whichSpecPart = BADTOK;
RETURN_TOK (QENDMACRO); }
"\\" { incColumn (); continueLine = TRUE; }
. { incColumn ();
}
%%
+/*
+** Resets flags set by flex.head.
+*/
+
+/*@=allmacros@*/
+/*@=pred@*/
+/*@=globstate@*/
+/*@=null@*/
+/*@=boolint@*/
+/*@=charint@*/
+/*@=macrospec@*/
+/*@=macroredef@*/
+/*@=exitarg@*/
+/*@=compdef@*/
+/*@=uniondef@*/
+/*@=ignorequals@*/
+/*@=noreturn@*/
+/*@=mustfree@*/
+/*@=compdestroy@*/
+/*@=branchstate@*/
+/*@=unreachable@*/
+/*@=varuse@*/
+/*@=fcnuse@*/
+/*@=exportlocal@*/
+/*@=evalorderuncon@*/
+/*@=exportheader@*/
+/*@=redecl@*/
+/*@=loopswitchbreak@*/
+/*@=switchswitchbreak@*/
+/*@=sizeoftype@*/
+/*@=czechfcns@*/
+/*@=noparams@*/
+/*@=ansireserved@*/
+/*@=ifblock@*/
+/*@=whileblock@*/
+/*@=forblock@*/
+/*@=elseifcomplete@*/
+/*@=ptrnegate@*/
+/*@=onlytrans@*/
+/*@=temptrans@*/
+/*@=immediatetrans@*/
+/*@=namechecks@*/
+/*@=matchanyintegral@*/
+/*@=statictrans@*/
+/*@=compmempass@*/
+/*@=forempty@*/
+/*@=evalorder@*/
+/*@=retalias@*/
+/*@=redecl@*/
+/*@=retvalother@*/
+/*@=exportheader@*/
+
struct skeyword
{
/*@null@*/ /*@observer@*/ char *name;
** grammar proper.
*/
-struct skeyword s_parsetable[] = {
+static struct skeyword s_parsetable[] = {
{ "modifies", QMODIFIES } ,
{ "globals", QGLOBALS } ,
{ "alt", QALT } ,
** token-specific text.
*/
-struct skeyword s_keytable[] = {
+static struct skeyword s_keytable[] = {
{ "anytype", QANYTYPE } ,
{ "integraltype", QINTEGRALTYPE } ,
{ "unsignedintegraltype", QUNSIGNEDINTEGRALTYPE } ,
{ "nullterminated", QNULLTERMINATED },
{ "setBufferSize", QSETBUFFERSIZE },
{ "testInRange", QTESTINRANGE},
+ { "isnull", QISNULL },
{ "MaxSet", QMAXSET},
{ "MaxRead", QMAXREAD},
+ { "maxSet", QMAXSET},
+ { "maxRead", QMAXREAD},
{ "reldef", QRELDEF } ,
{ "observer", QOBSERVER } ,
{ "exits", QEXITS } ,
|| cstring_equalLit (s, "alt"));
}
-void swallowMacro (void)
+void cscanner_swallowMacro (void)
{
int i;
bool skipnext = FALSE;
{
char c = (char) i;
-
if (c == '\\')
{
skipnext = TRUE;
return;
}
}
+ else
+ {
+ ;
+ }
}
if (i != EOF)
setArgsUsed ();
return SKIPTOK;
}
-
- return s_keytable[i].token;
+ else
+ {
+ return s_keytable[i].token;
+ }
}
-
+
i++;
}
{
c = context_typeofOne ();
}
+ else
+ {
+ ;
+ }
}
yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext),
return c;
}
-static char macro_nextChar ()
+static char macro_nextChar (void)
{
static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
int ic;
lmsavechar (c2);
}
}
+ else
+ {
+ ;
+ }
+
return c;
}
** keeps semantic comments
*/
-static char macro_nextCharC ()
+static char macro_nextCharC (void)
{
static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
char c;
lmsavechar (c2);
}
}
+ else /* normal character */
+ {
+ ;
+ }
+
return c;
}
** returns first non-whitespace character
*/
-static char skip_whitespace ()
+static char skip_whitespace (void)
{
char c;
{
int i;
- for (i = 0; i < ((c - '0') + 1); i++)
+ for (i = 0; i < (((int) (c - '0')) + 1); i++)
{
mac = cstring_appendChar (mac, ' ');
}
{
c = macro_nextChar ();
}
- unput (c);
+ unput ((int) c);
}
if (c == '\n')
{
emptyMacro = TRUE;
- unput (c);
+ unput ((int) c);
}
c = oldc;
fileloc_unparse (oloc)),
loc);
}
+ else
+ {
+ /* No warning */
+ }
}
context_enterConstantMacro (e2);
"typedef should be used instead."),
g_currentloc);
- swallowMacro ();
+ cscanner_swallowMacro ();
/* Must exit scope (not sure why a new scope was entered?) */
usymtab_quietExitScope (g_currentloc);
uentry_setDefined (e2, g_currentloc);
static bool handleSpecial (char *yyt)
{
- char *l = mstring_create (MAX_NAME_LENGTH);
+ char *l; /* !! = mstring_create (MAX_NAME_LENGTH); */
int lineno = 0;
char c;
char *ol;
cstring olc;
-
- int len_yyt;
+ size_t len_yyt;
len_yyt = strlen (yyt +1) ;
if (cstring_equalPrefixLit (olc, "pragma"))
{
- char *pname = mstring_create (longUnsigned_fromInt (MAX_PRAGMA_LEN));
+ char *pname = mstring_create (size_fromInt (MAX_PRAGMA_LEN));
char *opname = pname;
char *ptr = ol + 6; /* pragma is six characters, plus space */
int len = 0;
return FALSE;
}
-static int handleLlSpecial ()
+static int handleLlSpecial (void)
{
bool hasnl = FALSE;
int ic;
{
ic = ninput ();
- llassert (ic == AFTER_COMMENT_MARKER[1]);
+ llassert (ic == (int) AFTER_COMMENT_MARKER[1]);
if (*s == '\0')
{
{
tokLength = charsread;
sfree (os);
- inSpecPart = TRUE;
+ s_inSpecPart = TRUE;
+ s_whichSpecPart = tok;
fileloc_free (loc);
return tok;
}
charsread++;
while (((ic = ninput ()) != 0) && (ic != EOF)
- && (ic != AFTER_COMMENT_MARKER[0]))
+ && (ic != (int) AFTER_COMMENT_MARKER[0]))
{
c = (char) ic;
DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
- if (ic == AFTER_COMMENT_MARKER[0])
+ if (ic == (int) AFTER_COMMENT_MARKER[0])
{
int nc = ninput ();
llassert ((char) nc == AFTER_COMMENT_MARKER[1]);
{
;
}
- else if (flagcode_isInvalid (fflag))
+ else if (flagcode_isModeName (fflag))
{
- if (isMode (flagname))
+ if (ynm_isMaybe (set))
{
- if (ynm_isMaybe (set))
- {
- llerror
- (FLG_BADFLAG,
- message
- ("Semantic comment attempts to restore flag %s. "
- "A mode flag cannot be restored.",
- flagname));
- }
- else
- {
- context_setMode (flagname);
- }
+ llerror
+ (FLG_BADFLAG,
+ message
+ ("Semantic comment attempts to restore flag %s. "
+ "A mode flag cannot be restored.",
+ flagname));
}
else
{
- voptgenerror
- (FLG_UNRECOGFLAGCOMMENTS,
- message ("Unrecognized option in semantic comment: %s",
- flagname),
- loc);
+ context_setMode (flagname);
}
}
+ else if (flagcode_isInvalid (fflag))
+ {
+ voptgenerror
+ (FLG_UNRECOGFLAGCOMMENTS,
+ message ("Unrecognized option in semantic comment: %s",
+ flagname),
+ loc);
+ }
else if (flagcode_isGlobalFlag (fflag))
{
voptgenerror
rest++;
s++;
}
-
+ s--; /* evans 2002-07-12: this was previously only in the else branch.
+ Leads to an invalid read on the true branch.
+ */
+
sfree (orest);
if (cstring_isUndefined (extra))
message
("Flag %s (in semantic comment) must be followed by an argument",
flagcode_unparse (fflag)));
+
}
else
{
- s--;
-
if (flagcode_hasNumber (fflag))
{
setValueFlag (fflag, extra);
}
else
{
+ cstring_free (extra);
BADEXIT;
}
}
if (macrocode != BADTOK)
{
- tokLength = hasnl ? 0 : mstring_length (t);
+ tokLength = hasnl ? 0 : size_toInt (mstring_length (t));
sfree (t);
sfree (os);
while (lc >= '0' && lc <= '9')
{
val *= 10;
- val += lc - '0';
+ val += (int) (lc - '0');
lc = *(++tt);
}
}
while (TRUE)
{
- while ((c = *s) && (c == ' ' || c == '\t' || c == '\n'))
+ while (((c = *s) != '\0') && (c == ' ' || c == '\t' || c == '\n'))
{
s++;
}
while (TRUE)
{
- while ((lc = *s) && (lc == ' ' || lc == '\t' || lc == '\n'))
+ while (((lc = *s) != '\0') && (lc == ' ' || lc == '\t' || lc == '\n'))
{
s++;
}
static /*@only@*/ cstring makeIdentifier (char *s)
{
- char *c = mstring_create (size_toInt (strlen (s)) + 1);
+ char *c = mstring_create (strlen (s) + 1);
cstring id = cstring_fromChars (c);
while (isalnum (*s) || (*s == '_') || (*s == '$'))
return (usymtab_lookup (cn));
}
-/*@observer@*/ cstring LastIdentifier ()
+/*
+** Need to keep this in case there is a declaration that isn't processed until
+** the scope exits. Would be good to rearrange the symbol table so this doesn't
+** happen, and save all the cstring copying.
+*/
+
+/*@observer@*/ cstring cscanner_observeLastIdentifier ()
+{
+ cstring res = s_lastidprocessed;
+ return res;
+}
+
+static void cscanner_setLastIdentifier (/*@keep@*/ cstring id) /*@modifies s_lastidprocessed@*/
{
- return (lastidprocessed);
+ if (cstring_isDefined (s_lastidprocessed))
+ {
+ cstring_free (s_lastidprocessed);
+ }
+
+ s_lastidprocessed = id;
}
static int processIdentifier (cstring id)
}
context_clearJustPopped ();
- lastidprocessed = id;
+ cscanner_setLastIdentifier (id);
+
+ DPRINTF (("Context: %s", context_unparse ()));
if (context_inFunctionHeader ())
{
int tok = commentMarkerToken (id);
- DPRINTF (("in function decl..."));
+ DPRINTF (("in function decl: %s", id));
if (tok != BADTOK)
{
else
{
tok = tokenMacroCode (id);
-
+
if (tok != BADTOK)
{
return tok;
}
}
+ DPRINTF (("Here!"));
+
/* Consider handling: Defined by C99 as static const char __func__[] */
if (context_getFlag (FLG_GNUEXTENSIONS))
while ((ic = input ()) != EOF)
{
-
+ char cc = (char) ic;
+
if (inescape)
{
inescape = FALSE;
}
- else if (ic == '\\')
+ else if (cc == '\\')
{
inescape = TRUE;
}
- else if (ic == '\"')
+ else if (cc == '\"')
{
inquote = !inquote;
}
else if (!inquote)
{
- if (ic == '(')
+ if (cc == '(')
{
if (!useparens)
{
depth++;
}
}
- else if (ic == '{')
+ else if (cc == '{')
{
if (!usebraces)
{
depth++;
}
}
- else if (ic == ')' && useparens)
+ else if (cc == ')' && useparens)
{
depth--;
if (depth == 0) break;
}
- else if (ic == '}' && usebraces)
+ else if (cc == '}' && usebraces)
{
depth--;
if (depth == 0) break;
}
- else if (ic == '}'
+ else if (cc == '}'
&& !usebraces && !useparens
&& cstring_equalLit (id, "__asm"))
{
*/
return TRBRACE;
}
+ else
+ {
+ ;
+ }
+ }
+ else
+ {
+ ;
}
- if (ic == '\n')
+ if (cc == '\n')
{
context_incLineno ();
}
}
- llassert ((useparens && ic == ')')
- || (usebraces && ic == '}')
+ llassert ((useparens && ic == (int) ')')
+ || (usebraces && ic == (int) '}')
|| (!useparens && !usebraces));
return BADTOK;
{
tok = QINLINE;
}
+ else
+ {
+ ;
+ }
if (tok != BADTOK)
{
}
else if (uentry_isUndefined (le))
{
- yylval.cname = id;
+ yylval.cname = cstring_copy (id);
/* avoid parse errors for certain system built ins */
{
if (uentry_isDatatype (le))
{
- yylval.cname = id;
+ yylval.cname = cstring_copy (id);
return (NEW_IDENTIFIER);
}
else
{
if (!g_expectingTypeName)
{
- yylval.cname = id;
+ yylval.cname = cstring_copy (id);
return (NEW_IDENTIFIER);
}
context_clearJustPopped ();
- lastidprocessed = id;
le = usymtab_lookupSafe (id);
+ cscanner_setLastIdentifier (id);
if (uentry_isParam (le) || uentry_isRefParam (le))
{
}
-static /*@only@*/ exprNode processString ()
+static /*@only@*/ exprNode processString (void)
{
exprNode res;
fileloc loc;
if (nl == NULL)
{
loc = fileloc_copy (g_currentloc);
- addColumn (cstring_length (ns));
+ addColumn (size_toInt (cstring_length (ns)));
}
else
{
if (nl == NULL)
{
loc = fileloc_copy (g_currentloc);
- addColumn (cstring_length (ns));
+ addColumn (size_toInt (cstring_length (ns)));
}
else
{
{
size_t length = strlen (yytext);
- if (inSpecPart)
- {
- setTokLengthT (length);
- RETURN_TOK (tok);
- }
- else
+ if (s_inSpecPart)
{
- context_saveLocation ();
- setTokLengthT (length);
- return (processIdentifier (makeIdentifier (yytext)));
+#if 0
+
+ if (s_whichSpecPart == QMODIFIES
+ || s_whichSpecPart == QDEFINES
+ || s_whichSpecPart == QUSES
+ || s_whichSpecPart == QALLOCATES
+ || s_whichSpecPart == QSETS
+ || s_whichSpecPart == QRELEASES
+ || s_whichSpecPart == QPRECLAUSE
+ || s_whichSpecPart == QPOSTCLAUSE
+ || s_whichSpecPart == QINVARIANT)
+ {
+ ; /* Allow specificiation keywords to be used as identifiers in these contexts. */
+ }
+ else
+
+#endif
+
+ {
+ setTokLengthT (length);
+ RETURN_TOK (tok);
+ }
}
+
+ context_saveLocation ();
+ setTokLengthT (length);
+ return (processIdentifier (makeIdentifier (yytext)));
}
void cscanner_expectingMetaStateName ()