X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/b46462e0f425a997aca96d09c7eba11d4cdda1c4..28bf4b0bfd405a2057d865910f8589c54a40f17b:/src/lslparse.c?ds=sidebyside diff --git a/src/lslparse.c b/src/lslparse.c index 01ddf6b..3273075 100644 --- a/src/lslparse.c +++ b/src/lslparse.c @@ -1,6 +1,6 @@ /* ** LCLint - annotation-assisted static program checker -** Copyright (C) 1994-2000 University of Virginia, +** Copyright (C) 1994-2001 University of Virginia, ** Massachusetts Institute of Technology ** ** This program is free software; you can redistribute it and/or modify it @@ -49,43 +49,42 @@ /*@dependent@*/ /*@null@*/ lslOp g_importedlslOp = NULL; bool g_lslParsingTraits = FALSE; -static void invokeLSL (char *p_infile, char *p_outfile, bool p_deletep); +static void invokeLSL (cstring p_infile, cstring p_outfile, bool p_deletep); int parseSignatures (cstring infile) { - char *cinfile = cstring_toCharsSafe (infile); - tsource *sourceFile; + inputStream sourceFile; ltoken *id = (ltoken *) dmalloc (sizeof (*id)); int status = 0; /* parse traits */ - *id = LSLInsertToken (LST_SIMPLEID, lsymbol_fromChars (cinfile), 0, FALSE); - ltoken_setFileName (*id, cinfile); + *id = LSLInsertToken (LST_SIMPLEID, lsymbol_fromString (infile), 0, FALSE); + ltoken_setFileName (*id, infile); ltoken_setLine (*id, 0); ltoken_setCol (*id, 0); - sourceFile = tsource_create (cinfile, "", FALSE); + sourceFile = inputStream_create (infile, cstring_undefined, FALSE); - if (!tsource_getPath (cstring_toCharsSafe (context_getLarchPath ()), sourceFile)) + if (!inputStream_getPath (context_getLarchPath (), sourceFile)) { lclplainerror (message ("LSL signature parsing: can't find file %s containing trait", - cstring_fromChars (tsource_fileName (sourceFile)))); + inputStream_fileName (sourceFile))); status = 1; sfree (id); - tsource_free (sourceFile); + inputStream_free (sourceFile); return status; } - if (!tsource_open (sourceFile)) + if (!inputStream_open (sourceFile)) { lclplainerror (cstring_makeLiteral ("LSL parsing: can't open file containing trait")); status = 2; sfree (id); - tsource_free (sourceFile); + inputStream_free (sourceFile); return status; } @@ -100,8 +99,8 @@ parseSignatures (cstring infile) /* symtable_dump (symtab, stdout, TRUE); */ g_lslParsingTraits = FALSE; - (void) tsource_close (sourceFile); - tsource_free (sourceFile); + (void) inputStream_close (sourceFile); + inputStream_free (sourceFile); sfree (id); @@ -110,14 +109,14 @@ parseSignatures (cstring infile) } /*@only@*/ lslOp -parseOpLine (char *fname, char *line) +parseOpLine (cstring fname, cstring line) { - tsource *sourceFile; + inputStream sourceFile; bool status; - sourceFile = tsource_fromString (fname, line); + sourceFile = inputStream_fromString (fname, line); - if (check (tsource_open (sourceFile))) + if (check (inputStream_open (sourceFile))) { LSLScanReset (sourceFile); LSLReportEolTokens (FALSE); /* 0 by default, lslParsingTraits = 0; */ @@ -133,14 +132,13 @@ parseOpLine (char *fname, char *line) if (status) { - lclplainfatalerror (message ("Error in parsing line: %s", - cstring_fromChars (line))); + lclplainfatalerror (message ("Error in parsing line: %s", line)); } - (void) tsource_close (sourceFile); + (void) inputStream_close (sourceFile); } - tsource_free (sourceFile); + inputStream_free (sourceFile); llassert (g_importedlslOp != NULL); return (lslOp_copy (g_importedlslOp)); @@ -184,7 +182,7 @@ printTypeName2 (typeNameNode n) if (!sort_isValidSort (lclSort)) { err = lclTypeSpecNode_errorToken (p->type); - /* errorShowPoint (tsource_thisLine (lclsource), ltoken_getCol (err)); */ + /* errorShowPoint (inputStream_thisLine (lclsource), ltoken_getCol (err)); */ lclerror (err, message ("Unrecognized type in uses: %q", typeNameNode_unparse (n))); } @@ -222,7 +220,7 @@ printTypeName2 (typeNameNode n) } */ sn = sort_lookup (lclSort); - s = cstring_copy (cstring_fromChars (lsymbol_toChars (sn.name))); + s = cstring_copy (cstring_fromChars (lsymbol_toChars (sn->name))); /* s = string_paste (s, AbstDeclaratorNode_unparse (p->abst)); */ } } @@ -350,7 +348,7 @@ printRenamingNode2 (renamingNode x) } static /*@only@*/ cstring -printTraitRefList2 (traitRefNodeList x) +printTraitRefList2 (traitRefNodeList x) /*@*/ { cstring s = cstring_undefined; @@ -362,6 +360,7 @@ printTraitRefList2 (traitRefNodeList x) { s = message ("%q(%q)", s, printRenamingNode2 (i->rename)); } + s = message ("%q\n", s); } end_traitRefNodeList_elements; @@ -369,7 +368,7 @@ printTraitRefList2 (traitRefNodeList x) } void -callLSL (/*@unused@*/ char *specfile, /*@only@*/ char *text) +callLSL (/*@unused@*/ cstring specfile, /*@only@*/ cstring text) { /* specfile is the name of the LCL file that contains "uses" Create an intermediate file named @@ -381,76 +380,79 @@ callLSL (/*@unused@*/ char *specfile, /*@only@*/ char *text) symbols. */ - char *infile, *outfile; - char *tmp1, *tmp2; + cstring infile; + cstring outfile; + cstring nopath; + cstring noext; FILE *inptr; - infile = cstring_toCharsSafe (fileName (fileTable_addltemp (context_fileTable ()))); - - inptr = fopen (infile, "w"); + infile = fileName (fileTable_addltemp (context_fileTable ())); + inptr = fopen (cstring_toCharsSafe (infile), "w"); if (inptr == NULL) { /* fopen fails */ llfatalerror (message ("Unable to write intermediate file: %s", - cstring_fromChars (infile))); + infile)); } - tmp1 = removePath (infile); - tmp2 = removeAnyExtension (tmp1); + nopath = fileLib_removePath (infile); + noext = fileLib_removeAnyExtension (nopath); + + fprintf (inptr, "%s : trait\n", cstring_toCharsSafe (noext)); - fprintf (inptr, "%s : trait\n", tmp2); - sfree (tmp1); - sfree (tmp2); + cstring_free (noext); + cstring_free (nopath); - fprintf (inptr, "%s", text); + fprintf (inptr, "%s", cstring_toCharsSafe (text)); check (fclose (inptr) == 0); /* the default is to delete the input file */ - outfile = cstring_toCharsSafe (fileName (fileTable_addltemp (context_fileTable ()))); + outfile = fileName (fileTable_addltemp (context_fileTable ())); invokeLSL (infile, outfile, context_getFlag (FLG_KEEP)); - sfree (text); + cstring_free (text); } -static void invokeLSL (char *infile, char *outfile, bool deletep) +static void invokeLSL (cstring infile, cstring outfile, bool deletep) { /* run lsl on infile and leave result in outfile */ FILE *outptr; filestatus status; int callstatus; cstring call; - char *returnPath = NULL; + cstring returnPath = cstring_undefined; /* ** Ensures that outfile can be written into, should find a better ** way to do this. */ - outptr = fopen (outfile, "w"); + outptr = fopen (cstring_toCharsSafe (outfile), "w"); if (outptr == NULL) { /* fopen fails */ llfatalerror (message ("Unable to write intermediate file: %s", - cstring_fromChars (outfile))); + outfile)); } check (fclose (outptr) == 0); /* set call to the right command */ - status = osd_getExePath ("PATH", "lsl", &returnPath); + status = osd_getExePath (cstring_makeLiteralTemp ("PATH"), + cstring_makeLiteralTemp ("lsl"), + &returnPath); if (status == OSD_FILEFOUND) { - call = message ("%s -syms %s > %s", cstring_fromChars (returnPath), - cstring_fromChars (infile), cstring_fromChars (outfile)); + call = message ("%s -syms %s > %s", returnPath, infile, outfile); /* before calling, make sure old file is removed */ (void) osd_unlink (outfile); - callstatus = osd_system (cstring_toCharsSafe (call)); + callstatus = osd_system (call); cstring_free (call); @@ -459,10 +461,8 @@ static void invokeLSL (char *infile, char *outfile, bool deletep) /* ** lsl errors: call lsl again without -syms, sending output to stdout */ - cstring syscal = message ("%s %s", cstring_fromChars (returnPath), - cstring_fromChars (infile)); - - (void) osd_system (cstring_toCharsSafe (syscal)); + cstring syscal = message ("%s %s", returnPath, infile); + (void) osd_system (syscal); cstring_free (syscal); llfatalerror (cstring_makeLiteral ("LSL trait used contains errors.")); @@ -470,7 +470,7 @@ static void invokeLSL (char *infile, char *outfile, bool deletep) else { /* ok, go ahead */ /* Now parse the LSL output and store info in symbol table */ - callstatus = parseSignatures (cstring_fromChars (outfile)); + callstatus = parseSignatures (cstring_copy (outfile)); if (callstatus == 0) { @@ -505,8 +505,5 @@ void readlsignatures (interfaceNode n) { /* assume n->kind = usesKIND */ - char *content; - - content = cstring_toCharsSafe (printTraitRefList2 (n->content.uses)); - callLSL (cstring_toCharsSafe (g_currentSpec), content); + callLSL (g_currentSpec, printTraitRefList2 (n->content.uses)); }