Commit 59698041 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Iterate on Python3/PySide2

It can be installed and executed.. but many things misbehave
parent 65365327
......@@ -1502,8 +1502,8 @@ def _task_forloop(task, **kwargs):
local_decl.extend(stop_local)
stmt.extend(stop_stmt)
if loop['range']['step'] == 1:
if unicode.isnumeric(stop_str):
stop_str = unicode(int(stop_str) - 1)
if str.isnumeric(stop_str):
stop_str = str(int(stop_str) - 1)
else:
stop_str = u'{} - 1'.format(stop_str)
stmt.append(u'for {it} in {start}{stop} loop'
......@@ -1592,7 +1592,7 @@ def _primary_variable(prim, **kwargs):
ada_string = u'{sep}{name}'.format(sep=sep, name=prim.value[0])
return [], unicode(ada_string), []
return [], str(ada_string), []
@expression.register(ogAST.PrimCall)
......@@ -1839,7 +1839,7 @@ def _prim_call(prim, **kwargs):
ada_string += ', '.join(list_of_params)
ada_string += ')'
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.PrimIndex)
......@@ -1856,7 +1856,7 @@ def _prim_index(prim, **kwargs):
index = prim.value[1]['index'][0]
idx_stmts, idx_string, idx_var = expression(index, readonly=ro)
if unicode.isnumeric(idx_string):
if str.isnumeric(idx_string):
idx_string = int(idx_string) + 1
else:
idx_string = u'1 + Integer({idx})'.format(idx=idx_string)
......@@ -1866,7 +1866,7 @@ def _prim_index(prim, **kwargs):
stmts.extend(idx_stmts)
local_decl.extend(idx_var)
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.PrimSubstring)
......@@ -1888,12 +1888,12 @@ def _prim_substring(prim, **kwargs):
readonly=ro)
# Adding 1 because SDL starts indexes at 0, ASN1 Ada types at 1
if unicode.isnumeric(r1_string):
r1_string = unicode(int(r1_string) + 1)
if str.isnumeric(r1_string):
r1_string = str(int(r1_string) + 1)
else:
r1_string = u"Integer({}) + 1".format(r1_string)
if unicode.isnumeric(r2_string):
r2_string = unicode(int(r2_string) + 1)
if str.isnumeric(r2_string):
r2_string = str(int(r2_string) + 1)
else:
r2_string = u"Integer({}) + 1".format(r2_string)
......@@ -1905,7 +1905,7 @@ def _prim_substring(prim, **kwargs):
local_decl.extend(r1_local)
local_decl.extend(r2_local)
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.PrimSelector)
......@@ -1941,7 +1941,7 @@ def _prim_selector(prim, **kwargs):
stmts.append(u'{}.Exist.{} := 1;'.format(ada_string, field_name))
ada_string += '.' + field_name
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.PrimStateReference)
......@@ -2011,7 +2011,7 @@ def _basic_operators(expr, **kwargs):
code.extend(right_stmts)
local_decl.extend(left_local)
local_decl.extend(right_local)
return code, unicode(ada_string), local_decl
return code, str(ada_string), local_decl
@expression.register(ogAST.ExprEq)
......@@ -2055,7 +2055,7 @@ def _equality(expr, **kwargs):
op=expr.operand, right=right_str)
if isinstance(expr, ogAST.ExprNeq):
ada_string = u'not {}'.format(ada_string)
return code, unicode(ada_string), local_decl
return code, str(ada_string), local_decl
@expression.register(ogAST.ExprAssign)
......@@ -2203,7 +2203,7 @@ def _bitwise_operators(expr, **kwargs):
code.extend(right_stmts)
local_decl.extend(left_local)
local_decl.extend(right_local)
return code, unicode(ada_string), local_decl
return code, str(ada_string), local_decl
@expression.register(ogAST.ExprNot)
......@@ -2235,7 +2235,7 @@ def _not_expression(expr, **kwargs):
code.extend(expr_stmts)
local_decl.extend(expr_local)
return code, unicode(ada_string), local_decl
return code, str(ada_string), local_decl
@expression.register(ogAST.ExprNeg)
......@@ -2253,7 +2253,7 @@ def _neg_expression(expr, **kwargs):
ada_string = u'(-{expr})'.format(expr=expr_str)
code.extend(expr_stmts)
local_decl.extend(expr_local)
return code, unicode(ada_string), local_decl
return code, str(ada_string), local_decl
@expression.register(ogAST.ExprAppend)
......@@ -2307,7 +2307,7 @@ def _append(expr, **kwargs):
# rMax=expr.right.exprType.Max)
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.ExprIn)
......@@ -2364,7 +2364,7 @@ def _expr_in(expr, **kwargs):
.format(tmp=ada_string))
stmts.append(u"end loop in_loop_{};".format(ada_string))
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.PrimEnumeratedValue)
......@@ -2379,7 +2379,7 @@ def _enumerated_value(primary, **kwargs):
use_prefix = getattr(basic.EnumValues[each], "IsStandardEnum", True)
prefix = type_name(basic, use_prefix=use_prefix)
ada_string = (prefix + basic.EnumValues[each].EnumID)
return [], unicode(ada_string), []
return [], str(ada_string), []
@expression.register(ogAST.PrimChoiceDeterminant)
......@@ -2390,7 +2390,7 @@ def _choice_determinant(primary, **kwargs):
if each.lower() == enumerant:
break
ada_string = primary.exprType.EnumValues[each].EnumID
return [], unicode(ada_string), []
return [], str(ada_string), []
@expression.register(ogAST.PrimInteger)
......@@ -2403,28 +2403,28 @@ def _integer(primary, **kwargs):
ada_string = u'({})'.format(primary.value[0])
else:
ada_string = primary.value[0]
return [], unicode(ada_string), []
return [], str(ada_string), []
@expression.register(ogAST.PrimBoolean)
def _boolean(primary, **kwargs):
''' Generate code for a raw boolean value '''
ada_string = primary.value[0]
return [], unicode(ada_string), []
return [], str(ada_string), []
@expression.register(ogAST.PrimNull)
def _boolean(primary, **kwargs):
''' Generate code for a raw null value '''
ada_string = '0'
return [], unicode(ada_string), []
return [], str(ada_string), []
@expression.register(ogAST.PrimEmptyString)
def _empty_string(primary, **kwargs):
''' Generate code for an empty SEQUENCE OF: {} '''
ada_string = u'{}_Init'.format(type_name(primary.exprType))
return [], unicode(ada_string), []
return [], str(ada_string), []
@expression.register(ogAST.PrimStringLiteral)
......@@ -2437,13 +2437,13 @@ def _string_literal(primary, **kwargs):
unsigned_8 = [str(ord(val)) for val in primary.value[1:-1]]
ada_string = u', '.join(unsigned_8)
return [], unicode(ada_string), []
return [], str(ada_string), []
@expression.register(ogAST.PrimConstant)
def _constant(primary, **kwargs):
''' Generate code for a reference to an ASN.1 constant '''
return [], unicode(primary.constant_c_name), []
return [], str(primary.constant_c_name), []
@expression.register(ogAST.PrimMantissaBaseExp)
......@@ -2539,7 +2539,7 @@ def _conditional(cond, **kwargs):
.format(idx=cond.value['tmpVar'], else_len=else_len))
stmts.append('end if;')
ada_string = u'tmp{idx}'.format(idx=cond.value['tmpVar'])
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.PrimSequence)
......@@ -2603,7 +2603,7 @@ def _sequence(seq, **kwargs):
ada_string += u')'
ada_string += ')'
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.PrimSequenceOf)
......@@ -2622,7 +2622,7 @@ def _sequence_of(seqof, **kwargs):
sortref = sortref.type
asn_type = find_basic_type(sortref)
tab = []
for i in xrange(len(seqof.value)):
for i in range(len(seqof.value)):
item_stmts, item_str, local_var = expression(seqof.value[i],
readonly=1)
if isinstance(seqof.value[i],
......@@ -2633,7 +2633,7 @@ def _sequence_of(seqof, **kwargs):
local_decl.extend(local_var)
tab.append(u'{i} => {value}'.format(i=i + 1, value=item_str))
ada_string = u', '.join(tab)
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@expression.register(ogAST.PrimChoiceItem)
......@@ -2661,7 +2661,7 @@ def _choiceitem(choice, **kwargs):
kind=prefix,
opt=choice.value['choice'],
expr=choice_str)
return stmts, unicode(ada_string), local_decl
return stmts, str(ada_string), local_decl
@generate.register(ogAST.Decision)
......@@ -2841,7 +2841,7 @@ def _transition(tr, **kwargs):
code.append(u'trId := -1;')
elif not history: # tr.terminator.inputString.strip() != '-':
code.append(u'trId := ' +
unicode(tr.terminator.next_id) + u';')
str(tr.terminator.next_id) + u';')
if tr.terminator.next_id == -1:
if not tr.terminator.substate: # XXX add to C generator
code.append(u'{ctxt}.state := {nextState};'
......
......@@ -108,7 +108,7 @@ def parse_asn1(*files, **options):
out_py_name = new_hash + ".py"
out_html_name = new_hash + ".html"
if new_hash in AST.viewkeys():
if new_hash in AST.keys():
return AST[new_hash]
elif project_cache is not None:
outdir = project_cache
......@@ -189,7 +189,7 @@ def create_choice_determinant_types(ast):
returns the newly created types (does not modify input AST)
'''
new_sorts = {}
for each in (sort for sort in ast.types.viewvalues()
for each in (sort for sort in ast.types.values()
if sort.type.kind == 'ChoiceType'):
new_sort = each.__name__ + '-selection'
if new_sort in ast.types:
......@@ -262,7 +262,7 @@ def asn2dataModel(*files):
make.start(make_bin, args)
waitfor_qprocess(make, 'make -f Makefile.python')
if concat_prefix in ASN2DM.viewkeys():
if concat_prefix in ASN2DM.keys():
# Re-import module if it was already loaded
asn1mod = ASN2DM[concat_prefix]
reload(asn1mod)
......
......@@ -978,7 +978,7 @@ def _transition(tr, **kwargs):
label=tr.terminator.label.inputString))
if tr.terminator.kind == 'next_state':
if tr.terminator.inputString.strip() != '-':
stmts.append(u'trId = ' + unicode(tr.terminator.next_id) + u';')
stmts.append(u'trId = ' + str(tr.terminator.next_id) + u';')
if tr.terminator.next_id == -1:
stmts.append(u'{ctxt}.state = {nextState};'.format(ctxt=LPREFIX, nextState=tr.terminator.inputString.lower()))
else:
......@@ -1040,7 +1040,7 @@ def _primary_variable(prim):
else:
string = u'{lp}.{name}'.format(lp=LPREFIX, name=prim.value[0])
return [], unicode(string.lower()), []
return [], str(string.lower()), []
@expression.register(ogAST.PrimCall)
......@@ -1197,7 +1197,7 @@ def _prim_index(prim):
stmts.extend(idx_stmts)
local_decl.extend(idx_var)
return stmts, unicode(string), local_decl
return stmts, str(string), local_decl
......@@ -1215,7 +1215,7 @@ def _prim_substring(prim):
ret_decls.extend(base_decls)
r1_stmts, r1_string, r1_local = expression(prim.value[1]['substring'][0])
r2_stmts, r2_string, r2_local = expression(prim.value[1]['substring'][1])
if unicode.isnumeric(r1_string) and unicode.isnumeric(r2_string):
if str.isnumeric(r1_string) and str.isnumeric(r2_string):
ret_decls.extend(['char var' + tmp_var_id + '[' + (int(r2_string) - int(r1_string) + 1) + '];'])
else:
ret_decls.extend(['char * var' + tmp_var_id + ';'])
......@@ -1262,7 +1262,7 @@ def _prim_selector(prim):
field_case = field_name
string += '.' + field_case
return stmts, unicode(string), local_decl
return stmts, str(string), local_decl
@expression.register(ogAST.PrimStateReference)
......@@ -1294,7 +1294,7 @@ def _basic_operators(expr):
code.extend(right_stmts)
local_decl.extend(left_local)
local_decl.extend(right_local)
return code, unicode(string), local_decl
return code, str(string), local_decl
@expression.register(ogAST.ExprMod)
......@@ -1308,7 +1308,7 @@ def _basic_operators(expr):
code.extend(right_stmts)
local_decl.extend(left_local)
local_decl.extend(right_local)
return code, unicode(string), local_decl
return code, str(string), local_decl
@expression.register(ogAST.ExprEq)
......@@ -1366,7 +1366,7 @@ def _equality(expr):
string = u"({left}) {op} ({right})".format(left=left_string, op=operand, right=right_string)
if isinstance(expr, ogAST.ExprNeq):
string = u'! {}'.format(string)
return stmts, unicode(string), decls
return stmts, str(string), decls
@expression.register(ogAST.ExprAssign)
......@@ -1470,7 +1470,7 @@ def _bitwise_operators(expr):
stmts.extend(right_stmts)
decls.extend(left_local)
decls.extend(right_local)
return stmts, unicode(string), decls
return stmts, str(string), decls
@expression.register(ogAST.ExprNot)
......@@ -1516,7 +1516,7 @@ def _not_expression(expr):
else:
string = u'!{expr}'.format(expr=expr_str.replace(',',',!'))
return stmts, unicode(string), decls
return stmts, str(string), decls
@expression.register(ogAST.ExprNeg)
......@@ -1527,7 +1527,7 @@ def _neg_expression(expr):
string = u'(-{expr})'.format( expr=expr_str)
code.extend(expr_stmts)
local_decl.extend(expr_local)
return code, unicode(string), local_decl
return code, str(string), local_decl
@expression.register(ogAST.ExprAppend)
......@@ -1769,7 +1769,7 @@ def _append(expr):
else:
raise NotImplementedError(str(type(expr.left)) + str(type(expr.right)))
stmts.append(u'}')
return stmts, unicode(string), decls
return stmts, str(string), decls
@expression.register(ogAST.ExprIn)
......@@ -1809,7 +1809,7 @@ def _expr_in(expr):
stmts.append(u'break;')
stmts.append(u'}')
stmts.append(u'}')
return stmts, unicode(string), decls
return stmts, str(string), decls
@expression.register(ogAST.PrimEnumeratedValue)
......@@ -1822,7 +1822,7 @@ def _enumerated_value(primary):
break
prefix = type_name(basic)
string = (prefix + basic.EnumValues[each].EnumID)
return [], unicode(string), []
return [], str(string), []
@expression.register(ogAST.PrimChoiceDeterminant)
......@@ -1833,7 +1833,7 @@ def _choice_determinant(primary):
if each.lower() == enumerant:
break
string = primary.exprType.EnumValues[each].EnumID
return [], unicode(string), []
return [], str(string), []
@expression.register(ogAST.PrimInteger)
......@@ -1841,21 +1841,21 @@ def _choice_determinant(primary):
def _integer(primary):
''' Generate code for a raw numerical value '''
string = primary.value[0]
return [], unicode(string), []
return [], str(string), []
@expression.register(ogAST.PrimBoolean)
def _boolean(primary):
''' Generate code for a raw boolean value '''
string = primary.value[0]
return [], unicode(string.lower()), []
return [], str(string.lower()), []
@expression.register(ogAST.PrimEmptyString)
def _empty_string(primary):
''' Generate code for an empty SEQUENCE OF: {} '''
string = u'{}_Init()'.format(type_name(primary.exprType))
return [], unicode(string), []
return [], str(string), []
@expression.register(ogAST.PrimStringLiteral)
......@@ -1868,13 +1868,13 @@ def _string_literal(primary):
unsigned_8 = [str(ord(val)) for val in primary.value[1:-1]]
string = u', '.join(unsigned_8)
return [], unicode(string), []
return [], str(string), []
@expression.register(ogAST.PrimConstant)
def _constant(primary):
''' Generate code for a reference to an ASN.1 constant '''
return [], unicode(primary.value[0]), []
return [], str(primary.value[0]), []
@expression.register(ogAST.PrimMantissaBaseExp)
......@@ -1916,7 +1916,7 @@ def _conditional(cond):
stmts.append(u'tmp{idx} = {else_str};'.format(idx=cond.value['tmpVar'], else_str=else_str))
stmts.append(u'}')
string = u'tmp{idx}'.format(idx=cond.value['tmpVar'])
return stmts, unicode(string), local_decl
return stmts, str(string), local_decl
@expression.register(ogAST.PrimSequence)
......@@ -1970,7 +1970,7 @@ def _sequence(seq):
string += u'}'
string += '}'
return stmts, unicode(string), local_decl
return stmts, str(string), local_decl
@expression.register(ogAST.PrimSequenceOf)
......@@ -1992,7 +1992,7 @@ def _sequence_of(seqof):
except AttributeError:
pass
tab = []
for i in xrange(len(seqof.value)):
for i in range(len(seqof.value)):
temp = ''
item_stmts, item_str, local_var = expression(seqof.value[i])
if isinstance(seqof.value[i], (ogAST.PrimSequenceOf, ogAST.PrimStringLiteral)):
......@@ -2002,7 +2002,7 @@ def _sequence_of(seqof):
local_decl.extend(local_var)
tab.append(temp)
string += u', '.join(tab)
return stmts, unicode(string), local_decl
return stmts, str(string), local_decl
@expression.register(ogAST.PrimChoiceItem)
......@@ -2013,7 +2013,7 @@ def _choiceitem(choice):
choice_str = array_content(choice.value['value'], choice_str, find_basic_type(choice.value['value'].exprType))
choice_str = u'({ty}) {cs}'.format(ty=u'asn1Scc' + find_basic_type(choice.value['value'].exprType).__name__[:-5], cs=choice_str)
string = u'{cType}_{opt}_set({expr})'.format(cType=type_name(choice.exprType), opt=choice.value['choice'], expr=choice_str)
return stmts, unicode(string), local_decl
return stmts, str(string), local_decl
def append_size(append):
''' Return a string corresponding to the length of an APPEND construct
......@@ -2067,7 +2067,7 @@ def _prim_substring(prim):
local_decl.extend(r2_local)
local_decl.append(u'unsigned int max_range_{var_counter};'.format(var_counter=VAR_COUNTER))
return stmts, unicode(string), local_decl
return stmts, str(string), local_decl
......
......@@ -312,12 +312,12 @@ class Signalroute(Connection):
''' Called when user modified the text of label_in or label_out '''
for each in self.label_in, self.label_out:
if not each.hasFocus():
if not unicode(each).startswith('['):
each.setPlainText('[{}'.format(unicode(each)))
if not unicode(each).endswith(']'):
each.setPlainText('{}]'.format(unicode(each)))
Signalroute.in_sig = unicode(self.label_in)[1:-1]
Signalroute.out_sig = unicode(self.label_out)[1:-1]
if not str(each).startswith('['):
each.setPlainText('[{}'.format(str(each)))
if not str(each).endswith(']'):
each.setPlainText('{}]'.format(str(each)))
Signalroute.in_sig = str(self.label_in)[1:-1]
Signalroute.out_sig = str(self.label_out)[1:-1]
@property
......@@ -556,7 +556,7 @@ class Edge(Connection):
self.bezier = [self.mapFromScene(*self.edge['spline'][0])]
# Bezier control points (groups of three points):
assert(len(self.edge['spline']) % 3 == 1)
for i in xrange(1, len(self.edge['spline']), 3):
for i in range(1, len(self.edge['spline']), 3):
self.bezier.append([Controlpoint(
self.mapFromScene(*self.edge['spline'][i + j]), self)
for j in range(3)])
......
......@@ -144,7 +144,7 @@ def inner_labels_to_floating(process):
section of code, where they are in the scope of everybody
Works with processes, procedures and nested states
'''
for idx in xrange(len(process.content.floating_labels)):
for idx in range(len(process.content.floating_labels)):
for new_floating in find_labels(
process.content.floating_labels[idx].transition):
process.content.floating_labels.append(new_floating)
......
......@@ -159,7 +159,7 @@ class Context():
basic_asn1ty = asn1ty
while basic_asn1ty.kind == 'ReferenceType':
for typename in self.dataview.viewkeys():
for typename in self.dataview.keys():
if typename.lower() == basic_asn1ty.ReferencedTypeName.lower():
basic_asn1ty = self.dataview[typename].type
break
......@@ -406,7 +406,7 @@ def _process(process, ctx=None, options=None):
mapping = Helper.map_input_state(process)
# Initialize states
for name, val in process.mapping.viewitems():
for name, val in process.mapping.items():
if not name.endswith('START'):
cons_val = lc.Constant.int(ctx.i32, len(ctx.states))
ctx.states[name.lower()] = cons_val
......@@ -420,14 +420,14 @@ def _process(process, ctx=None, options=None):
ctx.scope.define('.state', state_cons)
# Generate ASN.1 constants
for name, t in process.dv.variables.viewitems():
for name, t in process.dv.variables.items():
var_llty = ctx.lltype_of(t.type)
name = str(name).replace('-', '_').lower()
global_var = ctx.module.add_global_variable(var_llty, name)
ctx.scope.define(name, global_var)
# Generare process-level vars
for name, (asn1ty, expr) in process.variables.viewitems():
for name, (asn1ty, expr) in process.variables.items():
var_llty = ctx.lltype_of(asn1ty)
global_var = ctx.module.add_global_variable(var_llty, str(name))
global_var.initializer = lc.Constant.null(var_llty)
......@@ -559,7 +559,7 @@ def generate_startup_func(process, ctx):
ctx.builder = lc.Builder.new(entry_block)
# Initialize process level variables
for name, (ty, expr) in process.variables.viewitems():
for name, (ty, expr) in process.variables.items():
if expr:
global_var = ctx.scope.resolve(str(name))
right = expression(expr, ctx)
......@@ -1601,7 +1601,7 @@ def _prim_sequence(prim, ctx):
seq_asn1ty = ctx.dataview[prim.exprType.ReferencedTypeName]
for field_name, field_expr in prim.value.viewitems():
for field_name, field_expr in prim.value.items():
# Workaround for unknown types in nested sequences
#field_expr.exprType = seq_asn1ty.type.Children[field_name.replace('_', '-')].type
field_expr.exprType = ctx.basic_asn1type_of(prim.exprType).Children[\
......@@ -1756,7 +1756,7 @@ def generate_next_state_terminator(term, ctx):
next_id_val = ctx.states[term.next_id.lower()]
ctx.builder.store(next_id_val, ctx.scope.resolve('id'))
else:
nexts = [(n, s) for (n, s) in term.candidate_id.viewitems() if n != -1]
nexts = [(n, s) for (n, s) in term.candidate_id.items() if n != -1]
if nexts:
# Calculate next transition id in base of the current state
func = ctx.builder.basic_block.function
......@@ -1841,7 +1841,7 @@ def _procedure(proc, ctx):
entry_block = func.append_basic_block('proc:entry')
ctx.builder = lc.Builder.new(entry_block)
for name, (ty, expr) in proc.variables.viewitems():
for name, (ty, expr) in proc.variables.items():