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

declaratorInvNodeList.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 ** declaratorInvNodeList.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 declaratorInvNodeList
00036   declaratorInvNodeList_new ()
00037 {
00038   declaratorInvNodeList s = (declaratorInvNodeList) dmalloc (sizeof (*s));
00039 
00040   s->nelements = 0;
00041 
00042   s->nspace = declaratorInvNodeListBASESIZE;
00043   s->elements = (declaratorInvNode *) 
00044     dmalloc (sizeof (*s->elements) * declaratorInvNodeListBASESIZE);
00045 
00046   return (s);
00047 }
00048 
00049 static void
00050 declaratorInvNodeList_grow (declaratorInvNodeList s)
00051 {
00052   int i;
00053   declaratorInvNode *newelements;
00054 
00055   s->nspace = declaratorInvNodeListBASESIZE + s->nspace;
00056 
00057    newelements = (declaratorInvNode *) 
00058      dmalloc (sizeof (*newelements) * (s->nelements + s->nspace));
00059 
00060   if (newelements == (declaratorInvNode *) 0)
00061     {
00062       llfatalerror (cstring_makeLiteral ("declaratorInvNodeList_grow: out of memory!"));
00063     }
00064 
00065   for (i = 0; i < s->nelements; i++)
00066     {
00067       newelements[i] = s->elements[i];
00068     }
00069 
00070   sfree (s->elements); 
00071   s->elements = newelements;
00072 }
00073 
00074 declaratorInvNodeList
00075 declaratorInvNodeList_add (declaratorInvNodeList s, declaratorInvNode el)
00076 {
00077   if (s->nspace <= 0)
00078     {
00079       declaratorInvNodeList_grow (s);
00080     }
00081 
00082   s->nspace--;
00083   s->elements[s->nelements] = el;
00084   s->nelements++;
00085 
00086   return s;
00087 }
00088 
00089 /*@only@*/ cstring
00090 declaratorInvNodeList_unparse (declaratorInvNodeList s)
00091 {
00092   int i;
00093   cstring st = cstring_undefined;
00094 
00095   for (i = 0; i < s->nelements; i++)
00096     {
00097       st = message ("%q%q", st, declaratorInvNode_unparse (s->elements[i]));
00098     }
00099 
00100   return st;
00101 }
00102 
00103 void
00104 declaratorInvNodeList_free (declaratorInvNodeList s)
00105 {
00106   int i;
00107   for (i = 0; i < s->nelements; i++)
00108     {
00109       declaratorInvNode_free (s->elements[i]);
00110     }
00111   
00112   sfree (s->elements); 
00113   sfree (s);
00114 }

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