Commit f48ce6ba authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Merge branch 'python3-setup-for-vm'

parents 0647ddfa bd30bf4a
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, ${PY_SRC})
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 mypy coverage
......@@ -13,7 +13,7 @@ pylint:
mypy:
@echo Performing type analysis via mypy...
@mypy --check-untyped-defs ${PY_SRC} || exit 1
@mypy --disallow-untyped-defs --check-untyped-defs ${PY_SRC} || exit 1
coverage:
@echo Performing coverage checks...
......
......@@ -26,10 +26,14 @@ import os
import sys
import distutils.spawn as spawn
from typing import List
from ..commonPy.utility import panic
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnAST import AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnEnumerated, AsnChoice
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
......@@ -37,7 +41,7 @@ def Version():
# the second param is not asnFile, it is asnFiles
def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str, unused_badTypes: SetOfBadTypenames) -> None: # pylint: disable=invalid-sequence-index
# print "Use ASN1SCC to generate the structures for '%s'" % asnFile
asn1SccPath = spawn.find_executable('asn1.exe')
if not asn1SccPath:
......@@ -49,33 +53,33 @@ def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
os.system("rm -f \"" + outputDir + "\"/*.adb")
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequence(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSet(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnEnumerated(unused_nodeTypename: str, unused_node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequenceOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSetOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnShutdown(unused_badTypes):
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
pass # pragma: no cover
......@@ -25,18 +25,22 @@ code generator A.'''
import os
import sys
import distutils.spawn as spawn
from typing import List
from ..commonPy.utility import panic
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnAST import AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnEnumerated, AsnChoice
from ..commonPy.asnParser import AST_Leaftypes
def Version():
def Version() -> None:
print("Code generator: " + "$Id: c_A_mapper.py 2382 2012-06-22 08:35:33Z ttsiodras $") # pragma: no cover
# 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
def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str, unused_badTypes: SetOfBadTypenames) -> None: # pylint: disable=invalid-sequence-index
# print "Use ASN1SCC to generate the structures for '%s'" % asnFile
asn1SccPath = spawn.find_executable('asn1.exe')
if not asn1SccPath:
......@@ -53,33 +57,33 @@ def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
os.system("rm -f \"" + outputDir + os.sep + os.path.basename(os.path.splitext(tmp)[0]) + ".c\"")
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequence(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSet(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnEnumerated(unused_nodeTypename: str, unused_node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequenceOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSetOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnShutdown(unused_badTypes):
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
pass # pragma: no cover
......@@ -24,47 +24,50 @@
# import re
from ..commonPy import asnParser
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnAST import AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnEnumerated, AsnChoice
from ..commonPy.asnParser import AST_Leaftypes
g_outputDir = ""
g_asnFile = ""
def Version():
def Version() -> None:
print("Code generator: " + "$Id: og_A_mapper.py 2382 2012-06-22 08:35:33Z ttsiodras $") # pragma: no cover
def OnStartup(unused_modelingLanguage, asnFile, outputDir, unused_badTypes):
def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, unused_badTypes: SetOfBadTypenames) -> None:
global g_asnFile
g_asnFile = asnFile
global g_outputDir
g_outputDir = outputDir
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequence(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSet(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnEnumerated(unused_nodeTypename: str, unused_node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequenceOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSetOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
# obsolete, now the grammar is re-created from the AST (PrintGrammarFromAST)
......@@ -84,7 +87,7 @@ def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
# 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)
......
......@@ -21,14 +21,14 @@
import re
import os
from typing import List # NOQA pylint: disable=unused-import
from typing import Union, List # NOQA pylint: disable=unused-import
from ..commonPy import asnParser
from ..commonPy.utility import panic, inform
from ..commonPy.asnAST import (
AsnBool, AsnInt, AsnReal, AsnString, isSequenceVariable, AsnEnumerated,
AsnSequence, AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf,
AsnBasicNode, AsnNode)
AsnBasicNode, AsnNode, AsnSequenceOrSet, AsnSequenceOrSetOf)
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
from ..commonPy.cleanupNodes import SetOfBadTypenames
......@@ -42,7 +42,7 @@ g_outputGetSetC = None
g_bHasStartupRunOnce = False
def Version():
def Version() -> None:
print("Code generator: " +
"$Id: python_A_mapper.py 2400 2012-09-04 10:40:19Z ttsiodras $") # pragma: no cover
......@@ -51,7 +51,7 @@ def CleanNameAsPythonWants(name: str) -> str:
return re.sub(r'[^a-zA-Z0-9_]', '_', name)
def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, badTypes: SetOfBadTypenames):
def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, badTypes: SetOfBadTypenames) -> None:
os.system("bash -c '[ ! -f \"" + outputDir + "/" + asnFile + "\" ] && cp \"" + asnFile + "\" \"" + outputDir + "\"'")
this_path = os.path.dirname(__file__)
stubs = this_path + os.sep + 'Stubs.py'
......@@ -181,7 +181,7 @@ clean:
g_outputGetSetH.write('\n/* Helper functions for NATIVE encodings */\n\n')
g_outputGetSetC.write('\n/* Helper functions for NATIVE encodings */\n\n')
def WorkOnType(nodeTypeName: str):
def WorkOnType(nodeTypeName: str) -> None:
typ = CleanNameAsPythonWants(nodeTypeName)
g_outputGetSetH.write('void SetDataFor_%s(void *dest, void *src);\n' % typ)
g_outputGetSetH.write("byte* MovePtrBySizeOf_%s(byte *pData);\n" % typ)
......@@ -226,35 +226,35 @@ clean:
g_outputGetSetC.close()
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequence(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSet(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnEnumerated(unused_nodeTypename: str, unused_node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequenceOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSetOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
def OnShutdown(unused_badTypes):
def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
pass
......@@ -272,7 +272,7 @@ class Params(object):
self._types = [] # type: List[str]
self._nodeTypeName = nodeTypename
def AddParam(self, node, varName, unused_leafTypeDict):
def AddParam(self, node: str, varName: str, unused_leafTypeDict: AST_Leaftypes) -> bool:
# Handle variable name
while varName in self._vars:
varName += "_"
......@@ -297,18 +297,24 @@ class Params(object):
# panic("Python_A_mapper: Can't map (%s,%s) to C type\n" % (varName, realLeafType))
# return True
def Pop(self):
def Pop(self) -> None:
self._vars.pop()
self._types.pop()
def GetDecl(self):
def GetDecl(self) -> str:
params = CleanNameAsPythonWants(self._nodeTypeName) + "* root"
for vvv, ttt in zip(self._vars, self._types):
params += ", " + ttt + " " + vvv
return params
def CommonBaseImpl(comment, ctype, path, params, accessPathInC, postfix="", returnPointer=False):
def CommonBaseImpl(comment: str,
ctype: str,
path: str,
params: Params,
accessPathInC: str,
postfix: str="",
returnPointer: bool=False) -> None:
takeAddr = '&' if returnPointer else ''
g_outputGetSetH.write("\n/* %s */\n%s %s_Get%s(%s);\n" % (comment, ctype, path, postfix, params.GetDecl()))
g_outputGetSetC.write("\n/* %s */\n%s %s_Get%s(%s)\n" % (comment, ctype, path, postfix, params.GetDecl()))
......@@ -324,7 +330,13 @@ def CommonBaseImpl(comment, ctype, path, params, accessPathInC, postfix="", retu
# def CommonBaseImplSequenceFixed(comment, ctype, path, params, accessPathInC, node, postfix = ""):
def CommonBaseImplSequenceFixed(comment, ctype, path, params, _, node, postfix=""):
def CommonBaseImplSequenceFixed(comment: str,
ctype: str,
path: str,
params: Params,
_: str,
node: Union[AsnSequenceOf, AsnSetOf, AsnString],
postfix: str="") -> None:
g_outputGetSetH.write("\n/* %s */\n%s %s_Get%s(%s);\n" % (comment, ctype, path, postfix, params.GetDecl()))
g_outputGetSetC.write("\n/* %s */\n%s %s_Get%s(%s)\n" % (comment, ctype, path, postfix, params.GetDecl()))
g_outputGetSetC.write("{\n")
......@@ -337,7 +349,13 @@ def CommonBaseImplSequenceFixed(comment, ctype, path, params, _, node, postfix="
g_outputGetSetC.write("}\n")
def CreateGettersAndSetters(path, params, accessPathInC, node, names, leafTypeDict):
def CreateGettersAndSetters(
path: str,
params: Params,
accessPathInC: str,
node: AsnNode,
names: AST_Lookup,
leafTypeDict: AST_Leaftypes) -> None:
if isinstance(node, str):
node = names[node]
if isinstance(node, AsnMetaMember):
......@@ -361,7 +379,7 @@ def CreateGettersAndSetters(path, params, accessPathInC, node, names, leafTypeDi
params.Pop()
elif isinstance(node, AsnEnumerated):
CommonBaseImpl("ENUMERATED", "int", path, params, accessPathInC)
elif isinstance(node, AsnSequence) or isinstance(node, AsnSet) or isinstance(node, AsnChoice):
elif isinstance(node, (AsnSequence, AsnSet, AsnChoice)):
if isinstance(node, AsnChoice):
CommonBaseImpl("CHOICE selector", "int", path + "_kind", params, accessPathInC + ".kind")
union = ""
......@@ -377,7 +395,7 @@ def CreateGettersAndSetters(path, params, accessPathInC, node, names, leafTypeDi
useStar = '' if baseTypeOfChild.endswith('OF') else '*'
CommonBaseImpl("Field " + childVarname + " selector", CleanNameAsPythonWants(childNode._containedType) + useStar, path + "_" + childVarname, params, accessPathInC + union + "." + childVarname, returnPointer=not baseTypeOfChild.endswith('OF'))
CreateGettersAndSetters(path + "_" + childVarname, params, accessPathInC + union + "." + childVarname, child[1], names, leafTypeDict)
elif isinstance(node, AsnSequenceOf) or isinstance(node, AsnSetOf):
elif isinstance(node, (AsnSequenceOf, AsnSetOf)):
containedNode = node._containedType
if isinstance(containedNode, str):
containedNode = names[containedNode]
......@@ -396,7 +414,7 @@ def DumpTypeDumper(
lines: List[str], # pylint: disable=invalid-sequence-index
variableName: str,
node: AsnNode,
names: AST_Lookup):
names: AST_Lookup) -> None:
''' Return the lines of code needed to display the value of a variable
of a given type, in the ASN.1 Value Notation format (aka GSER) '''
if isinstance(node, AsnBool):
......@@ -481,7 +499,7 @@ def DumpTypeDumper(
lines.append(codeIndent + 'lines.append("}")')
def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict: AST_Leaftypes):
def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict: AST_Leaftypes) -> None:
node = names[nodeTypename]
name = CleanNameAsPythonWants(nodeTypename)
if isinstance(node, (AsnBasicNode, AsnEnumerated, AsnSequence, AsnSet,
......@@ -523,7 +541,7 @@ def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict:
panic("Unexpected ASN.1 type... Send this grammar to Semantix") # pragma: no cover
def CreateDeclarationsForAllTypes(names, leafTypeDict, badTypes: SetOfBadTypenames):
def CreateDeclarationsForAllTypes(names: AST_Lookup, leafTypeDict: AST_Leaftypes, badTypes: SetOfBadTypenames) -> None:
for nodeTypename in names:
if not names[nodeTypename]._isArtificial and nodeTypename not in badTypes:
CreateDeclarationForType(nodeTypename, names, leafTypeDict)
......
......@@ -28,12 +28,20 @@ code generator A.'''
import os
import sys
import re
import distutils.spawn as spawn
from typing import List, Union
from ..commonPy import asnParser
from ..commonPy.utility import panic, inform
from ..commonPy.asnAST import AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence, AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf
from ..commonPy.createInternalTypes import ScanChildren
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnAST import (
AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnBool, AsnInt,
AsnReal, AsnString, AsnEnumerated, AsnSequence, AsnSet, AsnChoice,
AsnMetaMember, AsnSequenceOf, AsnSetOf)
from ..commonPy.asnAST import AsnNode # NOQA pylint: disable=unused-import
from ..commonPy.asnParser import AST_Leaftypes, AST_Lookup
# The file written to
g_outputFile = None
......@@ -46,18 +54,18 @@ g_octetStrings = 0
g_bHasStartupRunOnce = False
def Version():
def Version() -> None:
print("Code generator: " + "$Id: qgenada_A_mapper.py $") # pragma: no cover
def CleanNameAsSimulinkWants(name):
def CleanNameAsSimulinkWants(name: str) -> str:
return re.sub(r'[^a-zA-Z0-9_]', '_', name)
# 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
def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str, unused_badTypes: SetOfBadTypenames) -> None: # pylint: disable=invalid-sequence-index
# print "Use ASN1SCC to generate the structures for '%s'" % asnFile
asn1SccPath = spawn.find_executable('asn1.exe')
if not asn1SccPath:
......@@ -88,39 +96,39 @@ def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
CreateDeclarationsForAllTypes(asnParser.g_names, asnParser.g_leafTypeDict)
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequence(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSet(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnEnumerated(unused_nodeTypename: str, unused_node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequenceOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSetOf(unused_nodeTypename: str, unused_node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover
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:
......@@ -135,15 +143,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'
......@@ -164,7 +171,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))
......@@ -190,7 +197,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)
......@@ -224,7 +231,7 @@ def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
panic("QGenAda_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
......@@ -287,14 +294,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):
......@@ -318,6 +324,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)
......@@ -23,14 +23,18 @@
#
import re
from typing import Set # 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
from ..commonPy.asnAST import (
AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence,
AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf)
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, AST_Lookup
# The file written to
g_outputFile = None
......@@ -43,15 +47,15 @@ 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)
def OnStartup(unused_modelingLanguage, unused_asnFile, outputDir, unused_badTypes):
def OnStartup(unused_modelingLanguage: str, unused_asnFiles: List[str], outputDir: str, unused_badTypes: SetOfBadTypenames) -> None: # pylint: disable=invalid-sequence-index
global g_bHasStartupRunOnce
if g_bHasStartupRunOnce:
# Don't rerun, it has already done all the work
......@@ -71,39 +75,39 @@ def OnStartup(unused_modelingLanguage, unused_asnFile, outputDir, unused_badType
CreateDeclarationsForAllTypes(asnParser.g_names, asnParser.g_leafTypeDict)
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSequence(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: no cover
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnSet(unused_nodeTypename: str, unused_node: AsnSequenceOrSet, unused_leafTypeDict: AST_Leaftypes) -> None:
pass # pragma: nocover