/*
-** LCLint - annotation-assisted static program checker
-** Copyright (C) 1994-2000 University of Virginia,
+** Splint - annotation-assisted static program checker
+** Copyright (C) 1994-2003 University of Virginia,
** Massachusetts Institute of Technology
**
** This program is free software; you can redistribute it and/or modify it
** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
** MA 02111-1307, USA.
**
-** For information on lclint: lclint-request@cs.virginia.edu
-** To report a bug: lclint-bug@cs.virginia.edu
-** For more information: http://lclint.cs.virginia.edu
+** For information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
+** For more information: http://www.splint.org
*/
/*
** symtable.c
** 20 January 1991
*/
-# include "lclintMacros.nf"
-# include "llbasic.h"
+# include "splintMacros.nf"
+# include "basic.h"
# include "gram.h"
# include "lclscan.h"
# include "lclsyntable.h"
} info;
} idTableEntry;
-typedef struct _idTable
+typedef struct
{
unsigned int size;
unsigned int allocated;
bool exporting;
} idTable;
-struct _symtableStruct
+struct s_symtableStruct
{
idTable *idTable; /* data is idTableEntry */
symHashTable *hTable; /* data is htData */
- mapping *type2sort; /* maps LCL type symbol to LSL sort */
+ mapping type2sort; /* maps LCL type symbol to LSL sort */
} ;
static /*@observer@*/ ltoken idTableEntry_getId (idTableEntry *p_x);
void varInfo_free (/*@only@*/ varInfo v)
{
+ ltoken_free (v->id);
sfree (v);
}
static void typeInfo_free (/*@only@*/ typeInfo t)
{
+ ltoken_free (t->id);
sfree (t);
}
return (x->info.var->id);
}
- BADBRANCH;
+ BADBRANCHRET (ltoken_undefined);
}
/*@only@*/ symtable
/* symtable_disp (stable); */
- if (k != SPE_GLOBAL && k != SPE_INVALID) /* fixed for LCLint */
+ if (k != SPE_GLOBAL && k != SPE_INVALID) /* fixed for Splint */
{
llbug (message ("%q: symtable_enterType: expect global scope. (type: %s)",
ltoken_unparseLoc (ti->id),
}
lsymbol
-lsymbol_translateSort (mapping * m, lsymbol s)
+lsymbol_translateSort (mapping m, lsymbol s)
{
lsymbol res = mapping_find (m, s);
if (res == lsymbol_undefined)
}
static /*@null@*/ lslOp
- lslOp_renameSorts (mapping *map,/*@returned@*/ /*@null@*/ lslOp op)
+ lslOp_renameSorts (mapping map,/*@returned@*/ /*@null@*/ lslOp op)
{
sigNode sign;
*/
static /*@only@*/ pairNodeList
-parseGlobals (char *line, tsource *srce)
+parseGlobals (char *line, inputStream srce)
{
pairNodeList plist = pairNodeList_new ();
pairNode p;
(message
("%q: Imported file contains illegal function global declaration.\n"
"Skipping rest of the line: %s (%s)",
- fileloc_unparseRaw (cstring_fromChars (tsource_fileName (srce)),
- tsource_thisLineNumber (srce)),
+ fileloc_unparseRaw (inputStream_fileName (srce),
+ inputStream_thisLineNumber (srce)),
cstring_fromChars (line),
cstring_fromChars (lineptr)));
return plist;
typedef /*@only@*/ fctInfo o_fctInfo;
static void
-parseLine (char *line, tsource *srce, mapping * map)
+parseLine (char *line, inputStream srce, mapping map)
{
static /*@owned@*/ o_fctInfo *savedFcn = NULL;
- char *lineptr, *lineptr2, *cimportfile = tsource_fileName (srce);
- cstring importfile = cstring_fromChars (cimportfile);
+ char *lineptr, *lineptr2;
+ cstring importfile = inputStream_fileName (srce);
char namestr[MAXBUFFLEN], kstr[20], sostr[MAXBUFFLEN];
sort bsort, nullSort = sort_makeNoSort ();
int col = 0;
if (inImport)
{
- imploc = fileloc_createImport (importfile, tsource_thisLineNumber (srce));
+ imploc = fileloc_createImport (importfile, inputStream_thisLineNumber (srce));
}
if (firstWord (line, "op"))
*(lineptr2 + 1) = '\0';
}
- llassert (cimportfile != NULL);
- op = parseOpLine (cimportfile, lineptr + 1);
+ llassert (cstring_isDefined (importfile));
+ op = parseOpLine (importfile, cstring_fromChars (lineptr + 1));
if (op == (lslOp) 0)
{
(message
("%q: Imported file contains illegal operator declaration:\n "
"skipping this line: %s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
cstring_fromChars (line)));
fileloc_free (imploc);
return;
{
lclplainerror
(message ("%q: illegal type declaration:\n skipping this line: %s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
cstring_fromChars (line)));
fileloc_free (imploc);
return;
ti = (typeInfo) dmalloc (sizeof (*ti));
ti->id = ltoken_createFull (LLT_TYPEDEF_NAME, lsymbol_fromChars (namestr),
- importfile, tsource_thisLineNumber (srce), col);
+ importfile, inputStream_thisLineNumber (srce), col);
bsort = sort_lookupName (lsymbol_translateSort (map, lsymbol_fromChars (sostr)));
llassert (lineptr != NULL);
lineptr = strchr (lineptr + 1, ' '); /* go past namestr */
llassert (lineptr != NULL);
- col = 5 + lineptr - line; /* 5 for initial "%LCL "*/
+ col = 5 + ((int) (lineptr - line)); /* 5 for initial "%LCL "*/
lclbug (message ("%q: Imported files contains unknown base sort",
- fileloc_unparseRawCol (importfile, tsource_thisLineNumber (srce), col)));
+ fileloc_unparseRawCol (importfile, inputStream_thisLineNumber (srce), col)));
bsort = nullSort;
}
if (!usymtab_existsGlobEither (cnamestr))
{
(void) usymtab_addEntry
- (uentry_makeDatatype (cnamestr, ctype_unknown,
- ti->abstract ? ynm_fromBool (ti->modifiable) : MAYBE,
- ti->abstract ? YES : NO,
- fileloc_copy (imploc)));
+ (uentry_makeDatatype
+ (cnamestr, ctype_unknown,
+ ti->abstract ? ynm_fromBool (ti->modifiable) : MAYBE,
+ ti->abstract ? qual_createAbstract () : qual_createConcrete (),
+ fileloc_copy (imploc)));
}
}
lclplainerror
(message ("%q: Imported file contains illegal variable declaration. "
"Skipping this line.",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce))));
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce))));
fileloc_free (imploc);
return;
}
llassert (lineptr != NULL);
lineptr = strchr (lineptr + 1, ' '); /* go past namestr */
llassert (lineptr != NULL);
- col = 5 + lineptr - line; /* 5 for initial "%LCL "*/
+ col = 5 + ((int) (lineptr - line)); /* 5 for initial "%LCL "*/
if (sort_isNoSort (bsort))
{
lclplainerror (message ("%q: Imported file contains unknown base sort",
- fileloc_unparseRawCol (importfile, tsource_thisLineNumber (srce), col)));
+ fileloc_unparseRawCol (importfile, inputStream_thisLineNumber (srce), col)));
bsort = nullSort;
}
vi->id = ltoken_createFull (simpleId, lsymbol_fromChars (namestr),
- importfile, tsource_thisLineNumber (srce), col);
+ importfile, inputStream_thisLineNumber (srce), col);
vi->sort = bsort;
vi->kind = VRK_VAR;
vi->export = TRUE;
if (sscanf (line, "const %s %s", namestr, sostr) != 2)
{
lclbug (message ("%q: Imported file contains illegal constant declaration: %s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
cstring_fromChars (line)));
fileloc_free (imploc);
return;
lineptr = strchr (lineptr + 1, ' '); /* go past namestr */
llassert (lineptr != NULL);
- col = 5 + lineptr - line; /* 5 for initial "%LCL "*/
+ col = 5 + ((int) (lineptr - line)); /* 5 for initial "%LCL "*/
if (sort_isNoSort (bsort))
{
lclplainerror (message ("%q: Imported file contains unknown base sort",
- fileloc_unparseRawCol (importfile, tsource_thisLineNumber (srce), col)));
+ fileloc_unparseRawCol (importfile, inputStream_thisLineNumber (srce), col)));
bsort = nullSort;
}
vi->id = ltoken_createFull (simpleId, lsymbol_fromChars (namestr),
- importfile, tsource_thisLineNumber (srce), col);
+ importfile, inputStream_thisLineNumber (srce), col);
vi->sort = bsort;
vi->kind = VRK_CONST;
vi->export = TRUE;
lclplainerror
(message ("%q: Unexpected function globals. "
"Skipping this line: \n%s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
cstring_fromChars (line)));
savedFcn = NULL;
pairNodeList_free (globals);
{
lclplainerror
(message ("%q: illegal function declaration. Skipping this line:\n%s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
cstring_fromChars (line)));
fileloc_free (imploc);
return;
*(lineptr2 + 1) = '\0';
}
- op = parseOpLine (cimportfile, lineptr + 1);
+ op = parseOpLine (importfile, cstring_fromChars (lineptr + 1));
if (op == (lslOp) 0)
{
- lclplainerror (message ("%q: illegal function declaration: %s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
- cstring_fromChars (line)));
+ lclplainerror
+ (message ("%q: illegal function declaration: %s",
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
+ cstring_fromChars (line)));
fileloc_free (imploc);
return;
}
if (!usymtab_existsGlobEither (fname))
{
- (void) usymtab_addEntry (uentry_makeFunction
+ (void) usymtab_addEntry (uentry_makeFunction
(fname, ctype_unknown,
typeId_invalid, globSet_new (),
sRefSet_undefined,
+ warnClause_undefined,
fileloc_copy (imploc)));
}
}
}
else
{
- lclplainerror (message ("%q: unexpected function name: %s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
- cstring_fromChars (line)));
+ /* evans 2001-05-27: detected by splint after fixing external alias bug. */
+ if (op->name != NULL)
+ {
+ ltoken_free (op->name->content.opid);
+ }
+
+ lclplainerror
+ (message ("%q: unexpected function name: %s",
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
+ cstring_fromChars (line)));
}
}
else if (firstWord (line, "enumConst"))
lclplainerror
(message ("%q: Illegal enum constant declaration. "
"Skipping this line:\n%s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
cstring_fromChars (line)));
fileloc_free (imploc);
return;
lineptr = strchr (lineptr + 1, ' '); /* go past namestr */
llassert (lineptr != NULL);
- col = 5 + lineptr - line; /* 5 for initial "%LCL "*/
+ col = 5 + ((int) (lineptr - line)); /* 5 for initial "%LCL "*/
if (sort_isNoSort (bsort))
{
lclplainerror (message ("%q: unknown base sort\n",
- fileloc_unparseRawCol (importfile, tsource_thisLineNumber (srce), col)));
+ fileloc_unparseRawCol (importfile, inputStream_thisLineNumber (srce), col)));
bsort = nullSort;
}
vi->id = ltoken_createFull (simpleId, lsymbol_fromChars (namestr),
- importfile, tsource_thisLineNumber (srce), col);
+ importfile, inputStream_thisLineNumber (srce), col);
vi->sort = bsort;
vi->kind = VRK_ENUM;
{
lclplainerror
(message ("%q: Unknown symbol declaration. Skipping this line:\n%s",
- fileloc_unparseRaw (importfile, tsource_thisLineNumber (srce)),
+ fileloc_unparseRaw (importfile, inputStream_thisLineNumber (srce)),
cstring_fromChars (line)));
}
}
void
-symtable_import (tsource *imported, ltoken tok, mapping * map)
+symtable_import (inputStream imported, ltoken tok, mapping map)
{
- char *buf, *importfile;
- tsource *lclsource;
+ char *buf;
+ cstring importfile;
+ inputStream lclsource;
int old_lsldebug;
bool old_inImport = inImport;
- buf = tsource_nextLine (imported);
- importfile = tsource_fileName (imported);
+ buf = inputStream_nextLine (imported);
+ importfile = inputStream_fileName (imported);
llassert (buf != NULL);
lclsource = LCLScanSource ();
lclfatalerror (tok,
message ("Expecting '%%LCLSymbolTable' line in import file %s:\n%s\n",
- cstring_fromChars (importfile),
+ importfile,
cstring_fromChars (buf)));
}
for (;;)
{
- buf = tsource_nextLine (imported);
+ buf = inputStream_nextLine (imported);
llassert (buf != NULL);
lclfatalerror
(tok,
message ("Expecting '%%LCL' prefix in import file %s:\n%s\n",
- cstring_fromChars (importfile),
+ importfile,
cstring_fromChars (buf)));
}
}
static void tagInfo_free (/*@only@*/ tagInfo tag)
{
+ ltoken_free (tag->id);
sfree (tag);
}
/*@only@*/ lslOpSet
symtable_opsWithLegalDomain (symtable tab, /*@temp@*/ /*@null@*/ nameNode n,
- sortSetList argSorts, sort qual)
+ sortSetList argSorts, sort q)
{
/* handles nil qual */
lslOpSet ops = lslOpSet_new ();
{
rangeSort = sigNode_rangeSort (sig);
- if ((qual == 0) || (sort_equal (&rangeSort, &qual)))
+ if ((q == NULL) || (sort_equal (rangeSort, q)))
{
if (domainMatches (sig->domain, argSorts))
{