Bug 1289467 part 4. Make ForwardDeclarationBuilder error out if asked to forward-declare a templated type instead of spitting out nonsense that doesn't compile. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 27 Jul 2016 11:05:36 -0400
changeset 306905 2bf4894c52c903f96d10f534108ed9ebe43b47ba
parent 306904 d1031a67635a3b3a9fce33858f8ea7214a8b572a
child 306906 d1188f77967db7e9c98010620850ac066172b778
push id30891
push usercbook@mozilla.com
push dateThu, 28 Jul 2016 15:52:34 +0000
treeherderautoland@54eb32559af3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1289467
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1289467 part 4. Make ForwardDeclarationBuilder error out if asked to forward-declare a templated type instead of spitting out nonsense that doesn't compile. r=qdot
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -13083,16 +13083,26 @@ class ForwardDeclarationBuilder:
         Each tree node has a set of declarations |decls| and a dict |children|.
         Each declaration is a pair consisting of the class name and a boolean
         that is true iff the class is really a struct. |children| maps the
         names of inner namespaces to the declarations in that namespace.
         """
         self.decls = set()
         self.children = {}
 
+    def _ensureNonTemplateType(self, type):
+        if "<" in type:
+            # This is a templated type.  We don't really know how to
+            # forward-declare those, and trying to do it naively is not going to
+            # go well (e.g. we may have :: characters inside the type we're
+            # templated on!).  Just bail out.
+            raise TypeError("Attempt to use ForwardDeclarationBuilder on "
+                            "templated type %s.  We don't know how to do that "
+                            "yet." % type)
+
     def _listAdd(self, namespaces, name, isStruct=False):
         """
         Add a forward declaration, where |namespaces| is a list of namespaces.
         |name| should not contain any other namespaces.
         """
         if namespaces:
             child = self.children.setdefault(namespaces[0], ForwardDeclarationBuilder())
             child._listAdd(namespaces[1:], name, isStruct)
@@ -13100,23 +13110,25 @@ class ForwardDeclarationBuilder:
             assert '::' not in name
             self.decls.add((name, isStruct))
 
     def addInMozillaDom(self, name, isStruct=False):
         """
         Add a forward declaration to the mozilla::dom:: namespace. |name| should not
         contain any other namespaces.
         """
+        self._ensureNonTemplateType(name);
         self._listAdd(["mozilla", "dom"], name, isStruct)
 
     def add(self, nativeType, isStruct=False):
         """
         Add a forward declaration, where |nativeType| is a string containing
         the type and its namespaces, in the usual C++ way.
         """
+        self._ensureNonTemplateType(nativeType);
         components = nativeType.split('::')
         self._listAdd(components[:-1], components[-1], isStruct)
 
     def _build(self, atTopLevel):
         """
         Return a codegenerator for the forward declarations.
         """
         decls = []