c_A_mapper.py 3.46 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
from typing import List
29

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: c_A_mapper.py 2382 2012-06-22 08:35:33Z ttsiodras $")  # pragma: no cover
38 39 40 41 42


# 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

43
def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str, unused_badTypes: SetOfBadTypenames) -> None:  # pylint: disable=invalid-sequence-index
44
    # print "Use ASN1SCC to generate the structures for '%s'" % asnFile
45 46
    asn1SccPath = spawn.find_executable('asn1.exe')
    if not asn1SccPath:
47
        panic("ASN1SCC seems to be missing from your system (asn1.exe not found in PATH).\n")  # pragma: no cover
48
    os.system(
49
        ("mono " if sys.platform.startswith('linux') else "") +
50
        "\"{}\" -typePrefix asn1Scc -c -uPER -o \"".format(asn1SccPath) +
51
        outputDir + "\" \"" + "\" \"".join(asnFiles) + "\"")
52 53 54 55 56 57
#   cmd = 'rm -f '
#   for i in ['real.c', 'asn1crt.c', 'acn.c']:
#       cmd += ' "' + outputDir + '"/' + i
#   os.system(cmd)
#   for tmp in asnFiles:
#       os.system("rm -f \"" + outputDir + os.sep + os.path.basename(os.path.splitext(tmp)[0]) + ".c\"")
58 59


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


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


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


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


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


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


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


88
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
89
    pass  # pragma: no cover