Commit dc45a40a authored by dbarbera's avatar dbarbera
Browse files

Added choice determinant generation

parent 4a99fbc8
...@@ -44,6 +44,7 @@ class Context(): ...@@ -44,6 +44,7 @@ class Context():
self.scope = Scope() self.scope = Scope()
self.global_scope = self.scope self.global_scope = self.scope
self.states = {} self.states = {}
self.enums = {}
self.structs = {} self.structs = {}
self.unions = {} self.unions = {}
self.strings = {} self.strings = {}
...@@ -164,9 +165,13 @@ class Context(): ...@@ -164,9 +165,13 @@ class Context():
''' Return the equivalent LL type of a Choice ASN.1 type ''' ''' Return the equivalent LL type of a Choice ASN.1 type '''
field_names = [] field_names = []
field_types = [] field_types = []
for field_name, field_ty in choice_ty.Children.viewitems():
for idx, field_name in enumerate(Helper.sorted_fields(choice_ty)):
# enum values used in choice determinant/present
self.enums[field_name] = core.Constant.int(self.i32, idx)
field_names.append(field_name) field_names.append(field_name)
field_types.append(self.type_of(field_ty.type)) field_types.append(self.type_of(choice_ty.Children[field_name].type))
union = self.decl_union(field_names, field_types, name) union = self.decl_union(field_names, field_types, name)
return union.ty return union.ty
...@@ -1074,7 +1079,8 @@ def _enumerated_value(primary): ...@@ -1074,7 +1079,8 @@ def _enumerated_value(primary):
@expression.register(ogAST.PrimChoiceDeterminant) @expression.register(ogAST.PrimChoiceDeterminant)
def _choice_determinant(primary): def _choice_determinant(primary):
''' Generate code for a choice determinant (enumerated) ''' ''' Generate code for a choice determinant (enumerated) '''
raise NotImplementedError enumerant = primary.value[0].replace('_', '-')
return ctx.enums[enumerant]
@expression.register(ogAST.PrimInteger) @expression.register(ogAST.PrimInteger)
......
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