Bug 921563 - part 1 - declare return types in IPDL C++ with C++0x late return syntax; r=gps

Every IPDL C++ class contains a bunch of typedefs.

Every IPDL C++ source file contains a bunch of typedefs and using statements
for the exact same types.

Why is that?

Because the class itself is not in scope for name lookup of return types of C++
methods.  This limitation is annoying, but it makes sense.  The typedefs and
using statements therefore exist so we can be a little sloppy about return
types.

Let's stop being sloppy and polluting the global namespace inside these
files.  Less pollution makes it easier to smash the IPDL files together for
unified compilation.  One could do this by qualifying all necessary return
types...or we could just use the C++0x late return syntax, which guarantees the
class *is* in scope for name lookup.  I like this version a lot better.
This commit is contained in:
Nathan Froyd 2013-09-27 13:50:20 -04:00
parent ad1469a2d1
commit 9126a16e06
3 changed files with 11 additions and 3 deletions

View File

@ -478,6 +478,7 @@ class MethodDecl(Node):
self.never_inline = never_inline # bool
self.typeop = typeop # Type or None
self.T = T # Type or None
self.only_for_definition = False
def __deepcopy__(self, memo):
return MethodDecl(

View File

@ -189,9 +189,12 @@ class CxxCodeGen(CodePrinter, Visitor):
if md.virtual:
self.write('virtual ')
if md.ret:
md.ret.accept(self)
self.println()
self.printdent()
if md.only_for_definition:
self.write('auto ')
else:
md.ret.accept(self)
self.println()
self.printdent()
if md.typeop is not None:
self.write('operator ')
md.typeop.accept(self)
@ -204,6 +207,9 @@ class CxxCodeGen(CodePrinter, Visitor):
if md.const:
self.write(' const')
if md.ret and md.only_for_definition:
self.write(' -> ')
md.ret.accept(self)
if md.warn_unused:
self.write(' NS_WARN_UNUSED_RESULT')
if md.pure:

View File

@ -5316,6 +5316,7 @@ def _splitMethodDefn(md, clsname):
md.decl.static = 0
md.decl.warn_unused = 0
md.decl.never_inline = 0
md.decl.only_for_definition = True
for param in md.decl.params:
if isinstance(param, Param):
param.default = None