Commit 1ae5d468 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

More type annotations

parent cb91936e
...@@ -23,22 +23,25 @@ to RTDS. It is used by the backend of Semantix's code generator A.''' ...@@ -23,22 +23,25 @@ to RTDS. It is used by the backend of Semantix's code generator A.'''
import re import re
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import AST_Leaftypes, AsnNode
g_outputDir = "" g_outputDir = ""
g_asnFile = "" g_asnFile = ""
def Version(): def Version() -> None:
print("Code generator: " + "$Id: og_A_mapper.py 1879 2010-05-17 10:13:12Z ttsiodras $") # pragma: no cover print("Code generator: " + "$Id: og_A_mapper.py 1879 2010-05-17 10:13:12Z 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 global g_asnFile
g_asnFile = asnFile g_asnFile = asnFile
global g_outputDir global g_outputDir
g_outputDir = outputDir g_outputDir = outputDir
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict): def OnBasic(unused_nodeTypename: str, unused_node: AsnNode, unused_leafTypeDict: AST_Leaftypes) -> None:
pass pass
......
...@@ -23,6 +23,9 @@ import os ...@@ -23,6 +23,9 @@ import os
from typing import Set, Dict # NOQA pylint: disable=unused-import from typing import Set, Dict # NOQA pylint: disable=unused-import
from ..commonPy.aadlAST import ApLevelContainer, Param
from ..commonPy.asnParser import AST_Leaftypes, AST_Lookup, AsnNode
g_HeaderFile = None g_HeaderFile = None
g_SourceFile = None g_SourceFile = None
g_PythonFile = None g_PythonFile = None
...@@ -37,15 +40,22 @@ g_asn_name = "" ...@@ -37,15 +40,22 @@ g_asn_name = ""
g_outputDir = "" g_outputDir = ""
g_maybeFVname = "" g_maybeFVname = ""
g_perFV = set() # type: Set[str] g_perFV = set() # type: Set[str]
g_langPerSP = {} # type: Dict[str, str] g_langPerSP = {} # type: Dict[ApLevelContainer, str]
def CleanName(name): def CleanName(name: str) -> str:
return re.sub(r'[^a-zA-Z0-9_]', '_', name) return re.sub(r'[^a-zA-Z0-9_]', '_', name)
# Called once per RI (i.e. per SUBPROGRAM IMPLEMENTATION) # Called once per RI (i.e. per SUBPROGRAM IMPLEMENTATION)
def OnStartup(modelingLanguage, asnFile, subProgram, unused_subProgramImplementation, outputDir, maybeFVname, unused_useOSS): def OnStartup(
modelingLanguage: str,
asnFile: str,
subProgram: ApLevelContainer,
unused_subProgramImplementation: str,
outputDir: str,
maybeFVname: str,
unused_useOSS: bool) -> None:
g_langPerSP[subProgram] = modelingLanguage g_langPerSP[subProgram] = modelingLanguage
CleanSP = CleanName(subProgram._id) CleanSP = CleanName(subProgram._id)
...@@ -227,7 +237,7 @@ def OnStartup(modelingLanguage, asnFile, subProgram, unused_subProgramImplementa ...@@ -227,7 +237,7 @@ def OnStartup(modelingLanguage, asnFile, subProgram, unused_subProgramImplementa
g_SourceFile.write('}\n') g_SourceFile.write('}\n')
def Common(unused_nodeTypename, unused_node, unused_subProgram, unused_subProgramImplementation, unused_param, unused_leafTypeDict, unused_names): def Common(unused_nodeTypename: str, unused_node: AsnNode, unused_subProgram: ApLevelContainer, unused_subProgramImplementation: str, unused_param: Param, unused_leafTypeDict: AST_Leaftypes, unused_names: AST_Lookup) -> None:
pass pass
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
# #
# Charge for Runtimes None None # Charge for Runtimes None None
from typing import Tuple, Dict # NOQA pylint: disable=unused-import from typing import Tuple, Union, Dict, Any # NOQA pylint: disable=unused-import
g_apLevelContainers = {} # type: Dict[str, ApLevelContainer] g_apLevelContainers = {} # type: Dict[str, ApLevelContainer]
...@@ -49,102 +49,106 @@ g_threadImplementations = [] # type: List[Tuple[str,str,str,str]] ...@@ -49,102 +49,106 @@ g_threadImplementations = [] # type: List[Tuple[str,str,str,str]]
class AadlParameter: class AadlParameter:
def __init__(self, direction, typ): def __init__(self, direction: str, typ: str) -> None:
assert direction in ['IN', 'OUT', 'INOUT'] assert direction in ['IN', 'OUT', 'INOUT']
self._direction = direction self._direction = direction
self._type = typ self._type = typ
class AadlSubProgramFeature: class AadlSubProgramFeature:
def __init__(self, iid, parameter): def __init__(self, iid: str, parameter: AadlParameter) -> None:
self._id = iid self._id = iid
self._parameter = parameter self._parameter = parameter
class AadlPropertyAssociationNoModes: class AadlPropertyAssociationNoModes:
def __init__(self, name, pe): def __init__(self, name: str, pe: Any) -> None:
self._name = name self._name = name
self._propertyExpressionOrList = pe self._propertyExpressionOrList = pe
class AadlPort: class AadlPort:
def __init__(self, direction, typ): def __init__(self, direction: str, typ: str) -> None:
self._direction = direction self._direction = direction
self._type = typ self._type = typ
class AadlEventPort: class AadlEventPort:
def __init__(self, direction, sp): def __init__(self, direction: str, sp: 'ApLevelContainer') -> None:
self._direction = direction self._direction = direction
self._sp = sp self._sp = sp
def __repr__(self): def __repr__(self) -> str:
result = "AadlEventPort(" + self._direction + "," result = "AadlEventPort(" + self._direction + ","
if self._sp: if self._sp:
result += self._sp result += str(self._sp)
result += ")" result += ")"
return result return result
class AadlEventDataPort(AadlPort): class AadlEventDataPort(AadlPort):
def __init__(self, direction, typ): def __init__(self, direction: str, typ: str) -> None:
AadlPort.__init__(self, direction, typ) AadlPort.__init__(self, direction, typ)
class AadlThreadFeature: class AadlThreadFeature:
def __init__(self, iid, port): def __init__(self, iid: str, port: AadlPort) -> None:
assert isinstance(port, AadlPort) assert isinstance(port, AadlPort)
self._id = iid self._id = iid
self._port = port self._port = port
class AadlProcessFeature: class AadlProcessFeature:
def __init__(self, iid, port): def __init__(self, iid: str, port: AadlPort) -> None:
assert isinstance(port, AadlPort) assert isinstance(port, AadlPort)
self._id = iid self._id = iid
self._port = port self._port = port
class AadlContainedPropertyAssociation: class AadlContainedPropertyAssociation:
def __init__(self, name, value): def __init__(self, name: str, value: Any) -> None:
self._name = name self._name = name
self._value = value self._value = value
class Signal: class Signal:
def __init__(self, asnFilename, asnNodename, asnSize): def __init__(self, asnFilename: str, asnNodename: str, asnSize: int) -> None:
self._asnFilename = asnFilename self._asnFilename = asnFilename
self._asnNodename = asnNodename self._asnNodename = asnNodename
self._asnSize = asnSize self._asnSize = asnSize
class Port: # class Port:
def __init__(self, signal): # def __init__(self, signal):
self._signal = signal # self._signal = signal
#
#
class DualPort(Port): # class DualPort(Port):
def __init__(self, signal): # def __init__(self, signal):
Port.__init__(self, signal) # Port.__init__(self, signal)
#
#
class UniPort(Port): # class UniPort(Port):
def __init__(self, signal): # def __init__(self, signal):
Port.__init__(self, signal) # Port.__init__(self, signal)
#
#
class IncomingUniPort(UniPort): # class IncomingUniPort(UniPort):
def __init__(self, signal): # def __init__(self, signal):
UniPort.__init__(self, signal) # UniPort.__init__(self, signal)
#
#
class OutgoingUniPort(UniPort): # class OutgoingUniPort(UniPort):
def __init__(self, signal): # def __init__(self, signal):
UniPort.__init__(self, signal) # UniPort.__init__(self, signal)
class Param: class Param:
def __init__(self, aplcID, iid, signal, sourceElement): def __init__(self,
aplcID: str,
iid: str,
signal: Signal,
sourceElement: Union[AadlPort, AadlEventDataPort, AadlParameter]) -> None:
self._id = iid self._id = iid
# It is the Process, Thread or Subprogram ID # It is the Process, Thread or Subprogram ID
self._aplcID = aplcID self._aplcID = aplcID
...@@ -154,48 +158,60 @@ class Param: ...@@ -154,48 +158,60 @@ class Param:
class InParam(Param): class InParam(Param):
def __init__(self, aplcID, iid, signal, sourceElement): def __init__(self,
aplcID: str,
iid: str,
signal: Signal,
sourceElement: Union[AadlPort, AadlEventDataPort, AadlParameter]) -> None:
Param.__init__(self, aplcID, iid, signal, sourceElement) Param.__init__(self, aplcID, iid, signal, sourceElement)
class OutParam(Param): class OutParam(Param):
def __init__(self, aplcID, iid, signal, sourceElement): def __init__(self,
aplcID: str,
iid: str,
signal: Signal,
sourceElement: Union[AadlPort, AadlEventDataPort, AadlParameter]) -> None:
Param.__init__(self, aplcID, iid, signal, sourceElement) Param.__init__(self, aplcID, iid, signal, sourceElement)
class InOutParam(Param): class InOutParam(Param):
def __init__(self, aplcID, iid, signal, sourceElement): def __init__(self,
aplcID: str,
iid: str,
signal: Signal,
sourceElement: Union[AadlPort, AadlEventDataPort, AadlParameter]) -> None:
Param.__init__(self, aplcID, iid, signal, sourceElement) Param.__init__(self, aplcID, iid, signal, sourceElement)
class UniquePortIdentifier:
def __init__(self, componentId: str, portId: str) -> None:
self._componentId = componentId
self._portId = portId
class ApLevelContainer: class ApLevelContainer:
def __init__(self, iid): def __init__(self, iid: str) -> None:
self._id = iid self._id = iid
self._params = [] # type: List[Param] self._params = [] # type: List[Param]
self._connections = [] # type: List[Connection] self._connections = [] # type: List[Connection]
self._language = None # type: str self._language = None # type: str
def AddConnection(self, srcUniquePortId, destUniquePortId): def AddConnection(self, srcUniquePortId: UniquePortIdentifier, destUniquePortId: UniquePortIdentifier) -> None:
if srcUniquePortId._componentId is None: if srcUniquePortId._componentId is None:
srcUniquePortId._componentId = self._id srcUniquePortId._componentId = self._id
if destUniquePortId._componentId is None: if destUniquePortId._componentId is None:
destUniquePortId._componentId = self._id destUniquePortId._componentId = self._id
self._connections.append(Connection(srcUniquePortId, destUniquePortId)) self._connections.append(Connection(srcUniquePortId, destUniquePortId))
def AddParam(self, param: Param): def AddParam(self, param: Param) -> None:
self._params.append(param) self._params.append(param)
def SetLanguage(self, language: str): def SetLanguage(self, language: str) -> None:
self._language = language self._language = language
class UniquePortIdentifier:
def __init__(self, componentId, portId):
self._componentId = componentId
self._portId = portId
class Connection: class Connection:
def __init__(self, fromC, toC): def __init__(self, fromC: UniquePortIdentifier, toC: UniquePortIdentifier) -> None:
self._from = fromC self._from = fromC
self._to = toC self._to = toC
This diff is collapsed.
...@@ -43,17 +43,17 @@ import re ...@@ -43,17 +43,17 @@ import re
import platform import platform
import traceback import traceback
from typing import Dict, Union, Match # NOQA pylint: disable=unused-import from typing import Dict, Union, Match, Any # NOQA pylint: disable=unused-import
from . import configMT from . import configMT
def inform(fmt: str, *args) -> None: def inform(fmt: str, *args: Any) -> None:
if configMT.verbose: if configMT.verbose:
print(fmt % args) print(fmt % args)
def warn(fmt: str, *args) -> None: def warn(fmt: str, *args: Any) -> None:
sys.stderr.write(("WARNING: " + fmt) % args) sys.stderr.write(("WARNING: " + fmt) % args)
sys.stderr.write("\n") sys.stderr.write("\n")
...@@ -108,42 +108,42 @@ def readContexts(tapNumbers: str) -> Dict[str, str]: ...@@ -108,42 +108,42 @@ def readContexts(tapNumbers: str) -> Dict[str, str]:
class Matcher: class Matcher:
def __init__(self, pattern, flags=0): def __init__(self, pattern: str, flags: Any=0) -> None:
self._pattern = re.compile(pattern, flags) self._pattern = re.compile(pattern, flags)
self._lastOne = None # type: Union[str, None] self._lastOne = None # type: Union[str, None]
self._match = None # type: Union[Match, None] self._match = None # type: Union[Match, None]
self._search = None # type: Union[Match, None] self._search = None # type: Union[Match, None]
def match(self, line): def match(self, line: str) -> Match:
self._match = re.match(self._pattern, line) self._match = re.match(self._pattern, line)
self._lastOne = 'Match' self._lastOne = 'Match'
return self._match return self._match
def search(self, line): def search(self, line: str) -> Match:
self._search = re.search(self._pattern, line) self._search = re.search(self._pattern, line)
self._lastOne = 'Search' self._lastOne = 'Search'
return self._search return self._search
def group(self, idx): def group(self, idx: int) -> str:
if self._lastOne == 'Match': if self._lastOne == 'Match':
return self._match.group(idx) return self._match.group(idx)
elif self._lastOne == 'Search': elif self._lastOne == 'Search':
return self._search.group(idx) return self._search.group(idx)
else: else:
return panic( panic(
"Matcher group called with index " "Matcher group called with index "
"%d before match/search!\n" % idx) "%d before match/search!\n" % idx)
def groups(self): def groups(self) -> Any:
if self._lastOne == 'Match': if self._lastOne == 'Match':
return self._match.groups() return self._match.groups()
elif self._lastOne == 'Search': elif self._lastOne == 'Search':
return self._search.groups() return self._search.groups()
else: else:
return panic("Matcher groups called with match/search!\n") panic("Matcher groups called with match/search!\n")
def mysystem(cmd): def mysystem(cmd: str) -> int:
p = platform.system() p = platform.system()
if p == "Windows" or p.startswith("CYGWIN"): if p == "Windows" or p.startswith("CYGWIN"):
return os.system('"' + cmd + '"') return os.system('"' + cmd + '"')
......
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