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

Side by Side Diff: bindings/dart/scripts/dart_utilities.py

Issue 1660113002: Updated to Chrome 45 (2454) moved from SVN to git. Base URL: https://github.com/dart-lang/webcore.git@roll_45
Patch Set: Created 4 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
« no previous file with comments | « bindings/dart/scripts/dart_types.py ('k') | bindings/dart/scripts/idl_files.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 _enum_validation_expression(idl_type):
48 # FIXME: Add IdlEnumType, move property to derived type, and remove this che ck
49 if not idl_type.is_enum:
50 return None
51 return ' || '.join(['((String){param_name}) == "%s"' % enum_value
52 for enum_value in idl_type.enum_values])
53
54
55 def _scoped_name(interface, definition, base_name):
56 # partial interfaces are implemented as separate classes, with their members
57 # implemented as static member functions
58 partial_interface_implemented_as = definition.extended_attributes.get('Parti alInterfaceImplementedAs')
59 if partial_interface_implemented_as:
60 return '%s::%s' % (partial_interface_implemented_as, base_name)
61 if (definition.is_static or
62 definition.name in ('Constructor', 'NamedConstructor')):
63 return '%s::%s' % (v8_utilities.cpp_name(interface), base_name)
64 return 'receiver->%s' % base_name
65
66
67 def _bool_to_cpp(tf):
68 return "true" if tf else "false"
69
70
71 # [ActivityLogging]
72 def _activity_logging_world_list(member, access_type=None):
73 """Returns a set of world suffixes for which a definition member has activit y logging, for specified access type.
74
75 access_type can be 'Getter' or 'Setter' if only checking getting or setting.
76 """
77 if 'ActivityLogging' not in member.extended_attributes:
78 return set()
79 activity_logging = member.extended_attributes['ActivityLogging']
80 # [ActivityLogging=For*] (no prefix, starts with the worlds suffix) means
81 # "log for all use (method)/access (attribute)", otherwise check that value
82 # agrees with specified access_type (Getter/Setter).
83 has_logging = (activity_logging.startswith('For') or
84 (access_type and activity_logging.startswith(access_type)))
85 if not has_logging:
86 return set()
87 # TODO(terry): Remove Me?
88 # includes.add('bindings/core/v8/V8DOMActivityLogger.h')
89 if activity_logging.endswith('ForIsolatedWorlds'):
90 return set([''])
91 return set(['', 'ForMainWorld']) # endswith('ForAllWorlds')
92
93
94 # [CallWith]
95 _CALL_WITH_ARGUMENTS = {
96 'ScriptState': 'state',
97 'ExecutionContext': 'context',
98 'ScriptArguments': 'scriptArguments.release()',
99 'ActiveWindow': 'DartUtilities::callingDomWindowForCurrentIsolate()',
100 'FirstWindow': 'DartUtilities::enteredDomWindowForCurrentIsolate()',
101 'Document': 'document',
102 }
103
104 # List because key order matters, as we want arguments in deterministic order
105 _CALL_WITH_VALUES = [
106 'ScriptState',
107 'ExecutionContext',
108 'ScriptArguments',
109 'ActiveWindow',
110 'FirstWindow',
111 'Document',
112 ]
113
114
115 def _call_with_arguments(call_with_values):
116 if not call_with_values:
117 return []
118 return [_CALL_WITH_ARGUMENTS[value]
119 for value in _CALL_WITH_VALUES
120 if v8_utilities.extended_attribute_value_contains(call_with_values, value)]
121
122
123 # [DeprecateAs]
124 def _deprecate_as(member):
125 extended_attributes = member.extended_attributes
126 if 'DeprecateAs' not in extended_attributes:
127 return None
128 # TODO(terry): Remove me?
129 # includes.add('core/frame/UseCounter.h')
130 return extended_attributes['DeprecateAs']
131
132
133 # [MeasureAs]
134 def _measure_as(definition_or_member):
135 extended_attributes = definition_or_member.extended_attributes
136 if 'MeasureAs' not in extended_attributes:
137 return None
138 # TODO(terry): Remove Me?
139 # includes.add('core/frame/UseCounter.h')
140 return extended_attributes['MeasureAs']
141
142
143 def _generate_native_entry(interface_name, name, kind, is_static, arity):
144
145 def mkPublic(s):
146 if s.startswith("_") or s.startswith("$"):
147 return "$" + s
148 return s
149
150 arity_str = ""
151 if kind == 'Getter':
152 suffix = "_Getter"
153 elif kind == 'Setter':
154 suffix = "_Setter"
155 elif kind == 'Constructor':
156 name = "constructor"
157 suffix = "Callback"
158 arity_str = "_" + str(arity)
159 elif kind == 'Method':
160 suffix = "_Callback"
161 arity_str = "_" + str(arity)
162
163 tag = "%s%s" % (name, suffix)
164 blink_entry = mkPublic(tag + arity_str)
165 native_entry = "_".join([interface_name, tag])
166
167 argument_names = ['__arg_%d' % i for i in range(0, arity)]
168 if not is_static and kind != 'Constructor':
169 argument_names.insert(0, "mthis")
170
171 return {'blink_entry': blink_entry,
172 'argument_names': argument_names,
173 'resolver_string': native_entry}
174
175 ################################################################################
176 # This is the monkey patched methods most delegate to v8_utilities but some are
177 # overridden in dart_utilities.
178 ################################################################################
179
180
181 class dart_utilities_monkey():
182 def __init__(self):
183 self.base_class_name = 'dart_utilities'
184
185 DartUtilities = dart_utilities_monkey()
186
187 DartUtilities.activity_logging_world_list = _activity_logging_world_list
188 DartUtilities.bool_to_cpp = _bool_to_cpp
189 DartUtilities.call_with_arguments = _call_with_arguments
190 DartUtilities.capitalize = v8_utilities.capitalize
191 DartUtilities.conditional_string = v8_utilities.conditional_string
192 DartUtilities.cpp_name = v8_utilities.cpp_name
193 DartUtilities.deprecate_as = _deprecate_as
194 DartUtilities.extended_attribute_value_contains = v8_utilities.extended_attribut e_value_contains
195 DartUtilities.enum_validation_expression = _enum_validation_expression
196 DartUtilities.gc_type = v8_utilities.gc_type
197 DartUtilities.generate_native_entry = _generate_native_entry
198 DartUtilities.has_extended_attribute = v8_utilities.has_extended_attribute
199 DartUtilities.has_extended_attribute_value = v8_utilities.has_extended_attribute _value
200 DartUtilities.measure_as = _measure_as
201 DartUtilities.per_context_enabled_function_name = v8_utilities.per_context_enabl ed_function_name
202 DartUtilities.runtime_enabled_function_name = v8_utilities.runtime_enabled_funct ion_name
203 DartUtilities.scoped_name = _scoped_name
204 DartUtilities.strip_suffix = v8_utilities.strip_suffix
205 DartUtilities.uncapitalize = v8_utilities.uncapitalize
206 DartUtilities.v8_class_name = v8_utilities.v8_class_name
OLDNEW
« no previous file with comments | « bindings/dart/scripts/dart_types.py ('k') | bindings/dart/scripts/idl_files.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698