From: evans1629 Date: Mon, 25 Mar 2002 18:55:48 +0000 (+0000) Subject: Fixed creation of temp files. X-Git-Tag: splint-3_1_0~122 X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/commitdiff_plain/d5047b9135351b2240dbe50c224bd95cf3fe5d64 Fixed creation of temp files. --- diff --git a/lib/posix.h b/lib/posix.h index 6716ce8..afac9e4 100644 --- a/lib/posix.h +++ b/lib/posix.h @@ -95,10 +95,10 @@ extern int closedir (DIR *dirp) /*drl 1/4/2001 added the dependent annotation as suggested by Ralf Wildenhues */ - extern /*@null@*/ /*@dependent@*/ DIR *opendir (const char *dirname) +extern /*@null@*/ /*@dependent@*/ DIR *opendir (const char *dirname) /*@modifies errno, fileSystem@*/; -extern /*@null@*/ struct dirent *readdir (DIR *dirp) +extern /*@dependent@*/ /*@null@*/ struct dirent *readdir (DIR *dirp) /*@modifies errno@*/; extern void rewinddir (DIR *dirp) @@ -173,20 +173,32 @@ extern void rewinddir (DIR *dirp) /*@constant int SEEK_CUR@*/ /*@constant int SEEK_END@*/ /*@constant int SEEK_SET@*/ -/*@constant int S_IRGRP@*/ -/*@constant int S_IROTH@*/ -/*@constant int S_IUSR@*/ -/*@constant int S_IWXG@*/ -/*@constant int S_IWXO@*/ -/*@constant int S_IWXU@*/ -/*@constant int S_ISGID@*/ -/*@constant int S_ISUID@*/ -/*@constant int S_IWGRP@*/ -/*@constant int S_IWOTH@*/ -/*@constant int S_IWUSR@*/ -/*@constant int S_IXGRP@*/ -/*@constant int S_IXOTH@*/ -/*@constant int S_IXUSR@*/ + +/*@constant mode_t S_IFMT@*/ +/*@constant mode_t S_IFBLK@*/ +/*@constant mode_t S_IFCHR@*/ +/*@constant mode_t S_IFIFO@*/ +/*@constant mode_t S_IFREG@*/ +/*@constant mode_t S_IFDIR@*/ +/*@constant mode_t S_IFLNK@*/ + +/*@constant mode_t S_IRWXU@*/ +/*@constant mode_t S_IRUSR@*/ + +/*@constant mode_t S_IRGRP@*/ +/*@constant mode_t S_IROTH@*/ +/*@constant mode_t S_IUSR@*/ +/*@constant mode_t S_IWXG@*/ +/*@constant mode_t S_IWXO@*/ +/*@constant mode_t S_IWXU@*/ +/*@constant mode_t S_ISGID@*/ +/*@constant mode_t S_ISUID@*/ +/*@constant mode_t S_IWGRP@*/ +/*@constant mode_t S_IWOTH@*/ +/*@constant mode_t S_IWUSR@*/ +/*@constant mode_t S_IXGRP@*/ +/*@constant mode_t S_IXOTH@*/ +/*@constant mode_t S_IXUSR@*/ struct flock { short l_type; @@ -204,7 +216,8 @@ extern int fcntl (int fd, int cmd, ...) extern int open (const char *path, int oflag, ...) /*:checkerror -1 - returns -1 on error */ - /*@modifies errno@*/; + /* the ... is one mode_t param */ + /*@modifies errno@*/ ; /* ** grp.h @@ -397,21 +410,6 @@ extern int fileno (FILE *fp) /*@modifies errno@*/; ** sys/stat.h */ -/*@constant int S_IRGRP@*/ -/*@constant int S_IROTH@*/ -/*@constant int S_IUSR@*/ -/*@constant int S_IWXG@*/ -/*@constant int S_IWXO@*/ -/*@constant int S_IWXU@*/ -/*@constant int S_ISGID@*/ -/*@constant int S_ISUID@*/ -/*@constant int S_IWGRP@*/ -/*@constant int S_IWOTH@*/ -/*@constant int S_IWUSR@*/ -/*@constant int S_IXGRP@*/ -/*@constant int S_IXOTH@*/ -/*@constant int S_IXUSR@*/ - struct stat { mode_t st_mode; ino_t st_ino; @@ -511,6 +509,10 @@ extern int WTERMSIG (int status) /*@*/ ; /*@constant int WUNTRACED@*/ +/* These are in Unix spec, are they in POSIX? */ +/*@constant int WCONTINUED@*/ +/*@constant int WNOHANG@*/ + pid_t wait (/*@out@*/ /*@null@*/ int *st) /*@modifies *st, errno, systemState@*/; diff --git a/lib/standard.h b/lib/standard.h index ec91cf6..caed5a7 100644 --- a/lib/standard.h +++ b/lib/standard.h @@ -375,27 +375,31 @@ typedef /*@abstract@*/ /*@mutable@*/ void *fpos_t; int remove (char *filename) /*@modifies fileSystem, errno@*/ ; int rename (char *old, char *new) /*@modifies fileSystem, errno@*/ ; -/*@null@*/ FILE *tmpfile (void) /*@modifies fileSystem@*/ ; +/*@dependent@*/ /*@null@*/ FILE *tmpfile (void) + /*@modifies fileSystem, errno@*/ ; + /*@observer@*/ char * tmpnam (/*@out@*/ /*@null@*/ /*@returned@*/ char *s) /*@modifies *s, internalState@*/ ; -int fclose (FILE *stream) /*@modifies *stream, errno, fileSystem;@*/ ; +int fclose (FILE *stream) + /*@modifies *stream, errno, fileSystem;@*/ ; + int fflush (/*@null@*/ FILE *stream) /*@modifies *stream, errno, fileSystem;@*/ ; /*@null@*/ /*@dependent@*/ FILE *fopen (char *filename, char *mode) /*@modifies fileSystem@*/ ; -/*@null@*/ FILE *freopen (char *filename, char *mode, FILE *stream) +/*@dependent@*/ /*@null@*/ FILE *freopen (char *filename, char *mode, FILE *stream) /*@modifies *stream, fileSystem, errno@*/ ; - extern void setbuf (FILE *stream, /*@null@*/ /*@exposed@*/ /*@out@*/ char *buf) - /*@modifies fileSystem, *stream, *buf@*/ ; +extern void setbuf (FILE *stream, /*@null@*/ /*@exposed@*/ /*@out@*/ char *buf) + /*@modifies fileSystem, *stream, *buf@*/ ; - extern int setvbuf (FILE *stream, /*@null@*/ /*@exposed@*/ /*@out@*/ char *buf, +extern int setvbuf (FILE *stream, /*@null@*/ /*@exposed@*/ /*@out@*/ char *buf, int mode, size_t size) - /*@modifies fileSystem, *stream, *buf@*/ ; + /*@modifies fileSystem, *stream, *buf@*/ ; # ifdef STRICT /*@printflike@*/ @@ -525,6 +529,7 @@ void rewind (FILE *stream) /*@modifies *stream@*/ ; void clearerr (FILE *stream) /*@modifies *stream@*/ ; int feof (FILE *stream) /*@modifies errno@*/ ; + int ferror (FILE *stream) /*@modifies errno@*/ ; void perror (/*@null@*/ char *s) diff --git a/lib/tainted.xh b/lib/tainted.xh index 6c82bcb..7e031f0 100644 --- a/lib/tainted.xh +++ b/lib/tainted.xh @@ -9,6 +9,9 @@ extern int fprintf (FILE *stream, /*@untainted@*/ char *format, ...) ; extern int sprintf (/*@out@*/ char *s, /*@untainted@*/ char *format, ...) /*@ensures s:taintedness = ...:taintedness@*/ ; +extern int snprintf (/*@out@*/ char *s, size_t n, /*@untainted@*/ const char *format, ...) + /*@ensures s:taintedness = ...:taintedness@*/ ; + extern int vprintf (/*@untainted@*/ const char *format, va_list ap); extern int vfprintf(FILE *stream, /*@untainted@*/ const char *format, va_list ap); extern int vsprintf (/*@out@*/ char *str, /*@untainted@*/ const char *format, va_list ap) diff --git a/lib/unix.h b/lib/unix.h index 54ccec2..00e01fc 100644 --- a/lib/unix.h +++ b/lib/unix.h @@ -1142,15 +1142,22 @@ extern int shmget (key_t key, int size, int flag) /*@constant observer char *P_tmpdir@*/ +void clearerr (FILE *s) + /*@modifies s@*/ ; + /*@dependent@*/ char *ctermid (/*@returned@*/ /*@null@*/ char *) /*@*/ ; /* Result may be static pointer if parameter is NULL, otherwise is fresh. */ char *cuserid (/*@null@*/ /*@returned@*/ char *) /*@warn legacy "cuserid is obsolete"@*/ /*@*/ ; +/* fclose in standard.h */ + /*@null@*/ FILE *fdopen (int, const char *) /*@modifies errno, fileSystem@*/ ; +/* feof, ferror fflush, fgetc, fgetpos, fgets - in standard.h */ + int fileno (/*@notnull@*/ FILE *) /*:errorcode -1:*/ /*@modifies errno@*/ ; @@ -1219,9 +1226,15 @@ int rename (const char *, const char *) void rewind (FILE *stream) /*@modifies *stream@*/ ; -void setbuf (FILE *stream, /*@null@*/ char *buf); - int setvbuf(FILE *, char *, int, size_t); - int snprintf(char *, size_t, const char *, ...); +void setbuf (FILE *stream, /*@null@*/ /*@dependent@*/ /*@exposed@*/ char *buf) + /*@modifies stream@*/ + +int setvbuf (FILE *stream, /*@null@*/ /*@dependent@*/ /*@exposed@*/ char *buf, int type, size_t size) + /*@modifies stream@*/ + /*:errorcode !0:*/ ; + +int snprintf (char *s, size_t n, const char *format, ...); + int sprintf(char *, const char *, ...); int sscanf(const char *, const char *, int ...); char *tempnam(const char *, const char *); @@ -1285,33 +1298,26 @@ void setbuf (FILE *stream, /*@null@*/ char *buf); /*@constant int LOG_NOWAIT@*/ /*@constant int LOG_PERROR@*/ - extern int -LOG_MASK (int pri) - /*@*/; - - extern int -LOG_UPTO (int pri) - /*@*/; - - extern void -closelog (void) - /*@modifies fileSystem@*/; - - extern void -openlog (const char *ident, int logopt, int facility) - /*@modifies fileSystem@*/; - - extern int -setlogmask (int maskpri) - /*@modifies internalState@*/; - - extern void /*@printflike@*/ -syslog (int priority, const char *message, ...) - /*@modifies fileSystem@*/; - - extern void -vsyslog (int priority, const char *message, va_list args) - /*@modifies fileSystem@*/; +int LOG_MASK (int pri) + /*@*/; + +int LOG_UPTO (int pri) + /*@*/; + +void closelog (void) + /*@modifies fileSystem@*/; + +void openlog (const char *ident, int logopt, int facility) + /*@modifies fileSystem@*/; + +int setlogmask (int maskpri) + /*@modifies internalState@*/; + +void /*@printflike@*/ syslog (int priority, const char *message, ...) + /*@modifies fileSystem@*/; + +void vsyslog (int priority, const char *message, va_list args) + /*@modifies fileSystem@*/; /*________________________________________________________________________ * pwd.h @@ -1387,18 +1393,6 @@ struct stat { } ; /*@=redef@*/ /*@=matchfields@*/ -/*@constant mode_t S_IFMT@*/ -/*@constant mode_t S_IFBLK@*/ -/*@constant mode_t S_IFCHR@*/ -/*@constant mode_t S_IFIFO@*/ -/*@constant mode_t S_IFREG@*/ -/*@constant mode_t S_IFDIR@*/ -/*@constant mode_t S_IFLNK@*/ - -/*@constant mode_t S_IRWXU@*/ -/*@constant mode_t S_IRUSR@*/ - -/*@-incondefs@*/ /*: probably wrong in posix.h? */ /*@constant mode_t S_IWUSR@*/ /*@constant mode_t S_IXUSR@*/ /*@constant mode_t S_IRWXG@*/ @@ -1413,8 +1407,6 @@ struct stat { /*@constant mode_t S_ISGID@*/ /*@constant mode_t S_ISVTX@*/ -/*@=incondefs@*/ - # if 0 /*These are the old definitions - they don't appear to be in the Single UNIX Specification */ @@ -2253,8 +2245,13 @@ typedef /*@abstract@*/ DIR; int closedir (DIR *) /*:errorcode -1*/ ; /*@null@*/ /*@dependent@*/ DIR *opendir(const char *) /*@modifies errno, fileSystem@*/ ; -struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); + +/* in posix.h: struct dirent *readdir(DIR *); */ + +int readdir_r (DIR *, struct dirent *, /*@out@*/ struct dirent **result) + /*@modifies *result@*/ + /*:errorcode !0:*/ ; + void rewinddir(DIR *); void seekdir(DIR *, long int); long int telldir(DIR *); diff --git a/src/Headers/fileLib.h b/src/Headers/fileLib.h index e08dd54..d25aff3 100644 --- a/src/Headers/fileLib.h +++ b/src/Headers/fileLib.h @@ -40,9 +40,6 @@ extern /*@observer@*/ cstring /*@constant observer cstring C_EXTENSION; @*/ # define C_EXTENSION cstring_makeLiteralTemp (".c") -/*@constant observer cstring LHTMP_EXTENSION; @*/ -# define LHTMP_EXTENSION cstring_makeLiteralTemp (".lh_tmp") - /*@constant observer cstring XH_EXTENSION;@*/ # define XH_EXTENSION cstring_makeLiteralTemp (".xh") diff --git a/src/Headers/fileTable.h b/src/Headers/fileTable.h index 33c0d2f..8083be9 100644 --- a/src/Headers/fileTable.h +++ b/src/Headers/fileTable.h @@ -129,6 +129,12 @@ extern /*@observer@*/ cstring fileTable_fileName (fileId p_fid) /*@*/ ; extern /*@observer@*/ cstring fileTable_fileNameBase (fileId p_fid) /*@*/ ; extern /*@observer@*/ cstring fileTable_rootFileName (fileId p_fid) /*@*/ ; +extern /*@null@*/ /*@open@*/ /*@dependent@*/ FILE *fileTable_createFile (fileTable p_ft, cstring p_fname) + /*@modifies p_ft, fileSystem@*/ ; + +extern /*@null@*/ /*@open@*/ /*@dependent@*/ FILE *fileTable_createMacrosFile (fileTable p_ft, cstring p_fname) + /*@modifies p_ft, fileSystem@*/ ; + # define fileTable_fileName(fid) (fileTable_getName(context_fileTable(), fid)) # define fileTable_fileNameBase(fid) (fileTable_getNameBase(context_fileTable(), fid)) # define fileTable_rootFileName(fid) (fileTable_getRootName(context_fileTable(), fid)) @@ -138,9 +144,16 @@ extern bool fileId_baseEqual (/*@sef@*/ fileId p_t1, /*@sef@*/ fileId p_t2) /*@* # define fileId_baseEqual(t1,t2) \ (fileId_equal (t1, t2) || fileTable_sameBase (context_fileTable (), t1, t2)) +extern /*@null@*/ /*@open@*/ /*@dependent@*/ FILE * +fileTable_openReadFile (fileTable p_ft, cstring p_fname) + /*@modifies p_ft@*/ ; + +extern /*@null@*/ /*@open@*/ /*@dependent@*/ FILE * +fileTable_openWriteFile (fileTable p_ft, cstring p_fname) + /*@modifies p_ft@*/ ; extern /*@null@*/ /*@open@*/ /*@dependent@*/ FILE * -fileTable_openFile (fileTable p_ft, cstring p_fname, /*@observer@*/ char *p_mode) +fileTable_openWriteUpdateFile (fileTable p_ft, cstring p_fname) /*@modifies p_ft@*/ ; extern bool fileTable_closeFile (fileTable p_ft, FILE *p_f) diff --git a/src/Headers/lctype.h b/src/Headers/lctype.h index ecf61d0..4e2d0a8 100644 --- a/src/Headers/lctype.h +++ b/src/Headers/lctype.h @@ -73,7 +73,6 @@ typedef enum typedef enum { - CTK_ANYTYPE = -4, CTK_UNKNOWN = -3, CTK_INVALID = -2, CTK_DNE = -1, @@ -98,9 +97,6 @@ extern int ctkind_toInt (ctkind p_x); /*@constant ctype ctype_dne; @*/ # define ctype_dne ((ctype) CTK_DNE) -/*@constant ctype ctype_anytype; @*/ -# define ctype_anytype ((ctype) CTK_ANYTYPE) - /*@constant ctype ctype_unknown; @*/ # define ctype_unknown CTX_UNKNOWN @@ -262,12 +258,14 @@ extern ctype ctype_fixArrayPtr (ctype p_c); extern ctype ctype_getBaseType (ctype p_c) /*@*/ ; +extern ctype ctype_makeAnytype (void) /*@*/ ; +extern bool ctype_isAnytype (ctype) /*@*/ ; + extern ctype ctype_makeArray (ctype p_c); extern ctype ctype_makeFixedArray (ctype p_c, size_t p_size); -extern ctype ctype_makeInnerArray (ctype p_c); extern ctype ctype_makeInnerFixedArray (ctype p_c, size_t p_size); - -extern ctype ctype_makeConj (ctype p_c1, ctype p_c2); +extern ctype ctype_makeInnerArray (ctype p_c); +extern ctype ctype_makeConj (ctype p_c1, ctype p_c2) /*@modifies internalState@*/ ; extern ctype ctype_makeParamsFunction (ctype p_base, /*@only@*/ uentryList p_p); extern ctype ctype_makeFunction (ctype p_base, /*@only@*/ uentryList p_p) /*@*/ ; extern ctype ctype_makeNFParamsFunction (ctype p_base, /*@only@*/ uentryList p_p) /*@*/ ; @@ -347,9 +345,6 @@ extern bool ctype_isUndefined (ctype p_c) /*@*/ ; extern bool ctype_isUnknown (ctype p_c) /*@*/; # define ctype_isUnknown(c) ((c) == CTX_UNKNOWN) -extern bool ctype_isAnytype (ctype p_c) /*@*/; -# define ctype_isAnytype(c) ((c) == ctype_anytype) - extern bool ctype_isBogus (/*@sef@*/ ctype p_c) /*@*/ ; # define ctype_isBogus(c) (ctype_isUndefined(c) || ctype_isUnknown(c)) diff --git a/src/Headers/lh.h b/src/Headers/lh.h index d9211dd..b7445b0 100644 --- a/src/Headers/lh.h +++ b/src/Headers/lh.h @@ -9,7 +9,7 @@ extern void lhCleanup (void) /*@modifies internalState, fileSystem@*/ ; extern void lhIncludeBool (void) /*@modifies internalState@*/ ; -extern void lhInit (inputStream p_f) /*@modifies internalState, fileSystem@*/ ; +extern void lhInit (inputStream p_f) /*@modifies internalState@*/ ; extern void lhOutLine (/*@only@*/ cstring p_s) /*@modifies internalState@*/ ; extern void lhExternals (interfaceNodeList p_x) /*@modifies internalState@*/ ; diff --git a/src/abstract.c b/src/abstract.c index 978ab86..e57c603 100644 --- a/src/abstract.c +++ b/src/abstract.c @@ -3413,23 +3413,23 @@ lclTypeSpecNode_unparseAltComments (/*@null@*/ lclTypeSpecNode typespec) /*@*/ return (message ("%q%s", s, ltoken_unparse (n->opttagid))); } - s = message ("%q%s {\n\2\1", s, ltoken_unparse (n->opttagid)); + s = message ("%q%s {\n\t", s, ltoken_unparse (n->opttagid)); } else { - s = message ("%q{\n\2\1", s); + s = message ("%q{\n\t", s); } decls = n->structdecls; stDeclNodeList_elements (decls, f) { - s = message ("%q%q\1%q;\n\1", s, + s = message ("%q%q %q;\n\t", s, lclTypeSpecNode_unparseAltComments (f->lcltypespec), declaratorNodeList_unparse (f->declarators)); } end_stDeclNodeList_elements; - return (message ("%q\3}", s)); + return (message ("%q }", s)); } case LTS_CONJ: { @@ -3520,23 +3520,23 @@ cstring lclTypeSpecNode_unparseComments (/*@null@*/ lclTypeSpecNode typespec) return (message ("%q%s", s, ltoken_unparse (n->opttagid))); } - s = message ("%q%s {\n\2\1", s, ltoken_unparse (n->opttagid)); + s = message ("%q%s {\n\t", s, ltoken_unparse (n->opttagid)); } else { - s = message ("%q{\n\2\1", s); + s = message ("%q{\n\t", s); } decls = n->structdecls; stDeclNodeList_elements (decls, f) { - s = message ("%q%q\1%q;\n\1", s, + s = message ("%q%q %q;\n\t", s, lclTypeSpecNode_unparseComments (f->lcltypespec), declaratorNodeList_unparse (f->declarators)); } end_stDeclNodeList_elements; - return (message ("%q\3}", s)); + return (message ("%q }", s)); } case LTS_CONJ: { diff --git a/src/cgrammar.c.der b/src/cgrammar.c.der index 2ec46b4..18641a1 100644 --- a/src/cgrammar.c.der +++ b/src/cgrammar.c.der @@ -4368,7 +4368,7 @@ case 367: { yyval.typequal = yyvsp[-1].typequal; ; break;} case 374: -{ yyval.ctyp = ctype_anytype; DPRINTF (("anytype: %s", ctype_unparse (yyval.ctyp))); ; +{ yyval.ctyp = ctype_makeAnytype (); ; break;} case 375: { yyval.ctyp = ctype_anyintegral; ; diff --git a/src/cgrammar.y b/src/cgrammar.y index 1b18b8b..9ac04c6 100644 --- a/src/cgrammar.y +++ b/src/cgrammar.y @@ -1232,7 +1232,7 @@ typeSpecifier | CGFLOAT NotType | CDOUBLE NotType | CVOID NotType - | QANYTYPE NotType { $$ = ctype_anytype; DPRINTF (("anytype: %s", ctype_unparse ($$))); } + | QANYTYPE NotType { $$ = ctype_makeAnytype (); } | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; } | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; } | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; } diff --git a/src/context.c b/src/context.c index 4d11f04..d301d75 100644 --- a/src/context.c +++ b/src/context.c @@ -3009,7 +3009,7 @@ context_setString (flagcode flag, cstring val) { ; /* Okay not handle everything in this switch */ } - } + } /* evans 2002-03-24: splintme reports a spurious (I think) warning here...need to look into it */ if (cstring_length (val) >= 1 && cstring_firstChar (val) == '\"') diff --git a/src/cpplib.c b/src/cpplib.c index 25e1271..58dc81d 100644 --- a/src/cpplib.c +++ b/src/cpplib.c @@ -6737,7 +6737,7 @@ read_name_map (cppReader *pfile, cstring dirname) name = cstring_concatFree1 (name, cstring_makeLiteralTemp (FILE_NAME_MAP_FILE)); - f = fileTable_openFile (context_fileTable (), name, "r"); + f = fileTable_openReadFile (context_fileTable (), name); cstring_free (name); if (f == NULL) diff --git a/src/cppmain.c b/src/cppmain.c index 74c68ba..9c568d9 100644 --- a/src/cppmain.c +++ b/src/cppmain.c @@ -116,7 +116,7 @@ int cppProcess (/*@dependent@*/ cstring infile, llexit (LLFAILURE); } - ofile = fileTable_openFile (context_fileTable (), outfile, "w"); + ofile = fileTable_createFile (context_fileTable (), outfile); if (ofile == NULL) { diff --git a/src/ctbase.i b/src/ctbase.i index 2d9c42f..5e3d374 100644 --- a/src/ctbase.i +++ b/src/ctbase.i @@ -70,6 +70,7 @@ static ctype cttable_addDerived (ctkind p_ctk, /*@keep@*/ ctbase p_cnew, ctype p static ctype cttable_addFull (/*@keep@*/ ctentry p_cnew); static bool ctentry_isInteresting (ctentry p_c) /*@*/; static /*@notnull@*/ /*@only@*/ ctbase ctbase_makeFixedArray (ctype p_b, size_t p_size) /*@*/ ; +static bool ctbase_isAnytype (/*@notnull@*/ ctbase p_b) /*@*/ ; /* ** These are file-static macros (used in ctype.c). No way to @@ -538,7 +539,11 @@ ctbase_unparse (ctbase c) enumNameList_unparseBrief (c->contents.cenum->members))); } case CT_CONJ: - if (c->contents.conj->isExplicit || context_getFlag (FLG_SHOWALLCONJS)) + if (ctbase_isAnytype (c)) + { + return (cstring_makeLiteral ("")); + } + else if (c->contents.conj->isExplicit || context_getFlag (FLG_SHOWALLCONJS)) { if (!ctype_isSimple (c->contents.conj->a) || !ctype_isSimple (c->contents.conj->b)) @@ -609,7 +614,14 @@ static /*@only@*/ cstring case CT_UNION: return (message ("union %s { ... }", c->contents.su->name)); case CT_CONJ: - return (message ("%t", c->contents.conj->a)); + if (ctbase_isAnytype (c)) + { + return (cstring_makeLiteral ("")); + } + else + { + return (message ("%t", c->contents.conj->a)); + } BADDEFAULT; } BADEXIT; @@ -657,9 +669,16 @@ ctbase_unparseNotypes (ctbase c) case CT_ENUMLIST: return (message ("[enumlist]")); case CT_CONJ: - return (message ("%q/%q", - ctbase_unparseNotypes (ctype_getCtbase (c->contents.conj->a)), - ctbase_unparseNotypes (ctype_getCtbase (c->contents.conj->b)))); + if (ctbase_isAnytype (c)) + { + return (cstring_makeLiteral ("")); + } + else + { + return (message ("%q/%q", + ctbase_unparseNotypes (ctype_getCtbase (c->contents.conj->a)), + ctbase_unparseNotypes (ctype_getCtbase (c->contents.conj->b)))); + } BADDEFAULT; } BADEXIT; @@ -754,8 +773,12 @@ ctbase_unparseDeclaration (ctbase c, /*@only@*/ cstring name) /*@*/ enumNameList_unparseBrief (c->contents.cenum->members), name)); } - case CT_CONJ: - if (c->contents.conj->isExplicit || context_getFlag (FLG_SHOWALLCONJS)) + case CT_CONJ: + if (ctbase_isAnytype (c)) + { + return (message (" %q", name)); + } + else if (c->contents.conj->isExplicit || context_getFlag (FLG_SHOWALLCONJS)) { if (!ctype_isSimple (c->contents.conj->a) || !ctype_isSimple (c->contents.conj->b)) @@ -1839,6 +1862,23 @@ static /*@only@*/ ctbase return (c); } +static bool ctbase_isAnytype (/*@notnull@*/ ctbase b) +{ + /* + ** A unknown|dne conj is a special representation for an anytype. + */ + + if (b->type == CT_CONJ) + { + /*@access ctype@*/ + return (b->contents.conj->a == ctype_unknown + && b->contents.conj->b == ctype_dne); + /*@noaccess ctype@*/ + } + + return FALSE; +} + static ctype ctbase_getConjA (/*@notnull@*/ ctbase c) { diff --git a/src/ctype.c b/src/ctype.c index fd4daac..81cc6aa 100644 --- a/src/ctype.c +++ b/src/ctype.c @@ -80,7 +80,7 @@ ctkind ctkind_fromInt (int i) { /*@+enumint@*/ - if (i < CTK_ANYTYPE || i > CTK_COMPLEX) + if (i < CTK_UNKNOWN || i > CTK_COMPLEX) { llcontbug (message ("ctkind_fromInt: out of range: %d", i)); return CTK_INVALID; @@ -154,8 +154,9 @@ ctype_createUser (typeId u) ctype ctype_createAbstract (typeId u) { - /* requires: ctype_createAbstract (u) is never called more than once for any u. */ - /* [ tested by cttable_addFullSafe, not really required ] */ + /* requires: ctype_createAbstract (u) is never called more than once for any u. */ + /* [ tested by cttable_addFullSafe, not really required ] */ + return (cttable_addFullSafe (ctentry_makeNew (CTK_PLAIN, ctbase_createAbstract (u)))); } @@ -232,30 +233,22 @@ ctype_realishType (ctype c) return c; } -static bool -ctype_isSpecialType (ctype c) -{ - return (ctype_isUnknown (c) || ctype_isAnytype (c)); -} - bool ctype_isUA (ctype c) { - return (!ctype_isSpecialType (c) - && ctbase_isUA (ctype_getCtbase (c))); + return (!ctype_isUnknown (c) && ctbase_isUA (ctype_getCtbase (c))); } bool ctype_isUser (ctype c) { - return (!ctype_isSpecialType (c) - && ctbase_isUser (ctype_getCtbase (c))); + return (!ctype_isUnknown (c) && ctbase_isUser (ctype_getCtbase (c))); } bool ctype_isAbstract (ctype c) { - return (!ctype_isSpecialType (c) + return (!ctype_isUnknown (c) && ((ctype_isPlain (c) && ctbase_isAbstract (ctype_getCtbaseSafe (c))) || (ctype_isConj (c) && (ctype_isAbstract (ctype_getConjA (c)) @@ -496,9 +489,9 @@ ctype_isWideString (ctype c) ctype ctype_getReturnType (ctype c) { - if (ctype_isSpecialType (c)) + if (ctype_isUnknown (c)) { - return c; + return ctype_unknown; } return (ctbase_baseFunction (ctype_getCtbaseSafe (c))); @@ -511,7 +504,7 @@ ctype_getReturnType (ctype c) /*@observer@*/ uentryList ctype_argsFunction (ctype c) { - if (ctype_isSpecialType (c)) + if (ctype_isUnknown (c)) { return uentryList_undefined; } @@ -597,9 +590,9 @@ ctype_compare (ctype c1, ctype c2) ctentry ce1; ctentry ce2; - if (ctype_isSpecialType (c1)) + if (ctype_isUnknown (c1)) { - if (ctype_isSpecialType (c2)) + if (ctype_isUnknown (c2)) { return 0; } @@ -609,7 +602,7 @@ ctype_compare (ctype c1, ctype c2) } } - if (ctype_isSpecialType (c2)) + if (ctype_isUnknown (c2)) { return -1; } @@ -1121,8 +1114,6 @@ ctype_isForceRealBool (ctype * c) static ctype ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit) { - DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2))); - if (ctype_isBogus (c1) || ctype_isUndefined (c1)) { return c2; @@ -1147,9 +1138,11 @@ ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit) ctype ctype_makeExplicitConj (ctype c1, ctype c2) { - DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2))); - - if (ctype_isFunction (c1) && !ctype_isFunction (c2)) + if (ctype_isAnytype (c1) || ctype_isAnytype (c2)) + { + return ctype_makeAnytype (); + } + else if (ctype_isFunction (c1) && !ctype_isFunction (c2)) { ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2); @@ -1178,6 +1171,27 @@ static ctype ivb = ctype_unknown; /* int | void * | bool */ static ctype ivbf = ctype_unknown; /* int | void * | bool | float */ static ctype cuc = ctype_unknown; /* char | unsigned char */ +static ctype cany = ctype_unknown; + +ctype +ctype_makeAnytype () +{ + if (cany == ctype_unknown) + { + cany = ctype_makeConj (ctype_unknown, ctype_dne); + llassert (ctype_isAnytype (cany)); + } + + DPRINTF (("make anytype: %s", ctype_unparse (cany))); + return cany; +} + +bool +ctype_isAnytype (ctype c) +{ + return (c == cany); +} + static void ctype_recordConj (ctype c) { @@ -1298,7 +1312,15 @@ ctype_makeConj (ctype c1, ctype c2) DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2))); - if (ctype_isUnknown (c1)) + if (ctype_isAnytype (c1)) + { + return c1; + } + else if (ctype_isAnytype (c2)) + { + return c2; + } + else if (ctype_isUnknown (c1)) { return c2; } @@ -1489,7 +1511,6 @@ ctype_makeConj (ctype c1, ctype c2) { ; } - return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE))); } @@ -1641,11 +1662,11 @@ ctype_matchDef (ctype c1, ctype c2) return TRUE; if (ctype_isElips (c1)) - return (ctype_isElips (c2) || ctype_isSpecialType (c2)); + return (ctype_isElips (c2) || ctype_isUnknown (c2)); if (ctype_isElips (c2)) { - return (ctype_isSpecialType (c2)); + return (ctype_isUnknown (c2)); } else { @@ -1665,14 +1686,10 @@ bool ctype_match (ctype c1, ctype c2) return TRUE; if (ctype_isElips (c1)) - { - return (ctype_isElips (c2) || ctype_isSpecialType (c2)); - } - + return (ctype_isElips (c2) || ctype_isUnknown (c2)); + if (ctype_isElips (c2)) - { - return (ctype_isSpecialType (c2)); - } + return (ctype_isUnknown (c2)); return (ctbase_match (ctype_getCtbase (c1), ctype_getCtbase (c2))); } @@ -1802,9 +1819,9 @@ ctype_typeId (ctype c) cstring ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name) { - llassert (! (ctype_isElips (c) || ctype_isMissingParamsMarker (c))); + llassert (!(ctype_isElips (c) || ctype_isMissingParamsMarker (c))); - if (ctype_isSpecialType (c)) + if (ctype_isUnknown (c)) { return message ("? %q", name); } @@ -1825,14 +1842,14 @@ ctype_unparse (ctype c) { return cstring_makeLiteralTemp ("-"); } - else if (ctype_isUnknown (c)) - { - return cstring_makeLiteralTemp ("?"); - } else if (ctype_isAnytype (c)) { return cstring_makeLiteralTemp (""); } + else if (ctype_isUnknown (c)) + { + return cstring_makeLiteralTemp ("?"); + } else { /*@-modobserver@*/ @@ -1929,7 +1946,6 @@ ctype_getBaseType (ctype c) switch (ctentry_getKind (cte)) { - case CTK_ANYTYPE: case CTK_UNKNOWN: case CTK_INVALID: case CTK_PLAIN: @@ -2237,7 +2253,7 @@ bool ctype_isRefCounted (ctype t) bool ctype_isVisiblySharable (ctype t) { - if (ctype_isSpecialType (t)) return TRUE; + if (ctype_isUnknown (t)) return TRUE; if (ctype_isConj (t)) { @@ -2552,19 +2568,13 @@ ctype ctype_combine (ctype dominant, ctype modifier) ctype ctype_resolve (ctype c) { - if (ctype_isUnknown (c)) + if (ctype_isUnknown (c) && !ctype_isAnytype (c)) { - DPRINTF (("Resolving! %s", ctype_unparse (c))); + DPRINTF (("Resolving to int: %s", ctype_unparse (c))); return ctype_int; } - else if (c == ctype_anytype) - { - return ctype_unknown; - } - else - { - return c; - } + + return c; } ctype ctype_fromQual (qual q) @@ -2686,9 +2696,7 @@ static /*@observer@*/ ctbase ctype_getCtbase (ctype c) llbuglit ("ctype_getCtbase: ctype dne"); if (c == ctype_elipsMarker) llbuglit ("ctype_getCtbase: elips marker"); - if (c == ctype_anytype) - llbuglit ("ctype_getCtbase: ctype anytype"); - + llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c)); BADEXIT; } @@ -2731,8 +2739,6 @@ ctype_getCtentry (ctype c) } else if (c == CTK_UNKNOWN) llcontbuglit ("ctype_getCtentry: ctype unknown"); - else if (c == CTK_ANYTYPE) - llcontbuglit ("ctype_getCtentry: ctype unknown"); else if (c == CTK_INVALID) llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)"); else if (c == CTK_DNE) diff --git a/src/fileTable.c b/src/fileTable.c index 98daa02..96c060d 100644 --- a/src/fileTable.c +++ b/src/fileTable.c @@ -44,11 +44,15 @@ * - Added conditional stuff (#define and #include) for IBM's compiler. */ +# include +# include +# include # include "splintMacros.nf" # include "llbasic.h" # include "osd.h" # include "llmain.h" # include "portab.h" + # if defined(__IBMC__) && defined(OS2) # include # define getpid _getpid @@ -948,7 +952,6 @@ static /*@only@*/ cstring makeTempName (cstring dir, cstring pre, cstring suf) smsg = message ("%s%s%s%s%s", dir, pre, pidname, cstring_fromChars (msg), suf); nextMsg (msg); } - return smsg; } @@ -984,9 +987,106 @@ fileTable_addOpen (fileTable ft, /*@observer@*/ FILE *f, /*@only@*/ cstring fnam ft->nopen++; } -FILE *fileTable_openFile (fileTable ft, cstring fname, char *mode) +FILE *fileTable_createFile (fileTable ft, cstring fname) +{ + int fdesc = open (cstring_toCharsSafe (fname), O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR); + + if (fdesc == -1) + { + osd_setTempError (); + llfatalerror (message ("Temporary file for " + "pre-processor output already exists. Trying to " + "open: %s.", + fname)); + + /*@notreached@*/ return NULL; + } + else + { + FILE *res = fdopen (fdesc, "w"); + + if (res != NULL) + { + fileTable_addOpen (ft, res, cstring_copy (fname)); + DPRINTF (("Opening file: %s / %p", fname, res)); + } + else + { + DPRINTF (("Error opening: %s", fname)); + } + + return res; + } +} + +FILE *fileTable_createMacrosFile (fileTable ft, cstring fname) +{ + int fdesc = open (cstring_toCharsSafe (fname), O_RDWR | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR); + + if (fdesc == -1) + { + osd_setTempError (); + llfatalerror (message ("Temporary file for " + "pre-processor output already exists. Trying to " + "open: %s.", + fname)); + + /*@notreached@*/ return NULL; + } + else + { + FILE *res = fdopen (fdesc, "w+"); + + if (res != NULL) + { + fileTable_addOpen (ft, res, cstring_copy (fname)); + DPRINTF (("Opening file: %s / %p", fname, res)); + } + else + { + DPRINTF (("Error opening: %s", fname)); + } + + return res; + } +} + +FILE *fileTable_openReadFile (fileTable ft, cstring fname) { - FILE *res = fopen (cstring_toCharsSafe (fname), mode); + FILE *res = fopen (cstring_toCharsSafe (fname), "r"); + + if (res != NULL) + { + fileTable_addOpen (ft, res, cstring_copy (fname)); + DPRINTF (("Opening read file: %s / %p", fname, res)); + } + else + { + DPRINTF (("Cannot open read file: %s", fname)); + } + + return res; +} + +/* +** Allows overwriting +*/ + +FILE *fileTable_openWriteFile (fileTable ft, cstring fname) +{ + FILE *res = fopen (cstring_toCharsSafe (fname), "w"); + + if (res != NULL) { + fileTable_addOpen (ft, res, cstring_copy (fname)); + DPRINTF (("Opening file: %s / %p", fname, res)); + } + + return res; +} + +FILE *fileTable_openWriteUpdateFile (fileTable ft, cstring fname) +{ + FILE *res = fopen (cstring_toCharsSafe (fname), "w+"); if (res != NULL) { fileTable_addOpen (ft, res, cstring_copy (fname)); @@ -1010,7 +1110,7 @@ bool fileTable_closeFile (fileTable ft, FILE *f) if (ft->openelements[i]->f == f) { DPRINTF (("Closing file: %p = %s", f, ft->openelements[i]->fname)); - + if (i == ft->nopen - 1) { foentry_free (ft->openelements[i]); diff --git a/src/flags.def b/src/flags.def index f3167fc..588cfb1 100644 --- a/src/flags.def +++ b/src/flags.def @@ -2855,7 +2855,7 @@ static flaglist flags = NULL, 0, 0 }, { - FK_LIBS, FK_INIT, globalFlag, + FK_LIBS, FK_INIT, idemGlobalFlag, "isolib", FLG_ANSILIB, "use normal standard library", @@ -2863,7 +2863,7 @@ static flaglist flags = 0, 0 }, { - FK_LIBS, FK_INIT, globalFlag, + FK_LIBS, FK_INIT, idemGlobalFlag, "strictlib", FLG_STRICTLIB, "interpret standard library strictly", @@ -2872,7 +2872,7 @@ static flaglist flags = 0, 0 }, { - FK_LIBS, FK_INIT, globalFlag, + FK_LIBS, FK_INIT, idemGlobalFlag, "unixlib", FLG_UNIXLIB, "use UNIX (sort-of) standard library", @@ -2880,7 +2880,7 @@ static flaglist flags = 0, 0 }, { - FK_LIBS, FK_INIT, globalFlag, + FK_LIBS, FK_INIT, idemGlobalFlag, "unixstrictlib", FLG_UNIXSTRICTLIB, "use strict version of UNIX (sort-of) library", @@ -2888,7 +2888,7 @@ static flaglist flags = 0, 0 }, { - FK_LIBS, FK_INIT, globalFlag, + FK_LIBS, FK_INIT, idemGlobalFlag, "posixlib", FLG_POSIXLIB, "use POSIX standard library", @@ -2896,7 +2896,7 @@ static flaglist flags = 0, 0 }, { - FK_LIBS, FK_INIT, globalFlag, + FK_LIBS, FK_INIT, idemGlobalFlag, "posixstrictlib", FLG_POSIXSTRICTLIB, "use strict POSIX standard library", @@ -2904,7 +2904,7 @@ static flaglist flags = 0, 0 }, { - FK_LIBS, FK_INIT, globalFlag, + FK_LIBS, FK_INIT, idemGlobalFlag, "whichlib", FLG_WHICHLIB, "show standard library filename", diff --git a/src/imports.c b/src/imports.c index 78c91eb..2b609f3 100644 --- a/src/imports.c +++ b/src/imports.c @@ -50,7 +50,7 @@ outputLCSFile (char *path, char *msg, char *specname) char *sfile = mstring_concat (specname, ".lcs"); char *outfile = mstring_concat (path, sfile); char *s; - FILE *outfptr = fileTable_openFile (context_fileTable (), cstring_fromChars (outfile), "w"); + FILE *outfptr = fileTable_openWriteFile (context_fileTable (), cstring_fromChars (outfile)); sfree (sfile); DPRINTF (("Output lcl file: %s / %s / %s", path, specname, outfile)); diff --git a/src/inputStream.c b/src/inputStream.c index c38bb07..743b264 100644 --- a/src/inputStream.c +++ b/src/inputStream.c @@ -279,8 +279,8 @@ inputStream_open (inputStream s) return TRUE; } - DPRINTF (("Open: %s", s->name)); - s->file = fileTable_openFile (context_fileTable (), s->name, "r"); + DPRINTF (("Opening: %s", s->name)); + s->file = fileTable_openReadFile (context_fileTable (), s->name); return (s->file != 0 || s->fromString); } diff --git a/src/lcllib.c b/src/lcllib.c index cc7d661..ac388a6 100644 --- a/src/lcllib.c +++ b/src/lcllib.c @@ -274,7 +274,7 @@ dumpState (cstring cfname) FILE *f; cstring fname = fileLib_addExtension (cfname, cstring_makeLiteralTemp (DUMP_SUFFIX)); - f = fileTable_openFile (context_fileTable (), fname, "w"); + f = fileTable_openWriteFile (context_fileTable (), fname); displayScanOpen (message ("Dumping to %s ", fname)); @@ -355,7 +355,7 @@ loadStandardState () } else { - stdlib = fileTable_openFile (context_fileTable (), fpath, "r"); + stdlib = fileTable_openReadFile (context_fileTable (), fpath); if (stdlib == NULL) { @@ -405,7 +405,7 @@ loadStandardState () sfree (ot); check (fileTable_closeFile (context_fileTable (), stdlib)); - stdlib = fileTable_openFile (context_fileTable (), fpath, "r"); + stdlib = fileTable_openReadFile (context_fileTable (), fpath); } llassert (stdlib != NULL); @@ -569,7 +569,7 @@ loadState (cstring cfname) FILE *f; cstring fname = fileLib_addExtension (cfname, cstring_makeLiteralTemp (DUMP_SUFFIX)); - f = fileTable_openFile (context_fileTable (), fname, "r"); + f = fileTable_openReadFile (context_fileTable (), fname); if (f == NULL) { diff --git a/src/lh.c b/src/lh.c index 9a44f21..2c477d9 100644 --- a/src/lh.c +++ b/src/lh.c @@ -46,19 +46,11 @@ # include "llmain.h" /*@constant static char TABCH; @*/ -# define TABCH '\1' +# define TABCH ' ' /*@constant static char TABINCH; @*/ -# define TABINCH '\2' +# define TABINCH '\t' -/*@constant static char TABOUTCH; @*/ -# define TABOUTCH '\3' - -/* - # define TAB fputc (TABCH, LhFile.f); - # define TABIN fputc (TABINCH, LhFile.f); - # define TABOUT fputc (TABOUTCH, LhFile.f); -*/ /*@private@*/ typedef struct { @@ -82,15 +74,6 @@ static cstring lhTypeSpecNode (lclTypeSpecNode p_typespec); static /*@only@*/ cstring lhTypeExpr (/*@null@*/ typeExpr p_x); static /*@only@*/ cstring lhDeclaratorNode (declaratorNode p_x); -static /*:open:*/ /*@dependent@*/ /*@null@*/ FILE *out_open (cstring name, cstring suffix) - /*@modifies fileSystem@*/ -{ - cstring fullname = cstring_concat (name, suffix); - FILE *ret = fileTable_openFile (context_fileTable (), fullname, "w+"); - cstring_free (fullname); - return ret; -} - /*@only@*/ cstring lhFunction (lclTypeSpecNode lclTypeSpec, declaratorNode declarator) { @@ -99,7 +82,7 @@ lhFunction (lclTypeSpecNode lclTypeSpec, declaratorNode declarator) if (!genLh) return cstring_undefined; - s = message ("extern %q\1%q;", lhTypeSpecNode (lclTypeSpec), + s = message ("extern %q %q;", lhTypeSpecNode (lclTypeSpec), lhDeclaratorNode (declarator)); return s; @@ -261,7 +244,7 @@ lhVarDecl (lclTypeSpecNode lclTypeSpec, initDeclNodeList initDecls, break; } - s = message ("%q %q\1", s, lhTypeSpecNode (lclTypeSpec)); + s = message ("%q %q ", s, lhTypeSpecNode (lclTypeSpec)); initDeclNodeList_elements (initDecls, i) { @@ -289,71 +272,19 @@ lhCleanup (void) } else { - FILE *f; - int c, col = 0, tabcol = 0; - cstring fullname; - - f = out_open (LhFile.name, LH_EXTENSION); llassert (LhFile.f != NULL); - fullname = cstring_concat (LhFile.name, LHTMP_EXTENSION); - - if (f == NULL) + if (LhFile.f == NULL) { /*@i25534 check this! does it report the right filename? */ - lldiagmsg (message ("Cannot open lh file for output: %s", - fullname)); + lldiagmsg (message ("Cannot open lh file for output: %s", LhFile.name)); } else { - fprintf (f, "/* Output from %s */\n", LCL_PARSE_VERSION); - - rewind (LhFile.f); - - while (EOF != (c = getc (LhFile.f))) - { - switch (c) - { - case TABCH: - if (col == 0) - { - if (tabcol > 0) - fprintf (f, "%*s", tabcol, ""); - } - else - { - check (fputc (' ', f) == (int) ' '); - } - /*@switchbreak@*/ break; - - case TABINCH: - tabcol += 4; - /*@switchbreak@*/ break; - - case TABOUTCH: - tabcol -= 4; - /*@switchbreak@*/ break; - - case '\n': - col = 0; - check (fputc (c, f) == (int) c); - /*@switchbreak@*/ break; - - default: - col++; - check (fputc (c, f) == (int) c); - /*@switchbreak@*/ break; - } - } - - check (fileTable_closeFile (context_fileTable (), f)); + check (fprintf (LhFile.f, "/* Output from %s */\n", LCL_PARSE_VERSION) > 0); check (fileTable_closeFile (context_fileTable (), LhFile.f)); - - (void) osd_unlink (fullname); LhFile.f = NULL; } - - cstring_free (fullname); } } @@ -364,32 +295,7 @@ lhIncludeBool (void) needIncludeBool = TRUE; } -/* -**++ -** FUNCTIONAL DESCRIPTION: -** -** Initialize the .lh file processing. -** -** FORMAL PARAMETERS: -** -** source * f: The source file, from which we compute the name of -** the .lh file. -** -** bool outputLh: If true, produce a .lh file, otherwise don't. -** -** RETURN VALUE: -** -** None -** -** SIDE EFFECTS: -** -** The .lh file may be opened. -** -** -**-- -*/ - -void lhInit (inputStream f) /*@globals undef LhFile; @*/ +void lhInit (inputStream f) /*@globals undef LhFile; @*/ { static bool lherror = FALSE; @@ -401,18 +307,17 @@ void lhInit (inputStream f) /*@globals undef LhFile; @*/ return; } - LhFile.name = LSLRootName (inputStream_fileName (f)); - LhFile.f = out_open (LhFile.name, LHTMP_EXTENSION); + LhFile.name = cstring_concatFree1 (LSLRootName (inputStream_fileName (f)), + LH_EXTENSION); + LhFile.f = fileTable_openWriteUpdateFile (context_fileTable (), LhFile.name); if (LhFile.f == NULL) { genLh = FALSE; if (!lherror) { - lclplainerror (message ("Cannot write temporary %s file: %s%s", - LH_EXTENSION, - LhFile.name, - LHTMP_EXTENSION)); + lclplainerror (message ("Cannot write temporary file: %s", + LhFile.name)); lherror = TRUE; } } @@ -423,6 +328,7 @@ void lhOutLine (/*@only@*/ cstring s) if (genLh) { llassert (LhFile.f != NULL); + DPRINTF (("lhOutLine: %s / %s", s, LhFile.name)); if (cstring_length (s) > 0) { diff --git a/src/llmain.c b/src/llmain.c index 9b2251f..a847b1b 100644 --- a/src/llmain.c +++ b/src/llmain.c @@ -2295,7 +2295,7 @@ bool readOptionsFile (cstring fname, cstringSList *passThroughArgs, bool report) } else { - FILE *innerf = fileTable_openFile (context_fileTable (), fname, "r"); + FILE *innerf = fileTable_openReadFile (context_fileTable (), fname); if (innerf != NULL) { diff --git a/src/lslparse.c b/src/lslparse.c index 053ed81..9f7b3af 100644 --- a/src/lslparse.c +++ b/src/lslparse.c @@ -387,7 +387,7 @@ callLSL (/*@unused@*/ cstring specfile, /*@only@*/ cstring text) FILE *inptr; infile = fileTable_fileName (fileTable_addltemp (context_fileTable ())); - inptr = fileTable_openFile (context_fileTable (), infile, "w"); + inptr = fileTable_createFile (context_fileTable (), infile); if (inptr == NULL) { @@ -428,7 +428,7 @@ static void invokeLSL (cstring infile, cstring outfile, bool deletep) ** way to do this. */ - outptr = fileTable_openFile (context_fileTable (), outfile, "w"); + outptr = fileTable_createFile (context_fileTable (), outfile); if (outptr == NULL) { diff --git a/src/macrocache.c b/src/macrocache.c index 6a59b64..027eb52 100644 --- a/src/macrocache.c +++ b/src/macrocache.c @@ -237,7 +237,7 @@ static void pushString (/*@only@*/ cstring s) mtid = fileTable_addMacrosFile (context_fileTable ()); fname = fileTable_fileName (mtid); - s_macFile = fileTable_openFile (context_fileTable (), fname, "wb+"); + s_macFile = fileTable_createMacrosFile (context_fileTable (), fname); /* , "wb+"); ? **/ if (s_macFile == NULL) { diff --git a/src/osd.c b/src/osd.c index 9af9d10..8ba1c60 100644 --- a/src/osd.c +++ b/src/osd.c @@ -305,7 +305,7 @@ osd_fileExists (cstring filespec) return (stat (cstring_toCharsSafe (filespec), &buf) == 0); # else # if defined (WIN32) || defined (OS2) - FILE *test = fileTable_openFile (context_fileTable (), filespec, "r"); + FILE *test = fileTable_openReadFile (context_fileTable (), filespec); if (test != NULL) { @@ -567,7 +567,7 @@ cstring osd_fixDefine (cstring x) bool osd_fileIsReadable (cstring f) { - FILE *fl = fileTable_openFile (context_fileTable (), f, "r"); + FILE *fl = fileTable_openReadFile (context_fileTable (), f); if (fl != NULL) { diff --git a/src/usymtab.c b/src/usymtab.c index 69e810c..52a2f28 100644 --- a/src/usymtab.c +++ b/src/usymtab.c @@ -1594,7 +1594,7 @@ usymtab_rehash (/*@notnull@*/ usymtab s) cstringTable_free (s->htable); } - s->htable = cstringTable_create (LLHASHSIZE); + s->htable = cstringTable_create (LLAHSHSIZE); for (i = 0; i < s->nentries; i++) { diff --git a/test/db1.expect b/test/db1.expect index 3a27d48..dafec7b 100644 --- a/test/db1.expect +++ b/test/db1.expect @@ -561,25 +561,25 @@ drive.c:134: Return value (type bool) ignored: fire(17) drive.c:158: Return value (type bool) ignored: fire(empset_choo... drive.c:11: Parameter argv not used dbase.c:11: Type employeeKinds declared but not used -eref.lh:8: Function exported but not used outside eref: eref_free +eref.lh:7: Function exported but not used outside eref: eref_free eref.h:23: Definition of eref_free -empset.lh:8: Function exported but not used outside empset: empset_final +empset.lh:7: Function exported but not used outside empset: empset_final empset.h:29: Definition of empset_final -empset.lh:9: Function exported but not used outside empset: empset_clear +empset.lh:8: Function exported but not used outside empset: empset_clear empset.c:24: Definition of empset_clear -empset.lh:11: Function exported but not used outside empset: +empset.lh:10: Function exported but not used outside empset: empset_insertUnique empset.c:53: Definition of empset_insertUnique -empset.lh:17: Function exported but not used outside empset: empset_member +empset.lh:16: Function exported but not used outside empset: empset_member empset.h:30: Definition of empset_member -empset.lh:18: Function exported but not used outside empset: empset_subset +empset.lh:17: Function exported but not used outside empset: empset_subset empset.c:144: Definition of empset_subset -ereftab.lh:10: Function exported but not used outside ereftab: ereftab_delete +ereftab.lh:9: Function exported but not used outside ereftab: ereftab_delete ereftab.c:26: Definition of ereftab_delete dbase.c:13: Variable exported but not used outside dbase: db -dbase.lh:27: Function exported but not used outside dbase: promote +dbase.lh:26: Function exported but not used outside dbase: promote dbase.c:182: Definition of promote -dbase.lh:28: Function exported but not used outside dbase: setSalary +dbase.lh:27: Function exported but not used outside dbase: setSalary dbase.c:206: Definition of setSalary empset.h:10: Variable exported but not used outside empset: known dbase.c:15: Variable exported but not used outside dbase: initDone diff --git a/test/repexpose.expect b/test/repexpose.expect index bf162d1..41ce332 100644 --- a/test/repexpose.expect +++ b/test/repexpose.expect @@ -119,6 +119,6 @@ repexpose.c:51:10: Function returns reference to parameter im: (im->name) repexpose.c:51:10: Return value exposes rep of immut: (im->name) repexpose.c: (in function abst_setIm) repexpose.c:57:3: Undocumented modification of a->im: a->im = im -repexpose.lh:6:16: Variable globstring declared but not defined +repexpose.lh:5:16: Variable globstring declared but not defined Finished checking --- 27 code warnings, as expected diff --git a/test/utypes.expect b/test/utypes.expect index 008e619..9a3bf8a 100644 --- a/test/utypes.expect +++ b/test/utypes.expect @@ -4,13 +4,13 @@ utypes.c:16: Include file matches the name of a POSIX library, +posixstrictlib to select the POSIX library, or -warnposix to suppress this message. utypes.c:3:23: Variable uchar inconsistently redeclared as datatype - utypes.c:13: Previous definition of uchar as variable: ? + utypes.c:13: Previous definition of uchar as variable: utypes.c:4:24: Variable ushort inconsistently redeclared as datatype - utypes.c:15: Previous definition of ushort as variable: ? + utypes.c:15: Previous definition of ushort as variable: utypes.c:5:22: Variable uint inconsistently redeclared as datatype - utypes.c:14: Previous definition of uint as variable: ? + utypes.c:14: Previous definition of uint as variable: utypes.c:6:23: Variable ulong inconsistently redeclared as datatype - utypes.c:16: Previous definition of ulong as variable: ? + utypes.c:16: Previous definition of ulong as variable: utypes.c: (in function f) utypes.c:26:8: Variable src_bytes declared but not used