Commit c9f59d74 authored by dbarbera's avatar dbarbera
Browse files

flake8 fixes

parent 370bd8b1
......@@ -91,7 +91,6 @@ PROCEDURES = []
@singledispatch
def generate(ast):
''' Generate the code for an item of the AST '''
_ = ast
raise TypeError('[AdaGenerator] Unsupported AST construct')
return [], []
......@@ -713,7 +712,6 @@ def expression(expr):
- useable string corresponding to the evaluation of the expression,
- list of local declarations
'''
_ = expr
raise TypeError('Unsupported expression: ' + str(expr))
return [], '', []
......@@ -854,16 +852,19 @@ def _prim_substring(prim):
local_decl.extend(r1_local)
local_decl.extend(r2_local)
local_decl.append('tmp{idx} : aliased asn1Scc{parent_type};'.format(idx=prim.value[1]['tmpVar'], parent_type=receiver_ty_name))
local_decl.append('tmp{idx} : aliased asn1Scc{parent_type};'.format(
idx=prim.value[1]['tmpVar'], parent_type=receiver_ty_name))
# XXX types with fixed length: substrings will not work
if unicode.isnumeric(r1_string) and unicode.isnumeric(r2_string):
length = int(r2_string) - int(r1_string) + 1
else:
length = ('{r2} - {r1} + 1'.format(r2=r2_string, r1=r1_string))
stmts.append('tmp{idx}.Length := {length};'.format(idx=prim.value[1]['tmpVar'], length=length))
stmts.append('tmp{idx}.Length := {length};'.format(
idx=prim.value[1]['tmpVar'], length=length))
stmts.append('tmp{idx}.Data(1..{length}) := {data};'.format(idx=prim.value[1]['tmpVar'], length=length, data=ada_string))
stmts.append('tmp{idx}.Data(1..{length}) := {data};'.format(
idx=prim.value[1]['tmpVar'], length=length, data=ada_string))
ada_string = 'tmp{idx}'.format(idx=prim.value[1]['tmpVar'])
return stmts, ada_string, local_decl
......@@ -885,7 +886,8 @@ def _prim_selector(prim):
receiver_ty_name = receiver.exprType.ReferencedTypeName.replace('-', '_')
if receiver_bty.kind == 'ChoiceType':
ada_string = ('asn1Scc{typename}_{field_name}_get({ada_string})'.format(typename=receiver_ty_name, field_name=field_name, ada_string=ada_string))
ada_string = ('asn1Scc{typename}_{field_name}_get({ada_string})'.format(
typename=receiver_ty_name, field_name=field_name, ada_string=ada_string))
else:
ada_string += '.' + field_name
......@@ -1039,7 +1041,6 @@ def _append(expr):
return stmts, ada_string, local_decl
@expression.register(ogAST.ExprIn)
def _expr_in(expr):
''' IN expressions: check if item is in a SEQUENCE OF '''
......@@ -1101,7 +1102,7 @@ def _integer(primary):
@expression.register(ogAST.PrimBoolean)
def _integer(primary):
def _boolean(primary):
''' Generate code for a raw boolean value '''
ada_string = primary.value[0]
return [], ada_string, []
......@@ -1143,7 +1144,6 @@ def _constant(primary):
def _mantissa_base_exp(primary):
''' Generate code for a Real with Mantissa-base-Exponent representation '''
# TODO
_ = primary
return [], '', []
......@@ -1161,9 +1161,9 @@ def _if_then_else(ifThenElse):
tmp_type = 'String(1 .. {})'.format(max(lens) - 2)
# Ada require fixed-length strings, adjust with spaces
if lens[0] < lens[1]:
then_str = then_str[0:-1] + ' '* (lens[1] - lens[0]) + '"'
then_str = then_str[0:-1] + ' ' * (lens[1] - lens[0]) + '"'
elif lens[1] < lens[0]:
else_str = else_str[0:-1] + ' '* (lens[0] - lens[1]) + '"'
else_str = else_str[0:-1] + ' ' * (lens[0] - lens[1]) + '"'
else:
tmp_type = 'asn1Scc' + resType.ReferencedTypeName.replace('-', '_')
local_decl = ['tmp{idx} : {tmpType};'.format(
......
......@@ -83,8 +83,8 @@ INTEGER = type('IntegerType', (object,), {'kind': 'IntegerType',
'Min': str(-(2 ** 63)),
'Max': str(2 ** 63 - 1)})
INT32 = type('Integer32Type', (object,), {'kind': 'Integer32Type',
'Min':'-2147483648',
'Max':'2147483647'})
'Min': '-2147483648',
'Max': '2147483647'})
NUMERICAL = type('NumericalType', (object,), {'kind': 'Numerical'})
TIMER = type('TimerType', (object,), {'kind': 'TimerType'})
REAL = type('RealType', (object,), {'kind': 'RealType',
......@@ -347,7 +347,6 @@ def fix_special_operators(op_name, expr_list, context):
elif op_name.lower() == 'power':
if len(expr_list) != 2:
raise AttributeError('The "power" operator takes two parameters')
types = {}
for idx, expr in enumerate(expr_list):
if expr.exprType is UNKNOWN_TYPE:
expr.exprType = find_variable(expr.value[0], context)
......@@ -377,7 +376,7 @@ def fix_special_operators(op_name, expr_list, context):
# Has to be a variable...otherwise, error!
try:
param.exprType = find_variable(param.value[0], context)
except KeyError, AttributeError:
except (KeyError, AttributeError):
raise TypeError('Could not determine type of argument'
' "{}"'.format(param.inputString))
basic = find_basic_type(param.exprType)
......@@ -702,8 +701,7 @@ def compare_types(type_a, type_b):
else:
raise TypeError('Incompatible arrays')
return
elif type_a.kind.endswith('StringType') and type_b.kind.endswith(
'StringType'):
elif type_a.kind.endswith('StringType') and type_b.kind.endswith('StringType'):
# Allow Octet String values to be printable strings.. for convenience
return
elif not(type_a.kind in ('IntegerType', 'Integer32Type') and
......@@ -1804,7 +1802,6 @@ def procedure(root, parent=None, context=None):
def floating_label(root, parent, context):
''' Floating label: name and optional transition '''
_ = parent
errors = []
warnings = []
lab = ogAST.Floating_label()
......@@ -1840,6 +1837,7 @@ def floating_label(root, parent, context):
lab.terminators = list(context.terminators[terminators:])
return lab, errors, warnings
def newtype_gettype(root, ta_ast, context):
''' Returns the name of the new type created by a NEWTYPE construction '''
errors = []
......@@ -1847,27 +1845,29 @@ def newtype_gettype(root, ta_ast, context):
newtypename = ""
if (root.getChild(0).type != lexer.SORT):
warnings.append("Expected SORT in newtype identifier, got type:"
+ str(child.type))
+ str(root.type))
return newtypename, errors, warnings
newtypename = root.getChild(0).getChild(0).text
return newtypename, errors, warnings
def get_array_type(root):
''' Returns the subtype associated to an NEWTYPE ARRAY construction '''
indexSort = root.getChild(0).text
# indexSort = root.getChild(0).text
typeSort = root.getChild(1).text
typeSortLine = root.getChild(1).getLine()
typeSortChar = root.getChild(1).getCharPositionInLine()
# Constructing ASN.1 AST subtype
newtype = type("SeqOf_type", (object,), {
"Line" : typeSortLine, "CharPositionInLine" : typeSortChar,
"Kind" : "ReferenceType" , "ReferencedTypeName" : typeSort
"Line": typeSortLine, "CharPositionInLine": typeSortChar,
"Kind": "ReferenceType", "ReferencedTypeName": typeSort
})
return newtype
def get_struct_children(root):
''' Returns the fields of a STRUCT as a dictionary '''
children = {}
......@@ -1884,7 +1884,7 @@ def get_struct_children(root):
line = field.getChild(0).getLine()
charpos = field.getChild(0).getCharPositionInLine()
children[fieldname] = type(str(fieldname), (object ,), {
children[fieldname] = type(str(fieldname), (object,), {
"Optional": "False", "Line": line,
"CharPositionInLine": charpos,
"type": type(str(fieldname + "_type"), (object,), {
......@@ -1894,6 +1894,7 @@ def get_struct_children(root):
})
return children
def syntype(root, ta_ast, context):
''' Parse a SYNTYPE definition and inject it in ASN1 AST'''
errors = []
......@@ -1903,21 +1904,22 @@ def syntype(root, ta_ast, context):
global DV
newtypename = root.getChild(0).getChild(0).text
reftypename = root.getChild(1).getChild(0).text
# reftypename = root.getChild(1).getChild(0).text
newtype = type(str(newtypename), (object,), {
"Line" : root.getChild(0).getLine(),
"CharPositionInLine" : root.getChild(0).getCharPositionInLine(),
"Line": root.getChild(0).getLine(),
"CharPositionInLine": root.getChild(0).getCharPositionInLine(),
})
newtype.type = type(str(newtypename) + "_type", (object,), {
"Line" : root.getChild(1).getLine(),
"CharPositionInLine" : root.getChild(1).getCharPositionInLine(),
"kind" : reftype + "Type"
"Line": root.getChild(1).getLine(),
"CharPositionInLine": root.getChild(1).getCharPositionInLine(),
"kind": reftype + "Type"
})
DV.types[str(newtypename)] = newtype
LOG.debug("Found new SYNTYPE " + newtypename)
return errors, warnings
def newtype(root, ta_ast, context):
''' Parse a NEWTYPE definition and inject it in ASN1 AST'''
errors = []
......@@ -1929,8 +1931,8 @@ def newtype(root, ta_ast, context):
return errors, warnings
newtype = type(str(newtypename), (object,), {
"Line" : root.getLine(),
"CharPositionInLine" : root.getCharPositionInLine()})
"Line": root.getLine(),
"CharPositionInLine": root.getCharPositionInLine()})
if (root.getChild(1).type == lexer.ARRAY):
newtype.kind = "SequenceOfType"
......@@ -1947,11 +1949,12 @@ def newtype(root, ta_ast, context):
else:
warnings.append(
'Unsupported type definition in newtype, type: ' +
str(child.type))
str(root.type))
# STRUCT CASE
return errors, warnings
def synonym (root, ta_ast, context):
def synonym(root, ta_ast, context):
''' Parse a SYNONYM definition and inject it in ASN1 exported variables'''
errors = []
warnings = []
......@@ -1967,6 +1970,7 @@ def synonym (root, ta_ast, context):
child.getChild(0).getChild(0).text)
return errors, warnings
def text_area_content(root, ta_ast, context):
''' Content of a text area: DCL, NEWTYPES, SYNTYPES, SYNONYMS, operators,
procedures '''
......@@ -3247,7 +3251,7 @@ def pr_file(root):
# In case no ASN.1 files are parsed, the DV structure is pre-initialised
# This to allow SDL types injection in ASN1 ASTs
DV = type("ASNParseTree", (object, ),
{"types" : {}, "exportedVariables": {}, "asn1Modules": [] })
{"types": {}, "exportedVariables": {}, "asn1Modules": []})
# Re-order the children of the AST to make sure system and use clauses
# are parsed before process definition - to get signal definitions
......
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