/*
** 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
/*@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;
}
/* symtable_dump (symtab, stdout, TRUE); */
g_lslParsingTraits = FALSE;
- (void) tsource_close (sourceFile);
- tsource_free (sourceFile);
+ (void) inputStream_close (sourceFile);
+ inputStream_free (sourceFile);
sfree (id);
}
/*@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; */
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));
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)));
}
} */
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)); */
}
}
}
static /*@only@*/ cstring
-printTraitRefList2 (traitRefNodeList x)
+printTraitRefList2 (traitRefNodeList x) /*@*/
{
cstring s = cstring_undefined;
{
s = message ("%q(%q)", s, printRenamingNode2 (i->rename));
}
+
s = message ("%q\n", s);
} end_traitRefNodeList_elements;
}
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
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);
/*
** 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."));
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)
{
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));
}