...
 
Commits (7)
...@@ -5,11 +5,10 @@ all: ...@@ -5,11 +5,10 @@ all:
@echo A testcase can be build from source with "make test" @echo A testcase can be build from source with "make test"
install: uninstall install: uninstall
mkdir -p obj && rm -f obj/taste-asn1-iterators && \ mkdir -p obj && cp src/taste-asn1-iterators.py obj/taste-asn1-iterators
sed 's,$$PREFIX,$(PREFIX),g' src/taste-asn1-iterators > obj/taste-asn1-iterators && \
chmod +x obj/taste-asn1-iterators
gprbuild -p asn1_iterators.gpr gprbuild -p asn1_iterators.gpr
gprinstall -p -XLIBRARY_TYPE=dynamic --build-name=shared --prefix=$(PREFIX) asn1_iterators.gpr gprinstall -p -XLIBRARY_TYPE=dynamic --build-name=shared --prefix=$(PREFIX) asn1_iterators.gpr
rm -rf obj
@echo Do not forget to export ADA_PROJECT_PATH=$(PREFIX)/share/gpr @echo Do not forget to export ADA_PROJECT_PATH=$(PREFIX)/share/gpr
test_build: clean install test_build: clean install
......
PREFIX?=$(HOME)/.local
all:
@echo You can install with "make install"
@echo A testcase can be build from source with "make test"
install: uninstall
mkdir -p obj && rm -f obj/taste-asn1-iterators && \
sed 's,$$PREFIX,$(PREFIX),g' src/taste-asn1-iterators > obj/taste-asn1-iterators && \
chmod +x obj/taste-asn1-iterators
gprbuild -p asn1_iterators.gpr
gprinstall -p -XLIBRARY_TYPE=dynamic --build-name=shared --prefix=$(PREFIX) asn1_iterators.gpr
@echo Do not forget to export ADA_PROJECT_PATH=$(PREFIX)/share/gpr
test_build: clean install
mkdir -p build_test
cp test/DataView.asn build_test
cd build_test && taste-asn1-iterators DataView.asn
gprbuild -p -P test_generic.gpr
test: test_build
build_test/test_generic
uninstall:
gprinstall --uninstall --prefix=$(PREFIX) asn1_iterators || :
clean:
gprclean test_generic.gpr || :
gprclean asn1_iterators.gpr || :
.PHONY: all clean install test test_build
asn1-iterators asn1-iterators
============== ==============
(c) 2016-2017 European Space Agency (c) 2016-2019 European Space Agency
Author/Contact: Maxime.Perrotin@esa.int Author/Contact: Maxime.Perrotin@esa.int
Generic iterator functions in Ada for generating all combinations of values of ASN.1 data types Generic iterator functions in Ada for generating all combinations of values of ASN.1 data types
v0.1 support for INTEGER with a range and SEQUENCE OF INTEGER (fixed and variable size arrays) Support integer, enumerated, sequence, sequence of (fixed and variable sizes)
test:
cd src
make
Work in progress... Part of the TASTE project. Work in progress... Part of the TASTE project.
...@@ -16,33 +16,33 @@ package body ASN1_Iterators.Generic_Basic is ...@@ -16,33 +16,33 @@ package body ASN1_Iterators.Generic_Basic is
Self.Is_Valid := True; Self.Is_Valid := True;
end; end;
function Has_Element (Ptr : Iterator_Ptr) return Boolean is function Has_Element (Position : Cursor) return Boolean is
(Ptr.Value.Has_Element and Ptr.Is_Valid); (Position.Value.Has_Element and Position.Is_Valid);
function First (Item : Iterator) return Iterator_Ptr is function First (Item : Iterator) return Cursor is
begin begin
Item.Ptr.Value.First; Item.Position.Value.First;
-- Reset validity flag -- Reset validity flag
Item.Ptr.Is_Valid := True; Item.Position.Is_Valid := True;
return Item.Ptr; return Item.Position;
end; end;
function Next (Item : Iterator; function Next (Item : Iterator;
Ptr : Iterator_Ptr) return Iterator_Ptr is Position : Cursor) return Cursor is
pragma Unreferenced (Item); pragma Unreferenced (Item);
begin begin
Ptr.Value.Next; Position.Value.Next;
return Ptr; return Position;
exception exception
when Stop_Iteration => Ptr.Is_Valid := False; when Stop_Iteration => Position.Is_Valid := False;
return Ptr; return Position;
end; end;
function Iterate (Self : Basic_ASN1_Iterator) function Iterate (Self : Basic_ASN1_Iterator)
return Forward_Iterator is return Forward_Iterator is
begin begin
return I: Iterator do return I: Iterator do
I.Ptr := Self'Unrestricted_Access; I.Position := Self'Unrestricted_Access;
end return; end return;
end; end;
end; end;
...@@ -4,44 +4,44 @@ use Ada.Finalization; ...@@ -4,44 +4,44 @@ use Ada.Finalization;
with ASN1_Iterators.SimpleTypes; with ASN1_Iterators.SimpleTypes;
generic generic
with package P is new SimpleTypes (<>); with package P is new SimpleTypes (<>);
package ASN1_Iterators.Generic_Basic is package ASN1_Iterators.Generic_Basic is
-- Provides an iterator for a basic type -- Provides an iterator for a basic type
subtype Sort is P.Sort; subtype Sort is P.Sort;
type Basic_ASN1_Iterator is new Controlled type Basic_ASN1_Iterator is new Controlled
with record with record
Value : P.SimpleType; Value : P.SimpleType;
Is_Valid : Boolean := True; Is_Valid : Boolean := True;
end record end record
with Default_Iterator => Iterate, with Default_Iterator => Iterate,
Iterator_Element => P.Sort, Iterator_Element => P.Sort,
Constant_Indexing => Elem_Value; Constant_Indexing => Elem_Value;
procedure Initialize (self: in out Basic_ASN1_Iterator); procedure Initialize (self: in out Basic_ASN1_Iterator);
type Iterator_Ptr is access all Basic_ASN1_Iterator; type Cursor is access all Basic_ASN1_Iterator;
function Has_Element (Ptr : Iterator_Ptr) return Boolean; function Has_Element (Position : Cursor) return Boolean;
package Iterators is package Iterators is
new Ada.Iterator_Interfaces (Iterator_Ptr, Has_Element); new Ada.Iterator_Interfaces (Cursor, Has_Element);
type Iterator is new Iterators.Forward_Iterator with record type Iterator is new Iterators.Forward_Iterator with record
Ptr : Iterator_Ptr; Position : Cursor;
end record; end record;
function Ptr (Item: Iterator) return Iterator_Ptr is (Item.Ptr); function Get_Cursor (Item : Iterator) return Cursor is (Item.Position);
overriding function First (Item : Iterator) return Iterator_Ptr; overriding function First (Item : Iterator) return Cursor;
overriding function Next (Item : Iterator; overriding function Next (Item : Iterator;
Ptr : Iterator_Ptr) return Iterator_Ptr; Position : Cursor) return Cursor;
subtype Forward_Iterator is Iterators.Forward_Iterator'Class; subtype Forward_Iterator is Iterators.Forward_Iterator'Class;
function Iterate (Self : Basic_ASN1_Iterator) return Forward_Iterator; function Iterate (Self : Basic_ASN1_Iterator) return Forward_Iterator;
function Elem_Value (Self : Basic_ASN1_Iterator; function Elem_Value (Self : Basic_ASN1_Iterator;
Ptr : Iterator_Ptr) Position : Cursor)
return P.Sort is (Ptr.Value.Element_Value); return P.Sort is (Position.Value.Element_Value);
end; end ASN1_Iterators.Generic_Basic;
...@@ -5,22 +5,22 @@ with Interfaces; ...@@ -5,22 +5,22 @@ with Interfaces;
use Interfaces; use Interfaces;
generic generic
type Sort is (<>); -- a discrete type, such as enumerated type Sort is (<>); -- a discrete type, such as enumerated
package ASN1_Iterators.Generic_Enumerated is package ASN1_Iterators.Generic_Enumerated is
function Elem_Init return Sort; function Elem_Init return Sort;
function Has_Elem (Value : Sort) return Boolean; function Has_Elem (Value : Sort) return Boolean;
function Elem_First return Sort is (Sort'First); function Elem_First return Sort is (Sort'First);
function Elem_Next (Value : Sort) return Sort; function Elem_Next (Value : Sort) return Sort;
package Discrete_Type is new SimpleTypes (Sort => Sort, package Discrete_Type is new SimpleTypes (Sort => Sort,
Elem_Init => Elem_Init, Elem_Init => Elem_Init,
Has_Elem => Has_Elem, Has_Elem => Has_Elem,
Elem_First => Elem_First, Elem_First => Elem_First,
Elem_Next => Elem_Next); Elem_Next => Elem_Next);
package It is new Generic_Basic (P => Discrete_Type); package It is new Generic_Basic (P => Discrete_Type);
subtype Instance is It.Basic_ASN1_Iterator; subtype Instance is It.Basic_ASN1_Iterator;
end; end ASN1_Iterators.Generic_Enumerated;
...@@ -8,65 +8,65 @@ package body ASN1_Iterators.Generic_Fixed_SeqOf is ...@@ -8,65 +8,65 @@ package body ASN1_Iterators.Generic_Fixed_SeqOf is
if Self.Length > 1 then if Self.Length > 1 then
Self.Rest := new ASN1_SeqOf (self.Length - 1); Self.Rest := new ASN1_SeqOf (self.Length - 1);
Self.RestIt := new ASN1_SeqOf_It'(ASN1_SeqOf_It (Self.Rest.Iterate)); Self.RestIt := new ASN1_SeqOf_It'(ASN1_SeqOf_It (Self.Rest.Iterate));
Self.RestIt.Ptr := Self.RestIt.First; Self.RestIt.Position := Self.RestIt.First;
end if; end if;
end; end;
function Has_Element_SeqOf (Ptr: ASN1_SeqOf_Ptr) return Boolean is function Has_Element_SeqOf (Position: Cursor) return Boolean is
(P.Has_Element(P.Ptr(Ptr.FirstIt))); (P.Has_Element(P.Get_Cursor (Position.FirstIt)));
function Iterate (Self : ASN1_SeqOf) function Iterate (Self : ASN1_SeqOf)
return ASN1_SeqOf_It'Class is --Iterators_SeqOf.Forward_Iterator'Class is return ASN1_SeqOf_It'Class is --Iterators_SeqOf.Forward_Iterator'Class is
begin begin
return I: ASN1_SeqOf_It do return I: ASN1_SeqOf_It do
I.Ptr := Self'Unrestricted_Access; I.Position := Self'Unrestricted_Access;
end return; end return;
end; end;
function First (Item : ASN1_SeqOf_It) return ASN1_SeqOf_Ptr is function First (Item : ASN1_SeqOf_It) return Cursor is
Ptr_Elem : P.Iterator_Ptr := P.Ptr (Item.Ptr.FirstIt); Ptr_Elem : P.Cursor := P.Get_Cursor (Item.Position.FirstIt);
begin begin
-- Initialize the iterator (Compute first value) -- Initialize the iterator (Compute first value)
Item.Ptr.FirstIt := P.Iterator (Item.Ptr.FirstVal.Iterate); Item.Position.FirstIt := P.Iterator (Item.Position.FirstVal.Iterate);
Ptr_Elem := P.First (Item.Ptr.FirstIt); Ptr_Elem := P.First (Item.Position.FirstIt);
Item.Ptr.Value.Data (1) := P.Elem_Value (Item.Ptr.FirstVal, Item.Position.Value.Data (1) := P.Elem_Value (Item.Position.FirstVal,
Ptr_elem); Ptr_elem);
if Item.Ptr.Length > 1 then if Item.Position.Length > 1 then
Item.Ptr.Value.Data (2 .. Item.Ptr.Length) := Item.Position.Value.Data (2 .. Item.Position.Length) :=
Item.Ptr.RestIt.Ptr.Value.Data (1 .. Item.Ptr.RestIt.Ptr.Length); Item.Position.RestIt.Position.Value.Data (1 .. Item.Position.RestIt.Position.Length);
end if; end if;
return Item.Ptr; return Item.Position;
end; end;
function Next (Item : ASN1_SeqOf_It; function Next (Item : ASN1_SeqOf_It;
Ptr : ASN1_SeqOf_Ptr) return ASN1_SeqOf_Ptr is Position : Cursor) return Cursor is
pragma Unreferenced (Item); pragma Unreferenced (Item);
Ptr_elem : P.Iterator_Ptr := P.Ptr (Ptr.FirstIt); Ptr_elem : P.Cursor := P.Get_Cursor (Position.FirstIt);
begin begin
if Ptr.Length > 1 then if Position.Length > 1 then
Ptr.RestIt.Ptr := Ptr.RestIt.Next (Ptr.RestIt.Ptr); Position.RestIt.Position := Position.RestIt.Next (Position.RestIt.Position);
if Has_Element_SeqOf (Ptr.RestIt.Ptr) then if Has_Element_SeqOf (Position.RestIt.Position) then
Ptr.Value.Data (2 .. Ptr.Length) := Position.Value.Data (2 .. Position.Length) :=
Ptr.RestIt.Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Value.Length); Position.RestIt.Position.Value.Data (1 .. Position.RestIt.Position.Value.Length);
else else
Ptr.RestIt.Ptr := Ptr.RestIt.First; Position.RestIt.Position := Position.RestIt.First;
-- Exhausted "rest": iterate on the first item -- Exhausted "rest": iterate on the first item
Ptr_elem := P.Next(Ptr.FirstIt, Ptr_elem); Ptr_elem := P.Next(Position.FirstIt, Ptr_elem);
if P.Has_Element (Ptr_elem) then if P.Has_Element (Ptr_elem) then
Ptr.Value.Data (1) := P.Elem_Value (Ptr.FirstVal, Ptr_elem); Position.Value.Data (1) := P.Elem_Value (Position.FirstVal, Ptr_elem);
Ptr.Value.Data (2 .. Ptr.Length) := Position.Value.Data (2 .. Position.Length) :=
Ptr.RestIt.Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Length); Position.RestIt.Position.Value.Data (1 .. Position.RestIt.Position.Length);
end if; end if;
end if; end if;
else else
-- Size is 0 or 1 -- Size is 0 or 1
Ptr_elem := P.Next (Ptr.FirstIt, Ptr_elem); Ptr_elem := P.Next (Position.FirstIt, Ptr_elem);
if P.Has_Element (Ptr_elem) then if P.Has_Element (Ptr_elem) then
Ptr.Value.Data (1) := P.Elem_Value (Ptr.FirstVal, Ptr_elem); Position.Value.Data (1) := P.Elem_Value (Position.FirstVal, Ptr_elem);
end if; end if;
end if; end if;
return Ptr; return Position;
end; end;
end; end;
...@@ -7,56 +7,56 @@ with ASN1_Iterators.Generic_Basic; ...@@ -7,56 +7,56 @@ with ASN1_Iterators.Generic_Basic;
with ASN1_Iterators.SimpleTypes; with ASN1_Iterators.SimpleTypes;
generic generic
with package P is new Generic_Basic (<>); with package P is new Generic_Basic (<>);
package ASN1_Iterators.Generic_Fixed_SeqOf is package ASN1_Iterators.Generic_Fixed_SeqOf is
type DataArray is array (natural range <>) of P.Sort; type DataArray is array (natural range <>) of P.Sort;
type SeqOf (Max : Natural) is record type SeqOf (Max : Natural) is record
Length : Integer; Length : Integer;
Data : DataArray (1 .. Max); Data : DataArray (1 .. Max);
end record; end record;
type ASN1_SeqOf_Ptr; type Cursor;
type ASN1_SeqOf_It; type ASN1_SeqOf_It;
type ASN1_SeqOf (Size : Natural) is new Controlled type ASN1_SeqOf (Size : Natural) is new Controlled
with record with record
Length : Natural := Size; Length : Natural := Size;
Value : SeqOf (Size); Value : SeqOf (Size);
-- First value -- First value
FirstVal : P.Basic_ASN1_Iterator; FirstVal : P.Basic_ASN1_Iterator;
FirstIt : P.Iterator; FirstIt : P.Iterator;
-- The rest (recursive) -- The rest (recursive)
Rest : access ASN1_SeqOf; Rest : access ASN1_SeqOf;
RestIt : access ASN1_SeqOf_It; RestIt : access ASN1_SeqOf_It;
end record end record
with Default_Iterator => Iterate, with Default_Iterator => Iterate,
Iterator_Element => SeqOf, Iterator_Element => SeqOf,
Constant_Indexing => Element_SeqOf_Value; Constant_Indexing => Element_SeqOf_Value;
type ASN1_SeqOf_Ptr is access all ASN1_SeqOf; type Cursor is access all ASN1_SeqOf;
-- Constructor (called automatically) -- Constructor (called automatically)
procedure Initialize (Self : in out ASN1_SeqOf); procedure Initialize (Self : in out ASN1_SeqOf);
function Has_Element_SeqOf (Ptr : ASN1_SeqOf_Ptr) return Boolean; function Has_Element_SeqOf (Position : Cursor) return Boolean;
package Iterators_SeqOf is package Iterators_SeqOf is
new Ada.Iterator_Interfaces (ASN1_SeqOf_Ptr, Has_Element_SeqOf); new Ada.Iterator_Interfaces (Cursor, Has_Element_SeqOf);
type ASN1_SeqOf_It is new Iterators_SeqOf.Forward_Iterator with record type ASN1_SeqOf_It is new Iterators_SeqOf.Forward_Iterator with record
Ptr : ASN1_SeqOf_Ptr; Position : Cursor;
end record; end record;
overriding function First (Item : ASN1_SeqOf_It) return ASN1_SeqOf_Ptr; overriding function First (Item : ASN1_SeqOf_It) return Cursor;
overriding function Next (Item : ASN1_SeqOf_It; overriding function Next (Item : ASN1_SeqOf_It;
Ptr : ASN1_SeqOf_Ptr) return ASN1_SeqOf_Ptr; Position : Cursor) return Cursor;
function Iterate (self : ASN1_SeqOf) function Iterate (self : ASN1_SeqOf)
return ASN1_SeqOf_It'Class; -- Iterators_SeqOf.Forward_Iterator'Class; return ASN1_SeqOf_It'Class;
function Element_SeqOf_Value (Self : ASN1_SeqOf; function Element_SeqOf_Value (Self : ASN1_SeqOf;
Ptr : ASN1_SeqOf_Ptr) Position : Cursor)
return SeqOf is (self.Value); return SeqOf is (self.Value);
end; end ASN1_Iterators.Generic_Fixed_SeqOf;
...@@ -5,27 +5,27 @@ with Interfaces, ...@@ -5,27 +5,27 @@ with Interfaces,
use Interfaces; use Interfaces;
generic generic
Min: Interfaces.Integer_64; Min : Interfaces.Integer_64;
Max: Interfaces.Integer_64; Max : Interfaces.Integer_64;
package ASN1_Iterators.Generic_Integer is package ASN1_Iterators.Generic_Integer is
function Elem_Init return Interfaces.Integer_64 is (Min); function Elem_Init return Interfaces.Integer_64 is (Min);
function Has_Elem (Value : Interfaces.Integer_64) function Has_Elem (Value : Interfaces.Integer_64)
return Boolean is (Value <= Max); return Boolean is (Value <= Max);
function Elem_First return Interfaces.Integer_64 is (Min); function Elem_First return Interfaces.Integer_64 is (Min);
function Elem_Next (Value : Interfaces.Integer_64) function Elem_Next (Value : Interfaces.Integer_64)
return Interfaces.Integer_64 is (Value + 1); return Interfaces.Integer_64 is (Value + 1);
package Signed_Integer is new SimpleTypes package Signed_Integer is new SimpleTypes
(Sort => Interfaces.Integer_64, (Sort => Interfaces.Integer_64,
Elem_Init => Elem_Init, Elem_Init => Elem_Init,
Has_Elem => Has_Elem, Has_Elem => Has_Elem,
Elem_First => Elem_First, Elem_First => Elem_First,
Elem_Next => Elem_Next); Elem_Next => Elem_Next);
package It is new Generic_Basic (P => Signed_Integer); package It is new Generic_Basic (P => Signed_Integer);
subtype Instance is It.Basic_ASN1_Iterator; subtype Instance is It.Basic_ASN1_Iterator;
end; end ASN1_Iterators.Generic_Integer;
...@@ -7,18 +7,18 @@ package body ASN1_Iterators.Generic_Iterator is ...@@ -7,18 +7,18 @@ package body ASN1_Iterators.Generic_Iterator is
-- end; -- end;
function First (Item : Iterator) return Cursor is function First (Item : Iterator) return Cursor is
C: constant Cursor := Item.Ptr; C: constant Cursor := Item.Position;
begin begin
C.Item.Value := ASN1_Iterable.First(ASN1_Iterable.Iterable'Class(Item.Ptr.all.Item)); C.Item.Value := ASN1_Iterable.First(ASN1_Iterable.Iterable'Class(Item.Position.all.Item));
return C; return C;
end; end;
function Next (Item : Iterator; function Next (Item : Iterator;
Ptr : Cursor) Position : Cursor)
return Cursor is return Cursor is
C: constant Cursor := Item.Ptr; C: constant Cursor := Item.Position;
begin begin
C.Item.Value := ASN1_Iterable.Next(ASN1_Iterable.Iterable'Class(Ptr.all.Item)); C.Item.Value := ASN1_Iterable.Next(ASN1_Iterable.Iterable'Class(Position.all.Item));
return C; return C;
end; end;
...@@ -26,7 +26,7 @@ package body ASN1_Iterators.Generic_Iterator is ...@@ -26,7 +26,7 @@ package body ASN1_Iterators.Generic_Iterator is
return Iterators.Forward_Iterator'Class is return Iterators.Forward_Iterator'Class is
begin begin
return I: Iterator do return I: Iterator do
I.Ptr := self'Unrestricted_Access; I.Position := self'Unrestricted_Access;
end return; end return;
end; end;
......
...@@ -19,16 +19,16 @@ package ASN1_Iterators.Generic_Iterator is ...@@ -19,16 +19,16 @@ package ASN1_Iterators.Generic_Iterator is
type Cursor is access all Generic_Iterator_Type; type Cursor is access all Generic_Iterator_Type;
function Elem (Self : Generic_Iterator_Type; Ptr : Cursor) function Elem (Self : Generic_Iterator_Type; Position : Cursor)
return ASN1_Type is (Ptr.Item.Element); return ASN1_Type is (Position.Item.Element);
function Has_Element (Ptr : Cursor) return Boolean is function Has_Element (Position : Cursor) return Boolean is
(ASN1_Iterable.Has_Element(ASN1_Iterable.Iterable'Class(Ptr.all.Item))); (ASN1_Iterable.Has_Element(ASN1_Iterable.Iterable'Class(Position.all.Item)));
package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element); package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element);
type Iterator is new Iterators.Forward_Iterator with record type Iterator is new Iterators.Forward_Iterator with record
Ptr : Cursor; Position : Cursor;
end record; end record;
--overriding --overriding
...@@ -39,7 +39,7 @@ package ASN1_Iterators.Generic_Iterator is ...@@ -39,7 +39,7 @@ package ASN1_Iterators.Generic_Iterator is
overriding overriding
function Next (Item : Iterator; function Next (Item : Iterator;
Ptr : Cursor) Position : Cursor)
return Cursor; return Cursor;
function Iterate (self : Generic_Iterator_Type) function Iterate (self : Generic_Iterator_Type)
......
...@@ -7,60 +7,68 @@ package body ASN1_Iterators.Generic_SeqOf is ...@@ -7,60 +7,68 @@ package body ASN1_Iterators.Generic_SeqOf is
self.RestVal := new P.ASN1_SeqOf(Self.Length); self.RestVal := new P.ASN1_SeqOf(Self.Length);
self.RestIt := self.RestIt :=
new P.ASN1_SeqOf_It'(P.ASN1_SeqOf_It(Self.RestVal.Iterate)); new P.ASN1_SeqOf_It'(P.ASN1_SeqOf_It(Self.RestVal.Iterate));
self.RestIt.Ptr := self.RestIt.First; self.RestIt.Position := self.RestIt.First;
end if; end if;
end; end;
function Has_Element_Variable_SeqOf (Ptr: ASN1_Variable_SeqOf_Ptr) function Has_Element_Variable_SeqOf
return Boolean is (Length_Pkg.Has_Element(Length_Pkg.Ptr(Ptr.LenIt))); (Position : Cursor)
return Boolean is
(Length_Pkg.Has_Element(Length_Pkg.Get_Cursor (Position.LenIt)));
function Iterate (self : ASN1_Variable_SeqOf) function Iterate (self : ASN1_Variable_SeqOf)
return Iterators_Variable_SeqOf.Forward_Iterator'Class is return Iterators_Variable_SeqOf.Forward_Iterator'Class is
begin begin
return I: ASN1_Variable_SeqOf_It do return I: ASN1_Variable_SeqOf_It do
I.Ptr := Self'Unrestricted_Access; I.Position := Self'Unrestricted_Access;
end return; end return;
end; end;
function First (Item : ASN1_Variable_SeqOf_It) function First (Item : ASN1_Variable_SeqOf_It)
return ASN1_Variable_SeqOf_Ptr is return Cursor is
begin begin
-- Initialize the iterator (Compute first value) -- Initialize the iterator (Compute first value)
Item.Ptr.LenIt := Length_Pkg.Iterator(Item.Ptr.LenVal.Iterate); Item.Position.LenIt :=
Length_Pkg.Iterator(Item.Position.LenVal.Iterate);
-- Copy only the actual size, since the arrays may be different in size -- Copy only the actual size, since the arrays may be different in size
Item.Ptr.Value.Data (1 .. Item.Ptr.RestIt.Ptr.Value.Data'Length) := Item.Position.Value.Data
Item.Ptr.RestIt.Ptr.Value.Data; (1 .. Item.Position.RestIt.Position.Value.Data'Length) :=
return Item.Ptr; Item.Position.RestIt.Position.Value.Data;
return Item.Position;
end; end;
function Next (Item : ASN1_Variable_SeqOf_It; function Next (Item : ASN1_Variable_SeqOf_It;
Ptr : ASN1_Variable_SeqOf_Ptr) Position : Cursor)
return ASN1_Variable_SeqOf_Ptr return Cursor
is is
pragma Unreferenced (Item); pragma Unreferenced (Item);
Ptr_elem : Length_Pkg.Iterator_Ptr := Length_Pkg.Ptr(Ptr.LenIt); Position_elem : Length_Pkg.Cursor :=
begin Length_Pkg.Get_Cursor (Position.LenIt);
Ptr.RestIt.Ptr := Ptr.RestIt.Next (Ptr.RestIt.Ptr); begin
if P.Has_Element_SeqOf (Ptr.RestIt.Ptr) then Position.RestIt.Position := Position.RestIt.Next (Position.RestIt.Position);
Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Value.Data'Length) := if P.Has_Element_SeqOf (Position.RestIt.Position) then
Ptr.RestIt.Ptr.Value.Data; Position.Value.Data
(1 .. Position.RestIt.Position.Value.Data'Length) :=
Position.RestIt.Position.Value.Data;
else else
Ptr.RestIt.Ptr := Ptr.RestIt.First; Position.RestIt.Position := Position.RestIt.First;
-- Exhausted "rest": iterate on the first item -- Exhausted "rest": iterate on the first item
Ptr_elem := Ptr.LenIt.Next (Ptr_elem); Position_elem := Position.LenIt.Next (Position_elem);
if Length_Pkg.Has_Element (Ptr_elem) then if Length_Pkg.Has_Element (Position_elem) then
Ptr.Value.Length := Integer (Ptr_Elem.Value.Value); Position.Value.Length := Integer (Position_Elem.Value.Value);
Ptr.Length := Ptr.Value.Length; Position.Length := Position.Value.Length;
Ptr.RestVal := new P.ASN1_SeqOf(Ptr.Value.Length); Position.RestVal := new P.ASN1_SeqOf(Position.Value.Length);
Ptr.RestIt := Position.RestIt :=
new P.ASN1_SeqOf_It'(P.ASN1_SeqOf_It (Ptr.RestVal.Iterate)); new P.ASN1_SeqOf_It'(P.ASN1_SeqOf_It
Ptr.RestIt.Ptr := Ptr.RestIt.First; (Position.RestVal.Iterate));
Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Value.Data'Length) := Position.RestIt.Position := Position.RestIt.First;
Ptr.RestIt.Ptr.Value.Data; Position.Value.Data
end if; (1 .. Position.RestIt.Position.Value.Data'Length) :=
end if; Position.RestIt.Position.Value.Data;
return Ptr; end if;
end; end if;
end; return Position;
end;
end ASN1_Iterators.Generic_SeqOF;
...@@ -10,73 +10,71 @@ with ASN1_Iterators.Generic_Fixed_SeqOf, ...@@ -10,73 +10,71 @@ with ASN1_Iterators.Generic_Fixed_SeqOf,
with Interfaces; with Interfaces;
use Interfaces; use Interfaces;
-- Iterator for a variable-size array of basic type -- Iterator for a variable-size array of basic type
generic generic
Min : Natural; Min : Natural;
Max : Natural; Max : Natural;
with package Basic is new Generic_Basic (<>); with package Basic is new Generic_Basic (<>);
package ASN1_Iterators.Generic_SeqOf is package ASN1_Iterators.Generic_SeqOf is
Package P is new Generic_Fixed_SeqOF (P => Basic); package P is new Generic_Fixed_SeqOF (P => Basic);
-- Create an integer type with a range constraint to iterate on -- Create an integer type with a range constraint to iterate on
package Length_ty is new Generic_Integer (Integer_64(Min), package Length_ty is new Generic_Integer (Integer_64 (Min),
Integer_64(Max)); Integer_64 (Max));
-- Instantiate the package to iterate on the integer for the length -- Instantiate the package to iterate on the integer for the length
package Length_Pkg renames Length_ty.It; package Length_Pkg renames Length_ty.It;
type ASN1_Variable_SeqOf_Ptr is private; type Cursor is private;
subtype MySeqOf is P.SeqOf(Max); subtype Sequence_Of is P.SeqOf (Max);
type ASN1_Variable_SeqOf is new Controlled type ASN1_Variable_SeqOf is new Controlled
with record with record
Length : Natural := Min; Length : Natural := Min;
Value : MySeqOf; -- P.SeqOf(Max); Value : Sequence_Of;
-- Iterate on the length -- Iterate on the length
LenVal : Length_ty.Instance; LenVal : Length_ty.Instance;
LenIt : Length_Pkg.Iterator; LenIt : Length_Pkg.Iterator;
-- And on the value -- And on the value
RestVal : access P.ASN1_SeqOf; RestVal : access P.ASN1_SeqOf;
RestIt : access P.ASN1_SeqOf_It; RestIt : access P.ASN1_SeqOf_It;
end record end record
with Default_Iterator => Iterate, with Default_Iterator => Iterate,
Iterator_Element => MySeqOf, --P.SeqOf, Iterator_Element => Sequence_Of,
Constant_Indexing => Element_Variable_SeqOf_Value; Constant_Indexing => Element_Variable_SeqOf_Value;
-- Constructor (called automatically) -- Constructor (called automatically)
procedure Initialize(self: in out ASN1_Variable_SeqOf); procedure Initialize (Self : in out ASN1_Variable_SeqOf);
function Has_Element_Variable_SeqOf (Ptr : ASN1_Variable_SeqOf_Ptr) function Has_Element_Variable_SeqOf (Position : Cursor)
return Boolean; return Boolean;
package Iterators_Variable_SeqOf is package Iterators_Variable_SeqOf is
new Ada.Iterator_Interfaces (ASN1_Variable_SeqOf_Ptr, new Ada.Iterator_Interfaces (Cursor,
Has_Element_Variable_SeqOf); Has_Element_Variable_SeqOf);
type ASN1_Variable_SeqOf_It type ASN1_Variable_SeqOf_It
is new Iterators_Variable_SeqOf.Forward_Iterator with record is new Iterators_Variable_SeqOf.Forward_Iterator with record
Ptr : ASN1_Variable_SeqOf_Ptr; Position : Cursor;
end record; end record;
overriding overriding
function First (Item : ASN1_Variable_SeqOf_It) function First (Item : ASN1_Variable_SeqOf_It)
return ASN1_Variable_SeqOf_Ptr; return Cursor;
overriding overriding
function Next (Item : ASN1_Variable_SeqOf_It; function Next (Item : ASN1_Variable_SeqOf_It;
Ptr : ASN1_Variable_SeqOf_Ptr) Position : Cursor)
return ASN1_Variable_SeqOf_Ptr; return Cursor;
function Iterate (self : ASN1_Variable_SeqOf) function Iterate (self : ASN1_Variable_SeqOf)
return Iterators_Variable_SeqOf.Forward_Iterator'Class; return Iterators_Variable_SeqOf.Forward_Iterator'Class;
function Element_Variable_SeqOf_Value (Self : ASN1_Variable_SeqOf; function Element_Variable_SeqOf_Value (Self : ASN1_Variable_SeqOf;
Ptr : ASN1_Variable_SeqOf_Ptr) Position : Cursor)
--return P.SeqOf is (Self.Value); return Sequence_Of is (Self.Value);
return MySeqOf is (Self.Value);
subtype Instance is ASN1_Variable_SeqOf;
subtype Instance is ASN1_Variable_SeqOf;
private
private type Cursor is access all ASN1_Variable_SeqOf;
type ASN1_Variable_SeqOf_Ptr is access all ASN1_Variable_SeqOf;
end ASN1_Iterators.Generic_SeqOF;
end;
...@@ -5,24 +5,24 @@ with Interfaces; ...@@ -5,24 +5,24 @@ with Interfaces;
use Interfaces; use Interfaces;
generic generic
Min: Interfaces.Unsigned_64; Min : Interfaces.Unsigned_64;
Max: Interfaces.Unsigned_64; Max : Interfaces.Unsigned_64;
package ASN1_Iterators.Generic_Unsigned_Integer is package ASN1_Iterators.Generic_Unsigned_Integer is
function Elem_Init return Interfaces.Unsigned_64 is (Min); function Elem_Init return Interfaces.Unsigned_64 is (Min);
function Has_Elem(Value: Interfaces.Unsigned_64) return Boolean is function Has_Elem (Value : Interfaces.Unsigned_64) return Boolean is
(Value <= Max); (Value <= Max);
function Elem_First return Interfaces.Unsigned_64 is (Min); function Elem_First return Interfaces.Unsigned_64 is (Min);
function Elem_Next(Value: Interfaces.Unsigned_64) function Elem_Next (Value : Interfaces.Unsigned_64)
return Interfaces.Unsigned_64 is (Value + 1); return Interfaces.Unsigned_64 is (Value + 1);
package Unsigned_Type is new SimpleTypes package Unsigned_Type is new SimpleTypes
(Sort => Interfaces.Unsigned_64, (Sort => Interfaces.Unsigned_64,
Elem_Init => Elem_Init, Elem_Init => Elem_Init,
Has_Elem => Has_Elem, Has_Elem => Has_Elem,
Elem_First => Elem_First, Elem_First => Elem_First,
Elem_Next => Elem_Next); Elem_Next => Elem_Next);
package It is new Generic_Basic (P => Unsigned_Type); package It is new Generic_Basic (P => Unsigned_Type);
subtype Instance is It.Basic_ASN1_Iterator; subtype Instance is It.Basic_ASN1_Iterator;
end; end ASN1_Iterators.Generic_Unsigned_Integer;
...@@ -34,6 +34,6 @@ package ASN1_Iterators.Iterable_Integer is ...@@ -34,6 +34,6 @@ package ASN1_Iterators.Iterable_Integer is
-- If it is needed to iterate manually, provide Cursor and Iterator: -- If it is needed to iterate manually, provide Cursor and Iterator:
subtype Cursor is Custom_Iterator.Cursor; subtype Cursor is Custom_Iterator.Cursor;
subtype Iterator is Custom_Iterator.Iterators.Forward_Iterator'Class; subtype Iterator is Custom_Iterator.Iterators.Forward_Iterator'Class;
function Has_Element (Ptr: Cursor) return Boolean function Has_Element (Position : Cursor) return Boolean
renames Custom_Iterator.Has_Element; renames Custom_Iterator.Has_Element;
end; end;
...@@ -11,13 +11,11 @@ package body ASN1_Iterators.Iterable_SeqOF is ...@@ -11,13 +11,11 @@ package body ASN1_Iterators.Iterable_SeqOF is
end; end;
function Has_Element (It: ASN1_SequenceOf) return Boolean is function Has_Element (It: ASN1_SequenceOf) return Boolean is
-- (P.Has_Element(P.Ptr(Ptr.FirstIt)));
begin begin
return False; return False;
end; end;
function First (It: in out ASN1_SequenceOf) return Generic_SeqOf is function First (It: in out ASN1_SequenceOf) return Generic_SeqOf is
-- Ptr_elem : P.Iterator_Ptr := P.Ptr(Item.Ptr.FirstIt);
Ret : constant Generic_SeqOf := It.Value; Ret : constant Generic_SeqOf := It.Value;
begin begin
It.Value.Length := It.Length; It.Value.Length := It.Length;
...@@ -30,48 +28,14 @@ package body ASN1_Iterators.Iterable_SeqOF is ...@@ -30,48 +28,14 @@ package body ASN1_Iterators.Iterable_SeqOF is
It.Rest_It := It.Rest_It :=
new Cust_Iterator'(Custom_Iterator.Iterator (It.Rest.Iterate) new Cust_Iterator'(Custom_Iterator.Iterator (It.Rest.Iterate)
with others => <>); with others => <>);
It.Rest_It.Ptr := It.Rest_It.First; It.Rest_It.Position := It.Rest_It.First;
end if; end if;
-- Initialize the iterator (Compute first value)
-- Item.Ptr.FirstIt := P.Iterator(Item.Ptr.FirstVal.Iterate);
-- Ptr_elem := P.First(Item.Ptr.FirstIt);
-- Item.Ptr.Value.Data(1) := P.Elem_Value(Item.Ptr.FirstVal,
-- Ptr_elem);
-- if Item.Ptr.Length > 1 then
-- Item.Ptr.Value.Data(2 .. Item.Ptr.Length) :=
-- Item.Ptr.Rest_It.Ptr.Value.Data(1..Item.Ptr.Rest_It.Ptr.Length);
-- end if;
-- return Item.Ptr;
return Ret; return Ret;
end; end;
function Next (It: ASN1_SequenceOf) return Generic_SeqOf is function Next (It: ASN1_SequenceOf) return Generic_SeqOf is
--Ptr_elem : P.Iterator_Ptr := P.Ptr(Ptr.FirstIt);
Temp : constant Generic_SeqOf := It.Value; Temp : constant Generic_SeqOf := It.Value;
begin begin
-- if Ptr.Length > 1 then
-- Ptr.Rest_It.Ptr := Ptr.Rest_It.Next (Ptr.Rest_It.Ptr);
-- if Has_Element_SeqOf (Ptr.Rest_It.Ptr) then
-- Ptr.Value.Data (2..Ptr.Length) :=
-- Ptr.Rest_It.Ptr.Value.Data (1..Ptr.Rest_It.Ptr.Value.Length);
-- else
-- Ptr.Rest_It.Ptr := Ptr.Rest_It.First;
-- -- Exhausted "rest": iterate on the first item
-- Ptr_elem := P.Next(Ptr.FirstIt, Ptr_elem);
-- if P.Has_Element (Ptr_elem) then
-- Ptr.Value.Data(1) := P.Elem_Value(Ptr.FirstVal, Ptr_elem);
-- Ptr.Value.Data(2..Ptr.Length) := Ptr.Rest_It.Ptr.Value.Data (1..Ptr.Rest_It.Ptr.Length);
-- end if;
-- end if;
-- else
-- -- Size is 0 or 1
-- Ptr_elem := P.Next(Ptr.FirstIt, Ptr_elem);
-- if P.Has_Element (Ptr_elem) then
-- Ptr.Value.Data(1) := P.Elem_Value(Ptr.FirstVal, Ptr_elem);
-- end if;
-- end if;
-- return Ptr;
return Temp; return Temp;
end; end;
end; end;
...@@ -55,7 +55,7 @@ package ASN1_Iterators.Iterable_SeqOF is ...@@ -55,7 +55,7 @@ package ASN1_Iterators.Iterable_SeqOF is
subtype Iterator is Custom_Iterator.Iterators.Forward_Iterator'Class; subtype Iterator is Custom_Iterator.Iterators.Forward_Iterator'Class;
type Cust_Iterator is new Custom_Iterator.Iterator with null record; type Cust_Iterator is new Custom_Iterator.Iterator with null record;
function Has_Element (Ptr: Cursor) return Boolean function Has_Element (Position : Cursor) return Boolean
renames Custom_Iterator.Has_Element; renames Custom_Iterator.Has_Element;
......
generic generic
type Sort is private; type Sort is private;
with function Elem_Init return Sort; with function Elem_Init return Sort;
with function Has_Elem (Value : Sort) return Boolean; with function Has_Elem (Value : Sort) return Boolean;
with function Elem_First return Sort; with function Elem_First return Sort;
with function Elem_Next (Value : Sort) return Sort; with function Elem_Next (Value : Sort) return Sort;
package ASN1_Iterators.SimpleTypes is package ASN1_Iterators.SimpleTypes is
type SimpleType is tagged record type SimpleType is tagged record
Value : Sort; Value : Sort;
end record; end record;
procedure Initialize (Self : in out SimpleType); procedure Initialize (Self : in out SimpleType);
function Has_Element (Self : in out SimpleType) return Boolean is function Has_Element (Self : in out SimpleType) return Boolean is
(Has_Elem (Self.Value)); (Has_Elem (Self.Value));
procedure First (Self : in out SimpleType); procedure First (Self : in out SimpleType);
procedure Next (Self : in out SimpleType); procedure Next (Self : in out SimpleType);
function Element_Value (Self : in out SimpleType) return Sort is function Element_Value (Self : in out SimpleType) return Sort is
(Self.Value); (Self.Value);
end; end ASN1_Iterators.SimpleTypes;
package ASN1_Iterators is package ASN1_Iterators is
Stop_Iteration : exception; Stop_Iteration : exception;
end; end ASN1_Iterators;
This diff is collapsed.
this folder is DEPRECATED, the code is now generated from python
...@@ -147,7 +147,6 @@ ChoiceChild(sName, sCName, nLine, nPos, sChildContent, sNamePresent ) ::= << ...@@ -147,7 +147,6 @@ ChoiceChild(sName, sCName, nLine, nPos, sChildContent, sNamePresent ) ::= <<
ChoiceType(arrsChildren) ::= << ChoiceType(arrsChildren) ::= <<
-- $arrsChildren;separator=",\n"$ -- $arrsChildren;separator=",\n"$
}
>> >>
...@@ -159,7 +158,6 @@ SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) :: ...@@ -159,7 +158,6 @@ SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::
/* Full sequence (record) type */ /* Full sequence (record) type */
SequenceType(arrsChildren) ::= << SequenceType(arrsChildren) ::= <<
-- $arrsChildren;separator=",\n"$ -- $arrsChildren;separator=",\n"$
}
>> >>
......
...@@ -170,8 +170,7 @@ SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) :: ...@@ -170,8 +170,7 @@ SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::
/* Full sequence (record) type */ /* Full sequence (record) type */
SequenceType(arrsChildren) ::= << SequenceType(arrsChildren) ::= <<
-- $arrsChildren;separator=",\n"$ Sequence;
}
>> >>
......
with Ada.Unchecked_Conversion;
package body ASN1_Iterators.MySeq is
procedure Initialize (Self: in out ASN1_MySeq) is
begin
-- Self.Value.a :=
-- Self.Value.b :=
end;
function Has_Element_MySeq (Ptr: Cursor) return Boolean is
(P.Has_Element(P.Ptr(Ptr.FirstIt)));
function Iterate (Self : ASN1_MySeq)
return ASN1_MySeq'Class is --Iterators_MySeq.Forward_Iterator'Class is
begin
return I: ASN1_MySeq do
I.Ptr := Self'Unrestricted_Access;
end return;
end;
function First (Item : ASN1_MySeq) return Cursor is
Ptr_Elem : P.Iterator_Ptr := P.Ptr (Item.Ptr.FirstIt);
begin
-- Initialize the iterator (Compute first value)
Item.Ptr.FirstIt := P.Iterator (Item.Ptr.FirstVal.Iterate);
Ptr_Elem := P.First (Item.Ptr.FirstIt);
Item.Ptr.Value.Data (1) := P.Elem_Value (Item.Ptr.FirstVal,
Ptr_elem);
if Item.Ptr.Length > 1 then
Item.Ptr.Value.Data (2 .. Item.Ptr.Length) :=
Item.Ptr.RestIt.Ptr.Value.Data (1 .. Item.Ptr.RestIt.Ptr.Length);
end if;
return Item.Ptr;
end;
function Next (Item : ASN1_MySeq;
Ptr : Cursor) return Cursor is
pragma Unreferenced (Item);
Ptr_elem : P.Iterator_Ptr := P.Ptr (Ptr.FirstIt);
begin
if Ptr.Length > 1 then
Ptr.RestIt.Ptr := Ptr.RestIt.Next (Ptr.RestIt.Ptr);
if Has_Element_MySeq (Ptr.RestIt.Ptr) then
Ptr.Value.Data (2 .. Ptr.Length) :=
Ptr.RestIt.Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Value.Length);
else
Ptr.RestIt.Ptr := Ptr.RestIt.First;
-- Exhausted "rest": iterate on the first item
Ptr_elem := P.Next(Ptr.FirstIt, Ptr_elem);
if P.Has_Element (Ptr_elem) then
Ptr.Value.Data (1) := P.Elem_Value (Ptr.FirstVal, Ptr_elem);
Ptr.Value.Data (2 .. Ptr.Length) :=
Ptr.RestIt.Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Length);
end if;
end if;
else
-- Size is 0 or 1
Ptr_elem := P.Next (Ptr.FirstIt, Ptr_elem);
if P.Has_Element (Ptr_elem) then
Ptr.Value.Data (1) := P.Elem_Value (Ptr.FirstVal, Ptr_elem);
end if;
end if;
return Ptr;
end;
end;
with Ada.Iterator_Interfaces;
with Ada.Finalization;
use Ada.Finalization;
with ASN1_Iterators.Generic_Basic;
with ASN1_Iterators.SimpleTypes;
with ASN1_Ada_Iterators.Iterators;
use ASN1_Ada_Iterators.Iterators;
with TASTE_DataView;
package ASN1_Iterators.MySeq is
package a_Pkg renames MyInteger.Pkg;
package b_Pkg renames MyEnum_Pkg;
type ASN1_MySeq_Ptr;
type ASN1_MySeq_It;
type ASN1_MySeq is new Controlled
with record
a_val : a_Pkg.It.Basic_ASN1_Iterator;
a_it : a_Pkg.It.Iterator;
b_val : b_Pkg.It.Basic_ASN1_Iterator;
b_i : B_Pkg.It.Iterator;
Value : asn1SccMySeq;
-- First value
-- FirstVal : P.Basic_ASN1_Iterator;
--FirstIt : P.Iterator;
end record
with Default_Iterator => Iterate,
Iterator_Element => asn1SccMySeq,
Constant_Indexing => Element_MySeq_Value;
type Cursor is access all ASN1_MySeq;
-- Constructor (called automatically)
procedure Initialize (Self : in out ASN1_MySeq);
function Has_Element_MySeq (Ptr : Cursor) return Boolean;
package Iterators_MySeq is
new Ada.Iterator_Interfaces (Cursor, Has_Element_MySeq);
type ASN1_MySeq_It is new Iterators_MySeq.Forward_Iterator with record
Ptr : Cursor;
end record;
overriding function First (Item : ASN1_MySeq_It) return Cursor;
overriding function Next (Item : ASN1_MySeq_It;
Ptr : Cursor) return Cursor;
function Iterate (self : ASN1_MySeq)
return ASN1_MySeq_It'Class; -- Iterators_SeqOf.Forward_Iterator'Class;
function Element_MySeq_Value (Self : ASN1_MySeq;
Ptr : Cursor)
return asn1SccMySeq is (self.Value);
end;
with ASN1_Ada_Iterators.iterators; -- Generated by asn1scc using custom stg file with ASN1_Ada_Iterators.Iterators;
use ASN1_Ada_Iterators.iterators; use ASN1_Ada_Iterators.Iterators;
with TASTE_DataView; with TASTE_Dataview;
use TASTE_DataView; use TASTE_Dataview;
with ada.text_io; with Ada.Text_IO;
use ada.text_io; use Ada.Text_IO;
procedure test_generic is procedure test_generic is
-- THIS IS HOW TO DO IT MANUALLY: -- THIS IS HOW TO DO IT MANUALLY:
-- -- create an Integer type with a range constraint -- -- create an Integer type with a range constraint
-- package MyInteger is new Generic_Integer (1, 4); -- package MyInteger is new Generic_Integer (1, 4);
-- --
...@@ -23,50 +23,53 @@ procedure test_generic is ...@@ -23,50 +23,53 @@ procedure test_generic is
-- Max => 3, -- Max => 3,
-- Basic => MyInteger.It); -- Basic => MyInteger.It);
-- --
use MyInteger_Pkg; use MyInteger_Pkg;
use MySeqOf_Pkg; use MySeqOf_Pkg;
use MyVarSeqOf_Pkg; use MyVarSeqOf_Pkg;
use MyEnum_Pkg; use MyEnum_Pkg;
use MySeqOfEnum_Pkg; use MySeqOfEnum_Pkg;
use MySeq_Pkg;
-- Test cases -- Test cases
MyIt : MyInteger_Pkg.Instance; MyIt : MyInteger_Pkg.Instance;
Fixed_SeqOf : MySeqOf_Pkg.Instance; Fixed_SeqOf : MySeqOf_Pkg.Instance;
Var_SeqOf : MyVarSeqOf_Pkg.Instance; Var_SeqOf : MyVarSeqOf_Pkg.Instance;
Enum : MyEnum_Pkg.Instance; Enum : MyEnum_Pkg.Instance;
SeqOfEnum : MySeqOfEnum_Pkg.Instance; SeqOfEnum : MySeqOfEnum_Pkg.Instance;
SeqOfItm : asn1SccMySeqOf; Seq : MySeq_Pkg.Instance;
VarSeqOfItm : asn1SccMyVarSeqOf;
SeqOfEnumItm : asn1SccMySeqOfEnum; SeqOfItm : asn1SccMySeqOf;
i : Natural := 1; VarSeqOfItm : asn1SccMyVarSeqOf;
SeqOfEnumItm : asn1SccMySeqOfEnum;
i : Natural := 1;
begin begin
-- test: compute all possible values of the integer type -- test: compute all possible values of the integer type
-- (equivalent to "for each in 1..3 loop put_line(each'img); end loop;") -- (equivalent to "for each in 1..3 loop put_line(each'img); end loop;")
for each of MyIt loop for each of MyIt loop
--Put_Line(each'img); -- Put_Line(each'img);
Put_Line(Image(each)); Put_Line (Image (each));
end loop; end loop;
-- test: compute all combinations of values for the fixed-size array -- test: compute all combinations of values for the fixed-size array
Put_Line ("Variable-size array:"); Put_Line ("Variable-size array:");
for each of Var_SeqOf loop for each of Var_SeqOf loop
To_ASN1 (From => each, To => VarSeqOfItm); To_ASN1 (From => each, To => VarSeqOfItm);
Put(Image(VarSeqOfItm)); Put (Image (VarSeqOfItm));
i := (if i mod 10 = 0 then 1 else i + 1); i := (if i mod 10 = 0 then 1 else i + 1);
if i = 1 then if i = 1 then
New_Line; New_Line;
end if; end if;
end loop; end loop;
-- test: compute all combination of values for the variable-size array -- test: compute all combination of values for the variable-size array
New_Line; New_Line;
Put_Line ("Fixed-size array:"); Put_Line ("Fixed-size array:");
i := 1; i := 1;
for each of Fixed_SeqOf loop for each of Fixed_SeqOf loop
To_ASN1 (From => each, To => SeqOfItm); To_ASN1 (From => each, To => SeqOfItm);
Put(Image(SeqOfItm)); Put (Image (SeqOfItm));
i := (if i mod 10 = 0 then 1 else i + 1); i := (if i mod 10 = 0 then 1 else i + 1);
if i = 1 then if i = 1 then
New_Line; New_Line;
...@@ -87,5 +90,9 @@ begin ...@@ -87,5 +90,9 @@ begin
end loop; end loop;
New_Line; New_Line;
end; Put_Line ("Sequence with 2 fields");
for Each of Seq loop
Put (Image (Each) & " ");
end loop;
New_Line;
end test_generic;
...@@ -3,4 +3,17 @@ project test_generic is ...@@ -3,4 +3,17 @@ project test_generic is
for Source_Dirs use ("test", "build_test/iterators"); for Source_Dirs use ("test", "build_test/iterators");
for Main use ("test_generic.adb"); for Main use ("test_generic.adb");
for Object_Dir use "build_test"; for Object_Dir use "build_test";
package Compiler is
for Default_Switches ("Ada") use
("-g",
"-O2",
"-gnatf",
"-gnaty",
"-gnatwa",
"-gnatoa",
-- "-gnatg",
"-fstack-check");
end Compiler;
end test_generic; end test_generic;