Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dart_utilities.py
Go to the documentation of this file.
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"""Functions shared by various parts of the code generator.
29
30Extends IdlType and IdlUnion type with |enum_validation_expression| property.
31
32Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
33"""
34
35################################################################################
36# Utility function exposed for Dart CodeGenerator. Only 6 methods are special
37# to Dart the rest delegate to the v8_utilities functions.
38################################################################################
39
40import v8_types # Required
41import v8_utilities
42
43
44def _scoped_name(interface, definition, base_name):
45 # partial interfaces are implemented as separate classes, with their members
46 # implemented as static member functions
47 partial_interface_implemented_as = definition.extended_attributes.get(
48 'PartialInterfaceImplementedAs')
49 if partial_interface_implemented_as:
50 return '%s::%s' % (partial_interface_implemented_as, base_name)
51 if (definition.is_static or
52 definition.name in ('Constructor', 'NamedConstructor')):
53 return '%s::%s' % (v8_utilities.cpp_name(interface), base_name)
54 return 'receiver->%s' % base_name
55
56
58 return "true" if tf else "false"
59
60
61# [ActivityLogging]
62def _activity_logging_world_list(member, access_type=None):
63 """Returns a set of world suffixes for which a definition member has activity logging, for specified access type.
64
65 access_type can be 'Getter' or 'Setter' if only checking getting or setting.
66 """
67 if 'ActivityLogging' not in member.extended_attributes:
68 return set()
69 activity_logging = member.extended_attributes['ActivityLogging']
70 # [ActivityLogging=For*] (no prefix, starts with the worlds suffix) means
71 # "log for all use (method)/access (attribute)", otherwise check that value
72 # agrees with specified access_type (Getter/Setter).
73 has_logging = (activity_logging.startswith('For') or
74 (access_type and activity_logging.startswith(access_type)))
75 if not has_logging:
76 return set()
77# TODO(terry): Remove Me?
78# includes.add('bindings/v8/V8DOMActivityLogger.h')
79 if activity_logging.endswith('ForIsolatedWorlds'):
80 return set([''])
81 return set(['', 'ForMainWorld']) # endswith('ForAllWorlds')
82
83
84# [CallWith]
85_CALL_WITH_ARGUMENTS = {
86 'ScriptState': '&state',
87 'ExecutionContext': 'context',
88 'ScriptArguments': 'scriptArguments.release()',
89 'ActiveWindow': 'DartUtilities::callingDomWindowForCurrentIsolate()',
90 'FirstWindow': 'DartUtilities::enteredDomWindowForCurrentIsolate()',
91}
92
93# List because key order matters, as we want arguments in deterministic order
94_CALL_WITH_VALUES = [
95 'ScriptState',
96 'ExecutionContext',
97 'ScriptArguments',
98 'ActiveWindow',
99 'FirstWindow',
100]
101
102
103def _call_with_arguments(member, call_with_values=None):
104 # Optional parameter so setter can override with [SetterCallWith]
105 call_with_values = call_with_values or member.extended_attributes.get(
106 'CallWith')
107 if not call_with_values:
108 return []
109 return [
110 _CALL_WITH_ARGUMENTS[value]
111 for value in _CALL_WITH_VALUES
112 if v8_utilities.extended_attribute_value_contains(
113 call_with_values, value)
114 ]
115
116
117# [DeprecateAs]
118def _deprecate_as(member):
119 extended_attributes = member.extended_attributes
120 if 'DeprecateAs' not in extended_attributes:
121 return None
122# TODO(terry): Remove me?
123# includes.add('core/frame/UseCounter.h')
124 return extended_attributes['DeprecateAs']
125
126
127# [MeasureAs]
128def _measure_as(definition_or_member):
129 extended_attributes = definition_or_member.extended_attributes
130 if 'MeasureAs' not in extended_attributes:
131 return None
132# TODO(terry): Remove Me?
133# includes.add('core/frame/UseCounter.h')
134 return extended_attributes['MeasureAs']
135
136
137################################################################################
138# This is the monkey patched methods most delegate to v8_utilities but some are
139# overridden in dart_utilities.
140################################################################################
141
142
144
145 def __init__(self):
146 self.base_class_name = 'dart_utilities'
147
148
149DartUtilities = dart_utilities_monkey()
150
151DartUtilities.activity_logging_world_list = _activity_logging_world_list
152DartUtilities.bool_to_cpp = _bool_to_cpp
153DartUtilities.call_with_arguments = _call_with_arguments
154DartUtilities.capitalize = v8_utilities.capitalize
155DartUtilities.cpp_name = v8_utilities.cpp_name
156DartUtilities.deprecate_as = _deprecate_as
157DartUtilities.extended_attribute_value_contains = v8_utilities.extended_attribute_value_contains
158DartUtilities.has_extended_attribute = v8_utilities.has_extended_attribute
159DartUtilities.has_extended_attribute_value = v8_utilities.has_extended_attribute_value
160DartUtilities.measure_as = _measure_as
161DartUtilities.scoped_name = _scoped_name
162DartUtilities.strip_suffix = v8_utilities.strip_suffix
163DartUtilities.uncapitalize = v8_utilities.uncapitalize
164DartUtilities.v8_class_name = v8_utilities.v8_class_name
This is the monkey patched methods most delegate to v8_utilities but some are overridden in dart_util...
_call_with_arguments(member, call_with_values=None)
_scoped_name(interface, definition, base_name)
_measure_as(definition_or_member)
_activity_logging_world_list(member, access_type=None)