og_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,
    AsnOctetString, AsnChoice, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnNode)
from ..commonPy.asnParser import Typename, AST_Lookup, AST_Leaftypes  # NOQA pylint: disable=unused-import
98

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

isAsynchronous = True


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

111
    def UniqueID(self) -> int:
112
113
114
        self.uniqueID += 1
        return self.uniqueID

115
    def DecreaseUniqueID(self) -> None:
116
117
        self.uniqueID -= 1

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

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

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

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

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

153
    def MapSequence(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
154
        lines = []  # type: List[str]
155
156
157
158
159
160
161
162
163
164
        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

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

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

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

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


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

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

221
    def DecreaseUniqueID(self) -> None:
222
223
        self.uniqueID -= 1

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

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

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

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

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

258
    def MapSequence(self, srcSDLVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
259
        lines = []  # type: List[str]
260
261
262
263
264
265
266
267
268
269
        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

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

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

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

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


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

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

325
    def DecreaseUniqueID(self) -> None:
326
327
        self.uniqueID -= 1

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

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

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

337
    def MapOctetString(self, srcVar: str, dstSDLVariable: str, node: AsnOctetString, _: AST_Leaftypes, __: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
338
339
        # for i in xrange(0, node._range[-1]):
        #     lines.append("%s[%d] = %s->buf[%d];\n" % (dstSDLVariable, i, srcVar, i))
340
        lines = []  # type: List[str]
341
342
343
344
345
        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)
346
347
348
349
350
351
352
353
354
        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)
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
        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

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

375
    def MapSequence(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
376
        lines = []  # type: List[str]
377
378
379
380
381
382
383
384
385
386
        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

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

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

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

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


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

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

444
    def DecreaseUniqueID(self) -> None:
445
446
        self.uniqueID -= 1

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

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

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

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

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

493
    def MapSequence(self, srcVar: str, dstSDLVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:  # pylint: disable=invalid-sequence-index
494
        lines = []  # type: List[str]
495
496
497
498
499
500
501
502
503
504
        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

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

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

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

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


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

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

563
    def HeadersOnStartup(self, unused_asnFile: str, unused_outputDir: str, unused_maybeFVname: str) -> None:
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
        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")

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

        # This method also generates the DECLARE and DEFINE macros.
        if nodeTypename not in self.declarations:
584
            self.declarations.add(nodeTypename)
585
586
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
            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" %
620
                (self.CleanNameAsToolWants(nodeTypename), "ACN_" if encoding.lower() == "acn" else ""))
621
622
623
624
625
626
627
628
629
630
631
        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(
632
                # (isinstance(node, AsnInt) or isinstance(node, AsnBool)) and "(param1)" or "(*(param1))",
633
634
635
636
637
638
639
                "(param1)",
                "var_" + self.CleanNameAsToolWants(nodeTypename),
                node,
                leafTypeDict,
                names)
        else:
            lines = self.FromObjectGeodeToASN1SCC.Map(
640
                # (isinstance(node, AsnInt) or isinstance(node, AsnBool)) and "(param1)" or "(*(param1))",
641
642
643
644
645
646
                "(param1)",
                "var_" + self.CleanNameAsToolWants(nodeTypename),
                node,
                leafTypeDict,
                names)

647
        lines = ["    " + x.rstrip() + "\\" for x in lines]
648
649
650
651
652
653
654
655
656
        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' %
657
                nodeTypename)
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
            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' %
673
                nodeTypename)
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
            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()]
689
        if isinstance(node, (AsnInt, AsnBool, AsnReal, AsnEnumerated)):
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
            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)))

716
    def Decoder(self, nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup, encoding: str) -> None:
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
        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" %
742
                (self.CleanNameAsToolWants(nodeTypename), "ACN_" if encoding.lower() == "acn" else "", self.CleanNameAsToolWants(nodeTypename)))
743
744
745
746
747
748
749
750
751
752
753
754
        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")

755
756
        # dstSDLVariable = (isinstance(node, AsnInt) or isinstance(node, AsnBool)) and "(pSdlVar)" or "(*(pSdlVar))"
        # dstSDLVariable = (isinstance(node, AsnInt)) and "(pSdlVar)" or "(*(pSdlVar))"
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
        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)

774
        lines = ["        " + x.rstrip() + "\\" for x in lines]
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
        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")

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


802
803
804
ogBackend: OG_GlueGenerator


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


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


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


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


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


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


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


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


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