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

Side by Side Diff: sky/engine/bindings-dart/dart/scripts/dart_utilities.py

Issue 918273002: Remove bindings-dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
(Empty)
1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 """Functions shared by various parts of the code generator.
30
31 Extends IdlType and IdlUnion type with |enum_validation_expression| property.
32
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
34 """
35
36
37 ################################################################################
38 # Utility function exposed for Dart CodeGenerator. Only 6 methods are special
39 # to Dart the rest delegate to the v8_utilities functions.
40 ################################################################################
41
42
43 import v8_types # Required
44 import v8_utilities
45
46
47 def _scoped_name(interface, definition, base_name):
48 # partial interfaces are implemented as separate classes, with their members
49 # implemented as static member functions
50 partial_interface_implemented_as = definition.extended_attributes.get('Parti alInterfaceImplementedAs')
51 if partial_interface_implemented_as:
52 return '%s::%s' % (partial_interface_implemented_as, base_name)
53 if (definition.is_static or
54 definition.name in ('Constructor', 'NamedConstructor')):
55 return '%s::%s' % (v8_utilities.cpp_name(interface), base_name)
56 return 'receiver->%s' % base_name
57
58
59 def _bool_to_cpp(tf):
60 return "true" if tf else "false"
61
62
63 # [ActivityLogging]
64 def _activity_logging_world_list(member, access_type=None):
65 """Returns a set of world suffixes for which a definition member has activit y logging, for specified access type.
66
67 access_type can be 'Getter' or 'Setter' if only checking getting or setting.
68 """
69 if 'ActivityLogging' not in member.extended_attributes:
70 return set()
71 activity_logging = member.extended_attributes['ActivityLogging']
72 # [ActivityLogging=For*] (no prefix, starts with the worlds suffix) means
73 # "log for all use (method)/access (attribute)", otherwise check that value
74 # agrees with specified access_type (Getter/Setter).
75 has_logging = (activity_logging.startswith('For') or
76 (access_type and activity_logging.startswith(access_type)))
77 if not has_logging:
78 return set()
79 # TODO(terry): Remove Me?
80 # includes.add('bindings/core/v8/V8DOMActivityLogger.h')
81 if activity_logging.endswith('ForIsolatedWorlds'):
82 return set([''])
83 return set(['', 'ForMainWorld']) # endswith('ForAllWorlds')
84
85
86 # [CallWith]
87 _CALL_WITH_ARGUMENTS = {
88 'ScriptState': 'state',
89 'ExecutionContext': 'context',
90 'ScriptArguments': 'scriptArguments.release()',
91 'ActiveWindow': 'DartUtilities::callingDomWindowForCurrentIsolate()',
92 'FirstWindow': 'DartUtilities::enteredDomWindowForCurrentIsolate()',
93 'Document': 'document',
94 }
95
96 # List because key order matters, as we want arguments in deterministic order
97 _CALL_WITH_VALUES = [
98 'ScriptState',
99 'ExecutionContext',
100 'ScriptArguments',
101 'ActiveWindow',
102 'FirstWindow',
103 'Document',
104 ]
105
106
107 def _call_with_arguments(call_with_values):
108 if not call_with_values:
109 return []
110 return [_CALL_WITH_ARGUMENTS[value]
111 for value in _CALL_WITH_VALUES
112 if v8_utilities.extended_attribute_value_contains(call_with_values, value)]
113
114
115 # [DeprecateAs]
116 def _deprecate_as(member):
117 extended_attributes = member.extended_attributes
118 if 'DeprecateAs' not in extended_attributes:
119 return None
120 # TODO(terry): Remove me?
121 # includes.add('core/frame/UseCounter.h')
122 return extended_attributes['DeprecateAs']
123
124
125 # [MeasureAs]
126 def _measure_as(definition_or_member):
127 extended_attributes = definition_or_member.extended_attributes
128 if 'MeasureAs' not in extended_attributes:
129 return None
130 # TODO(terry): Remove Me?
131 # includes.add('core/frame/UseCounter.h')
132 return extended_attributes['MeasureAs']
133
134
135 def _generate_native_entry(interface_name, name, kind, is_static, arity):
136
137 def mkPublic(s):
138 if s.startswith("_") or s.startswith("$"):
139 return "$" + s
140 return s
141
142 arity_str = ""
143 if kind == 'Getter':
144 suffix = "_Getter"
145 elif kind == 'Setter':
146 suffix = "_Setter"
147 elif kind == 'Constructor':
148 name = "constructor"
149 suffix = "Callback"
150 arity_str = "_" + str(arity)
151 elif kind == 'Method':
152 suffix = "_Callback"
153 arity_str = "_" + str(arity)
154
155 tag = "%s%s" % (name, suffix)
156 blink_entry = mkPublic(tag + arity_str)
157 native_entry = "_".join([interface_name, tag])
158
159 argument_names = ['__arg_%d' % i for i in range(0, arity)]
160 if not is_static and kind != 'Constructor':
161 argument_names.insert(0, "mthis")
162
163 return {'blink_entry': blink_entry,
164 'argument_names': argument_names,
165 'resolver_string': native_entry}
166
167 ################################################################################
168 # This is the monkey patched methods most delegate to v8_utilities but some are
169 # overridden in dart_utilities.
170 ################################################################################
171
172
173 class dart_utilities_monkey():
174 def __init__(self):
175 self.base_class_name = 'dart_utilities'
176
177 DartUtilities = dart_utilities_monkey()
178
179 DartUtilities.activity_logging_world_list = _activity_logging_world_list
180 DartUtilities.bool_to_cpp = _bool_to_cpp
181 DartUtilities.call_with_arguments = _call_with_arguments
182 DartUtilities.capitalize = v8_utilities.capitalize
183 DartUtilities.conditional_string = v8_utilities.conditional_string
184 DartUtilities.cpp_name = v8_utilities.cpp_name
185 DartUtilities.deprecate_as = _deprecate_as
186 DartUtilities.extended_attribute_value_contains = v8_utilities.extended_attribut e_value_contains
187 DartUtilities.gc_type = v8_utilities.gc_type
188 DartUtilities.generate_native_entry = _generate_native_entry
189 DartUtilities.has_extended_attribute = v8_utilities.has_extended_attribute
190 DartUtilities.has_extended_attribute_value = v8_utilities.has_extended_attribute _value
191 DartUtilities.measure_as = _measure_as
192 DartUtilities.per_context_enabled_function_name = v8_utilities.per_context_enabl ed_function_name
193 DartUtilities.runtime_enabled_function_name = v8_utilities.runtime_enabled_funct ion_name
194 DartUtilities.scoped_name = _scoped_name
195 DartUtilities.strip_suffix = v8_utilities.strip_suffix
196 DartUtilities.uncapitalize = v8_utilities.uncapitalize
197 DartUtilities.v8_class_name = v8_utilities.v8_class_name
OLDNEW
« no previous file with comments | « sky/engine/bindings-dart/dart/scripts/dart_types.py ('k') | sky/engine/bindings-dart/dart/scripts/idl_files.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698