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

Added function returning sorted field list in SEQ/CHOICE types

parent 44a59893
......@@ -1515,6 +1515,7 @@ def path_type(path):
# Sequence, Choice (case insensitive)
if current.kind in ('SequenceType', 'ChoiceType'):
#print list(Helper.sorted_fields(current))
elem_asn1 = elem.replace('_', '-').lower()
type_idx, = (c for c in current.Children
if c.lower() == elem_asn1)
......@@ -11,6 +11,8 @@
inner_labels_to_floating(process) : remove labels from transitions
map_input_state(process) -> mapping: create a mapping
sorted_fields(SEQ/CHOICE) : returns the ordered list of fields
of an ASN.1 SEQUENCE or CHOICE type
Copyright (c) 2012-2014 European Space Agency
......@@ -19,6 +21,7 @@
import operator
import logging
from itertools import chain
from collections import defaultdict
......@@ -30,7 +33,7 @@ import ogAST
LOG = logging.getLogger(__name__)
__all__ = ['flatten', 'rename_everything', 'inner_labels_to_floating',
'map_input_state', 'sorted_fields']
def map_input_state(process):
......@@ -436,3 +439,12 @@ def find_labels(trans):
[slice(idx + 1, len(trans.actions))])
new_fl.transition.terminator = trans.terminator
yield new_fl
def sorted_fields(atype):
''' Return the sorted list of a SEQUENCE or CHOICE type fields '''
if atype.kind not in ('SequenceType', 'ChoiceType'):
raise TypeError('Not a SEQUENCE nor a CHOICE')
tmp = ([k, val.Line, val.CharPositionInLine]
for k, val in atype.Children.viewitems())
return (x[0] for x in sorted(tmp, key=operator.itemgetter(1,2)))
......@@ -22,8 +22,8 @@ IMPORTS T-Int32, T-UInt32, T-Int8, T-UInt8, T-Boolean FROM TASTE-BasicTypes;
sit-1 FCE-SIT-1,
sit-2 FCE-SIT-2,
sit-3 FCE-SIT-3,
sit-2 FCE-SIT-2,
sit-4 FCE-SIT-4
Supports Markdown
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