]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/sem_ch2.adb
[Ada] Variable-sized node types
[thirdparty/gcc.git] / gcc / ada / sem_ch2.adb
CommitLineData
996ae0b0
RK
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- S E M _ C H 2 --
6-- --
7-- B o d y --
8-- --
8d0d46f4 9-- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
996ae0b0
RK
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- --
b5c84c3c 13-- ware Foundation; either version 3, or (at your option) any later ver- --
996ae0b0
RK
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 --
b5c84c3c
RD
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. --
996ae0b0
RK
20-- --
21-- GNAT was originally developed by the GNAT team at New York University. --
71ff80dc 22-- Extensive contributions were provided by Ada Core Technologies Inc. --
996ae0b0
RK
23-- --
24------------------------------------------------------------------------------
25
26with Atree; use Atree;
76f9c7f4
BD
27with Einfo; use Einfo;
28with Einfo.Utils; use Einfo.Utils;
39f4e199 29with Namet; use Namet;
996ae0b0
RK
30with Opt; use Opt;
31with Restrict; use Restrict;
6e937c1c 32with Rident; use Rident;
996ae0b0 33with Sem_Ch8; use Sem_Ch8;
dec6faf1 34with Sem_Dim; use Sem_Dim;
76f9c7f4
BD
35with Sinfo; use Sinfo;
36with Sinfo.Nodes; use Sinfo.Nodes;
996ae0b0 37with Stand; use Stand;
82c80734 38with Uintp; use Uintp;
996ae0b0
RK
39
40package body Sem_Ch2 is
41
42 -------------------------------
43 -- Analyze_Character_Literal --
44 -------------------------------
45
46 procedure Analyze_Character_Literal (N : Node_Id) is
47 begin
996ae0b0
RK
48 -- The type is eventually inherited from the context. If expansion
49 -- has already established the proper type, do not modify it.
50
51 if No (Etype (N)) then
52 Set_Etype (N, Any_Character);
53 end if;
54
55 Set_Is_Static_Expression (N);
56
57 if Comes_From_Source (N)
82c80734 58 and then not In_Character_Range (UI_To_CC (Char_Literal_Value (N)))
996ae0b0
RK
59 then
60 Check_Restriction (No_Wide_Characters, N);
61 end if;
62 end Analyze_Character_Literal;
63
64 ------------------------
65 -- Analyze_Identifier --
66 ------------------------
67
68 procedure Analyze_Identifier (N : Node_Id) is
69 begin
07fc65c4
GB
70 -- Ignore call if prior errors, and identifier has no name, since
71 -- this is the result of some kind of previous error generating a
72 -- junk identifier.
73
d63199d8 74 if not Is_Valid_Name (Chars (N)) and then Total_Errors_Detected /= 0 then
07fc65c4
GB
75 return;
76 else
77 Find_Direct_Name (N);
78 end if;
dec6faf1
AC
79
80 Analyze_Dimension (N);
996ae0b0
RK
81 end Analyze_Identifier;
82
83 -----------------------------
84 -- Analyze_Integer_Literal --
85 -----------------------------
86
87 procedure Analyze_Integer_Literal (N : Node_Id) is
88 begin
4669743b
ES
89 -- As a lexical element, an integer literal has type Universal_Integer,
90 -- i.e., is compatible with any integer type. This is semantically
91 -- consistent and simplifies type checking and subsequent constant
92 -- folding when needed. An exception is caused by 64-bit modular types,
93 -- whose upper bound is not representable in a nonstatic context that
94 -- will use 64-bit integers at run time. For such cases, we need to
95 -- preserve the information that the analyzed literal has that modular
96 -- type. For simplicity, we preserve the information for all integer
97 -- literals that result from a modular operation. This happens after
98 -- prior analysis (or construction) of the literal, and after type
99 -- checking and resolution.
100
29c64a0f 101 if No (Etype (N)) or else not Is_Modular_Integer_Type (Etype (N)) then
4669743b
ES
102 Set_Etype (N, Universal_Integer);
103 end if;
104
996ae0b0
RK
105 Set_Is_Static_Expression (N);
106 end Analyze_Integer_Literal;
107
108 --------------------------
109 -- Analyze_Real_Literal --
110 --------------------------
111
112 procedure Analyze_Real_Literal (N : Node_Id) is
113 begin
114 Set_Etype (N, Universal_Real);
115 Set_Is_Static_Expression (N);
116 end Analyze_Real_Literal;
117
118 ----------------------------
119 -- Analyze_String_Literal --
120 ----------------------------
121
122 procedure Analyze_String_Literal (N : Node_Id) is
123 begin
996ae0b0
RK
124 -- The type is eventually inherited from the context. If expansion
125 -- has already established the proper type, do not modify it.
126
127 if No (Etype (N)) then
128 Set_Etype (N, Any_String);
129 end if;
130
131 -- String literals are static in Ada 95. Note that if the subtype
132 -- turns out to be non-static, then the Is_Static_Expression flag
133 -- will be reset in Eval_String_Literal.
134
0ab80019 135 if Ada_Version >= Ada_95 then
996ae0b0
RK
136 Set_Is_Static_Expression (N);
137 end if;
138
139 if Comes_From_Source (N) and then Has_Wide_Character (N) then
140 Check_Restriction (No_Wide_Characters, N);
141 end if;
142 end Analyze_String_Literal;
143
144end Sem_Ch2;