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

Remove obsolete Ada B mapper parts; add more type annotations

parent 0bdd5e1f
......@@ -49,268 +49,11 @@ cBackend = None
def Version():
print("Code generator: " + "$Id: ada_B_mapper.py 2382 2012-06-22 08:35:33Z ttsiodras $") # pragma: no cover
# All the ada B mapper is now Obsolete, we are using ASN1SCC for Dumpables
#
# class FromDumpableCtoASN1SCC(RecursiveMapper):
# def __init__(self):
# self.uniqueID = 0
# def UniqueID(self):
# self.uniqueID += 1
# return self.uniqueID
# def DecreaseUniqueID(self):
# self.uniqueID -= 1
# def MapInteger(self, srcCVariable, destVar, _, __, ___):
# return ["%s = %s;\n" % (destVar, srcCVariable)]
# def MapReal(self, srcCVariable, destVar, _, __, ___):
# return ["%s = %s;\n" % (destVar, srcCVariable)]
# def MapBoolean(self, srcCVariable, destVar, _, __, ___):
# return ["%s = %s;\n" % (destVar, srcCVariable)]
# def MapOctetString(self, srcCVariable, destVar, _, __, ___):
# lines = []
# lines.append("{\n")
# lines.append(" int i;\n")
# lines.append(" for(i=0; i<%s.length; i++)\n" % srcCVariable)
# lines.append(" %s.arr[i] = %s.content[i];\n" % (destVar, srcCVariable))
# lines.append(" %s.nCount = %s.length;\n" % (destVar, srcCVariable))
# lines.append("}\n")
# return lines
# def MapEnumerated(self, srcCVariable, destVar, _, __, ___):
# return ["%s = %s;\n" % (destVar, srcCVariable)]
# def MapSequence(self, srcCVariable, destVar, node, leafTypeDict, names):
# lines = []
# for child in node._members:
# lines.extend(
# self.Map(
# "%s.%s" % (srcCVariable, self.CleanName(child[0])),
# destVar + "." + self.CleanName(child[0]),
# child[1],
# leafTypeDict,
# names))
# return lines
# def MapSet(self, srcCVariable, destVar, node, leafTypeDict, names):
# return self.MapSequence(srcCVariable, destVar, node, leafTypeDict, names)
# def MapChoice(self, srcCVariable, destVar, node, leafTypeDict, names):
# lines = []
# childNo = 0
# for child in node._members:
# childNo += 1
# lines.append("%sif (%s.choiceIdx == %d) {\n" %
# (self.maybeElse(childNo), srcCVariable, childNo))
# lines.extend([' '+x for x in self.Map(
# "%s.u.%s" % (srcCVariable, self.CleanName(child[0])),
# destVar + ".u." + self.CleanName(child[0]),
# child[1],
# leafTypeDict,
# names)])
# lines.append(" %s.kind = %s_PRESENT;\n" % (destVar, self.CleanName(child[0])))
# lines.append("}\n")
# return lines
# def MapSequenceOf(self, srcCVariable, destVar, node, leafTypeDict, names):
# lines = []
# lines.append("{\n")
# uniqueId = self.UniqueID()
# lines.append(" int i%s;\n" % uniqueId)
# lines.append(" for(i%s=0; i%s<%s.length; i%s++) {\n" % (uniqueId, uniqueId, srcCVariable, uniqueId))
# lines.extend([" " + x for x in self.Map(
# "%s.content[i%s]" % (srcCVariable, uniqueId),
# "%s.arr[i%s]" % (destVar, uniqueId),
# node._containedType,
# leafTypeDict,
# names)])
# lines.append(" }\n")
# lines.append(" %s.nCount = %s.length;\n" % (destVar, srcCVariable))
# lines.append("}\n")
# self.DecreaseUniqueID()
# return lines
# def MapSetOf(self, srcCVariable, destVar, node, leafTypeDict, names):
# return self.MapSequenceOf(srcCVariable, destVar, node, leafTypeDict, names)
#
# class FromASN1SCCtoDumpableC(RecursiveMapper):
# def __init__(self):
# self.uniqueID = 0
# def UniqueID(self):
# self.uniqueID += 1
# return self.uniqueID
# def DecreaseUniqueID(self):
# self.uniqueID -= 1
# def MapInteger(self, srcCVariable, destVar, _, __, ___):
# return ["%s = %s;\n" % (destVar, srcCVariable)]
# def MapReal(self, srcCVariable, destVar, _, __, ___):
# return ["%s = %s;\n" % (destVar, srcCVariable)]
# def MapBoolean(self, srcCVariable, destVar, _, __, ___):
# return ["%s = %s;\n" % (destVar, srcCVariable)]
# def MapOctetString(self, srcCVariable, destVar, _, __, ___):
# lines = []
# lines.append("{\n")
# lines.append(" int i;\n")
# lines.append(" for(i=0; i<%s.nCount; i++)\n" % srcCVariable)
# lines.append(" %s.content[i] = %s.arr[i];\n" % (destVar, srcCVariable))
# lines.append(" %s.length = %s.nCount;\n" % (destVar, srcCVariable))
# lines.append("}\n")
# return lines
# def MapEnumerated(self, srcCVariable, destVar, _, __, ___):
# return ["%s = %s;\n" % (destVar, srcCVariable)]
# def MapSequence(self, srcCVariable, destVar, node, leafTypeDict, names):
# lines = []
# for child in node._members:
# lines.extend(
# self.Map(
# "%s.%s" % (srcCVariable, self.CleanName(child[0])),
# destVar + "." + self.CleanName(child[0]),
# child[1],
# leafTypeDict,
# names))
# return lines
# def MapSet(self, srcCVariable, destVar, node, leafTypeDict, names):
# return self.MapSequence(srcCVariable, destVar, node, leafTypeDict, names)
# def MapChoice(self, srcCVariable, destVar, node, leafTypeDict, names):
# lines = []
# childNo = 0
# for child in node._members:
# childNo += 1
# lines.append("%sif (%s.kind == %s_PRESENT) {\n" %
# (self.maybeElse(childNo), srcCVariable, self.CleanName(child[0])))
# lines.extend([' '+x for x in self.Map(
# "%s.u.%s" % (srcCVariable, self.CleanName(child[0])),
# destVar + ".u." + self.CleanName(child[0]),
# child[1],
# leafTypeDict,
# names)])
# lines.append(" %s.choiceIdx = %d;\n" % (destVar, childNo))
# lines.append("}\n")
# return lines
# def MapSequenceOf(self, srcCVariable, destVar, node, leafTypeDict, names):
# lines = []
# lines.append("{\n")
# uniqueId = self.UniqueID()
# lines.append(" int i%s;\n" % uniqueId)
# lines.append(" for(i%s=0; i%s<%s.nCount; i%s++) {\n" % (uniqueId, uniqueId, srcCVariable, uniqueId))
# lines.extend([" " + x for x in self.Map(
# "%s.arr[i%s]" % (srcCVariable, uniqueId),
# "%s.content[i%s]" % (destVar, uniqueId),
# node._containedType,
# leafTypeDict,
# names)])
# lines.append(" }\n")
# lines.append(" %s.length = %s.nCount;\n" % (destVar, srcCVariable))
# lines.append("}\n")
# self.DecreaseUniqueID()
# return lines
# def MapSetOf(self, srcCVariable, destVar, node, leafTypeDict, names):
# return self.MapSequenceOf(srcCVariable, destVar, node, leafTypeDict, names)
#
# class Ada_GlueGenerator(ASynchronousToolGlueGenerator):
# def __init__(self):
# ASynchronousToolGlueGenerator.__init__(self)
# self.FromDumpableCtoASN1SCC = FromDumpableCtoASN1SCC()
# self.FromASN1SCCtoDumpableC = FromASN1SCCtoDumpableC()
# self.Ada_HeaderFile = None
# self.Ada_SourceFile = None
# self.definedTypes = {}
# def Version(self):
# print "Code generator: " + "$Id: ada_B_mapper.py 2382 2012-06-22 08:35:33Z ttsiodras $"
# def HeadersOnStartup(self, unused_asnFile, unused_outputDir, unused_maybeFVname):
# if self.useOSS:
# self.C_HeaderFile.write("#include \"%s.oss.h\" // OSS generated\n\n" % self.asn_name)
# self.C_SourceFile.write("\nextern OssGlobal *g_world;\n\n")
# self.C_HeaderFile.write("#include \"%s.h\" // Space certified compiler generated\n\n" % self.asn_name)
# self.C_HeaderFile.write("#include \"DumpableTypes.h\"\n\n")
# def Encoder(self, nodeTypename, node, leafTypeDict, names, encoding):
# if encoding.lower() not in self.supportedEncodings:
# panic(str(self.__class__) + ": in (%s), encoding can be one of %s (not '%s')" %
# (nodeTypename, self.supportedEncodings, encoding))
#
# # Definition of the standard encoding function (same interface as the C mapper )
# cBackend.Encoder(nodeTypename, node, leafTypeDict, names, encoding)
# # End standard encoding function
#
# # in order not to duplicate conversion functions, skip the rest if encoding is native
# if encoding.lower() == "native":
# return
#
# if not self.definedTypes.has_key(nodeTypename):
# self.definedTypes[nodeTypename] = 1
# # Declare/define the C stub variable (one per ASN.1 type)
# self.C_HeaderFile.write("\n/* --- Staging var for %s --- */\n" % (nodeTypename))
#
# tmpTypeName = "asn1Scc%s" % self.CleanNameAsToolWants(nodeTypename)
# tmpVarName = "asn1scc"
# tmpSpName = "Ada_to_SCC_%s" % \
# self.CleanNameAsToolWants(nodeTypename)
#
# self.C_HeaderFile.write(
# "void %s(GT__%s *ada, %s *%s);\n" %
# (tmpSpName,
# self.CleanNameAsToolWants(nodeTypename),
# tmpTypeName,
# tmpVarName))
# self.C_SourceFile.write(
# "void %s(GT__%s *ada, %s *%s)\n{\n" %
# (tmpSpName,
# self.CleanNameAsToolWants(nodeTypename),
# tmpTypeName,
# tmpVarName))
#
# lines = self.FromDumpableCtoASN1SCC.Map(
# "(*ada)",
# "(*asn1scc)",
# node,
# leafTypeDict,
# names)
# lines = [" "+x for x in lines]
#
# self.C_SourceFile.write("".join(lines))
# self.C_SourceFile.write("}\n\n")
#
# def Decoder(self, nodeTypename, node, leafTypeDict, names, encoding):
# if encoding.lower() not in self.supportedEncodings:
# panic(str(self.__class__) + ": in (%s), encoding can be one of %s (not '%s')" %
# (nodeTypename, self.supportedEncodings, encoding))
#
# # Definition of the standard decoding function (same interface as the C mapper )
# cBackend.Decoder(nodeTypename, node, leafTypeDict, names, encoding)
# # End standard decoding function
#
# if encoding.lower() == "native":
# return
#
# tmpTypeName = "asn1Scc%s" % self.CleanNameAsToolWants(nodeTypename)
# tmpVarName = "asn1scc"
# tmpSpName = "SCC_to_Ada_%s" % self.CleanNameAsToolWants(nodeTypename)
#
# # Create C function that does the encoding
# self.C_HeaderFile.write(
# "void %s(%s *%s, GT__%s *ada);\n" %
# (tmpSpName,
# tmpTypeName,
# tmpVarName,
# self.CleanNameAsToolWants(nodeTypename)))
# self.C_SourceFile.write(
# "void %s(%s *%s, GT__%s *ada)\n{\n" %
# (tmpSpName,
# tmpTypeName,
# tmpVarName,
# self.CleanNameAsToolWants(nodeTypename)))
#
# lines = self.FromASN1SCCtoDumpableC.Map(
# "(*asn1scc)",
# "(*ada)",
# node,
# leafTypeDict,
# names)
# lines = [" "+x for x in lines]
#
# self.C_SourceFile.write("".join(lines))
# self.C_SourceFile.write("}\n\n")
#
# def OnShutdown(self, modelingLanguage, asnFile, maybeFVname):
# ASynchronousToolGlueGenerator.OnShutdown(self, modelingLanguage, asnFile, maybeFVname)
def OnStartup(unused_modelingLanguage, asnFile, outputDir, maybeFVname, useOSS):
global cBackend
# 2009-02-10: Since we now use ASN1SCC structures as dumpables (even for Ada)
# we no longer need these Ada-specific Dumpable structures.
# we no longer need Ada-specific Dumpable structures.
cBackend = c_B_mapper.C_GlueGenerator()
cBackend.OnStartup("C", asnFile, outputDir, maybeFVname, useOSS)
......
......@@ -39,26 +39,26 @@ class ASynchronousToolGlueGenerator:
def Version(self) -> None: # pylint: disable=no-self-use
panicWithCallStack("Method undefined in a ASynchronousToolGlueGenerator...") # pragma: no cover
def HeadersOnStartup(self,
def HeadersOnStartup(self, # pylint: disable=no-self-use
unused_asnFile: str,
unused_outputDir: str,
unused_maybeFVname: str) -> None: # pylint: disable=no-self-use
unused_maybeFVname: str) -> None:
panicWithCallStack("Method undefined in a ASynchronousToolGlueGenerator...") # pragma: no cover
def Encoder(self,
def Encoder(self, # pylint: disable=no-self-use
unused_nodeTypename: str,
unused_node: AsnNode,
unused_leafTypeDict: AST_Leaftypes,
unused_names: AST_Lookup,
unused_encoding: str) -> None: # pylint: disable=no-self-use
unused_encoding: str) -> None:
panicWithCallStack("Method undefined in a ASynchronousToolGlueGenerator...") # pragma: no cover
def Decoder(self,
def Decoder(self, # pylint: disable=no-self-use
unused_nodeTypename: str,
unused_node: AsnNode,
unused_leafTypeDict: AST_Leaftypes,
unused_names: AST_Lookup,
unused_encoding: str) -> None: # pylint: disable=no-self-use
unused_encoding: str) -> None:
panicWithCallStack("Method undefined in a ASynchronousToolGlueGenerator...") # pragma: no cover
########################################################
......
......@@ -36,9 +36,14 @@ To that end, this backend creates "glue" functions for input and
output parameters, which have C callable interfaces.
'''
from ..commonPy.utility import panic
from ..commonPy.asnAST import sourceSequenceLimit, isSequenceVariable, targetSequenceLimit
from typing import List
from ..commonPy.utility import panic
from ..commonPy.asnAST import (
sourceSequenceLimit, isSequenceVariable, targetSequenceLimit,
AsnInt, AsnReal, AsnBool, AsnSequenceOrSet, AsnSequenceOrSetOf,
AsnChoice, AsnOctetString, AsnEnumerated)
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
from ..commonPy.recursiveMapper import RecursiveMapper
from .asynchronousTool import ASynchronousToolGlueGenerator
......@@ -60,16 +65,16 @@ class FromCtoOSS(RecursiveMapper):
self.uniqueID += 1
return self.uniqueID
def MapInteger(self, srcCVariable, destVar, _, __, ___):
def MapInteger(self, srcCVariable: str, destVar: str, _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (destVar, srcCVariable)]
def MapReal(self, srcCVariable, destVar, _, __, ___):
def MapReal(self, srcCVariable: str, destVar: str, _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (destVar, srcCVariable)]
def MapBoolean(self, srcCVariable, destVar, _, __, ___):
def MapBoolean(self, srcCVariable: str, destVar: str, _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = (char)%s;\n" % (destVar, srcCVariable)]
def MapOctetString(self, srcCVariable, destVar, node, __, ___):
def MapOctetString(self, srcCVariable: str, destVar: str, node: AsnOctetString, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
lines.append("{\n")
lines.append(" int i;\n")
......@@ -80,10 +85,10 @@ class FromCtoOSS(RecursiveMapper):
lines.append("}\n")
return lines
def MapEnumerated(self, srcCVariable, destVar, _, __, ___):
def MapEnumerated(self, srcCVariable: str, destVar: str, _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (destVar, srcCVariable)]
def MapSequence(self, srcCVariable, destVar, node, leafTypeDict, names):
def MapSequence(self, srcCVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
for child in node._members:
lines.extend(
......@@ -95,10 +100,10 @@ class FromCtoOSS(RecursiveMapper):
names))
return lines
def MapSet(self, srcCVariable, destVar, node, leafTypeDict, names):
def MapSet(self, srcCVariable: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return self.MapSequence(srcCVariable, destVar, node, leafTypeDict, names) # pragma: nocover
def MapChoice(self, srcCVariable, destVar, node, leafTypeDict, names):
def MapChoice(self, srcCVariable: str, destVar: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
childNo = 0
for child in node._members:
......@@ -117,7 +122,7 @@ class FromCtoOSS(RecursiveMapper):
lines.append("}\n")
return lines
def MapSequenceOf(self, srcCVariable, destVar, node, leafTypeDict, names):
def MapSequenceOf(self, srcCVariable: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
lines.append("{\n")
uniqueId = self.UniqueID()
......@@ -137,7 +142,7 @@ class FromCtoOSS(RecursiveMapper):
lines.append("}\n")
return lines
def MapSetOf(self, srcCVariable, destVar, node, leafTypeDict, names):
def MapSetOf(self, srcCVariable: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return self.MapSequenceOf(srcCVariable, destVar, node, leafTypeDict, names) # pragma: nocover
......@@ -151,16 +156,16 @@ class FromOSStoC(RecursiveMapper):
self.uniqueID += 1
return self.uniqueID
def MapInteger(self, srcVar, dstCVariable, _, __, ___):
def MapInteger(self, srcVar: str, dstCVariable: str, _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (dstCVariable, srcVar)]
def MapReal(self, srcVar, dstCVariable, _, __, ___):
def MapReal(self, srcVar: str, dstCVariable: str, _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (dstCVariable, srcVar)]
def MapBoolean(self, srcVar, dstCVariable, _, __, ___):
def MapBoolean(self, srcVar: str, dstCVariable: str, _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = (%s)?1:0;\n" % (dstCVariable, srcVar)]
def MapOctetString(self, srcVar, dstCVariable, node, _, __):
def MapOctetString(self, srcVar: str, dstCVariable: str, node: AsnOctetString, _: AST_Leaftypes, __: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
lines.append("{\n")
lines.append(" int i;\n")
......@@ -172,10 +177,10 @@ class FromOSStoC(RecursiveMapper):
lines.append("}\n")
return lines
def MapEnumerated(self, srcVar, dstCVariable, _, __, ___):
def MapEnumerated(self, srcVar: str, dstCVariable: str, _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (dstCVariable, srcVar)]
def MapSequence(self, srcVar, dstCVariable, node, leafTypeDict, names):
def MapSequence(self, srcVar: str, dstCVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
for child in node._members:
lines.extend(
......@@ -187,10 +192,10 @@ class FromOSStoC(RecursiveMapper):
names))
return lines
def MapSet(self, srcVar, dstCVariable, node, leafTypeDict, names):
def MapSet(self, srcVar: str, dstCVariable: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return self.MapSequence(srcVar, dstCVariable, node, leafTypeDict, names) # pragma: nocover
def MapChoice(self, srcVar, dstCVariable, node, leafTypeDict, names):
def MapChoice(self, srcVar: str, dstCVariable: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
childNo = 0
for child in node._members:
......@@ -209,7 +214,7 @@ class FromOSStoC(RecursiveMapper):
lines.append("}\n")
return lines
def MapSequenceOf(self, srcVar, dstCVariable, node, leafTypeDict, names):
def MapSequenceOf(self, srcVar: str, dstCVariable: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
lines.append("{\n")
uniqueId = self.UniqueID()
......@@ -230,7 +235,7 @@ class FromOSStoC(RecursiveMapper):
lines.append("}\n")
return lines
def MapSetOf(self, srcVar, dstCVariable, node, leafTypeDict, names):
def MapSetOf(self, srcVar: str, dstCVariable: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return self.MapSequenceOf(srcVar, dstCVariable, node, leafTypeDict, names) # pragma: nocover
......
......@@ -18,6 +18,9 @@
# Note that in both cases, there are no charges (royalties) for the
# generated code.
#
# pylint: disable=too-many-lines
import re
import os
......
This diff is collapsed.
......@@ -38,10 +38,13 @@ parameters, which have C callable interfaces. The necessary
stubs (to allow calling from the VM side) are also generated.
'''
from typing import List
from ..commonPy.utility import panicWithCallStack
from ..commonPy.asnAST import AsnInt, AsnReal, AsnBool, AsnEnumerated, isSequenceVariable, sourceSequenceLimit
from ..commonPy.asnAST import (
sourceSequenceLimit, isSequenceVariable, AsnInt, AsnReal, AsnEnumerated,
AsnBool, AsnSequenceOrSet, AsnSequenceOrSetOf, AsnChoice, AsnOctetString)
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
from ..commonPy.aadlAST import AadlPort, AadlParameter
from ..commonPy.recursiveMapper import RecursiveMapper
from .synchronousTool import SynchronousToolGlueGenerator
......@@ -62,16 +65,16 @@ def IsElementMappedToPrimitive(node, names):
# pylint: disable=no-self-use
class FromQGenCToASN1SCC(RecursiveMapper):
def MapInteger(self, srcQGenC, destVar, _, __, ___):
def MapInteger(self, srcQGenC: str, destVar: str, _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = (asn1SccSint) %s;\n" % (destVar, srcQGenC)]
def MapReal(self, srcQGenC, destVar, _, __, ___):
def MapReal(self, srcQGenC: str, destVar: str, _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = (double) %s;\n" % (destVar, srcQGenC)]
def MapBoolean(self, srcQGenC, destVar, _, __, ___):
def MapBoolean(self, srcQGenC: str, destVar: str, _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = (asn1SccUint) %s;\n" % (destVar, srcQGenC)]
def MapOctetString(self, srcQGenC, destVar, node, _, __):
def MapOctetString(self, srcQGenC: str, destVar: str, node: AsnOctetString, _: AST_Leaftypes, __: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
if not node._range:
panicWithCallStack("OCTET STRING (in %s) must have a SIZE constraint inside ASN.1,\nor else we can't generate C code!" % node.Location()) # pragma: no cover
......@@ -84,10 +87,10 @@ class FromQGenCToASN1SCC(RecursiveMapper):
# lines.append("%s.nCount = %s;\n" % (destVar, node._range[-1]))
return lines
def MapEnumerated(self, srcQGenC, destVar, _, __, ___):
def MapEnumerated(self, srcQGenC: str, destVar: str, _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (destVar, srcQGenC)]
def MapSequence(self, unused_srcQGenC, unused_destVar, node, leafTypeDict, names):
def MapSequence(self, unused_srcQGenC: str, unused_destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
for child in node._members:
lines.extend(
......@@ -99,10 +102,10 @@ class FromQGenCToASN1SCC(RecursiveMapper):
names))
return lines
def MapSet(self, srcQGenC, destVar, node, leafTypeDict, names):
def MapSet(self, srcQGenC: str, destVar: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return self.MapSequence(srcQGenC, destVar, node, leafTypeDict, names) # pragma: nocover
def MapChoice(self, srcQGenC, destVar, node, leafTypeDict, names):
def MapChoice(self, srcQGenC: str, destVar: str, node: AsnChoice, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
lines = [] # type: List[str]
childNo = 0
for child in node._members:
......@@ -120,7 +123,7 @@ class FromQGenCToASN1SCC(RecursiveMapper):
lines.append("}\n")
return lines
def MapSequenceOf(self, srcQGenC, destVar, node, leafTypeDict, names):
def MapSequenceOf(self, srcQGenC: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
if not node._range:
panicWithCallStack("need a SIZE constraint or else we can't generate C code (%s)!\n" % node.Location()) # pragma: no cover
isMappedToPrimitive = IsElementMappedToPrimitive(node, names)
......@@ -139,22 +142,22 @@ class FromQGenCToASN1SCC(RecursiveMapper):
# lines.append("%s.nCount = %s;\n" % (destVar, node._range[-1]))
return lines
def MapSetOf(self, srcQGenC, destVar, node, leafTypeDict, names):
def MapSetOf(self, srcQGenC: str, destVar: str, node: AsnSequenceOrSetOf, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return self.MapSequenceOf(srcQGenC, destVar, node, leafTypeDict, names) # pragma: nocover
# pylint: disable=no-self-use
class FromASN1SCCtoQGenC(RecursiveMapper):
def MapInteger(self, srcVar, dstQGenC, _, __, ___):
def MapInteger(self, srcVar: str, dstQGenC: str, _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (dstQGenC, srcVar)]
def MapReal(self, srcVar, dstQGenC, _, __, ___):
def MapReal(self, srcVar: str, dstQGenC: str, _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (dstQGenC, srcVar)]
def MapBoolean(self, srcVar, dstQGenC, _, __, ___):
def MapBoolean(self, srcVar: str, dstQGenC: str, _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
return ["%s = %s;\n" % (dstQGenC, srcVar)]
def MapOctetString(self, srcVar, dstQGenC, node, _, __):
def MapOctetString(self, srcVar: str, dstQGenC: str, node: AsnOctetString, _: AST_Leaftypes, __: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
if not node._range:
panicWithCallStack("OCTET STRING (in %s) must have a SIZE constraint inside ASN.1,\nor else we can't generate C code!" % node.Location()) # pragma: no cover
......@@ -167,12 +170,12 @@ class FromASN1SCCtoQGenC(RecursiveMapper):
lines.append("%s.length = %s;\n" % (dstQGenC, limit))
return lines
def MapEnumerated(self, srcVar, dstQGenC, node, __, ___):
def MapEnumerated(self, srcVar: str, dstQGenC: str, node: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index
if None in [x[1] for x in node._members]:
panicWithCallStack("an ENUMERATED must have integer values! (%s)" % node.Location()) # pragma: no cover
return ["%s = %s;\n" % (dstQGenC, srcVar)]
def MapSequence(self, srcVar, dstQGenC, node, leafTypeDict, names):
def MapSequence(self, srcVar: str, dstQGenC: str, node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]: # pylint: disable=invalid-sequence-index