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

Side by Side Diff: Source/bindings/scripts/v8_utilities.py

Issue 17572008: WIP IDL compiler rewrite (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Branch: const + primitive type readonly attributes Created 7 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
« no previous file with comments | « Source/bindings/scripts/v8_types.py ('k') | Source/bindings/scripts/v8_values.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
30 import re
31
32 ACRONYMS = ['CSS', 'HTML', 'IME', 'JS', 'SVG', 'URL', 'XML', 'XSLT']
33
34
35 def generate_conditional_string(definition_or_member):
36 if 'Conditional' not in definition_or_member.extended_attributes:
37 return ''
38 conditional = definition_or_member.extended_attributes['Conditional']
39 for operator in ['&', '|']:
40 if operator in conditional:
41 conditions = sorted(conditional.split(operator))
42 operator_separator = ' {0}{0} '.format(operator)
43 return operator_separator.join(['ENABLE(%s)' % expression for expres sion in conditions])
44 return 'ENABLE(%s)' % conditional
45
46
47 def implemented_as_cpp_name(definition_or_member):
48 """Return ImplementedAs name, falling back on name attribute.
49
50 For interfaces (definitions), this is used as the class name.
51 For attributes and operations (members), this is used as the method name.
52 For attributes, this is also used in the getter and setter.
53 """
54 return definition_or_member.extended_attributes.get('ImplementedAs', definit ion_or_member.name)
55
56
57 def runtime_enable_function_name(definition_or_member):
58 """Return the name of the RuntimeEnabledFeatures function.
59
60 The returned function checks if a method/attribute is enabled.
61 If a parameter is given (e.g. 'EnabledAtRuntime=FeatureName'), return:
62 RuntimeEnabledFeatures::{featureName}Enabled
63 Otherwise return:
64 RuntimeEnabledFeatures::{methodName}Enabled
65 """
66 name = definition_or_member.extended_attributes.get('EnabledAtRuntime') or d efinition_or_member.name
67 return 'RuntimeEnabledFeatures::%sEnabled' % uncapitalize(name)
68
69
70 def uncapitalize(name):
71 """Uncapitalize first letter or initial acronym (* with some exceptions).
72
73 E.g., 'SetURL' becomes 'setURL', but 'URLFoo' becomes 'urlFoo'.
74 Used in method names; exceptions differ from capitalize().
75 """
76 for acronym in ACRONYMS:
77 if name.startswith(acronym):
78 name.replace(acronym, acronym.lower())
79 break
80 else:
81 name = name[0].lower() + name[1:]
82
83 # For HTML5 FileSystem API Flags attributes.
84 # (create is widely used to instantiate an object and must be avoided.)
85 if name == 'create':
86 return 'isCreate'
87 if name == 'exclusive':
88 return 'isExclusive'
89 return name
90
91
92 ################################################################################
93 # WIP
94 ################################################################################
95
96 ACTIVITY_LOGGING_INCLUDES = [
97 'bindings/v8/V8Binding.h',
98 'bindings/v8/V8DOMActivityLogger.h',
99 'wtf/Vector.h',
100 ]
101
102
103 def capitalize(name):
104 """Capitalize first letter or initial acronym (* with some exceptions).
105
106 Used in setter names.
107 """
108 name = name[0].upper() + name[1:]
109 # xmlEncoding becomes XMLEncoding, but xmlllang becomes Xmllang.
110 if name.startswith('CssText') or re.match('Xml[a-z]', name):
111 return name
112 for acronym in ACRONYMS:
113 if name.startswith(acronym.capitalize()):
114 name.replace(acronym.capitalize(), acronym)
115 break
116 return name
117
118
119 def strip_suffix(text, suffix):
120 if suffix and text.endswith(suffix):
121 return text[:-len(suffix)]
122 return text
123
124
125 def extended_attribute_contains(values_str, keyword):
126 return values_str and keyword in re.split('[|&]', values_str)
127
128
129 def get_raises_exception(function):
130 return 'RaisesException' in function.extended_attributes
131
132
133 def get_function_mandatory_parameters(function, count_variadic=False):
134 allow_non_optional = True
135 for parameter in function.arguments:
136 if parameter.is_optional or parameter.is_variadic:
137 allow_non_optional = False
138 else:
139 if not allow_non_optional:
140 raise Exception()
141 mandatory_parameters = 0
142 for parameter in function.arguments:
143 if parameter.is_optional:
144 break
145 if parameter.is_variadic and not count_variadic:
146 break
147 mandatory_parameters += 1
148 # print '[]', function.name, mandatory_parameters
149 return mandatory_parameters
150
151
152 def get_feature_observation_parameter(interface_or_attribute_or_function):
153 includes = []
154 measure_as = 'MeasureAs' in interface_or_attribute_or_function.extended_attr ibutes
155 if measure_as:
156 includes.append('core/page/UseCounter.h')
157 parameter = {
158 'measure_as': interface_or_attribute_or_function.extended_attributes.get ('MeasureAs'),
159 }
160 return parameter, includes
161
162
163 def get_deprecation_notification_parameter(interface_or_attribute_or_function):
164 includes = []
165 # print '[[]]', interface_or_attribute_or_function.extended_attributes
166 deprecate_as = 'DeprecateAs' in interface_or_attribute_or_function.extended_ attributes
167 if deprecate_as:
168 includes.append('core/page/PageConsole.h')
169 includes.append('core/page/UseCounter.h')
170 parameter = {
171 'deprecate_as': interface_or_attribute_or_function.extended_attributes.g et('DeprecateAs'),
172 }
173 return parameter, includes
174
175
176 def has_activity_logging(for_main_world_suffix, extended_attributes, access):
177 if access not in ['Method', 'Setter', 'Getter']:
178 raise Exception('Unrecognized activity logging access type')
179 if 'ActivityLog' not in extended_attributes:
180 return False
181 activity_log = extended_attributes['ActivityLog']
182 log_only_isolated_worlds = activity_log.endswith('ForIsolatedWorlds')
183 if log_only_isolated_worlds and for_main_world_suffix == 'ForMainWorld':
184 return False
185 return (
186 activity_log.startswith('Access') or
187 (access in ['Getter', 'Setter'] and activity_log.startswith(access)))
188
189
190 def get_custom_element_invocation_scope_parameter(interface_or_attribute_or_func tion):
191 # print '[[]]', interface_or_attribute_or_function.extended_attributes
192 includes = []
193 custom_element_invocation_scope = 'DeliverCustomElementCallbacks' in interfa ce_or_attribute_or_function.extended_attributes or 'Reflect' in interface_or_att ribute_or_function.extended_attributes
194 if custom_element_invocation_scope:
195 includes.append('core/dom/CustomElementCallbackDispatcher.h')
196 parameter = {
197 'custom_element_invocation_scope': custom_element_invocation_scope,
198 }
199 return parameter, includes
200
201
202 def get_call_with_parameter(call_with, return_void=False, function=None):
203 """
204 @return arguments, template_parameter, includes
205 """
206 if not call_with:
207 return [], {}, []
208
209 if return_void:
210 script_state_return_value = ''
211 else:
212 script_state_return_value = ' v8Undefined()'
213
214 script_state = extended_attribute_contains(call_with, 'ScriptState')
215 script_execution_context = extended_attribute_contains(call_with, 'ScriptExe cutionContext')
216 script_arguments = extended_attribute_contains(call_with, 'ScriptArguments')
217 active_window = extended_attribute_contains(call_with, 'ActiveWindow')
218 first_window = extended_attribute_contains(call_with, 'FirstWindow')
219
220 call_with_arguments = []
221 if script_state:
222 call_with_arguments.append('&state')
223 if script_execution_context:
224 call_with_arguments.append('scriptContext')
225 if function and script_arguments:
226 call_with_arguments.append('scriptArguments.release()')
227 includes = ['bindings/v8/ScriptCallStackFactory.h',
228 'core/inspector/ScriptArguments.h']
229 else:
230 includes = []
231 if active_window:
232 call_with_arguments.append('activeDOMWindow()')
233 if first_window:
234 call_with_arguments.append('firstDOMWindow()')
235
236 template_parameter = {
237 'script_state_return_value': script_state_return_value,
238 'script_state': script_state,
239 'script_execution_context': script_execution_context,
240 'function': function,
241 'number_of_function_parameters': len(function.arguments) if function els e 0,
242 }
243 return call_with_arguments, template_parameter, includes
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_types.py ('k') | Source/bindings/scripts/v8_values.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698