2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / gcc / ada / stringt.ads
blob92b74e2c049e7e46a2afbff3895aad7dcb9c1f78
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S T R I N G T --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2013, 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 3, 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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with System; use System;
33 with Types; use Types;
35 package Stringt is
36 pragma Elaborate_Body;
37 -- This is to make sure Null_String_Id is properly initialized
39 -- This package contains routines for handling the strings table which is
40 -- used to store string constants encountered in the source, and also those
41 -- additional string constants generated by compile time concatenation and
42 -- other similar processing.
44 -- A string constant in this table consists of a series of Char_Code values,
45 -- so that 16-bit character codes can be properly handled if this feature
46 -- is implemented in the scanner.
48 -- There is no guarantee that hashing is used in the implementation, although
49 -- it maybe. This means that the caller cannot count on having the same Id
50 -- value for two identical strings stored separately and also cannot count on
51 -- the two Id values being different.
53 Null_String_Id : String_Id;
54 -- Gets set to a null string with length zero
56 --------------------------------------
57 -- String Table Access Subprograms --
58 --------------------------------------
60 procedure Initialize;
61 -- Initializes the strings table for a new compilation. Note that
62 -- Initialize must not be called if Tree_Read is used.
64 procedure Lock;
65 -- Lock internal tables before calling back end
67 procedure Unlock;
68 -- Unlock internal tables, in case back end needs to modify them
70 procedure Mark;
71 -- Take a snapshot of the internal tables. Used in conjunction with Release
72 -- when computing temporary string values that need not be preserved.
74 procedure Release;
75 -- Restore the internal tables to the situation when Mark was last called.
76 -- If Release is called with no prior call to Mark, the entire string table
77 -- is cleared to its initial (empty) setting.
79 procedure Start_String;
80 -- Sets up for storing a new string in the table. To store a string, a
81 -- call is first made to Start_String, then successive calls are
82 -- made to Store_String_Character to store the characters of the string.
83 -- Finally, a call to End_String terminates the entry and returns it Id.
85 procedure Start_String (S : String_Id);
86 -- Like Start_String with no parameter, except that the contents of the
87 -- new string is initialized to be a copy of the given string. A test is
88 -- made to see if S is the last created string, and if so it is shared,
89 -- rather than copied, this can be particularly helpful for the case of
90 -- a continued concatenation of string constants.
92 procedure Store_String_Char (C : Char_Code);
93 procedure Store_String_Char (C : Character);
94 -- Store next character of string, see description above for Start_String
96 procedure Store_String_Chars (S : String);
97 procedure Store_String_Chars (S : String_Id);
98 -- Store character codes of given string in sequence
100 procedure Store_String_Int (N : Int);
101 -- Stored decimal representation of integer with possible leading minus
103 procedure Unstore_String_Char;
104 -- Undoes effect of previous Store_String_Char call, used in some error
105 -- situations of unterminated string constants.
107 function End_String return String_Id;
108 -- Terminates current string and returns its Id
110 function String_Length (Id : String_Id) return Nat;
111 -- Returns length of previously stored string
113 function Get_String_Char (Id : String_Id; Index : Int) return Char_Code;
114 pragma Inline (Get_String_Char);
115 -- Obtains the specified character from a stored string. The lower bound
116 -- of stored strings is always 1, so the range is 1 .. String_Length (Id).
118 function String_Equal (L, R : String_Id) return Boolean;
119 -- Determines if two string literals represent the same string
121 procedure String_To_Name_Buffer (S : String_Id);
122 -- Place characters of given string in Name_Buffer, setting Name_Len.
123 -- Error if any characters are out of Character range. Does not attempt
124 -- to do any encoding of any characters.
126 procedure Add_String_To_Name_Buffer (S : String_Id);
127 -- Append characters of given string to Name_Buffer, updating Name_Len.
128 -- Error if any characters are out of Character range. Does not attempt
129 -- to do any encoding of any characters.
131 function String_Chars_Address return System.Address;
132 -- Return address of String_Chars table (used by Back_End call to Gigi)
134 function String_From_Name_Buffer return String_Id;
135 -- Given a name stored in Namet.Name_Buffer (length in Namet.Name_Len),
136 -- returns a string of the corresponding value. The value in Name_Buffer
137 -- is unchanged, and the cases of letters are unchanged.
139 function Strings_Address return System.Address;
140 -- Return address of Strings table (used by Back_End call to Gigi)
142 procedure Tree_Read;
143 -- Initializes internal tables from current tree file using the relevant
144 -- Table.Tree_Read routines. Note that Initialize should not be called if
145 -- Tree_Read is used. Tree_Read includes all necessary initialization.
147 procedure Tree_Write;
148 -- Writes out internal tables to current tree file using the relevant
149 -- Table.Tree_Write routines.
151 procedure Write_Char_Code (Code : Char_Code);
152 -- Procedure to write a character code value, used for debugging purposes
153 -- for writing character codes. If the character code is in the range
154 -- 16#20# .. 16#7E#, then the single graphic character corresponding to
155 -- the code is output. For any other codes in the range 16#00# .. 16#FF#,
156 -- the code is output as ["hh"] where hh is the two digit hex value for
157 -- the code. Codes greater than 16#FF# are output as ["hhhh"] where hhhh
158 -- is the four digit hex representation of the code value (high order
159 -- byte first). Hex letters are always in lower case.
161 procedure Write_String_Table_Entry (Id : String_Id);
162 -- Writes a string value with enclosing quotes to the current file using
163 -- routines in package Output. Does not write an end of line character.
164 -- This procedure is used for debug output purposes, and also for output
165 -- of strings specified by pragma Linker Option to the ali file. 7-bit
166 -- ASCII graphics (except for double quote) are output literally.
167 -- The double quote appears as two successive double quotes.
168 -- All other codes, are output as described for Write_Char_Code. For
169 -- example, the string created by folding "A" & ASCII.HT & "Hello" will
170 -- print as "A["09"]Hello". A No_String value prints simply as "no string"
171 -- without surrounding quote marks.
173 private
174 pragma Inline (End_String);
175 pragma Inline (String_Length);
177 end Stringt;