Commit 7e44d06e authored by Maxime Perrotin's avatar Maxime Perrotin

Improve integer support (not complete)

parent 91256dde
......@@ -5,27 +5,25 @@ with Interfaces,
use Interfaces;
generic
Min : Interfaces.Integer_64;
Max : Interfaces.Integer_64;
type Sort is range <>;
with function Init return Sort;
with function Is_Constraint_Valid (Val : Sort) return Boolean;
Max : Sort;
Increment : Sort := 1;
package ASN1_Iterators.Generic_Integer is
function Elem_Init return Interfaces.Integer_64 is (Min);
function Has_Elem (Value : Interfaces.Integer_64)
return Boolean is (Value <= Max);
function Elem_First return Interfaces.Integer_64 is (Min);
function Elem_Next (Value : Interfaces.Integer_64)
return Interfaces.Integer_64 is (Value + 1);
-- Iterators for signed integers
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 Signed_Integer is new SimpleTypes
(Sort => Interfaces.Integer_64,
(Sort => Sort,
Elem_Init => Elem_Init,
Has_Elem => Has_Elem,
Elem_First => Elem_First,
Elem_Next => Elem_Next);
Has_Elem => Has_Element,
Elem_First => First,
Elem_Next => Next);
package It is new Generic_Basic (P => Signed_Integer);
subtype Instance is It.ASN1_Container;
end ASN1_Iterators.Generic_Integer;
......@@ -19,8 +19,15 @@ package ASN1_Iterators.Generic_SeqOf is
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));
function Init_Len return Integer_64 is (Integer_64 (Min));
function Is_Constraint_Valid (Val : Integer_64) return Boolean is
(Val >= Integer_64 (Min) and Val <= Integer_64 (Max));
package Length_ty is new Generic_Integer (Sort => Integer_64,
Init => Init_Len,
Is_Constraint_Valid =>
Is_Constraint_Valid,
Max => Integer_64 (Max));
-- Instantiate the package to iterate on the integer for the length
package Length_Pkg renames Length_ty.It;
......
......@@ -459,7 +459,12 @@ end {sort}_Pkg;'''
def signed_int_ads_template (sort: str, minR: int, maxR: int) -> str:
''' Template for iterating on an signed integer '''
return f'''package {sort}_Pkg is
package Inner is new Generic_Integer (Min => {minR},
function Is_Constraint_Valid (Val : asn1Scc{sort}) return Boolean is
(asn1Scc{sort}_IsConstraintValid (Val).Success);
package Inner is new Generic_Integer (Sort => asn1Scc{sort},
Init => asn1Scc{sort}_Init,
Is_Constraint_Valid =>
Is_Constraint_Valid,
Max => {maxR});
package It renames Inner.It;
procedure To_ASN1 (From : Interfaces.Integer_64;
......@@ -723,7 +728,7 @@ def run(options):
unsigned_int_adb_template(name,
int(basic.Min),
int(basic.Max)))
elif basic.kind == "IntegerType" and int(basic.Min < 0):
elif basic.kind == "IntegerType" and int(basic.Min) < 0:
packages_ads.append(
signed_int_ads_template(name,
int(basic.Min),
......
......@@ -39,6 +39,8 @@ MyChoice ::= CHOICE {
Boolean ::= BOOLEAN
MyReal ::= REAL (0.2 .. 1.5 | 10.5 .. 14.5)
MyInt2 ::= INTEGER (-5 .. 0 | 10 | 20 .. 25)
END
......@@ -35,6 +35,7 @@ procedure test_generic is
use MyChoice_Pkg;
use Boolean_Pkg;
use MyReal_Pkg;
use MyInt2_Pkg;
-- Test cases
MyIt : MyInteger_Pkg.Instance;
......@@ -49,6 +50,7 @@ procedure test_generic is
Seq4 : MySeq4_Pkg.Instance;
Bool : Boolean_Pkg.Instance;
Real : MyReal_Pkg.Instance;
MyInt2 : MyInt2_Pkg.Instance;
SeqOfItm : asn1SccMySeqOf;
VarSeqOfItm : asn1SccMyVarSeqOf;
......@@ -187,4 +189,11 @@ begin
Put (Each'Img & " ");
end loop;
New_Line;
New_Line;
Put_Line ("INTEGER WITH DISJOINT SET OF VALUES");
for each of MyInt2 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