Skip to content

Instantly share code, notes, and snippets.

@flyx
Created August 21, 2012 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyx/3418293 to your computer and use it in GitHub Desktop.
Save flyx/3418293 to your computer and use it in GitHub Desktop.
Trying to use Ada 2012 features
with Ada.Text_IO;
procedure Test is
type Int_Array is array (1 .. 64) of aliased Integer;
subtype Index is Integer range 1 .. 4;
type Ref_Element (Data : not null access Integer) is limited null record
with Implicit_Dereference => Data;
package Foo is
type My_Type is tagged private
with Variable_Indexing => Element;
function Element (Object : aliased in out My_Type; X, Y, Z : Index) return Ref_Element;
private
type My_Type is tagged record
Elements : Int_Array := (others => 0);
end record;
end Foo;
package body Foo is
function Element (Object : aliased in out My_Type; X, Y, Z : Index) return Ref_Element is
begin
return Ref_Element'(Data => Object.Elements (X + (Y - 1) * 4 + (Z - 1) * 16)'Access);
end Element;
end Foo;
Object : aliased Foo.My_Type;
Cur : Integer;
begin
Object (1, 1, 1) := 4;
Object (3, 1, 2) := 16;
for I in Index'Range loop
Cur := Object (I, I, I);
Ada.Text_IO.Put_Line (Cur'Img);
end loop;
end Test;
@flyx
Copy link
Author

flyx commented Aug 21, 2012

Compiler output with GNATMAKE GPL 2012 (20120509):
gcc -c -gnat12 test.adb
test.adb:25:04: container cannot be indexed with "Universal_Integer"
test.adb:26:04: container cannot be indexed with "Universal_Integer"
test.adb:29:17: container cannot be indexed with "Index"
a-textio.ads:205:14: aspect Indexing requires a function that applies to type "My_Type"
a-textio.ads:206:14: aspect Indexing requires a function that applies to type "My_Type"
a-textio.ads:239:14: aspect Indexing requires a function that applies to type "My_Type"
a-textio.ads:240:14: aspect Indexing requires a function that applies to type "My_Type"
gnatmake: "test.adb" compilation error

@flyx
Copy link
Author

flyx commented Aug 21, 2012

New output:
test.adb:14:32: "Element" is undefined

@flyx
Copy link
Author

flyx commented Aug 21, 2012

New output:

test.adb:34:04: missing argument for parameter "Y" in call to "Element" declared at line 16
test.adb:35:04: missing argument for parameter "Y" in call to "Element" declared at line 16
test.adb:38:14: missing argument for parameter "Y" in call to "Element" declared at line 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment