2 This module contains helper classes for structure fields and length expressions.
6 Represents a field of a structure.
8 type is the datatype object for the field.
9 field_type is the name of the type (string tuple)
10 field_name is the name of the structure field.
11 visible is true iff the field should be in the request API.
12 wire is true iff the field should be in the request structure.
13 auto is true iff the field is on the wire but not in the request API (e.g. opcode)
15 def __init__(self, type, field_type, field_name, visible, wire, auto):
17 self.field_type = field_type
18 self.field_name = field_name
19 self.visible = visible
24 class Expression(object):
26 Represents a mathematical expression for a list length or exprfield.
29 op is the operation (text +,*,/,<<) or None.
30 lhs and rhs are the sub-Expressions if op is set.
31 lenfield_name is the name of the length field, or None for request lists.
32 lenfield is the Field object for the length field, or None.
33 bitfield is True if the length field is a bitmask instead of a number.
34 nmemb is the fixed size (value)of the expression, or None
36 def __init__(self, elt, parent):
41 self.lenfield_name = None
42 self.lenfield_type = None
52 # List going into a request, which has no length field (inferred by server)
53 self.lenfield_name = elt.get('name') + '_len'
54 self.lenfield_type = 'CARD32'
56 elif elt.tag == 'fieldref':
57 # Standard list with a fieldref
58 self.lenfield_name = elt.text
60 elif elt.tag == 'valueparam':
61 # Value-mask. The length bitmask is described by attributes.
62 self.lenfield_name = elt.get('value-mask-name')
63 self.lenfield_type = elt.get('value-mask-type')
68 # Op field. Need to recurse.
69 self.op = elt.get('op')
70 self.lhs = Expression(list(elt)[0], parent)
71 self.rhs = Expression(list(elt)[1], parent)
73 # Hopefully we don't have two separate length fields...
74 self.lenfield_name = self.lhs.lenfield_name
75 if self.lenfield_name == None:
76 self.lenfield_name = self.rhs.lenfield_name
78 elif elt.tag == 'value':
80 self.nmemb = int(elt.text)
84 raise Exception('XXX')
88 return self.nmemb != None