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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 return _spec_to_decode_method[kind.spec] | 179 return _spec_to_decode_method[kind.spec] |
180 methodName = _DecodeMethodName(kind) | 180 methodName = _DecodeMethodName(kind) |
181 params = [ str(offset) ] | 181 params = [ str(offset) ] |
182 if (kind == mojom.BOOL): | 182 if (kind == mojom.BOOL): |
183 params.append(str(bit)) | 183 params.append(str(bit)) |
184 if mojom.IsReferenceKind(kind): | 184 if mojom.IsReferenceKind(kind): |
185 if mojom.IsAnyArrayKind(kind): | 185 if mojom.IsAnyArrayKind(kind): |
186 params.append(GetArrayNullabilityFlags(kind)) | 186 params.append(GetArrayNullabilityFlags(kind)) |
187 else: | 187 else: |
188 params.append(GetJavaTrueFalse(mojom.IsNullableKind(kind))) | 188 params.append(GetJavaTrueFalse(mojom.IsNullableKind(kind))) |
| 189 if mojom.IsAnyArrayKind(kind): |
| 190 if mojom.IsFixedArrayKind(kind): |
| 191 params.append(str(kind.length)) |
| 192 else: |
| 193 params.append( |
| 194 "org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH"); |
189 if mojom.IsInterfaceKind(kind): | 195 if mojom.IsInterfaceKind(kind): |
190 params.append('%s.MANAGER' % GetJavaType(context, kind)) | 196 params.append('%s.MANAGER' % GetJavaType(context, kind)) |
191 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 197 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
192 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) | 198 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
193 return '%s(%s)' % (methodName, ', '.join(params)) | 199 return '%s(%s)' % (methodName, ', '.join(params)) |
194 | 200 |
195 @contextfilter | 201 @contextfilter |
196 def EncodeMethod(context, kind, variable, offset, bit): | 202 def EncodeMethod(context, kind, variable, offset, bit): |
197 params = [ variable, str(offset) ] | 203 params = [ variable, str(offset) ] |
198 if (kind == mojom.BOOL): | 204 if (kind == mojom.BOOL): |
199 params.append(str(bit)) | 205 params.append(str(bit)) |
| 206 if mojom.IsAnyArrayKind(kind): |
| 207 if mojom.IsFixedArrayKind(kind): |
| 208 params.append(str(kind.length)) |
| 209 else: |
| 210 params.append( |
| 211 "org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH"); |
200 if mojom.IsInterfaceKind(kind): | 212 if mojom.IsInterfaceKind(kind): |
201 params.append('%s.MANAGER' % GetJavaType(context, kind)) | 213 params.append('%s.MANAGER' % GetJavaType(context, kind)) |
202 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 214 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
203 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) | 215 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
204 return 'encode(%s)' % ', '.join(params) | 216 return 'encode(%s)' % ', '.join(params) |
205 | 217 |
206 def GetPackage(module): | 218 def GetPackage(module): |
207 if 'JavaPackage' in module.attributes: | 219 if 'JavaPackage' in module.attributes: |
208 return ParseStringAttribute(module.attributes['JavaPackage']) | 220 return ParseStringAttribute(module.attributes['JavaPackage']) |
209 # Default package. | 221 # Default package. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 362 |
351 java_filters = { | 363 java_filters = { |
352 "interface_response_name": GetInterfaceResponseName, | 364 "interface_response_name": GetInterfaceResponseName, |
353 "constant_value": ConstantValue, | 365 "constant_value": ConstantValue, |
354 "default_value": DefaultValue, | 366 "default_value": DefaultValue, |
355 "decode_method": DecodeMethod, | 367 "decode_method": DecodeMethod, |
356 "expression_to_text": ExpressionToText, | 368 "expression_to_text": ExpressionToText, |
357 "encode_method": EncodeMethod, | 369 "encode_method": EncodeMethod, |
358 "has_method_with_response": HasMethodWithResponse, | 370 "has_method_with_response": HasMethodWithResponse, |
359 "has_method_without_response": HasMethodWithoutResponse, | 371 "has_method_without_response": HasMethodWithoutResponse, |
| 372 "is_fixed_array_kind": mojom.IsFixedArrayKind, |
360 "is_handle": mojom.IsNonInterfaceHandleKind, | 373 "is_handle": mojom.IsNonInterfaceHandleKind, |
361 "is_nullable_kind": mojom.IsNullableKind, | 374 "is_nullable_kind": mojom.IsNullableKind, |
362 "is_pointer_array_kind": IsPointerArrayKind, | 375 "is_pointer_array_kind": IsPointerArrayKind, |
363 "is_struct_kind": mojom.IsStructKind, | 376 "is_struct_kind": mojom.IsStructKind, |
364 "java_type": GetJavaType, | 377 "java_type": GetJavaType, |
365 "java_true_false": GetJavaTrueFalse, | 378 "java_true_false": GetJavaTrueFalse, |
366 "method_ordinal_name": GetMethodOrdinalName, | 379 "method_ordinal_name": GetMethodOrdinalName, |
367 "name": GetNameForElement, | 380 "name": GetNameForElement, |
368 "new_array": NewArray, | 381 "new_array": NewArray, |
369 "response_struct_from_method": GetResponseStructFromMethod, | 382 "response_struct_from_method": GetResponseStructFromMethod, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 def GetJinjaParameters(self): | 461 def GetJinjaParameters(self): |
449 return { | 462 return { |
450 'lstrip_blocks': True, | 463 'lstrip_blocks': True, |
451 'trim_blocks': True, | 464 'trim_blocks': True, |
452 } | 465 } |
453 | 466 |
454 def GetGlobals(self): | 467 def GetGlobals(self): |
455 return { | 468 return { |
456 'module': self.module, | 469 'module': self.module, |
457 } | 470 } |
OLD | NEW |