2015-05-01 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc.git] / gcc / ada / sem_eval.ads
blob7f206e71d0c40c8c7ff76e39671b36b2ff39d158
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ E V A L --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2015, 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 -- This package contains various subprograms involved in compile time
27 -- evaluation of expressions and checks for staticness of expressions and
28 -- types. It also contains the circuitry for checking for violations of pure
29 -- and preelaborated conditions (this naturally goes here, since these rules
30 -- involve consideration of staticness).
32 -- Note: the static evaluation for attributes is found in Sem_Attr even though
33 -- logically it belongs here. We have done this so that it is easier to add
34 -- new attributes to GNAT.
36 with Types; use Types;
37 with Uintp; use Uintp;
38 with Urealp; use Urealp;
40 package Sem_Eval is
42 ------------------------------------
43 -- Handling of Static Expressions --
44 ------------------------------------
46 -- This package contains a set of routines that process individual
47 -- subexpression nodes with the objective of folding (precomputing) the
48 -- value of static expressions that are known at compile time and properly
49 -- computing the setting of two flags that appear in every subexpression
50 -- node:
52 -- Is_Static_Expression
54 -- This flag is set on any expression that is static according to the
55 -- rules in (RM 4.9(3-32)). This flag should be tested during testing
56 -- of legality of parts of a larger static expression. For all other
57 -- contexts that require static expressions, use the separate predicate
58 -- Is_OK_Static_Expression, since an expression that meets the RM 4.9
59 -- requirements, but raises a constraint error when evaluated in a non-
60 -- static context does not meet the legality requirements.
62 -- Raises_Constraint_Error
64 -- This flag indicates that it is known at compile time that the
65 -- evaluation of an expression raises constraint error. If the
66 -- expression is static, and this flag is off, then it is also known at
67 -- compile time that the expression does not raise constraint error
68 -- (i.e. the flag is accurate for static expressions, and conservative
69 -- for non-static expressions.
71 -- If a static expression does not raise constraint error, then it will
72 -- have the flag Raises_Constraint_Error flag False, and the expression
73 -- must be computed at compile time, which means that it has the form of
74 -- either a literal, or a constant that is itself (recursively) either a
75 -- literal or a constant.
77 -- The above rules must be followed exactly in order for legality checks to
78 -- be accurate. For subexpressions that are not static according to the RM
79 -- definition, they are sometimes folded anyway, but of course in this case
80 -- Is_Static_Expression is not set.
82 -- When we are analyzing and evaluating static expressions, we propagate
83 -- both flags accurately. Usually if a subexpression raises a constraint
84 -- error, then so will its parent expression, and Raise_Constraint_Error
85 -- will be propagated to this parent. The exception is conditional cases
86 -- like (True or else 1/0 = 0) which results in an expresion that has the
87 -- Is_Static_Expression flag True, and Raises_Constraint_Error False. Even
88 -- though 1/0 would raise an exception, the right operand is never actually
89 -- executed, so the expression as a whole does not raise CE.
91 -- For constructs in the language where static expressions are part of the
92 -- required semantics, we need an expression that meets the 4.9 rules and
93 -- does not raise CE. So nearly everywhere, callers should call function
94 -- Is_OK_Static_Expression rather than Is_Static_Expression.
96 -- Finally, the case of static predicates. These are applied only to entire
97 -- expressions, not to subexpressions, so we do not have the case of having
98 -- to propagate this information. We handle this case simply by resetting
99 -- the Is_Static_Expression flag if a static predicate fails. Note that we
100 -- can't use this simpler approach for the constraint error case because of
101 -- the (True or else 1/0 = 0) example discussed above.
103 -------------------------------
104 -- Compile-Time Known Values --
105 -------------------------------
107 -- For most legality checking purposes the flag Is_Static_Expression
108 -- defined in Sinfo should be used. This package also provides a routine
109 -- called Is_OK_Static_Expression which in addition of checking that an
110 -- expression is static in the RM 4.9 sense, it checks that the expression
111 -- does not raise constraint error. In fact for certain legality checks not
112 -- only do we need to ascertain that the expression is static, but we must
113 -- also ensure that it does not raise constraint error.
115 -- Neither of Is_Static_Expression and Is_OK_Static_Expression should be
116 -- used for compile time evaluation purposes. In fact certain expression
117 -- whose value may be known at compile time are not static in the RM 4.9
118 -- sense. A typical example is:
120 -- C : constant Integer := Record_Type'Size;
122 -- The expression 'C' is not static in the technical RM sense, but for many
123 -- simple record types, the size is in fact known at compile time. When we
124 -- are trying to perform compile time constant folding (for instance for
125 -- expressions like C + 1, Is_Static_Expression or Is_OK_Static_Expression
126 -- are not the right functions to test if folding is possible. Instead, we
127 -- use Compile_Time_Known_Value. All static expressions that do not raise
128 -- constraint error (i.e. those for which Is_OK_Static_Expression is true)
129 -- are known at compile time, but as shown by the above example, there may
130 -- be cases of non-static expressions which are known at compile time.
132 -----------------
133 -- Subprograms --
134 -----------------
136 procedure Check_Expression_Against_Static_Predicate
137 (Expr : Node_Id;
138 Typ : Entity_Id);
139 -- Determine whether an arbitrary expression satisfies the static predicate
140 -- of a type. The routine does nothing if Expr is not known at compile time
141 -- or Typ lacks a static predicate, otherwise it may emit a warning if the
142 -- expression is prohibited by the predicate. If the expression is a static
143 -- expression and it fails a predicate that was not explicitly stated to be
144 -- a dynamic predicate, then an additional warning is given, and the flag
145 -- Is_Static_Expression is reset on Expr.
147 procedure Check_Non_Static_Context (N : Node_Id);
148 -- Deals with the special check required for a static expression that
149 -- appears in a non-static context, i.e. is not part of a larger static
150 -- expression (see RM 4.9(35)), i.e. the value of the expression must be
151 -- within the base range of the base type of its expected type. A check is
152 -- also made for expressions that are inside the base range, but outside
153 -- the range of the expected subtype (this is a warning message rather than
154 -- an illegality).
156 -- Note: most cases of non-static context checks are handled within
157 -- Sem_Eval itself, including all cases of expressions at the outer level
158 -- (i.e. those that are not a subexpression). Currently the only outside
159 -- customer for this procedure is Sem_Attr (because Eval_Attribute is
160 -- there). There is also one special case arising from ranges (see body of
161 -- Resolve_Range).
163 procedure Check_String_Literal_Length (N : Node_Id; Ttype : Entity_Id);
164 -- N is either a string literal, or a constraint error node. In the latter
165 -- case, the situation is already dealt with, and the call has no effect.
166 -- In the former case, if the target type, Ttyp is constrained, then a
167 -- check is made to see if the string literal is of appropriate length.
169 type Compare_Result is (LT, LE, EQ, GT, GE, NE, Unknown);
170 subtype Compare_GE is Compare_Result range EQ .. GE;
171 subtype Compare_LE is Compare_Result range LT .. EQ;
172 -- Result subtypes for Compile_Time_Compare subprograms
174 function Compile_Time_Compare
175 (L, R : Node_Id;
176 Assume_Valid : Boolean) return Compare_Result;
177 pragma Inline (Compile_Time_Compare);
178 -- Given two expression nodes, finds out whether it can be determined at
179 -- compile time how the runtime values will compare. An Unknown result
180 -- means that the result of a comparison cannot be determined at compile
181 -- time, otherwise the returned result indicates the known result of the
182 -- comparison, given as tightly as possible (i.e. EQ or LT is preferred
183 -- returned value to LE). If Assume_Valid is true, the result reflects
184 -- the result of assuming that entities involved in the comparison have
185 -- valid representations. If Assume_Valid is false, then the base type of
186 -- any involved entity is used so that no assumption of validity is made.
188 function Compile_Time_Compare
189 (L, R : Node_Id;
190 Diff : access Uint;
191 Assume_Valid : Boolean;
192 Rec : Boolean := False) return Compare_Result;
193 -- This version of Compile_Time_Compare returns extra information if the
194 -- result is GT or LT. In these cases, if the magnitude of the difference
195 -- can be determined at compile time, this (positive) magnitude is returned
196 -- in Diff.all. If the magnitude of the difference cannot be determined
197 -- then Diff.all contains No_Uint on return. Rec is a parameter that is set
198 -- True for a recursive call from within Compile_Time_Compare to avoid some
199 -- infinite recursion cases. It should never be set by a client.
201 procedure Flag_Non_Static_Expr (Msg : String; Expr : Node_Id);
202 -- This procedure is called after it has been determined that Expr is not
203 -- static when it is required to be. Msg is the text of a message that
204 -- explains the error. This procedure checks if an error is already posted
205 -- on Expr, if so, it does nothing unless All_Errors_Mode is set in which
206 -- case this flag is ignored. Otherwise the given message is posted using
207 -- Error_Msg_F, and then Why_Not_Static is called on Expr to generate
208 -- additional messages. The string given as Msg should end with ! to make
209 -- it an unconditional message, to ensure that if it is posted, the entire
210 -- set of messages is all posted.
212 function Is_OK_Static_Expression (N : Node_Id) return Boolean;
213 -- An OK static expression is one that is static in the RM definition sense
214 -- and which does not raise constraint error. For most legality checking
215 -- purposes you should use Is_Static_Expression. For those legality checks
216 -- where the expression N should not raise constraint error use this
217 -- routine. This routine is *not* to be used in contexts where the test is
218 -- for compile time evaluation purposes. Use Compile_Time_Known_Value
219 -- instead (see section on "Compile-Time Known Values" above).
221 function Is_OK_Static_Range (N : Node_Id) return Boolean;
222 -- Determines if range is static, as defined in RM 4.9(26), and also checks
223 -- that neither bound of the range raises constraint error, thus ensuring
224 -- that both bounds of the range are compile-time evaluable (i.e. do not
225 -- raise constraint error). A result of true means that the bounds are
226 -- compile time evaluable. A result of false means they are not (either
227 -- because the range is not static, or because one or the other bound
228 -- raises CE).
230 function Is_Static_Subtype (Typ : Entity_Id) return Boolean;
231 -- Determines whether a subtype fits the definition of an Ada static
232 -- subtype as given in (RM 4.9(26)). Important note: This check does not
233 -- include the Ada 2012 case of a non-static predicate which results in an
234 -- otherwise static subtype being non-static. Such a subtype will return
235 -- True for this test, so if the distinction is important, the caller must
236 -- deal with this.
238 -- Implementation note: an attempt to include this Ada 2012 case failed,
239 -- since it appears that this routine is called in some cases before the
240 -- Static_Discrete_Predicate field is set ???
242 -- This differs from Is_OK_Static_Subtype (which is what must be used by
243 -- clients) in that it does not care whether the bounds raise a constraint
244 -- error exception or not. Used for checking whether expressions are static
245 -- in the 4.9 sense (without worrying about exceptions).
247 function Is_OK_Static_Subtype (Typ : Entity_Id) return Boolean;
248 -- Determines whether a subtype fits the definition of an Ada static
249 -- subtype as given in (RM 4.9(26)) with the additional check that neither
250 -- bound raises constraint error (meaning that Expr_Value[_R|S] can be used
251 -- on these bounds). Important note: This check does not include the Ada
252 -- 2012 case of a non-static predicate which results in an otherwise static
253 -- subtype being non-static. Such a subtype will return True for this test,
254 -- so if the distinction is important, the caller must deal with this.
256 -- Implementation note: an attempt to include this Ada 2012 case failed,
257 -- since it appears that this routine is called in some cases before the
258 -- Static_Discrete_Predicate field is set ???
260 -- This differs from Is_Static_Subtype in that it includes the constraint
261 -- error checks, which are missing from Is_Static_Subtype.
263 function Subtypes_Statically_Compatible
264 (T1 : Entity_Id;
265 T2 : Entity_Id;
266 Formal_Derived_Matching : Boolean := False) return Boolean;
267 -- Returns true if the subtypes are unconstrained or the constraint on
268 -- on T1 is statically compatible with T2 (as defined by 4.9.1(4)).
269 -- Otherwise returns false. Formal_Derived_Matching indicates whether
270 -- the type T1 is a generic actual being checked against ancestor T2
271 -- in a formal derived type association.
273 function Subtypes_Statically_Match
274 (T1 : Entity_Id;
275 T2 : Entity_Id;
276 Formal_Derived_Matching : Boolean := False) return Boolean;
277 -- Determine whether two types T1, T2, which have the same base type,
278 -- are statically matching subtypes (RM 4.9.1(1-2)). Also includes the
279 -- extra GNAT rule that object sizes must match (this can be false for
280 -- types that match in the RM sense because of use of 'Object_Size),
281 -- except when testing a generic actual T1 against an ancestor T2 in a
282 -- formal derived type association (indicated by Formal_Derived_Matching).
284 function Compile_Time_Known_Value (Op : Node_Id) return Boolean;
285 -- Returns true if Op is an expression not raising Constraint_Error whose
286 -- value is known at compile time and for which a call to Expr_Value can
287 -- be used to determine this value. This is always true if Op is a static
288 -- expression, but can also be true for expressions which are technically
289 -- non-static but which are in fact known at compile time. Some examples of
290 -- such expressions are the static lower bound of a non-static range or the
291 -- value of a constant object whose initial value is itself compile time
292 -- known in the sense of this routine. Note that this routine is defended
293 -- against unanalyzed expressions. Such expressions will not cause a
294 -- blowup, they may cause pessimistic (i.e. False) results to be returned.
295 -- In general we take a pessimistic view. False does not mean the value
296 -- could not be known at compile time, but True means that absolutely
297 -- definition it is known at compile time and it is safe to call
298 -- Expr_Value[_XX] on the expression Op.
300 -- Note that we don't define precisely the set of expressions that return
301 -- True. Callers should not make any assumptions regarding the value that
302 -- is returned for non-static expressions. Functional behavior should never
303 -- be affected by whether a given non-static expression returns True or
304 -- False when this function is called. In other words this is purely for
305 -- efficiency optimization purposes. The code generated can often be more
306 -- efficient with compile time known values, e.g. range analysis for the
307 -- purpose of removing checks is more effective if we know precise bounds.
309 function CRT_Safe_Compile_Time_Known_Value (Op : Node_Id) return Boolean;
310 -- In the case of configurable run-times, there may be an issue calling
311 -- Compile_Time_Known_Value with non-static expressions where the legality
312 -- of the program is not well-defined. Consider this example:
314 -- X := B ** C;
316 -- Now if C is compile time known, and has the value 4, then inline code
317 -- can be generated at compile time, instead of calling a run-time routine.
318 -- That's fine in the normal case, but when we have a configurable run-time
319 -- the run-time routine may not be available. This means that the program
320 -- will be rejected if C is not known at compile time. We don't want the
321 -- legality of a program to depend on how clever the implementation of this
322 -- function is. If the run-time in use lacks the exponentiation routine,
323 -- then what we say is that exponentiation is permitted if the exponent is
324 -- officially static and has a value in the range 0 .. 4.
326 -- In a case like this, we use CRT_Safe_Compile_Time_Known_Value to avoid
327 -- this effect. This routine will return False for a non-static expression
328 -- if we are in configurable run-time mode, even if the expression would
329 -- normally be considered compile-time known.
331 function Compile_Time_Known_Value_Or_Aggr (Op : Node_Id) return Boolean;
332 -- Similar to Compile_Time_Known_Value, but also returns True if the value
333 -- is a compile-time-known aggregate, i.e. an aggregate all of whose
334 -- constituent expressions are either compile-time-known values (based on
335 -- calling Compile_Time_Known_Value) or compile-time-known aggregates.
336 -- Note that the aggregate could still involve run-time checks that might
337 -- fail (such as for subtype checks in component associations), but the
338 -- evaluation of the expressions themselves will not raise an exception.
340 function Compile_Time_Known_Bounds (T : Entity_Id) return Boolean;
341 -- If T is an array whose index bounds are all known at compile time, then
342 -- True is returned. If T is not an array type, or one or more of its index
343 -- bounds is not known at compile time, then False is returned.
345 function Expr_Value (N : Node_Id) return Uint;
346 -- Returns the folded value of the expression N. This function is called in
347 -- instances where it has already been determined that the expression is
348 -- static or its value is compile time known (Compile_Time_Known_Value (N)
349 -- returns True). This version is used for integer values, and enumeration
350 -- or character literals. In the latter two cases, the value returned is
351 -- the Pos value in the relevant enumeration type. It can also be used for
352 -- fixed-point values, in which case it returns the corresponding integer
353 -- value. It cannot be used for floating-point values.
355 function Expr_Value_E (N : Node_Id) return Entity_Id;
356 -- Returns the folded value of the expression. This function is called in
357 -- instances where it has already been determined that the expression is
358 -- static or its value known at compile time. This version is used for
359 -- enumeration types and returns the corresponding enumeration literal.
361 function Expr_Value_R (N : Node_Id) return Ureal;
362 -- Returns the folded value of the expression. This function is called in
363 -- instances where it has already been determined that the expression is
364 -- static or its value known at compile time. This version is used for real
365 -- values (including both the floating-point and fixed-point cases). In the
366 -- case of a fixed-point type, the real value is returned (cf above version
367 -- returning Uint).
369 function Expr_Value_S (N : Node_Id) return Node_Id;
370 -- Returns the folded value of the expression. This function is called
371 -- in instances where it has already been determined that the expression
372 -- is static or its value is known at compile time. This version is used
373 -- for string types and returns the corresponding N_String_Literal node.
375 function Expr_Rep_Value (N : Node_Id) return Uint;
376 -- This is identical to Expr_Value, except in the case of enumeration
377 -- literals of types for which an enumeration representation clause has
378 -- been given, in which case it returns the representation value rather
379 -- than the pos value. This is the value that is needed for generating code
380 -- sequences, while the Expr_Value value is appropriate for compile time
381 -- constraint errors or getting the logical value. Note that this function
382 -- does NOT concern itself with biased values, if the caller needs a
383 -- properly biased value, the subtraction of the bias must be handled
384 -- explicitly.
386 procedure Eval_Actual (N : Node_Id);
387 procedure Eval_Allocator (N : Node_Id);
388 procedure Eval_Arithmetic_Op (N : Node_Id);
389 procedure Eval_Call (N : Node_Id);
390 procedure Eval_Case_Expression (N : Node_Id);
391 procedure Eval_Character_Literal (N : Node_Id);
392 procedure Eval_Concatenation (N : Node_Id);
393 procedure Eval_Entity_Name (N : Node_Id);
394 procedure Eval_If_Expression (N : Node_Id);
395 procedure Eval_Indexed_Component (N : Node_Id);
396 procedure Eval_Integer_Literal (N : Node_Id);
397 procedure Eval_Logical_Op (N : Node_Id);
398 procedure Eval_Membership_Op (N : Node_Id);
399 procedure Eval_Named_Integer (N : Node_Id);
400 procedure Eval_Named_Real (N : Node_Id);
401 procedure Eval_Op_Expon (N : Node_Id);
402 procedure Eval_Op_Not (N : Node_Id);
403 procedure Eval_Real_Literal (N : Node_Id);
404 procedure Eval_Relational_Op (N : Node_Id);
405 procedure Eval_Shift (N : Node_Id);
406 procedure Eval_Short_Circuit (N : Node_Id);
407 procedure Eval_Slice (N : Node_Id);
408 procedure Eval_String_Literal (N : Node_Id);
409 procedure Eval_Qualified_Expression (N : Node_Id);
410 procedure Eval_Type_Conversion (N : Node_Id);
411 procedure Eval_Unary_Op (N : Node_Id);
412 procedure Eval_Unchecked_Conversion (N : Node_Id);
414 procedure Fold_Str (N : Node_Id; Val : String_Id; Static : Boolean);
415 -- Rewrite N with a new N_String_Literal node as the result of the compile
416 -- time evaluation of the node N. Val is the resulting string value from
417 -- the folding operation. The Is_Static_Expression flag is set in the
418 -- result node. The result is fully analyzed and resolved. Static indicates
419 -- whether the result should be considered static or not (True = consider
420 -- static). The point here is that normally all string literals are static,
421 -- but if this was the result of some sequence of evaluation where values
422 -- were known at compile time but not static, then the result is not
423 -- static. The call has no effect if Raises_Constraint_Error (N) is True,
424 -- since there is no point in folding if we have an error.
426 procedure Fold_Uint (N : Node_Id; Val : Uint; Static : Boolean);
427 -- Rewrite N with a (N_Integer_Literal, N_Identifier, N_Character_Literal)
428 -- node as the result of the compile time evaluation of the node N. Val is
429 -- the result in the integer case and is the position of the literal in the
430 -- literals list for the enumeration case. Is_Static_Expression is set True
431 -- in the result node. The result is fully analyzed/resolved. Static
432 -- indicates whether the result should be considered static or not (True =
433 -- consider static). The point here is that normally all integer literals
434 -- are static, but if this was the result of some sequence of evaluation
435 -- where values were known at compile time but not static, then the result
436 -- is not static. The call has no effect if Raises_Constraint_Error (N) is
437 -- True, since there is no point in folding if we have an error.
439 procedure Fold_Ureal (N : Node_Id; Val : Ureal; Static : Boolean);
440 -- Rewrite N with a new N_Real_Literal node as the result of the compile
441 -- time evaluation of the node N. Val is the resulting real value from the
442 -- folding operation. The Is_Static_Expression flag is set in the result
443 -- node. The result is fully analyzed and result. Static indicates whether
444 -- the result should be considered static or not (True = consider static).
445 -- The point here is that normally all string literals are static, but if
446 -- this was the result of some sequence of evaluation where values were
447 -- known at compile time but not static, then the result is not static.
448 -- The call has no effect if Raises_Constraint_Error (N) is True, since
449 -- there is no point in folding if we have an error.
451 function Is_In_Range
452 (N : Node_Id;
453 Typ : Entity_Id;
454 Assume_Valid : Boolean := False;
455 Fixed_Int : Boolean := False;
456 Int_Real : Boolean := False) return Boolean;
457 -- Returns True if it can be guaranteed at compile time that expression
458 -- N is known to be in range of the subtype Typ. A result of False does
459 -- not mean that the expression is out of range, merely that it cannot be
460 -- determined at compile time that it is in range. If Typ is a floating
461 -- point type or Int_Real is set, any integer value is treated as though it
462 -- was a real value (i.e. the underlying real value is used). In this case
463 -- we use the corresponding real value, both for the bounds of Typ, and for
464 -- the value of the expression N. If Typ is a fixed type or a discrete type
465 -- and Int_Real is False but flag Fixed_Int is True then any fixed-point
466 -- value is treated as though it was discrete value (i.e. the underlying
467 -- integer value is used). In this case we use the corresponding integer
468 -- value, both for the bounds of Typ, and for the value of the expression
469 -- N. If Typ is a discrete type and Fixed_Int as well as Int_Real are
470 -- false, integer values are used throughout.
472 -- If Assume_Valid is set True, then N is always assumed to contain a valid
473 -- value. If Assume_Valid is set False, then N may be invalid (unless there
474 -- is some independent way of knowing that it is valid, i.e. either it is
475 -- an entity with Is_Known_Valid set, or Assume_No_Invalid_Values is True.
477 function Is_Out_Of_Range
478 (N : Node_Id;
479 Typ : Entity_Id;
480 Assume_Valid : Boolean := False;
481 Fixed_Int : Boolean := False;
482 Int_Real : Boolean := False) return Boolean;
483 -- Returns True if it can be guaranteed at compile time that expression is
484 -- known to be out of range of the subtype Typ. True is returned if Typ is
485 -- a scalar type, and the value of N can be determined to be outside the
486 -- range of Typ. A result of False does not mean that the expression is in
487 -- range, but rather merely that it cannot be determined at compile time
488 -- that it is out of range. The parameters Assume_Valid, Fixed_Int, and
489 -- Int_Real are as described for Is_In_Range above.
491 function In_Subrange_Of
492 (T1 : Entity_Id;
493 T2 : Entity_Id;
494 Fixed_Int : Boolean := False) return Boolean;
495 -- Returns True if it can be guaranteed at compile time that the range of
496 -- values for scalar type T1 are always in the range of scalar type T2. A
497 -- result of False does not mean that T1 is not in T2's subrange, only that
498 -- it cannot be determined at compile time. Flag Fixed_Int is used as in
499 -- routine Is_In_Range above.
501 function Is_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean;
502 -- Returns True if it can guarantee that Lo .. Hi is a null range. If it
503 -- cannot (because the value of Lo or Hi is not known at compile time) then
504 -- it returns False.
506 function Is_Statically_Unevaluated (Expr : Node_Id) return Boolean;
507 -- This function returns True if the given expression Expr is statically
508 -- unevaluated, as defined in (RM 4.9 (32.1-32.6)).
510 function Not_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean;
511 -- Returns True if it can guarantee that Lo .. Hi is not a null range. If
512 -- it cannot (because the value of Lo or Hi is not known at compile time)
513 -- then it returns False.
515 function Predicates_Match (T1, T2 : Entity_Id) return Boolean;
516 -- In Ada 2012, subtypes statically match if their static predicates
517 -- match as well. This function performs the required check that
518 -- predicates match. Separated out from Subtypes_Statically_Match so
519 -- that it can be used in specializing error messages.
521 procedure Why_Not_Static (Expr : Node_Id);
522 -- This procedure may be called after generating an error message that
523 -- complains that something is non-static. If it finds good reasons, it
524 -- generates one or more error messages pointing the appropriate offending
525 -- component of the expression. If no good reasons can be figured out, then
526 -- no messages are generated. The expectation here is that the caller has
527 -- already issued a message complaining that the expression is non-static.
528 -- Note that this message should be placed using Error_Msg_F or
529 -- Error_Msg_FE, so that it will sort before any messages placed by this
530 -- call. Note that it is fine to call Why_Not_Static with something that
531 -- is not an expression, and usually this has no effect, but in some cases
532 -- (N_Parameter_Association or N_Range), it makes sense for the internal
533 -- recursive calls.
535 -- Note that these messages are not continuation messages, instead they are
536 -- separate unconditional messages, marked with '!'. The reason for this is
537 -- that they can be posted at a different location from the main message as
538 -- documented above ("appropriate offending component"), and continuation
539 -- messages must always point to the same location as the parent message.
541 procedure Initialize;
542 -- Initializes the internal data structures. Must be called before each
543 -- separate main program unit (e.g. in a GNSA/ASIS context).
545 private
546 -- The Eval routines are all marked inline, since they are called once
548 pragma Inline (Eval_Actual);
549 pragma Inline (Eval_Allocator);
550 pragma Inline (Eval_Character_Literal);
551 pragma Inline (Eval_If_Expression);
552 pragma Inline (Eval_Indexed_Component);
553 pragma Inline (Eval_Named_Integer);
554 pragma Inline (Eval_Named_Real);
555 pragma Inline (Eval_Real_Literal);
556 pragma Inline (Eval_Shift);
557 pragma Inline (Eval_Slice);
558 pragma Inline (Eval_String_Literal);
559 pragma Inline (Eval_Unchecked_Conversion);
561 pragma Inline (Is_OK_Static_Expression);
563 end Sem_Eval;