Rich Lane | 002e70c | 2013-05-09 17:08:16 -0700 | [diff] [blame] | 1 | :: from loxi_ir import * |
Rich Lane | da11f8b | 2013-06-19 15:53:25 -0700 | [diff] [blame] | 2 | :: import py_gen.oftype |
Rich Lane | a2de219 | 2013-11-29 17:58:32 -0800 | [diff] [blame^] | 3 | :: type_members = [m for m in ofclass.members if type(m) == OFTypeMember] |
Rich Lane | 002e70c | 2013-05-09 17:08:16 -0700 | [diff] [blame] | 4 | :: normal_members = [m for m in ofclass.members if type(m) == OFDataMember] |
Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 5 | class ${ofclass.pyname}(${superclass}): |
Rich Lane | a2de219 | 2013-11-29 17:58:32 -0800 | [diff] [blame^] | 6 | :: for m in type_members: |
Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 7 | ${m.name} = ${m.value} |
| 8 | :: #endfor |
| 9 | |
Rich Lane | 8ca3b77 | 2013-04-30 13:36:55 -0700 | [diff] [blame] | 10 | def __init__(${', '.join(['self'] + ["%s=None" % m.name for m in normal_members])}): |
| 11 | :: for m in normal_members: |
Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 12 | if ${m.name} != None: |
| 13 | self.${m.name} = ${m.name} |
| 14 | else: |
Rich Lane | 0f7f9d5 | 2013-11-29 17:00:49 -0800 | [diff] [blame] | 15 | :: if m.name == 'xid': |
| 16 | :: # HACK for message xid |
| 17 | self.${m.name} = None |
| 18 | :: else: |
Andreas Wundsam | 69ecfdc | 2013-09-17 13:50:12 -0700 | [diff] [blame] | 19 | self.${m.name} = ${py_gen.oftype.gen_init_expr(m.oftype, version=version)} |
Rich Lane | 0f7f9d5 | 2013-11-29 17:00:49 -0800 | [diff] [blame] | 20 | :: #endif |
Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 21 | :: #endfor |
| 22 | return |
| 23 | |
| 24 | def pack(self): |
| 25 | packed = [] |
| 26 | :: include("_pack.py", ofclass=ofclass) |
| 27 | return ''.join(packed) |
| 28 | |
| 29 | @staticmethod |
| 30 | def unpack(buf): |
| 31 | obj = ${ofclass.pyname}() |
| 32 | :: include("_unpack.py", ofclass=ofclass) |
| 33 | return obj |
| 34 | |
| 35 | def __eq__(self, other): |
| 36 | if type(self) != type(other): return False |
Rich Lane | 8ca3b77 | 2013-04-30 13:36:55 -0700 | [diff] [blame] | 37 | :: for m in normal_members: |
Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 38 | if self.${m.name} != other.${m.name}: return False |
| 39 | :: #endfor |
| 40 | return True |
| 41 | |
| 42 | def __ne__(self, other): |
| 43 | return not self.__eq__(other) |
| 44 | |
| 45 | def show(self): |
| 46 | import loxi.pp |
| 47 | return loxi.pp.pp(self) |
| 48 | |
| 49 | def pretty_print(self, q): |
| 50 | :: include('_pretty_print.py', ofclass=ofclass) |