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.IsArrayKind(kind): | |
ppi
2014/08/29 15:23:45
nit: how about checking if mojom.IsAnyArrayKind at
qsr
2014/08/29 16:24:11
Done.
| |
156 params.append( | |
157 "org.chromium.mojo.bindings.BindingsHelper.UNDEFINED_ARRAY_LENTH"); | |
158 if mojom.IsFixedArrayKind(kind): | |
159 params.append(str(kind.length)) | |
155 if mojom.IsInterfaceKind(kind): | 160 if mojom.IsInterfaceKind(kind): |
156 params.append('%s.MANAGER' % GetJavaType(context, kind)) | 161 params.append('%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 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) | 163 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
159 return '%s(%s)' % (methodName, ', '.join(params)) | 164 return '%s(%s)' % (methodName, ', '.join(params)) |
160 | 165 |
161 @contextfilter | 166 @contextfilter |
162 def EncodeMethod(context, kind, variable, offset, bit): | 167 def EncodeMethod(context, kind, variable, offset, bit): |
163 params = [ variable, str(offset) ] | 168 params = [ variable, str(offset) ] |
164 if (kind == mojom.BOOL): | 169 if (kind == mojom.BOOL): |
165 params.append(str(bit)) | 170 params.append(str(bit)) |
171 if mojom.IsArrayKind(kind): | |
172 params.append( | |
173 "org.chromium.mojo.bindings.BindingsHelper.UNDEFINED_ARRAY_LENTH"); | |
174 if mojom.IsFixedArrayKind(kind): | |
175 params.append(str(kind.length)) | |
166 if mojom.IsInterfaceKind(kind): | 176 if mojom.IsInterfaceKind(kind): |
167 params.append('%s.MANAGER' % GetJavaType(context, kind)) | 177 params.append('%s.MANAGER' % GetJavaType(context, kind)) |
168 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 178 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
169 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) | 179 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
170 return 'encode(%s)' % ', '.join(params) | 180 return 'encode(%s)' % ', '.join(params) |
171 | 181 |
172 def GetPackage(module): | 182 def GetPackage(module): |
173 if 'JavaPackage' in module.attributes: | 183 if 'JavaPackage' in module.attributes: |
174 return ParseStringAttribute(module.attributes['JavaPackage']) | 184 return ParseStringAttribute(module.attributes['JavaPackage']) |
175 # Default package. | 185 # Default package. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 | 326 |
317 java_filters = { | 327 java_filters = { |
318 "interface_response_name": GetInterfaceResponseName, | 328 "interface_response_name": GetInterfaceResponseName, |
319 "constant_value": ConstantValue, | 329 "constant_value": ConstantValue, |
320 "default_value": DefaultValue, | 330 "default_value": DefaultValue, |
321 "decode_method": DecodeMethod, | 331 "decode_method": DecodeMethod, |
322 "expression_to_text": ExpressionToText, | 332 "expression_to_text": ExpressionToText, |
323 "encode_method": EncodeMethod, | 333 "encode_method": EncodeMethod, |
324 "has_method_with_response": HasMethodWithResponse, | 334 "has_method_with_response": HasMethodWithResponse, |
325 "has_method_without_response": HasMethodWithoutResponse, | 335 "has_method_without_response": HasMethodWithoutResponse, |
336 "is_fixed_array_kind": mojom.IsFixedArrayKind, | |
326 "is_handle": mojom.IsNonInterfaceHandleKind, | 337 "is_handle": mojom.IsNonInterfaceHandleKind, |
327 "is_pointer_array_kind": IsPointerArrayKind, | 338 "is_pointer_array_kind": IsPointerArrayKind, |
328 "is_struct_kind": mojom.IsStructKind, | 339 "is_struct_kind": mojom.IsStructKind, |
329 "java_type": GetJavaType, | 340 "java_type": GetJavaType, |
330 "method_ordinal_name": GetMethodOrdinalName, | 341 "method_ordinal_name": GetMethodOrdinalName, |
331 "name": GetNameForElement, | 342 "name": GetNameForElement, |
332 "new_array": NewArray, | 343 "new_array": NewArray, |
333 "response_struct_from_method": GetResponseStructFromMethod, | 344 "response_struct_from_method": GetResponseStructFromMethod, |
334 "struct_from_method": GetStructFromMethod, | 345 "struct_from_method": GetStructFromMethod, |
335 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, | 346 "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): | 423 def GetJinjaParameters(self): |
413 return { | 424 return { |
414 'lstrip_blocks': True, | 425 'lstrip_blocks': True, |
415 'trim_blocks': True, | 426 'trim_blocks': True, |
416 } | 427 } |
417 | 428 |
418 def GetGlobals(self): | 429 def GetGlobals(self): |
419 return { | 430 return { |
420 'module': self.module, | 431 'module': self.module, |
421 } | 432 } |
OLD | NEW |