| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 class Interface(object): | 5 class Interface(object): |
| 6 def __init__(self): | 6 def __init__(self): |
| 7 self.functions = [] | 7 self.functions = [] |
| 8 | 8 |
| 9 def Func(self, name, return_type): | 9 def Func(self, name, return_type): |
| 10 f = Function(self, len(self.functions), name, return_type) | 10 f = Function(self, len(self.functions), name, return_type) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 return [param.param_type + ' ' + param.name for param in self.params] | 35 return [param.param_type + ' ' + param.name for param in self.params] |
| 36 | 36 |
| 37 def ParamDecl(self): | 37 def ParamDecl(self): |
| 38 if self.params: | 38 if self.params: |
| 39 return ', '.join(self.ParamList()) | 39 return ', '.join(self.ParamList()) |
| 40 else: | 40 else: |
| 41 return 'void' | 41 return 'void' |
| 42 | 42 |
| 43 def Finalize(self): | 43 def Finalize(self): |
| 44 self.result_param = Param(self, len(self.params), 'result') | 44 self.result_param = Param(self, len(self.params), 'result') |
| 45 self.result_param.Out(self.return_type) | 45 self.result_param.Out(self.return_type).AlwaysWritten() |
| 46 | 46 |
| 47 class Param(object): | 47 class Param(object): |
| 48 def __init__(self, parent, uid, name, param_type=None): | 48 def __init__(self, parent, uid, name, param_type=None): |
| 49 self.parent = parent | 49 self.parent = parent |
| 50 self.uid = uid | 50 self.uid = uid |
| 51 self.name = name | 51 self.name = name |
| 52 self.base_type = param_type | 52 self.base_type = param_type |
| 53 self.param_type = param_type | 53 self.param_type = param_type |
| 54 self.size = None | 54 self.size = None |
| 55 self.is_input = False | 55 self.is_input = False |
| 56 self.is_output = False | 56 self.is_output = False |
| 57 self.is_array = False | 57 self.is_array = False |
| 58 self.is_struct = False | 58 self.is_struct = False |
| 59 self.is_extensible = False |
| 59 self.is_optional = False | 60 self.is_optional = False |
| 61 self.is_always_written = False |
| 60 | 62 |
| 61 def GetSizeParam(self): | 63 def GetSizeParam(self): |
| 62 assert self.size | 64 assert self.size |
| 63 return self.parent.param_by_name[self.size] | 65 return self.parent.param_by_name[self.size] |
| 64 | 66 |
| 65 def In(self, ty): | 67 def In(self, ty): |
| 66 self.base_type = ty | 68 self.base_type = ty |
| 67 self.param_type = ty | 69 self.param_type = ty |
| 68 self.is_input = True | 70 self.is_input = True |
| 69 return self | 71 return self |
| 70 | 72 |
| 71 def InArray(self, ty, size): | 73 def InArray(self, ty, size): |
| 72 self.base_type = ty | 74 self.base_type = ty |
| 73 self.param_type = 'const ' + ty + '*' | 75 self.param_type = 'const ' + ty + '*' |
| 74 self.size = size | 76 self.size = size |
| 75 self.is_input = True | 77 self.is_input = True |
| 76 self.is_array = True | 78 self.is_array = True |
| 77 return self | 79 return self |
| 78 | 80 |
| 79 def InStruct(self, 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): |
| 80 self.base_type = ty | 86 self.base_type = ty |
| 81 self.param_type = 'const struct ' + ty + '*' | 87 self.param_type = 'const struct ' + ty + '*' |
| 82 self.is_input = True | 88 self.is_input = True |
| 83 self.is_struct = True | 89 self.is_struct = True |
| 90 self.is_extensible = True |
| 84 return self | 91 return self |
| 85 | 92 |
| 86 def InOut(self, ty): | 93 def InOut(self, ty): |
| 87 self.base_type = ty | 94 self.base_type = ty |
| 88 self.param_type = ty + '*' | 95 self.param_type = ty + '*' |
| 89 self.is_input = True | 96 self.is_input = True |
| 90 self.is_output = True | 97 self.is_output = True |
| 91 return self | 98 return self |
| 92 | 99 |
| 93 def Out(self, ty): | 100 def Out(self, ty): |
| 94 self.base_type = ty | 101 self.base_type = ty |
| 95 self.param_type = ty + '*' | 102 self.param_type = ty + '*' |
| 96 self.is_output = True | 103 self.is_output = True |
| 97 return self | 104 return self |
| 98 | 105 |
| 99 def OutArray(self, ty, size): | 106 def OutArray(self, ty, size): |
| 100 self.base_type = ty | 107 self.base_type = ty |
| 101 self.param_type = ty + '*' | 108 self.param_type = ty + '*' |
| 102 self.size = size | 109 self.size = size |
| 103 self.is_array = True | 110 self.is_array = True |
| 104 self.is_output = True | 111 self.is_output = True |
| 105 return self | 112 return self |
| 106 | 113 |
| 114 # The size of the struct is fixed by the API, it cannot be extended. |
| 115 def OutFixedStruct(self, ty): |
| 116 self.base_type = ty |
| 117 self.param_type = 'struct ' + ty + '*' |
| 118 self.is_output = True |
| 119 self.is_struct = True |
| 120 self.is_extensible = False |
| 121 return self |
| 122 |
| 123 # Declares that it is valid to pass a null pointer. |
| 107 def Optional(self): | 124 def Optional(self): |
| 108 assert not self.IsPassedByValue() | 125 assert not self.IsPassedByValue() |
| 109 self.is_optional = True | 126 self.is_optional = True |
| 110 return self | 127 return self |
| 111 | 128 |
| 129 def AlwaysWritten(self): |
| 130 assert self.is_output, self |
| 131 self.is_always_written = True |
| 132 return self |
| 133 |
| 112 def IsScalar(self): | 134 def IsScalar(self): |
| 113 return not self.is_array and not self.is_struct | 135 return not self.is_array and not self.is_struct |
| 114 | 136 |
| 115 def IsPassedByValue(self): | 137 def IsPassedByValue(self): |
| 116 return not self.is_output and self.IsScalar() | 138 return not self.is_output and self.IsScalar() |
| OLD | NEW |