OLD | NEW |
(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/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 } |
| 94 |
| 95 # List because key order matters, as we want arguments in deterministic order |
| 96 _CALL_WITH_VALUES = [ |
| 97 'ScriptState', |
| 98 'ExecutionContext', |
| 99 'ScriptArguments', |
| 100 'ActiveWindow', |
| 101 'FirstWindow', |
| 102 ] |
| 103 |
| 104 |
| 105 def _call_with_arguments(member, call_with_values=None): |
| 106 # Optional parameter so setter can override with [SetterCallWith] |
| 107 call_with_values = call_with_values or member.extended_attributes.get('CallW
ith') |
| 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 ################################################################################ |
| 136 # This is the monkey patched methods most delegate to v8_utilities but some are |
| 137 # overridden in dart_utilities. |
| 138 ################################################################################ |
| 139 |
| 140 |
| 141 class dart_utilities_monkey(): |
| 142 def __init__(self): |
| 143 self.base_class_name = 'dart_utilities' |
| 144 |
| 145 DartUtilities = dart_utilities_monkey() |
| 146 |
| 147 DartUtilities.activity_logging_world_list = _activity_logging_world_list |
| 148 DartUtilities.bool_to_cpp = _bool_to_cpp |
| 149 DartUtilities.call_with_arguments = _call_with_arguments |
| 150 DartUtilities.capitalize = v8_utilities.capitalize |
| 151 DartUtilities.conditional_string = v8_utilities.conditional_string |
| 152 DartUtilities.cpp_name = v8_utilities.cpp_name |
| 153 DartUtilities.deprecate_as = _deprecate_as |
| 154 DartUtilities.extended_attribute_value_contains = v8_utilities.extended_attribut
e_value_contains |
| 155 DartUtilities.gc_type = v8_utilities.gc_type |
| 156 DartUtilities.has_extended_attribute = v8_utilities.has_extended_attribute |
| 157 DartUtilities.has_extended_attribute_value = v8_utilities.has_extended_attribute
_value |
| 158 DartUtilities.measure_as = _measure_as |
| 159 DartUtilities.per_context_enabled_function_name = v8_utilities.per_context_enabl
ed_function_name |
| 160 DartUtilities.runtime_enabled_function_name = v8_utilities.runtime_enabled_funct
ion_name |
| 161 DartUtilities.scoped_name = _scoped_name |
| 162 DartUtilities.strip_suffix = v8_utilities.strip_suffix |
| 163 DartUtilities.uncapitalize = v8_utilities.uncapitalize |
| 164 DartUtilities.v8_class_name = v8_utilities.v8_class_name |
OLD | NEW |