sdl_B_mapper.py 43.4 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
#
# (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.
#
'''
This is the code generator for the ObjectGeode code mappers.
This backend is called by aadl2glueC, when an OG subprogram
is identified in the input concurrency view.

All the ASSERT supported encodings are handled by this code
in the form of generated C macros:

  DECLARE_Typename
  DEFINE_Typename
  ENCODE_UPER_Typename     (uses Semantix's asn1scc)
  ENCODE_ACN_Typename     (uses Semantix's asn1scc)
  ENCODE_NATIVE_Typename   (uses memory dumps)
  DECODE_UPER_Typename     (uses Semantix's asn1scc)
  DECODE_ACN_Typename     (uses Semantix's asn1scc)
  DECODE_NATIVE_Typename   (uses memory dumps)

The macros are called from the wrapping layer, created by
Maxime Perottin's buildSupport.

Implementation notes: OG is by far the most complex case;
It is used to model asynchronous processes (SDL)...

The following are done by the buildSupport prior to this backend:

vm_if.c :

 For each Provided Interface which is provided by the modeled APLC,
 a "bridge" function must be created inside this file. This function
 will be in one of two forms:
 (a) if the PI has no associated PARAMETER with it, then this function
     is simply doing
     (I)   G2S_OUTPUT(...);
     (II)  sdl_loop_FVNAME();

 (b) if the PI has an associated PARAMETER with it, then this function
     must
     (I)   decode the ASN.1 message (incoming arguments: pointer,length)
     (II)  place the decoded values in the appropriate ObjectGeode generated
           global variable (for this PI)
     (III) G2S_OUTPUT(...);
     (IV)  sdl_loop_FVNAME();

hpostdef.h :

  OG-related definitions: for each type used by this APLC, a call to

    DEFINE_ASN1TYPENAME(name_of_variable)

  must be issued, to reserve space for the variable. The macro knows
  (by way of this code generator) what size to reserve to accomodate
  the maximum configuration of this message.

  Also, for each Required Interface used by the modeled APLC, this header
  file must also declare a C MACRO:
         #define riname(param1, param2, ...)
  which will
     (I)   encode all the input data from the input params, via the
           ENCODE_ macros, into the reserved spaces (the DEFINE_ASN1TYPENAME
           ones)
     (II)  call the vm callback to access the RI (vm_fvname_riname)
     (III) decode all the output data from the output params, via the
           DECODE_ macros.
  This MACRO will be called by the ObjectGeode generated code whenever the
  RI is to be called.

hpredef.h :

 Contains the prototypes (extern declarations) of the vm callbacks.
'''

92
from typing import Set, List  # NOQA pylint: disable=unused-import
93

94
95
96
97
from ..commonPy.asnAST import (
    isSequenceVariable, sourceSequenceLimit,
    AsnInt, AsnBool, AsnReal, AsnEnumerated, AsnNode, AsnOctetString,
    AsnSequenceOrSet, AsnSequenceOrSetOf, AsnChoice)
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
98
from ..commonPy.asnParser import Typename, AST_Lookup, AST_Leaftypes  # NOQA pylint: disable=unused-import
99

100
from ..commonPy.recursiveMapper import RecursiveMapper
101
102
103
104
105
106
from .asynchronousTool import ASynchronousToolGlueGenerator

isAsynchronous = True
ogBackend = None


107
# noinspection PyListCreation
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
108
# pylint: disable=no-self-use
109
class FromObjectGeodeToASN1SCC(RecursiveMapper):
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
110
    def __init__(self) -> None:
111
112
        self.uniqueID = 0

Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
113
    def UniqueID(self) -> int:
114
115
116
        self.uniqueID += 1
        return self.uniqueID

Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
117
    def DecreaseUniqueID(self) -> None:
118
119
        self.uniqueID -= 1

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

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

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

