summaryrefslogtreecommitdiff
path: root/gcc/ada/sem_eval.adb
diff options
context:
space:
mode:
authorbosch <bosch@138bc75d-0d04-0410-961f-82ee72b054a4>2002-03-08 20:11:04 +0000
committerbosch <bosch@138bc75d-0d04-0410-961f-82ee72b054a4>2002-03-08 20:11:04 +0000
commitf15731c43ae5e8cea424ea40f905c19afa1bd2e4 (patch)
treeb584a79288c93215b05fb451943291ccd039388b /gcc/ada/sem_eval.adb
parent1d347c236ad815c77bd345611ed221b0bd6091de (diff)
downloadgcc-f15731c43ae5e8cea424ea40f905c19afa1bd2e4.tar.gz
* 41intnam.ads, 42intnam.ads, 4aintnam.ads, 4cintnam.ads,
4dintnam.ads, 4gintnam.ads, 4hintnam.ads, 4lintnam.ads, 4mintnam.ads, 4pintnam.ads, 4rintnam.ads, 4sintnam.ads, 4uintnam.ads, 4vcalend.adb, 4zintnam.ads, 52system.ads, 5amastop.adb, 5asystem.ads, 5ataprop.adb, 5atpopsp.adb, 5avxwork.ads, 5bosinte.adb, 5bsystem.ads, 5esystem.ads, 5fsystem.ads, 5ftaprop.adb, 5ginterr.adb, 5gmastop.adb, 5gsystem.ads, 5gtaprop.adb, 5gtasinf.adb, 5gtasinf.ads, 5hparame.ads, 5hsystem.ads, 5htaprop.adb, 5htraceb.adb, 5itaprop.adb, 5ksystem.ads, 5kvxwork.ads, 5lintman.adb, 5lsystem.ads, 5mvxwork.ads, 5ninmaop.adb, 5nosinte.ads, 5ntaprop.adb, 5ointerr.adb, 5omastop.adb, 5oosinte.adb, 5osystem.ads, 5otaprop.adb, 5otaspri.ads, 5pvxwork.ads, 5qtaprop.adb, 5sintman.adb, 5ssystem.ads, 5staprop.adb, 5stpopse.adb, 5svxwork.ads, 5tosinte.ads, 5uintman.adb, 5vasthan.adb, 5vinmaop.adb, 5vinterr.adb, 5vintman.adb, 5vmastop.adb, 5vparame.ads, 5vsystem.ads, 5vtaprop.adb, 5vtpopde.adb, 5wmemory.adb, 5wsystem.ads, 5wtaprop.adb, 5ysystem.ads, 5zinterr.adb, 5zintman.adb, 5zosinte.adb, 5zosinte.ads, 5zsystem.ads, 5ztaprop.adb, 6vcpp.adb, 6vcstrea.adb, 7sintman.adb, 7staprop.adb, 7stpopsp.adb, 9drpc.adb, Make-lang.in, Makefile.in, a-caldel.adb, a-comlin.ads, a-dynpri.adb, a-except.adb, a-except.ads, a-finali.adb, a-ncelfu.ads, a-reatim.adb, a-retide.adb, a-stream.ads, a-ststio.adb, a-ststio.ads, a-stwifi.adb, a-tags.adb, a-tasatt.adb, a-textio.adb, a-tideau.adb, a-tiflau.adb, a-tigeau.adb, a-tigeau.ads, a-tiinau.adb, a-timoau.adb, a-witeio.adb, a-wtdeau.adb, a-wtenau.adb, a-wtflau.adb, a-wtgeau.adb, a-wtgeau.ads, a-wtinau.adb, a-wtmoau.adb, ada-tree.def, ada-tree.h, adaint.c, adaint.h, ali-util.adb, ali.adb, ali.ads, atree.adb, atree.ads, atree.h, back_end.adb, bcheck.adb, bindgen.adb, bindusg.adb, checks.adb, comperr.adb, config-lang.in, csets.adb, csets.ads, cstand.adb, cstreams.c, debug.adb, debug.ads, decl.c, einfo.adb, einfo.ads, einfo.h, elists.h, errout.adb, errout.ads, eval_fat.adb, exp_aggr.adb, exp_attr.adb, exp_ch11.adb, exp_ch12.adb, exp_ch13.adb, exp_ch2.adb, exp_ch3.adb, exp_ch3.ads, exp_ch4.adb, exp_ch5.adb, exp_ch6.adb, exp_ch7.adb, exp_ch7.ads, exp_ch9.adb, exp_ch9.ads, exp_dbug.adb, exp_dbug.ads, exp_disp.ads, exp_dist.adb, exp_fixd.adb, exp_intr.adb, exp_pakd.adb, exp_prag.adb, exp_strm.adb, exp_util.adb, exp_util.ads, expander.adb, expect.c, fe.h, fmap.adb, fmap.ads, fname-uf.adb, freeze.adb, frontend.adb, g-awk.adb, g-cgideb.adb, g-comlin.adb, g-comlin.ads, g-debpoo.adb, g-dirope.adb, g-dirope.ads, g-dyntab.adb, g-expect.adb, g-expect.ads, g-io.ads, g-io_aux.adb, g-io_aux.ads, g-locfil.adb, g-locfil.ads, g-os_lib.adb, g-os_lib.ads, g-regexp.adb, g-regpat.adb, g-socket.adb, g-socket.ads, g-spipat.adb, g-table.adb, g-trasym.adb, g-trasym.ads, gigi.h, gmem.c, gnat1drv.adb, gnatbind.adb, gnatbl.c, gnatchop.adb, gnatcmd.adb, gnatdll.adb, gnatfind.adb, gnatlbr.adb, gnatlink.adb, gnatls.adb, gnatmem.adb, gnatprep.adb, gnatvsn.ads, gnatxref.adb, hlo.adb, hostparm.ads, i-cobol.adb, i-cpp.adb, i-cstrea.ads, i-cstrin.adb, i-pacdec.adb, i-vxwork.ads, impunit.adb, init.c, inline.adb, io-aux.c, layout.adb, lib-load.adb, lib-util.adb, lib-writ.adb, lib-writ.ads, lib-xref.adb, lib-xref.ads, lib.adb, lib.ads, make.adb, makeusg.adb, mdll.adb, memroot.adb, misc.c, mlib-tgt.adb, mlib-utl.adb, mlib-utl.ads, mlib.adb, namet.adb, namet.ads, namet.h, nlists.h, nmake.adb, nmake.ads, nmake.adt, opt.adb, opt.ads, osint.adb, osint.ads, output.adb, output.ads, par-ch2.adb, par-ch3.adb, par-ch5.adb, par-prag.adb, par-tchk.adb, par-util.adb, par.adb, prj-attr.adb, prj-dect.adb, prj-env.adb, prj-env.ads, prj-nmsc.adb, prj-part.adb, prj-proc.adb, prj-strt.adb, prj-tree.adb, prj-tree.ads, prj.adb, prj.ads, raise.c, raise.h, repinfo.adb, restrict.adb, restrict.ads, rident.ads, rtsfind.adb, rtsfind.ads, s-arit64.adb, s-asthan.adb, s-atacco.adb, s-atacco.ads, s-auxdec.adb, s-crc32.adb, s-crc32.ads, s-direio.adb, s-fatgen.adb, s-fileio.adb, s-finimp.adb, s-gloloc.adb, s-gloloc.ads, s-interr.adb, s-mastop.adb, s-mastop.ads, s-memory.adb, s-parame.ads, s-parint.adb, s-pooglo.adb, s-pooloc.adb, s-rpc.adb, s-secsta.adb, s-sequio.adb, s-shasto.adb, s-soflin.adb, s-soflin.ads, s-stache.adb, s-taasde.adb, s-taasde.ads, s-tadeca.adb, s-tadeca.ads, s-tadert.adb, s-tadert.ads, s-taenca.adb, s-taenca.ads, s-taprob.adb, s-taprop.ads, s-tarest.adb, s-tasdeb.adb, s-tasini.adb, s-tasini.ads, s-taskin.adb, s-taskin.ads, s-tasque.adb, s-tasque.ads, s-tasren.adb, s-tasren.ads, s-tassta.adb, s-tasuti.adb, s-tasuti.ads, s-tataat.adb, s-tataat.ads, s-tpoben.adb, s-tpoben.ads, s-tpobop.adb, s-tposen.adb, s-tposen.ads, s-traceb.adb, s-traceb.ads, s-unstyp.ads, s-widenu.adb, scn-nlit.adb, scn.adb, sem.adb, sem_aggr.adb, sem_attr.adb, sem_attr.ads, sem_case.adb, sem_ch10.adb, sem_ch11.adb, sem_ch11.ads, sem_ch12.adb, sem_ch13.adb, sem_ch13.ads, sem_ch2.adb, sem_ch3.adb, sem_ch3.ads, sem_ch4.adb, sem_ch5.adb, sem_ch6.adb, sem_ch6.ads, sem_ch7.adb, sem_ch8.adb, sem_ch8.ads, sem_ch9.adb, sem_disp.adb, sem_dist.adb, sem_elab.adb, sem_elim.adb, sem_elim.ads, sem_eval.adb, sem_intr.adb, sem_mech.adb, sem_prag.adb, sem_res.adb, sem_type.adb, sem_util.adb, sem_util.ads, sem_vfpt.adb, sem_warn.adb, sinfo.adb, sinfo.ads, sinfo.h, sinput-l.adb, sinput-l.ads, sinput.adb, sinput.ads, snames.adb, snames.ads, snames.h, sprint.adb, sprint.ads, stringt.adb, stringt.ads, stringt.h, style.adb, switch.adb, switch.ads, sysdep.c, system.ads, table.adb, targparm.adb, targparm.ads, targtyps.c, tbuild.adb, tbuild.ads, tracebak.c, trans.c, tree_gen.adb, tree_io.adb, treepr.adb, treepr.ads, treeprs.ads, treeprs.adt, ttypes.ads, types.adb, types.ads, types.h, uintp.ads, urealp.ads, usage.adb, utils.c, utils2.c, validsw.adb, xnmake.adb, xr_tabls.adb, xr_tabls.ads, xref_lib.adb, xref_lib.ads : Merge in ACT changes. * 1ssecsta.adb, 1ssecsta.ads, a-chlat9.ads, a-cwila9.ads, g-enblsp.adb, g-md5.adb, g-md5.ads, gnatname.adb, gnatname.ads, mkdir.c, osint-b.adb, osint-b.ads, osint-c.adb, osint-c.ads, osint-l.adb, osint-l.ads, osint-m.adb, osint-m.ads : New files * 3lsoccon.ads, 5qparame.ads, 5qvxwork.ads, 5smastop.adb, 5zparame.ads, gnatmain.adb, gnatmain.ads, gnatpsys.adb : Removed * mdllfile.adb, mdllfile.ads, mdlltool.adb, mdlltool.ads : Renamed to mdll-fil.ad[bs] and mdll-util.ad[bs] * mdll-fil.adb, mdll-fil.ads, mdll-utl.adb, mdll-utl.ads : Renamed from mdllfile.ad[bs] and mdlltool.ad[bs] git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@50451 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/sem_eval.adb')
-rw-r--r--gcc/ada/sem_eval.adb279
1 files changed, 219 insertions, 60 deletions
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index 97930a6c1b5..9decc499f62 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -1,4 +1,4 @@
-------------------------------------------------------------------------------
+---------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
@@ -8,7 +8,7 @@
-- --
-- $Revision$
-- --
--- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -47,6 +47,7 @@ with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Stringt; use Stringt;
+with Tbuild; use Tbuild;
package body Sem_Eval is
@@ -96,17 +97,44 @@ package body Sem_Eval is
type Bits is array (Nat range <>) of Boolean;
-- Used to convert unsigned (modular) values for folding logical ops
+ -- The following definitions are used to maintain a cache of nodes that
+ -- have compile time known values. The cache is maintained only for
+ -- discrete types (the most common case), and is populated by calls to
+ -- Compile_Time_Known_Value and Expr_Value, but only used by Expr_Value
+ -- since it is possible for the status to change (in particular it is
+ -- possible for a node to get replaced by a constraint error node).
+
+ CV_Bits : constant := 5;
+ -- Number of low order bits of Node_Id value used to reference entries
+ -- in the cache table.
+
+ CV_Cache_Size : constant Nat := 2 ** CV_Bits;
+ -- Size of cache for compile time values
+
+ subtype CV_Range is Nat range 0 .. CV_Cache_Size;
+
+ type CV_Entry is record
+ N : Node_Id;
+ V : Uint;
+ end record;
+
+ type CV_Cache_Array is array (CV_Range) of CV_Entry;
+
+ CV_Cache : CV_Cache_Array := (others => (Node_High_Bound, Uint_0));
+ -- This is the actual cache, with entries consisting of node/value pairs,
+ -- and the impossible value Node_High_Bound used for unset entries.
+
-----------------------
-- Local Subprograms --
-----------------------
- function OK_Bits (N : Node_Id; Bits : Uint) return Boolean;
- -- Bits represents the number of bits in an integer value to be computed
- -- (but the value has not been computed yet). If this value in Bits is
- -- reasonable, a result of True is returned, with the implication that
- -- the caller should go ahead and complete the calculation. If the value
- -- in Bits is unreasonably large, then an error is posted on node N, and
- -- False is returned (and the caller skips the proposed calculation).
+ function Constant_Array_Ref (Op : Node_Id) return Node_Id;
+ -- The caller has checked that Op is an array reference (i.e. that its
+ -- node kind is N_Indexed_Component). If the array reference is constant
+ -- at compile time, and yields a constant value of a discrete type, then
+ -- the expression node for the constant value is returned. otherwise Empty
+ -- is returned. This is used by Compile_Time_Known_Value, as well as by
+ -- Expr_Value and Expr_Rep_Value.
function From_Bits (B : Bits; T : Entity_Id) return Uint;
-- Converts a bit string of length B'Length to a Uint value to be used
@@ -121,6 +149,14 @@ package body Sem_Eval is
-- two must be available, or the operand would not have been marked
-- as foldable in the earlier analysis of the operation).
+ function OK_Bits (N : Node_Id; Bits : Uint) return Boolean;
+ -- Bits represents the number of bits in an integer value to be computed
+ -- (but the value has not been computed yet). If this value in Bits is
+ -- reasonable, a result of True is returned, with the implication that
+ -- the caller should go ahead and complete the calculation. If the value
+ -- in Bits is unreasonably large, then an error is posted on node N, and
+ -- False is returned (and the caller skips the proposed calculation).
+
procedure Out_Of_Range (N : Node_Id);
-- This procedure is called if it is determined that node N, which
-- appears in a non-static context, is a compile time known value
@@ -218,11 +254,6 @@ package body Sem_Eval is
and then not Is_Machine_Number (N)
and then not Is_Generic_Type (Etype (N))
and then Etype (N) /= Universal_Real
- and then not Debug_Flag_S
- and then (not Debug_Flag_T
- or else
- (Nkind (Parent (N)) = N_Object_Declaration
- and then Constant_Present (Parent (N))))
then
-- Check that value is in bounds before converting to machine
-- number, so as not to lose case where value overflows in the
@@ -282,7 +313,8 @@ package body Sem_Eval is
Intval (N) > Expr_Value (Type_High_Bound (Universal_Integer)))
then
Apply_Compile_Time_Constraint_Error
- (N, "non-static universal integer value out of range?");
+ (N, "non-static universal integer value out of range?",
+ CE_Range_Check_Failed);
-- Check out of range of base type
@@ -302,7 +334,7 @@ package body Sem_Eval is
elsif Is_Out_Of_Range (N, T) then
Apply_Compile_Time_Constraint_Error
- (N, "value not in range of}?");
+ (N, "value not in range of}?", CE_Range_Check_Failed);
elsif Checks_On then
Enable_Range_Check (N);
@@ -327,6 +359,7 @@ package body Sem_Eval is
then
Apply_Compile_Time_Constraint_Error
(N, "string length wrong for}?",
+ CE_Length_Check_Failed,
Ent => Ttype,
Typ => Ttype);
end if;
@@ -541,6 +574,18 @@ package body Sem_Eval is
-- Start of processing for Compile_Time_Compare
begin
+ -- If either operand could raise constraint error, then we cannot
+ -- know the result at compile time (since CE may be raised!)
+
+ if not (Cannot_Raise_Constraint_Error (L)
+ and then
+ Cannot_Raise_Constraint_Error (R))
+ then
+ return Unknown;
+ end if;
+
+ -- Identical operands are most certainly equal
+
if L = R then
return EQ;
@@ -684,7 +729,9 @@ package body Sem_Eval is
------------------------------
function Compile_Time_Known_Value (Op : Node_Id) return Boolean is
- K : constant Node_Kind := Nkind (Op);
+ K : constant Node_Kind := Nkind (Op);
+ CV_Ent : CV_Entry renames CV_Cache (Nat (Op) mod CV_Cache_Size);
+ Val : Node_Id;
begin
-- Never known at compile time if bad type or raises constraint error
@@ -719,10 +766,7 @@ package body Sem_Eval is
if Ekind (E) = E_Enumeration_Literal then
return True;
- elsif Ekind (E) /= E_Constant then
- return False;
-
- else
+ elsif Ekind (E) = E_Constant then
V := Constant_Value (E);
return Present (V) and then Compile_Time_Known_Value (V);
end if;
@@ -731,10 +775,16 @@ package body Sem_Eval is
-- We have a value, see if it is compile time known
else
- -- Literals and NULL are known at compile time
+ -- Integer literals are worth storing in the cache
- if K = N_Integer_Literal
- or else
+ if K = N_Integer_Literal then
+ CV_Ent.N := Op;
+ CV_Ent.V := Intval (Op);
+ return True;
+
+ -- Other literals and NULL are known at compile time
+
+ elsif
K = N_Character_Literal
or else
K = N_Real_Literal
@@ -752,13 +802,29 @@ package body Sem_Eval is
elsif K = N_Attribute_Reference then
return Attribute_Name (Op) = Name_Null_Parameter;
- -- All other types of values are not known at compile time
+ -- A reference to an element of a constant array may be constant.
- else
- return False;
- end if;
+ elsif K = N_Indexed_Component then
+ Val := Constant_Array_Ref (Op);
+ if Present (Val) then
+ CV_Ent.N := Op;
+ CV_Ent.V := Expr_Value (Val);
+ return True;
+ end if;
+ end if;
end if;
+
+ -- If we fall through, not known at compile time
+
+ return False;
+
+ -- If we get an exception while trying to do this test, then some error
+ -- has occurred, and we simply say that the value is not known after all
+
+ exception
+ when others =>
+ return False;
end Compile_Time_Known_Value;
--------------------------------------
@@ -843,6 +909,50 @@ package body Sem_Eval is
end if;
end Compile_Time_Known_Value_Or_Aggr;
+ ------------------------
+ -- Constant_Array_Ref --
+ ------------------------
+
+ function Constant_Array_Ref (Op : Node_Id) return Node_Id is
+ begin
+ if List_Length (Expressions (Op)) = 1
+ and then Is_Entity_Name (Prefix (Op))
+ and then Ekind (Entity (Prefix (Op))) = E_Constant
+ then
+ declare
+ Arr : constant Node_Id := Constant_Value (Entity (Prefix (Op)));
+ Sub : constant Node_Id := First (Expressions (Op));
+ Ind : constant Node_Id := First_Index (Etype (Arr));
+ Lbd : constant Node_Id := Type_Low_Bound (Etype (Ind));
+
+ Lin : Nat;
+ -- Linear one's origin subscript value for array reference
+
+ Elm : Node_Id;
+ -- Value from constant array
+
+ begin
+ if Compile_Time_Known_Value (Sub)
+ and then Nkind (Arr) = N_Aggregate
+ and then Compile_Time_Known_Value (Lbd)
+ and then Is_Discrete_Type (Component_Type (Etype (Arr)))
+ then
+ Lin := UI_To_Int (Expr_Value (Sub) - Expr_Value (Lbd)) + 1;
+
+ if List_Length (Expressions (Arr)) >= Lin then
+ Elm := Pick (Expressions (Arr), Lin);
+
+ if Compile_Time_Known_Value (Elm) then
+ return Elm;
+ end if;
+ end if;
+ end if;
+ end;
+ end if;
+
+ return Empty;
+ end Constant_Array_Ref;
+
-----------------
-- Eval_Actual --
-----------------
@@ -931,7 +1041,7 @@ package body Sem_Eval is
if Right_Int = 0 then
Apply_Compile_Time_Constraint_Error
- (N, "division by zero");
+ (N, "division by zero", CE_Divide_By_Zero);
return;
else
Result := Left_Int / Right_Int;
@@ -944,7 +1054,7 @@ package body Sem_Eval is
if Right_Int = 0 then
Apply_Compile_Time_Constraint_Error
- (N, "mod with zero divisor");
+ (N, "mod with zero divisor", CE_Divide_By_Zero);
return;
else
Result := Left_Int mod Right_Int;
@@ -957,7 +1067,7 @@ package body Sem_Eval is
if Right_Int = 0 then
Apply_Compile_Time_Constraint_Error
- (N, "rem with zero divisor");
+ (N, "rem with zero divisor", CE_Divide_By_Zero);
return;
else
Result := Left_Int rem Right_Int;
@@ -1011,7 +1121,7 @@ package body Sem_Eval is
else pragma Assert (Nkind (N) = N_Op_Divide);
if UR_Is_Zero (Right_Real) then
Apply_Compile_Time_Constraint_Error
- (N, "division by zero");
+ (N, "division by zero", CE_Divide_By_Zero);
return;
end if;
@@ -1033,6 +1143,8 @@ package body Sem_Eval is
-- Nothing to be done!
procedure Eval_Character_Literal (N : Node_Id) is
+ pragma Warnings (Off, N);
+
begin
null;
end Eval_Character_Literal;
@@ -1552,7 +1664,7 @@ package body Sem_Eval is
if Right_Int < 0 then
Apply_Compile_Time_Constraint_Error
- (N, "integer exponent negative");
+ (N, "integer exponent negative", CE_Range_Check_Failed);
return;
else
@@ -1583,7 +1695,7 @@ package body Sem_Eval is
if Right_Int < 0 then
Apply_Compile_Time_Constraint_Error
- (N, "zero ** negative integer");
+ (N, "zero ** negative integer", CE_Range_Check_Failed);
return;
else
Fold_Ureal (N, Ureal_0);
@@ -1655,8 +1767,9 @@ package body Sem_Eval is
Operand : constant Node_Id := Expression (N);
Target_Type : constant Entity_Id := Entity (Subtype_Mark (N));
- Stat : Boolean;
- Fold : Boolean;
+ Stat : Boolean;
+ Fold : Boolean;
+ Hex : Boolean;
begin
-- Can only fold if target is string or scalar and subtype is static
@@ -1687,12 +1800,23 @@ package body Sem_Eval is
return;
end if;
+ -- Here we will fold, save Print_In_Hex indication
+
+ Hex := Nkind (Operand) = N_Integer_Literal
+ and then Print_In_Hex (Operand);
+
-- Fold the result of qualification
if Is_Discrete_Type (Target_Type) then
Fold_Uint (N, Expr_Value (Operand));
Set_Is_Static_Expression (N, Stat);
+ -- Preserve Print_In_Hex indication
+
+ if Hex and then Nkind (N) = N_Integer_Literal then
+ Set_Print_In_Hex (N);
+ end if;
+
elsif Is_Real_Type (Target_Type) then
Fold_Ureal (N, Expr_Value_R (Operand));
Set_Is_Static_Expression (N, Stat);
@@ -2072,7 +2196,7 @@ package body Sem_Eval is
if String_Literal_Length (T) > String_Type_Len (B) then
Apply_Compile_Time_Constraint_Error
- (N, "string literal too long for}",
+ (N, "string literal too long for}", CE_Length_Check_Failed,
Ent => B,
Typ => First_Subtype (B));
@@ -2083,6 +2207,7 @@ package body Sem_Eval is
then
Apply_Compile_Time_Constraint_Error
(N, "null string literal not allowed for}",
+ CE_Length_Check_Failed,
Ent => B,
Typ => First_Subtype (B));
end if;
@@ -2331,8 +2456,9 @@ package body Sem_Eval is
--------------------
function Expr_Rep_Value (N : Node_Id) return Uint is
- Kind : constant Node_Kind := Nkind (N);
- Ent : Entity_Id;
+ Kind : constant Node_Kind := Nkind (N);
+ Ent : Entity_Id;
+ Vexp : Node_Id;
begin
if Is_Entity_Name (N) then
@@ -2363,14 +2489,24 @@ package body Sem_Eval is
-- obtain the desired value from Corresponding_Integer_Value.
elsif Kind = N_Real_Literal then
-
- -- Apply the assertion to the Underlying_Type of the literal for
- -- the benefit of calls to this function in the JGNAT back end,
- -- where literal types can reflect private views.
-
pragma Assert (Is_Fixed_Point_Type (Underlying_Type (Etype (N))));
return Corresponding_Integer_Value (N);
+ -- Peculiar VMS case, if we have xxx'Null_Parameter, return zero
+
+ elsif Kind = N_Attribute_Reference
+ and then Attribute_Name (N) = Name_Null_Parameter
+ then
+ return Uint_0;
+
+ -- Array reference case
+
+ elsif Kind = N_Indexed_Component then
+ Vexp := Constant_Array_Ref (N);
+ pragma Assert (Present (Vexp));
+ return Expr_Rep_Value (Vexp);
+
+ -- Otherwise must be character literal
else
pragma Assert (Kind = N_Character_Literal);
Ent := Entity (N);
@@ -2394,10 +2530,23 @@ package body Sem_Eval is
----------------
function Expr_Value (N : Node_Id) return Uint is
- Kind : constant Node_Kind := Nkind (N);
- Ent : Entity_Id;
+ Kind : constant Node_Kind := Nkind (N);
+ CV_Ent : CV_Entry renames CV_Cache (Nat (N) mod CV_Cache_Size);
+ Ent : Entity_Id;
+ Val : Uint;
+ Vexp : Node_Id;
begin
+ -- If already in cache, then we know it's compile time known and
+ -- we can return the value that was previously stored in the cache
+ -- since compile time known values cannot change :-)
+
+ if CV_Ent.N = N then
+ return CV_Ent.V;
+ end if;
+
+ -- Otherwise proceed to test value
+
if Is_Entity_Name (N) then
Ent := Entity (N);
@@ -2405,20 +2554,20 @@ package body Sem_Eval is
-- created as a result of static evaluation.
if Ekind (Ent) = E_Enumeration_Literal then
- return Enumeration_Pos (Ent);
+ Val := Enumeration_Pos (Ent);
-- A user defined static constant
else
pragma Assert (Ekind (Ent) = E_Constant);
- return Expr_Value (Constant_Value (Ent));
+ Val := Expr_Value (Constant_Value (Ent));
end if;
-- An integer literal that was either in the source or created
-- as a result of static evaluation.
elsif Kind = N_Integer_Literal then
- return Intval (N);
+ Val := Intval (N);
-- A real literal for a fixed-point type. This must be the fixed-point
-- case, either the literal is of a fixed-point type, or it is a bound
@@ -2427,19 +2576,22 @@ package body Sem_Eval is
elsif Kind = N_Real_Literal then
- -- Apply the assertion to the Underlying_Type of the literal for
- -- the benefit of calls to this function in the JGNAT back end,
- -- where literal types can reflect private views.
-
pragma Assert (Is_Fixed_Point_Type (Underlying_Type (Etype (N))));
- return Corresponding_Integer_Value (N);
+ Val := Corresponding_Integer_Value (N);
-- Peculiar VMS case, if we have xxx'Null_Parameter, return zero
elsif Kind = N_Attribute_Reference
and then Attribute_Name (N) = Name_Null_Parameter
then
- return Uint_0;
+ Val := Uint_0;
+
+ -- Array reference case
+
+ elsif Kind = N_Indexed_Component then
+ Vexp := Constant_Array_Ref (N);
+ pragma Assert (Present (Vexp));
+ Val := Expr_Value (Vexp);
-- Otherwise must be character literal
@@ -2454,12 +2606,17 @@ package body Sem_Eval is
-- their Pos value as usual.
if No (Ent) then
- return UI_From_Int (Int (Char_Literal_Value (N)));
+ Val := UI_From_Int (Int (Char_Literal_Value (N)));
else
- return Enumeration_Pos (Ent);
+ Val := Enumeration_Pos (Ent);
end if;
end if;
+ -- Come here with Val set to value to be returned, set cache
+
+ CV_Ent.N := N;
+ CV_Ent.V := Val;
+ return Val;
end Expr_Value;
------------------
@@ -3161,7 +3318,7 @@ package body Sem_Eval is
else
Apply_Compile_Time_Constraint_Error
- (N, "value not in range of}");
+ (N, "value not in range of}", CE_Range_Check_Failed);
end if;
-- Here we generate a warning for the Ada 83 case, or when we are
@@ -3170,7 +3327,7 @@ package body Sem_Eval is
else
Warn_On_Instance := True;
Apply_Compile_Time_Constraint_Error
- (N, "value not in range of}?");
+ (N, "value not in range of}?", CE_Range_Check_Failed);
Warn_On_Instance := False;
end if;
end Out_Of_Range;
@@ -3201,7 +3358,9 @@ package body Sem_Eval is
-- We have to build an explicit raise_ce node
else
- Rewrite (N, Make_Raise_Constraint_Error (Sloc (Exp)));
+ Rewrite (N,
+ Make_Raise_Constraint_Error (Sloc (Exp),
+ Reason => CE_Range_Check_Failed));
Set_Raises_Constraint_Error (N);
Set_Etype (N, Typ);
end if;