| 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 # [CallWith] |
| 64 _CALL_WITH_ARGUMENTS = { |
| 65 'ScriptState': 'state', |
| 66 'ExecutionContext': 'context', |
| 67 'ScriptArguments': 'scriptArguments.release()', |
| 68 'ActiveWindow': 'DOMDartState::CurrentWindow()', |
| 69 'FirstWindow': 'DOMDartState::CurrentWindow()', |
| 70 'Document': 'document', |
| 71 } |
| 72 |
| 73 # List because key order matters, as we want arguments in deterministic order |
| 74 _CALL_WITH_VALUES = [ |
| 75 'ScriptState', |
| 76 'ExecutionContext', |
| 77 'ScriptArguments', |
| 78 'ActiveWindow', |
| 79 'FirstWindow', |
| 80 'Document', |
| 81 ] |
| 82 |
| 83 |
| 84 def _call_with_arguments(call_with_values): |
| 85 if not call_with_values: |
| 86 return [] |
| 87 return [_CALL_WITH_ARGUMENTS[value] |
| 88 for value in _CALL_WITH_VALUES |
| 89 if v8_utilities.extended_attribute_value_contains(call_with_values,
value)] |
| 90 |
| 91 |
| 92 def _generate_native_entry(interface_name, name, kind, is_static, arity): |
| 93 |
| 94 if kind == 'Getter': |
| 95 suffix = "_Getter" |
| 96 elif kind == 'Setter': |
| 97 suffix = "_Setter" |
| 98 elif kind == 'Constructor': |
| 99 name = "constructor" |
| 100 suffix = "Callback" |
| 101 elif kind == 'Method': |
| 102 suffix = "_Callback" |
| 103 |
| 104 tag = "%s%s" % (name, suffix) |
| 105 native_entry = "_".join([interface_name, tag]) |
| 106 |
| 107 argument_names = ['__arg_%d' % i for i in range(0, arity)] |
| 108 |
| 109 return {'blink_entry': name, |
| 110 'argument_names': argument_names, |
| 111 'resolver_string': native_entry} |
| 112 |
| 113 ################################################################################ |
| 114 # This is the monkey patched methods most delegate to v8_utilities but some are |
| 115 # overridden in dart_utilities. |
| 116 ################################################################################ |
| 117 |
| 118 |
| 119 class dart_utilities_monkey(): |
| 120 def __init__(self): |
| 121 self.base_class_name = 'dart_utilities' |
| 122 |
| 123 DartUtilities = dart_utilities_monkey() |
| 124 |
| 125 DartUtilities.bool_to_cpp = _bool_to_cpp |
| 126 DartUtilities.call_with_arguments = _call_with_arguments |
| 127 DartUtilities.capitalize = v8_utilities.capitalize |
| 128 DartUtilities.cpp_name = v8_utilities.cpp_name |
| 129 DartUtilities.extended_attribute_value_contains = v8_utilities.extended_attribut
e_value_contains |
| 130 DartUtilities.generate_native_entry = _generate_native_entry |
| 131 DartUtilities.has_extended_attribute = v8_utilities.has_extended_attribute |
| 132 DartUtilities.has_extended_attribute_value = v8_utilities.has_extended_attribute
_value |
| 133 DartUtilities.scoped_name = _scoped_name |
| 134 DartUtilities.strip_suffix = v8_utilities.strip_suffix |
| 135 DartUtilities.uncapitalize = v8_utilities.uncapitalize |
| OLD | NEW |