1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, 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 Namet
; use Namet
;
30 with Restrict
; use Restrict
;
31 with Rident
; use Rident
;
32 with Sem_Ch8
; use Sem_Ch8
;
33 with Sem_Dim
; use Sem_Dim
;
34 with Sinfo
; use Sinfo
;
35 with Stand
; use Stand
;
36 with Uintp
; use Uintp
;
38 package body Sem_Ch2
is
40 -------------------------------
41 -- Analyze_Character_Literal --
42 -------------------------------
44 procedure Analyze_Character_Literal
(N
: Node_Id
) is
46 -- The type is eventually inherited from the context. If expansion
47 -- has already established the proper type, do not modify it.
49 if No
(Etype
(N
)) then
50 Set_Etype
(N
, Any_Character
);
53 Set_Is_Static_Expression
(N
);
55 if Comes_From_Source
(N
)
56 and then not In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
)))
58 Check_Restriction
(No_Wide_Characters
, N
);
60 end Analyze_Character_Literal
;
62 ------------------------
63 -- Analyze_Identifier --
64 ------------------------
66 procedure Analyze_Identifier
(N
: Node_Id
) is
68 -- Ignore call if prior errors, and identifier has no name, since
69 -- this is the result of some kind of previous error generating a
72 if not Is_Valid_Name
(Chars
(N
)) and then Total_Errors_Detected
/= 0 then
78 Analyze_Dimension
(N
);
79 end Analyze_Identifier
;
81 -----------------------------
82 -- Analyze_Integer_Literal --
83 -----------------------------
85 procedure Analyze_Integer_Literal
(N
: Node_Id
) is
87 -- As a lexical element, an integer literal has type Universal_Integer,
88 -- i.e., is compatible with any integer type. This is semantically
89 -- consistent and simplifies type checking and subsequent constant
90 -- folding when needed. An exception is caused by 64-bit modular types,
91 -- whose upper bound is not representable in a nonstatic context that
92 -- will use 64-bit integers at run time. For such cases, we need to
93 -- preserve the information that the analyzed literal has that modular
94 -- type. For simplicity, we preserve the information for all integer
95 -- literals that result from a modular operation. This happens after
96 -- prior analysis (or construction) of the literal, and after type
97 -- checking and resolution.
99 if No
(Etype
(N
)) or else not Is_Modular_Integer_Type
(Etype
(N
)) then
100 Set_Etype
(N
, Universal_Integer
);
103 Set_Is_Static_Expression
(N
);
104 end Analyze_Integer_Literal
;
106 --------------------------
107 -- Analyze_Real_Literal --
108 --------------------------
110 procedure Analyze_Real_Literal
(N
: Node_Id
) is
112 Set_Etype
(N
, Universal_Real
);
113 Set_Is_Static_Expression
(N
);
114 end Analyze_Real_Literal
;
116 ----------------------------
117 -- Analyze_String_Literal --
118 ----------------------------
120 procedure Analyze_String_Literal
(N
: Node_Id
) is
122 -- The type is eventually inherited from the context. If expansion
123 -- has already established the proper type, do not modify it.
125 if No
(Etype
(N
)) then
126 Set_Etype
(N
, Any_String
);
129 -- String literals are static in Ada 95. Note that if the subtype
130 -- turns out to be non-static, then the Is_Static_Expression flag
131 -- will be reset in Eval_String_Literal.
133 if Ada_Version
>= Ada_95
then
134 Set_Is_Static_Expression
(N
);
137 if Comes_From_Source
(N
) and then Has_Wide_Character
(N
) then
138 Check_Restriction
(No_Wide_Characters
, N
);
140 end Analyze_String_Literal
;