Commit d5c9012d authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files

Use bleeding edge of all Static Analysis tools.

- Dead code removed.
- Improve typing.
- Latest Mypy pass.
- Latest Pylint pass.
- Latest Flake8 pass.
parent 0e5f6db8
......@@ -25,7 +25,7 @@ flake8:
pylint:
@echo Performing static analysis via pylint...
@pylint --disable=I --rcfile=pylint.cfg ${PY_SRC} | grep -v '^$$' | sed -n '/^Report/q;p'
@pylint --disable=I --rcfile=pylint.cfg ${PY_SRC}
mypy:
@echo Performing type analysis via mypy...
......
......@@ -8,7 +8,7 @@
import re
import os
from typing import Union, List # NOQA pylint: disable=unused-import
from typing import Union, List, IO, Any # NOQA pylint: disable=unused-import
from ..commonPy import asnParser
from ..commonPy.utility import panic, inform
......@@ -21,11 +21,11 @@ from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
from ..commonPy.cleanupNodes import SetOfBadTypenames
# The Python file written to
g_outputFile = None
g_outputFile: IO[Any]
# The SETers and GETers files
g_outputGetSetH = None
g_outputGetSetC = None
g_outputGetSetH: IO[Any]
g_outputGetSetC: IO[Any]
g_bHasStartupRunOnce = False
......
......@@ -30,7 +30,7 @@ import sys
import re
from distutils import spawn
from typing import List, Union, Set # NOQA
from typing import List, Union, Set, IO, Any # NOQA
from ..commonPy import asnParser
from ..commonPy.utility import panic, inform
......@@ -44,7 +44,7 @@ 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
g_outputFile: IO[Any]
# A map of the ASN.1 types defined so far
g_definedTypes = set() # type: Set[asnParser.Typename]
......
......@@ -23,7 +23,7 @@
#
import re
from typing import Union, Set, List # NOQA pylint: disable=unused-import
from typing import Union, Set, List, IO, Any # NOQA pylint: disable=unused-import
from ..commonPy.utility import panic, inform
from ..commonPy import asnParser
......@@ -37,7 +37,7 @@ from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import AST_Leaftypes, AST_Lookup
# The file written to
g_outputFile = None
g_outputFile: IO[Any]
# A map of the ASN.1 types defined so far
g_definedTypes = set() # type: Set[asnParser.Typename]
......
......@@ -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 Union, Set, Dict # NOQA pylint: disable=unused-import
from typing import Optional, Union, Set, Dict, IO, Any # NOQA pylint: disable=unused-import
from ..commonPy.utility import inform, panic
from ..commonPy.asnAST import (
......@@ -47,7 +47,7 @@ g_lookup = {
}
# The file written to
g_outputFile = None
g_outputFile: IO[Any]
# The assigned OIDs
g_oid = {} # type: Dict[str, str]
......@@ -62,7 +62,7 @@ g_currOid = 0x1f00
g_declaredTypes = set() # type: Set[str]
# The DOM elements
g_doc = None
g_doc: Document
g_Declarations = None
......@@ -142,7 +142,7 @@ def RenderElements(controlString: str) -> None:
for elem in controlString.split(","):
if '`' in elem:
element = elem.split("`")[0]
under = elem.split("`")[1]
under = elem.split("`")[1] # type: Optional[str]
else:
element = elem
under = None
......
......@@ -20,7 +20,7 @@
#
import re
from typing import Union, Set, List # NOQA pylint: disable=unused-import
from typing import Union, Set, List, IO, Any # NOQA pylint: disable=unused-import
from ..commonPy.utility import panic, inform
from ..commonPy import asnParser
......@@ -35,7 +35,7 @@ from ..commonPy.cleanupNodes import SetOfBadTypenames
# The file written to
g_outputFile = None
g_outputFile: IO[Any]
# A map of the ASN.1 types defined so far
g_definedTypes = set() # type: Set[str]
......
......@@ -34,11 +34,11 @@ from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnAST import AsnBasicNode, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnEnumerated
from ..commonPy.asnParser import AST_Leaftypes
g_catalogueXML = None # type: IO[Any]
g_catalogueXML: IO[Any]
g_innerTypes = set() # type: Set[str]
g_uniqueStringOfASN1files = ""
g_outputDir = "."
g_asnFiles = None
g_asnFiles: List[str]
def Version() -> None:
......
......@@ -35,11 +35,11 @@ from ..commonPy.utility import panic, warn
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import AST_Leaftypes
g_sqlOutput = None # type: IO[Any]
g_sqlOutput: IO[Any]
g_innerTypes = set() # type: Set[str]
g_uniqueStringOfASN1files = ""
g_outputDir = "."
g_asnFiles = None
g_asnFiles: List[str]
# ====== Dummy stubs =====
......
......@@ -34,11 +34,11 @@ from ..commonPy.asnParser import g_names, g_leafTypeDict, CleanNameForAST, AST_L
from ..commonPy.utility import panic, warn
from ..commonPy.cleanupNodes import SetOfBadTypenames
g_sqlalchemyOutput = None # type: IO[Any]
g_sqlalchemyOutput: IO[Any]
g_innerTypes = {} # type: Dict[str, int]
g_uniqueStringOfASN1files = ""
g_outputDir = "."
g_asnFiles = None # type: Union[str, List[str]]
g_asnFiles: Union[str, List[str]]
# ====== Dummy stubs =====
......
......@@ -45,7 +45,7 @@ from ..commonPy.asnAST import AsnNode
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
isAsynchronous = True
cBackend = None
cBackend: c_B_mapper.C_GlueGenerator
def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
......
......@@ -73,11 +73,9 @@ class ASynchronousToolGlueGenerator:
def __init__(self) -> None:
# The files written to
self.C_HeaderFile = None # type: IO[Any]
self.C_SourceFile = None # type: IO[Any]
self.asn_name = ""
self.supportedEncodings = ['native', 'uper', 'acn']
self.useOSS = None # type: bool
self.useOSS = False
self.typesToWorkOn = {} # type: Dict[str, Tuple[AsnNode, AST_Leaftypes, AST_Lookup]]
def OnStartup(self, modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
......@@ -89,10 +87,10 @@ class ASynchronousToolGlueGenerator:
outputCsourceFilename = self.CleanNameAsToolWants(prefix) + "_ASN1_Types.c"
inform(str(self.__class__) + ": Creating file '%s'...", outputCheaderFilename)
self.C_HeaderFile = open(outputDir + outputCheaderFilename, 'w')
self.C_HeaderFile = open(outputDir + outputCheaderFilename, 'w') # pylint: disable=attribute-defined-outside-init
inform(str(self.__class__) + ": Creating file '%s'...", outputCsourceFilename)
self.C_SourceFile = open(outputDir + outputCsourceFilename, 'w')
self.C_SourceFile = open(outputDir + outputCsourceFilename, 'w') # pylint: disable=attribute-defined-outside-init
self.asn_name = os.path.basename(os.path.splitext(asnFile)[0])
......@@ -118,8 +116,6 @@ class ASynchronousToolGlueGenerator:
self.HeadersOnStartup(asnFile, outputDir, maybeFVname)
self.typesToWorkOn = {} # type: Dict[str, Tuple[AsnNode, AST_Leaftypes, AST_Lookup]]
def Common(self, nodeTypename: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
# Async backends are different: they work on ASN.1 types, not SP params.
......
......@@ -48,7 +48,6 @@ from ..commonPy.recursiveMapper import RecursiveMapper
from .asynchronousTool import ASynchronousToolGlueGenerator
isAsynchronous = True
cBackend = None
# noinspection PyListCreation
......@@ -429,6 +428,9 @@ class C_GlueGenerator(ASynchronousToolGlueGenerator):
self.C_SourceFile.write("#endif\n\n")
cBackend: C_GlueGenerator
def OnStartup(modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
global cBackend
cBackend = C_GlueGenerator()
......
......@@ -35,20 +35,20 @@ from ..commonPy import asnParser
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
from ..commonPy.aadlAST import ApLevelContainer, Param
g_HeaderFile = None # type: IO[Any]
g_SourceFile = None # type: IO[Any]
g_GnuplotFile = None # type: IO[Any]
g_MyEvents = None
g_MyCreation = None
g_MyClickPrototypes = None
g_MyAction = None
g_MyControls = None
g_MyLoad = None
g_MySave = None
g_MyThreadsInc = None
g_MyThreadsH = None
g_MyTelemetryActions = None
g_HeaderFile: IO[Any]
g_SourceFile: IO[Any]
g_GnuplotFile: IO[Any]
g_MyEvents: IO[Any]
g_MyCreation: IO[Any]
g_MyClickPrototypes: IO[Any]
g_MyAction: IO[Any]
g_MyControls: IO[Any]
g_MyLoad: IO[Any]
g_MySave: IO[Any]
g_MyThreadsInc: IO[Any]
g_MyThreadsH: IO[Any]
g_MyTelemetryActions: IO[Any]
g_bStarted = False
g_IDs = 20000
......
......@@ -50,7 +50,7 @@ from .c_B_mapper import C_GlueGenerator
backend_C = None
backend_uPy = None
backends = None
backends = [] # type: List[ASynchronousToolGlueGenerator]
# TODO replace most of the typedefs with an include of py/obj.h
h_header_str = """
......
......@@ -100,7 +100,6 @@ from ..commonPy.recursiveMapper import RecursiveMapper
from .asynchronousTool import ASynchronousToolGlueGenerator
isAsynchronous = True
ogBackend = None
# noinspection PyListCreation
......@@ -800,6 +799,9 @@ class OG_GlueGenerator(ASynchronousToolGlueGenerator):
# (self.CleanNameAsToolWants(nodeTypename), self.CleanNameAsToolWants(nodeTypename)))
ogBackend: OG_GlueGenerator
def OnStartup(modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
global ogBackend
ogBackend = OG_GlueGenerator()
......
......@@ -3,7 +3,7 @@
import re
import os
from typing import List
from typing import List, IO, Any
from ..commonPy.asnAST import (
AsnInt, AsnBool, AsnReal, AsnEnumerated,
......@@ -14,13 +14,13 @@ from ..commonPy.utility import panic
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
from ..commonPy.aadlAST import ApLevelContainer, Param
g_PyDataModel = None
g_PyDataModel: IO[Any]
g_iter = 1
g_IFCount = 0
g_BackendFile = None
g_BackendFile: IO[Any]
g_fromPysideToASN1 = [] # type: List[str]
g_fromASN1ToPyside = [] # type: List[str]
g_QUiFile = None
g_QUiFile: IO[Any]
g_bStarted = False # type: bool
g_firstElem = True # type: bool
g_asnId = "" # type: str
......
......@@ -279,6 +279,8 @@ def OnShutdown(unused_modelingLanguage: str, unused_asnFile: str, unused_sp: ApL
def OnFinal() -> None:
assert g_HeaderFile is not None
assert g_PythonFile is not None
g_HeaderFile.write("\n#endif\n")
g_PythonFile.write('\n'.join(g_headerPython))
g_PythonFile.write('\n\n')
......
......@@ -48,7 +48,7 @@ from ..commonPy.asnAST import AsnBasicNode, AsnSequence, AsnSet, AsnEnumerated,
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
isAsynchronous = True
cBackend = None
cBackend: c_B_mapper.C_GlueGenerator
# All the ada B mapper is now Obsolete, we are using ASN1SCC for Dumpables
......
......@@ -50,7 +50,6 @@ from ..commonPy.recursiveMapper import RecursiveMapper
from .synchronousTool import SynchronousToolGlueGenerator
isAsynchronous = False
qgencBackend = None
def IsElementMappedToPrimitive(node: AsnSequenceOrSetOf, names: AST_Lookup) -> bool:
......@@ -469,6 +468,9 @@ class QGenCGlueGenerator(SynchronousToolGlueGenerator):
self.C_SourceFile.write("#endif\n")
qgencBackend: QGenCGlueGenerator
def OnStartup(modelingLanguage: str, asnFile: str, subProgram: ApLevelContainer, subProgramImplementation: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
global qgencBackend
qgencBackend = QGenCGlueGenerator()
......
......@@ -42,8 +42,6 @@ from .asynchronousTool import ASynchronousToolGlueGenerator
from . import c_B_mapper
isAsynchronous = True
rtdsBackend = None
cBackend = None
# noinspection PyListCreation
......@@ -553,6 +551,10 @@ class RTDS_GlueGenerator(ASynchronousToolGlueGenerator):
fileOutSource.write("\n}\n\n")
rtdsBackend: RTDS_GlueGenerator
cBackend: c_B_mapper.C_GlueGenerator
def OnStartup(modelingLanguage: str, asnFile: str, outputDir: str, maybeFVname: str, useOSS: bool) -> None:
global rtdsBackend
rtdsBackend = RTDS_GlueGenerator()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment