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

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: fix test Created 6 years, 4 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 kind_spec == 'd':
264 if token == "double.INFINITY":
265 return "java.lang.Double.POSITIVE_INFINITY"
266 if token == "double.NEGATIVE_INFINITY":
267 return "java.lang.Double.NEGATIVE_INFINITY"
268 if token == "double.NAN":
269 return "java.lang.Double.NaN"
270 if kind_spec == 'f':
271 if token == "float.INFINITY":
272 return "java.lang.Float.POSITIVE_INFINITY"
273 if token == "-float.NEGATIVE_INFINITY":
274 return "java.lang.Float.NEGATIVE_INFINITY"
275 if token == "float.NAN":
276 return "java.lang.Float.NaN"
263 return token 277 return token
264 278
265 def IsPointerArrayKind(kind): 279 def IsPointerArrayKind(kind):
266 if not mojom.IsAnyArrayKind(kind): 280 if not mojom.IsAnyArrayKind(kind):
267 return False 281 return False
268 sub_kind = kind.kind 282 sub_kind = kind.kind
269 return mojom.IsObjectKind(sub_kind) 283 return mojom.IsObjectKind(sub_kind)
270 284
271 def GetConstantsMainEntityName(module): 285 def GetConstantsMainEntityName(module):
272 if 'JavaConstantsClassName' in module.attributes: 286 if 'JavaConstantsClassName' in module.attributes:
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 def GetJinjaParameters(self): 376 def GetJinjaParameters(self):
363 return { 377 return {
364 'lstrip_blocks': True, 378 'lstrip_blocks': True,
365 'trim_blocks': True, 379 'trim_blocks': True,
366 } 380 }
367 381
368 def GetGlobals(self): 382 def GetGlobals(self):
369 return { 383 return {
370 'module': self.module, 384 'module': self.module,
371 } 385 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698