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

idDeclList.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 ** idDeclList.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 
00035 idDeclList
00036   idDeclList_singleton (/*@only@*/ idDecl e)
00037 {
00038   idDeclList s = (idDeclList) dmalloc (sizeof (*s));
00039   
00040   s->nelements = 1;
00041   s->nspace = idDeclListBASESIZE - 1; 
00042   s->elements = (idDecl *) dmalloc (sizeof (*s->elements) * idDeclListBASESIZE);
00043   s->elements[0] = e;
00044   return (s);
00045 }
00046 
00047 static void
00048 idDeclList_grow (idDeclList s)
00049 {
00050   int i;
00051   idDecl *newelements;
00052   
00053   s->nspace += idDeclListBASESIZE; 
00054   newelements = (idDecl *) dmalloc (sizeof (*newelements) 
00055                                     * (s->nelements + s->nspace));
00056 
00057   for (i = 0; i < s->nelements; i++)
00058     {
00059       newelements[i] = s->elements[i]; 
00060     }
00061   
00062   sfree (s->elements); 
00063   s->elements = newelements;
00064 }
00065 
00066 idDeclList idDeclList_add (idDeclList s, /*@only@*/ idDecl el)
00067 {
00068   if (s->nspace <= 0)
00069     idDeclList_grow (s);
00070   
00071   s->nspace--;
00072   s->elements[s->nelements] = el;
00073   s->nelements++;
00074 
00075   return s;
00076 }
00077 
00078 /*@only@*/ cstring
00079 idDeclList_unparse (idDeclList s)
00080 {
00081    int i;
00082    cstring st = cstring_makeLiteral ("[");
00083 
00084    for (i = 0; i < s->nelements; i++)
00085      {
00086        if (i == 0)
00087          {
00088            st = message ("%q %q", st, idDecl_unparse (s->elements[i]));
00089          }
00090        else
00091          st = message ("%q, %q", st, idDecl_unparse (s->elements[i]));
00092      }
00093    
00094    st = message ("%q ]", st);
00095    return st;
00096 }
00097 
00098 void
00099 idDeclList_free (idDeclList s)
00100 {
00101   int i;
00102   for (i = 0; i < s->nelements; i++)
00103     {
00104       idDecl_free (s->elements[i]);
00105     }
00106   
00107   sfree (s->elements);
00108   sfree (s);
00109 }

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