OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 10 matching lines...) Expand all Loading... |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 """Functions shared by various parts of the code generator. | 29 """Functions shared by various parts of the code generator. |
30 | 30 |
31 Extends IdlType and IdlUnion type with |enum_validation_expression| property. | 31 Extends IdlTypeBase type with |enum_validation_expression| property. |
32 | 32 |
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
34 """ | 34 """ |
35 | 35 |
36 import re | 36 import re |
37 | 37 |
38 from idl_types import IdlType, IdlUnionType | 38 from idl_types import IdlTypeBase |
39 import idl_types | 39 import idl_types |
40 from v8_globals import includes | 40 from v8_globals import includes |
41 import v8_types | 41 import v8_types |
42 | 42 |
43 ACRONYMS = [ | 43 ACRONYMS = [ |
44 'CSSOM', # must come *before* CSS to match full acronym | 44 'CSSOM', # must come *before* CSS to match full acronym |
45 'CSS', | 45 'CSS', |
46 'HTML', | 46 'HTML', |
47 'IME', | 47 'IME', |
48 'JS', | 48 'JS', |
49 'SVG', | 49 'SVG', |
50 'URL', | 50 'URL', |
51 'WOFF', | 51 'WOFF', |
52 'XML', | 52 'XML', |
53 'XSLT', | 53 'XSLT', |
54 ] | 54 ] |
55 | 55 |
56 | 56 |
57 ################################################################################ | 57 ################################################################################ |
58 # Extended attribute parsing | 58 # Extended attribute parsing |
59 ################################################################################ | 59 ################################################################################ |
60 | 60 |
61 def extended_attribute_value_contains(extended_attribute_value, value): | 61 def extended_attribute_value_contains(extended_attribute_value, value): |
62 return (extended_attribute_value and | 62 return (extended_attribute_value and |
63 value in re.split('[|&]', extended_attribute_value)) | 63 value in re.split('[|,]', extended_attribute_value)) |
64 | 64 |
65 | 65 |
66 def has_extended_attribute(definition_or_member, extended_attribute_list): | 66 def has_extended_attribute(definition_or_member, extended_attribute_list): |
67 return any(extended_attribute in definition_or_member.extended_attributes | 67 return any(extended_attribute in definition_or_member.extended_attributes |
68 for extended_attribute in extended_attribute_list) | 68 for extended_attribute in extended_attribute_list) |
69 | 69 |
70 | 70 |
71 def has_extended_attribute_value(definition_or_member, name, value): | 71 def has_extended_attribute_value(definition_or_member, name, value): |
72 extended_attributes = definition_or_member.extended_attributes | 72 extended_attributes = definition_or_member.extended_attributes |
73 return (name in extended_attributes and | 73 return (name in extended_attributes and |
74 extended_attribute_value_contains(extended_attributes[name], value)) | 74 extended_attribute_value_contains(extended_attributes[name], value)) |
75 | 75 |
76 | 76 |
| 77 def sorted_extended_attribute_set(definition_or_member, name): |
| 78 extended_attributes = definition_or_member.extended_attributes |
| 79 if name not in extended_attributes: |
| 80 return [] |
| 81 |
| 82 attribute_values = re.split('[|,]', extended_attributes[name]) |
| 83 return sorted(attribute_values) |
| 84 |
| 85 |
77 ################################################################################ | 86 ################################################################################ |
78 # String handling | 87 # String handling |
79 ################################################################################ | 88 ################################################################################ |
80 | 89 |
81 def capitalize(name): | 90 def capitalize(name): |
82 """Capitalize first letter or initial acronym (used in setter names).""" | 91 """Capitalize first letter or initial acronym (used in setter names).""" |
83 for acronym in ACRONYMS: | 92 for acronym in ACRONYMS: |
84 if name.startswith(acronym.lower()): | 93 if name.startswith(acronym.lower()): |
85 return name.replace(acronym.lower(), acronym) | 94 return name.replace(acronym.lower(), acronym) |
86 return name[0].upper() + name[1:] | 95 return name[0].upper() + name[1:] |
(...skipping 19 matching lines...) Expand all Loading... |
106 ################################################################################ | 115 ################################################################################ |
107 # C++ | 116 # C++ |
108 ################################################################################ | 117 ################################################################################ |
109 | 118 |
110 def enum_validation_expression(idl_type): | 119 def enum_validation_expression(idl_type): |
111 # FIXME: Add IdlEnumType, move property to derived type, and remove this che
ck | 120 # FIXME: Add IdlEnumType, move property to derived type, and remove this che
ck |
112 if not idl_type.is_enum: | 121 if not idl_type.is_enum: |
113 return None | 122 return None |
114 return ' || '.join(['string == "%s"' % enum_value | 123 return ' || '.join(['string == "%s"' % enum_value |
115 for enum_value in idl_type.enum_values]) | 124 for enum_value in idl_type.enum_values]) |
116 IdlType.enum_validation_expression = property(enum_validation_expression) | 125 IdlTypeBase.enum_validation_expression = property(enum_validation_expression) |
117 | 126 |
118 | 127 |
119 def scoped_name(interface, definition, base_name): | 128 def scoped_name(interface, definition, base_name): |
| 129 if 'ImplementedInPrivateScript' in definition.extended_attributes: |
| 130 return '%s::PrivateScript::%s' % (v8_class_name(interface), base_name) |
120 # partial interfaces are implemented as separate classes, with their members | 131 # partial interfaces are implemented as separate classes, with their members |
121 # implemented as static member functions | 132 # implemented as static member functions |
122 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') | 133 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') |
123 if partial_interface_implemented_as: | 134 if partial_interface_implemented_as: |
124 return '%s::%s' % (partial_interface_implemented_as, base_name) | 135 return '%s::%s' % (partial_interface_implemented_as, base_name) |
125 if (definition.is_static or | 136 if (definition.is_static or |
126 definition.name in ('Constructor', 'NamedConstructor')): | 137 definition.name in ('Constructor', 'NamedConstructor')): |
127 return '%s::%s' % (cpp_name(interface), base_name) | 138 return '%s::%s' % (cpp_name(interface), base_name) |
128 return 'impl->%s' % base_name | 139 return 'impl->%s' % base_name |
129 | 140 |
(...skipping 12 matching lines...) Expand all Loading... |
142 | 153 |
143 access_type can be 'Getter' or 'Setter' if only checking getting or setting. | 154 access_type can be 'Getter' or 'Setter' if only checking getting or setting. |
144 """ | 155 """ |
145 extended_attributes = member.extended_attributes | 156 extended_attributes = member.extended_attributes |
146 if 'LogActivity' not in extended_attributes: | 157 if 'LogActivity' not in extended_attributes: |
147 return set() | 158 return set() |
148 log_activity = extended_attributes['LogActivity'] | 159 log_activity = extended_attributes['LogActivity'] |
149 if log_activity and not log_activity.startswith(access_type): | 160 if log_activity and not log_activity.startswith(access_type): |
150 return set() | 161 return set() |
151 | 162 |
152 includes.add('bindings/v8/V8DOMActivityLogger.h') | 163 includes.add('bindings/core/v8/V8DOMActivityLogger.h') |
153 if 'LogAllWorlds' in extended_attributes: | 164 if 'LogAllWorlds' in extended_attributes: |
154 return set(['', 'ForMainWorld']) | 165 return set(['', 'ForMainWorld']) |
155 return set(['']) # At minimum, include isolated worlds. | 166 return set(['']) # At minimum, include isolated worlds. |
156 | 167 |
157 | 168 |
158 # [ActivityLogging] | 169 # [ActivityLogging] |
159 def activity_logging_world_check(member): | 170 def activity_logging_world_check(member): |
160 """Returns if an isolated world check is required when generating activity | 171 """Returns if an isolated world check is required when generating activity |
161 logging code. | 172 logging code. |
162 | 173 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 205 |
195 def call_with_arguments(call_with_values): | 206 def call_with_arguments(call_with_values): |
196 if not call_with_values: | 207 if not call_with_values: |
197 return [] | 208 return [] |
198 return [CALL_WITH_ARGUMENTS[value] | 209 return [CALL_WITH_ARGUMENTS[value] |
199 for value in CALL_WITH_VALUES | 210 for value in CALL_WITH_VALUES |
200 if extended_attribute_value_contains(call_with_values, value)] | 211 if extended_attribute_value_contains(call_with_values, value)] |
201 | 212 |
202 | 213 |
203 # [Conditional] | 214 # [Conditional] |
| 215 DELIMITER_TO_OPERATOR = { |
| 216 '|': '||', |
| 217 ',': '&&', |
| 218 } |
| 219 |
| 220 |
204 def conditional_string(definition_or_member): | 221 def conditional_string(definition_or_member): |
205 extended_attributes = definition_or_member.extended_attributes | 222 extended_attributes = definition_or_member.extended_attributes |
206 if 'Conditional' not in extended_attributes: | 223 if 'Conditional' not in extended_attributes: |
207 return None | 224 return None |
208 conditional = extended_attributes['Conditional'] | 225 conditional = extended_attributes['Conditional'] |
209 for operator in '&|': | 226 for delimiter in ',|': |
210 if operator in conditional: | 227 if delimiter in conditional: |
211 conditions = conditional.split(operator) | 228 conditions = conditional.split(delimiter) |
212 operator_separator = ' %s%s ' % (operator, operator) | 229 operator_separator = ' %s ' % DELIMITER_TO_OPERATOR[delimiter] |
213 return operator_separator.join('ENABLE(%s)' % expression for express
ion in sorted(conditions)) | 230 return operator_separator.join('ENABLE(%s)' % expression for express
ion in sorted(conditions)) |
214 return 'ENABLE(%s)' % conditional | 231 return 'ENABLE(%s)' % conditional |
215 | 232 |
216 | 233 |
217 # [DeprecateAs] | 234 # [DeprecateAs] |
218 def deprecate_as(member): | 235 def deprecate_as(member): |
219 extended_attributes = member.extended_attributes | 236 extended_attributes = member.extended_attributes |
220 if 'DeprecateAs' not in extended_attributes: | 237 if 'DeprecateAs' not in extended_attributes: |
221 return None | 238 return None |
222 includes.add('core/frame/UseCounter.h') | 239 includes.add('core/frame/UseCounter.h') |
223 return extended_attributes['DeprecateAs'] | 240 return extended_attributes['DeprecateAs'] |
224 | 241 |
225 | 242 |
| 243 # [Exposed] |
| 244 EXPOSED_EXECUTION_CONTEXT_METHOD = { |
| 245 'DedicatedWorker': 'isDedicatedWorkerGlobalScope', |
| 246 'ServiceWorker': 'isServiceWorkerGlobalScope', |
| 247 'SharedWorker': 'isSharedWorkerGlobalScope', |
| 248 'Window': 'isDocument', |
| 249 'Worker': 'isWorkerGlobalScope', |
| 250 } |
| 251 |
| 252 |
| 253 def exposed(definition_or_member, interface): |
| 254 exposure_set = sorted_extended_attribute_set(definition_or_member, 'Exposed'
) |
| 255 if not exposure_set: |
| 256 return None |
| 257 |
| 258 interface_exposure_set = expanded_exposure_set_for_interface(interface) |
| 259 |
| 260 # Methods must not be exposed to a broader scope than their interface. |
| 261 if not set(exposure_set).issubset(interface_exposure_set): |
| 262 raise ValueError('Interface members\' exposure sets must be a subset of
the interface\'s.') |
| 263 |
| 264 exposure_checks = [] |
| 265 for environment in exposure_set: |
| 266 # Methods must be exposed on one of the scopes known to Blink. |
| 267 if environment not in EXPOSED_EXECUTION_CONTEXT_METHOD: |
| 268 raise ValueError('Values for the [Exposed] annotation must reflect t
o a valid exposure scope.') |
| 269 |
| 270 exposure_checks.append('context->%s()' % EXPOSED_EXECUTION_CONTEXT_METHO
D[environment]) |
| 271 |
| 272 return ' || '.join(exposure_checks) |
| 273 |
| 274 |
| 275 def expanded_exposure_set_for_interface(interface): |
| 276 exposure_set = sorted_extended_attribute_set(interface, 'Exposed') |
| 277 |
| 278 # "Worker" is an aggregation for the different kinds of workers. |
| 279 if 'Worker' in exposure_set: |
| 280 exposure_set.extend(('DedicatedWorker', 'SharedWorker', 'ServiceWorker')
) |
| 281 |
| 282 return sorted(set(exposure_set)) |
| 283 |
| 284 |
226 # [GarbageCollected], [WillBeGarbageCollected] | 285 # [GarbageCollected], [WillBeGarbageCollected] |
227 def gc_type(definition): | 286 def gc_type(definition): |
228 extended_attributes = definition.extended_attributes | 287 extended_attributes = definition.extended_attributes |
229 if 'GarbageCollected' in extended_attributes: | 288 if 'GarbageCollected' in extended_attributes: |
230 return 'GarbageCollectedObject' | 289 return 'GarbageCollectedObject' |
231 elif 'WillBeGarbageCollected' in extended_attributes: | 290 elif 'WillBeGarbageCollected' in extended_attributes: |
232 return 'WillBeGarbageCollectedObject' | 291 return 'WillBeGarbageCollectedObject' |
233 return 'RefCountedObject' | 292 return 'RefCountedObject' |
234 | 293 |
235 | 294 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 feature_name = extended_attributes['RuntimeEnabled'] | 332 feature_name = extended_attributes['RuntimeEnabled'] |
274 return 'RuntimeEnabledFeatures::%sEnabled' % uncapitalize(feature_name) | 333 return 'RuntimeEnabledFeatures::%sEnabled' % uncapitalize(feature_name) |
275 | 334 |
276 | 335 |
277 ################################################################################ | 336 ################################################################################ |
278 # Dart Specific extended attributes | 337 # Dart Specific extended attributes |
279 ################################################################################ | 338 ################################################################################ |
280 def dart_custom_method(extended_attributes): | 339 def dart_custom_method(extended_attributes): |
281 return ('DartCustom' in extended_attributes and | 340 return ('DartCustom' in extended_attributes and |
282 extended_attribute_value_contains(extended_attributes['DartCustom'],
'New')) | 341 extended_attribute_value_contains(extended_attributes['DartCustom'],
'New')) |
OLD | NEW |