rtds_B_mapper.py 29.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#
# (C) Semantix Information Technologies.
#
# Semantix Information Technologies is licensing the code of the
# Data Modelling Tools (DMT) in the following dual-license mode:
#
# Commercial Developer License:
#       The DMT Commercial Developer License is the suggested version
# to use for the development of proprietary and/or commercial software.
# This version is for developers/companies who do not want to comply
# with the terms of the GNU Lesser General Public License version 2.1.
#
# GNU LGPL v. 2.1:
#       This version of DMT is the one to use for the development of
# applications, when you are willing to comply with the terms of the
# GNU Lesser General Public License version 2.1.
#
# Note that in both cases, there are no charges (royalties) for the
# generated code.
#
21
'''
22
23
24
25
26
27
28
29
30
This is the code generator for the PragmaDev RTDS code mappers.
This backend is called by aadl2glueC, when an RTDS subprogram
is identified in the input concurrency view.

Implementation notes: Like OG, RTDS is a complex case;
It is used to model asynchronous processes (SDL)...

'''

31
from typing import List
32

33
34
35
36
from ..commonPy.utility import panic
from ..commonPy.asnAST import (
    sourceSequenceLimit, isSequenceVariable, AsnInt, AsnReal, AsnEnumerated,
    AsnBool, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnChoice, AsnOctetString,
37
    AsnBasicNode, AsnNode, AsnSequence, AsnSet, AsnSetOf, AsnSequenceOf)
38
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
39
from ..commonPy.recursiveMapper import RecursiveMapper
40
41
42
43
44
45
46
from .asynchronousTool import ASynchronousToolGlueGenerator

from . import c_B_mapper

isAsynchronous = True


47
# noinspection PyListCreation
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
48
# pylint: disable=no-self-use
49
class FromRTDSToASN1SCC(RecursiveMapper):
50
    def __init__(self) -> None:
51
52
        self.uniqueID = 0

53
    def UniqueID(self) -> int:
54
55
56
        self.uniqueID += 1
        return self.uniqueID

57
    def DecreaseUniqueID(self) -> None:
58
59
        self.uniqueID -= 1

