Commit c9f59d74 authored by dbarbera's avatar dbarbera
Browse files

flake8 fixes

parent 370bd8b1
...@@ -91,7 +91,6 @@ PROCEDURES = [] ...@@ -91,7 +91,6 @@ PROCEDURES = []
@singledispatch @singledispatch
def generate(ast): def generate(ast):
''' Generate the code for an item of the AST ''' ''' Generate the code for an item of the AST '''
_ = ast
raise TypeError('[AdaGenerator] Unsupported AST construct') raise TypeError('[AdaGenerator] Unsupported AST construct')
return [], [] return [], []
...@@ -223,7 +222,7 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -223,7 +222,7 @@ package {process_name} is'''.format(process_name=process_name,
if 'type' in signal: if 'type' in signal:
typename = signal['type'].ReferencedTypeName.replace('-', '_') typename = signal['type'].ReferencedTypeName.replace('-', '_')
pi_header += '({pName}: access asn1Scc{pType})'.format( pi_header += '({pName}: access asn1Scc{pType})'.format(
pName=param_name, pType=typename) pName=param_name, pType=typename)
# Add declaration of the provided interface in the .ads file # Add declaration of the provided interface in the .ads file
ads_template.append('-- Provided interface "' + signal['name'] + '"') ads_template.append('-- Provided interface "' + signal['name'] + '"')
...@@ -279,7 +278,7 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -279,7 +278,7 @@ package {process_name} is'''.format(process_name=process_name,
taste_template.append('null;') taste_template.append('null;')
taste_template.append('end case;') taste_template.append('end case;')
taste_template.append(u'end {sig_name};'.format( taste_template.append(u'end {sig_name};'.format(
sig_name=signal['name'])) sig_name=signal['name']))
taste_template.append('\n') taste_template.append('\n')
# for the .ads file, generate the declaration of the required interfaces # for the .ads file, generate the declaration of the required interfaces
...@@ -308,7 +307,7 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -308,7 +307,7 @@ package {process_name} is'''.format(process_name=process_name,
if params: if params:
ri_header += u'(' + u';'.join(params) + ')' ri_header += u'(' + u';'.join(params) + ')'
ads_template.append( ads_template.append(
u'-- Sync required interface "' + proc.inputString) u'-- Sync required interface "' + proc.inputString)
ads_template.append(ri_header + u';') ads_template.append(ri_header + u';')
ads_template.append(u'pragma import(C, {sig}, "{proc}_RI_{sig}");' ads_template.append(u'pragma import(C, {sig}, "{proc}_RI_{sig}");'
.format(sig=proc.inputString, proc=process_name)) .format(sig=proc.inputString, proc=process_name))
...@@ -444,7 +443,7 @@ def write_statement(param, newline): ...@@ -444,7 +443,7 @@ def write_statement(param, newline):
.format(tmp=localstr, st=string, sep=sep), .format(tmp=localstr, st=string, sep=sep),
u"end loop;"]) u"end loop;"])
if basic_type.Min != basic_type.Max: if basic_type.Min != basic_type.Max:
code.extend(["if {string}.Length < {to} then" code.extend(["if {string}.Length < {to} then"
.format(string=string, to=basic_type.Max), .format(string=string, to=basic_type.Max),
u"{tmp}({string}.Length + 1 .. {to}) " u"{tmp}({string}.Length + 1 .. {to}) "
u":= (others=>Character'Val(0));" u":= (others=>Character'Val(0));"
...@@ -562,7 +561,7 @@ def _call_external_function(output): ...@@ -562,7 +561,7 @@ def _call_external_function(output):
# Create a temporary variable for input parameters only # Create a temporary variable for input parameters only
# (If needed, i.e. if argument is not a local variable) # (If needed, i.e. if argument is not a local variable)
if param_direction == 'in' \ if param_direction == 'in' \
and (not (isinstance(param, ogAST.PrimVariable) and and (not (isinstance(param, ogAST.PrimVariable) and
p_id.startswith('l_')) or isinstance(param, ogAST.PrimFPAR)): p_id.startswith('l_')) or isinstance(param, ogAST.PrimFPAR)):
tmp_id = out['tmpVars'][idx] tmp_id = out['tmpVars'][idx]
local_decl.append('tmp{idx} : aliased asn1Scc{oType};' local_decl.append('tmp{idx} : aliased asn1Scc{oType};'
...@@ -639,7 +638,7 @@ def _task_forloop(task): ...@@ -639,7 +638,7 @@ def _task_forloop(task):
start_str, stop_str = '0', '' start_str, stop_str = '0', ''
if loop['range']['start']: if loop['range']['start']:
start_stmt, start_str, start_local = expression( start_stmt, start_str, start_local = expression(
loop['range']['start']) loop['range']['start'])
local_decl.extend(start_local) local_decl.extend(start_local)
stmt.extend(start_stmt) stmt.extend(start_stmt)
# ASN.1 Integers are 64 bits - we need to convert to 32 bits # ASN.1 Integers are 64 bits - we need to convert to 32 bits
...@@ -654,8 +653,8 @@ def _task_forloop(task): ...@@ -654,8 +653,8 @@ def _task_forloop(task):
# stop_str = 'Integer({})'.format(stop_str) # stop_str = 'Integer({})'.format(stop_str)
if loop['range']['step'] == 1: if loop['range']['step'] == 1:
stmt.append( stmt.append(
'for {it} in {start}{stop} loop' 'for {it} in {start}{stop} loop'
.format(it=loop['var'], start=start_str, stop=stop_str)) .format(it=loop['var'], start=start_str, stop=stop_str))
else: else:
# Step is not directly supported in Ada, we need to use 'while' # Step is not directly supported in Ada, we need to use 'while'
stmt.extend(['declare', stmt.extend(['declare',
...@@ -713,7 +712,6 @@ def expression(expr): ...@@ -713,7 +712,6 @@ def expression(expr):
- useable string corresponding to the evaluation of the expression, - useable string corresponding to the evaluation of the expression,
- list of local declarations - list of local declarations
''' '''
_ = expr
raise TypeError('Unsupported expression: ' + str(expr)) raise TypeError('Unsupported expression: ' + str(expr))
return [], '', [] return [], '', []
...@@ -854,16 +852,19 @@ def _prim_substring(prim): ...@@ -854,16 +852,19 @@ def _prim_substring(prim):
local_decl.extend(r1_local) local_decl.extend(r1_local)
local_decl.extend(r2_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 # XXX types with fixed length: substrings will not work
if unicode.isnumeric(r1_string) and unicode.isnumeric(r2_string): if unicode.isnumeric(r1_string) and unicode.isnumeric(r2_string):
length = int(r2_string) - int(r1_string) + 1 length = int(r2_string) - int(r1_string) + 1
else: else:
length = ('{r2} - {r1} + 1'.format(r2=r2_string, r1=r1_string)) 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']) ada_string = 'tmp{idx}'.format(idx=prim.value[1]['tmpVar'])
return stmts, ada_string, local_decl return stmts, ada_string, local_decl
...@@ -885,7 +886,8 @@ def _prim_selector(prim): ...@@ -885,7 +886,8 @@ def _prim_selector(prim):
receiver_ty_name = receiver.exprType.ReferencedTypeName.replace('-', '_') receiver_ty_name = receiver.exprType.ReferencedTypeName.replace('-', '_')
if receiver_bty.kind == 'ChoiceType': 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: else:
ada_string += '.' + field_name ada_string += '.' + field_name
...@@ -947,10 +949,10 @@ def _bitwise_operators(expr): ...@@ -947,10 +949,10 @@ def _bitwise_operators(expr):
ada_string += u')' ada_string += u')'
else: else:
ada_string = u'({left} {op}{short} {right})'.format( ada_string = u'({left} {op}{short} {right})'.format(
left=left_str, left=left_str,
op=expr.operand, op=expr.operand,
short=expr.shortcircuit, short=expr.shortcircuit,
right=right_str) right=right_str)
code.extend(left_stmts) code.extend(left_stmts)
code.extend(right_stmts) code.extend(right_stmts)
local_decl.extend(left_local) local_decl.extend(left_local)
...@@ -1039,7 +1041,6 @@ def _append(expr): ...@@ -1039,7 +1041,6 @@ def _append(expr):
return stmts, ada_string, local_decl return stmts, ada_string, local_decl
@expression.register(ogAST.ExprIn) @expression.register(ogAST.ExprIn)
def _expr_in(expr): def _expr_in(expr):
''' IN expressions: check if item is in a SEQUENCE OF ''' ''' IN expressions: check if item is in a SEQUENCE OF '''
...@@ -1101,7 +1102,7 @@ def _integer(primary): ...@@ -1101,7 +1102,7 @@ def _integer(primary):
@expression.register(ogAST.PrimBoolean) @expression.register(ogAST.PrimBoolean)
def _integer(primary): def _boolean(primary):
''' Generate code for a raw boolean value ''' ''' Generate code for a raw boolean value '''
ada_string = primary.value[0] ada_string = primary.value[0]
return [], ada_string, [] return [], ada_string, []
...@@ -1111,7 +1112,7 @@ def _integer(primary): ...@@ -1111,7 +1112,7 @@ def _integer(primary):
def _empty_string(primary): def _empty_string(primary):
''' Generate code for an empty SEQUENCE OF: {} ''' ''' Generate code for an empty SEQUENCE OF: {} '''
ada_string = 'asn1Scc{typeRef}_Init'.format( ada_string = 'asn1Scc{typeRef}_Init'.format(
typeRef=primary.exprType.ReferencedTypeName.replace('-', '_')) typeRef=primary.exprType.ReferencedTypeName.replace('-', '_'))
return [], ada_string, [] return [], ada_string, []
...@@ -1124,7 +1125,7 @@ def _string_literal(primary): ...@@ -1124,7 +1125,7 @@ def _string_literal(primary):
# as expected by the Ada type corresponding to Octet String # as expected by the Ada type corresponding to Octet String
unsigned_8 = [str(ord(val)) for val in primary.value[1:-1]] unsigned_8 = [str(ord(val)) for val in primary.value[1:-1]]
ada_string = '(Data => (' + ', '.join( ada_string = '(Data => (' + ', '.join(
unsigned_8) + ', others => 0)' unsigned_8) + ', others => 0)'
if basic_type.Min != basic_type.Max: if basic_type.Min != basic_type.Max:
# Non-fixed string size -> add Length field # Non-fixed string size -> add Length field
ada_string += ', Length => {}'.format( ada_string += ', Length => {}'.format(
...@@ -1143,7 +1144,6 @@ def _constant(primary): ...@@ -1143,7 +1144,6 @@ def _constant(primary):
def _mantissa_base_exp(primary): def _mantissa_base_exp(primary):
''' Generate code for a Real with Mantissa-base-Exponent representation ''' ''' Generate code for a Real with Mantissa-base-Exponent representation '''
# TODO # TODO
_ = primary
return [], '', [] return [], '', []
...@@ -1161,9 +1161,9 @@ def _if_then_else(ifThenElse): ...@@ -1161,9 +1161,9 @@ def _if_then_else(ifThenElse):
tmp_type = 'String(1 .. {})'.format(max(lens) - 2) tmp_type = 'String(1 .. {})'.format(max(lens) - 2)
# Ada require fixed-length strings, adjust with spaces # Ada require fixed-length strings, adjust with spaces
if lens[0] < lens[1]: 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]: 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: else:
tmp_type = 'asn1Scc' + resType.ReferencedTypeName.replace('-', '_') tmp_type = 'asn1Scc' + resType.ReferencedTypeName.replace('-', '_')
local_decl = ['tmp{idx} : {tmpType};'.format( local_decl = ['tmp{idx} : {tmpType};'.format(
...@@ -1255,7 +1255,7 @@ def _choiceitem(choice): ...@@ -1255,7 +1255,7 @@ def _choiceitem(choice):
stmts, choice_str, local_decl = expression(choice.value['value']) stmts, choice_str, local_decl = expression(choice.value['value'])
choiceType = choice.exprType choiceType = choice.exprType
actual_type = getattr( actual_type = getattr(
choiceType, 'ReferencedTypeName', None) or choiceType.kind choiceType, 'ReferencedTypeName', None) or choiceType.kind
actual_type = actual_type.replace('-', '_') actual_type = actual_type.replace('-', '_')
ada_string = 'asn1Scc{cType}_{opt}_set({expr})'.format( ada_string = 'asn1Scc{cType}_{opt}_set({expr})'.format(
cType=actual_type, cType=actual_type,
...@@ -1379,7 +1379,7 @@ def _transition(tr): ...@@ -1379,7 +1379,7 @@ def _transition(tr):
unicode(tr.terminator.next_id) + u';') unicode(tr.terminator.next_id) + u';')
if tr.terminator.next_id == -1: if tr.terminator.next_id == -1:
code.append(u'state := {nextState};'.format( code.append(u'state := {nextState};'.format(
nextState=tr.terminator.inputString)) nextState=tr.terminator.inputString))
else: else:
if any(next_id if any(next_id
for next_id in tr.terminator.candidate_id.viewkeys() for next_id in tr.terminator.candidate_id.viewkeys()
......
...@@ -83,8 +83,8 @@ INTEGER = type('IntegerType', (object,), {'kind': 'IntegerType', ...@@ -83,8 +83,8 @@ INTEGER = type('IntegerType', (object,), {'kind': 'IntegerType',
'Min': str(-(2 ** 63)), 'Min': str(-(2 ** 63)),
'Max': str(2 ** 63 - 1)}) 'Max': str(2 ** 63 - 1)})
INT32 = type('Integer32Type', (object,), {'kind': 'Integer32Type', INT32 = type('Integer32Type', (object,), {'kind': 'Integer32Type',
'Min':'-2147483648', 'Min': '-2147483648',
'Max':'2147483647'}) 'Max': '2147483647'})
NUMERICAL = type('NumericalType', (object,), {'kind': 'Numerical'}) NUMERICAL = type('NumericalType', (object,), {'kind': 'Numerical'})
TIMER = type('TimerType', (object,), {'kind': 'TimerType'}) TIMER = type('TimerType', (object,), {'kind': 'TimerType'})
REAL = type('RealType', (object,), {'kind': 'RealType', REAL = type('RealType', (object,), {'kind': 'RealType',
...@@ -347,7 +347,6 @@ def fix_special_operators(op_name, expr_list, context): ...@@ -347,7 +347,6 @@ def fix_special_operators(op_name, expr_list, context):
elif op_name.lower() == 'power': elif op_name.lower() == 'power':
if len(expr_list) != 2: if len(expr_list) != 2:
raise AttributeError('The "power" operator takes two parameters') raise AttributeError('The "power" operator takes two parameters')
types = {}
for idx, expr in enumerate(expr_list): for idx, expr in enumerate(expr_list):
if expr.exprType is UNKNOWN_TYPE: if expr.exprType is UNKNOWN_TYPE:
expr.exprType = find_variable(expr.value[0], context) expr.exprType = find_variable(expr.value[0], context)
...@@ -377,7 +376,7 @@ def fix_special_operators(op_name, expr_list, context): ...@@ -377,7 +376,7 @@ def fix_special_operators(op_name, expr_list, context):
# Has to be a variable...otherwise, error! # Has to be a variable...otherwise, error!
try: try:
param.exprType = find_variable(param.value[0], context) param.exprType = find_variable(param.value[0], context)
except KeyError, AttributeError: except (KeyError, AttributeError):
raise TypeError('Could not determine type of argument' raise TypeError('Could not determine type of argument'
' "{}"'.format(param.inputString)) ' "{}"'.format(param.inputString))
basic = find_basic_type(param.exprType) basic = find_basic_type(param.exprType)
...@@ -604,7 +603,7 @@ def check_type_compatibility(primary, typeRef, context): ...@@ -604,7 +603,7 @@ def check_type_compatibility(primary, typeRef, context):
# Compare the types for semantic equivalence # Compare the types for semantic equivalence
try: try:
compare_types( compare_types(
primary.value[ufield].exprType, fd_data.type) primary.value[ufield].exprType, fd_data.type)
except TypeError as err: except TypeError as err:
raise TypeError('Field ' + ufield + raise TypeError('Field ' + ufield +
' is not of the proper type, i.e. ' + ' is not of the proper type, i.e. ' +
...@@ -640,10 +639,10 @@ def check_type_compatibility(primary, typeRef, context): ...@@ -640,10 +639,10 @@ def check_type_compatibility(primary, typeRef, context):
value.exprType = choice_field_type # XXX value.exprType = choice_field_type # XXX
return return
elif isinstance(primary, ogAST.PrimChoiceDeterminant) \ elif isinstance(primary, ogAST.PrimChoiceDeterminant) \
and actual_type.kind.startswith('Choice'): and actual_type.kind.startswith('Choice'):
for choicekey, choice in actual_type.EnumValues.viewitems(): for choicekey, choice in actual_type.EnumValues.viewitems():
if choicekey.replace('-', '_').lower() == \ if choicekey.replace('-', '_').lower() == \
primary.inputString.lower(): primary.inputString.lower():
break break
else: else:
raise TypeError('Non-existent choice "{choice}" in type {t1}' raise TypeError('Non-existent choice "{choice}" in type {t1}'
...@@ -657,7 +656,7 @@ def check_type_compatibility(primary, typeRef, context): ...@@ -657,7 +656,7 @@ def check_type_compatibility(primary, typeRef, context):
return return
elif basic_type.kind.endswith('StringType'): elif basic_type.kind.endswith('StringType'):
if int(basic_type.Min) <= len( if int(basic_type.Min) <= len(
primary.value[1:-1]) <= int(basic_type.Max): primary.value[1:-1]) <= int(basic_type.Max):
return return
else: else:
raise TypeError('Invalid string literal - check that length is' raise TypeError('Invalid string literal - check that length is'
...@@ -702,8 +701,7 @@ def compare_types(type_a, type_b): ...@@ -702,8 +701,7 @@ def compare_types(type_a, type_b):
else: else:
raise TypeError('Incompatible arrays') raise TypeError('Incompatible arrays')
return return
elif type_a.kind.endswith('StringType') and type_b.kind.endswith( elif type_a.kind.endswith('StringType') and type_b.kind.endswith('StringType'):
'StringType'):
# Allow Octet String values to be printable strings.. for convenience # Allow Octet String values to be printable strings.. for convenience
return return
elif not(type_a.kind in ('IntegerType', 'Integer32Type') and elif not(type_a.kind in ('IntegerType', 'Integer32Type') and
...@@ -824,7 +822,7 @@ def fix_expression_types(expr, context): ...@@ -824,7 +822,7 @@ def fix_expression_types(expr, context):
if fd_expr.exprType == UNKNOWN_TYPE: if fd_expr.exprType == UNKNOWN_TYPE:
try: try:
expected_type = asn_type.Children.get( expected_type = asn_type.Children.get(
field.replace('_', '-')).type field.replace('_', '-')).type
except AttributeError: except AttributeError:
raise TypeError('Field not found: ' + field) raise TypeError('Field not found: ' + field)
check_expr = ogAST.ExprAssign() check_expr = ogAST.ExprAssign()
...@@ -1804,7 +1802,6 @@ def procedure(root, parent=None, context=None): ...@@ -1804,7 +1802,6 @@ def procedure(root, parent=None, context=None):
def floating_label(root, parent, context): def floating_label(root, parent, context):
''' Floating label: name and optional transition ''' ''' Floating label: name and optional transition '''
_ = parent
errors = [] errors = []
warnings = [] warnings = []
lab = ogAST.Floating_label() lab = ogAST.Floating_label()
...@@ -1840,6 +1837,7 @@ def floating_label(root, parent, context): ...@@ -1840,6 +1837,7 @@ def floating_label(root, parent, context):
lab.terminators = list(context.terminators[terminators:]) lab.terminators = list(context.terminators[terminators:])
return lab, errors, warnings return lab, errors, warnings
def newtype_gettype(root, ta_ast, context): def newtype_gettype(root, ta_ast, context):
''' Returns the name of the new type created by a NEWTYPE construction ''' ''' Returns the name of the new type created by a NEWTYPE construction '''
errors = [] errors = []
...@@ -1847,27 +1845,29 @@ def newtype_gettype(root, ta_ast, context): ...@@ -1847,27 +1845,29 @@ def newtype_gettype(root, ta_ast, context):
newtypename = "" newtypename = ""
if (root.getChild(0).type != lexer.SORT): if (root.getChild(0).type != lexer.SORT):
warnings.append("Expected SORT in newtype identifier, got type:" warnings.append("Expected SORT in newtype identifier, got type:"
+ str(child.type)) + str(root.type))
return newtypename, errors, warnings return newtypename, errors, warnings
newtypename = root.getChild(0).getChild(0).text newtypename = root.getChild(0).getChild(0).text
return newtypename, errors, warnings return newtypename, errors, warnings
def get_array_type(root): def get_array_type(root):
''' Returns the subtype associated to an NEWTYPE ARRAY construction ''' ''' Returns the subtype associated to an NEWTYPE ARRAY construction '''
indexSort = root.getChild(0).text # indexSort = root.getChild(0).text
typeSort = root.getChild(1).text typeSort = root.getChild(1).text
typeSortLine = root.getChild(1).getLine() typeSortLine = root.getChild(1).getLine()
typeSortChar = root.getChild(1).getCharPositionInLine() typeSortChar = root.getChild(1).getCharPositionInLine()
# Constructing ASN.1 AST subtype # Constructing ASN.1 AST subtype
newtype = type("SeqOf_type", (object,), { newtype = type("SeqOf_type", (object,), {
"Line" : typeSortLine, "CharPositionInLine" : typeSortChar, "Line": typeSortLine, "CharPositionInLine": typeSortChar,
"Kind" : "ReferenceType" , "ReferencedTypeName" : typeSort "Kind": "ReferenceType", "ReferencedTypeName": typeSort
}) })
return newtype return newtype
def get_struct_children(root): def get_struct_children(root):
''' Returns the fields of a STRUCT as a dictionary ''' ''' Returns the fields of a STRUCT as a dictionary '''
children = {} children = {}
...@@ -1884,7 +1884,7 @@ def get_struct_children(root): ...@@ -1884,7 +1884,7 @@ def get_struct_children(root):
line = field.getChild(0).getLine() line = field.getChild(0).getLine()
charpos = field.getChild(0).getCharPositionInLine() charpos = field.getChild(0).getCharPositionInLine()
children[fieldname] = type(str(fieldname), (object ,), { children[fieldname] = type(str(fieldname), (object,), {
"Optional": "False", "Line": line, "Optional": "False", "Line": line,
"CharPositionInLine": charpos, "CharPositionInLine": charpos,
"type": type(str(fieldname + "_type"), (object,), { "type": type(str(fieldname + "_type"), (object,), {
...@@ -1894,6 +1894,7 @@ def get_struct_children(root): ...@@ -1894,6 +1894,7 @@ def get_struct_children(root):
}) })
return children return children
def syntype(root, ta_ast, context): def syntype(root, ta_ast, context):
''' Parse a SYNTYPE definition and inject it in ASN1 AST''' ''' Parse a SYNTYPE definition and inject it in ASN1 AST'''
errors = [] errors = []
...@@ -1903,21 +1904,22 @@ def syntype(root, ta_ast, context): ...@@ -1903,21 +1904,22 @@ def syntype(root, ta_ast, context):
global DV global DV
newtypename = root.getChild(0).getChild(0).text 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,), { newtype = type(str(newtypename), (object,), {
"Line" : root.getChild(0).getLine(), "Line": root.getChild(0).getLine(),
"CharPositionInLine" : root.getChild(0).getCharPositionInLine(), "CharPositionInLine": root.getChild(0).getCharPositionInLine(),
}) })
newtype.type = type(str(newtypename) + "_type", (object,), { newtype.type = type(str(newtypename) + "_type", (object,), {
"Line" : root.getChild(1).getLine(), "Line": root.getChild(1).getLine(),
"CharPositionInLine" : root.getChild(1).getCharPositionInLine(), "CharPositionInLine": root.getChild(1).getCharPositionInLine(),
"kind" : reftype + "Type" "kind": reftype + "Type"
}) })
DV.types[str(newtypename)] = newtype DV.types[str(newtypename)] = newtype
LOG.debug("Found new SYNTYPE " + newtypename) LOG.debug("Found new SYNTYPE " + newtypename)
return errors, warnings return errors, warnings
def newtype(root, ta_ast, context): def newtype(root, ta_ast, context):
''' Parse a NEWTYPE definition and inject it in ASN1 AST''' ''' Parse a NEWTYPE definition and inject it in ASN1 AST'''
errors = [] errors = []
...@@ -1929,8 +1931,8 @@ def newtype(root, ta_ast, context): ...@@ -1929,8 +1931,8 @@ def newtype(root, ta_ast, context):
return errors, warnings return errors, warnings
newtype = type(str(newtypename), (object,), { newtype = type(str(newtypename), (object,), {
"Line" : root.getLine(), "Line": root.getLine(),
"CharPositionInLine" : root.getCharPositionInLine()}) "CharPositionInLine": root.getCharPositionInLine()})
if (root.getChild(1).type == lexer.ARRAY): if (root.getChild(1).type == lexer.ARRAY):
newtype.kind = "SequenceOfType" newtype.kind = "SequenceOfType"
...@@ -1939,7 +1941,7 @@ def newtype(root, ta_ast, context): ...@@ -1939,7 +1941,7 @@ def newtype(root, ta_ast, context):
newtype.Max = "Max" newtype.Max = "Max"
DV.types[str(newtypename)] = newtype DV.types[str(newtypename)] = newtype
LOG.debug("Found new ARRAY type " + newtypename) LOG.debug("Found new ARRAY type " + newtypename)
elif (root.getChild(1).type == lexer.STRUCT): elif (root.getChild(1).type == lexer.STRUCT):
newtype.kind = "SequenceType" newtype.kind = "SequenceType"
newtype.Children = get_struct_children(root.getChild(1)) newtype.Children = get_struct_children(root.getChild(1))
DV.types[str(newtypename)] = newtype DV.types[str(newtypename)] = newtype
...@@ -1947,11 +1949,12 @@ def newtype(root, ta_ast, context): ...@@ -1947,11 +1949,12 @@ def newtype(root, ta_ast, context):
else: else:
warnings.append( warnings.append(
'Unsupported type definition in newtype, type: ' + 'Unsupported type definition in newtype, type: ' +
str(child.type)) str(root.type))
# STRUCT CASE # STRUCT CASE
return errors, warnings 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''' ''' Parse a SYNONYM definition and inject it in ASN1 exported variables'''
errors = [] errors = []
warnings = [] warnings = []
...@@ -1967,6 +1970,7 @@ def synonym (root, ta_ast, context): ...@@ -1967,6 +1970,7 @@ def synonym (root, ta_ast, context):
child.getChild(0).getChild(0).text) child.getChild(0).getChild(0).text)
return errors, warnings return errors, warnings
def text_area_content(root, ta_ast, context): def text_area_content(root, ta_ast, context):
''' Content of a text area: DCL, NEWTYPES, SYNTYPES, SYNONYMS, operators, ''' Content of a text area: DCL, NEWTYPES, SYNTYPES, SYNONYMS, operators,
procedures ''' procedures '''
...@@ -2221,7 +2225,7 @@ def process_definition(root, parent=None, context=None): ...@@ -2221,7 +2225,7 @@ def process_definition(root, parent=None, context=None):