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

termNodeList.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 ** termNodeList.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 termNodeList termNodeList_new ()
00036 {
00037   termNodeList s = (termNodeList) dmalloc (sizeof (*s));
00038   
00039   s->nelements = 0;
00040   s->nspacelow = termNodeListGROWLOW;
00041   s->nspacehigh = termNodeListGROWHI;
00042   s->elementsroot = (termNode *) dmalloc (sizeof (*s->elements) * (s->nspacelow + s->nspacehigh));
00043   s->elements = s->elementsroot + termNodeListGROWLOW;
00044   s->current = 0;
00045 
00046   return (s);
00047 }
00048 
00049 static void
00050 termNodeList_grow (termNodeList s)
00051 {
00052   int i;
00053   termNode *newelements = (termNode *) dmalloc (sizeof (*newelements)
00054                                                 * (s->nelements + termNodeListBASESIZE));
00055 
00056   for (i = 0; i < s->nelements; i++)
00057     {
00058       newelements[i + termNodeListGROWLOW] = s->elements[i];
00059     }
00060   
00061   sfree (s->elementsroot);
00062 
00063   s->nspacelow = termNodeListGROWLOW;
00064   s->nspacehigh = termNodeListGROWHI; 
00065 
00066   s->elementsroot = newelements;
00067   s->elements = s->elementsroot + s->nspacelow;
00068 }
00069 
00070 void 
00071 termNodeList_addh (termNodeList s, termNode el)
00072 {
00073   llassert (termNodeListGROWHI > 0);
00074 
00075   if (s->nspacehigh <= 0)
00076     termNodeList_grow (s);
00077 
00078   s->nspacehigh--;
00079   s->elements[s->nelements] = el;
00080   s->nelements++;
00081 }
00082 
00083 termNodeList 
00084 termNodeList_push (termNodeList s, termNode el)
00085 {
00086   termNodeList_addh (s, el);
00087   return s;
00088 }
00089 
00090 void 
00091 termNodeList_addl (termNodeList s, termNode el)
00092 {
00093   llassert (termNodeListGROWLOW > 0);
00094 
00095   if (s->nspacelow <= 0)
00096     termNodeList_grow (s);
00097 
00098   s->nspacelow--;
00099   s->elements--;
00100   s->elements[0] = el;
00101   s->current++;
00102   s->nelements++;
00103 }
00104 
00105 void 
00106 termNodeList_reset (termNodeList s)
00107 {
00108   s->current = 0;
00109 }
00110 
00111 void 
00112 termNodeList_finish (termNodeList s)
00113 {
00114   s->current = s->nelements - 1;
00115 }
00116 
00117 void 
00118 termNodeList_advance (termNodeList s)
00119 {
00120   s->current++;
00121   llassert (s->current < s->nelements);
00122 }
00123 
00124 /*@exposed@*/ termNode 
00125 termNodeList_head (termNodeList s)
00126 {
00127   llassert (s->nelements > 0);
00128   return (s->elements[0]);
00129 }
00130 
00131 /*@only@*/ termNodeList 
00132 termNodeList_copy (termNodeList s)
00133 {
00134   termNodeList r = termNodeList_new ();
00135 
00136   termNodeList_elements (s, x)
00137   {
00138     termNodeList_addh (r, termNode_copySafe (x));
00139   } end_termNodeList_elements;
00140 
00141   return r;
00142 }
00143 
00144 /*@exposed@*/ termNode 
00145 termNodeList_current (termNodeList s)
00146 {
00147   llassert (!(s->current >= s->nelements));
00148   return (s->elements[s->current]);
00149 }
00150 
00151 termNode 
00152 termNodeList_getN (termNodeList s, int n)
00153 {
00154   llassert (n >= 0 && n < s->nelements);
00155 
00156   return (s->elements[n]);
00157 }
00158 
00159 /*@only@*/ cstring
00160 termNodeList_unparse (termNodeList s)
00161 {
00162   bool first = TRUE;
00163   cstring st = cstring_undefined;
00164 
00165   termNodeList_elements (s, current)
00166   {
00167     if (first)
00168       {
00169         st = termNode_unparse (current);
00170         first = FALSE;
00171       }
00172     else
00173       st = message ("%q, %q", st, termNode_unparse (current));
00174   } end_termNodeList_elements;
00175 
00176   return st;
00177 }
00178 
00179 /*@only@*/ cstring
00180 termNodeList_unparseTail (termNodeList s)
00181 {
00182   bool head = TRUE;
00183   bool first = TRUE;
00184   cstring st = cstring_undefined;
00185 
00186   termNodeList_elements (s, current)
00187   {
00188     if (head)
00189       {
00190         head = FALSE;
00191       }
00192     else
00193       {
00194         if (first)
00195           {
00196             st = termNode_unparse (current);
00197             first = FALSE;
00198           }
00199         else
00200           st = message ("%q, %q", st, termNode_unparse (current));
00201       }
00202   } end_termNodeList_elements;
00203 
00204   return st;
00205 }
00206 
00207 /*@only@*/ cstring
00208 termNodeList_unparseToCurrent (termNodeList s)
00209 {
00210   int i;
00211   cstring st = cstring_undefined;
00212 
00213   for (i = 0; i < s->current; i++)
00214     {
00215       termNode current = s->elements[i];
00216 
00217       if (i == 0)
00218         st = termNode_unparse (current);
00219       else
00220         st = message ("%q, %q", st, termNode_unparse (current));
00221     }
00222 
00223   return st;
00224 }
00225 
00226 /*@only@*/ cstring
00227 termNodeList_unparseSecondToCurrent (termNodeList s)
00228 {
00229   int i;
00230   cstring st = cstring_undefined;
00231 
00232   for (i = 1; i < s->current; i++)
00233     {
00234       termNode current = s->elements[i];
00235 
00236       if (i == 1)
00237         {
00238           st = termNode_unparse (current);
00239         }
00240       else
00241         {
00242           st = message ("%q, %q", st, termNode_unparse (current));
00243         }
00244     }
00245 
00246   return st;
00247 }
00248 
00249 void
00250 termNodeList_free (termNodeList s)
00251 {
00252   int i;
00253   for (i = 0; i < s->nelements; i++)
00254     {
00255       termNode_free (s->elements[i]); 
00256     }
00257 
00258   sfree (s->elementsroot);
00259   sfree (s);
00260 }

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