aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/Configuration.py
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-07-09 07:55:27 -0600
committerbors-servo <metajack+bors@gmail.com>2015-07-09 07:55:27 -0600
commit2d2a340633dcc73e458a8454b78e26ba93511d37 (patch)
tree8a24a61ae92605810bdd7163aad10204833e9a99 /components/script/dom/bindings/codegen/Configuration.py
parentfe17067d6a30b85a0346fd1ccb2b95e2081e6962 (diff)
parent0ec2375cabb69abbfd1014bfb68136fdea6edadb (diff)
downloadservo-2d2a340633dcc73e458a8454b78e26ba93511d37.tar.gz
servo-2d2a340633dcc73e458a8454b78e26ba93511d37.zip
Auto merge of #6580 - frewsxcv:lint-codegen, r=Ms2ger
Remove tidy blacklist for 'script/dom/bindings/*' Recently, I found myself reading through the Python codegen scripts that live in 'components/script/dom/bindings/*' and noticed that there were many tidy violations: unnecessary semicolons, weird spacing, unused variables, lack of license headers, etc. Considering these files are now living in our tree and mostly maintained directly by contributors of Servo (as opposed to being from upstream), I feel these files should not be excluded from our normal tidy process. This commit removes the blacklist on these files and fixes all tidy violations. I added these subdirectories to the blacklist because they appear to be maintained upstream somewhere else: * "components/script/dom/bindings/codegen/parser/*", * "components/script/dom/bindings/codegen/ply/*", Also, I added a few '# noqa' comments which tells us to ignore the flake8 errors for that line; they are mostly for unused/undefined variables. I chose to ignore these (instead of fixing them) to make the work for this commit simpler for me. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6580) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/codegen/Configuration.py')
-rw-r--r--components/script/dom/bindings/codegen/Configuration.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py
index 6e4bcbed34c..436823a9329 100644
--- a/components/script/dom/bindings/codegen/Configuration.py
+++ b/components/script/dom/bindings/codegen/Configuration.py
@@ -1,11 +1,12 @@
# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this file,
-# You can obtain one at http://mozilla.org/MPL/2.0/.
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from WebIDL import IDLInterface
autogenerated_comment = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n"
+
class Configuration:
"""
Represents global configuration state based on IDL parse data and
@@ -22,7 +23,7 @@ class Configuration:
# |parseData|.
self.descriptors = []
self.interfaces = {}
- self.maxProtoChainLength = 0;
+ self.maxProtoChainLength = 0
for thing in parseData:
# Some toplevel things are sadly types, and those have an
# isInterface that doesn't mean the same thing as IDLObject's
@@ -44,7 +45,8 @@ class Configuration:
if not isinstance(entry, list):
assert isinstance(entry, dict)
entry = [entry]
- self.descriptors.extend([Descriptor(self, iface, x) for x in entry])
+ self.descriptors.extend(
+ [Descriptor(self, iface, x) for x in entry])
# Mark the descriptors for which only a single nativeType implements
# an interface.
@@ -60,10 +62,11 @@ class Configuration:
c.isCallback() and not c.isInterface()]
# Keep the descriptor list sorted for determinism.
- self.descriptors.sort(lambda x,y: cmp(x.name, y.name))
+ self.descriptors.sort(lambda x, y: cmp(x.name, y.name))
def getInterface(self, ifname):
return self.interfaces[ifname]
+
def getDescriptors(self, **filters):
"""Gets the descriptors that match the given filters."""
curr = self.descriptors
@@ -80,6 +83,7 @@ class Configuration:
getter = lambda x: getattr(x, key)
curr = filter(lambda x: getter(x) == val, curr)
return curr
+
def getEnums(self, webIDLFile):
return filter(lambda e: e.filename() == webIDLFile, self.enums)
@@ -93,6 +97,7 @@ class Configuration:
def getDictionaries(self, webIDLFile=""):
return self._filterForFile(self.dictionaries, webIDLFile=webIDLFile)
+
def getCallbacks(self, webIDLFile=""):
return self._filterForFile(self.callbacks, webIDLFile=webIDLFile)
@@ -104,20 +109,23 @@ class Configuration:
descriptors = self.getDescriptors(interface=iface)
# We should have exactly one result.
- if len(descriptors) is not 1:
+ if len(descriptors) != 1:
raise NoSuchDescriptorError("For " + interfaceName + " found " +
- str(len(matches)) + " matches");
+ str(len(descriptors)) + " matches")
return descriptors[0]
+
def getDescriptorProvider(self):
"""
Gets a descriptor provider that can provide descriptors as needed.
"""
return DescriptorProvider(self)
+
class NoSuchDescriptorError(TypeError):
def __init__(self, str):
TypeError.__init__(self, str)
+
class DescriptorProvider:
"""
A way of getting descriptors for interface names
@@ -132,6 +140,7 @@ class DescriptorProvider:
"""
return self.config.getDescriptor(interfaceName)
+
class Descriptor(DescriptorProvider):
"""
Represents a single descriptor for an interface. See Bindings.conf.
@@ -148,7 +157,7 @@ class Descriptor(DescriptorProvider):
if self.interface.isCallback():
self.needsRooting = False
ty = "%sBinding::%s" % (ifaceName, ifaceName)
- self.returnType = "Rc<%s>"% ty
+ self.returnType = "Rc<%s>" % ty
self.argumentType = "???"
self.memberType = "???"
self.nativeType = ty
@@ -230,7 +239,7 @@ class Descriptor(DescriptorProvider):
# self.extendedAttributes is a dict of dicts, keyed on
# all/getterOnly/setterOnly and then on member name. Values are an
# array of extended attributes.
- self.extendedAttributes = { 'all': {}, 'getterOnly': {}, 'setterOnly': {} }
+ self.extendedAttributes = {'all': {}, 'getterOnly': {}, 'setterOnly': {}}
def addExtendedAttribute(attribute, config):
def add(key, members, attribute):
@@ -334,6 +343,7 @@ def getTypesFromDescriptor(descriptor):
types.extend(a.type for a in members if a.isAttr())
return types
+
def getFlatTypes(types):
retval = set()
for type in types:
@@ -344,6 +354,7 @@ def getFlatTypes(types):
retval.add(type)
return retval
+
def getTypesFromDictionary(dictionary):
"""
Get all member types for this dictionary
@@ -355,12 +366,13 @@ def getTypesFromDictionary(dictionary):
curDict = curDict.parent
return types
+
def getTypesFromCallback(callback):
"""
Get the types this callback depends on: its return type and the
types of its arguments.
"""
sig = callback.signatures()[0]
- types = [sig[0]] # Return type
- types.extend(arg.type for arg in sig[1]) # Arguments
+ types = [sig[0]] # Return type
+ types.extend(arg.type for arg in sig[1]) # Arguments
return types