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

declaratorNodeList.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 ** declaratorNodeList.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 declaratorNodeList
00036   declaratorNodeList_new ()
00037 {
00038   declaratorNodeList s = (declaratorNodeList) dmalloc (sizeof (*s));
00039 
00040   s->nelements = 0;
00041   s->nspace = declaratorNodeListBASESIZE;
00042   s->elements = (declaratorNode *) 
00043     dmalloc (sizeof (*s->elements) * declaratorNodeListBASESIZE);
00044 
00045   return (s);
00046 }
00047 
00048 static void
00049 declaratorNodeList_grow (declaratorNodeList s)
00050 {
00051   int i;
00052   declaratorNode *newelements;
00053 
00054   s->nspace = declaratorNodeListBASESIZE + s->nspace;
00055   newelements = (declaratorNode *) dmalloc (sizeof (*newelements) * (s->nelements + s->nspace));
00056 
00057   if (newelements == (declaratorNode *) 0)
00058     {
00059       llfatalerror (cstring_makeLiteral ("declaratorNodeList_grow: out of memory!"));
00060     }
00061 
00062   for (i = 0; i < s->nelements; i++)
00063     {
00064       newelements[i] = s->elements[i];
00065     }
00066 
00067   sfree (s->elements); 
00068   s->elements = newelements;
00069 }
00070 
00071 declaratorNodeList 
00072 declaratorNodeList_add (declaratorNodeList s, declaratorNode el)
00073 {
00074   if (s->nspace <= 0)
00075     declaratorNodeList_grow (s);
00076 
00077   s->nspace--;
00078   s->elements[s->nelements] = el;
00079   s->nelements++;
00080 
00081   return s;
00082 }
00083 
00084 /*@only@*/ cstring
00085 declaratorNodeList_unparse (declaratorNodeList s)
00086 {
00087   cstring st = cstring_undefined;
00088   bool first = TRUE;
00089 
00090   declaratorNodeList_elements (s, current)
00091   {
00092     if (first)
00093       {
00094         st = declaratorNode_unparse (current);
00095         first = FALSE;
00096       }
00097     else
00098       {
00099         st = message ("%q, %q", st, declaratorNode_unparse (current));
00100       }
00101   } end_declaratorNodeList_elements;
00102 
00103   return st;
00104 }
00105 
00106 declaratorNodeList
00107 declaratorNodeList_copy (declaratorNodeList s)
00108 {
00109   declaratorNodeList ret = declaratorNodeList_new ();
00110 
00111   declaratorNodeList_elements (s, el)
00112     {
00113       ret = declaratorNodeList_add (ret, declaratorNode_copy (el));
00114     } end_declaratorNodeList_elements ;
00115 
00116   return ret;
00117 }
00118 
00119 void
00120 declaratorNodeList_free (declaratorNodeList s)
00121 {
00122   int i;
00123   for (i = 0; i < s->nelements; i++)
00124     {
00125       declaratorNode_free (s->elements[i]); 
00126     }
00127 
00128   sfree (s->elements);
00129   sfree (s);
00130 }

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