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 """Generates java source files from a mojom.Module.""" | 5 """Generates java source files from a mojom.Module.""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import ast | 8 import ast |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 return ConstantStyle(element.name) | 129 return ConstantStyle(element.name) |
130 raise Exception("Unexpected element: " % element) | 130 raise Exception("Unexpected element: " % element) |
131 | 131 |
132 def GetInterfaceResponseName(method): | 132 def GetInterfaceResponseName(method): |
133 return UpperCamelCase(method.name + 'Response') | 133 return UpperCamelCase(method.name + 'Response') |
134 | 134 |
135 def ParseStringAttribute(attribute): | 135 def ParseStringAttribute(attribute): |
136 assert isinstance(attribute, basestring) | 136 assert isinstance(attribute, basestring) |
137 return attribute | 137 return attribute |
138 | 138 |
139 def GetJavaTrueFalse(value): | |
140 return "true" if value else "false" | |
141 | |
139 @contextfilter | 142 @contextfilter |
140 def DecodeMethod(context, kind, offset, bit): | 143 def DecodeMethod(context, kind, offset, bit): |
141 def _DecodeMethodName(kind): | 144 def _DecodeMethodName(kind): |
142 if mojom.IsAnyArrayKind(kind): | 145 if mojom.IsAnyArrayKind(kind): |
143 return _DecodeMethodName(kind.kind) + 's' | 146 return _DecodeMethodName(kind.kind) + 's' |
144 if mojom.IsEnumKind(kind): | 147 if mojom.IsEnumKind(kind): |
145 return _DecodeMethodName(mojom.INT32) | 148 return _DecodeMethodName(mojom.INT32) |
146 if mojom.IsInterfaceRequestKind(kind): | 149 if mojom.IsInterfaceRequestKind(kind): |
147 return "readInterfaceRequest" | 150 return "readInterfaceRequest" |
148 if mojom.IsInterfaceKind(kind): | 151 if mojom.IsInterfaceKind(kind): |
149 return "readServiceInterface" | 152 return "readServiceInterface" |
150 return _spec_to_decode_method[kind.spec] | 153 return _spec_to_decode_method[kind.spec] |
151 methodName = _DecodeMethodName(kind) | 154 methodName = _DecodeMethodName(kind) |
152 additionalParams = '' | 155 additionalParams = '' |
153 if (kind == mojom.BOOL): | 156 if (kind == mojom.BOOL): |
154 additionalParams = ', %d' % bit | 157 additionalParams = ', %d' % bit |
158 if mojom.IsReferenceKind(kind): | |
159 additionalParams = ', %s' % GetJavaTrueFalse(mojom.IsNullableKind(kind)) | |
155 if mojom.IsInterfaceKind(kind): | 160 if mojom.IsInterfaceKind(kind): |
156 additionalParams = ', %s.MANAGER' % GetJavaType(context, kind) | 161 additionalParams += ', %s.MANAGER' % GetJavaType(context, kind) |
157 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 162 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
158 additionalParams = ', %s.MANAGER' % GetJavaType(context, kind.kind) | 163 additionalParams += ', %s.MANAGER' % GetJavaType(context, kind.kind) |
159 return '%s(%s%s)' % (methodName, offset, additionalParams) | 164 return '%s(%s%s)' % (methodName, offset, additionalParams) |
160 | 165 |
161 @contextfilter | 166 @contextfilter |
162 def EncodeMethod(context, kind, variable, offset, bit): | 167 def EncodeMethod(context, kind, variable, offset, bit): |
163 additionalParams = '' | 168 additionalParams = '' |
164 if (kind == mojom.BOOL): | 169 if (kind == mojom.BOOL): |
165 additionalParams = ', %d' % bit | 170 additionalParams = ', %d' % bit |
166 if mojom.IsInterfaceKind(kind): | 171 if mojom.IsInterfaceKind(kind): |
167 additionalParams = ', %s.MANAGER' % GetJavaType(context, kind) | 172 additionalParams = ', %s.MANAGER' % GetJavaType(context, kind) |
168 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 173 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 java_filters = { | 322 java_filters = { |
318 "interface_response_name": GetInterfaceResponseName, | 323 "interface_response_name": GetInterfaceResponseName, |
319 "constant_value": ConstantValue, | 324 "constant_value": ConstantValue, |
320 "default_value": DefaultValue, | 325 "default_value": DefaultValue, |
321 "decode_method": DecodeMethod, | 326 "decode_method": DecodeMethod, |
322 "expression_to_text": ExpressionToText, | 327 "expression_to_text": ExpressionToText, |
323 "encode_method": EncodeMethod, | 328 "encode_method": EncodeMethod, |
324 "has_method_with_response": HasMethodWithResponse, | 329 "has_method_with_response": HasMethodWithResponse, |
325 "has_method_without_response": HasMethodWithoutResponse, | 330 "has_method_without_response": HasMethodWithoutResponse, |
326 "is_handle": mojom.IsNonInterfaceHandleKind, | 331 "is_handle": mojom.IsNonInterfaceHandleKind, |
332 "is_nullable_kind": mojom.IsNullableKind, | |
qsr
2014/08/29 07:56:20
The java_filters is only there to make method avai
ppi
2014/08/29 14:03:34
I do use both of them in macro decode of struct_de
| |
327 "is_pointer_array_kind": IsPointerArrayKind, | 333 "is_pointer_array_kind": IsPointerArrayKind, |
328 "is_struct_kind": mojom.IsStructKind, | 334 "is_struct_kind": mojom.IsStructKind, |
329 "java_type": GetJavaType, | 335 "java_type": GetJavaType, |
336 "java_true_false": GetJavaTrueFalse, | |
330 "method_ordinal_name": GetMethodOrdinalName, | 337 "method_ordinal_name": GetMethodOrdinalName, |
331 "name": GetNameForElement, | 338 "name": GetNameForElement, |
332 "new_array": NewArray, | 339 "new_array": NewArray, |
333 "response_struct_from_method": GetResponseStructFromMethod, | 340 "response_struct_from_method": GetResponseStructFromMethod, |
334 "struct_from_method": GetStructFromMethod, | 341 "struct_from_method": GetStructFromMethod, |
335 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, | 342 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, |
336 } | 343 } |
337 | 344 |
338 def GetJinjaExports(self): | 345 def GetJinjaExports(self): |
339 return { | 346 return { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 def GetJinjaParameters(self): | 419 def GetJinjaParameters(self): |
413 return { | 420 return { |
414 'lstrip_blocks': True, | 421 'lstrip_blocks': True, |
415 'trim_blocks': True, | 422 'trim_blocks': True, |
416 } | 423 } |
417 | 424 |
418 def GetGlobals(self): | 425 def GetGlobals(self): |
419 return { | 426 return { |
420 'module': self.module, | 427 'module': self.module, |
421 } | 428 } |
OLD | NEW |