Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_java_generator.py

Issue 474063002: Mojo: add support for {double,float}.{INFINITY,NEGATIVE_INFINITY,NAN} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: another windows fix Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 # Add Long suffix to all integer literals. 253 # Add Long suffix to all integer literals.
254 number = ast.literal_eval(token.lstrip('+ ')) 254 number = ast.literal_eval(token.lstrip('+ '))
255 if not isinstance(number, (int, long)): 255 if not isinstance(number, (int, long)):
256 raise ValueError('got unexpected type %r for int literal %r' % ( 256 raise ValueError('got unexpected type %r for int literal %r' % (
257 type(number), token)) 257 type(number), token))
258 # If the literal is too large to fit a signed long, convert it to the 258 # If the literal is too large to fit a signed long, convert it to the
259 # equivalent signed long. 259 # equivalent signed long.
260 if number >= 2 ** 63: 260 if number >= 2 ** 63:
261 number -= 2 ** 64 261 number -= 2 ** 64
262 return '%dL' % number 262 return '%dL' % number
263 if isinstance(token, mojom.BuiltinValue):
264 if token.value == "double.INFINITY":
265 return "java.lang.Double.POSITIVE_INFINITY"
266 if token.value == "double.NEGATIVE_INFINITY":
267 return "java.lang.Double.NEGATIVE_INFINITY"
268 if token.value == "double.NAN":
269 return "java.lang.Double.NaN"
270 if token.value == "float.INFINITY":
271 return "java.lang.Float.POSITIVE_INFINITY"
272 if token.value == "float.NEGATIVE_INFINITY":
273 return "java.lang.Float.NEGATIVE_INFINITY"
274 if token.value == "float.NAN":
275 return "java.lang.Float.NaN"
263 return token 276 return token
264 277
265 def IsPointerArrayKind(kind): 278 def IsPointerArrayKind(kind):
266 if not mojom.IsAnyArrayKind(kind): 279 if not mojom.IsAnyArrayKind(kind):
267 return False 280 return False
268 sub_kind = kind.kind 281 sub_kind = kind.kind
269 return mojom.IsObjectKind(sub_kind) 282 return mojom.IsObjectKind(sub_kind)
270 283
271 def GetConstantsMainEntityName(module): 284 def GetConstantsMainEntityName(module):
272 if 'JavaConstantsClassName' in module.attributes: 285 if 'JavaConstantsClassName' in module.attributes:
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 def GetJinjaParameters(self): 375 def GetJinjaParameters(self):
363 return { 376 return {
364 'lstrip_blocks': True, 377 'lstrip_blocks': True,
365 'trim_blocks': True, 378 'trim_blocks': True,
366 } 379 }
367 380
368 def GetGlobals(self): 381 def GetGlobals(self):
369 return { 382 return {
370 'module': self.module, 383 'module': self.module,
371 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698