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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/data.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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 # TODO(vtl): "data" is a pretty vague name. Rename it? 5 # TODO(vtl): "data" is a pretty vague name. Rename it?
6 6
7 import copy 7 import copy
8 8
9 import module as mojom 9 import module as mojom
10 10
(...skipping 24 matching lines...) Expand all
35 # pretty printing maintain the order. 35 # pretty printing maintain the order.
36 def istr(index, string): 36 def istr(index, string):
37 class IndexedString(str): 37 class IndexedString(str):
38 def __lt__(self, other): 38 def __lt__(self, other):
39 return self.__index__ < other.__index__ 39 return self.__index__ < other.__index__
40 40
41 rv = IndexedString(string) 41 rv = IndexedString(string)
42 rv.__index__ = index 42 rv.__index__ = index
43 return rv 43 return rv
44 44
45 builtin_values = frozenset([
46 "double.INFINITY",
47 "double.NEGATIVE_INFINITY",
48 "double.NAN",
49 "float.INFINITY",
50 "float.NEGATIVE_INFINITY",
51 "float.NAN"])
52
53 def IsBuiltinValue(value):
54 return value in builtin_values
55
45 def LookupKind(kinds, spec, scope): 56 def LookupKind(kinds, spec, scope):
46 """Tries to find which Kind a spec refers to, given the scope in which its 57 """Tries to find which Kind a spec refers to, given the scope in which its
47 referenced. Starts checking from the narrowest scope to most general. For 58 referenced. Starts checking from the narrowest scope to most general. For
48 example, given a struct field like 59 example, given a struct field like
49 Foo.Bar x; 60 Foo.Bar x;
50 Foo.Bar could refer to the type 'Bar' in the 'Foo' namespace, or an inner 61 Foo.Bar could refer to the type 'Bar' in the 'Foo' namespace, or an inner
51 type 'Bar' in the struct 'Foo' in the current namespace. 62 type 'Bar' in the struct 'Foo' in the current namespace.
52 63
53 |scope| is a tuple that looks like (namespace, struct/interface), referring 64 |scope| is a tuple that looks like (namespace, struct/interface), referring
54 to the location where the type is referenced.""" 65 to the location where the type is referenced."""
(...skipping 23 matching lines...) Expand all
78 if test_spec: 89 if test_spec:
79 test_spec += '.' 90 test_spec += '.'
80 test_spec += name 91 test_spec += name
81 value = values.get(test_spec) 92 value = values.get(test_spec)
82 if value: 93 if value:
83 return value 94 return value
84 95
85 return values.get(name) 96 return values.get(name)
86 97
87 def FixupExpression(module, value, scope, kind): 98 def FixupExpression(module, value, scope, kind):
88 """Translates an IDENTIFIER into a structured Value object.""" 99 """Translates an IDENTIFIER into a built-in value or structured NamedValue
100 object."""
89 if isinstance(value, tuple) and value[0] == 'IDENTIFIER': 101 if isinstance(value, tuple) and value[0] == 'IDENTIFIER':
102 # Allow user defined values to shadow builtins.
90 result = LookupValue(module.values, value[1], scope, kind) 103 result = LookupValue(module.values, value[1], scope, kind)
91 if result: 104 if result:
92 return result 105 return result
106 if IsBuiltinValue(value[1]):
107 return mojom.BuiltinValue(value[1])
93 return value 108 return value
94 109
95 def KindToData(kind): 110 def KindToData(kind):
96 return kind.spec 111 return kind.spec
97 112
98 def KindFromData(kinds, data, scope): 113 def KindFromData(kinds, data, scope):
99 kind = LookupKind(kinds, data, scope) 114 kind = LookupKind(kinds, data, scope)
100 if kind: 115 if kind:
101 return kind 116 return kind
102 117
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 365
351 def OrderedModuleFromData(data): 366 def OrderedModuleFromData(data):
352 module = ModuleFromData(data) 367 module = ModuleFromData(data)
353 for interface in module.interfaces: 368 for interface in module.interfaces:
354 next_ordinal = 0 369 next_ordinal = 0
355 for method in interface.methods: 370 for method in interface.methods:
356 if method.ordinal is None: 371 if method.ordinal is None:
357 method.ordinal = next_ordinal 372 method.ordinal = next_ordinal
358 next_ordinal = method.ordinal + 1 373 next_ordinal = method.ordinal + 1
359 return module 374 return module
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_js_generator.py ('k') | mojo/public/tools/bindings/pylib/mojom/generate/module.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698