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

typeNameNodeList.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 ** typeNameNodeList.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 typeNameNodeList typeNameNodeList_new ()
00036 {
00037   typeNameNodeList s = (typeNameNodeList) dmalloc (sizeof (*s));
00038   
00039   s->nelements = 0;
00040   s->nspace = typeNameNodeListBASESIZE;
00041   s->elements = (typeNameNode *) 
00042     dmalloc (sizeof (*s->elements) * typeNameNodeListBASESIZE);
00043 
00044   return (s);
00045 }
00046 
00047 static void
00048 typeNameNodeList_grow (typeNameNodeList s)
00049 {
00050   int i;
00051   typeNameNode *newelements; 
00052 
00053   s->nspace += typeNameNodeListBASESIZE;
00054 
00055   newelements = (typeNameNode *) dmalloc (sizeof (*newelements)
00056                                           * (s->nelements + s->nspace));
00057 
00058   for (i = 0; i < s->nelements; i++)
00059     {
00060       newelements[i] =  s->elements[i]; 
00061     }
00062 
00063   sfree (s->elements); 
00064   s->elements = newelements;
00065 }
00066 
00067 typeNameNodeList 
00068 typeNameNodeList_add (typeNameNodeList s, typeNameNode el)
00069 {
00070   if (s->nspace <= 0)
00071     typeNameNodeList_grow (s);
00072 
00073   s->nspace--;
00074   s->elements[s->nelements] = el;
00075   s->nelements++;
00076 
00077   return s;
00078 }
00079 
00080 /*@only@*/ cstring
00081 typeNameNodeList_unparse (typeNameNodeList s)
00082 {
00083   cstring st = cstring_undefined;
00084   bool first = TRUE;
00085 
00086   typeNameNodeList_elements (s, current)
00087   {
00088     if (first)
00089       {
00090         st = typeNameNode_unparse (current);
00091         first = FALSE;
00092       }
00093     else
00094       {
00095         st = message ("%q, %q", st, typeNameNode_unparse (current));
00096       }
00097   } end_typeNameNodeList_elements;
00098   return (st);
00099 }
00100 
00101 void
00102 typeNameNodeList_free (typeNameNodeList s)
00103 {
00104   int i;
00105   for (i = 0; i < s->nelements; i++)
00106     {
00107       typeNameNode_free (s->elements[i]); 
00108     }
00109 
00110   sfree (s->elements);
00111   sfree (s);
00112 }

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