129
    def MapOctetString(self, srcSDLVariable: str, destVar: str, node: AsnOctetString, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
130
        lines = []  # type: List[str]
131
132
133
134
135
136
137
138
139
140
141
142
143
144
        lines.append("{\n")
        lines.append("    int i;\n")
        lines.append("    for(i=0; i<%s.length; i++) {\n" % srcSDLVariable)
        lines.append("        unsigned char value = 0;\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.arr[i] = value;\n" % destVar)
        lines.append("    }\n")
145
146
        # for i in xrange(0, node._range[-1]):
        #     lines.append("    placeHolder[%d] = %s[%d];\n" % (i, srcSDLVariable, i))
147
148
149
150
151
        if isSequenceVariable(node):
            lines.append("    %s.nCount = %s.length;\n" % (destVar, srcSDLVariable))
        lines.append("}\n")
        return lines

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

155
    def MapSequence(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
156
        lines = []  # type: List[str]
157
158
159
160
161
162
163
164
165
166
        for child in node._members:
            lines.extend(
                self.Map(
                    "%s.fd_%s" % (srcSDLVariable, self.CleanName(child[0]).lower()),
                    destVar + "." + self.CleanName(child[0]),
                    child[1],
                    leafTypeDict,
                    names))
        return lines

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

170
    def MapChoice(self, srcSDLVariable: str, destVar: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
171
        lines = []  # type: List[str]
172
173
174
175
        childNo = 0
        for child in node._members:
            childNo += 1
            lines.append("%sif (%s.present == %d) {\n" % (self.maybeElse(childNo), srcSDLVariable, childNo))
176
            lines.extend(
177
                ["    " + x
178
179
180
181
182
183
                 for x in self.Map(
                     "%s.u.u%d.fd_%s" % (srcSDLVariable, childNo, self.CleanName(child[0]).lower()),
                     destVar + (".u.%s" % self.CleanName(child[0])),
                     child[1],
                     leafTypeDict,
                     names)])
184
185
186
187
            lines.append("    %s.kind = %s;\n" % (destVar, self.CleanName(child[2])))
            lines.append("}\n")
        return lines

188
    def MapSequenceOf(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
189
        lines = []  # type: List[str]
190
191
192
193
        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))
194
        lines.extend(
195
            ["        " + x
196
197
198
199
200
201
             for x in self.Map(
                 "%s.cont[i%s]" % (srcSDLVariable, uniqueId),
                 "%s.arr[i%s]" % (destVar, uniqueId),
                 node._containedType,
                 leafTypeDict,
                 names)])
202
203
204
205
206
207
208
        lines.append("    }\n")
        if isSequenceVariable(node):
            lines.append("    %s.nCount = %s.length;\n" % (destVar, srcSDLVariable))
        lines.append("}\n")
        self.DecreaseUniqueID()
        return lines

209
    def MapSetOf(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
210
211
212
        return self.MapSequenceOf(srcSDLVariable, destVar, node, leafTypeDict, names)  # pragma: nocover


213
# noinspection PyListCreation
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
214
# pylint: disable=no-self-use
215
class FromObjectGeodeToOSS(RecursiveMapper):
216
    def __init__(self) -> None:
217
218
        self.uniqueID = 0

219
    def UniqueID(self) -> int:
220
221
222
        self.uniqueID += 1
        return self.uniqueID

223
    def DecreaseUniqueID(self) -> None:
224
225
        self.uniqueID -= 1

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

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

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

235
    def MapOctetString(self, srcSDLVariable: str, destVar: str, _: AsnOctetString, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
236
        lines = []  # type: List[str]
237
238
239
240
241
242
243
244
245
246
247
248
249
250
        lines.append("{\n")
        lines.append("    int i;\n")
        lines.append("    for(i=0; i<%s.length; i++) {\n" % srcSDLVariable)
        lines.append("        unsigned char value = 0;\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")
251
252
        # for i in xrange(0, node._range[-1]):
        #     lines.append("    placeHolder[%d] = %s[%d];\n" % (i, srcSDLVariable, i))
253
254
255
256
        lines.append("    %s.length = %s.length;\n" % (destVar, srcSDLVariable))
        lines.append("}\n")
        return lines

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

260
    def MapSequence(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
261
        lines = []  # type: List[str]
262
263
264
265
266
267
268
269
270
271
        for child in node._members:
            lines.extend(
                self.Map(
                    "%s.fd_%s" % (srcSDLVariable, self.CleanName(child[0]).lower()),
                    destVar + "." + self.CleanName(child[0]),
                    child[1],
                    leafTypeDict,
                    names))
        return lines

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

275
    def MapChoice(self, srcSDLVariable: str, destVar: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
276
        lines = []  # type: List[str]
277
278
279
280
        childNo = 0
        for child in node._members:
            childNo += 1
            lines.append("%sif (%s.present == %d) {\n" % (self.maybeElse(childNo), srcSDLVariable, childNo))
281
            lines.extend(
282
                ["    " + x
283
284
285
286
287
288
                 for x in self.Map(
                     "%s.u.u%d.fd_%s" % (srcSDLVariable, childNo, self.CleanName(child[0]).lower()),
                     destVar + (".u.%s" % self.CleanName(child[0])),
                     child[1],
                     leafTypeDict,
                     names)])
289
290
291
292
            lines.append("    %s.choice = OSS_%s_chosen;\n" % (destVar, self.CleanName(child[0])))
            lines.append("}\n")
        return lines

293
    def MapSequenceOf(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
294
        lines = []  # type: List[str]
295
296
297
298
        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))
299
        lines.extend(
300
            ["        " + x
301
302
303
304
305
306
             for x in self.Map(
                 "%s.cont[i%s]" % (srcSDLVariable, uniqueId),
                 "%s.value[i%s]" % (destVar, uniqueId),
                 node._containedType,
                 leafTypeDict,
                 names)])
307
308
309
310
311
312
        lines.append("    }\n")
        lines.append("    %s.count = %s.length;\n" % (destVar, srcSDLVariable))
        lines.append("}\n")
        self.DecreaseUniqueID()
        return lines

313
    def MapSetOf(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
314
315
316
        return self.MapSequenceOf(srcSDLVariable, destVar, node, leafTypeDict, names)  # pragma: nocover


317
# noinspection PyListCreation
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
318
# pylint: disable=no-self-use
319
class FromASN1SCCtoObjectGeode(RecursiveMapper):
320
    def __init__(self) -> None:
321
322
        self.uniqueID = 0

323
    def UniqueID(self) -> int:
324
325
326
        self.uniqueID += 1
        return self.uniqueID

327
    def DecreaseUniqueID(self) -> None:
328
329
        self.uniqueID -= 1

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

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

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

339
    def MapOctetString(self, srcVar: str, dstSDLVariable: str, node: AsnOctetString, _: AST_Leaftypes, __: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
340
341
        # for i in xrange(0, node._range[-1]):
        #     lines.append("%s[%d] = %s->buf[%d];\n" % (dstSDLVariable, i, srcVar, i))
342
        lines = []  # type: List[str]
343
344
345
346
347
        limit = sourceSequenceLimit(node, srcVar)
        lines.append("{\n")
        lines.append("    int i;\n")
        lines.append("    for(i=0; i<%s; i++) {\n" % limit)
        lines.append("        unsigned char value = %s.arr[i];\n" % srcVar)
348
349
350
351
352
353
354
355
356
        lines.append("        %s.cont[i].cont[0] = (value & 128) >> 7;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[1] = (value & 64) >> 6;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[2] = (value & 32) >> 5;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[3] = (value & 16) >> 4;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[4] = (value & 8) >> 3;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[5] = (value & 4) >> 2;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[6] = (value & 2) >> 1;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].cont[7] = value & 1;\n" % dstSDLVariable)
        lines.append("        %s.cont[i].length = 8;\n" % dstSDLVariable)
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
        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;\n" % (dstSDLVariable, limit))
        lines.append("}\n")
        return lines

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

377
    def MapSequence(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
378
        lines = []  # type: List[str]
379
380
381
382
383
384
385
386
387
388
        for child in node._members:
            lines.extend(
                self.Map(
                    srcVar + "." + self.CleanName(child[0]),
                    "%s.fd_%s" % (dstSDLVariable, self.CleanName(child[0]).lower()),
                    child[1],
                    leafTypeDict,
                    names))
        return lines

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

392
    def MapChoice(self, srcVar: str, dstSDLVariable: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
393
        lines = []  # type: List[str]
394
395
396
397
398
        childNo = 0
        for child in node._members:
            childNo += 1
            lines.append("%sif (%s.kind == %s) {\n" %
                         (self.maybeElse(childNo), srcVar, self.CleanName(child[2])))
399
            lines.extend(
400
                ['    ' + x
401
402
403
404
405
406
                 for x in self.Map(
                     srcVar + ".u." + self.CleanName(child[0]),
                     "%s.u.u%d.fd_%s" % (dstSDLVariable, childNo, self.CleanName(child[0]).lower()),
                     child[1],
                     leafTypeDict,
                     names)])
407
408
409
410
            lines.append("    %s.present = %d;\n" % (dstSDLVariable, childNo))
            lines.append("}\n")
        return lines

411
    def MapSequenceOf(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
412
        lines = []  # type: List[str]
413
414
415
416
417
418
        lines.append("{\n")
        uniqueId = self.UniqueID()
        lines.append("    int i%s;\n" % uniqueId)
        limit = sourceSequenceLimit(node, srcVar)
        lines.append("    %s.length = %s;\n" % (dstSDLVariable, limit))
        lines.append("    for(i%s=0; i%s<%s; i%s++) {\n" % (uniqueId, uniqueId, limit, uniqueId))
419
        lines.extend(
420
            ["        " + x
421
422
423
424
425
426
             for x in self.Map(
                 srcVar + ".arr[i%s]" % uniqueId,
                 "%s.cont[i%s]" % (dstSDLVariable, uniqueId),
                 node._containedType,
                 leafTypeDict,
                 names)])
427
428
429
430
431
        lines.append("    }\n")
        lines.append("}\n")
        self.DecreaseUniqueID()
        return lines

432
    def MapSetOf(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
433
434
435
        return self.MapSequenceOf(srcVar, dstSDLVariable, node, leafTypeDict, names)  # pragma: nocover


436
# noinspection PyListCreation
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
437
# pylint: disable=no-self-use
438
class FromOSStoObjectGeode(RecursiveMapper):
439
    def __init__(self) -> None:
440
441
        self.uniqueID = 0

442
    def UniqueID(self) -> int:
443
444
445
        self.uniqueID += 1
        return self.uniqueID

446
    def DecreaseUniqueID(self) -> None:
447
448
        self.uniqueID -= 1

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

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

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

458
    def MapOctetString(self, srcVar: str, dstSDLVariable: str, node: AsnOctetString, _: AST_Leaftypes, __: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
459
        lines = []  # type: List[str]
460
461
        # for i in xrange(0, node._range[-1]):
        #     lines.append("%s[%d] = %s->buf[%d];\n" % (dstSDLVariable, i, srcVar, i))
462
463
464
465
        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)
466
467
468
469
470
471
472
473
474
        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)
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
        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

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

495
    def MapSequence(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
496
        lines = []  # type: List[str]
497
498
499
500
501
502
503
504
505
506
        for child in node._members:
            lines.extend(
                self.Map(
                    srcVar + "." + self.CleanName(child[0]),
                    "%s.fd_%s" % (dstSDLVariable, self.CleanName(child[0]).lower()),
                    child[1],
                    leafTypeDict,
                    names))
        return lines

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

510
    def MapChoice(self, srcVar: str, dstSDLVariable: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
511
        lines = []  # type: List[str]
512
513
514
515
516
        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])))
517
            lines.extend(
518
                ['    ' + x
519
520
521
522
523
524
                 for x in self.Map(
                     srcVar + ".u." + self.CleanName(child[0]),
                     "%s.u.u%d.fd_%s" % (dstSDLVariable, childNo, self.CleanName(child[0]).lower()),
                     child[1],
                     leafTypeDict,
                     names)])
525
526
527
528
            lines.append("    %s.present = %d;\n" % (dstSDLVariable, childNo))
            lines.append("}\n")
        return lines

529
    def MapSequenceOf(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
530
        lines = []  # type: List[str]
531
532
533
534
535
        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))
536
        lines.extend(
537
            ["        " + x
538
539
540
541
542
543
             for x in self.Map(
                 srcVar + ".value[i%s]" % uniqueId,
                 "%s.cont[i%s]" % (dstSDLVariable, uniqueId),
                 node._containedType,
                 leafTypeDict,
                 names)])
544
545
546
547
548
        lines.append("    }\n")
        lines.append("}\n")
        self.DecreaseUniqueID()
        return lines

549
    def MapSetOf(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
550
551
552
553
        return self.MapSequenceOf(srcVar, dstSDLVariable, node, leafTypeDict, names)  # pragma: nocover


class OG_GlueGenerator(ASynchronousToolGlueGenerator):
554
    def __init__(self) -> None:
555
556
557
558
559
        ASynchronousToolGlueGenerator.__init__(self)
        self.FromObjectGeodeToASN1SCC = FromObjectGeodeToASN1SCC()
        self.FromObjectGeodeToOSS = FromObjectGeodeToOSS()
        self.FromASN1SCCtoObjectGeode = FromASN1SCCtoObjectGeode()
        self.FromOSStoObjectGeode = FromOSStoObjectGeode()
560
        self.declarations = set()  # type: Set[Typename]
561

562
    def Version(self) -> None:
563
564
        print(("Code generator: " + "$Id: og_B_mapper.py 2390 2012-07-19 12:39:17Z ttsiodras $"))  # pragma: no cover

565
    def HeadersOnStartup(self, unused_asnFile: str, unused_outputDir: str, unused_maybeFVname: str) -> None:
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
        self.C_HeaderFile.write("#include <assert.h>\n\n")
        if self.useOSS:
            self.C_HeaderFile.write("#include \"%s.oss.h\" // OSS generated\n\n" % self.asn_name)
            self.C_HeaderFile.write("#include \"%s.h\" // Space certified compiler (only for REQUIRED_BYTES_FOR_ENCODING)\n\n" % self.asn_name)
            self.C_HeaderFile.write("extern OssGlobal *g_world;\n\n")
        else:
            self.C_HeaderFile.write("#include \"%s.h\" // Space certified compiler generated\n\n" % self.asn_name)
        self.C_HeaderFile.write("#define ASSERT_MAX(a, b)  (((a) > (b)) ? (a) : (b))\n\n")
        self.C_HeaderFile.write("#define ASSERT_MAX3(a, b, c) ((ASSERT_MAX(a,b)<c) ? (c) : (ASSERT_MAX(a,b)))\n\n")
        self.C_HeaderFile.write("#ifdef __linux__\n")
        self.C_HeaderFile.write("#define CLEAR_MEM(ptr, size)  (void)memset(ptr, 0, size)\n")
        self.C_HeaderFile.write("#else\n")
        self.C_HeaderFile.write("#define CLEAR_MEM(ptr, size)\n")
        self.C_HeaderFile.write("#endif\n\n")

581
    def Encoder(self, nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup, encoding: str) -> None:
582
583
584
585
        fileOutHeader = self.C_HeaderFile

        # This method also generates the DECLARE and DEFINE macros.
        if nodeTypename not in self.declarations:
586
            self.declarations.add(nodeTypename)
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
            fileOutHeader.write("#define DECLARE_%s(varName) \\\n" % self.CleanNameAsToolWants(nodeTypename))
            fileOutHeader.write("    extern char varName[ASSERT_MAX3(asn1Scc%s_REQUIRED_BYTES_FOR_ENCODING, asn1Scc%s_REQUIRED_BYTES_FOR_ACN_ENCODING, sizeof(asn1Scc%s))];\\\n" %
                                (self.CleanNameAsToolWants(nodeTypename),
                                 self.CleanNameAsToolWants(nodeTypename),
                                 self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write("    extern int varName##_len;\\\n\\\n\n")

            fileOutHeader.write("#define DEFINE_%s(varName) \\\n" %
                                self.CleanNameAsToolWants(nodeTypename))
            fileOutHeader.write("    char varName[ASSERT_MAX3(asn1Scc%s_REQUIRED_BYTES_FOR_ENCODING, asn1Scc%s_REQUIRED_BYTES_FOR_ACN_ENCODING, sizeof(asn1Scc%s))];\\\n" %
                                (self.CleanNameAsToolWants(nodeTypename),
                                 self.CleanNameAsToolWants(nodeTypename),
                                 self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write("    int varName##_len;\\\n\\\n\n")

        # Create the macro that does the encoding
        fileOutHeader.write(
            "#define ENCODE_%s_%s(varName, param1) {\\\n" %
            ({"uper": "UPER", "native": "NATIVE", "acn": "ACN"}[encoding.lower()], self.CleanNameAsToolWants(nodeTypename)))

        if self.useOSS and encoding.lower() == "uper":
            fileOutHeader.write("    STATIC OssBuf strm;\\\n")
            fileOutHeader.write("    STATIC OSS_%s var_%s;\\\n" %
                                (self.CleanNameAsToolWants(nodeTypename),
                                 self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write("\\\n    strm.value=NULL;\\\n")
            fileOutHeader.write("    strm.length = 0;\\\n")
        elif encoding.lower() in ["uper", "acn"]:
            fileOutHeader.write("    int errorCode = 314159;\\\n")
            fileOutHeader.write("    STATIC BitStream strm;\\\n")
            fileOutHeader.write(
                "    STATIC asn1Scc%s var_%s;\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write(
                "\\\n    BitStream_Init(&strm, varName, asn1Scc%s_REQUIRED_BYTES_FOR_%sENCODING);\\\n" %
622
                (self.CleanNameAsToolWants(nodeTypename), "ACN_" if encoding.lower() == "acn" else ""))
623
624
625
626
627
628
629
630
631
632
633
        else:
            fileOutHeader.write(
                "    STATIC asn1Scc%s var_%s;\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write(
                "    CLEAR_MEM(&var_%s, sizeof(var_%s));\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))

        # Write the mapping code for the message
        if self.useOSS and encoding.lower() == "uper":
            lines = self.FromObjectGeodeToOSS.Map(
634
                # (isinstance(node, AsnInt) or isinstance(node, AsnBool)) and "(param1)" or "(*(param1))",
635
636
637
638
639
640
641
                "(param1)",
                "var_" + self.CleanNameAsToolWants(nodeTypename),
                node,
                leafTypeDict,
                names)
        else:
            lines = self.FromObjectGeodeToASN1SCC.Map(
642
                # (isinstance(node, AsnInt) or isinstance(node, AsnBool)) and "(param1)" or "(*(param1))",
643
644
645
646
647
648
                "(param1)",
                "var_" + self.CleanNameAsToolWants(nodeTypename),
                node,
                leafTypeDict,
                names)

649
        lines = ["    " + x.rstrip() + "\\" for x in lines]
650
651
652
653
654
655
656
657
658
        fileOutHeader.write("\n".join(lines))

        # Call the encoder
        if self.useOSS and encoding.lower() == "uper":
            fileOutHeader.write(
                "\n    if (0 != ossEncode(g_world, OSS_%s_PDU, &var_%s, &strm)) {\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write(
                '\tfprintf(stderr, "Could not encode %s (at %%s, %%d), error message was %%s\\n", __FILE__, __LINE__, ossGetErrMsg(g_world));\\\n' %
659
                nodeTypename)
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
            fileOutHeader.write("        varName##_len = -1;\\\n")
            fileOutHeader.write("    } else {\\\n")
            fileOutHeader.write("        memcpy(&varName[0], strm.value, strm.length);\\\n")
            fileOutHeader.write("        ossFreeBuf(g_world, strm.value);\\\n")
            fileOutHeader.write("        varName##_len = strm.length;\\\n")
            fileOutHeader.write("    }\\\n")
            fileOutHeader.write("}\n\n")
        elif encoding.lower() in ["uper", "acn"]:
            fileOutHeader.write(
                "\n    if (asn1Scc%s_%sEncode(&var_%s, &strm, &errorCode, TRUE) == FALSE) {\\\n" %
                (self.CleanNameAsToolWants(nodeTypename),
                 "ACN_" if encoding.lower() == "acn" else "",
                 self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write(
                '\tfprintf(stderr, "Could not encode %s (at %%s, %%d), error code was %%d\\n", __FILE__, __LINE__, errorCode);\\\n' %
675
                nodeTypename)
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
            fileOutHeader.write("        varName##_len = -1;\\\n")
            fileOutHeader.write("    } else {\\\n")
            fileOutHeader.write("        varName##_len = BitStream_GetLength(&strm);\\\n")
            fileOutHeader.write("    }\\\n")
            fileOutHeader.write("}\n\n")
        else:
            fileOutHeader.write(
                "\n    memcpy(&varName[0], &var_%s, sizeof(asn1Scc%s));\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write(
                "    varName##_len = sizeof(asn1Scc%s);\\\n" %
                self.CleanNameAsToolWants(nodeTypename))
            fileOutHeader.write("}\n\n")

        coding = {"uper": "UPER", "native": "NATIVE", "acn": "ACN"}[encoding.lower()]
        if isinstance(node, AsnInt) or isinstance(node, AsnBool) or isinstance(node, AsnReal) or isinstance(node, AsnEnumerated):
            fileOutHeader.write(
                "#define ENCODE_SYNC_%s_%s(varName, param1) ENCODE_%s_%s(varName, param1)\n\n" %
                (coding,
                 self.CleanNameAsToolWants(nodeTypename),
                 coding,
                 self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write(
                "#define ENCODE_ASYNC_%s_%s(varName, param1) ENCODE_%s_%s(varName, param1)\n\n" %
                (coding,
                 self.CleanNameAsToolWants(nodeTypename),
                 coding,
                 self.CleanNameAsToolWants(nodeTypename)))
        else:
            fileOutHeader.write(
                "#define ENCODE_SYNC_%s_%s(varName, param1) ENCODE_%s_%s(varName, param1)\n\n" %
                (coding,
                 self.CleanNameAsToolWants(nodeTypename),
                 coding,
                 self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write(
                "#define ENCODE_ASYNC_%s_%s(varName, param1) ENCODE_%s_%s(varName, (*param1))\n\n" %
                (coding,
                 self.CleanNameAsToolWants(nodeTypename),
                 coding,
                 self.CleanNameAsToolWants(nodeTypename)))

718
    def Decoder(self, nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup, encoding: str) -> None:
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
        fileOutHeader = self.C_HeaderFile
        fileOutHeader.write(
            "#define DECODE_%s_%s(pBuffer, iBufferSize, pSdlVar) {\\\n" %
            ({"uper": "UPER", "native": "NATIVE", "acn": "ACN"}[encoding.lower()], self.CleanNameAsToolWants(nodeTypename)))

        if self.useOSS and encoding.lower() == "uper":
            fileOutHeader.write("    int pdutype = OSS_%s_PDU;\\\n" % self.CleanNameAsToolWants(nodeTypename))
            fileOutHeader.write("    STATIC OssBuf strm;\\\n")
            fileOutHeader.write(
                "    OSS_%s *pVar_%s = NULL;\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write("    strm.value = pBuffer;\\\n")
            fileOutHeader.write("    strm.length = iBufferSize;\\\n")
            fileOutHeader.write(
                "    if (0 == ossDecode(g_world, &pdutype, &strm, (void**)&pVar_%s)) {\\\n" %
                (self.CleanNameAsToolWants(nodeTypename)))
        elif encoding.lower() in ["uper", "acn"]:
            fileOutHeader.write("    int errorCode = 314159;\\\n")
            fileOutHeader.write("    STATIC BitStream strm;\\\n")
            fileOutHeader.write(
                "    STATIC asn1Scc%s var_%s;\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write("    BitStream_AttachBuffer(&strm, pBuffer, iBufferSize);\\\n")
            fileOutHeader.write(
                "    if(asn1Scc%s_%sDecode(&var_%s, &strm, &errorCode)) {\\\n" %
744
                (self.CleanNameAsToolWants(nodeTypename), "ACN_" if encoding.lower() == "acn" else "", self.CleanNameAsToolWants(nodeTypename)))
745
746
747
748
749
750
751
752
753
754
755
756
        else:
            fileOutHeader.write(
                "    STATIC asn1Scc%s var_%s;\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write(
                "    assert(iBufferSize == sizeof(asn1Scc%s));\\\n" %
                self.CleanNameAsToolWants(nodeTypename))
            fileOutHeader.write(
                "    memcpy(&var_%s, pBuffer, sizeof(asn1Scc%s));\\\n" %
                (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write("    {\\\n")

757
758
        # dstSDLVariable = (isinstance(node, AsnInt) or isinstance(node, AsnBool)) and "(pSdlVar)" or "(*(pSdlVar))"
        # dstSDLVariable = (isinstance(node, AsnInt)) and "(pSdlVar)" or "(*(pSdlVar))"
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
        dstSDLVariable = "(*(pSdlVar))"

        if self.useOSS and encoding.lower() == "uper":
            lines = self.FromOSStoObjectGeode.Map(
                "(*pVar_" + self.CleanNameAsToolWants(nodeTypename) + ")",
                dstSDLVariable,
                node,
                leafTypeDict,
                names)
        else:
            lines = self.FromASN1SCCtoObjectGeode.Map(
                "var_" + self.CleanNameAsToolWants(nodeTypename),
                dstSDLVariable,
                node,
                leafTypeDict,
                names)

776
        lines = ["        " + x.rstrip() + "\\" for x in lines]
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
        fileOutHeader.write("\n".join(lines))

        if self.useOSS and encoding.lower() == "uper":
            fileOutHeader.write("\n        ossFreeBuf(g_world, pVar_%s);\\\n" % self.CleanNameAsToolWants(nodeTypename))
            fileOutHeader.write("        /*return 0*/;\\\n")
            fileOutHeader.write("    } else {\\\n")
            fileOutHeader.write('        fprintf(stderr, "Could not decode %s\\n");\\\n' % (self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write("        /*return -1*/;\\\n")
            fileOutHeader.write("    }\\\n")
            fileOutHeader.write("}\n\n")
        elif encoding.lower() in ["uper", "acn"]:
            fileOutHeader.write("\n        /*return 0*/;\\\n")
            fileOutHeader.write("    } else {\\\n")
            fileOutHeader.write('\tfprintf(stderr, "Could not decode %s\\n");\\\n' % (self.CleanNameAsToolWants(nodeTypename)))
            fileOutHeader.write("        /*return -1*/;\\\n")
            fileOutHeader.write("    }\\\n")
            fileOutHeader.write("}\n\n")
        else:
            fileOutHeader.write("\n        /*return 0*/;\\\n")
            fileOutHeader.write("    }\\\n")
            fileOutHeader.write("}\n\n")

799
800
801
        # fileOutHeader.write(
        #     "#define DECODE_%s(pBuffer, iBufferSize, pSdlVar) DECODE_UPER_%s(pBuffer, iBufferSize, pSdlVar)\n\n" %
        #     (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
802
803


804
def OnStartup(modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
805
806
807
808
809
    global ogBackend
    ogBackend = OG_GlueGenerator()
    ogBackend.OnStartup(modelingLanguage, asnFile, outputDir, maybeFVname, useOSS)


810
def OnBasic(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
811
812
813
    ogBackend.OnBasic(nodeTypename, node, leafTypeDict, names)


814
def OnSequence(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
815
816
817
    ogBackend.OnSequence(nodeTypename, node, leafTypeDict, names)


818
def OnSet(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
819
820
821
    ogBackend.OnSet(nodeTypename, node, leafTypeDict, names)  # pragma: nocover


822
def OnEnumerated(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
823
824
825
    ogBackend.OnEnumerated(nodeTypename, node, leafTypeDict, names)


826
def OnSequenceOf(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
827
828
829
    ogBackend.OnSequenceOf(nodeTypename, node, leafTypeDict, names)


830
def OnSetOf(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
831
832
833
    ogBackend.OnSetOf(nodeTypename, node, leafTypeDict, names)  # pragma: nocover


834
def OnChoice(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
835
836
837
    ogBackend.OnChoice(nodeTypename, node, leafTypeDict, names)


838
def OnShutdown(modelingLanguage: str, asnFile: str, maybeFVname: str) -> None:
839
    ogBackend.OnShutdown(modelingLanguage, asnFile, maybeFVname)