1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 class Interface(object):
9 def Func(self
, name
, return_type
):
10 f
= Function(self
, len(self
.functions
), name
, return_type
)
11 self
.functions
.append(f
)
15 for f
in self
.functions
:
18 class Function(object):
19 def __init__(self
, parent
, uid
, name
, return_type
):
23 self
.return_type
= return_type
25 self
.param_by_name
= {}
26 self
.result_param
= None
28 def Param(self
, name
, param_type
=None):
29 p
= Param(self
, len(self
.params
), name
, param_type
)
31 self
.param_by_name
[name
] = p
35 return [param
.param_type
+ ' ' + param
.name
for param
in self
.params
]
39 return ', '.join(self
.ParamList())
44 self
.result_param
= Param(self
, len(self
.params
), 'result')
45 self
.result_param
.Out(self
.return_type
).AlwaysWritten()
48 def __init__(self
, parent
, uid
, name
, param_type
=None):
52 self
.base_type
= param_type
53 self
.param_type
= param_type
56 self
.is_output
= False
58 self
.is_struct
= False
59 self
.is_extensible
= False
60 self
.is_optional
= False
61 self
.is_always_written
= False
63 def GetSizeParam(self
):
65 return self
.parent
.param_by_name
[self
.size
]
73 def InArray(self
, ty
, size
):
75 self
.param_type
= 'const ' + ty
+ '*'
81 # An "extensible" struct is one where we don't know the exact size - rather
82 # the first 4 bytes of the struct declare the length of the struct. This
83 # allows forwards and backwards compatibility with additive changes to the
84 # structure definition.
85 def InExtensibleStruct(self
, ty
):
87 self
.param_type
= 'const struct ' + ty
+ '*'
90 self
.is_extensible
= True
95 self
.param_type
= ty
+ '*'
102 self
.param_type
= ty
+ '*'
103 self
.is_output
= True
106 def OutArray(self
, ty
, size
):
108 self
.param_type
= ty
+ '*'
111 self
.is_output
= True
114 # The size of the struct is fixed by the API, it cannot be extended.
115 def OutFixedStruct(self
, ty
):
117 self
.param_type
= 'struct ' + ty
+ '*'
118 self
.is_output
= True
119 self
.is_struct
= True
120 self
.is_extensible
= False
123 def OutFixedStructArray(self
, ty
, size
):
125 self
.param_type
= 'struct ' + ty
+ '*'
128 self
.is_output
= True
131 # Declares that it is valid to pass a null pointer.
133 assert not self
.IsPassedByValue()
134 self
.is_optional
= True
137 def AlwaysWritten(self
):
138 assert self
.is_output
, self
139 self
.is_always_written
= True
143 return not self
.is_array
and not self
.is_struct
145 def IsPassedByValue(self
):
146 return not self
.is_output
and self
.IsScalar()