1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
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. 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Einfo
; use Einfo
;
28 with Einfo
.Utils
; use Einfo
.Utils
;
29 with Ghost
; use Ghost
;
30 with Namet
; use Namet
;
31 with Nlists
; use Nlists
;
33 with Restrict
; use Restrict
;
34 with Rident
; use Rident
;
36 with Sem_Ch8
; use Sem_Ch8
;
37 with Sem_Dim
; use Sem_Dim
;
38 with Sinfo
; use Sinfo
;
39 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
40 with Sinfo
.Utils
; use Sinfo
.Utils
;
41 with Stand
; use Stand
;
42 with Uintp
; use Uintp
;
44 package body Sem_Ch2
is
46 -------------------------------
47 -- Analyze_Character_Literal --
48 -------------------------------
50 procedure Analyze_Character_Literal
(N
: Node_Id
) is
52 -- The type is eventually inherited from the context. If expansion
53 -- has already established the proper type, do not modify it.
55 if No
(Etype
(N
)) then
56 Set_Etype
(N
, Any_Character
);
59 Set_Is_Static_Expression
(N
);
61 if Comes_From_Source
(N
)
62 and then not In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
)))
64 Check_Restriction
(No_Wide_Characters
, N
);
66 end Analyze_Character_Literal
;
68 ------------------------
69 -- Analyze_Identifier --
70 ------------------------
72 procedure Analyze_Identifier
(N
: Node_Id
) is
74 -- Ignore call if prior errors, and identifier has no name, since
75 -- this is the result of some kind of previous error generating a
78 if not Is_Valid_Name
(Chars
(N
)) and then Total_Errors_Detected
/= 0 then
84 -- A Ghost entity must appear in a specific context. Only do this
85 -- checking on non-overloaded expressions, as otherwise we need to
86 -- wait for resolution, and the checking is done in Resolve_Entity_Name.
88 if Nkind
(N
) in N_Expanded_Name | N_Identifier
89 and then Present
(Entity
(N
))
90 and then Is_Ghost_Entity
(Entity
(N
))
91 and then not Is_Overloaded
(N
)
93 Check_Ghost_Context
(Entity
(N
), N
);
96 Analyze_Dimension
(N
);
97 end Analyze_Identifier
;
99 -----------------------------
100 -- Analyze_Integer_Literal --
101 -----------------------------
103 procedure Analyze_Integer_Literal
(N
: Node_Id
) is
105 -- As a lexical element, an integer literal has type Universal_Integer,
106 -- i.e., is compatible with any integer type. This is semantically
107 -- consistent and simplifies type checking and subsequent constant
108 -- folding when needed. An exception is caused by 64-bit modular types,
109 -- whose upper bound is not representable in a nonstatic context that
110 -- will use 64-bit integers at run time. For such cases, we need to
111 -- preserve the information that the analyzed literal has that modular
112 -- type. For simplicity, we preserve the information for all integer
113 -- literals that result from a modular operation. This happens after
114 -- prior analysis (or construction) of the literal, and after type
115 -- checking and resolution.
117 if No
(Etype
(N
)) or else not Is_Modular_Integer_Type
(Etype
(N
)) then
118 Set_Etype
(N
, Universal_Integer
);
121 Set_Is_Static_Expression
(N
);
122 end Analyze_Integer_Literal
;
124 -----------------------------------------
125 -- Analyze_Interpolated_String_Literal --
126 -----------------------------------------
128 procedure Analyze_Interpolated_String_Literal
(N
: Node_Id
) is
132 Set_Etype
(N
, Any_String
);
134 Str_Elem
:= First
(Expressions
(N
));
135 while Present
(Str_Elem
) loop
139 end Analyze_Interpolated_String_Literal
;
141 --------------------------
142 -- Analyze_Real_Literal --
143 --------------------------
145 procedure Analyze_Real_Literal
(N
: Node_Id
) is
147 Set_Etype
(N
, Universal_Real
);
148 Set_Is_Static_Expression
(N
);
149 end Analyze_Real_Literal
;
151 ----------------------------
152 -- Analyze_String_Literal --
153 ----------------------------
155 procedure Analyze_String_Literal
(N
: Node_Id
) is
157 -- The type is eventually inherited from the context. If expansion
158 -- has already established the proper type, do not modify it.
160 if No
(Etype
(N
)) then
161 Set_Etype
(N
, Any_String
);
164 -- String literals are static in Ada 95. Note that if the subtype
165 -- turns out to be non-static, then the Is_Static_Expression flag
166 -- will be reset in Eval_String_Literal.
168 if Ada_Version
>= Ada_95
then
169 Set_Is_Static_Expression
(N
);
172 if Comes_From_Source
(N
) and then Has_Wide_Character
(N
) then
173 Check_Restriction
(No_Wide_Characters
, N
);
175 end Analyze_String_Literal
;