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

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

Powered by Google App Engine
This is Rietveld 408576698