1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 with System; use System;
37 with Types; use Types;
41 -- This package contains routines for handling the strings table which is
42 -- used to store string constants encountered in the source, and also those
43 -- additional string constants generated by compile time concatenation and
44 -- other similar processing.
46 -- A string constant in this table consists of a series of Char_Code values,
47 -- so that 16-bit character codes can be properly handled if this feature
48 -- is implemented in the scanner.
50 -- There is no guarantee that hashing is used in the implementation, although
51 -- it maybe. This means that the caller cannot count on having the same Id
52 -- value for two identical strings stored separately and also cannot count on
53 -- the two Id values being different.
55 --------------------------------------
56 -- String Table Access Subprograms --
57 --------------------------------------
60 -- Initializes the strings table for a new compilation. Note that
61 -- Initialize must not be called if Tree_Read is used.
64 -- Lock internal tables before calling back end
67 -- Unlock internal tables, in case back end needs to modify them
69 procedure Start_String;
70 -- Sets up for storing a new string in the table. To store a string, a
71 -- call is first made to Start_String, then successive calls are
72 -- made to Store_String_Character to store the characters of the string.
73 -- Finally, a call to End_String terminates the entry and returns it Id.
75 procedure Start_String (S : String_Id);
76 -- Like Start_String with no parameter, except that the contents of the
77 -- new string is initialized to be a copy of the given string. A test is
78 -- made to see if S is the last created string, and if so it is shared,
79 -- rather than copied, this can be particularly helpful for the case of
80 -- a continued concatenaion of string constants.
82 procedure Store_String_Char (C : Char_Code);
83 procedure Store_String_Char (C : Character);
84 -- Store next character of string, see description above for Start_String
86 procedure Store_String_Chars (S : String);
87 procedure Store_String_Chars (S : String_Id);
88 -- Store character codes of given string in sequence
90 procedure Store_String_Int (N : Int);
91 -- Stored decimal representation of integer with possible leading minus
93 procedure Unstore_String_Char;
94 -- Undoes effect of previous Store_String_Char call, used in some error
95 -- situations of unterminated string constants.
97 function End_String return String_Id;
98 -- Terminates current string and returns its Id
100 function String_Length (Id : String_Id) return Nat;
101 -- Returns length of previously stored string
103 function Get_String_Char (Id : String_Id; Index : Int) return Char_Code;
104 -- Obtains the specified character from a stored string. The lower bound
105 -- of stored strings is always 1, so the range is 1 .. String_Length (Id).
107 function String_Equal (L, R : String_Id) return Boolean;
108 -- Determines if two string literals represent the same string
110 procedure String_To_Name_Buffer (S : String_Id);
111 -- Place characters of given string in Name_Buffer, setting Name_Len
113 procedure Add_String_To_Name_Buffer (S : String_Id);
114 -- Append characters of given string to Name_Buffer, updating Name_Len
116 function String_Chars_Address return System.Address;
117 -- Return address of String_Chars table (used by Back_End call to Gigi)
119 function String_From_Name_Buffer return String_Id;
120 -- Given a name stored in Namet.Name_Buffer (length in Namet.Name_Len),
121 -- returns a string of the corresponding value. The value in Name_Buffer
122 -- is unchanged, and the cases of letters are unchanged.
124 function Strings_Address return System.Address;
125 -- Return address of Strings table (used by Back_End call to Gigi)
128 -- Initializes internal tables from current tree file using Tree_Read.
129 -- Note that Initialize should not be called if Tree_Read is used.
130 -- Tree_Read includes all necessary initialization.
132 procedure Tree_Write;
133 -- Writes out internal tables to current tree file using Tree_Write
135 procedure Write_Char_Code (Code : Char_Code);
136 -- Procedure to write a character code value, used for debugging purposes
137 -- for writing character codes. If the character code is in the range
138 -- 16#20# .. 16#7E#, then the single graphic character corresponding to
139 -- the code is output. For any other codes in the range 16#00# .. 16#FF#,
140 -- the code is output as ["hh"] where hh is the two digit hex value for
141 -- the code. Codes greater than 16#FF# are output as ["hhhh"] where hhhh
142 -- is the four digit hex representation of the code value (high order
143 -- byte first). Hex letters are always in upper case.
145 procedure Write_String_Table_Entry (Id : String_Id);
146 -- Writes a string value with enclosing quotes to the current file using
147 -- routines in package Output. Does not write an end of line character.
148 -- This procedure is used for debug output purposes, and also for output
149 -- of strings specified by pragma Linker Option to the ali file. 7-bit
150 -- ASCII graphics (except for double quote and left brace) are output
151 -- literally. The double quote appears as two successive double quotes.
152 -- All other codes, are output as described for Write_Char_Code. For
153 -- example, the string created by folding "A" & ASCII.LF & "Hello" will
154 -- print as "A{0A}Hello". A No_String value prints simply as "no string"
155 -- without surrounding quote marks.
158 pragma Inline (End_String);
159 pragma Inline (String_Length);