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