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

paramNodeList.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 ** paramNodeList.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 /*@only@*/ paramNodeList
00036 paramNodeList_new ()
00037 {
00038   paramNodeList s = (paramNodeList) dmalloc (sizeof (*s));
00039 
00040   s->nelements = 0;
00041   s->nspace = paramNodeListBASESIZE;
00042   s->elements = (paramNode *) 
00043     dmalloc (sizeof (*s->elements) * paramNodeListBASESIZE);
00044 
00045   return (s);
00046 }
00047 
00048 /*@only@*/ paramNodeList
00049 paramNodeList_single (/*@keep@*/ paramNode p)
00050 {
00051   paramNodeList s = (paramNodeList) dmalloc (sizeof (*s));
00052   
00053   s->nelements = 1;
00054   s->nspace = paramNodeListBASESIZE - 1;
00055   s->elements = (paramNode *) dmalloc (sizeof (*s->elements) * paramNodeListBASESIZE);
00056   s->elements[0] = p;
00057 
00058   return (s);
00059 }
00060 
00061 static void
00062 paramNodeList_grow (/*@notnull@*/ paramNodeList s)
00063 {
00064   int i;
00065   paramNode *newelements;
00066 
00067   s->nspace += paramNodeListBASESIZE;
00068 
00069   newelements = (paramNode *) dmalloc (sizeof (*newelements)
00070                                        * (s->nelements + s->nspace));
00071 
00072   for (i = 0; i < s->nelements; i++)
00073     {
00074       newelements[i] = s->elements[i];
00075     }
00076 
00077   sfree (s->elements);
00078   s->elements = newelements;
00079 }
00080 
00081 paramNodeList
00082 paramNodeList_add (paramNodeList s, paramNode el)
00083 {
00084   llassert (paramNodeList_isDefined (s));
00085 
00086   if (s->nspace <= 0)
00087     paramNodeList_grow (s);
00088 
00089   s->nspace--;
00090   s->elements[s->nelements] = el;
00091   
00092   s->nelements++;
00093   return s;
00094 }
00095 
00096 /*@only@*/ paramNodeList 
00097 paramNodeList_copy (paramNodeList s)
00098 {
00099   paramNodeList r = paramNodeList_new ();
00100 
00101   paramNodeList_elements (s, x)
00102   {
00103     r = paramNodeList_add (r, paramNode_copy (x));
00104   } end_paramNodeList_elements;
00105 
00106   return r;
00107 }
00108 
00109 /*@only@*/ cstring
00110 paramNodeList_unparse (paramNodeList s)
00111 {
00112   bool first = TRUE;
00113   cstring st = cstring_undefined;
00114 
00115   paramNodeList_elements (s, current)
00116   {
00117     if (first)
00118       {
00119         st = paramNode_unparse (current);
00120         first = FALSE;
00121       }
00122     else
00123       {
00124         st = message ("%q, %q", st, paramNode_unparse (current));
00125       }
00126   } end_paramNodeList_elements;
00127 
00128   return st;
00129 }
00130 
00131 /*@only@*/ cstring
00132 paramNodeList_unparseComments (paramNodeList s)
00133 {
00134   bool first = TRUE;
00135   cstring st = cstring_undefined;
00136 
00137   paramNodeList_elements (s, current)
00138   {
00139     if (first)
00140       {
00141         st = paramNode_unparseComments (current);
00142         first = FALSE;
00143       }
00144     else
00145       {
00146         st = message ("%q, %q", st, paramNode_unparseComments (current));
00147       }
00148   } end_paramNodeList_elements;
00149 
00150   return st;
00151 }
00152 
00153 void
00154 paramNodeList_free (/*@only@*/ paramNodeList s)
00155 {
00156   if (paramNodeList_isDefined (s))
00157     {
00158       int i;
00159       for (i = 0; i < s->nelements; i++)
00160         {
00161           paramNode_free (s->elements[i]); 
00162         }
00163       
00164       sfree (s->elements); 
00165       sfree (s);
00166     }
00167 }

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