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

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

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