...
 
Commits (7)
......@@ -5,11 +5,10 @@ all:
@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
mkdir -p obj && cp src/taste-asn1-iterators.py obj/taste-asn1-iterators
gprbuild -p 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
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
==============
(c) 2016-2017 European Space Agency
(c) 2016-2019 European Space Agency
Author/Contact: Maxime.Perrotin@esa.int
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)
test:
cd src
make
Support integer, enumerated, sequence, sequence of (fixed and variable sizes)
Work in progress... Part of the TASTE project.
......@@ -16,33 +16,33 @@ package body ASN1_Iterators.Generic_Basic is
Self.Is_Valid := True;
end;
function Has_Element (Ptr : Iterator_Ptr) return Boolean is
(Ptr.Value.Has_Element and Ptr.Is_Valid);
function Has_Element (Position : Cursor) return Boolean is
(Position.Value.Has_Element and Position.Is_Valid);
function First (Item : Iterator) return Iterator_Ptr is
function First (Item : Iterator) return Cursor is
begin
Item.Ptr.Value.First;
Item.Position.Value.First;
-- Reset validity flag
Item.Ptr.Is_Valid := True;
return Item.Ptr;
Item.Position.Is_Valid := True;
return Item.Position;
end;
function Next (Item : Iterator;
Ptr : Iterator_Ptr) return Iterator_Ptr is
Position : Cursor) return Cursor is
pragma Unreferenced (Item);
begin
Ptr.Value.Next;
return Ptr;
Position.Value.Next;
return Position;
exception
when Stop_Iteration => Ptr.Is_Valid := False;
return Ptr;
when Stop_Iteration => Position.Is_Valid := False;
return Position;
end;
function Iterate (Self : Basic_ASN1_Iterator)
return Forward_Iterator is
begin
return I: Iterator do
I.Ptr := Self'Unrestricted_Access;
I.Position := Self'Unrestricted_Access;
end return;
end;
end;
......@@ -20,28 +20,28 @@ package ASN1_Iterators.Generic_Basic is
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
new Ada.Iterator_Interfaces (Iterator_Ptr, Has_Element);
new Ada.Iterator_Interfaces (Cursor, Has_Element);
type Iterator is new Iterators.Forward_Iterator with record
Ptr : Iterator_Ptr;
Position : Cursor;
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;
Ptr : Iterator_Ptr) return Iterator_Ptr;
Position : Cursor) return Cursor;
subtype Forward_Iterator is Iterators.Forward_Iterator'Class;
function Iterate (Self : Basic_ASN1_Iterator) return Forward_Iterator;
function Elem_Value (Self : Basic_ASN1_Iterator;
Ptr : Iterator_Ptr)
return P.Sort is (Ptr.Value.Element_Value);
end;
Position : Cursor)
return P.Sort is (Position.Value.Element_Value);
end ASN1_Iterators.Generic_Basic;
......@@ -23,4 +23,4 @@ package ASN1_Iterators.Generic_Enumerated is
package It is new Generic_Basic (P => Discrete_Type);
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
if Self.Length > 1 then
Self.Rest := new ASN1_SeqOf (self.Length - 1);
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;
function Has_Element_SeqOf (Ptr: ASN1_SeqOf_Ptr) return Boolean is
(P.Has_Element(P.Ptr(Ptr.FirstIt)));
function Has_Element_SeqOf (Position: Cursor) return Boolean is
(P.Has_Element(P.Get_Cursor (Position.FirstIt)));
function Iterate (Self : ASN1_SeqOf)
return ASN1_SeqOf_It'Class is --Iterators_SeqOf.Forward_Iterator'Class is
begin
return I: ASN1_SeqOf_It do
I.Ptr := Self'Unrestricted_Access;
I.Position := Self'Unrestricted_Access;
end return;
end;
function First (Item : ASN1_SeqOf_It) return ASN1_SeqOf_Ptr is
Ptr_Elem : P.Iterator_Ptr := P.Ptr (Item.Ptr.FirstIt);
function First (Item : ASN1_SeqOf_It) return Cursor is
Ptr_Elem : P.Cursor := P.Get_Cursor (Item.Position.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,
Item.Position.FirstIt := P.Iterator (Item.Position.FirstVal.Iterate);
Ptr_Elem := P.First (Item.Position.FirstIt);
Item.Position.Value.Data (1) := P.Elem_Value (Item.Position.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);
if Item.Position.Length > 1 then
Item.Position.Value.Data (2 .. Item.Position.Length) :=
Item.Position.RestIt.Position.Value.Data (1 .. Item.Position.RestIt.Position.Length);
end if;
return Item.Ptr;
return Item.Position;
end;
function Next (Item : ASN1_SeqOf_It;
Ptr : ASN1_SeqOf_Ptr) return ASN1_SeqOf_Ptr is
Position : Cursor) return Cursor is
pragma Unreferenced (Item);
Ptr_elem : P.Iterator_Ptr := P.Ptr (Ptr.FirstIt);
Ptr_elem : P.Cursor := P.Get_Cursor (Position.FirstIt);
begin
if Ptr.Length > 1 then
Ptr.RestIt.Ptr := Ptr.RestIt.Next (Ptr.RestIt.Ptr);
if Has_Element_SeqOf (Ptr.RestIt.Ptr) then
Ptr.Value.Data (2 .. Ptr.Length) :=
Ptr.RestIt.Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Value.Length);
if Position.Length > 1 then
Position.RestIt.Position := Position.RestIt.Next (Position.RestIt.Position);
if Has_Element_SeqOf (Position.RestIt.Position) then
Position.Value.Data (2 .. Position.Length) :=
Position.RestIt.Position.Value.Data (1 .. Position.RestIt.Position.Value.Length);
else
Ptr.RestIt.Ptr := Ptr.RestIt.First;
Position.RestIt.Position := Position.RestIt.First;
-- 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
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);
Position.Value.Data (1) := P.Elem_Value (Position.FirstVal, Ptr_elem);
Position.Value.Data (2 .. Position.Length) :=
Position.RestIt.Position.Value.Data (1 .. Position.RestIt.Position.Length);
end if;
end if;
else
-- 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
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;
return Ptr;
return Position;
end;
end;
......@@ -17,7 +17,7 @@ package ASN1_Iterators.Generic_Fixed_SeqOf is
Data : DataArray (1 .. Max);
end record;
type ASN1_SeqOf_Ptr;
type Cursor;
type ASN1_SeqOf_It;
type ASN1_SeqOf (Size : Natural) is new Controlled
......@@ -35,28 +35,28 @@ package ASN1_Iterators.Generic_Fixed_SeqOf is
Iterator_Element => SeqOf,
Constant_Indexing => Element_SeqOf_Value;
type ASN1_SeqOf_Ptr is access all ASN1_SeqOf;
type Cursor is access all ASN1_SeqOf;
-- Constructor (called automatically)
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
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
Ptr : ASN1_SeqOf_Ptr;
Position : Cursor;
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;
Ptr : ASN1_SeqOf_Ptr) return ASN1_SeqOf_Ptr;
Position : Cursor) return Cursor;
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;
Ptr : ASN1_SeqOf_Ptr)
Position : Cursor)
return SeqOf is (self.Value);
end;
end ASN1_Iterators.Generic_Fixed_SeqOf;
......@@ -5,8 +5,8 @@ with Interfaces,
use Interfaces;
generic
Min: Interfaces.Integer_64;
Max: Interfaces.Integer_64;
Min : Interfaces.Integer_64;
Max : Interfaces.Integer_64;
package ASN1_Iterators.Generic_Integer is
function Elem_Init return Interfaces.Integer_64 is (Min);
......@@ -28,4 +28,4 @@ package ASN1_Iterators.Generic_Integer is
package It is new Generic_Basic (P => Signed_Integer);
subtype Instance is It.Basic_ASN1_Iterator;
end;
end ASN1_Iterators.Generic_Integer;
......@@ -7,18 +7,18 @@ package body ASN1_Iterators.Generic_Iterator is
-- end;
function First (Item : Iterator) return Cursor is
C: constant Cursor := Item.Ptr;
C: constant Cursor := Item.Position;
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;
end;
function Next (Item : Iterator;
Ptr : Cursor)
Position : Cursor)
return Cursor is
C: constant Cursor := Item.Ptr;
C: constant Cursor := Item.Position;
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;
end;
......@@ -26,7 +26,7 @@ package body ASN1_Iterators.Generic_Iterator is
return Iterators.Forward_Iterator'Class is
begin
return I: Iterator do
I.Ptr := self'Unrestricted_Access;
I.Position := self'Unrestricted_Access;
end return;
end;
......
......@@ -19,16 +19,16 @@ package ASN1_Iterators.Generic_Iterator is
type Cursor is access all Generic_Iterator_Type;
function Elem (Self : Generic_Iterator_Type; Ptr : Cursor)
return ASN1_Type is (Ptr.Item.Element);
function Elem (Self : Generic_Iterator_Type; Position : Cursor)
return ASN1_Type is (Position.Item.Element);
function Has_Element (Ptr : Cursor) return Boolean is
(ASN1_Iterable.Has_Element(ASN1_Iterable.Iterable'Class(Ptr.all.Item)));
function Has_Element (Position : Cursor) return Boolean is
(ASN1_Iterable.Has_Element(ASN1_Iterable.Iterable'Class(Position.all.Item)));
package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element);
type Iterator is new Iterators.Forward_Iterator with record
Ptr : Cursor;
Position : Cursor;
end record;
--overriding
......@@ -39,7 +39,7 @@ package ASN1_Iterators.Generic_Iterator is
overriding
function Next (Item : Iterator;
Ptr : Cursor)
Position : Cursor)
return Cursor;
function Iterate (self : Generic_Iterator_Type)
......
......@@ -7,60 +7,68 @@ package body ASN1_Iterators.Generic_SeqOf is
self.RestVal := new P.ASN1_SeqOf(Self.Length);
self.RestIt :=
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;
function Has_Element_Variable_SeqOf (Ptr: ASN1_Variable_SeqOf_Ptr)
return Boolean is (Length_Pkg.Has_Element(Length_Pkg.Ptr(Ptr.LenIt)));
function Has_Element_Variable_SeqOf
(Position : Cursor)
return Boolean is
(Length_Pkg.Has_Element(Length_Pkg.Get_Cursor (Position.LenIt)));
function Iterate (self : ASN1_Variable_SeqOf)
return Iterators_Variable_SeqOf.Forward_Iterator'Class is
begin
return I: ASN1_Variable_SeqOf_It do
I.Ptr := Self'Unrestricted_Access;
I.Position := Self'Unrestricted_Access;
end return;
end;
function First (Item : ASN1_Variable_SeqOf_It)
return ASN1_Variable_SeqOf_Ptr is
return Cursor is
begin
-- 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
Item.Ptr.Value.Data (1 .. Item.Ptr.RestIt.Ptr.Value.Data'Length) :=
Item.Ptr.RestIt.Ptr.Value.Data;
return Item.Ptr;
Item.Position.Value.Data
(1 .. Item.Position.RestIt.Position.Value.Data'Length) :=
Item.Position.RestIt.Position.Value.Data;
return Item.Position;
end;
function Next (Item : ASN1_Variable_SeqOf_It;
Ptr : ASN1_Variable_SeqOf_Ptr)
return ASN1_Variable_SeqOf_Ptr
Position : Cursor)
return Cursor
is
pragma Unreferenced (Item);
Ptr_elem : Length_Pkg.Iterator_Ptr := Length_Pkg.Ptr(Ptr.LenIt);
Position_elem : Length_Pkg.Cursor :=
Length_Pkg.Get_Cursor (Position.LenIt);
begin
Ptr.RestIt.Ptr := Ptr.RestIt.Next (Ptr.RestIt.Ptr);
if P.Has_Element_SeqOf (Ptr.RestIt.Ptr) then
Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Value.Data'Length) :=
Ptr.RestIt.Ptr.Value.Data;
Position.RestIt.Position := Position.RestIt.Next (Position.RestIt.Position);
if P.Has_Element_SeqOf (Position.RestIt.Position) then
Position.Value.Data
(1 .. Position.RestIt.Position.Value.Data'Length) :=
Position.RestIt.Position.Value.Data;
else
Ptr.RestIt.Ptr := Ptr.RestIt.First;
Position.RestIt.Position := Position.RestIt.First;
-- Exhausted "rest": iterate on the first item
Ptr_elem := Ptr.LenIt.Next (Ptr_elem);
if Length_Pkg.Has_Element (Ptr_elem) then
Ptr.Value.Length := Integer (Ptr_Elem.Value.Value);
Ptr.Length := Ptr.Value.Length;
Ptr.RestVal := new P.ASN1_SeqOf(Ptr.Value.Length);
Ptr.RestIt :=
new P.ASN1_SeqOf_It'(P.ASN1_SeqOf_It (Ptr.RestVal.Iterate));
Ptr.RestIt.Ptr := Ptr.RestIt.First;
Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Value.Data'Length) :=
Ptr.RestIt.Ptr.Value.Data;
Position_elem := Position.LenIt.Next (Position_elem);
if Length_Pkg.Has_Element (Position_elem) then
Position.Value.Length := Integer (Position_Elem.Value.Value);
Position.Length := Position.Value.Length;
Position.RestVal := new P.ASN1_SeqOf(Position.Value.Length);
Position.RestIt :=
new P.ASN1_SeqOf_It'(P.ASN1_SeqOf_It
(Position.RestVal.Iterate));
Position.RestIt.Position := Position.RestIt.First;
Position.Value.Data
(1 .. Position.RestIt.Position.Value.Data'Length) :=
Position.RestIt.Position.Value.Data;
end if;
end if;
return Ptr;
return Position;
end;
end;
end ASN1_Iterators.Generic_SeqOF;
......@@ -17,19 +17,19 @@ generic
with package Basic is new Generic_Basic (<>);
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
package Length_ty is new Generic_Integer (Integer_64(Min),
Integer_64(Max));
package Length_ty is new Generic_Integer (Integer_64 (Min),
Integer_64 (Max));
-- Instantiate the package to iterate on the integer for the length
package Length_Pkg renames Length_ty.It;
type ASN1_Variable_SeqOf_Ptr is private;
subtype MySeqOf is P.SeqOf(Max);
type Cursor is private;
subtype Sequence_Of is P.SeqOf (Max);
type ASN1_Variable_SeqOf is new Controlled
with record
Length : Natural := Min;
Value : MySeqOf; -- P.SeqOf(Max);
Value : Sequence_Of;
-- Iterate on the length
LenVal : Length_ty.Instance;
LenIt : Length_Pkg.Iterator;
......@@ -38,45 +38,43 @@ package ASN1_Iterators.Generic_SeqOf is
RestIt : access P.ASN1_SeqOf_It;
end record
with Default_Iterator => Iterate,
Iterator_Element => MySeqOf, --P.SeqOf,
Iterator_Element => Sequence_Of,
Constant_Indexing => Element_Variable_SeqOf_Value;
-- 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;
package Iterators_Variable_SeqOf is
new Ada.Iterator_Interfaces (ASN1_Variable_SeqOf_Ptr,
new Ada.Iterator_Interfaces (Cursor,
Has_Element_Variable_SeqOf);
type ASN1_Variable_SeqOf_It
is new Iterators_Variable_SeqOf.Forward_Iterator with record
Ptr : ASN1_Variable_SeqOf_Ptr;
Position : Cursor;
end record;
overriding
function First (Item : ASN1_Variable_SeqOf_It)
return ASN1_Variable_SeqOf_Ptr;
return Cursor;
overriding
function Next (Item : ASN1_Variable_SeqOf_It;
Ptr : ASN1_Variable_SeqOf_Ptr)
return ASN1_Variable_SeqOf_Ptr;
Position : Cursor)
return Cursor;
function Iterate (self : ASN1_Variable_SeqOf)
return Iterators_Variable_SeqOf.Forward_Iterator'Class;
function Element_Variable_SeqOf_Value (Self : ASN1_Variable_SeqOf;
Ptr : ASN1_Variable_SeqOf_Ptr)
--return P.SeqOf is (Self.Value);
return MySeqOf is (Self.Value);
Position : Cursor)
return Sequence_Of is (Self.Value);
subtype Instance is ASN1_Variable_SeqOf;
private
type ASN1_Variable_SeqOf_Ptr is access all ASN1_Variable_SeqOf;
end;
private
type Cursor is access all ASN1_Variable_SeqOf;
end ASN1_Iterators.Generic_SeqOF;
......@@ -5,14 +5,14 @@ with Interfaces;
use Interfaces;
generic
Min: Interfaces.Unsigned_64;
Max: Interfaces.Unsigned_64;
Min : Interfaces.Unsigned_64;
Max : Interfaces.Unsigned_64;
package ASN1_Iterators.Generic_Unsigned_Integer is
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);
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);
package Unsigned_Type is new SimpleTypes
......@@ -25,4 +25,4 @@ package ASN1_Iterators.Generic_Unsigned_Integer is
package It is new Generic_Basic (P => Unsigned_Type);
subtype Instance is It.Basic_ASN1_Iterator;
end;
end ASN1_Iterators.Generic_Unsigned_Integer;
......@@ -34,6 +34,6 @@ package ASN1_Iterators.Iterable_Integer is
-- If it is needed to iterate manually, provide Cursor and Iterator:
subtype Cursor is Custom_Iterator.Cursor;
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;
end;
......@@ -11,13 +11,11 @@ package body ASN1_Iterators.Iterable_SeqOF is
end;
function Has_Element (It: ASN1_SequenceOf) return Boolean is
-- (P.Has_Element(P.Ptr(Ptr.FirstIt)));
begin
return False;
end;
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;
begin
It.Value.Length := It.Length;
......@@ -30,48 +28,14 @@ package body ASN1_Iterators.Iterable_SeqOF is
It.Rest_It :=
new Cust_Iterator'(Custom_Iterator.Iterator (It.Rest.Iterate)
with others => <>);
It.Rest_It.Ptr := It.Rest_It.First;
It.Rest_It.Position := It.Rest_It.First;
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;
end;
function Next (It: ASN1_SequenceOf) return Generic_SeqOf is
--Ptr_elem : P.Iterator_Ptr := P.Ptr(Ptr.FirstIt);
Temp : constant Generic_SeqOf := It.Value;
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;
end;
end;
......@@ -55,7 +55,7 @@ package ASN1_Iterators.Iterable_SeqOF is
subtype Iterator is Custom_Iterator.Iterators.Forward_Iterator'Class;
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;
......
......@@ -20,4 +20,4 @@ package ASN1_Iterators.SimpleTypes is
function Element_Value (Self : in out SimpleType) return Sort is
(Self.Value);
end;
end ASN1_Iterators.SimpleTypes;
package ASN1_Iterators is
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 ) ::= <<
ChoiceType(arrsChildren) ::= <<
-- $arrsChildren;separator=",\n"$
}
>>
......@@ -159,7 +158,6 @@ SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::
/* Full sequence (record) type */
SequenceType(arrsChildren) ::= <<
-- $arrsChildren;separator=",\n"$
}
>>
......
......@@ -170,8 +170,7 @@ SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::
/* Full sequence (record) type */
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
use ASN1_Ada_Iterators.iterators;
with ASN1_Ada_Iterators.Iterators;
use ASN1_Ada_Iterators.Iterators;
with TASTE_DataView;
use TASTE_DataView;
with TASTE_Dataview;
use TASTE_Dataview;
with ada.text_io;
use ada.text_io;
with Ada.Text_IO;
use Ada.Text_IO;
procedure test_generic is
......@@ -28,6 +28,7 @@ procedure test_generic is
use MyVarSeqOf_Pkg;
use MyEnum_Pkg;
use MySeqOfEnum_Pkg;
use MySeq_Pkg;
-- Test cases
MyIt : MyInteger_Pkg.Instance;
......@@ -36,6 +37,8 @@ procedure test_generic is
Enum : MyEnum_Pkg.Instance;
SeqOfEnum : MySeqOfEnum_Pkg.Instance;
Seq : MySeq_Pkg.Instance;
SeqOfItm : asn1SccMySeqOf;
VarSeqOfItm : asn1SccMyVarSeqOf;
SeqOfEnumItm : asn1SccMySeqOfEnum;
......@@ -45,15 +48,15 @@ begin
-- test: compute all possible values of the integer type
-- (equivalent to "for each in 1..3 loop put_line(each'img); end loop;")
for each of MyIt loop
--Put_Line(each'img);
Put_Line(Image(each));
-- Put_Line(each'img);
Put_Line (Image (each));
end loop;
-- test: compute all combinations of values for the fixed-size array
Put_Line ("Variable-size array:");
for each of Var_SeqOf loop
To_ASN1 (From => each, To => VarSeqOfItm);
Put(Image(VarSeqOfItm));
Put (Image (VarSeqOfItm));
i := (if i mod 10 = 0 then 1 else i + 1);
if i = 1 then
New_Line;
......@@ -66,7 +69,7 @@ begin
i := 1;
for each of Fixed_SeqOf loop
To_ASN1 (From => each, To => SeqOfItm);
Put(Image(SeqOfItm));
Put (Image (SeqOfItm));
i := (if i mod 10 = 0 then 1 else i + 1);
if i = 1 then
New_Line;
......@@ -87,5 +90,9 @@ begin
end loop;
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
for Source_Dirs use ("test", "build_test/iterators");
for Main use ("test_generic.adb");
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;