ada_A_mapper.py 3.43 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
#
# (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 contains the implementation of model level mapping
of ASN.1 constructs to C. It is used as a backend of Semantix's
code generator A.'''

import os
import sys
27
from distutils import spawn
28

29
from typing import List
30
from ..commonPy.utility import panic
31
from ..commonPy.cleanupNodes import SetOfBadTypenames
32 33
from ..commonPy.asnAST import AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnEnumerated, AsnChoice
from ..commonPy.asnParser import AST_Leaftypes
34 35


36
def Version() -> None:
37
    print("Code generator: " + "$Id: ada_A_mapper.py 2382 2012-06-22 08:35:33Z ttsiodras $")  # pragma: no cover
38 39 40 41 42 43


# Especially for the C mapper, since we need to pass the complete ASN.1 files list to ASN1SCC,
# the second param is not asnFile, it is asnFiles


44
def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str, unused_badTypes: SetOfBadTypenames) -> None:  # pylint: disable=invalid-sequence-index
45
    # print "Use ASN1SCC to generate the structures for '%s'" % asnFile
46 47
    asn1SccPath = spawn.find_executable('asn1.exe')
    if not asn1SccPath:
48
        panic("ASN1SCC seems to be missing from your system (asn1.exe not found in PATH).\n")  # pragma: no cover
49
    # allow externally-defined flags when calling the asn1 compiler (e.g. to set word size based on target)
50
    extraFlags = os.getenv("ASN1SCC_FLAGS") or ""
51
    os.system(
52
        ("mono " if sys.platform.startswith('linux') else "") +
53
        "\"{}\" -typePrefix asn1Scc -Ada {} -o \"".format(asn1SccPath, extraFlags) +
54
        outputDir + "\" \"" + "\" \"".join(asnFiles) + "\"")
55
    # os.system("rm -f \"" + outputDir + "\"/*.adb")
56 57


58
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
59 60 61
    pass  # pragma: no cover


62
def OnSequence(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
63 64 65
    pass  # pragma: no cover


66
def OnSet(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
67 68 69
    pass  # pragma: no cover


70
def OnEnumerated(unused_nodeTypename: str, unused_node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
71 72 73
    pass  # pragma: no cover


74
def OnSequenceOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
75 76 77
    pass  # pragma: no cover


78
def OnSetOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
79 80 81
    pass  # pragma: no cover


82
def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDict: AST_Leaftypes) -> None:
83 84 85
    pass  # pragma: no cover


86
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
87
    pass  # pragma: no cover