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

pairNodeList.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 ** pairNodeList.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@*/ pairNodeList
00036 pairNodeList_new ()
00037 {
00038   pairNodeList s = (pairNodeList) dmalloc (sizeof (*s));
00039   
00040   s->nelements = 0;
00041   s->nspace = pairNodeListBASESIZE;
00042   s->elements = (pairNode *) 
00043     dmalloc (sizeof (*s->elements) * pairNodeListBASESIZE);
00044 
00045   return (s);
00046 }
00047 
00048 static void
00049 pairNodeList_grow (/*@notnull@*/ pairNodeList s)
00050 {
00051   int i;
00052   pairNode *newelements; 
00053 
00054   s->nspace += pairNodeListBASESIZE;
00055   newelements = (pairNode *) 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 void 
00068 pairNodeList_addh (pairNodeList s, pairNode el)
00069 {
00070   llassert (pairNodeList_isDefined (s));
00071   llassert (pairNodeListBASESIZE > 0);
00072 
00073   if (s->nspace <= 0)
00074     pairNodeList_grow (s);
00075 
00076   s->nspace--;
00077   s->elements[s->nelements] = el;
00078   s->nelements++;
00079 }
00080 
00081 /*@only@*/ cstring
00082 pairNodeList_unparse (pairNodeList s)
00083 {
00084   cstring st = cstring_undefined;
00085   
00086   if (s != (pairNodeList)0)
00087     {
00088       pairNodeList_elements (s, current)
00089         {
00090           if (current != NULL)
00091             {
00092               st = message ("%q%s %s; ", st, 
00093                             sort_unparseName (current->sort), 
00094                             ltoken_getRawString (current->tok));
00095             }
00096         } end_pairNodeList_elements;
00097     }
00098 
00099   return st;
00100 }
00101 
00102 void
00103 pairNodeList_free (/*@only@*/ pairNodeList s)
00104 {
00105   if (pairNodeList_isDefined (s))
00106     {
00107       int i;
00108       for (i = 0; i < s->nelements; i++)
00109         {
00110           pairNode_free (s->elements[i]); 
00111         }
00112       
00113       sfree (s->elements); 
00114       sfree (s);
00115     }
00116 }

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