Skip to content

Commit

Permalink
general: add support for declaring enums as struct members
Browse files Browse the repository at this point in the history
the enum types are resolved to the wiretypes for the benefit of c-loxi.
  • Loading branch information
andi-bigswitch committed Sep 17, 2013
1 parent bea97f5 commit 37c7bc2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions loxi_utils/loxi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import sys
import of_g
import tenjin
from generic_utils import find, memoize

def class_signature(members):
"""
Expand Down Expand Up @@ -517,6 +518,17 @@ def render_static(out, name, path):
with open(template_filename) as infile:
out.write(infile.read())

@memoize
def lookup_ir_wiretype(oftype, version):
""" if of is a reference to an enum in ir, resolve it to the wiretype
declared in that enum. Else return oftype """
enums = of_g.ir[version].enums
enum = find(lambda e: e.name == oftype, enums)
if enum and 'wire_type' in enum.params:
return enum.params['wire_type']
else:
return oftype

class TemplateEngine(tenjin.Engine):
def include(self, template_name, **kwargs):
"""
Expand Down
6 changes: 5 additions & 1 deletion loxigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,11 @@ def read_input():
if m.oftype == 'of_oxm_t':
m_type = 'of_octets_t'
else:
m_type = m.oftype
enum = find(lambda e: e.name == m.oftype, ofinput.enums)
if enum and "wire_type" in enum.params:
m_type = enum.params["wire_type"]
else:
m_type = m.oftype
legacy_members.append(dict(m_type=m_type, name=m.name))
versions[version_name]['classes'][ofclass.name] = legacy_members

Expand Down

0 comments on commit 37c7bc2

Please sign in to comment.