Commit bd30bf4a authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Completed Herculean task: DMT statically type-safe

parent b2dd0302
PY_SRC:=$(wildcard dmt/asn2dataModel.py dmt/aadl2glueC.py dmt/smp2asn.py dmt/*mappers/[a-zA-Z]*py dmt/commonPy/[a-zA-Z]*py)
PY_SRC:=$(filter-out dmt/B_mappers/antlr.main.py dmt/A_mappers/Stubs.py dmt/B_mappers/pyside_B_mapper.py, ${PY_SRC})
all: flake8 pylint coverage
all: flake8 pylint mypy coverage
flake8:
@echo Performing syntax checks via flake8...
......
......@@ -33,7 +33,7 @@ from ..commonPy.asnAST import AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf
from ..commonPy.asnParser import AST_Leaftypes
def Version():
def Version() -> None:
print("Code generator: " + "$Id: ada_A_mapper.py 2382 2012-06-22 08:35:33Z ttsiodras $") # pragma: no cover
......@@ -81,5 +81,5 @@ def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDi
pass # pragma: no cover
def OnShutdown(unused_badTypes):
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
pass # pragma: no cover
......@@ -87,7 +87,7 @@ def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDi
# return outputText
def OnShutdown(unused_badTypes):
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
# text = open(g_asnFile, 'r').read()
# text = re.sub(r'^.*BEGIN', 'Datamodel DEFINITIONS ::= BEGIN', text)
# text = re.sub(r'--.*', '', text)
......
......@@ -301,7 +301,6 @@ def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict:
containedNode = contained # type: Union[AsnNode, str]
while isinstance(containedNode, str):
containedNode = names[containedNode]
if isinstance(containedNode, AsnBool):
DeclareSimpleCollection(node, name, 'boolean')
elif isinstance(containedNode, AsnInt):
......
......@@ -23,7 +23,7 @@
#
import re
from typing import Set, List # NOQA pylint: disable=unused-import
from typing import Union, Set, List # NOQA pylint: disable=unused-import
from ..commonPy.utility import panic, inform
from ..commonPy import asnParser
......@@ -31,9 +31,10 @@ from ..commonPy.asnAST import (
AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence,
AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf,
AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf)
from ..commonPy.asnAST import AsnNode # NOQA pylint: disable=unused-import
from ..commonPy.createInternalTypes import ScanChildren
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import AST_Leaftypes
from ..commonPy.asnParser import AST_Leaftypes, AST_Lookup
# The file written to
g_outputFile = None
......@@ -46,11 +47,11 @@ g_octetStrings = 0
g_bHasStartupRunOnce = False
def Version():
def Version() -> None:
print("Code generator: " + "$Id: qgenc_A_mapper.py $") # pragma: no cover
def CleanNameAsSimulinkWants(name):
def CleanNameAsSimulinkWants(name: str) -> str:
return re.sub(r'[^a-zA-Z0-9_]', '_', name)
......@@ -102,11 +103,11 @@ def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDi
pass # pragma: no cover
def OnShutdown(unused_badTypes):
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
pass
def MapInteger(node):
def MapInteger(node: AsnInt) -> str:
if node._range[0] >= 0 and node._range[1] <= 255:
return "uint8"
elif node._range[0] >= -128 and node._range[1] <= 127:
......@@ -121,15 +122,14 @@ def MapInteger(node):
return "int32"
def CreateAlias(nodeTypename, mappedType, description):
def CreateAlias(nodeTypename: str, mappedType: str, description: str) -> None:
# Requirements have changed: Simulink has an issue with AliasType...
g_outputFile.write("%s = Simulink.AliasType;\n" % CleanNameAsSimulinkWants(nodeTypename))
g_outputFile.write("%s.BaseType = '%s';\n" % (CleanNameAsSimulinkWants(nodeTypename), mappedType))
g_outputFile.write("%s.Description = '%s';\n\n" % (CleanNameAsSimulinkWants(nodeTypename), description))
return
def DeclareCollection(node, name, internal):
def DeclareCollection(node: AsnSequenceOrSetOf, name: str, internal: str) -> None:
for i in range(0, node._range[-1]):
g_outputFile.write('%s_member_%02d=Simulink.BusElement;\n' % (name, i))
# Andreas(ESA) wants them to be called 'element_%02d'
......@@ -150,7 +150,7 @@ def DeclareCollection(node, name, internal):
g_outputFile.write(";\n\n")
def DeclareSimpleCollection(node, name, internal):
def DeclareSimpleCollection(node: Union[AsnString, AsnSequenceOf, AsnSetOf], name: str, internal: str) -> None:
g_outputFile.write('%s_member_data=Simulink.BusElement;\n' % name)
g_outputFile.write("%s_member_data.name='element_data';\n" % name)
g_outputFile.write("%s_member_data.DataType='%s';\n" % (name, internal))
......@@ -176,7 +176,7 @@ def DeclareSimpleCollection(node, name, internal):
g_outputFile.write(";\n\n")
def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict: AST_Leaftypes) -> None:
if nodeTypename in g_definedTypes:
return
g_definedTypes.add(nodeTypename)
......@@ -210,7 +210,7 @@ def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
panic("QGenC_A_mapper: must have values for enumerants (%s)" % node.Location()) # pragma: no cover
CreateAlias(nodeTypename, "int32", "values of ENUMERATED %s" % nodeTypename)
g_outputFile.write("\n")
elif isinstance(node, AsnSequence) or isinstance(node, AsnSet) or isinstance(node, AsnChoice):
elif isinstance(node, (AsnSequence, AsnSet, AsnChoice)):
elemNo = 0
if isinstance(node, AsnChoice):
elemNo += 1
......@@ -273,14 +273,13 @@ def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
if elemNo > 1:
g_outputFile.write(']')
g_outputFile.write(";\n\n")
elif isinstance(node, AsnSequenceOf) or isinstance(node, AsnSetOf):
elif isinstance(node, (AsnSequenceOf, AsnSetOf)):
name = CleanNameAsSimulinkWants(nodeTypename)
contained = node._containedType
assert isinstance(contained, str)
containedNode = contained
containedNode = contained # type: Union[AsnNode, str]
while isinstance(containedNode, str):
containedNode = names[containedNode]
if isinstance(containedNode, AsnBool):
DeclareSimpleCollection(node, name, 'boolean')
elif isinstance(containedNode, AsnInt):
......@@ -304,6 +303,6 @@ def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
panic("Unexpected ASN.1 type... Send this grammar to Semantix") # pragma: no cover
def CreateDeclarationsForAllTypes(names, leafTypeDict):
def CreateDeclarationsForAllTypes(names: AST_Lookup, leafTypeDict: AST_Leaftypes) -> None:
for nodeTypename in list(names.keys()):
CreateDeclarationForType(nodeTypename, names, leafTypeDict)
......@@ -28,7 +28,7 @@ import os
import random
from xml.dom.minidom import Document, Node # type: ignore # NOQA pylint: disable=unused-import
from typing import Set # NOQA pylint: disable=unused-import
from typing import Union, Set # NOQA pylint: disable=unused-import
from ..commonPy.utility import inform, panic
from ..commonPy.asnAST import (
......@@ -134,7 +134,7 @@ def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, unused
File.appendChild(g_Declarations)
def RenderElements(controlString: str):
def RenderElements(controlString: str) -> None:
if controlString.endswith(","):
controlString = controlString[:-1]
createdElements = {} # type: Dict[str, Node]
......@@ -171,7 +171,7 @@ def RenderElements(controlString: str):
parent = newElement # pylint: disable=redefined-variable-type
def GetOID(nodeTypename):
def GetOID(nodeTypename: str) -> str:
global g_currOid
if nodeTypename not in g_oid:
oid = hex(g_currOid)[2:] + g_mainOid + RandomHex(12)
......@@ -182,17 +182,17 @@ def GetOID(nodeTypename):
return oid
def CheckPrerequisites(nodeTypename):
def CheckPrerequisites(nodeTypename: str) -> None:
names = asnParser.g_names
leafTypeDict = asnParser.g_leafTypeDict
if nodeTypename not in g_declaredTypes:
node = names[nodeTypename]
leafType = leafTypeDict[nodeTypename]
# If it is a base type,
if leafType in ['BOOLEAN', 'INTEGER', 'REAL', 'OCTET STRING']:
if isinstance(node, AsnBasicNode):
OnBasic(nodeTypename, node, leafTypeDict)
# if it is a complex type
elif leafType in ['SEQUENCE', 'SET', 'CHOICE', 'SEQUENCEOF', 'SETOF', 'ENUMERATED']:
elif isinstance(node, (AsnSequence, AsnSet, AsnChoice, AsnSequenceOf, AsnSetOf, AsnEnumerated)):
# make sure we have mapping instructions for the element
mappedName = {
'SEQUENCE': 'OnSequence',
......@@ -256,7 +256,10 @@ def OnBasic(nodeTypename: str, node: AsnBasicNode, unused_leafTypeDict: AST_Leaf
RenderElements(controlString)
def OnSequence(nodeTypename, node, unused_leafTypeDict, isChoice=False):
def CommonSeqSetChoice(nodeTypename: str,
node: Union[AsnSequence, AsnSet, AsnChoice],
unused_leafTypeDict: AST_Leaftypes,
isChoice: bool=False) -> None:
if nodeTypename in g_declaredTypes:
return
g_declaredTypes.add(nodeTypename)
......@@ -285,8 +288,16 @@ def OnSequence(nodeTypename, node, unused_leafTypeDict, isChoice=False):
RenderElements(controlString)
def OnSequence(nodeTypename: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes) -> None:
CommonSeqSetChoice(nodeTypename, node, leafTypeDict) # pragma: nocover
def OnSet(nodeTypename: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes) -> None:
OnSequence(nodeTypename, node, leafTypeDict) # pragma: nocover
CommonSeqSetChoice(nodeTypename, node, leafTypeDict) # pragma: nocover
def OnChoice(nodeTypename: str, node: AsnChoice, leafTypeDict: AST_Leaftypes) -> None:
CommonSeqSetChoice(nodeTypename, node, leafTypeDict, isChoice=True)
def OnEnumerated(nodeTypename: str, node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
......@@ -347,11 +358,7 @@ def OnSetOf(nodeTypename: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaft
OnSequenceOf(nodeTypename, node, leafTypeDict) # pragma: nocover
def OnChoice(nodeTypename: str, node: AsnChoice, leafTypeDict: AST_Leaftypes) -> None:
OnSequence(nodeTypename, node, leafTypeDict, isChoice=True)
def OnShutdown(unused_badTypes):
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
g_outputFile.write(g_doc.toprettyxml(indent=" ", encoding="UTF-8"))
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
......@@ -20,7 +20,7 @@
#
import re
from typing import Set # NOQA pylint: disable=unused-import
from typing import Union, Set # NOQA pylint: disable=unused-import
from ..commonPy.utility import panic, inform
from ..commonPy import asnParser
......@@ -28,8 +28,10 @@ from ..commonPy.asnAST import (
AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence,
AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf,
AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf)
from ..commonPy.asnAST import AsnNode # NOQA pylint: disable=unused-import
from ..commonPy.createInternalTypes import ScanChildren
from ..commonPy.asnParser import AST_Leaftypes
from ..commonPy.asnParser import AST_Leaftypes, AST_Lookup
from ..commonPy.cleanupNodes import SetOfBadTypenames
# The file written to
......@@ -43,15 +45,15 @@ g_octetStrings = 0
g_bHasStartupRunOnce = False
def Version():
def Version() -> None:
print("Code generator: " + "$Id: simulink_A_mapper.py 2390 2012-07-19 12:39:17Z ttsiodras $") # pragma: no cover
def CleanNameAsSimulinkWants(name):
def CleanNameAsSimulinkWants(name: str) -> str:
return re.sub(r'[^a-zA-Z0-9_]', '_', name)
def OnStartup(unused_modelingLanguage, unused_asnFile, outputDir, unused_badTypes):
def OnStartup(unused_modelingLanguage: str, unused_asnFile: str, outputDir: str, unused_badTypes: SetOfBadTypenames) -> None:
global g_bHasStartupRunOnce
if g_bHasStartupRunOnce:
# Don't rerun, it has already done all the work
......@@ -99,11 +101,11 @@ def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDi
pass
def OnShutdown(unused_badTypes):
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
pass
def MapInteger(node):
def MapInteger(node: AsnInt) -> str:
if node._range[0] >= 0 and node._range[1] <= 255:
return "uint8"
elif node._range[0] >= -128 and node._range[1] <= 127:
......@@ -118,15 +120,14 @@ def MapInteger(node):
return "int32"
def CreateAlias(nodeTypename, mappedType, description):
def CreateAlias(nodeTypename: str, mappedType: str, description: str) -> None:
# Requirements have changed: Simulink has an issue with AliasType...
g_outputFile.write("%s = Simulink.AliasType;\n" % CleanNameAsSimulinkWants(nodeTypename))
g_outputFile.write("%s.BaseType = '%s';\n" % (CleanNameAsSimulinkWants(nodeTypename), mappedType))
g_outputFile.write("%s.Description = '%s';\n\n" % (CleanNameAsSimulinkWants(nodeTypename), description))
return
def DeclareCollection(node, name, internal):
def DeclareCollection(node: AsnSequenceOrSetOf, name: str, internal: str) -> None:
for i in range(0, node._range[-1]):
g_outputFile.write('%s_member_%02d=Simulink.BusElement;\n' % (name, i))
# Andreas(ESA) wants them to be called 'element_%02d'
......@@ -147,7 +148,7 @@ def DeclareCollection(node, name, internal):
g_outputFile.write(";\n\n")
def DeclareSimpleCollection(node, name, internal):
def DeclareSimpleCollection(node: Union[AsnString, AsnSequenceOf, AsnSetOf], name: str, internal: str) -> None:
g_outputFile.write('%s_member_data=Simulink.BusElement;\n' % name)
g_outputFile.write("%s_member_data.name='element_data';\n" % name)
g_outputFile.write("%s_member_data.DataType='%s';\n" % (name, internal))
......@@ -173,7 +174,7 @@ def DeclareSimpleCollection(node, name, internal):
g_outputFile.write(";\n\n")
def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict: AST_Leaftypes) -> None:
if nodeTypename in g_definedTypes:
return
g_definedTypes.add(nodeTypename)
......@@ -207,7 +208,7 @@ def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
panic("Simulink_A_mapper: must have values for enumerants (%s)" % node.Location()) # pragma: no cover
CreateAlias(nodeTypename, "int32", "values of ENUMERATED %s" % nodeTypename)
g_outputFile.write("\n")
elif isinstance(node, AsnSequence) or isinstance(node, AsnSet) or isinstance(node, AsnChoice):
elif isinstance(node, (AsnSequence, AsnSet, AsnChoice)):
if len(node._members) == 0:
panic("Simulink_A_mapper: Simulink can't support empty Seq/Set/Choice! (%s)" % node.Location()) # pragma: no cover
elemNo = 0
......@@ -272,14 +273,13 @@ def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
if elemNo > 1:
g_outputFile.write(']')
g_outputFile.write(";\n\n")
elif isinstance(node, AsnSequenceOf) or isinstance(node, AsnSetOf):
elif isinstance(node, (AsnSequenceOf, AsnSetOf)):
name = CleanNameAsSimulinkWants(nodeTypename)
contained = node._containedType
assert isinstance(contained, str)
containedNode = contained
containedNode = contained # type: Union[AsnNode, str]
while isinstance(containedNode, str):
containedNode = names[containedNode]
if isinstance(containedNode, AsnBool):
DeclareSimpleCollection(node, name, 'boolean')
elif isinstance(containedNode, AsnInt):
......@@ -303,6 +303,6 @@ def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
panic("Unexpected ASN.1 type... Send this grammar to Semantix") # pragma: no cover
def CreateDeclarationsForAllTypes(names, leafTypeDict):
def CreateDeclarationsForAllTypes(names: AST_Lookup, leafTypeDict: AST_Leaftypes) -> None:
for nodeTypename in list(names.keys()):
CreateDeclarationForType(nodeTypename, names, leafTypeDict)
......@@ -25,9 +25,9 @@ import os
import re
import random
from typing import List, Set, IO, Any # NOQA pylint: disable=unused-import
from typing import Dict, List, Set, IO, Any # NOQA pylint: disable=unused-import
from ..commonPy.asnAST import AsnMetaMember, AsnChoice, AsnSet, AsnSequence, AsnSequenceOf, AsnSetOf
from ..commonPy.asnAST import AsnMetaMember, AsnChoice, AsnSet, AsnSequence, AsnSequenceOf, AsnSetOf, AsnBool, AsnInt, AsnReal, AsnOctetString
from ..commonPy.asnParser import g_names, g_leafTypeDict, CleanNameForAST
from ..commonPy.utility import panic, warn
from ..commonPy.cleanupNodes import SetOfBadTypenames
......@@ -41,13 +41,13 @@ g_outputDir = "."
g_asnFiles = None
def Version():
def Version() -> None:
print("Code generator: " + "$Id: smp2_A_mapper.py 1932 2010-06-15 13:41:15Z ttsiodras $") # pragma: no cover
# noinspection PyDefaultArgument
def getUID(strIdentifier, idStore={}): # pylint: disable=dangerous-default-value
def h(digits):
def getUID(strIdentifier: str, idStore: Dict[str, str]={}) -> str: # pylint: disable=dangerous-default-value
def h(digits: int) -> str:
ret = ""
for _ in range(0, digits):
ret += random.choice('0123456789abcdef')
......@@ -60,14 +60,14 @@ def getUID(strIdentifier, idStore={}): # pylint: disable=dangerous-default-valu
g_dependencyGraph = {} # type: Dict[str, Dict[str, int]]
def FixupAstForSMP2():
def FixupAstForSMP2() -> None:
'''
Find all the SEQUENCE, CHOICE and SEQUENCE OFs
and make sure the contained types are not "naked" (i.e. unnamed)
'''
internalNo = 1
def neededToAddPseudoType():
def neededToAddPseudoType() -> bool:
nonlocal internalNo
addedNewPseudoType = False
listOfTypenames = sorted(list(g_names.keys()) + list(g_innerTypes))
......@@ -144,7 +144,7 @@ def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str,
FixupAstForSMP2()
def CleanName(fieldName):
def CleanName(fieldName: str) -> str:
return re.sub(r'[^a-zA-Z0-9_]', '_', fieldName)
......@@ -152,7 +152,7 @@ def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafType
pass # pragma: no cover
def CreateBasic(nodeTypename, node, leafTypeDict):
def CreateBasic(nodeTypename: str, node: AsnBasicNode, leafTypeDict: AST_Leaftypes) -> None:
baseType = leafTypeDict[node._leafType]
xsitype = {
'INTEGER': 'Types:Integer',
......@@ -161,11 +161,11 @@ def CreateBasic(nodeTypename, node, leafTypeDict):
'OCTET STRING': 'Types:Array'
}[baseType]
span = ""
if baseType == 'BOOLEAN':
if isinstance(node, AsnBool):
span = 'Minimum="0" Maximum="1"'
elif baseType in ['INTEGER', 'REAL'] and node._range:
elif isinstance(node, (AsnInt, AsnReal)) and node._range:
span = 'Minimum="%s" Maximum="%s"' % (node._range[0], node._range[-1])
elif baseType == 'OCTET STRING':
elif isinstance(node, AsnOctetString):
span = 'Size="%s"' % node._range[-1]
uid = getUID(nodeTypename)
d = {"uid": uid, "xsitype": xsitype, "name": CleanName(nodeTypename), "range": span}
......@@ -189,7 +189,7 @@ def OnSequence(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_l
pass # pragma: no cover
def CreateSequence(nodeTypename, node, unused_leafTypeDict):
def CreateSequence(nodeTypename: str, node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
uid = getUID(nodeTypename)
d = {"uid": uid, "name": CleanName(nodeTypename)}
g_catalogueXML.write(' <Type xsi:type="Types:Structure" Id="ID_%(uid)s" Name="%(name)s">\n' % d)
......@@ -220,7 +220,7 @@ def OnEnumerated(unused_nodeTypename: str, unused_node: AsnEnumerated, unused_le
pass # pragma: no cover
def CreateEnumerated(nodeTypename, node, unused_leafTypeDict):
def CreateEnumerated(nodeTypename: str, node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
uid = getUID(nodeTypename)
d = {"uid": uid, "name": CleanName(nodeTypename)}
g_catalogueXML.write(' <Type xsi:type="Types:Enumeration" Id="ID_%(uid)s" Name="%(name)s">\n' % d)
......@@ -239,7 +239,7 @@ def OnSequenceOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unus
pass # pragma: no cover
def CreateSequenceOf(nodeTypename, node, unused_leafTypeDict):
def CreateSequenceOf(nodeTypename: str, node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
uid = getUID(nodeTypename)
d = {"uid": uid, "name": CleanName(nodeTypename), "sz": node._range[-1]}
g_catalogueXML.write(' <Type xsi:type="Types:Array" Id="ID_%(uid)s" Name="%(name)s" Size="%(sz)s">\n' % d)
......@@ -272,7 +272,7 @@ def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDi
pass # pragma: no cover
def CreateChoice(nodeTypename, node, _):
def CreateChoice(nodeTypename: str, node: AsnChoice, _: AST_Leaftypes) -> None:
uid = getUID(nodeTypename)
d = {"uid": uid, "name": CleanName(nodeTypename)}
g_catalogueXML.write(' <Type xsi:type="Types:Structure" Id="ID_%(uid)s" Name="%(name)s">\n' % d)
......@@ -302,7 +302,7 @@ def CreateChoice(nodeTypename, node, _):
g_bShutdownRun = False
def OnShutdown(badTypes: SetOfBadTypenames):
def OnShutdown(badTypes: SetOfBadTypenames) -> None:
global g_bShutdownRun
if g_bShutdownRun:
return # pragma: no cover
......@@ -348,15 +348,15 @@ def OnShutdown(badTypes: SetOfBadTypenames):
node = g_names[nodeTypename]
assert nodeTypename in g_leafTypeDict
leafType = g_leafTypeDict[nodeTypename]
if leafType in ['BOOLEAN', 'INTEGER', 'REAL', 'OCTET STRING']:
if isinstance(node, AsnBasicNode):
CreateBasic(nodeTypename, node, g_leafTypeDict)
elif leafType in ['SEQUENCE', 'SET']:
elif isinstance(node, (AsnSequence, AsnSet)):
CreateSequence(nodeTypename, node, g_leafTypeDict)
elif leafType == 'CHOICE':
elif isinstance(node, AsnChoice):
CreateChoice(nodeTypename, node, g_leafTypeDict)
elif leafType in ['SEQUENCEOF', 'SETOF']:
elif isinstance(node, (AsnSequenceOf, AsnSetOf)):
CreateSequenceOf(nodeTypename, node, g_leafTypeDict)
elif leafType == 'ENUMERATED':
elif isinstance(node, AsnEnumerated):
CreateEnumerated(nodeTypename, node, g_leafTypeDict)
else: # pragma: no cover
warn("Ignoring unsupported node type: %s (%s)" % (leafType, nodeTypename)) # pragma: no cover
......
......@@ -41,16 +41,18 @@ output parameters, which have Ada callable interfaces.
# from asynchronousTool import ASynchronousToolGlueGenerator
from . import c_B_mapper
from ..commonPy.asnAST import AsnNode
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
isAsynchronous = True
cBackend = None
def Version():
def Version() -> None:
print("Code generator: " + "$Id: ada_B_mapper.py 2382 2012-06-22 08:35:33Z ttsiodras $") # pragma: no cover
def OnStartup(unused_modelingLanguage, asnFile, outputDir, maybeFVname, useOSS):
def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
global cBackend
# 2009-02-10: Since we now use ASN1SCC structures as dumpables (even for Ada)
# we no longer need Ada-specific Dumpable structures.
......@@ -58,33 +60,33 @@ def OnStartup(unused_modelingLanguage, asnFile, outputDir, maybeFVname, useOSS):
cBackend.OnStartup("C", asnFile, outputDir, maybeFVname, useOSS)
def OnBasic(nodeTypename, node, leafTypeDict, names):
def OnBasic(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnBasic(nodeTypename, node, leafTypeDict, names)
def OnSequence(nodeTypename, node, leafTypeDict, names):
def OnSequence(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnSequence(nodeTypename, node, leafTypeDict, names)
def OnSet(nodeTypename, node, leafTypeDict, names):
def OnSet(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnSet(nodeTypename, node, leafTypeDict, names) # pragma: nocover
def OnEnumerated(nodeTypename, node, leafTypeDict, names):
def OnEnumerated(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnEnumerated(nodeTypename, node, leafTypeDict, names)
def OnSequenceOf(nodeTypename, node, leafTypeDict, names):
def OnSequenceOf(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnSequenceOf(nodeTypename, node, leafTypeDict, names)
def OnSetOf(nodeTypename, node, leafTypeDict, names):
def OnSetOf(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnSetOf(nodeTypename, node, leafTypeDict, names) # pragma: nocover
def OnChoice(nodeTypename, node, leafTypeDict, names):
def OnChoice(nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnChoice(nodeTypename, node, leafTypeDict, names)
def OnShutdown(unused_modelingLanguage, asnFile, maybeFVname):
def OnShutdown(unused_modelingLanguage: str, asnFile: str, maybeFVname: str) -> None:
cBackend.OnShutdown("C", asnFile, maybeFVname)
......@@ -44,18 +44,20 @@ output parameters, which have Ada callable interfaces.
# from asynchronousTool import ASynchronousToolGlueGenerator
from . import c_B_mapper
from ..commonPy.asnAST import AsnBasicNode, AsnSequence, AsnSet, AsnEnumerated, AsnSequenceOf, AsnSetOf, AsnChoice
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
isAsynchronous = True
cBackend = None
def Version():
def Version() -> None:
print("Code generator: " + "$Id: qgenada_B_mapper.py $") # pragma: no cover
# All the ada B mapper is now Obsolete, we are using ASN1SCC for Dumpables
def OnStartup(unused_modelingLanguage, asnFile, outputDir, maybeFVname, useOSS):
def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
global cBackend
# 2009-02-10: Since we now use ASN1SCC structures as dumpables (even for Ada)
# we no longer need these Ada-specific Dumpable structures.
......@@ -63,33 +65,33 @@ def OnStartup(unused_modelingLanguage, asnFile, outputDir, maybeFVname, useOSS):
cBackend.OnStartup("C", asnFile, outputDir, maybeFVname, useOSS)
def OnBasic(nodeTypename, node, leafTypeDict, names):
def OnBasic(nodeTypename: str, node: AsnBasicNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnBasic(nodeTypename, node, leafTypeDict, names)
def OnSequence(nodeTypename, node, leafTypeDict, names):
def OnSequence(nodeTypename: str, node: AsnSequence, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnSequence(nodeTypename, node, leafTypeDict, names)
def OnSet(nodeTypename, node, leafTypeDict, names):
def OnSet(nodeTypename: str, node: AsnSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnSet(nodeTypename, node, leafTypeDict, names) # pragma: nocover
def OnEnumerated(nodeTypename, node, leafTypeDict, names):
def OnEnumerated(nodeTypename: str, node: AsnEnumerated, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnEnumerated(nodeTypename, node, leafTypeDict, names)
def OnSequenceOf(nodeTypename, node, leafTypeDict, names):
def OnSequenceOf(nodeTypename: str, node: AsnSequenceOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnSequenceOf(nodeTypename, node, leafTypeDict, names)
def OnSetOf(nodeTypename, node, leafTypeDict, names):
def OnSetOf(nodeTypename: str, node: AsnSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnSetOf(nodeTypename, node, leafTypeDict, names) # pragma: nocover
def OnChoice(nodeTypename, node, leafTypeDict, names):
def OnChoice(nodeTypename: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
cBackend.OnChoice(nodeTypename, node, leafTypeDict, names)
def OnShutdown(unused_modelingLanguage, asnFile, maybeFVname):
def OnShutdown(unused_modelingLanguage: str, asnFile: str, maybeFVname: str) -> None:
cBackend.OnShutdown("C", asnFile, maybeFVname)
This diff is collapsed.
......@@ -34,7 +34,7 @@ from ..commonPy.utility import panic