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

exprNodeSList.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 ** exprNodeSList.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 "basic.h"
00034 # include "exprNodeSList.h"
00035 
00036 exprNodeSList
00037   exprNodeSList_new ()
00038 {
00039   exprNodeSList s = (exprNodeSList) dmalloc (sizeof (*s));
00040   
00041   s->nelements = 0;
00042   s->nspace = exprNodeSListBASESIZE; 
00043   s->elements = (exprNode *) 
00044     dmalloc (sizeof (*s->elements) * exprNodeSListBASESIZE);
00045 
00046   return (s);
00047 }
00048 
00049 static void
00050 exprNodeSList_grow (exprNodeSList s)
00051 {
00052   int i;
00053   exprNode *newelements; 
00054   
00055   s->nspace += exprNodeSListBASESIZE; 
00056 
00057   newelements = (exprNode *) dmalloc (sizeof (*newelements)
00058                                       * (s->nelements + s->nspace));
00059 
00060   if (newelements == (exprNode *) 0)
00061     {
00062       llfatalerror (cstring_makeLiteral ("exprNodeSList_grow: out of memory!"));
00063     }
00064 
00065   for (i = 0; i < s->nelements; i++)
00066     {
00067       newelements[i] = s->elements[i];
00068     }
00069   
00070   sfree (s->elements);
00071   s->elements = newelements;
00072 }
00073 
00074 void exprNodeSList_addh (exprNodeSList s, /*@exposed@*/ /*@dependent@*/ exprNode el)
00075 {
00076   llassert (exprNodeSListBASESIZE > 0);
00077 
00078   if (s->nspace <= 0)
00079     exprNodeSList_grow (s);
00080   
00081   s->nspace--;
00082   s->elements[s->nelements] = el;
00083   s->nelements++;
00084 }
00085 
00086 /*
00087 ** appends s2 to s1 
00088 */
00089 
00090 exprNodeSList exprNodeSList_append (/*@returned@*/ exprNodeSList s1, /*@only@*/ exprNodeSList s2)
00091 {
00092   exprNodeSList_elements (s2, x)
00093     {
00094       exprNodeSList_addh (s1, x);
00095     } end_exprNodeSList_elements;
00096 
00097   exprNodeSList_free (s2);
00098   return s1;
00099 }
00100 
00101 /*@only@*/ exprNodeSList exprNodeSList_singleton (/*@exposed@*/ /*@dependent@*/ exprNode e)
00102 {
00103   exprNodeSList s = (exprNodeSList) dmalloc (sizeof (*s));
00104   
00105   s->nelements = 1;
00106   s->nspace = exprNodeSListBASESIZE - 1; 
00107   s->elements = (exprNode *) dmalloc (sizeof (*s->elements) * exprNodeSListBASESIZE);
00108   s->elements[0] = e;
00109 
00110   return (s);
00111 }
00112 
00113 /*@only@*/ cstring
00114 exprNodeSList_unparse (exprNodeSList s)
00115 {
00116    int i;
00117    cstring st = cstring_undefined;
00118 
00119    for (i = 0; i < s->nelements; i++)
00120      {
00121        if (i == 0)
00122          {
00123            st = cstring_copy (exprNode_unparse (s->elements[i]));
00124          }
00125        else
00126          st = message ("%q, %s", st, exprNode_unparse (s->elements[i]));
00127      }
00128    
00129    return st;
00130 }
00131 
00132 void
00133 exprNodeSList_free (exprNodeSList s)
00134 {
00135   sfree (s->elements); 
00136   sfree (s);
00137 }
00138 

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