Commit 6c9ee7f1 authored by Maxime Perrotin's avatar Maxime Perrotin

Update stg to be compliant with ASN1SCC_V4

parent 119bf0b8
/*
* Copyright (c) 2017 European Space Agency
*
* This file is a custom backend to be used with the ASN1SCC tool.
* It generates an Ada package with iterators that compute all possible values
* of all ASN.1 types.
*
* Licensed under the terms of GNU General Public Licence as published by
* the Free Software Foundation.
*
*/
group ada_iterators_iterators_adb;
//delimiters "$", "$"
/* Header of the file */
RootXml(arrsFiles) ::= <<
-- This file was generated automatically by TASTE: DO NOT EDIT
package body ASN1_Ada_Iterators.iterators is
$arrsFiles;separator="\n"$
end;
>>
/* sFileName is a string with the current file name */
FileXml(sFileName, arrsModules) ::= <<
-- ASN.1 File $sFileName$
$arrsModules;separator="\n"$
>>
ModuleXml(sName, sCName, arrsImportedModules, arrsExpTypes, arrsExpVars, arrsTases, arrsVases) ::=<<
-- Module $sCName$
$arrsTases;separator="\n"$
>>
/* An imported module with a list of imported types and variables */
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$
end;
>>
/* A single Variable Assignment (ignored) */
VasXml(sName, nLine, nPos, sType, sValue, sCName) ::= <<
>>
TypeGeneric(nLine, nPos, sSubType) ::= <<
$sSubType$
>>
/* Type with Min and Max constraint. sName is the type kind
This template is used for Integer and Real types; for others,
see MinMaxType2 and SequenceOf
sName may be Generic_Integer or Generic_Real
*/
MinMaxType(sName, sMin, sMax, bFixedSize) ::= <<
function Image(Elm: ASN1_Type) return String is (Elm'Img);
procedure To_ASN1(from: Interfaces.Integer_64; to: out ASN1_Type) is
begin
to := from;
>>
/* String types with size constraint: Bitstring, Octetstring, Ia5String,
NumericString */
MinMaxType2(sName, sMin, sMax, bFixedSize) ::= <<
"kind": "$sName$", "Min": "$sMin$", "Max": "$sMax$"
>>
BooleanType () ::= "Generic_Boolean"
NullType () ::= "Generic_NullType"
/* Integer and RealType full spec in MinMaxType */
IntegerType () ::= "Generic_Integer"
RealType () ::= "Generic_Real"
/* String type full spec in MixMaxType2 */
BitStringType () ::= "BitStringType"
OctetStringType () ::= "OctetStringType"
IA5StringType () ::= "IA5StringType"
NumericStringType () ::= "NumericStringType"
AssigOpNormalType () ::= "="
AssigOpSpecialType () ::= "::"
/* Enumerated item, note the difference between sName, which is the enumerated
name given in the input type, for example if you have
MyType ::= ENUMERATED { a, b, c } then sName can be a, b or c
and sCID which is a name built by the parser for removing ambiguities in
some languages, e.g. if you have two types with the same enumerated name:
MyOtherType ::= ENUMERATED { b, x, y }
When this case happens, sCID will be either "MyType_b" or "MyOtherType_b"
Check if your language needs this or not (C does, Ada does not)
note: the renaming policy can be controlled with the command line of asn1scc
for VDM: assuming sCID, to be checked
nVal is the integer value of the enumerated, use it if needed
*/
EnumItem (sName, sCName, nVal, nLine, nPos, sCID) ::= <<
"$sName$": type("$sCID$", (object,), {
"IntValue": $nVal$, "Line": $nLine$, "CharPositionInLine": $nPos$, "EnumID": "$sCID$"
})
>>
/* Enumerated type: arrsItems is an array of EnumItem */
EnumType(arrsItems) ::= <<
"kind": "EnumeratedType", "Extensible": "False", "ValuesAutoCalculated": "False", "EnumValues": {
$arrsItems;separator=",\n"$
}
>>
/* Choice field
Choice are discriminated unions, they have a name per field and a type :
MyCHOICE ::= CHOICE {
choice-a Type-of-A, -- choice-a is sName
choice-b Type-of-B,
...
}
sNamePresent is an unambiguous name to access the field
*/
ChoiceChild(sName, sCName, nLine, nPos, sChildContent, sNamePresent ) ::= <<
"$sName$": type("$sNamePresent$", (object,), {
"Line": $nLine$, "CharPositionInLine": $nPos$, "EnumID": "$sNamePresent$", "type": type("$sNamePresent$_type", (object,), {
$sChildContent$
})
})
>>
ChoiceType(arrsChildren) ::= <<
"kind": "ChoiceType", "Children": {
$arrsChildren;separator=",\n"$
}
>>
/* Sequence (record) field. May be optional and may have a default value */
SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::= <<
"$sName$": type("$sName$", (object,), {
"Optional": "$bOptional$"$if(sDefVal)$, "DefaultValue": "$sDefVal$"$endif$, "Line": $nLine$, "CharPositionInLine": $nPos$, "type": type("$sName$_type", (object,), {
$sChildContent$
})
})
>>
/* Full sequence (record) type */
SequenceType(arrsChildren) ::= <<
$arrsChildren;separator=",\n"$
}
>>
/* Sequence of (array) */
SequenceOfType(sMin, sMax, sChild) ::= <<
procedure To_ASN1(from: Inner.MySeqOf; to: out ASN1_Type) is
begin
for idx in 1..from.length loop
to.data(idx) := from.data(idx);
end loop;
>>
/* RefTypeMinMax, eg. in SEQUENCE OF INTEGER (0..5) */
RefTypeMinMax(sMin, sMax, sName, sModName, sCName, sCModName) ::= <<
$if(sModName)$$sCModName$.$endif$$sCName$
>>
RefType(sName, sModName, sCName, sCModName) ::= <<
$if(sModName)$$sCModName$.$endif$$sCName$
>>
/* Possible additional information generated after the type itself */
Contract(sTypePattern, sExpr) ::= <<
$sExpr$
>>
TypePatternCommonTypes() ::= ""
TypePatternSequence(sName, sCName, arrsChildren) ::= "--bleuh"
SequencePatternChild(sName, sCName) ::= "--blah"
ContractExprMinMax(sPattern, sMin, sMax, bFixedSize) ::= <<
end;
>>
// SeqOF may have fixed size, in that case there is no Length field
ContractExprSize(sPattern, sMin, sMax, bFixedSize) ::= <<
$if(!bFixedSize)$
to.length := from.length;
$endif$
end;
function Image(Elm: ASN1_Type) return String is
$if(bFixedSize)$
Res : Unbounded_String;
begin
if Elm.Data'Length >= 1 then
Res := To_Unbounded_String(Image(Elm.Data(1)));
end if;
if Elm.Data'Length > 1 then
for idx in 2..Elm.Data'Length loop
Res := Res & "," & Image(Elm.Data(Idx));
end loop;
end if;
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 "," &
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) & " }";
end;
$endif$
>>
ContractExprSequence(arrsChildren) ::= ""
/* Print Values */
Print_IntegerValue(nVal) ::= ""
Print_RealValue(dVal) ::= ""
Print_StringValue(v) ::= ""
Print_TrueValue() ::= ""
Print_FalseValue() ::= ""
Print_BitStringValue(v) ::= ""
Print_OctetStringValue(arruOctets) ::= ""
Print_RefValue(sName) ::= ""
Print_SeqOfValue(arrsValues) ::= ""
Print_SeqValue_Child(sName, sChildValue) ::= ""
Print_SeqValue(arrsValues) ::= ""
Print_ChValue(sAltName,sAltValue) ::= ""
Print_NullValue() ::= ""
/*
* Copyright (c) 2017 European Space Agency
*
* This file is a custom backend to be used with the ASN1SCC tool.
* It generates an Ada package with iterators that compute all possible values
* of all ASN.1 types.
*
* Licensed under the terms of GNU General Public Licence as published by
* the Free Software Foundation.
*
*/
group ada_iterators_iterators_adb;
//delimiters "$", "$"
/* Header of the file */
RootXml(arrsFiles) ::= <<
-- This file was generated automatically by TASTE: DO NOT EDIT
package body ASN1_Ada_Iterators.iterators is
$arrsFiles;separator="\n"$
end;
>>
/* sFileName is a string with the current file name */
FileXml(sFileName, arrsModules) ::= <<
-- ASN.1 File $sFileName$
$arrsModules;separator="\n"$
>>
ModuleXml(sName, sCName, arrsImportedModules, arrsExpTypes, arrsExpVars, arrsTases, arrsVases) ::=<<
-- Module $sCName$
$arrsTases;separator="\n"$
>>
/* An imported module with a list of imported types and variables */
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$
end;
>>
/* A single Variable Assignment (ignored) */
VasXml(sName, nLine, nPos, sType, sValue, sCName) ::= <<
>>
TypeGeneric(nLine, nPos, sAsnFile, sSubType) ::= <<
$sSubType$
>>
/* Type with Min and Max constraint. sName is the type kind
This template is used for Integer and Real types; for others,
see MinMaxType2 and SequenceOf
sName may be Generic_Integer or Generic_Real
*/
MinMaxType(sName, sMin, sMax, bFixedSize) ::= <<
function Image(Elm: ASN1_Type) return String is (Elm'Img);
procedure To_ASN1(from: Interfaces.Integer_64; to: out ASN1_Type) is
begin
to := from;
>>
/* String types with size constraint: Bitstring, Octetstring, Ia5String,
NumericString */
MinMaxType2(sName, sMin, sMax, bFixedSize) ::= <<
"kind": "$sName$", "Min": "$sMin$", "Max": "$sMax$"
>>
BooleanType () ::= "Generic_Boolean"
NullType () ::= "Generic_NullType"
/* Integer and RealType full spec in MinMaxType */
IntegerType () ::= "Generic_Integer"
RealType () ::= "Generic_Real"
/* String type full spec in MixMaxType2 */
BitStringType () ::= "BitStringType"
OctetStringType () ::= "OctetStringType"
IA5StringType () ::= "IA5StringType"
NumericStringType () ::= "NumericStringType"
AssigOpNormalType () ::= "="
AssigOpSpecialType () ::= "::"
/* Enumerated item, note the difference between sName, which is the enumerated
name given in the input type, for example if you have
MyType ::= ENUMERATED { a, b, c } then sName can be a, b or c
and sCID which is a name built by the parser for removing ambiguities in
some languages, e.g. if you have two types with the same enumerated name:
MyOtherType ::= ENUMERATED { b, x, y }
When this case happens, sCID will be either "MyType_b" or "MyOtherType_b"
Check if your language needs this or not (C does, Ada does not)
note: the renaming policy can be controlled with the command line of asn1scc
for VDM: assuming sCID, to be checked
nVal is the integer value of the enumerated, use it if needed
*/
EnumItem (sName, sCName, nVal, nLine, nPos, sCID) ::= <<
"$sName$": type("$sCID$", (object,), {
"IntValue": $nVal$, "Line": $nLine$, "CharPositionInLine": $nPos$, "EnumID": "$sCID$"
})
>>
/* Enumerated type: arrsItems is an array of EnumItem */
EnumType(arrsItems) ::= <<
"kind": "EnumeratedType", "Extensible": "False", "ValuesAutoCalculated": "False", "EnumValues": {
$arrsItems;separator=",\n"$
}
>>
/* Choice field
Choice are discriminated unions, they have a name per field and a type :
MyCHOICE ::= CHOICE {
choice-a Type-of-A, -- choice-a is sName
choice-b Type-of-B,
...
}
sNamePresent is an unambiguous name to access the field
*/
ChoiceChild(sName, sCName, nLine, nPos, sChildContent, sNamePresent ) ::= <<
"$sName$": type("$sNamePresent$", (object,), {
"Line": $nLine$, "CharPositionInLine": $nPos$, "EnumID": "$sNamePresent$", "type": type("$sNamePresent$_type", (object,), {
$sChildContent$
})
})
>>
ChoiceType(arrsChildren) ::= <<
"kind": "ChoiceType", "Children": {
$arrsChildren;separator=",\n"$
}
>>
/* Sequence (record) field. May be optional and may have a default value */
SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::= <<
"$sName$": type("$sName$", (object,), {
"Optional": "$bOptional$"$if(sDefVal)$, "DefaultValue": "$sDefVal$"$endif$, "Line": $nLine$, "CharPositionInLine": $nPos$, "type": type("$sName$_type", (object,), {
$sChildContent$
})
})
>>
/* Full sequence (record) type */
SequenceType(arrsChildren) ::= <<
$arrsChildren;separator=",\n"$
}
>>
/* Sequence of (array) */
SequenceOfType(sMin, sMax, sChild, bFixedSize) ::= <<
procedure To_ASN1(from: Inner.MySeqOf; to: out ASN1_Type) is
begin
for idx in 1..from.length loop
to.data(idx) := from.data(idx);
end loop;
>>
/* RefTypeMinMax, eg. in SEQUENCE OF INTEGER (0..5) */
RefTypeMinMax(sMin, sMax, sName, sModName, sCName, sCModName, bFixedSize) ::= <<
$if(sModName)$$sCModName$.$endif$$sCName$
>>
RefType(sName, sModName, sCName, sCModName) ::= <<
$if(sModName)$$sCModName$.$endif$$sCName$
>>
/* Possible additional information generated after the type itself */
Contract(sTypePattern, sExpr) ::= <<
$sExpr$
>>
TypePatternCommonTypes() ::= ""
TypePatternSequence(sName, sCName, arrsChildren) ::= "--bleuh"
SequencePatternChild(sName, sCName) ::= "--blah"
ContractExprMinMax(sPattern, sMin, sMax, bFixedSize) ::= <<
end;
>>
// SeqOF may have fixed size, in that case there is no Length field
ContractExprSize(sPattern, sMin, sMax, bFixedSize) ::= <<
$if(!bFixedSize)$
to.length := from.length;
$endif$
end;
function Image(Elm: ASN1_Type) return String is
$if(bFixedSize)$
Res : Unbounded_String;
begin
if Elm.Data'Length >= 1 then
Res := To_Unbounded_String(Image(Elm.Data(1)));
end if;
if Elm.Data'Length > 1 then
for idx in 2..Elm.Data'Length loop
Res := Res & "," & Image(Elm.Data(Idx));
end loop;
end if;
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 "," &
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) & " }";
end;
$endif$
>>
ContractExprSequence(arrsChildren) ::= ""
/* Print Values */
Print_IntegerValue(nVal) ::= ""
Print_RealValue(dVal) ::= ""
Print_StringValue(v) ::= ""
Print_TrueValue() ::= ""
Print_FalseValue() ::= ""
Print_BitStringValue(v) ::= ""
Print_OctetStringValue(arruOctets) ::= ""
Print_RefValue(sName) ::= ""
Print_SeqOfValue(arrsValues) ::= ""
Print_SeqValue_Child(sName, sChildValue) ::= ""
Print_SeqValue(arrsValues) ::= ""
Print_ChValue(sAltName,sAltValue) ::= ""
Print_NullValue() ::= ""
......@@ -78,7 +78,7 @@ end;
VasXml(sName, nLine, nPos, sType, sValue, sCName) ::= <<
>>
TypeGeneric(nLine, nPos, sSubType) ::= <<
TypeGeneric(nLine, nPos, sAsnFile, sSubType) ::= <<
$sSubType$
>>
......@@ -191,7 +191,7 @@ SequenceType(arrsChildren) ::= <<
/* Sequence of (array) */
SequenceOfType(sMin, sMax, sChild) ::= <<
SequenceOfType(sMin, sMax, sChild, bFixedSize) ::= <<
Generic_SeqOf (Min => $sMin$, Max => $sMax$, Basic => $sChild$_Pkg.It);
use $sChild$_Pkg;
procedure To_ASN1(from: Inner.MySeqOf; to: out ASN1_Type);
......@@ -199,7 +199,7 @@ Generic_SeqOf (Min => $sMin$, Max => $sMax$, Basic => $sChild$_Pkg.It);
/* RefTypeMinMax, eg. in SEQUENCE OF INTEGER (0..5) */
RefTypeMinMax(sMin, sMax, sName, sModName, sCName, sCModName) ::= <<
RefTypeMinMax(sMin, sMax, sName, sModName, sCName, sCModName, bFixedSize) ::= <<
$if(sModName)$$sCModName$.$endif$$sCName$
>>
......
/*
* Copyright (c) 2016 European Space Agency
*
* This file is a custom backend to be used with the ASN1SCC tool.
* It generates an Ada package with iterators that compute all possible values
* of all ASN.1 types.
*
* Licensed under the terms of GNU General Public Licence as published by
* the Free Software Foundation.
*
*/
group ada_iterators;
//delimiters "$", "$"
/* Header of the file */
RootXml(arrsFiles) ::= <<
-- This file was generated automatically by TASTE: DO NOT EDIT
-- Dummy package that is used to "with" the ASN.1 modules
$arrsFiles;separator="\n"$
package ASN1_Ada_Iterators is
end;
>>
/* sFileName is a string with the current file name */
FileXml(sFileName, arrsModules) ::= <<
-- ASN.1 File $sFileName$
$arrsModules;separator="\n"$
>>
ModuleXml(sName, sCName, arrsImportedModules, arrsExpTypes, arrsExpVars, arrsTases, arrsVases) ::=<<
with $sCName$;
use $sCName$;
pragma Unreferenced($sCName$);
>>
ImportedMod(sName, sCName, arrsTypes, arrsVars) ::= ""
TasXml(sName, nLine, nPos, sType, sCName, sAssigOp, sContract) ::= ""
VasXml(sName, nLine, nPos, sType, sValue, sCName) ::= ""
TypeGeneric(nLine, nPos, sSubType) ::= ""
MinMaxType(sName, sMin, sMax, bFixedSize) ::= ""
MinMaxType2(sName, sMin, sMax, bFixedSize) ::= ""
BooleanType () ::= ""
NullType () ::= ""
IntegerType () ::= ""
RealType () ::= ""
BitStringType () ::= ""
OctetStringType () ::= ""
IA5StringType () ::= ""
NumericStringType () ::= ""
AssigOpNormalType () ::= ""
AssigOpSpecialType () ::= ""
EnumItem (sName, sCName, nVal, nLine, nPos, sCID) ::= ""
EnumType(arrsItems) ::= ""
ChoiceChild(sName, sCName, nLine, nPos, sChildContent, sNamePresent ) ::= ""
ChoiceType(arrsChildren) ::= ""
SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::= ""
SequenceType(arrsChildren) ::= ""
SequenceOfType(sMin, sMax, sChild) ::= ""
RefTypeMinMax(sMin, sMax, sName, sModName, sCName, sCModName) ::= ""
RefType(sName, sModName, sCName, sCModName) ::= ""
Contract(sTypePattern, sExpr) ::= ""
TypePatternCommonTypes() ::= ""
TypePatternSequence(sName, sCName, arrsChildren) ::= ""
SequencePatternChild(sName, sCName) ::= ""
ContractExprMinMax(sPattern, sMin, sMax, bFixedSize) ::= ""
ContractExprSize(sPattern, sMin, sMax, bFixedSize) ::= ""
ContractExprSequence(arrsChildren) ::= ""
Print_IntegerValue(nVal) ::= ""
Print_RealValue(dVal) ::= ""
Print_StringValue(v) ::= ""
Print_TrueValue() ::= ""
Print_FalseValue() ::= ""
Print_BitStringValue(v) ::= ""
Print_OctetStringValue(arruOctets) ::= ""
Print_RefValue(sName) ::= ""
Print_SeqOfValue(arrsValues) ::= ""
Print_SeqValue_Child(sName, sChildValue) ::= ""
Print_SeqValue(arrsValues) ::= ""
Print_ChValue(sAltName,sAltValue) ::= ""
Print_NullValue() ::= ""
/*
* Copyright (c) 2016 European Space Agency
*
* This file is a custom backend to be used with the ASN1SCC tool.
* It generates an Ada package with iterators that compute all possible values
* of all ASN.1 types.
*
* Licensed under the terms of GNU General Public Licence as published by
* the Free Software Foundation.
*
*/
group ada_iterators;
//delimiters "$", "$"
/* Header of the file */
RootXml(arrsFiles) ::= <<
-- This file was generated automatically by TASTE: DO NOT EDIT
-- Dummy package that is used to "with" the ASN.1 modules
$arrsFiles;separator="\n"$
package ASN1_Ada_Iterators is
end;
>>
/* sFileName is a string with the current file name */
FileXml(sFileName, arrsModules) ::= <<
-- ASN.1 File $sFileName$
$arrsModules;separator="\n"$
>>
ModuleXml(sName, sCName, arrsImportedModules, arrsExpTypes, arrsExpVars, arrsTases, arrsVases) ::=<<
with $sCName$;
use $sCName$;
pragma Unreferenced($sCName$);
>>
ImportedMod(sName, sCName, arrsTypes, arrsVars) ::= ""
TasXml(sName, nLine, nPos, sType, sCName, sAssigOp, sContract) ::= ""
VasXml(sName, nLine, nPos, sType, sValue, sCName) ::= ""
TypeGeneric(nLine, nPos, sAsnFile, sSubType) ::= ""
MinMaxType(sName, sMin, sMax, bFixedSize) ::= ""
MinMaxType2(sName, sMin, sMax, bFixedSize) ::= ""
BooleanType () ::= ""
NullType () ::= ""
IntegerType () ::= ""
RealType () ::= ""
BitStringType () ::= ""
OctetStringType () ::= ""
IA5StringType () ::= ""
NumericStringType () ::= ""
AssigOpNormalType () ::= ""
AssigOpSpecialType () ::= ""
EnumItem (sName, sCName, nVal, nLine, nPos, sCID) ::= ""
EnumType(arrsItems) ::= ""
ChoiceChild(sName, sCName, nLine, nPos, sChildContent, sNamePresent ) ::= ""
ChoiceType(arrsChildren) ::= ""
SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::= ""
SequenceType(arrsChildren) ::= ""
SequenceOfType(sMin, sMax, sChild, bFixedSize) ::= ""
RefTypeMinMax(sMin, sMax, sName, sModName, sCName, sCModName, bFixedSize) ::= ""
RefType(sName, sModName, sCName, sCModName) ::= ""
Contract(sTypePattern, sExpr) ::= ""
TypePatternCommonTypes() ::= ""
TypePatternSequence(sName, sCName, arrsChildren) ::= ""
SequencePatternChild(sName, sCName) ::= ""
ContractExprMinMax(sPattern, sMin, sMax, bFixedSize) ::= ""
ContractExprSize(sPattern, sMin, sMax, bFixedSize) ::= ""
ContractExprSequence(arrsChildren) ::= ""
Print_IntegerValue(nVal) ::= ""
Print_RealValue(dVal) ::= ""
Print_StringValue(v) ::= ""
Print_TrueValue() ::= ""
Print_FalseValue() ::= ""
Print_BitStringValue(v) ::= ""
Print_OctetStringValue(arruOctets) ::= ""