Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

varNodeList.c

Go to the documentation of this file.
00001 /*
00002 ** LCLint - annotation-assisted static program checker
00003 ** Copyright (C) 1994-2000 University of Virginia,
00004 **         Massachusetts Institute of Technology
00005 **
00006 ** This program is free software; you can redistribute it and/or modify it
00007 ** under the terms of the GNU General Public License as published by the
00008 ** Free Software Foundation; either version 2 of the License, or (at your
00009 ** option) any later version.
00010 ** 
00011 ** This program is distributed in the hope that it will be useful, but
00012 ** WITHOUT ANY WARRANTY; without even the implied warranty of
00013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 ** General Public License for more details.
00015 ** 
00016 ** The GNU General Public License is available from http://www.gnu.org/ or
00017 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00018 ** MA 02111-1307, USA.
00019 **
00020 ** For information on lclint: lclint-request@cs.virginia.edu
00021 ** To report a bug: lclint-bug@cs.virginia.edu
00022 ** For more information: http://lclint.cs.virginia.edu
00023 */
00024 /*
00025 ** varNodeList.c
00026 **
00027 ** based on list_template.c
00028 **
00029 ** where T has T_equal (or change this) and T_unparse
00030 */
00031 
00032 # include "lclintMacros.nf"
00033 # include "llbasic.h"
00034 
00035 varNodeList varNodeList_new ()
00036 {
00037   varNodeList s = (varNodeList) dmalloc (sizeof (*s));
00038 
00039   s->nelements = 0;
00040   s->nspace = varNodeListBASESIZE;
00041   s->elements = (varNode *)
00042     dmalloc (sizeof (*s->elements) * varNodeListBASESIZE);
00043 
00044   return (s);
00045 }
00046 
00047 static void
00048 varNodeList_grow (varNodeList s)
00049 {
00050   int i;
00051   varNode *newelements; 
00052 
00053   s->nspace += varNodeListBASESIZE;
00054   newelements = (varNode *) dmalloc (sizeof (*newelements)
00055                                      * (s->nelements + s->nspace));
00056 
00057   for (i = 0; i < s->nelements; i++)
00058     {
00059       newelements[i] = s->elements[i]; 
00060     }
00061 
00062   sfree (s->elements); 
00063   s->elements = newelements;
00064 }
00065 
00066 varNodeList 
00067 varNodeList_add (varNodeList s, varNode el)
00068 {
00069   if (s->nspace <= 0)
00070     varNodeList_grow (s);
00071 
00072   s->nspace--;
00073   s->elements[s->nelements] = el;
00074   s->nelements++;
00075   return s;
00076 }
00077 
00078 cstring
00079 varNodeList_unparse (varNodeList s)
00080 {
00081   int i;
00082   cstring st = cstring_undefined;
00083   bool first = TRUE;
00084 
00085   for (i = 0; i < s->nelements; i++)
00086     {
00087       cstring type = cstring_undefined;
00088       varNode current = s->elements[i];
00089 
00090       if (current->isObj)
00091         {
00092           type = cstring_makeLiteral ("obj ");
00093         }
00094 
00095       if (current->type != NULL)
00096         {
00097           type = message (": %q%q", type, lclTypeSpecNode_unparse (current->type));
00098         }
00099 
00100       if (first)
00101         {
00102           st = type;
00103           first = FALSE;
00104         }
00105       else
00106         {
00107           st = message ("%q, %q", st, type);
00108         }
00109     }
00110 
00111   return st;
00112 }
00113 
00114 void
00115 varNodeList_free (varNodeList s)
00116 {
00117   int i;
00118   for (i = 0; i < s->nelements; i++)
00119     {
00120       varNode_free (s->elements[i]); 
00121     }
00122 
00123   sfree (s->elements);
00124   sfree (s);
00125 }
00126 
00127 varNodeList
00128 varNodeList_copy (varNodeList s)
00129 {
00130   varNodeList ret = varNodeList_new ();
00131 
00132   varNodeList_elements (s, el)
00133     {
00134       ret = varNodeList_add (ret, varNode_copy (el));
00135     } end_varNodeList_elements;
00136 
00137   return ret;
00138 }

Generated at Fri Nov 3 18:57:46 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000