0

I want to compare min, max of values of two subtypes. In Ada language it is possible to assign between two different subtypes, for example

procedure Example_1 is
   subtype Type_1 is Integer range 0 .. 10;
   subtype Type_2 is Integer range 0 .. 30;
   A : Type_1 := 0;
   B : Type_2 := 12;
begin
   A := B;
end Example_1;

At run time A := B can give range overflow error. In ASIS, is it possible to compare subtypes, min/max values of subtypes (integer, real, enumeration types) so that I can identify overflow problem before run-time?

Jacob Sparre Andersen
  • 6,733
  • 17
  • 22

2 Answers2

2

The compiler detects this problem when compiled with -gnatVa -gnat12

Jim Rogers
  • 4,822
  • 1
  • 11
  • 24
1

Yes, it is possible to check this with ASIS.

See the answer to this question for how to extract 'First and 'Last for a subtype.

Jacob Sparre Andersen
  • 6,733
  • 17
  • 22
  • Thank you for your answer sir. I getting exception in "sub_constraint" call for enumeration type. Please let me know how to overcome this problem. – Lakshman Naik Jul 24 '18 at 03:43
  • I can't help you with that without a bit more context. Maybe you should compose a new question, demonstrating how far you've got. - Or just update this one with additional context. – Jacob Sparre Andersen Jul 25 '18 at 12:11