forked from ateleris/asn1scc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvdm.stg
228 lines (173 loc) · 6.13 KB
/
vdm.stg
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
group vdm;
//delimiters "$", "$"
/* VDM (Vienna Development Method) backend for ASN.1 data types
(c) 2015 European Space Agency
*/
/* Header of the file */
RootXml(arrsFiles) ::= <<
$arrsFiles;separator="\n"$
>>
/* sFileName is a string with the current file name */
FileXml(sFileName, arrsModules) ::= <<
$arrsModules;separator="\n"$
>>
/* Per ASN.1 module. you can use:
- the module name (sName, sCName is the same but using underscores)
- the list of types that are exported by this module.
Example of use:
$arrsExpTypes:{x|"$x$"};separator=", "$
- the list of variables that are exported by this module (arrsExpVars)
- the list of imported modules (generated by template ImportedMod)
Then you can use the list of types and variables defined in this module
arrsTases is an array of strings generated by template TasXml
arrsVases is an array of strings generated by template VasXml
*/
ModuleXml(sName, sCName, arrsImportedModules, arrsExpTypes, arrsExpVars, arrsTases, arrsVases) ::= <<
class $sCName$
types
$arrsTases;separator=";\n\n"$
values
$arrsVases;separator=";\n\n"$
end $sCName$
>>
/* 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.
Use sCName which is the type name using underscores in place of dashes
*/
TasXml(sName, nLine, nPos, sType, sCName, sAssignOp, sContract) ::= <<
public $sCName$ $sAssignOp$ $sType$$sContract$
>>
/* A single Variable Assignment */
VasXml(sName, nLine, nPos, sType, sValue, sCName) ::= <<
public $sCName$ : $sType$ = $sValue$
>>
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 */
MinMaxType(sName, sMin, sMax, bFixedSize) ::= <<
$sName$
>>
/* String types with size constraint: Bitstring, Octetstring, Ia5String,
NumericString */
MinMaxType2(sName, sMin, sMax, bFixedSize) ::= <<
$sName$
>>
BooleanType () ::= "bool"
NullType () ::= "nil"
IntegerType () ::= "int"
RealType () ::= "real"
BitStringType () ::= "seq of bool"
/* Octet string in VDM mapped to sequence of characters */
OctetStringType () ::= "seq of char"
IA5StringType () ::= "seq of char"
NumericStringType () ::= "seq of char"
AssignOpNormalType () ::= "="
AssignOpSpecialType () ::= "::"
/* Enumerated item, note the difference between sName and sCID:
sName is the enumerated name given in the input type, e.g. 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) ::= <<
<$sCID$>
>>
/* Enumerated type: arrsItems is an array of EnumItem */
EnumType(arrsItems) ::= <<
$arrsItems;separator=" | "$
>>
/* 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_a is sCName
choice-b Type-of-B,
...
}
sNamePresent is an unambiguous name to access the field
*/
ChoiceChild(sName, sCName, nLine, nPos, sChildContent, sNamePresent ) ::= <<
$sChildContent$
>>
/* Full choice type: in VDM, should be <Type-of-A> | <Type-of-B> | ... */
ChoiceType(arrsChildren) ::= <<
$arrsChildren;separator=" | "$
>>
/* Sequence (record) field. May be optional and may have a default value */
SequenceChild(sName, sCName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::= <<
$sCName$ : $sChildContent$
>>
/* Full sequence (record) type */
SequenceType(arrsChildren) ::= <<
$arrsChildren;separator="\n"$
>>
/* Sequence of (array) */
SequenceOfType(sMin, sMax, sChild) ::= <<
seq of $sChild$
>>
/* Reference to another type, with Min/Max subtype
Could be in a different module */
RefTypeMinMax(sMin, sMax, sName, sModName, sCName, sCModName) ::= <<
$if(sCModName)$$sCModName$`$endif$$sCName$
>>
/* Reference to another type */
RefType(sName, sModName, sCName, sCModName) ::= <<
$if(sCModName)$$sCModName$`$endif$$sCName$
>>
/* VDM allows declaration of constraints on types */
Contract(sTypePattern, sExpr) ::= <<
$if(sTypePattern)$
$if(sExpr)$
inv $sTypePattern$ ==
$sExpr$
$endif$
$endif$
>>
/* Type pattern is used for pattern matching of the contract. In VDM it maps
to an instance of the type, e.g:
MyType = nat
inv inst >= 10 and inst <= 100 -- inst is the type pattern
*/
TypePatternCommonTypes() ::= "x"
/* Records have a more complex pattern in VDM: mk_Type(field1, ...) */
TypePatternSequence(sName, sCName, arrsChildren) ::= <<
mk_$sCName$($arrsChildren;separator=", "$)
>>
/* Name used in the Sequence pattern to identify field names */
SequencePatternChild(sName, sCName) ::= "$sCName$"
ContractExprMinMax(sPattern, sMin, sMax, bFixedSize) ::= <<
$sPattern$ >= $sMin$ and $sPattern$ <= $sMax$
>>
ContractExprSize(sPattern, sMin, sMax, bFixedSize) ::= <<
$if(bFixedSize)$
len $sPattern$ = $sMin$
$else$
len $sPattern$ >= $sMin$ and len $sPattern$ <= $sMax$
$endif$
>>
ContractExprSequence(arrsChildren) ::= <<
$arrsChildren;separator=" and "$
>>
/* Print Values */
Print_IntegerValue(nVal) ::= "$nVal$"
Print_RealValue(dVal) ::= "$dVal$"
Print_StringValue(v) ::= <<"$v$">>
Print_TrueValue() ::= "true"
Print_FalseValue() ::= "false"
Print_BitStringValue(v) ::= "$v$"
Print_OctetStringValue(arruOctets) ::= <<'$arruOctets:{b|<b;format="X2">}$>>
Print_RefValue(sName) ::= "<$sName$>"
Print_SeqOfValue(arrsValues) ::= <<[$arrsValues; separator=", "$]>>
Print_SeqValue_Child(sName, sChildValue) ::= "undefined"
Print_SeqValue(arrsValues) ::= "undefined"
Print_ChValue(sAltName,sAltValue) ::= "$sAltValue$"
Print_NullValue() ::= "nil"