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

fcnNodeList.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 ** fcnNodeList.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 fcnNodeList
00036   fcnNodeList_new ()
00037 {
00038   return fcnNodeList_undefined;
00039 }
00040 
00041 static /*@notnull@*/ /*@only@*/ fcnNodeList
00042 fcnNodeList_newEmpty (void)
00043 {
00044   fcnNodeList s = (fcnNodeList) dmalloc (sizeof (*s));
00045   
00046   s->nelements = 0;
00047   s->nspace = fcnNodeListBASESIZE;
00048   s->elements = (fcnNode *) dmalloc (sizeof (*s->elements) * fcnNodeListBASESIZE);
00049 
00050   return (s);
00051 }
00052 
00053 static void
00054 fcnNodeList_grow (/*@notnull@*/ fcnNodeList s)
00055 {
00056   int i;
00057   fcnNode *newelements;
00058 
00059   s->nspace += fcnNodeListBASESIZE;
00060   newelements = (fcnNode *) dmalloc (sizeof (*newelements) 
00061                                      * (s->nelements + s->nspace));
00062 
00063   if (newelements == (fcnNode *) 0)
00064     {
00065       llfatalerror (cstring_makeLiteral ("fcnNodeList_grow: out of memory!"));
00066     }
00067 
00068   for (i = 0; i < s->nelements; i++)
00069     {
00070       newelements[i] = s->elements[i];
00071     }
00072 
00073   sfree (s->elements);
00074   s->elements = newelements;
00075 }
00076 
00077 fcnNodeList
00078 fcnNodeList_add (fcnNodeList s, fcnNode el)
00079 {
00080   if (fcnNodeList_isUndefined (s))
00081     {
00082       s = fcnNodeList_newEmpty ();
00083     }
00084 
00085   if (s->nspace <= 0)
00086     fcnNodeList_grow (s);
00087 
00088   s->nspace--;
00089   s->elements[s->nelements] = el;
00090   s->nelements++;
00091 
00092   return s;
00093 }
00094 
00095 /*@only@*/ cstring
00096 fcnNodeList_unparse (fcnNodeList s)
00097 {
00098   int i;
00099   cstring st = cstring_undefined;
00100 
00101   if (fcnNodeList_isDefined (s))
00102     {
00103       for (i = 0; i < s->nelements; i++)
00104         {
00105           st = message ("%q%q\n", st, fcnNode_unparse (s->elements[i]));
00106         }
00107     }
00108 
00109   return st;
00110 }
00111 
00112 void
00113 fcnNodeList_free (/*@null@*/ /*@only@*/ fcnNodeList s)
00114 {
00115   if (s != NULL)
00116     {
00117       int i;
00118       for (i = 0; i < s->nelements; i++)
00119         {
00120           fcnNode_free (s->elements[i]); 
00121         }
00122       
00123       sfree (s->elements);
00124       sfree (s);
00125     
00126     }
00127 }

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