Commit f64c0cd7 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

'make flake8 pylint' - all DMT source passes. Now for 'make mypy'...

parent 5ed832e9
......@@ -23,7 +23,7 @@ import sys
import re
import copy
import traceback
import DV_Types
import DV_Types # pylint: disable=import-error
from ctypes import (
cdll, c_void_p, c_ubyte, c_double, c_uint,
c_longlong, c_bool, c_int, c_long
......
......@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
asn2dataModel converts ASN.1 modules to a variety of target languages
asn2dataModel converts ASN.1 modules to a variety of target languages
"""
from . import msgPrinter
from . import msgPrinterASN1
......
......@@ -49,31 +49,31 @@ def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
os.system("rm -f \"" + outputDir + "\"/*.adb")
def OnBasic(nodeTypename, node, leafTypeDict):
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSequence(nodeTypename, node, leafTypeDict):
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSet(nodeTypename, node, leafTypeDict):
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnEnumerated(nodeTypename, node, leafTypeDict):
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSequenceOf(nodeTypename, node, leafTypeDict):
def OnSequenceOf(unused_nodeTypename, unused_node, _unused_leafTypeDict):
pass # pragma: no cover
def OnSetOf(nodeTypename, node, leafTypeDict):
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnChoice(nodeTypename, node, leafTypeDict):
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
......
......@@ -53,31 +53,31 @@ 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(nodeTypename, node, leafTypeDict):
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSequence(nodeTypename, node, leafTypeDict):
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSet(nodeTypename, node, leafTypeDict):
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnEnumerated(nodeTypename, node, leafTypeDict):
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSequenceOf(nodeTypename, node, leafTypeDict):
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSetOf(nodeTypename, node, leafTypeDict):
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnChoice(nodeTypename, node, leafTypeDict):
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
......
......@@ -43,8 +43,8 @@ void main()
%(enums_dump)s
}""" % {"enums_dump": enums_dump, "base": sys.argv[1]})
f.close()
if 0 != os.system(
"gcc -o %s -I. %s.c" % (extractor_filename, extractor_filename)):
cmd = "gcc -o %s -I. %s.c" % (extractor_filename, extractor_filename)
if os.system(cmd) != 0:
print("Failed to extract CHOICE enum values...")
sys.exit(1)
os.system(extractor_filename)
......
#!/usr/bin/env python3
# vim: set expandtab ts=8 sts=4 shiftwidth=4
#
# (C) Semantix Information Technologies.
#
......@@ -34,12 +33,12 @@ import os
import sys
import copy
from typing import Tuple
from typing import Tuple, List
import commonPy.configMT
from commonPy.asnAST import sourceSequenceLimit, AsnNode # NOQA pylint: disable=unused-import
from commonPy.asnParser import ( # NOQA
AST_Lookup, AST_TypesOfFile, AST_TypenamesOfFile, AST_Leaftypes,
from commonPy.asnParser import ( # NOQA pylint: disable=unused-import
AST_Lookup, AST_Leaftypes,
Typename, Filename, ParseAsnFileList)
from commonPy.utility import inform, panic
import commonPy.cleanupNodes
......@@ -175,7 +174,7 @@ def main():
ParseAsnFileList(sys.argv[1:])
Triples = Tuple[AST_Lookup, List[AsnNode], AST_Leaftypes] # NOQA pylint: disable=unused-variable
Triples = Tuple[AST_Lookup, List[AsnNode], AST_Leaftypes] # NOQA pylint: disable=unused-variable,invalid-sequence-index
uniqueASNfiles = {} # type: Dict[Filename, Triples]
for asnFile in uniqueASNfiles:
......@@ -261,7 +260,9 @@ def main():
if __name__ == "__main__":
if "-pdb" in sys.argv:
sys.argv.remove("-pdb") # pragma: no cover
import pdb # pylint: disable=wrong-import-position pragma: nocover
import pdb # pragma: nocover pylint: disable=wrong-import-position,wrong-import-order
pdb.run('main()') # pragma: no cover
else:
main()
# vim: set expandtab ts=8 sts=4 shiftwidth=4
#!/usr/bin/env python
# vim: set expandtab ts=8 sts=4 shiftwidth=4
'''
This is one of the code generators that Semantix developed for
the European research project ASSERT. It is now enhanced in the
context of Data Modelling and Data Modelling Tuning projects.
It reads the ASN.1 specification of the exchanged messages, and
generates printer-functions for their content.
'''
# (C) Semantix Information Technologies.
#
......@@ -24,12 +31,12 @@ import os
import sys
import copy
from typing import Tuple
from typing import Tuple, List
import commonPy.configMT
from commonPy.asnAST import sourceSequenceLimit, AsnNode # NOQA pylint: disable=unused-import
from commonPy.asnParser import ( # NOQA
AST_Lookup, AST_TypesOfFile, AST_TypenamesOfFile, AST_Leaftypes,
from commonPy.asnParser import ( # NOQA pylint: disable=unused-import
AST_Lookup, AST_Leaftypes,
Typename, Filename, ParseAsnFileList)
from commonPy.utility import inform, panic
import commonPy.cleanupNodes
......@@ -37,15 +44,6 @@ from commonPy.recursiveMapper import RecursiveMapper
import commonPy.verify
__doc__ = '''\
This is one of the code generators that Semantix developed for
the European research project ASSERT. It is now enhanced in the
context of Data Modelling and Data Modelling Tuning projects.
It reads the ASN.1 specification of the exchanged messages, and
generates "printer" functions for their content.
'''
def usage():
'''Print usage instructions.'''
......@@ -62,7 +60,7 @@ class Printer(RecursiveMapper):
self.uniqueID += 1 if self.uniqueID != 385 else 2
return self.uniqueID
def MapInteger(self, srcCVariable, empty, _, __, ___):
def MapInteger(self, srcCVariable, unused, _, __, ___):
lines = []
lines.append('#if WORD_SIZE==8')
lines.append('printf("%%lld", %s);' % srcCVariable)
......@@ -71,13 +69,13 @@ class Printer(RecursiveMapper):
lines.append('#endif')
return lines
def MapReal(self, srcCVariable, empty, _, __, ___):
def MapReal(self, srcCVariable, unused, _, __, ___):
return ['printf("%%f", %s);' % srcCVariable]
def MapBoolean(self, srcCVariable, empty, _, __, ___):
def MapBoolean(self, srcCVariable, unused, _, __, ___):
return ['printf("%%s", (int)%s?"TRUE":"FALSE");' % srcCVariable]
def MapOctetString(self, srcCVariable, empty, node, __, ___):
def MapOctetString(self, srcCVariable, unused, node, __, ___):
lines = []
lines.append("{")
lines.append(" int i;")
......@@ -89,7 +87,7 @@ class Printer(RecursiveMapper):
lines.append("}\n")
return lines
def MapEnumerated(self, srcCVariable, empty, node, __, ___):
def MapEnumerated(self, srcCVariable, unused, node, __, ___):
lines = []
lines.append("switch(%s) {" % srcCVariable)
for d in node._members:
......@@ -130,12 +128,14 @@ class Printer(RecursiveMapper):
"%sif (%s.kind == %s) {" %
(self.maybeElse(childNo), srcCVariable, self.CleanName(child[2])))
lines.append(" printf(\"%s:\");" % child[0]) # Choices need the field name printed
lines.extend([' '+x for x in self.Map(
"%s.u.%s" % (srcCVariable, self.CleanName(child[0])),
prefix + "::" + self.CleanName(child[0]),
child[1],
leafTypeDict,
names)])
lines.extend(
[' '+x
for x in self.Map(
"%s.u.%s" % (srcCVariable, self.CleanName(child[0])),
prefix + "::" + self.CleanName(child[0]),
child[1],
leafTypeDict,
names)])
lines.append("}")
return lines
......@@ -149,12 +149,14 @@ class Printer(RecursiveMapper):
lines.append(" for(i%s=0; i%s<%s; i%s++) {" % (uniqueId, uniqueId, limit, uniqueId))
lines.append(" if (i%s) " % uniqueId)
lines.append(" printf(\",\");")
lines.extend([" " + x for x in self.Map(
"%s.arr[i%s]" % (srcCVariable, uniqueId),
prefix + "::Elem",
node._containedType,
leafTypeDict,
names)])
lines.extend(
[" "+x
for x in self.Map(
"%s.arr[i%s]" % (srcCVariable, uniqueId),
prefix + "::Elem",
node._containedType,
leafTypeDict,
names)])
lines.append(" }")
lines.append(" printf(\"}\");")
lines.append("}")
......@@ -192,7 +194,7 @@ def main():
ParseAsnFileList(sys.argv[1:])
Triples = Tuple[AST_Lookup, List[AsnNode], AST_Leaftypes] # NOQA pylint: disable=unused-variable
Triples = Tuple[AST_Lookup, List[AsnNode], AST_Leaftypes] # NOQA pylint: disable=unused-variable,invalid-sequence-index
uniqueASNfiles = {} # type: Dict[Filename, Triples]
for asnFile in uniqueASNfiles:
......@@ -250,7 +252,7 @@ def main():
inform("Processing %s...", nodeTypename)
# First, make sure we know what leaf type this node is
assert(nodeTypename in leafTypeDict)
assert nodeTypename in leafTypeDict
C_HeaderFile.write('void PrintASN1%s(const char *paramName, const asn1Scc%s *pData);\n' % (cleanNodeTypename, cleanNodeTypename))
C_SourceFile.write('void PrintASN1%s(const char *paramName, const asn1Scc%s *pData)\n{\n' % (cleanNodeTypename, cleanNodeTypename))
......@@ -275,7 +277,9 @@ def main():
if __name__ == "__main__":
if "-pdb" in sys.argv:
sys.argv.remove("-pdb") # pragma: no cover
import pdb # pragma: no cover
import pdb # pragma: no cover pylint: disable=wrong-import-position,wrong-import-order
pdb.run('main()') # pragma: no cover
else:
main()
# vim: set expandtab ts=8 sts=4 shiftwidth=4
......@@ -38,31 +38,31 @@ def OnStartup(unused_modelingLanguage, asnFile, outputDir, unused_badTypes):
g_outputDir = outputDir
def OnBasic(nodeTypename, node, leafTypeDict):
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSequence(nodeTypename, node, leafTypeDict):
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSet(nodeTypename, node, leafTypeDict):
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnEnumerated(nodeTypename, node, leafTypeDict):
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSequenceOf(nodeTypename, node, leafTypeDict):
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSetOf(nodeTypename, node, leafTypeDict):
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnChoice(nodeTypename, node, leafTypeDict):
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
# obsolete, now the grammar is re-created from the AST (PrintGrammarFromAST)
......
......@@ -457,11 +457,8 @@ def DumpTypeDumper(codeIndent, outputIndent, lines, variableName, node, names):
def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict: AST_Leaftypes):
node = names[nodeTypename]
name = CleanNameAsPythonWants(nodeTypename)
if isinstance(node, AsnBasicNode) or isinstance(node, AsnEnumerated) or \
isinstance(node, AsnSequence) or isinstance(node, AsnSet) or \
isinstance(node, AsnChoice) or isinstance(node, AsnSequenceOf) or \
isinstance(node, AsnSetOf):
if isinstance(node, (AsnBasicNode, AsnEnumerated, AsnSequence, AsnSet,
AsnChoice, AsnSequenceOf, AsnSetOf)):
g_outputFile.write("class " + name + "(COMMON):\n")
if isinstance(node, AsnEnumerated):
g_outputFile.write(" # Allowed enumerants:\n")
......
......@@ -89,31 +89,31 @@ def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
CreateDeclarationsForAllTypes(commonPy.asnParser.g_names, commonPy.asnParser.g_leafTypeDict)
def OnBasic(nodeTypename, node, leafTypeDict):
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnSequence(nodeTypename, node, leafTypeDict):
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnSet(nodeTypename, node, leafTypeDict):
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnEnumerated(nodeTypename, node, leafTypeDict):
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnSequenceOf(nodeTypename, node, leafTypeDict):
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnSetOf(nodeTypename, node, leafTypeDict):
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnChoice(nodeTypename, node, leafTypeDict):
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
......
......@@ -68,31 +68,31 @@ def OnStartup(unused_modelingLanguage, unused_asnFile, outputDir, unused_badType
CreateDeclarationsForAllTypes(commonPy.asnParser.g_names, commonPy.asnParser.g_leafTypeDict)
def OnBasic(nodeTypename, node, leafTypeDict):
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSequence(nodeTypename, node, leafTypeDict):
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSet(nodeTypename, node, leafTypeDict):
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnEnumerated(nodeTypename, node, leafTypeDict):
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSequenceOf(nodeTypename, node, leafTypeDict):
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnSetOf(nodeTypename, node, leafTypeDict):
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnChoice(nodeTypename, node, leafTypeDict):
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
......
......@@ -38,31 +38,31 @@ def OnStartup(unused_modelingLanguage, asnFile, outputDir, unused_badTypes):
g_outputDir = outputDir
def OnBasic(nodeTypename, node, leafTypeDict):
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSequence(nodeTypename, node, leafTypeDict):
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSet(nodeTypename, node, leafTypeDict):
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnEnumerated(nodeTypename, node, leafTypeDict):
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSequenceOf(nodeTypename, node, leafTypeDict):
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSetOf(nodeTypename, node, leafTypeDict):
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: no cover
def OnChoice(nodeTypename, node, leafTypeDict):
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
......
......@@ -27,8 +27,8 @@ import re
import os
import random
from xml.dom.minidom import Document, Node # NOQA
from typing import Set # NOQA
from xml.dom.minidom import Document, Node # type: ignore # NOQA pylint: disable=unused-import
from typing import Set # NOQA pylint: disable=unused-import
from commonPy.utility import inform, panic
from commonPy.asnAST import (
......@@ -67,11 +67,11 @@ def Version():
print("Code generator: " + "$Id: scade612_A_mapper.py 1842 2010-03-10 14:16:42Z ttsiodras $") # pragma: no cover
def CleanNameAsScadeWants(name):
def CleanNameAsScadeWants(name: str) -> str:
return re.sub(r'[^a-zA-Z0-9_]', '_', name)
def RandomHex(digits):
def RandomHex(digits: int) -> str:
result = ""
for _ in range(0, digits):
result += random.choice('0123456789abcdef')
......@@ -86,23 +86,23 @@ def FixupNestedStringsAndEnumerated():
if isinstance(node, (AsnSequence, AsnChoice, AsnSet)):
for child in node._members:
if isinstance(child[1], AsnString) or isinstance(child[1], AsnEnumerated):
newName = nodeTypename + "_" + child[0] # pragma: no cover
while newName in names: # pragma: no cover
newName += "_t" # pragma: no cover
names[newName] = child[1] # pragma: no cover
leafTypeDict[newName] = isinstance(child[1], AsnString) and 'OCTET STRING' or 'ENUMERATED' # pragma: no cover
child[1] = AsnMetaMember(asnFilename=child[1]._asnFilename, containedType=newName) # pragma: no cover
newName = nodeTypename + "_" + child[0] # pragma: no cover
while newName in names: # pragma: no cover
newName += "_t" # pragma: no cover
names[newName] = child[1] # pragma: no cover
leafTypeDict[newName] = 'OCTET STRING' if isinstance(child[1], AsnString) else 'ENUMERATED' # pragma: no cover
child[1] = AsnMetaMember(asnFilename=child[1]._asnFilename, containedType=newName) # pragma: no cover
elif isinstance(node, (AsnSequenceOf, AsnSetOf)):
if isinstance(node._containedType, (AsnString, AsnEnumerated)):
newName = nodeTypename + "_contained" # pragma: no cover
while newName in names: # pragma: no cover
newName += "_t" # pragma: no cover
names[newName] = node._containedType # pragma: no cover
leafTypeDict[newName] = isinstance(node._containedType, AsnString) and 'OCTET STRING' or 'ENUMERATED' # pragma: no cover
node._containedType = newName # pragma: no cover
newName = nodeTypename + "_contained" # pragma: no cover
while newName in names: # pragma: no cover
newName += "_t" # pragma: no cover
names[newName] = node._containedType # pragma: no cover
leafTypeDict[newName] = 'OCTET STRING' if isinstance(node._containedType, AsnString) else 'ENUMERATED' # pragma: no cover
node._containedType = newName # pragma: no cover
def OnStartup(unused_modelingLanguage, asnFile, outputDir, unused_badTypes):
def OnStartup(unused_modelingLanguage, asnFile: str, outputDir: str, unused_badTypes) -> None:
outputFilename = CleanNameAsScadeWants(os.path.basename(os.path.splitext(asnFile)[0])) + ".xscade"
FixupNestedStringsAndEnumerated()
......@@ -135,7 +135,7 @@ def RenderElements(controlString: str):
if controlString.endswith(","):
controlString = controlString[:-1]
createdElements = {} # type: Dict[str, Node]
parent = g_Declarations
parent = g_Declarations # type: Node
for elem in controlString.split(","):
if '`' in elem:
element = elem.split("`")[0]
......@@ -161,7 +161,7 @@ def RenderElements(controlString: str):
parent = createdElements[under]
parent.appendChild(newElement)
createdElements[finalElementName] = newElement
parent = newElement
parent = newElement # pylint: disable=redefined-variable-type
def GetOID(nodeTypename):
......
......@@ -64,31 +64,31 @@ def OnStartup(unused_modelingLanguage, unused_asnFile, outputDir, unused_badType
CreateDeclarationsForAllTypes(commonPy.asnParser.g_names, commonPy.asnParser.g_leafTypeDict)
def OnBasic(nodeTypename, node, leafTypeDict):
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSequence(nodeTypename, node, leafTypeDict):
def OnSequence(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSet(nodeTypename, node, leafTypeDict):
def OnSet(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnEnumerated(nodeTypename, node, leafTypeDict):
def OnEnumerated(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSequenceOf(nodeTypename, node, leafTypeDict):
def OnSequenceOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
def OnSetOf(nodeTypename, node, leafTypeDict):
def OnSetOf(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass # pragma: nocover
def OnChoice(nodeTypename, node, leafTypeDict):
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
pass
......
......@@ -41,7 +41,7 @@ def Version():
print("Code generator: " + "$Id: smp2_A_mapper.py 1932 2010-06-15 13:41:15Z ttsiodras $") # pragma: no cover
def getUID(strIdentifier, idStore={}):
def getUID(strIdentifier, idStore={}): # pylint: disable=dangerous-default-value
def h(digits):
ret = ""
for _ in range(0, digits):
......@@ -61,13 +61,14 @@ def FixupAstForSMP2():
and make sure the contained types are not "naked" (i.e. unnamed)
'''
internalNo = 1
addedNewPseudoType = True
while addedNewPseudoType:
def neededToAddPseudoType():
nonlocal internalNo
addedNewPseudoType = False
listOfTypenames = sorted(list(g_names.keys()) + list(g_innerTypes.keys()))
for nodeTypename in listOfTypenames:
node = g_names[nodeTypename]
if isinstance(node, AsnChoice) or isinstance(node, AsnSequence) or isinstance(node, AsnSet):
if isinstance(node, (AsnChoice, AsnSequence, AsnSet)):
for child in node._members:
if not isinstance(child[1], AsnMetaMember):
internalName = newname = "TaStE_" + CleanNameForAST(child[0].capitalize() + "_type")
......@@ -85,7 +86,7 @@ def FixupAstForSMP2():