Bug 1000675. Don't always include nsContentUtils in example codegen, fix example header guards to not end with __, don't use fully-qualified names in argument types when those argument types are in the mozilla::dom namespace already, and include headers from mozilla/dom. r=jst
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 26 Apr 2014 21:49:59 -0400
changeset 180859 2f394d14ac89d54511dd36bfc0f4718492bcbaec
parent 180858 fcf19894d9f339f73df310905520047902b009df
child 180860 252653fe3a934b7106cdf929f2ac9ee6d821e818
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersjst
bugs1000675
milestone31.0a1
Bug 1000675. Don't always include nsContentUtils in example codegen, fix example header guards to not end with __, don't use fully-qualified names in argument types when those argument types are in the mozilla::dom namespace already, and include headers from mozilla/dom. r=jst
dom/bindings/Codegen.py
dom/bindings/Configuration.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -862,17 +862,17 @@ class CGNamespace(CGWrapper):
 
 
 class CGIncludeGuard(CGWrapper):
     """
     Generates include guards for a header.
     """
     def __init__(self, prefix, child):
         """|prefix| is the filename without the extension."""
-        define = 'mozilla_dom_%s_h__' % prefix
+        define = 'mozilla_dom_%s_h' % prefix
         CGWrapper.__init__(self, child,
                            declarePre='#ifndef %s\n#define %s\n\n' % (define, define),
                            declarePost='\n#endif // %s\n' % define)
 
 
 def getRelevantProviders(descriptor, config):
     if descriptor is not None:
         return [descriptor]
@@ -11179,25 +11179,18 @@ class CGNativeMember(ClassMethod):
                 enumName = CGTemplatedType("Nullable",
                                            CGGeneric(enumName)).define()
                 defaultValue = "%s()" % enumName
             else:
                 defaultValue = "%s(0)" % enumName
             return enumName, defaultValue, "return ${declName};\n"
         if type.isGeckoInterface():
             iface = type.unroll().inner
-            nativeType = self.descriptorProvider.getDescriptor(
-                iface.identifier.name).nativeType
-            # Now trim off unnecessary namespaces
-            nativeType = nativeType.split("::")
-            if nativeType[0] == "mozilla":
-                nativeType.pop(0)
-                if nativeType[0] == "dom":
-                    nativeType.pop(0)
-            result = CGGeneric("::".join(nativeType))
+            result = CGGeneric(self.descriptorProvider.getDescriptor(
+                iface.identifier.name).prettyNativeType)
             if self.resultAlreadyAddRefed:
                 if isMember:
                     holder = "nsRefPtr"
                 else:
                     holder = "already_AddRefed"
                 if memberReturnsNewObject(self.member):
                     warning = ""
                 else:
@@ -11357,17 +11350,17 @@ class CGNativeMember(ClassMethod):
                 if optional or isMember:
                     if forceOwningType:
                         typeDecl = "OwningNonNull<%s>"
                     else:
                         typeDecl = "NonNull<%s>"
                 else:
                     typeDecl = "%s&"
             return ((typeDecl %
-                     self.descriptorProvider.getDescriptor(iface.identifier.name).nativeType),
+                     self.descriptorProvider.getDescriptor(iface.identifier.name).prettyNativeType),
                     False, False)
 
         if type.isSpiderMonkeyInterface():
             if self.jsObjectsArePtr:
                 return "JSObject*", False, False
 
             return type.name, True, True
 
@@ -11810,20 +11803,19 @@ class CGExampleRoot(CGThing):
                             self.root], "\n")
 
         # Throw in our #includes
         self.root = CGHeaders([], [], [], [],
                               ["nsWrapperCache.h",
                                "nsCycleCollectionParticipant.h",
                                "mozilla/Attributes.h",
                                "mozilla/ErrorResult.h"],
-                              ["%s.h" % interfaceName,
+                              ["mozilla/dom/%s.h" % interfaceName,
                                ("mozilla/dom/%s" %
-                                CGHeaders.getDeclarationFilename(descriptor.interface)),
-                               "nsContentUtils.h"], "", self.root)
+                                CGHeaders.getDeclarationFilename(descriptor.interface))], "", self.root)
 
         # And now some include guards
         self.root = CGIncludeGuard(interfaceName, self.root)
 
         # And our license block comes before everything else
         self.root = CGWrapper(self.root, pre=dedent("""
             /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
             /* vim:set ts=2 sw=2 sts=2 et cindent: */
--- a/dom/bindings/Configuration.py
+++ b/dom/bindings/Configuration.py
@@ -228,16 +228,25 @@ class Descriptor(DescriptorProvider):
             nativeTypeDefault = "mozilla::dom::" + ifaceName
         else:
             if self.workers:
                 nativeTypeDefault = "mozilla::dom::workers::" + ifaceName
             else:
                 nativeTypeDefault = "mozilla::dom::" + ifaceName
 
         self.nativeType = desc.get('nativeType', nativeTypeDefault)
+        # Now create a version of nativeType that doesn't have extra
+        # mozilla::dom:: at the beginning.
+        prettyNativeType = self.nativeType.split("::")
+        if prettyNativeType[0] == "mozilla":
+            prettyNativeType.pop(0)
+            if prettyNativeType[0] == "dom":
+                prettyNativeType.pop(0)
+        self.prettyNativeType = "::".join(prettyNativeType)
+
         self.jsImplParent = desc.get('jsImplParent', self.nativeType)
 
         # Do something sane for JSObject
         if self.nativeType == "JSObject":
             headerDefault = "js/TypeDecls.h"
         elif self.interface.isCallback() or self.interface.isJSImplemented():
             # A copy of CGHeaders.getDeclarationFilename; we can't
             # import it here, sadly.