Commit 91256dde authored by Maxime Perrotin's avatar Maxime Perrotin

Support REAL iterators

parent bb720820
with Text_IO; use Text_IO;
package body ASN1_Iterators.Generic_Real is
function Next (Value : Sort) return Sort is
Result : Sort := Value + Increment;
begin
loop
exit when Is_Constraint_Valid (Result);
Result := Result + Increment;
if Result >= Max then
raise Stop_Iteration;
end if;
end loop;
return Result;
end Next;
end ASN1_Iterators.Generic_Real;
with ASN1_Iterators.SimpleTypes,
ASN1_Iterators.Generic_Basic;
with Interfaces;
use Interfaces;
generic
type Sort is digits <>;
with function Init return Sort;
with function Is_Constraint_Valid (Val : Sort) return Boolean;
Max : Sort;
Increment : Sort := 0.5;
package ASN1_Iterators.Generic_Real is
function Elem_Init return Sort is (Init);
function Has_Element (Value : Sort) return Boolean is (Value <= Max);
function First return Sort is (Init);
function Next (Value : Sort) return Sort;
package Real_Type is new SimpleTypes (Sort => Sort,
Elem_Init => Elem_Init,
Has_Elem => Has_Element,
Elem_First => First,
Elem_Next => Next);
package It is new Generic_Basic (P => Real_Type);
subtype Instance is It.ASN1_Container;
end ASN1_Iterators.Generic_Real;
......@@ -70,10 +70,6 @@ def unsigned_int_adb_template (sort: str, minR: int, maxR: int) -> str:
To_ASN1 (From, Result);
return Result;
end To_ASN1;
function Image (Elm : asn1Scc{sort}) return String is
(Ada.Strings.Fixed.Trim (Elm'Img, Both));
end {sort}_Pkg;'''
......@@ -92,10 +88,6 @@ def signed_int_adb_template (sort: str, minR: int, maxR: int) -> str:
To_ASN1 (From, Result);
return Result;
end To_ASN1;
function Image (Elm : asn1Scc{sort}) return String is
(Ada.Strings.Fixed.Trim (Elm'Img, Both));
end {sort}_Pkg;'''
......@@ -182,8 +174,6 @@ def boolean_adb_template (sort: str) -> str:
end {sort}_Pkg;'''
def fields_adb_init (fields : dict) -> List [str]:
'''
Template for the fields of a sequence used in the Initialize function
......@@ -427,8 +417,11 @@ def ads_template(packages: List[str]) -> str:
with Ada.Iterator_Interfaces,
Ada.Finalization,
Interfaces,
Ada.Strings,
Ada.Strings.Fixed,
ASN1_Ada_Iterators,
ASN1_Iterators.Generic_Integer,
ASN1_Iterators.Generic_Real,
ASN1_Iterators.Generic_Unsigned_Integer,
ASN1_Iterators.Generic_Enumerated,
ASN1_Iterators.Generic_SeqOf;
......@@ -436,6 +429,8 @@ with Ada.Iterator_Interfaces,
pragma Unreferenced (ASN1_Ada_Iterators);
use Ada.Finalization,
Ada.Strings,
Ada.Strings.Fixed,
Interfaces,
ASN1_Iterators;
......@@ -456,7 +451,8 @@ def unsigned_int_ads_template (sort: str, minR: int, maxR: int) -> str:
To : out asn1Scc{sort});
function To_ASN1 (From : Interfaces.Unsigned_64) return asn1Scc{sort};
subtype Instance is Inner.Instance;
function Image (Elm : asn1Scc{sort}) return String;
function Image (Elm : asn1Scc{sort}) return String is
(Ada.Strings.Fixed.Trim (Elm'Img, Both));
end {sort}_Pkg;'''
......@@ -470,7 +466,8 @@ def signed_int_ads_template (sort: str, minR: int, maxR: int) -> str:
To : out asn1Scc{sort});
function To_ASN1 (From : Interfaces.Integer_64) return asn1Scc{sort};
subtype Instance is Inner.Instance;
function Image (Elm : asn1Scc{sort}) return String;
function Image (Elm : asn1Scc{sort}) return String is
(Ada.Strings.Fixed.Trim (Elm'Img, Both));
end {sort}_Pkg;'''
......@@ -501,6 +498,24 @@ def enum_ads_template (sort: str) -> str:
end {sort}_Pkg;'''
def real_ads_template (sort: str, maxR: float) -> str:
''' Template for iterating on a REAL type '''
return f'''package {sort}_Pkg is
function Is_Constraint_Valid (Val : asn1Scc{sort}) return Boolean is
(asn1Scc{sort}_IsConstraintValid (Val).Success);
package Inner is new Generic_Real (Sort => asn1Scc{sort},
Init => asn1Scc{sort}_Init,
Is_Constraint_Valid =>
Is_Constraint_Valid,
Max => {maxR},
Increment => 0.5);
package It renames Inner.It;
function To_ASN1 (From : asn1Scc{sort}) return asn1Scc{sort} is (From);
subtype Instance is Inner.Instance;
function Image (Elm : asn1Scc{sort}) return String is (Elm'Img);
end {sort}_Pkg;'''
def fields_ads_pkg (fields : dict) -> List [str]:
''' for each field of a sequence, do a package renaming :
package P_<field> renames <Sort>_Pkg.It
......@@ -723,6 +738,9 @@ def run(options):
packages_adb.append(enum_adb_template(name))
else:
packages_adb.append(boolean_adb_template(name))
elif basic.kind == "RealType":
packages_ads.append(real_ads_template(name,
float(basic.Max)))
elif basic.kind == "SequenceOfType":
inner=basic.type.ReferencedTypeName.replace("-", "_")
packages_ads.append(
......
......@@ -37,6 +37,8 @@ MyChoice ::= CHOICE {
}
Boolean ::= BOOLEAN
MyReal ::= REAL (0.2 .. 1.5 | 10.5 .. 14.5)
END
......@@ -34,6 +34,7 @@ procedure test_generic is
use MySeq4_Pkg;
use MyChoice_Pkg;
use Boolean_Pkg;
use MyReal_Pkg;
-- Test cases
MyIt : MyInteger_Pkg.Instance;
......@@ -47,6 +48,7 @@ procedure test_generic is
Seq3 : MySeq3_Pkg.Instance;
Seq4 : MySeq4_Pkg.Instance;
Bool : Boolean_Pkg.Instance;
Real : MyReal_Pkg.Instance;
SeqOfItm : asn1SccMySeqOf;
VarSeqOfItm : asn1SccMyVarSeqOf;
......@@ -179,4 +181,10 @@ begin
Put (Each'Img & " ");
end loop;
New_Line;
New_Line;
Put_Line ("REAL WITH DISJOINT SET OF VALUES");
for each of Real loop
Put (Each'Img & " ");
end loop;
New_Line;
end test_generic;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment