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

Unified Diff: third_party/WebKit/Source/bindings/scripts/idl_definitions.py

Issue 2446923002: bindings: Drop |idl_name| from IdlDefinitions (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/idl_reader.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/scripts/idl_definitions.py
diff --git a/third_party/WebKit/Source/bindings/scripts/idl_definitions.py b/third_party/WebKit/Source/bindings/scripts/idl_definitions.py
index 5ed496a16d5c2ebd1169af656f1f53012b01f211..7021fe1314ae8ae6a615915836ad5fd092389da3 100644
--- a/third_party/WebKit/Source/bindings/scripts/idl_definitions.py
+++ b/third_party/WebKit/Source/bindings/scripts/idl_definitions.py
@@ -88,14 +88,13 @@ class TypedObject(object):
################################################################################
class IdlDefinitions(object):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
"""Args: node: AST root node, class == 'File'"""
self.callback_functions = {}
self.dictionaries = {}
self.enumerations = {}
self.implements = []
self.interfaces = {}
- self.idl_name = idl_name
self.typedefs = {}
node_class = node.GetClass()
@@ -106,25 +105,25 @@ class IdlDefinitions(object):
for child in children:
child_class = child.GetClass()
if child_class == 'Interface':
- interface = IdlInterface(idl_name, child)
+ interface = IdlInterface(child)
self.interfaces[interface.name] = interface
elif child_class == 'Exception':
- exception = IdlException(idl_name, child)
+ exception = IdlException(child)
# For simplicity, treat exceptions as interfaces
self.interfaces[exception.name] = exception
elif child_class == 'Typedef':
typedef = IdlTypedef(child)
self.typedefs[typedef.name] = typedef
elif child_class == 'Enum':
- enumeration = IdlEnum(idl_name, child)
+ enumeration = IdlEnum(child)
self.enumerations[enumeration.name] = enumeration
elif child_class == 'Callback':
- callback_function = IdlCallbackFunction(idl_name, child)
+ callback_function = IdlCallbackFunction(child)
self.callback_functions[callback_function.name] = callback_function
elif child_class == 'Implements':
self.implements.append(IdlImplement(child))
elif child_class == 'Dictionary':
- dictionary = IdlDictionary(idl_name, child)
+ dictionary = IdlDictionary(child)
self.dictionaries[dictionary.name] = dictionary
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -170,7 +169,7 @@ class IdlDefinitions(object):
################################################################################
class IdlCallbackFunction(TypedObject):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
children = node.GetChildren()
num_children = len(children)
if num_children < 2 or num_children > 3:
@@ -180,17 +179,16 @@ class IdlCallbackFunction(TypedObject):
if num_children == 3:
ext_attributes_node = children[2]
self.extended_attributes = (
- ext_attributes_node_to_extended_attributes(idl_name, ext_attributes_node))
+ ext_attributes_node_to_extended_attributes(ext_attributes_node))
else:
self.extended_attributes = {}
arguments_node_class = arguments_node.GetClass()
if arguments_node_class != 'Arguments':
raise ValueError('Expected Arguments node, got %s' % arguments_node_class)
- self.idl_name = idl_name
self.name = node.GetName()
self.idl_type = type_node_to_type(type_node)
- self.arguments = arguments_node_to_arguments(idl_name, arguments_node)
+ self.arguments = arguments_node_to_arguments(arguments_node)
def accept(self, visitor):
visitor.visit_callback_function(self)
@@ -203,10 +201,9 @@ class IdlCallbackFunction(TypedObject):
################################################################################
class IdlDictionary(object):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
self.extended_attributes = {}
self.is_partial = bool(node.GetProperty('Partial'))
- self.idl_name = idl_name
self.name = node.GetName()
self.members = []
self.parent = None
@@ -215,10 +212,10 @@ class IdlDictionary(object):
if child_class == 'Inherit':
self.parent = child.GetName()
elif child_class == 'Key':
- self.members.append(IdlDictionaryMember(idl_name, child))
+ self.members.append(IdlDictionaryMember(child))
elif child_class == 'ExtAttributes':
self.extended_attributes = (
- ext_attributes_node_to_extended_attributes(idl_name, child))
+ ext_attributes_node_to_extended_attributes(child))
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -229,11 +226,10 @@ class IdlDictionary(object):
class IdlDictionaryMember(TypedObject):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
self.default_value = None
self.extended_attributes = {}
self.idl_type = None
- self.idl_name = idl_name
self.is_required = bool(node.GetProperty('REQUIRED'))
self.name = node.GetName()
for child in node.GetChildren():
@@ -244,7 +240,7 @@ class IdlDictionaryMember(TypedObject):
self.default_value = default_node_to_idl_literal(child)
elif child_class == 'ExtAttributes':
self.extended_attributes = (
- ext_attributes_node_to_extended_attributes(idl_name, child))
+ ext_attributes_node_to_extended_attributes(child))
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -257,9 +253,7 @@ class IdlDictionaryMember(TypedObject):
################################################################################
class IdlEnum(object):
- # FIXME: remove, just treat enums as a dictionary
bashi 2016/10/25 02:09:31 We do want to represent an enum as a class instanc
- def __init__(self, idl_name, node):
- self.idl_name = idl_name
+ def __init__(self, node):
self.name = node.GetName()
self.values = []
for child in node.GetChildren():
@@ -289,7 +283,7 @@ class IdlTypedef(object):
################################################################################
class IdlInterface(object):
- def __init__(self, idl_name, node=None):
+ def __init__(self, node=None):
self.attributes = []
self.constants = []
self.constructors = []
@@ -312,7 +306,6 @@ class IdlInterface(object):
self.is_exception = False
# FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser
self.is_partial = bool(node.GetProperty('Partial'))
- self.idl_name = idl_name
self.name = node.GetName()
self.idl_type = IdlType(self.name)
@@ -323,37 +316,37 @@ class IdlInterface(object):
for child in children:
child_class = child.GetClass()
if child_class == 'Attribute':
- attr = IdlAttribute(idl_name, child)
+ attr = IdlAttribute(child)
if attr.idl_type.is_integer_type and attr.name == 'length':
has_integer_typed_length = True
self.attributes.append(attr)
elif child_class == 'Const':
- self.constants.append(IdlConstant(idl_name, child))
+ self.constants.append(IdlConstant(child))
elif child_class == 'ExtAttributes':
- extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, child)
+ extended_attributes = ext_attributes_node_to_extended_attributes(child)
self.constructors, self.custom_constructors = (
- extended_attributes_to_constructors(idl_name, extended_attributes))
+ extended_attributes_to_constructors(extended_attributes))
clear_constructor_attributes(extended_attributes)
self.extended_attributes = extended_attributes
elif child_class == 'Operation':
- op = IdlOperation(idl_name, child)
+ op = IdlOperation(child)
if 'getter' in op.specials and str(op.arguments[0].idl_type) == 'unsigned long':
has_indexed_property_getter = True
self.operations.append(op)
elif child_class == 'Inherit':
self.parent = child.GetName()
elif child_class == 'Serializer':
- self.serializer = IdlSerializer(idl_name, child)
+ self.serializer = IdlSerializer(child)
self.process_serializer()
elif child_class == 'Stringifier':
- self.stringifier = IdlStringifier(idl_name, child)
+ self.stringifier = IdlStringifier(child)
self.process_stringifier()
elif child_class == 'Iterable':
- self.iterable = IdlIterable(idl_name, child)
+ self.iterable = IdlIterable(child)
elif child_class == 'Maplike':
- self.maplike = IdlMaplike(idl_name, child)
+ self.maplike = IdlMaplike(child)
elif child_class == 'Setlike':
- self.setlike = IdlSetlike(idl_name, child)
+ self.setlike = IdlSetlike(child)
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -414,13 +407,12 @@ class IdlException(IdlInterface):
# are not expected. Thus it is easier to implement exceptions as a
# restricted subclass of interfaces.
# http://www.w3.org/TR/WebIDL/#idl-exceptions
- def __init__(self, idl_name, node):
+ def __init__(self, node):
# Exceptions are similar to Interfaces, but simpler
- IdlInterface.__init__(self, idl_name)
+ IdlInterface.__init__(self)
self.is_callback = False
self.is_exception = True
self.is_partial = False
- self.idl_name = idl_name
self.name = node.GetName()
self.idl_type = IdlType(self.name)
@@ -428,18 +420,18 @@ class IdlException(IdlInterface):
for child in children:
child_class = child.GetClass()
if child_class == 'Attribute':
- attribute = IdlAttribute(idl_name, child)
+ attribute = IdlAttribute(child)
self.attributes.append(attribute)
elif child_class == 'Const':
- self.constants.append(IdlConstant(idl_name, child))
+ self.constants.append(IdlConstant(child))
elif child_class == 'ExtAttributes':
- extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, child)
+ extended_attributes = ext_attributes_node_to_extended_attributes(child)
self.constructors, self.custom_constructors = (
- extended_attributes_to_constructors(idl_name, extended_attributes))
+ extended_attributes_to_constructors(extended_attributes))
clear_constructor_attributes(extended_attributes)
self.extended_attributes = extended_attributes
elif child_class == 'ExceptionOperation':
- self.operations.append(IdlOperation.from_exception_operation_node(idl_name, child))
+ self.operations.append(IdlOperation.from_exception_operation_node(child))
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -449,10 +441,9 @@ class IdlException(IdlInterface):
################################################################################
class IdlAttribute(TypedObject):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
self.is_read_only = bool(node.GetProperty('READONLY'))
self.is_static = bool(node.GetProperty('STATIC'))
- self.idl_name = idl_name
self.name = node.GetName()
# Defaults, overridden below
self.idl_type = None
@@ -464,7 +455,7 @@ class IdlAttribute(TypedObject):
if child_class == 'Type':
self.idl_type = type_node_to_type(child)
elif child_class == 'ExtAttributes':
- self.extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, child)
+ self.extended_attributes = ext_attributes_node_to_extended_attributes(child)
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -477,7 +468,7 @@ class IdlAttribute(TypedObject):
################################################################################
class IdlConstant(TypedObject):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
children = node.GetChildren()
num_children = len(children)
if num_children < 2 or num_children > 3:
@@ -488,7 +479,6 @@ class IdlConstant(TypedObject):
if value_node_class != 'Value':
raise ValueError('Expected Value node, got %s' % value_node_class)
- self.idl_name = idl_name
self.name = node.GetName()
# ConstType is more limited than Type, so subtree is smaller and
# we don't use the full type_node_to_type function.
@@ -503,7 +493,7 @@ class IdlConstant(TypedObject):
if num_children == 3:
ext_attributes_node = children[2]
- self.extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, ext_attributes_node)
+ self.extended_attributes = ext_attributes_node_to_extended_attributes(ext_attributes_node)
else:
self.extended_attributes = {}
@@ -569,12 +559,11 @@ def default_node_to_idl_literal(node):
################################################################################
class IdlOperation(TypedObject):
- def __init__(self, idl_name, node=None):
+ def __init__(self, node=None):
self.arguments = []
self.extended_attributes = {}
self.specials = []
self.is_constructor = False
- self.idl_name = idl_name
self.idl_type = None
self.is_static = False
@@ -596,21 +585,21 @@ class IdlOperation(TypedObject):
for child in children:
child_class = child.GetClass()
if child_class == 'Arguments':
- self.arguments = arguments_node_to_arguments(idl_name, child)
+ self.arguments = arguments_node_to_arguments(child)
elif child_class == 'Type':
self.idl_type = type_node_to_type(child)
elif child_class == 'ExtAttributes':
- self.extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, child)
+ self.extended_attributes = ext_attributes_node_to_extended_attributes(child)
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@classmethod
- def from_exception_operation_node(cls, idl_name, node):
+ def from_exception_operation_node(cls, node):
# Needed to handle one case in DOMException.idl:
# // Override in a Mozilla compatible format
# [NotEnumerable] DOMString toString();
# FIXME: can we remove this? replace with a stringifier?
- operation = cls(idl_name)
+ operation = cls()
operation.name = node.GetName()
children = node.GetChildren()
if len(children) < 1 or len(children) > 2:
@@ -621,15 +610,15 @@ class IdlOperation(TypedObject):
if len(children) > 1:
ext_attributes_node = children[1]
- operation.extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, ext_attributes_node)
+ operation.extended_attributes = ext_attributes_node_to_extended_attributes(ext_attributes_node)
return operation
@classmethod
- def constructor_from_arguments_node(cls, name, idl_name, arguments_node):
- constructor = cls(idl_name)
+ def constructor_from_arguments_node(cls, name, arguments_node):
+ constructor = cls()
constructor.name = name
- constructor.arguments = arguments_node_to_arguments(idl_name, arguments_node)
+ constructor.arguments = arguments_node_to_arguments(arguments_node)
constructor.is_constructor = True
return constructor
@@ -644,12 +633,11 @@ class IdlOperation(TypedObject):
################################################################################
class IdlArgument(TypedObject):
- def __init__(self, idl_name, node=None):
+ def __init__(self, node=None):
self.extended_attributes = {}
self.idl_type = None
self.is_optional = False # syntax: (optional T)
self.is_variadic = False # syntax: (T...)
- self.idl_name = idl_name
self.default_value = None
if not node:
@@ -664,7 +652,7 @@ class IdlArgument(TypedObject):
if child_class == 'Type':
self.idl_type = type_node_to_type(child)
elif child_class == 'ExtAttributes':
- self.extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, child)
+ self.extended_attributes = ext_attributes_node_to_extended_attributes(child)
elif child_class == 'Argument':
child_name = child.GetName()
if child_name != '...':
@@ -679,15 +667,14 @@ class IdlArgument(TypedObject):
visitor.visit_argument(self)
-def arguments_node_to_arguments(idl_name, node):
+def arguments_node_to_arguments(node):
# [Constructor] and [CustomConstructor] without arguments (the bare form)
# have None instead of an arguments node, but have the same meaning as using
# an empty argument list, [Constructor()], so special-case this.
# http://www.w3.org/TR/WebIDL/#Constructor
if node is None:
return []
- return [IdlArgument(idl_name, argument_node)
- for argument_node in node.GetChildren()]
+ return [IdlArgument(argument_node) for argument_node in node.GetChildren()]
################################################################################
@@ -695,7 +682,7 @@ def arguments_node_to_arguments(idl_name, node):
################################################################################
class IdlSerializer(object):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
self.attribute_name = node.GetProperty('ATTRIBUTE')
self.attribute_names = None
self.operation = None
@@ -705,12 +692,11 @@ class IdlSerializer(object):
self.is_inherit = False
self.is_list = False
self.is_map = False
- self.idl_name = idl_name
for child in node.GetChildren():
child_class = child.GetClass()
if child_class == 'Operation':
- self.operation = IdlOperation(idl_name, child)
+ self.operation = IdlOperation(child)
elif child_class == 'List':
self.is_list = True
self.is_getter = bool(child.GetProperty('GETTER'))
@@ -722,7 +708,7 @@ class IdlSerializer(object):
self.is_inherit = bool(child.GetProperty('INHERIT'))
self.attributes = child.GetProperty('ATTRIBUTES')
elif child_class == 'ExtAttributes':
- self.extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, child)
+ self.extended_attributes = ext_attributes_node_to_extended_attributes(child)
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -732,22 +718,21 @@ class IdlSerializer(object):
################################################################################
class IdlStringifier(object):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
self.attribute = None
self.operation = None
self.extended_attributes = {}
- self.idl_name = idl_name
for child in node.GetChildren():
child_class = child.GetClass()
if child_class == 'Attribute':
- self.attribute = IdlAttribute(idl_name, child)
+ self.attribute = IdlAttribute(child)
elif child_class == 'Operation':
- operation = IdlOperation(idl_name, child)
+ operation = IdlOperation(child)
if operation.name:
self.operation = operation
elif child_class == 'ExtAttributes':
- self.extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, child)
+ self.extended_attributes = ext_attributes_node_to_extended_attributes(child)
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -763,14 +748,14 @@ class IdlStringifier(object):
################################################################################
class IdlIterableOrMaplikeOrSetlike(TypedObject):
- def __init__(self, idl_name, node):
+ def __init__(self, node):
self.extended_attributes = {}
self.type_children = []
for child in node.GetChildren():
child_class = child.GetClass()
if child_class == 'ExtAttributes':
- self.extended_attributes = ext_attributes_node_to_extended_attributes(idl_name, child)
+ self.extended_attributes = ext_attributes_node_to_extended_attributes(child)
elif child_class == 'Type':
self.type_children.append(child)
else:
@@ -780,8 +765,8 @@ class IdlIterableOrMaplikeOrSetlike(TypedObject):
class IdlIterable(IdlIterableOrMaplikeOrSetlike):
idl_type_attributes = ('key_type', 'value_type')
- def __init__(self, idl_name, node):
- super(IdlIterable, self).__init__(idl_name, node)
+ def __init__(self, node):
+ super(IdlIterable, self).__init__(node)
if len(self.type_children) == 1:
self.key_type = None
@@ -800,8 +785,8 @@ class IdlIterable(IdlIterableOrMaplikeOrSetlike):
class IdlMaplike(IdlIterableOrMaplikeOrSetlike):
idl_type_attributes = ('key_type', 'value_type')
- def __init__(self, idl_name, node):
- super(IdlMaplike, self).__init__(idl_name, node)
+ def __init__(self, node):
+ super(IdlMaplike, self).__init__(node)
self.is_read_only = bool(node.GetProperty('READONLY'))
@@ -819,8 +804,8 @@ class IdlMaplike(IdlIterableOrMaplikeOrSetlike):
class IdlSetlike(IdlIterableOrMaplikeOrSetlike):
idl_type_attributes = ('value_type',)
- def __init__(self, idl_name, node):
- super(IdlSetlike, self).__init__(idl_name, node)
+ def __init__(self, node):
+ super(IdlSetlike, self).__init__(node)
self.is_read_only = bool(node.GetProperty('READONLY'))
@@ -862,7 +847,7 @@ class Exposure:
self.runtime_enabled = runtime_enabled
-def ext_attributes_node_to_extended_attributes(idl_name, node):
+def ext_attributes_node_to_extended_attributes(node):
"""
Returns:
Dictionary of {ExtAttributeName: ExtAttributeValue}.
@@ -920,7 +905,7 @@ def ext_attributes_node_to_extended_attributes(idl_name, node):
raise ValueError('[SetWrapperReferenceTo] supports only one child.')
if child_class != 'Arguments':
raise ValueError('[SetWrapperReferenceTo] only supports Arguments as child, but has child of class: %s' % child_class)
- extended_attributes[name] = IdlArgument(idl_name, children[0])
+ extended_attributes[name] = IdlArgument(children[0])
elif name == 'Exposed':
if child_class and child_class != 'Arguments':
raise ValueError('[Exposed] only supports Arguments as child, but has child of class: %s' % child_class)
@@ -928,7 +913,7 @@ def ext_attributes_node_to_extended_attributes(idl_name, node):
if child_class == 'Arguments':
exposures = [Exposure(exposed=str(arg.idl_type),
runtime_enabled=arg.name)
- for arg in arguments_node_to_arguments('*', child)]
+ for arg in arguments_node_to_arguments(child)]
else:
value = extended_attribute_node.GetProperty('VALUE')
if type(value) is str:
@@ -952,7 +937,7 @@ def ext_attributes_node_to_extended_attributes(idl_name, node):
return extended_attributes
-def extended_attributes_to_constructors(idl_name, extended_attributes):
+def extended_attributes_to_constructors(extended_attributes):
"""Returns constructors and custom_constructors (lists of IdlOperations).
Auxiliary function for IdlInterface.__init__.
@@ -960,12 +945,12 @@ def extended_attributes_to_constructors(idl_name, extended_attributes):
constructor_list = extended_attributes.get('Constructors', [])
constructors = [
- IdlOperation.constructor_from_arguments_node('Constructor', idl_name, arguments_node)
+ IdlOperation.constructor_from_arguments_node('Constructor', arguments_node)
for arguments_node in constructor_list]
custom_constructor_list = extended_attributes.get('CustomConstructors', [])
custom_constructors = [
- IdlOperation.constructor_from_arguments_node('CustomConstructor', idl_name, arguments_node)
+ IdlOperation.constructor_from_arguments_node('CustomConstructor', arguments_node)
for arguments_node in custom_constructor_list]
if 'NamedConstructor' in extended_attributes:
@@ -977,7 +962,7 @@ def extended_attributes_to_constructors(idl_name, extended_attributes):
if len(children) != 1:
raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children))
arguments_node = children[0]
- named_constructor = IdlOperation.constructor_from_arguments_node('NamedConstructor', idl_name, arguments_node)
+ named_constructor = IdlOperation.constructor_from_arguments_node('NamedConstructor', arguments_node)
# FIXME: should return named_constructor separately; appended for Perl
constructors.append(named_constructor)
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/idl_reader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698