Name change (It's hitacho micro systems, not hitachi data systems)
[deliverable/binutils-gdb.git] / gdb / obstack.h
old mode 100644 (file)
new mode 100755 (executable)
index 069afc6..2e80c9c
 /* obstack.h - object stack macros
-   Copyright (C) 1986, 1988 Free Software Foundation, Inc.
-
-                      NO WARRANTY
-
-  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
-NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
-WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
-RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
-WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
-AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
-DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
-CORRECTION.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
-STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
-WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
-LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
-OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
-DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
-A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
-PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
-
-               GENERAL PUBLIC LICENSE TO COPY
-
-  1. You may copy and distribute verbatim copies of this source file
-as you receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy a valid copyright notice "Copyright
-(C) 1988 Free Software Foundation, Inc."; and include following the
-copyright notice a verbatim copy of the above disclaimer of warranty
-and of this License.  You may charge a distribution fee for the
-physical act of transferring a copy.
-
-  2. You may modify your copy or copies of this source file or
-any portion of it, and copy and distribute such modifications under
-the terms of Paragraph 1 above, provided that you also do the following:
-
-    a) cause the modified files to carry prominent notices stating
-    that you changed the files and the date of any change; and
-
-    b) cause the whole of any work that you distribute or publish,
-    that in whole or in part contains or is a derivative of this
-    program or any part thereof, to be licensed at no charge to all
-    third parties on terms identical to those contained in this
-    License Agreement (except that you may choose to grant more extensive
-    warranty protection to some or all third parties, at your option).
-
-    c) You may charge a distribution fee for the physical act of
-    transferring a copy, and you may at your option offer warranty
-    protection in exchange for a fee.
-
-Mere aggregation of another unrelated program with this program (or its
-derivative) on a volume of a storage or distribution medium does not bring
-the other program under the scope of these terms.
-
-  3. You may copy and distribute this program (or a portion or derivative
-of it, under Paragraph 2) in object code or executable form under the terms
-of Paragraphs 1 and 2 above provided that you also do one of the following:
-
-    a) accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of
-    Paragraphs 1 and 2 above; or,
-
-    b) accompany it with a written offer, valid for at least three
-    years, to give any third party free (except for a nominal
-    shipping charge) a complete machine-readable copy of the
-    corresponding source code, to be distributed under the terms of
-    Paragraphs 1 and 2 above; or,
-
-    c) accompany it with the information you received as to where the
-    corresponding source code may be obtained.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form alone.)
-
-For an executable file, complete source code means all the source code for
-all modules it contains; but, as a special exception, it need not include
-source code for modules which are standard libraries that accompany the
-operating system on which the executable file runs.
-
-  4. You may not copy, sublicense, distribute or transfer this program
-except as expressly provided under this License Agreement.  Any attempt
-otherwise to copy, sublicense, distribute or transfer this program is void and
-your rights to use the program under this License agreement shall be
-automatically terminated.  However, parties who have received computer
-software programs from you with this License Agreement will not have
-their licenses terminated so long as such parties remain in full compliance.
-
-  5. If you wish to incorporate parts of this program into other free
-programs whose distribution conditions are different, write to the Free
-Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
-worked out a simple rule that can be stated here, but we will often permit
-this.  We will be guided by the two goals of preserving the free status of
-all derivatives our free software and of promoting the sharing and reuse of
-software.
-
-
-In other words, you are welcome to use, share and improve this program.
-You are forbidden to forbid anyone else to use, share and improve
-what you give them.   Help stamp out software-hoarding!  */
+   Copyright (C) 1988 Free Software Foundation, Inc.
 
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 1, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 /* Summary:
 
@@ -128,7 +40,7 @@ Each of the obstack macros expects a pointer to such a structure
 as the first argument.
 
 One motivation for this package is the problem of growing char strings
-in symbol tables.  Unless you are "facist pig with a read-only mind"
+in symbol tables.  Unless you are "fascist pig with a read-only mind"
 [Gosper's immortal quote from HAKMEM item 154, out of context] you
 would not like to put any arbitrary upper limit on the length of your
 symbols.
@@ -147,7 +59,7 @@ When the name is complete, finalize it.  Then, if the symbol exists already,
 free the newly read name.
 
 The way we do this is to take a large chunk, allocating memory from
-low addresses.  When you want to build a aymbol in the chunk you just
+low addresses.  When you want to build a symbol in the chunk you just
 add chars above the current "high water mark" in the chunk.  When you
 have finished adding chars, because you got to the end of the symbol,
 you know how long the chars are, and you can create a new object.
@@ -164,8 +76,8 @@ change its address during its lifetime.
 
 When the chars burst over a chunk boundary, we allocate a larger
 chunk, and then copy the partly formed object from the end of the old
-chunk to the beggining of the new larger chunk.  We then carry on
-accreting characters to the end of the object as we normaly would.
+chunk to the beginning of the new larger chunk.  We then carry on
+accreting characters to the end of the object as we normally would.
 
 A special macro is provided to add a single char at a time to a
 growing object.  This allows the use of register variables, which
@@ -191,9 +103,46 @@ Summary:
 #ifndef __OBSTACKS__
 #define __OBSTACKS__
 \f
+/* We use subtraction of (char *)0 instead of casting to int
+   because on word-addressable machines a simple cast to int
+   may ignore the byte-within-word field of the pointer.  */
+
+#ifndef __PTR_TO_INT
+#define __PTR_TO_INT(P) ((P) - (char *)0)
+#endif
+
+#ifndef __INT_TO_PTR
+#define __INT_TO_PTR(P) ((P) + (char *)0)
+#endif
+
+struct _obstack_chunk          /* Lives at front of each chunk. */
+{
+  char  *limit;                        /* 1 past end of this chunk */
+  struct _obstack_chunk *prev; /* address of prior chunk or NULL */
+  char contents[4];            /* objects begin here */
+};
+
+struct obstack         /* control current object in current chunk */
+{
+  long chunk_size;             /* preferred size to allocate chunks in */
+  struct _obstack_chunk* chunk;        /* address of current struct obstack_chunk */
+  char *object_base;           /* address of object we are building */
+  char *next_free;             /* where to add next char to current object */
+  char *chunk_limit;           /* address of char after current chunk */
+  int  temp;                   /* Temporary for some macros.  */
+  int   alignment_mask;                /* Mask of alignment for each object. */
+#ifdef __STDC__
+  void  *(*chunkfun) ();       /* User's fcn to allocate a chunk.  */
+#else
+  char  *(*chunkfun) ();       /* User's fcn to allocate a chunk.  */
+#endif
+  void (*freefun) ();          /* User's function to free a chunk.  */
+};
+\f
 #ifdef __STDC__
 
-/* Do the function-declarations before defining the macros.  */
+/* Do the function-declarations after the structs
+   but before defining the macros.  */
 
 void obstack_init (struct obstack *obstack);
 
@@ -210,6 +159,8 @@ void obstack_grow (struct obstack *obstack, void *data, int size);
 void obstack_grow0 (struct obstack *obstack, void *data, int size);
 
 void obstack_1grow (struct obstack *obstack, int data_char);
+void obstack_ptr_grow (struct obstack *obstack, void *data);
+void obstack_int_grow (struct obstack *obstack, int data);
 
 void * obstack_finish (struct obstack *obstack);
 
@@ -217,10 +168,12 @@ int obstack_object_size (struct obstack *obstack);
 
 int obstack_room (struct obstack *obstack);
 void obstack_1grow_fast (struct obstack *obstack, int data_char);
+void obstack_ptr_grow_fast (struct obstack *obstack, void *data);
+void obstack_int_grow_fast (struct obstack *obstack, int data);
 void obstack_blank_fast (struct obstack *obstack, int size);
 
-void * object_base (struct obstack *obstack);
-void * object_next_free (struct obstack *obstack);
+void * obstack_base (struct obstack *obstack);
+void * obstack_next_free (struct obstack *obstack);
 int obstack_alignment_mask (struct obstack *obstack);
 int obstack_chunk_size (struct obstack *obstack);
 
@@ -229,26 +182,6 @@ int obstack_chunk_size (struct obstack *obstack);
 /* Non-ANSI C cannot really support alternative functions for these macros,
    so we do not declare them.  */
 \f
-struct _obstack_chunk          /* Lives at front of each chunk. */
-{
-  char  *limit;                        /* 1 past end of this chunk */
-  struct _obstack_chunk *prev; /* address of prior chunk or NULL */
-  char contents[4];            /* objects begin here */
-};
-
-struct obstack         /* control current object in current chunk */
-{
-  long chunk_size;             /* preferred size to allocate chunks in */
-  struct _obstack_chunk* chunk;        /* address of current struct obstack_chunk */
-  char *object_base;           /* address of object we are building */
-  char *next_free;             /* where to add next char to current object */
-  char *chunk_limit;           /* address of char after current chunk */
-  int  temp;                   /* Temporary for some macros.  */
-  int   alignment_mask;                /* Mask of alignment for each object. */
-  struct _obstack_chunk *(*chunkfun) (); /* User's fcn to allocate a chunk.  */
-  void (*freefun) ();          /* User's function to free a chunk.  */
-};
-
 /* Pointer to beginning of object being allocated or to be allocated next.
    Note that this might not be the final address of the object
    because a new chunk might be needed to hold the final size.  */
@@ -268,23 +201,21 @@ struct obstack            /* control current object in current chunk */
 #define obstack_alignment_mask(h) ((h)->alignment_mask)
 
 #define obstack_init(h) \
-  _obstack_begin ((h), 4096 - 4, 4, obstack_chunk_alloc, obstack_chunk_free)
+  _obstack_begin ((h), 0, 0, obstack_chunk_alloc, obstack_chunk_free)
 
 #define obstack_begin(h, size) \
-  _obstack_begin ((h), (size), 4, obstack_chunk_alloc, obstack_chunk_free)
+  _obstack_begin ((h), (size), 0, obstack_chunk_alloc, obstack_chunk_free)
 
 #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar)
 
 #define obstack_blank_fast(h,n) ((h)->next_free += (n))
 \f
-#if defined (__GNU__) && defined (__STDC__)
+#if defined (__GNUC__) && defined (__STDC__)
 
-/* For GNU C we can define these macros to compute all args only once
+/* For GNU C, if not -traditional,
+   we can define these macros to compute all args only once
    without using a global variable.
-   Also, we can avoid using the `temp' slot, to make faster code.
-
-   By checking both __GNU__ and __STDC__, we can make sure
-   both GNU language extensions and ANSI preprocessing are available.  */
+   Also, we can avoid using the `temp' slot, to make faster code.  */
 
 #define obstack_object_size(OBSTACK)                                   \
   ({ struct obstack *__o = (OBSTACK);                                  \
@@ -320,10 +251,31 @@ struct obstack            /* control current object in current chunk */
    *(__o->next_free)++ = (datum);                                      \
    (void) 0; })
 
+/* These assume that the obstack alignment is good enough for pointers or ints,
+   and that the data added so far to the current object
+   shares that much alignment.  */
+   
+#define obstack_ptr_grow(OBSTACK,datum)                                        \
+({ struct obstack *__o = (OBSTACK);                                    \
+   ((__o->next_free + sizeof (void *) > __o->chunk_limit)              \
+    ? _obstack_newchunk (__o, sizeof (void *)) : 0),                   \
+   *(*(void ***)&__o->next_free)++ = ((void *)datum);                  \
+   (void) 0; })
+
+#define obstack_int_grow(OBSTACK,datum)                                        \
+({ struct obstack *__o = (OBSTACK);                                    \
+   ((__o->next_free + sizeof (int) > __o->chunk_limit)                 \
+    ? _obstack_newchunk (__o, sizeof (int)) : 0),                      \
+   *(*(int **)&__o->next_free)++ = ((int)datum);                               \
+   (void) 0; })
+
+#define obstack_ptr_grow_fast(h,aptr) (*(*(void ***)&(h)->next_free)++ = (void *)aptr)
+#define obstack_int_grow_fast(h,aint) (*(*(int **)&(h)->next_free)++ = (int)aint)
+
 #define obstack_blank(OBSTACK,length)                                  \
 ({ struct obstack *__o = (OBSTACK);                                    \
    int __len = (length);                                               \
-   ((__o->next_free + __len > __o->chunk_limit)                                \
+   ((__o->chunk_limit - __o->next_free < __len)                                \
     ? _obstack_newchunk (__o, __len) : 0);                             \
    __o->next_free += __len;                                            \
    (void) 0; })
@@ -347,33 +299,28 @@ struct obstack            /* control current object in current chunk */
 ({ struct obstack *__o = (OBSTACK);                                    \
    void *value = (void *) __o->object_base;                            \
    __o->next_free                                                      \
-     = (char*)((int)(__o->next_free+__o->alignment_mask)               \
-              & ~ (__o->alignment_mask));                              \
+     = __INT_TO_PTR ((__PTR_TO_INT (__o->next_free)+__o->alignment_mask)\
+                    & ~ (__o->alignment_mask));                        \
    ((__o->next_free - (char *)__o->chunk                               \
      > __o->chunk_limit - (char *)__o->chunk)                          \
-    ? __o->next_free = __o->chunk_limit : 0);                          \
+    ? (__o->next_free = __o->chunk_limit) : 0);                                \
    __o->object_base = __o->next_free;                                  \
    value; })
 
 #define obstack_free(OBSTACK, OBJ)                                     \
 ({ struct obstack *__o = (OBSTACK);                                    \
    void *__obj = (OBJ);                                                        \
-   if (__obj >= (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
+   if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit)  \
      __o->next_free = __o->object_base = __obj;                                \
    else (obstack_free) (__o, __obj); })
 \f
-#else /* not __GNU__ */
-
-/* The non-GNU macros copy the obstack-pointer into this global variable
-   to avoid multiple evaluation.  */
-
-extern struct obstack *_obstack;
+#else /* not __GNUC__ or not __STDC__ */
 
 #define obstack_object_size(h) \
- (unsigned) (_obstack = (h), (h)->next_free - (h)->object_base)
+ (unsigned) ((h)->next_free - (h)->object_base)
 
 #define obstack_room(h)                \
- (unsigned) (_obstack = (h), (h)->chunk_limit - (h)->next_free)
+ (unsigned) ((h)->chunk_limit - (h)->next_free)
 
 #define obstack_grow(h,where,length)                                   \
 ( (h)->temp = (length),                                                        \
@@ -385,7 +332,7 @@ extern struct obstack *_obstack;
 #define obstack_grow0(h,where,length)                                  \
 ( (h)->temp = (length),                                                        \
   (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit)                 \
-   ? _obstack_newchunk ((h), (h)->temp + 1) : 0),                              \
+   ? _obstack_newchunk ((h), (h)->temp + 1) : 0),                      \
   bcopy (where, (h)->next_free, (h)->temp),                            \
   (h)->next_free += (h)->temp,                                         \
   *((h)->next_free)++ = 0)
@@ -395,9 +342,22 @@ extern struct obstack *_obstack;
    ? _obstack_newchunk ((h), 1) : 0),                                  \
   *((h)->next_free)++ = (datum))
 
+#define obstack_ptr_grow(h,datum)                                      \
+( (((h)->next_free + sizeof (char *) > (h)->chunk_limit)               \
+   ? _obstack_newchunk ((h), sizeof (char *)) : 0),                    \
+  *(*(char ***)&(h)->next_free)++ = ((char *)datum))
+
+#define obstack_int_grow(h,datum)                                      \
+( (((h)->next_free + sizeof (int) > (h)->chunk_limit)                  \
+   ? _obstack_newchunk ((h), sizeof (int)) : 0),                       \
+  *(*(int **)&(h)->next_free)++ = ((int)datum))
+
+#define obstack_ptr_grow_fast(h,aptr) (*(*(char ***)&(h)->next_free)++ = (char *)aptr)
+#define obstack_int_grow_fast(h,aint) (*(*(int **)&(h)->next_free)++ = (int)aint)
+
 #define obstack_blank(h,length)                                                \
 ( (h)->temp = (length),                                                        \
-  (((h)->next_free + (h)->temp > (h)->chunk_limit)                     \
+  (((h)->chunk_limit - (h)->next_free < (h)->temp)                     \
    ? _obstack_newchunk ((h), (h)->temp) : 0),                          \
   (h)->next_free += (h)->temp)
 
@@ -411,15 +371,15 @@ extern struct obstack *_obstack;
  (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
 
 #define obstack_finish(h)                                              \
-( (h)->temp = (int) (h)->object_base,                                  \
+( (h)->temp = __PTR_TO_INT ((h)->object_base),                         \
   (h)->next_free                                                       \
-    = (char*)((int)((h)->next_free+(h)->alignment_mask)                        \
-             & ~ ((h)->alignment_mask)),                               \
+    = __INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask)        \
+                   & ~ ((h)->alignment_mask)),                         \
   (((h)->next_free - (char *)(h)->chunk                                        \
     > (h)->chunk_limit - (char *)(h)->chunk)                           \
-   ? (h)->next_free = (h)->chunk_limit : 0),                           \
+   ? ((h)->next_free = (h)->chunk_limit) : 0),                         \
   (h)->object_base = (h)->next_free,                                   \
-  (char *) (h)->temp)
+  __INT_TO_PTR ((h)->temp))
 
 #ifdef __STDC__
 #define obstack_free(h,obj)                                            \
@@ -427,7 +387,7 @@ extern struct obstack *_obstack;
   (((h)->temp >= 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\
    ? (int) ((h)->next_free = (h)->object_base                          \
            = (h)->temp + (char *) (h)->chunk)                          \
-   : (int) (obstack_free) ((h), (h)->temp + (char *) (h)->chunk)))
+   : ((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0)))
 #else
 #define obstack_free(h,obj)                                            \
 ( (h)->temp = (char *)(obj) - (char *) (h)->chunk,                     \
@@ -437,7 +397,20 @@ extern struct obstack *_obstack;
    : (int) _obstack_free ((h), (h)->temp + (char *) (h)->chunk)))
 #endif
 
-#endif /* not __GNU__ */
+#endif /* not __GNUC__ or not __STDC__ */
+
+/* Declare the external functions we use; they are in obstack.c.  */
+
+#ifdef __STDC__
+  extern int _obstack_newchunk (struct obstack *h, int length);
+  extern int _obstack_free (struct obstack *h, void *obj);
+  extern void _obstack_begin (struct obstack *h, int size, int alignment,
+                             void *(*chunkfun) (), void (*freefun) ());
+#else
+  extern int _obstack_newchunk ();
+  extern int _obstack_free ();
+  extern void _obstack_begin ();
+#endif
 
 #endif /* not __OBSTACKS__ */
 
This page took 0.02953 seconds and 4 git commands to generate.