* constant in instantiations in GNAT/asis
@ 2005-09-09 17:27 Chi-Hua Chen
0 siblings, 0 replies; only message in thread
From: Chi-Hua Chen @ 2005-09-09 17:27 UTC (permalink / raw)
I am having trouble getting back the constants used in
generic instantiations from asis. For example, in a call
inside an instantiation that has three actuals: a variable
(X1), a constant (K1), and a literal, I get only the variable
and the constant when I call Function_Call_Parameters on
the call. K1 is no where to be found. (However, in the
assembly output, I do see the constant appears for the call.)
So is there a way I can get K1 for the call (other than going
back to the tree for the generic itself)?
Another perhaps related problem is when I try to get the
element_span_in_template (a gnat extension) for an aggregate
containing a constant, I get an exception
Returned_List_Length = 3
First part length = 2
Second part length = 0
Exception information: Exception name: CONSTRAINT_ERROR
Message: asis-expressions.adb:1395 length check failed
Below is a small program extracted from
Ada.Numerics.Discrete_Random, from which I first encounter the
problem, with some modifications.
I am using GNAT 3.15p (20020523).
Chi-Hua
========== random.ads ==========
generic
package Random is
type Generator is limited private;
procedure Reset(Gen : Generator);
private
K1 : constant := 94_833_359;
type Generator is limited record
Gen_State : Integer;
end record;
end Random;
========== random.adb ==========
package body Random is
function Square_Mod_N (X, N, Z : Integer) return Integer;
type Agg is
record
Field1 : Integer;
Field2 : Integer;
Field3 : Integer;
end record;
procedure Reset (Gen : Generator) is
X1 : Integer;
X2 : Integer;
A1 : Agg;
begin
-- Only two items show up in function_call_parameters
X1 := Square_Mod_N(X1, K1, X2);
-- Exceptions in element_span_in_template span
A1 := (X1, K1, 1);
-- This one seems fine, though
X1 := K1;
end Reset;
function Square_Mod_N (X, N, Z : Integer) return Integer is
begin
return 0;
end Square_Mod_N;
end Random;
========== main.adb =========
with Random;
procedure Main is
package Ada95_Random is new Random;
G: Ada95_Random.Generator;
begin
Ada95_Random.Reset(Gen=>G);
end Main;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-09-09 17:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-09 17:27 constant in instantiations in GNAT/asis Chi-Hua Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox