Commit 84a6e427 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Better handle internal state and swig conversions

parent d8be14da
......@@ -514,16 +514,38 @@ class asn1Editor(QTreeView):
ASN1_AST: full AST generated by ASN1SCC
'''
var = self.getVariable(root).popitem()[1]
def reach(field, orig, idx=True):
''' Helper: move swig pointer to the next field, and optionaly
index (if idx=True)
Inputs: field is a string with optional index (e.g. "a[0]")
orig is the swig pointer
idx: set to true if you want the index to be reached
'''
split = field.strip(']').split('[')
ptr = getattr(orig, split[0]) if split else orig
if len(split) > 1 and idx:
# SEQOF index
ptr = ptr[int(split[1])]
def rec(inp, outp, sort):
''' Recursively fill up the value '''
if sort.kind == 'ReferenceType':
sort = ASN1_AST[sort.ReferencedTypeName]
if isinstance(inp, list):
# SEQUENCE OF
# get the path to the sequence of
_, params, path = outp.GetState()
if path:
path = path.strip('.').split('.')
for i in range(len(inp)):
outp.Reset()
for each in path:
reach(each, outp)
# Follow the ASN.1 type in the AST from ASN1SCC
rec(inp[i], outp[i], sort.type.type)
if sort.type.Min != sort.type.Max:
outp.Reset()
for each in path:
reach(each, outp)
# The ASN1SCC AST only knows if the list has a fixed length
outp.SetLength(len(inp))
elif isinstance(inp, (int, float, bool)):
......@@ -546,12 +568,23 @@ class asn1Editor(QTreeView):
ch_ty.type)
else:
# SEQUENCE
# get the path to the sequence
_, params, path = outp.GetState()
if path:
path = path.strip('.').split('.')
for field, data in inp.viewitems():
outp.Reset()
for each in path:
# Reach the path, including indexes
reach(each, outp)
# Then get the field itself
reach(field.replace('-', '_'), outp)
field_ty = sort.type.Children[field.replace('_', '-')]
#print outp, field, outp.GSER()
rec(data,
getattr(outp, field.replace('-', '_')),
field_ty.type)
rec(data, outp, field_ty.type)
# move back to original path
outp.Reset()
if len(path):
reach(path[0], outp)
else:
self.log.error('Unsupported type in to_asn1scc_swig')
rec(var, dest, sort)
......
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