Mercurial > hg > CbC > CbC_gcc
comparison gcc/ada/sem_eval.adb @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
4 -- -- | 4 -- -- |
5 -- S E M _ E V A L -- | 5 -- S E M _ E V A L -- |
6 -- -- | 6 -- -- |
7 -- B o d y -- | 7 -- B o d y -- |
8 -- -- | 8 -- -- |
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- | 9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. -- |
10 -- -- | 10 -- -- |
11 -- GNAT is free software; you can redistribute it and/or modify it under -- | 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- -- | 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- -- | 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- -- | 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
102 | 102 |
103 type Bits is array (Nat range <>) of Boolean; | 103 type Bits is array (Nat range <>) of Boolean; |
104 -- Used to convert unsigned (modular) values for folding logical ops | 104 -- Used to convert unsigned (modular) values for folding logical ops |
105 | 105 |
106 -- The following declarations are used to maintain a cache of nodes that | 106 -- The following declarations are used to maintain a cache of nodes that |
107 -- have compile time known values. The cache is maintained only for | 107 -- have compile-time-known values. The cache is maintained only for |
108 -- discrete types (the most common case), and is populated by calls to | 108 -- discrete types (the most common case), and is populated by calls to |
109 -- Compile_Time_Known_Value and Expr_Value, but only used by Expr_Value | 109 -- Compile_Time_Known_Value and Expr_Value, but only used by Expr_Value |
110 -- since it is possible for the status to change (in particular it is | 110 -- since it is possible for the status to change (in particular it is |
111 -- possible for a node to get replaced by a constraint error node). | 111 -- possible for a node to get replaced by a constraint error node). |
112 | 112 |
169 Choices : List_Id) return Match_Result; | 169 Choices : List_Id) return Match_Result; |
170 -- This function applies Choice_Matches to each element of Choices. If the | 170 -- This function applies Choice_Matches to each element of Choices. If the |
171 -- result is No_Match, then it continues and checks the next element. If | 171 -- result is No_Match, then it continues and checks the next element. If |
172 -- the result is Match or Non_Static, this result is immediately given | 172 -- the result is Match or Non_Static, this result is immediately given |
173 -- as the result without checking the rest of the list. Expr can be of | 173 -- as the result without checking the rest of the list. Expr can be of |
174 -- discrete, real, or string type and must be a compile time known value | 174 -- discrete, real, or string type and must be a compile-time-known value |
175 -- (it is an error to make the call if these conditions are not met). | 175 -- (it is an error to make the call if these conditions are not met). |
176 | 176 |
177 function Find_Universal_Operator_Type (N : Node_Id) return Entity_Id; | 177 function Find_Universal_Operator_Type (N : Node_Id) return Entity_Id; |
178 -- Check whether an arithmetic operation with universal operands which is a | 178 -- Check whether an arithmetic operation with universal operands which is a |
179 -- rewritten function call with an explicit scope indication is ambiguous: | 179 -- rewritten function call with an explicit scope indication is ambiguous: |
229 -- Bits is unreasonably large, then an error is posted on node N, and | 229 -- Bits is unreasonably large, then an error is posted on node N, and |
230 -- False is returned (and the caller skips the proposed calculation). | 230 -- False is returned (and the caller skips the proposed calculation). |
231 | 231 |
232 procedure Out_Of_Range (N : Node_Id); | 232 procedure Out_Of_Range (N : Node_Id); |
233 -- This procedure is called if it is determined that node N, which appears | 233 -- This procedure is called if it is determined that node N, which appears |
234 -- in a non-static context, is a compile time known value which is outside | 234 -- in a non-static context, is a compile-time-known value which is outside |
235 -- its range, i.e. the range of Etype. This is used in contexts where | 235 -- its range, i.e. the range of Etype. This is used in contexts where |
236 -- this is an illegality if N is static, and should generate a warning | 236 -- this is an illegality if N is static, and should generate a warning |
237 -- otherwise. | 237 -- otherwise. |
238 | 238 |
239 function Real_Or_String_Static_Predicate_Matches | 239 function Real_Or_String_Static_Predicate_Matches |
545 -- case in which non-static universal integer values can occur, and | 545 -- case in which non-static universal integer values can occur, and |
546 -- furthermore, Check_Non_Static_Context is currently (incorrectly???) | 546 -- furthermore, Check_Non_Static_Context is currently (incorrectly???) |
547 -- called in contexts like the expression of a number declaration where | 547 -- called in contexts like the expression of a number declaration where |
548 -- we certainly want to allow out of range values. | 548 -- we certainly want to allow out of range values. |
549 | 549 |
550 -- We inhibit the warning when expansion is disabled, because the | |
551 -- preanalysis of a range of a 64-bit modular type may appear to | |
552 -- violate the constraint on non-static Universal_Integer. If there | |
553 -- is a true overflow it will be diagnosed during full analysis. | |
554 | |
550 if Etype (N) = Universal_Integer | 555 if Etype (N) = Universal_Integer |
551 and then Nkind (N) = N_Integer_Literal | 556 and then Nkind (N) = N_Integer_Literal |
552 and then Nkind (Parent (N)) in N_Subexpr | 557 and then Nkind (Parent (N)) in N_Subexpr |
558 and then Expander_Active | |
553 and then | 559 and then |
554 (Intval (N) < Expr_Value (Type_Low_Bound (Universal_Integer)) | 560 (Intval (N) < Expr_Value (Type_Low_Bound (Universal_Integer)) |
555 or else | 561 or else |
556 Intval (N) > Expr_Value (Type_High_Bound (Universal_Integer))) | 562 Intval (N) > Expr_Value (Type_High_Bound (Universal_Integer))) |
557 then | 563 then |
572 elsif T /= Base_Type (T) and then Nkind (Parent (N)) /= N_Range then | 578 elsif T /= Base_Type (T) and then Nkind (Parent (N)) /= N_Range then |
573 if Is_In_Range (N, T, Assume_Valid => True) then | 579 if Is_In_Range (N, T, Assume_Valid => True) then |
574 null; | 580 null; |
575 | 581 |
576 elsif Is_Out_Of_Range (N, T, Assume_Valid => True) then | 582 elsif Is_Out_Of_Range (N, T, Assume_Valid => True) then |
577 Apply_Compile_Time_Constraint_Error | 583 |
578 (N, "value not in range of}<<", CE_Range_Check_Failed); | 584 -- Ignore out of range values for System.Priority in CodePeer |
585 -- mode since the actual target compiler may provide a wider | |
586 -- range. | |
587 | |
588 if CodePeer_Mode and then T = RTE (RE_Priority) then | |
589 Set_Do_Range_Check (N, False); | |
590 else | |
591 Apply_Compile_Time_Constraint_Error | |
592 (N, "value not in range of}<<", CE_Range_Check_Failed); | |
593 end if; | |
579 | 594 |
580 elsif Checks_On then | 595 elsif Checks_On then |
581 Enable_Range_Check (N); | 596 Enable_Range_Check (N); |
582 | 597 |
583 else | 598 else |
829 -- Even if the context does not assume that values are valid, some | 844 -- Even if the context does not assume that values are valid, some |
830 -- simple cases can be recognized. | 845 -- simple cases can be recognized. |
831 | 846 |
832 function Is_Same_Value (L, R : Node_Id) return Boolean; | 847 function Is_Same_Value (L, R : Node_Id) return Boolean; |
833 -- Returns True iff L and R represent expressions that definitely have | 848 -- Returns True iff L and R represent expressions that definitely have |
834 -- identical (but not necessarily compile time known) values Indeed the | 849 -- identical (but not necessarily compile-time-known) values Indeed the |
835 -- caller is expected to have already dealt with the cases of compile | 850 -- caller is expected to have already dealt with the cases of compile |
836 -- time known values, so these are not tested here. | 851 -- time known values, so these are not tested here. |
837 | 852 |
838 ----------------------- | 853 ----------------------- |
839 -- Compare_Decompose -- | 854 -- Compare_Decompose -- |
1032 and then not Is_Volatile_Reference (L) | 1047 and then not Is_Volatile_Reference (L) |
1033 and then not Is_Volatile_Reference (R) | 1048 and then not Is_Volatile_Reference (R) |
1034 then | 1049 then |
1035 return True; | 1050 return True; |
1036 | 1051 |
1037 -- Or if they are compile time known and identical | 1052 -- Or if they are compile-time-known and identical |
1038 | 1053 |
1039 elsif Compile_Time_Known_Value (Lf) | 1054 elsif Compile_Time_Known_Value (Lf) |
1040 and then | 1055 and then |
1041 Compile_Time_Known_Value (Rf) | 1056 Compile_Time_Known_Value (Rf) |
1042 and then Expr_Value (Lf) = Expr_Value (Rf) | 1057 and then Expr_Value (Lf) = Expr_Value (Rf) |
1181 | 1196 |
1182 else | 1197 else |
1183 return Unknown; | 1198 return Unknown; |
1184 end if; | 1199 end if; |
1185 | 1200 |
1186 -- Case where comparison involves two compile time known values | 1201 -- Case where comparison involves two compile-time-known values |
1187 | 1202 |
1188 elsif Compile_Time_Known_Value (L) | 1203 elsif Compile_Time_Known_Value (L) |
1189 and then | 1204 and then |
1190 Compile_Time_Known_Value (R) | 1205 Compile_Time_Known_Value (R) |
1191 then | 1206 then |
1504 end case; | 1519 end case; |
1505 end if; | 1520 end if; |
1506 end if; | 1521 end if; |
1507 | 1522 |
1508 -- Next attempt is to see if we have an entity compared with a | 1523 -- Next attempt is to see if we have an entity compared with a |
1509 -- compile time known value, where there is a current value | 1524 -- compile-time-known value, where there is a current value |
1510 -- conditional for the entity which can tell us the result. | 1525 -- conditional for the entity which can tell us the result. |
1511 | 1526 |
1512 declare | 1527 declare |
1513 Var : Node_Id; | 1528 Var : Node_Id; |
1514 -- Entity variable (left operand) | 1529 -- Entity variable (left operand) |
1656 | 1671 |
1657 if Is_Generic_Type (Typ) then | 1672 if Is_Generic_Type (Typ) then |
1658 return False; | 1673 return False; |
1659 end if; | 1674 end if; |
1660 | 1675 |
1661 -- Otherwise check bounds for compile time known | 1676 -- Otherwise check bounds for compile-time-known |
1662 | 1677 |
1663 if not Compile_Time_Known_Value (Type_Low_Bound (Typ)) then | 1678 if not Compile_Time_Known_Value (Type_Low_Bound (Typ)) then |
1664 return False; | 1679 return False; |
1665 elsif not Compile_Time_Known_Value (Type_High_Bound (Typ)) then | 1680 elsif not Compile_Time_Known_Value (Type_High_Bound (Typ)) then |
1666 return False; | 1681 return False; |
1694 then | 1709 then |
1695 return False; | 1710 return False; |
1696 end if; | 1711 end if; |
1697 | 1712 |
1698 -- If we have an entity name, then see if it is the name of a constant | 1713 -- If we have an entity name, then see if it is the name of a constant |
1699 -- and if so, test the corresponding constant value, or the name of | 1714 -- and if so, test the corresponding constant value, or the name of an |
1700 -- an enumeration literal, which is always a constant. | 1715 -- enumeration literal, which is always a constant. |
1701 | 1716 |
1702 if Present (Etype (Op)) and then Is_Entity_Name (Op) then | 1717 if Present (Etype (Op)) and then Is_Entity_Name (Op) then |
1703 declare | 1718 declare |
1704 E : constant Entity_Id := Entity (Op); | 1719 Ent : constant Entity_Id := Entity (Op); |
1705 V : Node_Id; | 1720 Val : Node_Id; |
1706 | 1721 |
1707 begin | 1722 begin |
1708 -- Never known at compile time if it is a packed array value. | 1723 -- Never known at compile time if it is a packed array value. We |
1709 -- We might want to try to evaluate these at compile time one | 1724 -- might want to try to evaluate these at compile time one day, |
1710 -- day, but we do not make that attempt now. | 1725 -- but we do not make that attempt now. |
1711 | 1726 |
1712 if Is_Packed_Array_Impl_Type (Etype (Op)) then | 1727 if Is_Packed_Array_Impl_Type (Etype (Op)) then |
1713 return False; | 1728 return False; |
1714 end if; | 1729 |
1715 | 1730 elsif Ekind (Ent) = E_Enumeration_Literal then |
1716 if Ekind (E) = E_Enumeration_Literal then | |
1717 return True; | 1731 return True; |
1718 | 1732 |
1719 elsif Ekind (E) = E_Constant then | 1733 elsif Ekind (Ent) = E_Constant then |
1720 V := Constant_Value (E); | 1734 Val := Constant_Value (Ent); |
1721 return Present (V) and then Compile_Time_Known_Value (V); | 1735 |
1736 if Present (Val) then | |
1737 | |
1738 -- Guard against an illegal deferred constant whose full | |
1739 -- view is initialized with a reference to itself. Treat | |
1740 -- this case as a value not known at compile time. | |
1741 | |
1742 if Is_Entity_Name (Val) and then Entity (Val) = Ent then | |
1743 return False; | |
1744 else | |
1745 return Compile_Time_Known_Value (Val); | |
1746 end if; | |
1747 | |
1748 -- Otherwise, the constant does not have a compile-time-known | |
1749 -- value. | |
1750 | |
1751 else | |
1752 return False; | |
1753 end if; | |
1722 end if; | 1754 end if; |
1723 end; | 1755 end; |
1724 | 1756 |
1725 -- We have a value, see if it is compile time known | 1757 -- We have a value, see if it is compile-time-known |
1726 | 1758 |
1727 else | 1759 else |
1728 -- Integer literals are worth storing in the cache | 1760 -- Integer literals are worth storing in the cache |
1729 | 1761 |
1730 if K = N_Integer_Literal then | 1762 if K = N_Integer_Literal then |
1783 return Present (V) | 1815 return Present (V) |
1784 and then Compile_Time_Known_Value_Or_Aggr (V); | 1816 and then Compile_Time_Known_Value_Or_Aggr (V); |
1785 end if; | 1817 end if; |
1786 end; | 1818 end; |
1787 | 1819 |
1788 -- We have a value, see if it is compile time known | 1820 -- We have a value, see if it is compile-time-known |
1789 | 1821 |
1790 else | 1822 else |
1791 if Compile_Time_Known_Value (Op) then | 1823 if Compile_Time_Known_Value (Op) then |
1792 return True; | 1824 return True; |
1793 | 1825 |
2299 | 2331 |
2300 declare | 2332 declare |
2301 Left_Str : constant Node_Id := Get_String_Val (Left); | 2333 Left_Str : constant Node_Id := Get_String_Val (Left); |
2302 Left_Len : Nat; | 2334 Left_Len : Nat; |
2303 Right_Str : constant Node_Id := Get_String_Val (Right); | 2335 Right_Str : constant Node_Id := Get_String_Val (Right); |
2304 Folded_Val : String_Id; | 2336 Folded_Val : String_Id := No_String; |
2305 | 2337 |
2306 begin | 2338 begin |
2307 -- Establish new string literal, and store left operand. We make | 2339 -- Establish new string literal, and store left operand. We make |
2308 -- sure to use the special Start_String that takes an operand if | 2340 -- sure to use the special Start_String that takes an operand if |
2309 -- the left operand is a string literal. Since this is optimized | 2341 -- the left operand is a string literal. Since this is optimized |
2605 Lin := UI_To_Int (Expr_Value (Sub) - Expr_Value (Lbd)) + 1; | 2637 Lin := UI_To_Int (Expr_Value (Sub) - Expr_Value (Lbd)) + 1; |
2606 | 2638 |
2607 if List_Length (Expressions (Arr)) >= Lin then | 2639 if List_Length (Expressions (Arr)) >= Lin then |
2608 Elm := Pick (Expressions (Arr), Lin); | 2640 Elm := Pick (Expressions (Arr), Lin); |
2609 | 2641 |
2610 -- If the resulting expression is compile time known, | 2642 -- If the resulting expression is compile-time-known, |
2611 -- then we can rewrite the indexed component with this | 2643 -- then we can rewrite the indexed component with this |
2612 -- value, being sure to mark the result as non-static. | 2644 -- value, being sure to mark the result as non-static. |
2613 -- We also reset the Sloc, in case this generates an | 2645 -- We also reset the Sloc, in case this generates an |
2614 -- error later on (e.g. 136'Access). | 2646 -- error later on (e.g. 136'Access). |
2615 | 2647 |
2660 -- the possibility of turning off the Is_Static_Expression flag after | 2692 -- the possibility of turning off the Is_Static_Expression flag after |
2661 -- analysis, but before resolution, when integer literals are generated in | 2693 -- analysis, but before resolution, when integer literals are generated in |
2662 -- the expander that do not correspond to static expressions. | 2694 -- the expander that do not correspond to static expressions. |
2663 | 2695 |
2664 procedure Eval_Integer_Literal (N : Node_Id) is | 2696 procedure Eval_Integer_Literal (N : Node_Id) is |
2665 T : constant Entity_Id := Etype (N); | 2697 function In_Any_Integer_Context (Context : Node_Id) return Boolean; |
2666 | |
2667 function In_Any_Integer_Context return Boolean; | |
2668 -- If the literal is resolved with a specific type in a context where | 2698 -- If the literal is resolved with a specific type in a context where |
2669 -- the expected type is Any_Integer, there are no range checks on the | 2699 -- the expected type is Any_Integer, there are no range checks on the |
2670 -- literal. By the time the literal is evaluated, it carries the type | 2700 -- literal. By the time the literal is evaluated, it carries the type |
2671 -- imposed by the enclosing expression, and we must recover the context | 2701 -- imposed by the enclosing expression, and we must recover the context |
2672 -- to determine that Any_Integer is meant. | 2702 -- to determine that Any_Integer is meant. |
2673 | 2703 |
2674 ---------------------------- | 2704 ---------------------------- |
2675 -- In_Any_Integer_Context -- | 2705 -- In_Any_Integer_Context -- |
2676 ---------------------------- | 2706 ---------------------------- |
2677 | 2707 |
2678 function In_Any_Integer_Context return Boolean is | 2708 function In_Any_Integer_Context (Context : Node_Id) return Boolean is |
2679 Par : constant Node_Id := Parent (N); | |
2680 K : constant Node_Kind := Nkind (Par); | |
2681 | |
2682 begin | 2709 begin |
2683 -- Any_Integer also appears in digits specifications for real types, | 2710 -- Any_Integer also appears in digits specifications for real types, |
2684 -- but those have bounds smaller that those of any integer base type, | 2711 -- but those have bounds smaller that those of any integer base type, |
2685 -- so we can safely ignore these cases. | 2712 -- so we can safely ignore these cases. |
2686 | 2713 |
2687 return Nkind_In (K, N_Number_Declaration, | 2714 return |
2688 N_Attribute_Reference, | 2715 Nkind_In (Context, N_Attribute_Definition_Clause, |
2689 N_Attribute_Definition_Clause, | 2716 N_Attribute_Reference, |
2690 N_Modular_Type_Definition, | 2717 N_Modular_Type_Definition, |
2691 N_Signed_Integer_Type_Definition); | 2718 N_Number_Declaration, |
2719 N_Signed_Integer_Type_Definition); | |
2692 end In_Any_Integer_Context; | 2720 end In_Any_Integer_Context; |
2693 | 2721 |
2722 -- Local variables | |
2723 | |
2724 Par : constant Node_Id := Parent (N); | |
2725 Typ : constant Entity_Id := Etype (N); | |
2726 | |
2694 -- Start of processing for Eval_Integer_Literal | 2727 -- Start of processing for Eval_Integer_Literal |
2695 | 2728 |
2696 begin | 2729 begin |
2697 | |
2698 -- If the literal appears in a non-expression context, then it is | 2730 -- If the literal appears in a non-expression context, then it is |
2699 -- certainly appearing in a non-static context, so check it. This is | 2731 -- certainly appearing in a non-static context, so check it. This is |
2700 -- actually a redundant check, since Check_Non_Static_Context would | 2732 -- actually a redundant check, since Check_Non_Static_Context would |
2701 -- check it, but it seems worthwhile to optimize out the call. | 2733 -- check it, but it seems worthwhile to optimize out the call. |
2702 | 2734 |
2703 -- An exception is made for a literal in an if or case expression | 2735 -- Additionally, when the literal appears within an if or case |
2704 | 2736 -- expression it must be checked as well. However, due to the literal |
2705 if (Nkind_In (Parent (N), N_If_Expression, N_Case_Expression_Alternative) | 2737 -- appearing within a conditional statement, expansion greatly changes |
2738 -- the nature of its context and performing some of the checks within | |
2739 -- Check_Non_Static_Context on an expanded literal may lead to spurious | |
2740 -- and misleading warnings. | |
2741 | |
2742 if (Nkind_In (Par, N_Case_Expression_Alternative, N_If_Expression) | |
2706 or else Nkind (Parent (N)) not in N_Subexpr) | 2743 or else Nkind (Parent (N)) not in N_Subexpr) |
2707 and then not In_Any_Integer_Context | 2744 and then (not Nkind_In (Par, N_Case_Expression_Alternative, |
2745 N_If_Expression) | |
2746 or else Comes_From_Source (N)) | |
2747 and then not In_Any_Integer_Context (Par) | |
2708 then | 2748 then |
2709 Check_Non_Static_Context (N); | 2749 Check_Non_Static_Context (N); |
2710 end if; | 2750 end if; |
2711 | 2751 |
2712 -- Modular integer literals must be in their base range | 2752 -- Modular integer literals must be in their base range |
2713 | 2753 |
2714 if Is_Modular_Integer_Type (T) | 2754 if Is_Modular_Integer_Type (Typ) |
2715 and then Is_Out_Of_Range (N, Base_Type (T), Assume_Valid => True) | 2755 and then Is_Out_Of_Range (N, Base_Type (Typ), Assume_Valid => True) |
2716 then | 2756 then |
2717 Out_Of_Range (N); | 2757 Out_Of_Range (N); |
2718 end if; | 2758 end if; |
2719 end Eval_Integer_Literal; | 2759 end Eval_Integer_Literal; |
2720 | 2760 |
3401 -- First easy case string literal | 3441 -- First easy case string literal |
3402 | 3442 |
3403 if Nkind (Expr) = N_String_Literal then | 3443 if Nkind (Expr) = N_String_Literal then |
3404 return UI_From_Int (String_Length (Strval (Expr))); | 3444 return UI_From_Int (String_Length (Strval (Expr))); |
3405 | 3445 |
3446 -- With frontend inlining as performed in GNATprove mode, a variable | |
3447 -- may be inserted that has a string literal subtype. Deal with this | |
3448 -- specially as for the previous case. | |
3449 | |
3450 elsif Ekind (Etype (Expr)) = E_String_Literal_Subtype then | |
3451 return String_Literal_Length (Etype (Expr)); | |
3452 | |
3406 -- Second easy case, not constrained subtype, so no length | 3453 -- Second easy case, not constrained subtype, so no length |
3407 | 3454 |
3408 elsif not Is_Constrained (Etype (Expr)) then | 3455 elsif not Is_Constrained (Etype (Expr)) then |
3409 return Uint_Minus_1; | 3456 return Uint_Minus_1; |
3410 end if; | 3457 end if; |
4156 CV_Ent : CV_Entry renames CV_Cache (Nat (N) mod CV_Cache_Size); | 4203 CV_Ent : CV_Entry renames CV_Cache (Nat (N) mod CV_Cache_Size); |
4157 Ent : Entity_Id; | 4204 Ent : Entity_Id; |
4158 Val : Uint; | 4205 Val : Uint; |
4159 | 4206 |
4160 begin | 4207 begin |
4161 -- If already in cache, then we know it's compile time known and we can | 4208 -- If already in cache, then we know it's compile-time-known and we can |
4162 -- return the value that was previously stored in the cache since | 4209 -- return the value that was previously stored in the cache since |
4163 -- compile time known values cannot change. | 4210 -- compile-time-known values cannot change. |
4164 | 4211 |
4165 if CV_Ent.N = N then | 4212 if CV_Ent.N = N then |
4166 return CV_Ent.V; | 4213 return CV_Ent.V; |
4167 end if; | 4214 end if; |
4168 | 4215 |
4673 then | 4720 then |
4674 return True; | 4721 return True; |
4675 end if; | 4722 end if; |
4676 | 4723 |
4677 -- If bounds not comparable at compile time, then the bounds of T2 | 4724 -- If bounds not comparable at compile time, then the bounds of T2 |
4678 -- must be compile time known or we cannot answer the query. | 4725 -- must be compile-time-known or we cannot answer the query. |
4679 | 4726 |
4680 if not Compile_Time_Known_Value (L2) | 4727 if not Compile_Time_Known_Value (L2) |
4681 or else not Compile_Time_Known_Value (H2) | 4728 or else not Compile_Time_Known_Value (H2) |
4682 then | 4729 then |
4683 return False; | 4730 return False; |
4753 ------------------- | 4800 ------------------- |
4754 -- Is_Null_Range -- | 4801 -- Is_Null_Range -- |
4755 ------------------- | 4802 ------------------- |
4756 | 4803 |
4757 function Is_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean is | 4804 function Is_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean is |
4758 Typ : constant Entity_Id := Etype (Lo); | 4805 begin |
4759 | 4806 if Compile_Time_Known_Value (Lo) |
4760 begin | 4807 and then Compile_Time_Known_Value (Hi) |
4761 if not Compile_Time_Known_Value (Lo) | |
4762 or else not Compile_Time_Known_Value (Hi) | |
4763 then | 4808 then |
4809 declare | |
4810 Typ : Entity_Id := Etype (Lo); | |
4811 begin | |
4812 -- When called from the frontend, as part of the analysis of | |
4813 -- potentially static expressions, Typ will be the full view of a | |
4814 -- type with all the info needed to answer this query. When called | |
4815 -- from the backend, for example to know whether a range of a loop | |
4816 -- is null, Typ might be a private type and we need to explicitly | |
4817 -- switch to its corresponding full view to access the same info. | |
4818 | |
4819 if Is_Incomplete_Or_Private_Type (Typ) | |
4820 and then Present (Full_View (Typ)) | |
4821 then | |
4822 Typ := Full_View (Typ); | |
4823 end if; | |
4824 | |
4825 if Is_Discrete_Type (Typ) then | |
4826 return Expr_Value (Lo) > Expr_Value (Hi); | |
4827 else pragma Assert (Is_Real_Type (Typ)); | |
4828 return Expr_Value_R (Lo) > Expr_Value_R (Hi); | |
4829 end if; | |
4830 end; | |
4831 else | |
4764 return False; | 4832 return False; |
4765 end if; | |
4766 | |
4767 if Is_Discrete_Type (Typ) then | |
4768 return Expr_Value (Lo) > Expr_Value (Hi); | |
4769 else pragma Assert (Is_Real_Type (Typ)); | |
4770 return Expr_Value_R (Lo) > Expr_Value_R (Hi); | |
4771 end if; | 4833 end if; |
4772 end Is_Null_Range; | 4834 end Is_Null_Range; |
4773 | 4835 |
4774 ------------------------- | 4836 ------------------------- |
4775 -- Is_OK_Static_Choice -- | 4837 -- Is_OK_Static_Choice -- |
5328 -------------------- | 5390 -------------------- |
5329 -- Not_Null_Range -- | 5391 -- Not_Null_Range -- |
5330 -------------------- | 5392 -------------------- |
5331 | 5393 |
5332 function Not_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean is | 5394 function Not_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean is |
5333 Typ : constant Entity_Id := Etype (Lo); | 5395 begin |
5334 | 5396 if Compile_Time_Known_Value (Lo) |
5335 begin | 5397 and then Compile_Time_Known_Value (Hi) |
5336 if not Compile_Time_Known_Value (Lo) | |
5337 or else not Compile_Time_Known_Value (Hi) | |
5338 then | 5398 then |
5399 declare | |
5400 Typ : Entity_Id := Etype (Lo); | |
5401 begin | |
5402 -- When called from the frontend, as part of the analysis of | |
5403 -- potentially static expressions, Typ will be the full view of a | |
5404 -- type with all the info needed to answer this query. When called | |
5405 -- from the backend, for example to know whether a range of a loop | |
5406 -- is null, Typ might be a private type and we need to explicitly | |
5407 -- switch to its corresponding full view to access the same info. | |
5408 | |
5409 if Is_Incomplete_Or_Private_Type (Typ) | |
5410 and then Present (Full_View (Typ)) | |
5411 then | |
5412 Typ := Full_View (Typ); | |
5413 end if; | |
5414 | |
5415 if Is_Discrete_Type (Typ) then | |
5416 return Expr_Value (Lo) <= Expr_Value (Hi); | |
5417 else pragma Assert (Is_Real_Type (Typ)); | |
5418 return Expr_Value_R (Lo) <= Expr_Value_R (Hi); | |
5419 end if; | |
5420 end; | |
5421 else | |
5339 return False; | 5422 return False; |
5340 end if; | 5423 end if; |
5341 | 5424 |
5342 if Is_Discrete_Type (Typ) then | |
5343 return Expr_Value (Lo) <= Expr_Value (Hi); | |
5344 else pragma Assert (Is_Real_Type (Typ)); | |
5345 return Expr_Value_R (Lo) <= Expr_Value_R (Hi); | |
5346 end if; | |
5347 end Not_Null_Range; | 5425 end Not_Null_Range; |
5348 | 5426 |
5349 ------------- | 5427 ------------- |
5350 -- OK_Bits -- | 5428 -- OK_Bits -- |
5351 ------------- | 5429 ------------- |
5397 Error_Msg_N | 5475 Error_Msg_N |
5398 ("length of packed array must not exceed Integer''Last", | 5476 ("length of packed array must not exceed Integer''Last", |
5399 First_Rep_Item (Parent (N))); | 5477 First_Rep_Item (Parent (N))); |
5400 Rewrite (N, Make_Integer_Literal (Sloc (N), Uint_1)); | 5478 Rewrite (N, Make_Integer_Literal (Sloc (N), Uint_1)); |
5401 | 5479 |
5402 -- All cases except the special array case | 5480 -- All cases except the special array case. |
5403 | 5481 -- No message if we are dealing with System.Priority values in |
5404 else | 5482 -- CodePeer mode where the target runtime may have more priorities. |
5483 | |
5484 elsif not CodePeer_Mode or else Etype (N) /= RTE (RE_Priority) then | |
5405 Apply_Compile_Time_Constraint_Error | 5485 Apply_Compile_Time_Constraint_Error |
5406 (N, "value not in range of}", CE_Range_Check_Failed); | 5486 (N, "value not in range of}", CE_Range_Check_Failed); |
5407 end if; | 5487 end if; |
5408 | 5488 |
5409 -- Here we generate a warning for the Ada 83 case, or when we are in an | 5489 -- Here we generate a warning for the Ada 83 case, or when we are in an |
5612 ------------------------- | 5692 ------------------------- |
5613 -- Rewrite_In_Raise_CE -- | 5693 -- Rewrite_In_Raise_CE -- |
5614 ------------------------- | 5694 ------------------------- |
5615 | 5695 |
5616 procedure Rewrite_In_Raise_CE (N : Node_Id; Exp : Node_Id) is | 5696 procedure Rewrite_In_Raise_CE (N : Node_Id; Exp : Node_Id) is |
5697 Stat : constant Boolean := Is_Static_Expression (N); | |
5617 Typ : constant Entity_Id := Etype (N); | 5698 Typ : constant Entity_Id := Etype (N); |
5618 Stat : constant Boolean := Is_Static_Expression (N); | |
5619 | 5699 |
5620 begin | 5700 begin |
5621 -- If we want to raise CE in the condition of a N_Raise_CE node, we | 5701 -- If we want to raise CE in the condition of a N_Raise_CE node, we |
5622 -- can just clear the condition if the reason is appropriate. We do | 5702 -- can just clear the condition if the reason is appropriate. We do |
5623 -- not do this operation if the parent has a reason other than range | 5703 -- not do this operation if the parent has a reason other than range |
5631 Set_Condition (Parent (N), Empty); | 5711 Set_Condition (Parent (N), Empty); |
5632 | 5712 |
5633 -- Else build an explicit N_Raise_CE | 5713 -- Else build an explicit N_Raise_CE |
5634 | 5714 |
5635 else | 5715 else |
5636 Rewrite (N, | 5716 if Nkind (Exp) = N_Raise_Constraint_Error then |
5637 Make_Raise_Constraint_Error (Sloc (Exp), | 5717 Rewrite (N, |
5638 Reason => CE_Range_Check_Failed)); | 5718 Make_Raise_Constraint_Error (Sloc (Exp), |
5719 Reason => Reason (Exp))); | |
5720 else | |
5721 Rewrite (N, | |
5722 Make_Raise_Constraint_Error (Sloc (Exp), | |
5723 Reason => CE_Range_Check_Failed)); | |
5724 end if; | |
5725 | |
5639 Set_Raises_Constraint_Error (N); | 5726 Set_Raises_Constraint_Error (N); |
5640 Set_Etype (N, Typ); | 5727 Set_Etype (N, Typ); |
5641 end if; | 5728 end if; |
5642 | 5729 |
5643 -- Set proper flags in result | 5730 -- Set proper flags in result |
6313 Val : Uint; | 6400 Val : Uint; |
6314 Valr : Ureal; | 6401 Valr : Ureal; |
6315 | 6402 |
6316 pragma Warnings (Off, Assume_Valid); | 6403 pragma Warnings (Off, Assume_Valid); |
6317 -- For now Assume_Valid is unreferenced since the current implementation | 6404 -- For now Assume_Valid is unreferenced since the current implementation |
6318 -- always returns Unknown if N is not a compile time known value, but we | 6405 -- always returns Unknown if N is not a compile-time-known value, but we |
6319 -- keep the parameter to allow for future enhancements in which we try | 6406 -- keep the parameter to allow for future enhancements in which we try |
6320 -- to get the information in the variable case as well. | 6407 -- to get the information in the variable case as well. |
6321 | 6408 |
6322 begin | 6409 begin |
6323 -- If an error was posted on expression, then return Unknown, we do not | 6410 -- If an error was posted on expression, then return Unknown, we do not |
6346 elsif not Is_Scalar_Type (Typ) then | 6433 elsif not Is_Scalar_Type (Typ) then |
6347 return Unknown; | 6434 return Unknown; |
6348 | 6435 |
6349 -- Never known if this is a generic type, since the bounds of generic | 6436 -- Never known if this is a generic type, since the bounds of generic |
6350 -- types are junk. Note that if we only checked for static expressions | 6437 -- types are junk. Note that if we only checked for static expressions |
6351 -- (instead of compile time known values) below, we would not need this | 6438 -- (instead of compile-time-known values) below, we would not need this |
6352 -- check, because values of a generic type can never be static, but they | 6439 -- check, because values of a generic type can never be static, but they |
6353 -- can be known at compile time. | 6440 -- can be known at compile time. |
6354 | 6441 |
6355 elsif Is_Generic_Type (Typ) then | 6442 elsif Is_Generic_Type (Typ) then |
6356 return Unknown; | 6443 return Unknown; |