Commit 6369e391 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

B_mappers done, adding type specs to A_mappers now.

parent a9d13f08
......@@ -29,6 +29,8 @@ 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():
......@@ -51,31 +53,31 @@ def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str,
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
......
......@@ -29,6 +29,8 @@ 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() -> None:
......@@ -55,33 +57,33 @@ def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str,
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
......@@ -25,6 +25,8 @@
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 = ""
......@@ -41,31 +43,31 @@ def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, unused
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)
......
......@@ -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)
......
......@@ -30,13 +30,17 @@ import sys
import re
import distutils.spawn as spawn
from typing import List
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, AsnNode)
from ..commonPy.asnParser import AST_Leaftypes, AST_Lookup
# The file written to
g_outputFile = None
......@@ -49,11 +53,11 @@ 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)
......@@ -91,39 +95,39 @@ def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str,
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:
......@@ -138,15 +142,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'
......@@ -167,7 +170,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))
......@@ -193,7 +196,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)
......@@ -227,7 +230,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
......@@ -290,11 +293,11 @@ 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]
......@@ -321,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)
......@@ -29,9 +29,11 @@ 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.createInternalTypes import ScanChildren
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import AST_Leaftypes
# The file written to
g_outputFile = None
......@@ -72,31 +74,31 @@ def OnStartup(unused_modelingLanguage: str, unused_asnFiles: List[str], outputDi
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
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: nocover
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
......
......@@ -25,6 +25,7 @@ import re
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import AST_Leaftypes, AsnNode
from ..commonPy.asnAST import AsnSequenceOrSet, AsnSequenceOrSetOf, AsnEnumerated, AsnChoice
g_outputDir = ""
g_asnFile = ""
......@@ -45,27 +46,27 @@ def OnBasic(unused_nodeTypename: str, unused_node: AsnNode, unused_leafTypeDict:
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: no cover
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: no cover
def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
def OnChoice(unused_nodeTypename: str, unused_node: AsnChoice, unused_leafTypeDict: AST_Leaftypes) -> None:
pass
......@@ -85,7 +86,7 @@ def OnChoice(unused_nodeTypename, unused_node, unused_leafTypeDict):
# outputText += c
# 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)
......
......@@ -33,10 +33,12 @@ from typing import Set # NOQA pylint: disable=unused-import
from ..commonPy.utility import inform, panic
from ..commonPy.asnAST import (
AsnBasicNode, AsnString, AsnEnumerated, AsnMetaMember, AsnSet,
AsnSetOf, AsnSequence, AsnSequenceOf, AsnChoice
AsnSetOf, AsnSequence, AsnSequenceOf, AsnChoice,
AsnSequenceOrSet, AsnSequenceOrSetOf
)
from ..commonPy import asnParser
from ..commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import AST_Leaftypes
g_lookup = {
"INTEGER": "int",
......@@ -220,7 +222,7 @@ def HandleTypedef(nodeTypename: str) -> bool:
return True
def OnBasic(nodeTypename, node, unused_leafTypeDict):
def OnBasic(nodeTypename: str, node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
assert isinstance(node, AsnBasicNode)
if nodeTypename in g_declaredTypes:
return
......@@ -283,11 +285,11 @@ def OnSequence(nodeTypename, node, unused_leafTypeDict, isChoice=False):
RenderElements(controlString)
def OnSet(nodeTypename, node, leafTypeDict):
def OnSet(nodeTypename: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes) -> None:
OnSequence(nodeTypename, node, leafTypeDict) # pragma: nocover
def OnEnumerated(nodeTypename, node, unused_leafTypeDict):
def OnEnumerated(nodeTypename: str, node: AsnEnumerated, unused_leafTypeDict: AST_Leaftypes) -> None:
if nodeTypename in g_declaredTypes:
return
g_declaredTypes.add(nodeTypename)
......@@ -316,7 +318,7 @@ def OnEnumerated(nodeTypename, node, unused_leafTypeDict):
RenderElements(controlString)
def OnSequenceOf(nodeTypename, node, unused_leafTypeDict):
def OnSequenceOf(nodeTypename: str, node: AsnSequenceOrSetOf, unused_leafTypeDict: AST_Leaftypes) -> None:
if nodeTypename in g_declaredTypes:
return
g_declaredTypes.add(nodeTypename)
......@@ -341,11 +343,11 @@ def OnSequenceOf(nodeTypename, node, unused_leafTypeDict):