60
    def MapInteger(self, srcSDLVariable: str, destVar: str, _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
61
62
        return ["%s = (asn1SccSint) %s;\n" % (destVar, srcSDLVariable)]

63
    def MapReal(self, srcSDLVariable: str, destVar: str, _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
64
65
        return ["%s = (double)%s;\n" % (destVar, srcSDLVariable)]

66
    def MapBoolean(self, srcSDLVariable: str, destVar: str, _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
67
68
        return ["%s = (%s==TRUE)?0xff:0;\n" % (destVar, srcSDLVariable)]

69
    def MapOctetString(self, srcSDLVariable: str, destVar: str, node: AsnOctetString, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
70
        lines = []  # type: List[str]
71
72
73
74
75
        lines.append("{\n")
        lines.append("    int i;\n")
        lines.append("    for(i=0; i<%s.__length; i++) {\n" % srcSDLVariable)
        lines.append("        %s.arr[i] = %s.__string[i];\n" % (destVar, srcSDLVariable))
        lines.append("    }\n")
76
77
        # for i in xrange(0, node._range[-1]):
        #     lines.append("    placeHolder[%d] = %s[%d];\n" % (i, srcSDLVariable, i))
78
79
80
81
82
        if isSequenceVariable(node):
            lines.append("    %s.nCount = %s.__length;\n" % (destVar, srcSDLVariable))
        lines.append("}\n")
        return lines

83
    def MapEnumerated(self, srcSDLVariable: str, destVar: str, _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
84
85
        return ["%s = %s;\n" % (destVar, srcSDLVariable)]

86
    def MapSequence(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
87
        lines = []  # type: List[str]
88
89
90
91
92
93
94
95
96
97
        for child in node._members:
            lines.extend(
                self.Map(
                    "%s.%s" % (srcSDLVariable, self.CleanName(child[0])),
                    destVar + "." + self.CleanName(child[0]),
                    child[1],
                    leafTypeDict,
                    names))
        return lines

98
    def MapSet(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
99
100
        return self.MapSequence(srcSDLVariable, destVar, node, leafTypeDict, names)  # pragma: nocover

101
    def MapChoice(self, srcSDLVariable: str, destVar: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
102
        lines = []  # type: List[str]
103
104
105
106
        childNo = 0
        for child in node._members:
            childNo += 1
            lines.append("%sif (%s.present == %d) {\n" % (self.maybeElse(childNo), srcSDLVariable, childNo))
107
            lines.extend(
108
                ["    " + x
109
110
111
112
113
114
                 for x in self.Map(
                     "%s.__value.%s" % (srcSDLVariable, self.CleanName(child[0])),
                     destVar + (".u.%s" % self.CleanName(child[0])),
                     child[1],
                     leafTypeDict,
                     names)])
115
116
117
118
            lines.append("    %s.kind = %s;\n" % (destVar, self.CleanName(child[2])))
            lines.append("}\n")
        return lines

119
    def MapSequenceOf(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
120
        lines = []  # type: List[str]
121
122
123
124
        lines.append("{\n")
        uniqueId = self.UniqueID()
        lines.append("    int i%s;\n" % uniqueId)
        lines.append("    for(i%s=0; i%s<%s.length; i%s++) {\n" % (uniqueId, uniqueId, srcSDLVariable, uniqueId))
125
        lines.extend(
126
            ["        " + x
127
128
129
130
131
132
             for x in self.Map(
                 "%s.elements[i%s]" % (srcSDLVariable, uniqueId),
                 "%s.arr[i%s]" % (destVar, uniqueId),
                 node._containedType,
                 leafTypeDict,
                 names)])
133
134
135
136
137
138
139
        lines.append("    }\n")
        if isSequenceVariable(node):
            lines.append("    %s.nCount = %s.length;\n" % (destVar, srcSDLVariable))
        lines.append("}\n")
        self.DecreaseUniqueID()
        return lines

140
    def MapSetOf(self, unused_srcSDLVariable: str, unused_destVar: str, node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes, unused_names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
141
142
143
        panic("The PragmaDev mapper does not support SETOF. Please use SEQUENCEOF instead (%s)" % node.Location())  # pragma: nocover


144
# noinspection PyListCreation
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
145
# pylint: disable=no-self-use
146
class FromRTDSToOSS(RecursiveMapper):
147
    def __init__(self) -> None:
148
149
        self.uniqueID = 0

150
    def UniqueID(self) -> int:
151
152
153
        self.uniqueID += 1
        return self.uniqueID

154
    def DecreaseUniqueID(self) -> None:
155
156
        self.uniqueID -= 1

157
    def MapInteger(self, srcSDLVariable: str, destVar: str, _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
158
159
        return ["%s = %s;\n" % (destVar, srcSDLVariable)]

160
    def MapReal(self, srcSDLVariable: str, destVar: str, _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
161
162
        return ["%s = %s;\n" % (destVar, srcSDLVariable)]

163
    def MapBoolean(self, srcSDLVariable: str, destVar: str, _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
164
165
        return ["%s = (%s==SDL_TRUE)?0xff:0;\n" % (destVar, srcSDLVariable)]

166
    def MapOctetString(self, srcSDLVariable: str, destVar: str, _: AsnOctetString, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
167
        lines = []  # type: List[str]
168
169
170
171
172
173
174
175
176
177
178
179
180
181
        lines.append("{\n")
        lines.append("    int i;\n")
        lines.append("    for(i=0; i<%s.length; i++) {\n" % srcSDLVariable)
        lines.append("        unsigned char value;\n")
        lines.append("        if(%s.cont[i].cont[0]) value |= 128;\n" % srcSDLVariable)
        lines.append("        if(%s.cont[i].cont[1]) value |= 64;\n" % srcSDLVariable)
        lines.append("        if(%s.cont[i].cont[2]) value |= 32;\n" % srcSDLVariable)
        lines.append("        if(%s.cont[i].cont[3]) value |= 16;\n" % srcSDLVariable)
        lines.append("        if(%s.cont[i].cont[4]) value |= 8;\n" % srcSDLVariable)
        lines.append("        if(%s.cont[i].cont[5]) value |= 4;\n" % srcSDLVariable)
        lines.append("        if(%s.cont[i].cont[6]) value |= 2;\n" % srcSDLVariable)
        lines.append("        if(%s.cont[i].cont[7]) value |= 1;\n" % srcSDLVariable)
        lines.append("        %s.value[i] = value;\n" % destVar)
        lines.append("    }\n")
182
183
        # for i in xrange(0, node._range[-1]):
        #     lines.append("    placeHolder[%d] = %s[%d];\n" % (i, srcSDLVariable, i))
184
185
186
187
        lines.append("    %s.length = %s.length;\n" % (destVar, srcSDLVariable))
        lines.append("}\n")
        return lines

188
    def MapEnumerated(self, srcSDLVariable: str, destVar: str, _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
189
190
        return ["%s = %s;\n" % (destVar, srcSDLVariable)]

191
    def MapSequence(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
192
        lines = []  # type: List[str]
193
194
195
196
197
198
199
200
201
202
        for child in node._members:
            lines.extend(
                self.Map(
                    "%s.%s" % (srcSDLVariable, self.CleanName(child[0])),
                    destVar + "." + self.CleanName(child[0]),
                    child[1],
                    leafTypeDict,
                    names))
        return lines

203
    def MapSet(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
204
205
        return self.MapSequence(srcSDLVariable, destVar, node, leafTypeDict, names)  # pragma: nocover

206
    def MapChoice(self, srcSDLVariable: str, destVar: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
207
        lines = []  # type: List[str]
208
209
210
211
        childNo = 0
        for child in node._members:
            childNo += 1
            lines.append("%sif (%s.present == %d) {\n" % (self.maybeElse(childNo), srcSDLVariable, childNo))
212
            lines.extend(
213
                ["    " + x
214
215
216
217
218
219
                 for x in self.Map(
                     "%s.u.u%d.%s" % (srcSDLVariable, childNo, self.CleanName(child[0])),
                     destVar + (".u.%s" % self.CleanName(child[0])),
                     child[1],
                     leafTypeDict,
                     names)])
220
221
222
223
            lines.append("    %s.choice = OSS_%s_chosen;\n" % (destVar, self.CleanName(child[0])))
            lines.append("}\n")
        return lines

224
    def MapSequenceOf(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
225
        lines = []  # type: List[str]
226
227
228
229
        lines.append("{\n")
        uniqueId = self.UniqueID()
        lines.append("    int i%s;\n" % uniqueId)
        lines.append("    for(i%s=0; i%s<%s.length; i%s++) {\n" % (uniqueId, uniqueId, srcSDLVariable, uniqueId))
230
        lines.extend(
231
            ["        " + x
232
233
234
235
236
237
             for x in self.Map(
                 "%s.cont[i%s]" % (srcSDLVariable, uniqueId),
                 "%s.value[i%s]" % (destVar, uniqueId),
                 node._containedType,
                 leafTypeDict,
                 names)])
238
239
240
241
242
243
        lines.append("    }\n")
        lines.append("    %s.count = %s.length;\n" % (destVar, srcSDLVariable))
        lines.append("}\n")
        self.DecreaseUniqueID()
        return lines

244
    def MapSetOf(self, unused_srcSDLVariable: str, unused_destVar: str, node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes, unused_names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
245
246
247
        panic("The PragmaDev mapper does not support SETOF. Please use SEQUENCEOF instead (%s)" % node.Location())  # pragma: nocover


248
# noinspection PyListCreation
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
249
# pylint: disable=no-self-use
250
class FromASN1SCCtoRTDS(RecursiveMapper):
251
    def __init__(self) -> None:
252
253
        self.uniqueID = 0

254
    def UniqueID(self) -> int:
255
256
257
        self.uniqueID += 1
        return self.uniqueID

258
    def DecreaseUniqueID(self) -> None:
259
260
        self.uniqueID -= 1

261
    def MapInteger(self, srcVar: str, dstSDLVariable: str, _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
262
263
        return ["%s = %s;\n" % (dstSDLVariable, srcVar)]

264
    def MapReal(self, srcVar: str, dstSDLVariable: str, _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
265
266
        return ["%s = %s;\n" % (dstSDLVariable, srcVar)]

267
    def MapBoolean(self, srcVar: str, dstSDLVariable: str, _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
268
269
        return ["%s = (%s)?TRUE:FALSE;\n" % (dstSDLVariable, srcVar)]

270
    def MapOctetString(self, srcVar: str, dstSDLVariable: str, node: AsnOctetString, _: AST_Leaftypes, __: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
271
272
        # for i in xrange(0, node._range[-1]):
        #     lines.append("%s[%d] = %s->buf[%d];\n" % (dstSDLVariable, i, srcVar, i))
273
        lines = []  # type: List[str]
274
275
276
277
278
279
280
281
282
283
284
285
286
287
        limit = sourceSequenceLimit(node, srcVar)
        lines.append("{\n")
        lines.append("    int i;\n")
        lines.append("    for(i=0; i<%s; i++) {\n" % limit)
        lines.append("        %s.__string[i] = %s.arr[i];\n" % (dstSDLVariable, srcVar))
        lines.append("    }\n")
        lines.append("    while(i<%d) {\n" % node._range[-1])
        lines.append("        %s.__string[i]=0;\n" % dstSDLVariable)
        lines.append("        i++;\n")
        lines.append("    };\n")
        lines.append("    %s.__length = %s;\n" % (dstSDLVariable, limit))
        lines.append("}\n")
        return lines

288
    def MapEnumerated(self, srcVar: str, dstSDLVariable: str, _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
289
290
        return ["%s = %s;\n" % (dstSDLVariable, srcVar)]

291
    def MapSequence(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
292
        lines = []  # type: List[str]
293
294
295
296
297
298
299
300
301
302
        for child in node._members:
            lines.extend(
                self.Map(
                    srcVar + "." + self.CleanName(child[0]),
                    "%s.%s" % (dstSDLVariable, self.CleanName(child[0])),
                    child[1],
                    leafTypeDict,
                    names))
        return lines

303
    def MapSet(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
304
305
        return self.MapSequence(srcVar, dstSDLVariable, node, leafTypeDict, names)  # pragma: nocover

306
    def MapChoice(self, srcVar: str, dstSDLVariable: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
307
        lines = []  # type: List[str]
308
309
310
311
312
        childNo = 0
        for child in node._members:
            childNo += 1
            lines.append("%sif (%s.kind == %s) {\n" %
                         (self.maybeElse(childNo), srcVar, self.CleanName(child[2])))
313
            lines.extend(
314
                ['    ' + x
315
316
317
318
319
320
                 for x in self.Map(
                     srcVar + ".u." + self.CleanName(child[0]),
                     "%s.__value.%s" % (dstSDLVariable, self.CleanName(child[0])),
                     child[1],
                     leafTypeDict,
                     names)])
321
322
323
324
            lines.append("    %s.present = %d;\n" % (dstSDLVariable, childNo))
            lines.append("}\n")
        return lines

325
    def MapSequenceOf(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
326
        lines = []  # type: List[str]
327
328
329
330
331
332
        lines.append("{\n")
        uniqueId = self.UniqueID()
        limit = sourceSequenceLimit(node, srcVar)
        lines.append("    int i%s;\n" % uniqueId)
        lines.append("    %s.length = %s;\n" % (dstSDLVariable, limit))
        lines.append("    for(i%s=0; i%s<%s; i%s++) {\n" % (uniqueId, uniqueId, limit, uniqueId))
333
        lines.extend(
334
            ["        " + x
335
336
337
338
339
340
             for x in self.Map(
                 srcVar + ".arr[i%s]" % uniqueId,
                 "%s.elements[i%s]" % (dstSDLVariable, uniqueId),
                 node._containedType,
                 leafTypeDict,
                 names)])
341
342
343
344
345
        lines.append("    }\n")
        lines.append("}\n")
        self.DecreaseUniqueID()
        return lines

346
    def MapSetOf(self, unused_srcVar: str, unused_dstSDLVariable: str, node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes, unused_names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
347
348
349
        panic("The PragmaDev mapper does not support SETOF. Please use SEQUENCEOF instead (%s)" % node.Location())  # pragma: nocover


350
# noinspection PyListCreation
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
351
# pylint: disable=no-self-use
352
class FromOSStoRTDS(RecursiveMapper):
353
    def __init__(self) -> None:
354
355
        self.uniqueID = 0

356
    def UniqueID(self) -> int:
357
358
359
        self.uniqueID += 1
        return self.uniqueID

360
    def DecreaseUniqueID(self) -> None:
361
362
        self.uniqueID -= 1

363
    def MapInteger(self, srcVar: str, dstSDLVariable: str, _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
364
365
        return ["%s = %s;\n" % (dstSDLVariable, srcVar)]

366
    def MapReal(self, srcVar: str, dstSDLVariable: str, _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
367
368
        return ["%s = %s;\n" % (dstSDLVariable, srcVar)]

369
    def MapBoolean(self, srcVar: str, dstSDLVariable: str, _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
370
371
        return ["%s = (%s)?SDL_TRUE:SDL_FALSE;\n" % (dstSDLVariable, srcVar)]

372
    def MapOctetString(self, srcVar: str, dstSDLVariable: str, node: AsnOctetString, _: AST_Leaftypes, __: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
373
        lines = []  # type: List[str]
374
375
        # for i in xrange(0, node._range[-1]):
        #     lines.append("%s[%d] = %s->buf[%d];\n" % (dstSDLVariable, i, srcVar, i))
376
377
378
379
        lines.append("{\n")
        lines.append("    int i;\n")
        lines.append("    for(i=0; i<%s.length; i++) {\n" % srcVar)
        lines.append("        unsigned char value = %s.value[i];\n" % srcVar)
380
381
382
383
384
385
386
387
388
        lines.append("        %s.cont[i].cont[0] = value & 128;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[1] = value & 64;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[2] = value & 32;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[3] = value & 16;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[4] = value & 8;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[5] = value & 4;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[6] = value & 2;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[7] = value & 1;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].length = 8;\n" % dstSDLVariable)
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
        lines.append("    }\n")
        lines.append("    while(i<%d) {\n" % node._range[-1])
        lines.append("        %s.cont[i].cont[0]=0;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[1]=0;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[2]=0;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[3]=0;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[4]=0;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[5]=0;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[6]=0;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[7]=0;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].length=0;\n" % dstSDLVariable)
        lines.append("        i++;\n")
        lines.append("    };\n")
        lines.append("    %s.length = %s.length;\n" % (dstSDLVariable, srcVar))
        lines.append("}\n")
        return lines

406
    def MapEnumerated(self, srcVar: str, dstSDLVariable: str, _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
407
408
        return ["%s = %s;\n" % (dstSDLVariable, srcVar)]

409
    def MapSequence(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
410
        lines = []  # type: List[str]
411
412
413
414
415
416
417
418
419
420
        for child in node._members:
            lines.extend(
                self.Map(
                    srcVar + "." + self.CleanName(child[0]),
                    "%s.%s" % (dstSDLVariable, self.CleanName(child[0])),
                    child[1],
                    leafTypeDict,
                    names))
        return lines

421
    def MapSet(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
422
423
        return self.MapSequence(srcVar, dstSDLVariable, node, leafTypeDict, names)  # pragma: nocover

424
    def MapChoice(self, srcVar: str, dstSDLVariable: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
425
        lines = []  # type: List[str]
426
427
428
429
430
        childNo = 0
        for child in node._members:
            childNo += 1
            lines.append("%sif (%s.choice == OSS_%s_chosen) {\n" %
                         (self.maybeElse(childNo), srcVar, self.CleanName(child[0])))
431
            lines.extend(
432
                ['    ' + x
433
434
435
436
437
438
                 for x in self.Map(
                     srcVar + ".u." + self.CleanName(child[0]),
                     "%s.u.u%d.%s" % (dstSDLVariable, childNo, self.CleanName(child[0])),
                     child[1],
                     leafTypeDict,
                     names)])
439
440
441
442
            lines.append("    %s.present = %d;\n" % (dstSDLVariable, childNo))
            lines.append("}\n")
        return lines

443
    def MapSequenceOf(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
444
        lines = []  # type: List[str]
445
446
447
448
449
        lines.append("{\n")
        uniqueId = self.UniqueID()
        lines.append("    int i%s;\n" % uniqueId)
        lines.append("    %s.length = %s.count;\n" % (dstSDLVariable, srcVar))
        lines.append("    for(i%s=0; i%s<%s.count; i%s++) {\n" % (uniqueId, uniqueId, srcVar, uniqueId))
450
        lines.extend(
451
            ["        " + x
452
453
454
455
456
457
             for x in self.Map(
                 srcVar + ".value[i%s]" % uniqueId,
                 "%s.cont[i%s]" % (dstSDLVariable, uniqueId),
                 node._containedType,
                 leafTypeDict,
                 names)])
458
459
460
461
462
        lines.append("    }\n")
        lines.append("}\n")
        self.DecreaseUniqueID()
        return lines

463
    def MapSetOf(self, unused_srcVar: str, unused_dstSDLVariable: str, node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes, unused_names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
464
465
466
467
        panic("The PragmaDev mapper does not support SETOF. Please use SEQUENCEOF instead (%s)" % node.Location())  # pragma: nocover


class RTDS_GlueGenerator(ASynchronousToolGlueGenerator):
468
    def __init__(self) -> None:
469
470
471
472
473
474
        ASynchronousToolGlueGenerator.__init__(self)
        self.FromRTDSToASN1SCC = FromRTDSToASN1SCC()
        self.FromRTDSToOSS = FromRTDSToOSS()
        self.FromASN1SCCtoRTDS = FromASN1SCCtoRTDS()
        self.FromOSStoRTDS = FromOSStoRTDS()

475
    def Version(self) -> None:
476
477
        print("Code generator: " + "$Id: rtds_B_mapper.py 2390 2012-07-19 12:39:17Z ttsiodras $")

478
    def HeadersOnStartup(self, unused_asnFile: str, unused_outputDir: str, unused_maybeFVname: str) -> None:
479
480
481
482
483
        self.C_HeaderFile.write("#include <assert.h>\n\n")
        self.C_HeaderFile.write("#include \"%s.h\"\n" % self.asn_name)
        self.C_HeaderFile.write("#include \"RTDS_gen.h\"\n\n")
        self.C_HeaderFile.write("#include \"RTDSdataView.h\"\n\n")

484
    def Encoder(self, nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup, encoding: str) -> None:
485
486
487
488
489
        if encoding.lower() in ["uper", "acn"]:
            return
        fileOutHeader = self.C_HeaderFile
        fileOutSource = self.C_SourceFile
        isPointer = True
490
        if isinstance(node, (AsnBasicNode, AsnEnumerated)):
491
            isPointer = False
492
        cleaned = self.CleanNameAsToolWants(nodeTypename)
493
494
        fileOutHeader.write(
            "void Convert_%s_from_RTDS_to_ASN1SCC(asn1Scc%s *ptrASN1SCC, %s %sRTDS);\n" %
495
            (cleaned, cleaned, cleaned, "*" if isPointer else ""))
496
497
        fileOutSource.write(
            "void Convert_%s_from_RTDS_to_ASN1SCC(asn1Scc%s *ptrASN1SCC, %s %sRTDS)\n{\n" %
498
            (cleaned, cleaned, cleaned, "*" if isPointer else ""))
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515

        # Write the mapping code for the message
        if self.useOSS:
            lines = self.FromRTDSToOSS.Map(
                "(%sRTDS)" % ("*" if isPointer else ""),
                "(*ptrASN1SCC)",
                node,
                leafTypeDict,
                names)
        else:
            lines = self.FromRTDSToASN1SCC.Map(
                "(%sRTDS)" % ("*" if isPointer else ""),
                "(*ptrASN1SCC)",
                node,
                leafTypeDict,
                names)

516
        lines = ["    " + x.rstrip() for x in lines]
517
518
519
        fileOutSource.write("\n".join(lines))
        fileOutSource.write("\n}\n\n")

520
    def Decoder(self, nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup, encoding: str) -> None:
521
522
523
524
        if encoding.lower() in ["uper", "acn"]:
            return
        fileOutHeader = self.C_HeaderFile
        fileOutSource = self.C_SourceFile
525
        cleaned = self.CleanNameAsToolWants(nodeTypename)
526
527
        fileOutHeader.write(
            "void Convert_%s_from_ASN1SCC_to_RTDS(%s *ptrRTDS, const asn1Scc%s *ptrASN1SCC);\n" %
528
            (cleaned, cleaned, cleaned))
529
530
531

        fileOutSource.write(
            "void Convert_%s_from_ASN1SCC_to_RTDS(%s *ptrRTDS, const asn1Scc%s *ptrASN1SCC)\n{\n" %
532
            (cleaned, cleaned, cleaned))
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548

        if self.useOSS:
            lines = self.FromOSStoRTDS.Map(
                "(*ptrASN1SCC)",
                "(*ptrRTDS)",
                node,
                leafTypeDict,
                names)
        else:
            lines = self.FromASN1SCCtoRTDS.Map(
                "(*ptrASN1SCC)",
                "(*ptrRTDS)",
                node,
                leafTypeDict,
                names)

549
        lines = ["    " + x.rstrip() for x in lines]
550
551
552
553
        fileOutSource.write("\n".join(lines))
        fileOutSource.write("\n}\n\n")


554
555
556
557
rtdsBackend: RTDS_GlueGenerator
cBackend: c_B_mapper.C_GlueGenerator


558
def OnStartup(modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
559
560
561
562
563
564
565
566
    global rtdsBackend
    rtdsBackend = RTDS_GlueGenerator()
    rtdsBackend.OnStartup(modelingLanguage, asnFile, outputDir, maybeFVname, useOSS)
    global cBackend
    cBackend = c_B_mapper.C_GlueGenerator()
    cBackend.OnStartup("C", asnFile, outputDir, maybeFVname, useOSS)


567
def OnBasic(nodeTypename: str, node: AsnBasicNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
568
569
570
571
    rtdsBackend.OnBasic(nodeTypename, node, leafTypeDict, names)
    cBackend.OnBasic(nodeTypename, node, leafTypeDict, names)


572
def OnSequence(nodeTypename: str, node: AsnSequence, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
573
574
575
576
    rtdsBackend.OnSequence(nodeTypename, node, leafTypeDict, names)
    cBackend.OnSequence(nodeTypename, node, leafTypeDict, names)


577
def OnSet(nodeTypename: str, node: AsnSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
578
579
580
581
    rtdsBackend.OnSet(nodeTypename, node, leafTypeDict, names)  # pragma: nocover
    cBackend.OnSet(nodeTypename, node, leafTypeDict, names)  # pragma: nocover


582
def OnEnumerated(nodeTypename: str, node: AsnEnumerated, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
583
584
585
586
    rtdsBackend.OnEnumerated(nodeTypename, node, leafTypeDict, names)
    cBackend.OnEnumerated(nodeTypename, node, leafTypeDict, names)


587
def OnSequenceOf(nodeTypename: str, node: AsnSequenceOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
588
589
590
591
    rtdsBackend.OnSequenceOf(nodeTypename, node, leafTypeDict, names)
    cBackend.OnSequenceOf(nodeTypename, node, leafTypeDict, names)


592
def OnSetOf(nodeTypename: str, node: AsnSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
593
594
595
596
    rtdsBackend.OnSetOf(nodeTypename, node, leafTypeDict, names)  # pragma: nocover
    cBackend.OnSetOf(nodeTypename, node, leafTypeDict, names)  # pragma: nocover


597
def OnChoice(nodeTypename: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
598
599
600
601
    rtdsBackend.OnChoice(nodeTypename, node, leafTypeDict, names)
    cBackend.OnChoice(nodeTypename, node, leafTypeDict, names)


602
def OnShutdown(modelingLanguage: str, asnFile: str, maybeFVname: str) -> None:
603
604
    rtdsBackend.OnShutdown(modelingLanguage, asnFile, maybeFVname)
    cBackend.OnShutdown("C", asnFile, maybeFVname)