Skip several gcc.dg/builtin-dynamic-object-size tests on hppa*-*-hpux*
[official-gcc.git] / gcc / ada / sem_ch2.adb
blobd75c73b4ec31ae09e718dbc5e2490d270744399f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 2 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2023, 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. 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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
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;
32 with Opt; use Opt;
33 with Restrict; use Restrict;
34 with Rident; use Rident;
35 with Sem; use Sem;
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
51 begin
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);
57 end if;
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)))
63 then
64 Check_Restriction (No_Wide_Characters, N);
65 end if;
66 end Analyze_Character_Literal;
68 ------------------------
69 -- Analyze_Identifier --
70 ------------------------
72 procedure Analyze_Identifier (N : Node_Id) is
73 begin
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
76 -- junk identifier.
78 if not Is_Valid_Name (Chars (N)) and then Total_Errors_Detected /= 0 then
79 return;
80 else
81 Find_Direct_Name (N);
82 end if;
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)
92 then
93 Check_Ghost_Context (Entity (N), N);
94 end if;
96 Analyze_Dimension (N);
97 end Analyze_Identifier;
99 -----------------------------
100 -- Analyze_Integer_Literal --
101 -----------------------------
103 procedure Analyze_Integer_Literal (N : Node_Id) is
104 begin
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);
119 end if;
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
129 Str_Elem : Node_Id;
131 begin
132 Set_Etype (N, Any_String);
134 Str_Elem := First (Expressions (N));
135 while Present (Str_Elem) loop
136 Analyze (Str_Elem);
137 Next (Str_Elem);
138 end loop;
139 end Analyze_Interpolated_String_Literal;
141 --------------------------
142 -- Analyze_Real_Literal --
143 --------------------------
145 procedure Analyze_Real_Literal (N : Node_Id) is
146 begin
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
156 begin
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);
162 end if;
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);
170 end if;
172 if Comes_From_Source (N) and then Has_Wide_Character (N) then
173 Check_Restriction (No_Wide_Characters, N);
174 end if;
175 end Analyze_String_Literal;
177 end Sem_Ch2;