OSDN Git Service

2006-10-31 Bob Duff <duff@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / stringt.h
1 /****************************************************************************
2  *                                                                          *
3  *                         GNAT COMPILER COMPONENTS                         *
4  *                                                                          *
5  *                              S T R I N G T                               *
6  *                                                                          *
7  *                              C Header File                               *
8  *                                                                          *
9  *          Copyright (C) 1992-2003 Free Software Foundation, Inc.          *
10  *                                                                          *
11  * GNAT is free software;  you can  redistribute it  and/or modify it under *
12  * terms of the  GNU General Public License as published  by the Free Soft- *
13  * ware  Foundation;  either version 2,  or (at your option) any later ver- *
14  * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
15  * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
16  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License *
17  * for  more details.  You should have  received  a copy of the GNU General *
18  * Public License  distributed with GNAT;  see file COPYING.  If not, write *
19  * to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, *
20  * Boston, MA 02110-1301, USA.                                              *
21  *                                                                          *
22  * GNAT was originally developed  by the GNAT team at  New York University. *
23  * Extensive contributions were provided by Ada Core Technologies Inc.      *
24  *                                                                          *
25  ****************************************************************************/
26
27 /* This file is the C file that corresponds to the Ada package spec
28    Stringt. It was created manually from stringt.ads and stringt.adb
29
30    Note: only the access functions are provided, since the tree transformer
31    is not allowed to modify the tree or its auxiliary structures.
32
33    This package contains routines for handling the strings table which is
34    used to store string constants encountered in the source, and also those
35    additional string constants generated by compile time concatenation and
36    other similar processing.
37
38    A string constant in this table consists of a series of Char_Code values,
39    so that 16-bit character codes can be properly handled if this feature is
40    implemented in the scanner.
41
42    There is no guarantee that hashing is used in the implementation. This
43    means that the caller cannot count on having the same Id value for two
44    identical strings stored separately.
45
46    The String_Id values reference entries in the Strings table, which
47    contains String_Entry records that record the length of each stored string
48    and its starting location in the String_Chars table.  */
49
50 struct String_Entry
51 {
52   Int String_Index;
53   Int Length;
54 };
55
56 /* Pointer to string entry vector. This pointer is passed to the tree
57    transformer and stored in a global location.  */
58 extern struct String_Entry *Strings_Ptr;
59
60 /* Pointer to name characters table. This pointer is passed to the tree
61    transformer and stored in a global location for access from here. The
62    String_Index values are subscripts into this array.  */
63 extern Char_Code *String_Chars_Ptr;
64
65
66 /* String_Length returns the length of the specified string.  */
67 INLINE Int String_Length (String_Id);
68
69 INLINE Int
70 String_Length (String_Id Id)
71 {
72   return Strings_Ptr[Id - First_String_Id].Length;
73 }
74
75
76 /* Get_String_Char obtains the specified character from a stored string.  The
77    lower bound of stored strings is always 1, so the range of values is 1 to
78    String_Length (Id).  */
79 INLINE Char_Code Get_String_Char (String_Id, Int);
80
81 INLINE Char_Code
82 Get_String_Char (String_Id Id, Int Index)
83 {
84   return
85     String_Chars_Ptr
86       [Strings_Ptr[Id - First_String_Id].String_Index + Index - 1];
87 }