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

Improve a bit the enumerated

parent 4aeaa78f
......@@ -7,6 +7,8 @@ use Interfaces;
generic
type Sort is (<>); -- a discrete type, such as enumerated
package ASN1_Iterators.Generic_Enumerated is
-- To avoid exception with 'Succ attribute when last item is reached
-- keep a flag set to one when the iteration is finished
Is_Last : Boolean := False;
-- function Elem_Init return Sort is (Sort'First);
......
......@@ -18,9 +18,17 @@ group ada_iterators_iterators_adb;
RootXml(arrsFiles) ::= <<
-- This file was generated automatically by TASTE: DO NOT EDIT
with Ada.Strings,
Ada.Strings.Fixed,
Ada.Characters.Handling;
use Ada.Strings,
Ada.Strings.Fixed,
Ada.Characters.Handling;
package body ASN1_Ada_Iterators.iterators is
$arrsFiles;separator="\n"$
$arrsFiles;separator="\n"$
end;
>>
......@@ -47,8 +55,8 @@ ImportedMod(sName, sCName, arrsTypes, arrsVars) ::= <<
/* A single Type Assignment, this is filled for all types of all modules */
TasXml(sName, nLine, nPos, sType, sCName, sAssigOp, sContract) ::= <<
package body $sCName$_pkg is
$sType$
$sContract$
$sType$
$sContract$
end;
>>
......@@ -67,7 +75,8 @@ $sSubType$
sName may be Generic_Integer or Generic_Real
*/
MinMaxType(sName, sMin, sMax, bFixedSize, bIsUnsigned, bIsRealType) ::= <<
function Image (Elm : ASN1_Type) return String is (Elm'Img);
function Image (Elm : ASN1_Type) return String is
(Ada.Strings.Fixed.Trim (Elm'Img, Both));
procedure To_ASN1 (From : Interfaces.$if(bIsUnsigned)$Unsigned_64$else$$if(bIsRealType)$Long_Float$else$Integer_64$endif$$endif$; To : out ASN1_Type) is
begin
......@@ -119,7 +128,7 @@ EnumItem (sName, sCName, nVal, nLine, nPos, sCID) ::= <<
/* Enumerated type: arrsItems is an array of EnumItem */
EnumType(arrsItems) ::= <<
function Image (Elm : ASN1_Type) return String is (Elm'Img);
function Image (Elm : ASN1_Type) return String is (To_Lower (Elm'Img));
>>
......@@ -201,23 +210,23 @@ begin
end if;
if Elm.Data'Length > 1 then
for Idx in 2 .. Elm.Data'Length loop
Res := Res & "," & Image (Elm.Data (Idx));
Res := Res & ", " & Image (Elm.Data (Idx));
end loop;
end if;
return To_String ("{" & Res & " }");
return To_String ("{ " & Res & " }");
end;
$else$
function Image_Rec (Elm : ASN1_Type) return String is
(if Elm.Length > 0 then
(Image (Elm.Data (1))
& (if Elm.Length > 1 then ","
& (if Elm.Length > 1 then ", "
& Image_Rec (ASN1_Type'(Length => Elm.Length-1,
Data => Elm.Data(2 .. Elm.Length) &
Elm.Data(1 .. Elm.Data'Length - Elm.Length + 1)))
else ""))
else "");
begin
return "{" & Image_Rec (Elm) & " }";
return "{ " & Image_Rec (Elm) & " }";
end;
$endif$
>>
......
......@@ -69,10 +69,10 @@ ImportedMod(sName, sCName, arrsTypes, arrsVars) ::= <<
TasXml(sName, nLine, nPos, sType, sCName, sAssigOp, sContract) ::= <<
-- Type "$sName$ defined at line $nLine$
package $sCName$_pkg is
subtype ASN1_Type is asn1Scc$sCName$;
package Inner is new $sType$
subtype Instance is Inner.Instance;
function Image (Elm : ASN1_Type) return String;
subtype ASN1_Type is asn1Scc$sCName$;
package Inner is new $sType$
subtype Instance is Inner.Instance;
function Image (Elm : ASN1_Type) return String;
end;
>>
......@@ -92,8 +92,8 @@ $sSubType$
*/
MinMaxType(sName, sMin, sMax, bFixedSize, bIsUnsigned, bIsRealType) ::= <<
Generic_$if(bIsUnsigned)$Unsigned_$endif$$sName$ (Min => $sMin$, Max => $sMax$);
package It renames Inner.It;
procedure To_ASN1(From : Interfaces.$if(bIsUnsigned)$Unsigned_64$else$$if(bIsRealType)$Long_Float$else$Integer_64$endif$$endif$; To : out ASN1_Type);
package It renames Inner.It;
procedure To_ASN1(From : Interfaces.$if(bIsUnsigned)$Unsigned_64$else$$if(bIsRealType)$Long_Float$else$Integer_64$endif$$endif$; To : out ASN1_Type);
>>
......@@ -143,6 +143,7 @@ EnumItem (sName, sCName, nVal, nLine, nPos, sCID) ::= <<
/* Enumerated type: arrsItems is an array of EnumItem */
EnumType(arrsItems) ::= <<
Generic_Enumerated (Sort => ASN1_Type);
package It renames Inner.It;
>>
......
......@@ -9,6 +9,8 @@ MyVarSeqOf ::= SEQUENCE (SIZE (1..4)) OF MyInteger
MyEnum ::= ENUMERATED { hello, world, how-are-you }
MySeqOfEnum ::= SEQUENCE (SIZE (3)) OF MyEnum
--MyChoice ::= CHOICE {
-- choice-a MyInteger,
-- choice-b MySeqOf
......
......@@ -27,16 +27,19 @@ procedure test_generic is
use MySeqOf_Pkg;
use MyVarSeqOf_Pkg;
use MyEnum_Pkg;
use MySeqOfEnum_Pkg;
-- Test cases
MyIt : MyInteger_Pkg.Instance;
Fixed_SeqOf : MySeqOf_Pkg.Instance;
Var_SeqOf : MyVarSeqOf_Pkg.Instance;
Enum : MyEnum_Pkg.Instance;
MyIt : MyInteger_Pkg.Instance;
Fixed_SeqOf : MySeqOf_Pkg.Instance;
Var_SeqOf : MyVarSeqOf_Pkg.Instance;
Enum : MyEnum_Pkg.Instance;
SeqOfEnum : MySeqOfEnum_Pkg.Instance;
SeqOfItm : asn1SccMySeqOf;
VarSeqOfItm : asn1SccMyVarSeqOf;
i : Natural := 1;
SeqOfItm : asn1SccMySeqOf;
VarSeqOfItm : asn1SccMyVarSeqOf;
SeqOfEnumItm : asn1SccMySeqOfEnum;
i : Natural := 1;
begin
-- test: compute all possible values of the integer type
......@@ -45,6 +48,7 @@ begin
--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
......@@ -57,6 +61,7 @@ begin
end loop;
-- test: compute all combination of values for the variable-size array
New_Line;
Put_Line ("Fixed-size array:");
i := 1;
for each of Fixed_SeqOf loop
......@@ -68,10 +73,19 @@ begin
end if;
end loop;
New_Line;
Put_Line ("Enumerated type");
for Each of Enum loop
Put_Line (Image (Each));
end loop;
New_Line;
Put_Line ("Sequence of Enumerated type");
for Each of SeqOfEnum loop
To_ASN1 (From => Each, To => SeqOfEnumItm);
Put (Image (SeqOfEnumItm) & " ");
end loop;
New_Line;
end;
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