Chromium Code Reviews| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 return _DecodeMethodName(mojom.INT32) | 145 return _DecodeMethodName(mojom.INT32) |
| 146 if mojom.IsInterfaceRequestKind(kind): | 146 if mojom.IsInterfaceRequestKind(kind): |
| 147 return "readInterfaceRequest" | 147 return "readInterfaceRequest" |
| 148 if mojom.IsInterfaceKind(kind): | 148 if mojom.IsInterfaceKind(kind): |
| 149 return "readServiceInterface" | 149 return "readServiceInterface" |
| 150 return _spec_to_decode_method[kind.spec] | 150 return _spec_to_decode_method[kind.spec] |
| 151 methodName = _DecodeMethodName(kind) | 151 methodName = _DecodeMethodName(kind) |
| 152 params = [ str(offset) ] | 152 params = [ str(offset) ] |
| 153 if (kind == mojom.BOOL): | 153 if (kind == mojom.BOOL): |
| 154 params.append(str(bit)) | 154 params.append(str(bit)) |
| 155 if mojom.IsAnyArrayKind(kind): | |
| 156 if mojom.IsFixedArrayKind(kind): | |
| 157 params.append(str(kind.length)) | |
| 158 else: | |
| 159 params.append( | |
| 160 "org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH"); | |
| 155 if mojom.IsInterfaceKind(kind): | 161 if mojom.IsInterfaceKind(kind): |
| 156 params.append('%s.MANAGER' % GetJavaType(context, kind)) | 162 params.append('%s.MANAGER' % GetJavaType(context, kind)) |
| 157 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 163 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
| 158 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) | 164 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
| 159 return '%s(%s)' % (methodName, ', '.join(params)) | 165 return '%s(%s)' % (methodName, ', '.join(params)) |
| 160 | 166 |
| 161 @contextfilter | 167 @contextfilter |
| 162 def EncodeMethod(context, kind, variable, offset, bit): | 168 def EncodeMethod(context, kind, variable, offset, bit): |
| 163 params = [ variable, str(offset) ] | 169 params = [ variable, str(offset) ] |
| 164 if (kind == mojom.BOOL): | 170 if (kind == mojom.BOOL): |
| 165 params.append(str(bit)) | 171 params.append(str(bit)) |
| 172 if mojom.IsAnyArrayKind(kind): | |
| 173 if mojom.IsFixedArrayKind(kind): | |
| 174 params.append(str(kind.length)) | |
| 175 else: | |
| 176 params.append( | |
| 177 "org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH"); | |
|
yzshen1
2014/08/29 16:32:24
One nit: Other bindings use 0 as "unspecified leng
qsr
2014/09/01 09:07:00
Not sure to understand exactly what to do here. Th
| |
| 166 if mojom.IsInterfaceKind(kind): | 178 if mojom.IsInterfaceKind(kind): |
| 167 params.append('%s.MANAGER' % GetJavaType(context, kind)) | 179 params.append('%s.MANAGER' % GetJavaType(context, kind)) |
| 168 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 180 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
| 169 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) | 181 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
| 170 return 'encode(%s)' % ', '.join(params) | 182 return 'encode(%s)' % ', '.join(params) |
| 171 | 183 |
| 172 def GetPackage(module): | 184 def GetPackage(module): |
| 173 if 'JavaPackage' in module.attributes: | 185 if 'JavaPackage' in module.attributes: |
| 174 return ParseStringAttribute(module.attributes['JavaPackage']) | 186 return ParseStringAttribute(module.attributes['JavaPackage']) |
| 175 # Default package. | 187 # Default package. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 | 328 |
| 317 java_filters = { | 329 java_filters = { |
| 318 "interface_response_name": GetInterfaceResponseName, | 330 "interface_response_name": GetInterfaceResponseName, |
| 319 "constant_value": ConstantValue, | 331 "constant_value": ConstantValue, |
| 320 "default_value": DefaultValue, | 332 "default_value": DefaultValue, |
| 321 "decode_method": DecodeMethod, | 333 "decode_method": DecodeMethod, |
| 322 "expression_to_text": ExpressionToText, | 334 "expression_to_text": ExpressionToText, |
| 323 "encode_method": EncodeMethod, | 335 "encode_method": EncodeMethod, |
| 324 "has_method_with_response": HasMethodWithResponse, | 336 "has_method_with_response": HasMethodWithResponse, |
| 325 "has_method_without_response": HasMethodWithoutResponse, | 337 "has_method_without_response": HasMethodWithoutResponse, |
| 338 "is_fixed_array_kind": mojom.IsFixedArrayKind, | |
| 326 "is_handle": mojom.IsNonInterfaceHandleKind, | 339 "is_handle": mojom.IsNonInterfaceHandleKind, |
| 327 "is_pointer_array_kind": IsPointerArrayKind, | 340 "is_pointer_array_kind": IsPointerArrayKind, |
| 328 "is_struct_kind": mojom.IsStructKind, | 341 "is_struct_kind": mojom.IsStructKind, |
| 329 "java_type": GetJavaType, | 342 "java_type": GetJavaType, |
| 330 "method_ordinal_name": GetMethodOrdinalName, | 343 "method_ordinal_name": GetMethodOrdinalName, |
| 331 "name": GetNameForElement, | 344 "name": GetNameForElement, |
| 332 "new_array": NewArray, | 345 "new_array": NewArray, |
| 333 "response_struct_from_method": GetResponseStructFromMethod, | 346 "response_struct_from_method": GetResponseStructFromMethod, |
| 334 "struct_from_method": GetStructFromMethod, | 347 "struct_from_method": GetStructFromMethod, |
| 335 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, | 348 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 def GetJinjaParameters(self): | 425 def GetJinjaParameters(self): |
| 413 return { | 426 return { |
| 414 'lstrip_blocks': True, | 427 'lstrip_blocks': True, |
| 415 'trim_blocks': True, | 428 'trim_blocks': True, |
| 416 } | 429 } |
| 417 | 430 |
| 418 def GetGlobals(self): | 431 def GetGlobals(self): |
| 419 return { | 432 return { |
| 420 'module': self.module, | 433 'module': self.module, |
| 421 } | 434 } |
| OLD | NEW |