ada_iterators-iterators-ads.stg 6.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
/*
* 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

with ASN1_Ada_Iterators,
     ASN1_Iterators.Generic_Integer,
     ASN1_Iterators.Generic_SeqOf,
     Interfaces,
     Ada.Strings.Unbounded;

pragma Unreferenced (ASN1_Ada_Iterators);

use ASN1_Iterators,
    Interfaces;

package ASN1_Ada_Iterators.iterators is
    package Str renames Ada.Strings.Unbounded;
    use Str;

    $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$
--  List of exported types: $arrsExpTypes:{x|"$x$"};separator=", "$

--  Imported modules: 
$arrsImportedModules:{x|with $x$;};separator="\n"$
--  End imported modules --

$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) ::= <<
--  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;
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, bIsUnsigned, bIsRealType) ::= <<
Generic_$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);
>>


/* 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 () ::= "Integer"
RealType () ::= "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) ::= <<
Generic_SeqOf (Min => $sMin$, Max => $sMax$, Basic => $sChild$_Pkg.It);
    use $sChild$_Pkg;
    procedure To_ASN1(from: Inner.MySeqOf; to: out ASN1_Type);
>>


/* 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) ::= ""
TypePatternCommonTypes() ::= ""
TypePatternSequence(sName, sCName, arrsChildren) ::= ""
SequencePatternChild(sName, sCName) ::= ""
ContractExprMinMax(sPattern, sMin, sMax, bFixedSize) ::= ""
ContractExprSize(sPattern, sMin, sMax, bFixedSize) ::= ""
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() ::= ""