Bug 521898, part 4: Make TranslationUnits namespaced things in preparation for headers, which don't have distinguished nodes to infer a C++ namespace from. r=bent
authorChris Jones <jones.chris.g@gmail.com>
Fri, 08 Jun 2012 17:25:36 -0700
changeset 101026 f713eb64e8e1370a38c12a9bd4a73f269cc3a6a2
parent 101025 b96cb0e882eb5c2f2e59f6c405f537a09ce5dd06
child 101027 fece9a6bae3f360c8878362e91ae4fce46653aa7
push id1316
push userakeybl@mozilla.com
push dateMon, 27 Aug 2012 22:37:00 +0000
treeherdermozilla-beta@db4b09302ee2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs521898
milestone16.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 521898, part 4: Make TranslationUnits namespaced things in preparation for headers, which don't have distinguished nodes to infer a C++ namespace from. r=bent
ipc/ipdl/ipdl/__init__.py
ipc/ipdl/ipdl/ast.py
ipc/ipdl/ipdl/parser.py
--- a/ipc/ipdl/ipdl/__init__.py
+++ b/ipc/ipdl/ipdl/__init__.py
@@ -30,17 +30,17 @@ def typecheck(ast, errout=sys.stderr):
 def gencxx(ipdlfilename, ast, outheadersdir, outcppdir):
     headers, cpps = LowerToCxx().lower(ast)
 
     def resolveHeader(hdr):
         return [
             hdr, 
             os.path.join(
                 outheadersdir,
-                *([ns.name for ns in ast.protocol.namespaces] + [hdr.name]))
+                *([ns.name for ns in ast.namespaces] + [hdr.name]))
         ]
     def resolveCpp(cpp):
         return [ cpp, os.path.join(outcppdir, cpp.name) ]
 
     for ast, filename in ([ resolveHeader(hdr) for hdr in headers ]
                           + [ resolveCpp(cpp) for cpp in cpps ]):
         tempfile = StringIO()
         CxxCodeGen(tempfile).cgen(ast)
--- a/ipc/ipdl/ipdl/ast.py
+++ b/ipc/ipdl/ipdl/ast.py
@@ -143,19 +143,19 @@ class NamespacedNode(Node):
 
     def addOuterNamespace(self, namespace):
         self.namespaces.insert(0, namespace)
 
     def qname(self):
         return QualifiedId(self.loc, self.name,
                            [ ns.name for ns in self.namespaces ])
 
-class TranslationUnit(Node):
-    def __init__(self):
-        Node.__init__(self)
+class TranslationUnit(NamespacedNode):
+    def __init__(self, name):
+        NamespacedNode.__init__(self, name=name)
         self.filename = None
         self.cxxIncludes = [ ]
         self.includes = [ ]
         self.using = [ ]
         self.structsAndUnions = [ ]
         self.protocol = None
 
     def addCxxInclude(self, cxxInclude): self.cxxIncludes.append(cxxInclude)
--- a/ipc/ipdl/ipdl/parser.py
+++ b/ipc/ipdl/ipdl/parser.py
@@ -43,17 +43,17 @@ class Parser:
 
     def __init__(self, debug=0):
         self.debug = debug
         self.filename = None
         self.includedirs = None
         self.loc = None         # not always up to date
         self.lexer = None
         self.parser = None
-        self.tu = TranslationUnit()
+        self.tu = TranslationUnit('(none)')
         self.direction = None
         self.errout = None
 
     def parse(self, input, filename, includedirs, errout):
         assert os.path.isabs(filename)
 
         if filename in Parser.parsed:
             return Parser.parsed[filename].tu
@@ -199,16 +199,21 @@ def p_TranslationUnit(p):
             tu.addUnionDecl(thing)
         elif isinstance(thing, Protocol):
             if tu.protocol is not None:
                 _error(thing.loc, "only one protocol definition per file")
             tu.protocol = thing
         else:
             assert(0)
 
+    # The "canonical" namespace of the tu, what it's considered to be
+    # in for the purposes of C++: |#include "foo/bar/TU.h"|
+    tu.namespaces = tu.protocol.namespaces
+    tu.name = tu.protocol.name
+
     p[0] = tu
 
 ##--------------------
 ## Preamble
 def p_Preamble(p):
     """Preamble : Preamble PreambleStmt ';'
                 |"""
     if 1 == len(p):