From 51d8168a2010b5a6250636e8bf3b8af14fb9df7d Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 10 Jul 2009 15:56:40 -0500 Subject: [PATCH] generate skeleton IPDL actor impls, like the IDL compiler does for interfaces. also fix the C++ visitor. --- dom/ipc/IFrameEmbeddingProtocolChild.h | 50 ++++++++++++++++++ dom/ipc/IFrameEmbeddingProtocolParent.h | 24 +++++++++ dom/plugins/NPAPIProtocolChild.h | 56 +++++++++++++++++++++ dom/plugins/NPAPIProtocolParent.h | 50 ++++++++++++++++++ dom/plugins/NPPProtocolChild.h | 44 ++++++++++++++++ dom/plugins/NPPProtocolParent.h | 34 +++++++++++++ ipc/ipdl/ipdl/cxx/ast.py | 23 +++++++-- ipc/ipdl/ipdl/lower.py | 67 +++++++++++++++++++++++++ 8 files changed, 344 insertions(+), 4 deletions(-) diff --git a/dom/ipc/IFrameEmbeddingProtocolChild.h b/dom/ipc/IFrameEmbeddingProtocolChild.h index 0869a7bf616d..af4df7b57f0f 100644 --- a/dom/ipc/IFrameEmbeddingProtocolChild.h +++ b/dom/ipc/IFrameEmbeddingProtocolChild.h @@ -142,5 +142,55 @@ private: }; +#if 0 + +//----------------------------------------------------------------------------- +// Skeleton implementation of abstract actor class + +// Header file contents +class ActorImpl : + public IFrameEmbeddingProtocolChild +{ + virtual nsresult Answerinit(const MagicWindowHandle& parentWidget); + virtual nsresult AnswerloadURL(const String& uri); + virtual nsresult Answermove( + const PRUint32& x, + const PRUint32& y, + const PRUint32& width, + const PRUint32& height); + ActorImpl(); + virtual ~ActorImpl(); +}; + + +// C++ file contents +nsresult ActorImpl::Answerinit(const MagicWindowHandle& parentWidget) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult ActorImpl::AnswerloadURL(const String& uri) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult ActorImpl::Answermove( + const PRUint32& x, + const PRUint32& y, + const PRUint32& width, + const PRUint32& height) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +ActorImpl::ActorImpl() +{ +} + +ActorImpl::~ActorImpl() +{ +} + +#endif // if 0 #endif // ifndef IFrameEmbeddingProtocolChild_h diff --git a/dom/ipc/IFrameEmbeddingProtocolParent.h b/dom/ipc/IFrameEmbeddingProtocolParent.h index 3db49428b33a..09a9fc74198c 100644 --- a/dom/ipc/IFrameEmbeddingProtocolParent.h +++ b/dom/ipc/IFrameEmbeddingProtocolParent.h @@ -136,5 +136,29 @@ private: }; +#if 0 + +//----------------------------------------------------------------------------- +// Skeleton implementation of abstract actor class + +// Header file contents +class ActorImpl : + public IFrameEmbeddingProtocolParent +{ + ActorImpl(); + virtual ~ActorImpl(); +}; + + +// C++ file contents +ActorImpl::ActorImpl() +{ +} + +ActorImpl::~ActorImpl() +{ +} + +#endif // if 0 #endif // ifndef IFrameEmbeddingProtocolParent_h diff --git a/dom/plugins/NPAPIProtocolChild.h b/dom/plugins/NPAPIProtocolChild.h index 6e15ce416919..11ccd32c72f0 100644 --- a/dom/plugins/NPAPIProtocolChild.h +++ b/dom/plugins/NPAPIProtocolChild.h @@ -192,5 +192,61 @@ private: } // namespace plugins } // namespace mozilla +#if 0 + +//----------------------------------------------------------------------------- +// Skeleton implementation of abstract actor class + +// Header file contents +class ActorImpl : + public NPAPIProtocolChild +{ + virtual nsresult AnswerNP_Initialize(NPError* rv); + virtual NPPProtocolChild* NPPConstructor( + const String& aMimeType, + const uint16_t& aMode, + const StringArray& aNames, + const StringArray& aValues, + NPError* rv); + virtual nsresult NPPDestructor( + NPPProtocolChild* __a, + NPError* rv); + ActorImpl(); + virtual ~ActorImpl(); +}; + + +// C++ file contents +nsresult ActorImpl::AnswerNP_Initialize(NPError* rv) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NPPProtocolChild* ActorImpl::NPPConstructor( + const String& aMimeType, + const uint16_t& aMode, + const StringArray& aNames, + const StringArray& aValues, + NPError* rv) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult ActorImpl::NPPDestructor( + NPPProtocolChild* __a, + NPError* rv) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +ActorImpl::ActorImpl() +{ +} + +ActorImpl::~ActorImpl() +{ +} + +#endif // if 0 #endif // ifndef mozilla_plugins_NPAPIProtocolChild_h diff --git a/dom/plugins/NPAPIProtocolParent.h b/dom/plugins/NPAPIProtocolParent.h index d23f8110d53a..3371c1d05251 100644 --- a/dom/plugins/NPAPIProtocolParent.h +++ b/dom/plugins/NPAPIProtocolParent.h @@ -206,5 +206,55 @@ private: } // namespace plugins } // namespace mozilla +#if 0 + +//----------------------------------------------------------------------------- +// Skeleton implementation of abstract actor class + +// Header file contents +class ActorImpl : + public NPAPIProtocolParent +{ + virtual NPPProtocolParent* NPPConstructor( + const String& aMimeType, + const uint16_t& aMode, + const StringArray& aNames, + const StringArray& aValues, + NPError* rv); + virtual nsresult NPPDestructor( + NPPProtocolParent* __a, + NPError* rv); + ActorImpl(); + virtual ~ActorImpl(); +}; + + +// C++ file contents +NPPProtocolParent* ActorImpl::NPPConstructor( + const String& aMimeType, + const uint16_t& aMode, + const StringArray& aNames, + const StringArray& aValues, + NPError* rv) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult ActorImpl::NPPDestructor( + NPPProtocolParent* __a, + NPError* rv) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +ActorImpl::ActorImpl() +{ +} + +ActorImpl::~ActorImpl() +{ +} + +#endif // if 0 #endif // ifndef mozilla_plugins_NPAPIProtocolParent_h diff --git a/dom/plugins/NPPProtocolChild.h b/dom/plugins/NPPProtocolChild.h index 6d068784735d..aa23e1d0566c 100644 --- a/dom/plugins/NPPProtocolChild.h +++ b/dom/plugins/NPPProtocolChild.h @@ -135,5 +135,49 @@ private: } // namespace plugins } // namespace mozilla +#if 0 + +//----------------------------------------------------------------------------- +// Skeleton implementation of abstract actor class + +// Header file contents +class ActorImpl : + public NPPProtocolChild +{ + virtual nsresult AnswerNPP_SetWindow( + const NPWindow& window, + NPError* rv); + virtual nsresult AnswerNPP_GetValue( + const String& key, + String* value); + ActorImpl(); + virtual ~ActorImpl(); +}; + + +// C++ file contents +nsresult ActorImpl::AnswerNPP_SetWindow( + const NPWindow& window, + NPError* rv) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult ActorImpl::AnswerNPP_GetValue( + const String& key, + String* value) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +ActorImpl::ActorImpl() +{ +} + +ActorImpl::~ActorImpl() +{ +} + +#endif // if 0 #endif // ifndef mozilla_plugins_NPPProtocolChild_h diff --git a/dom/plugins/NPPProtocolParent.h b/dom/plugins/NPPProtocolParent.h index 64804b8a5129..593909bffc53 100644 --- a/dom/plugins/NPPProtocolParent.h +++ b/dom/plugins/NPPProtocolParent.h @@ -133,5 +133,39 @@ private: } // namespace plugins } // namespace mozilla +#if 0 + +//----------------------------------------------------------------------------- +// Skeleton implementation of abstract actor class + +// Header file contents +class ActorImpl : + public NPPProtocolParent +{ + virtual nsresult AnswerNPN_GetValue( + const String& key, + String* value); + ActorImpl(); + virtual ~ActorImpl(); +}; + + +// C++ file contents +nsresult ActorImpl::AnswerNPN_GetValue( + const String& key, + String* value) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +ActorImpl::ActorImpl() +{ +} + +ActorImpl::~ActorImpl() +{ +} + +#endif // if 0 #endif // ifndef mozilla_plugins_NPPProtocolParent_h diff --git a/ipc/ipdl/ipdl/cxx/ast.py b/ipc/ipdl/ipdl/cxx/ast.py index 9588993d1b1f..5934b8ddce30 100644 --- a/ipc/ipdl/ipdl/cxx/ast.py +++ b/ipc/ipdl/ipdl/cxx/ast.py @@ -62,19 +62,22 @@ class Visitor: def visitTypedef(self, tdef): tdef.fromtype.accept(self) - tdef.tottype.accept(self) + tdef.totype.accept(self) def visitDecl(self, decl): decl.type.accept(self) def visitClass(self, cls): - for viz, parent in cls.inherits: - parent.accept(self) + for inherit in cls.inherits: + inherit.accept(self) self.visitBlock(cls) def visitInherit(self, inh): pass + def visitFriendClassDecl(self, fcd): + pass + def visitMethodDecl(self, meth): for param in meth.params: param.accept(self) @@ -101,6 +104,9 @@ class Visitor: dd.decl.accept(self) self.visitBlock(dd) + def visitExprLiteral(self, l): + pass + def visitExprVar(self, v): pass @@ -117,6 +123,9 @@ class Visitor: def visitExprDeref(self, ed): self.visitExprPrefixUnop(ed) + def visitExprCast(self, ec): + ec.expr.accept(self) + def visitExprSelect(self, es): es.obj.accept(self) @@ -153,6 +162,12 @@ class Visitor: def visitDefaultLabel(self, dl): pass + def visitStmtIf(self, si): + si.cond.accept(self) + si.ifb.accept(self) + if si.elseb is not None: + si.elseb.accept(self) + def visitStmtSwitch(self, ss): ss.expr.accept(self) self.visitBlock(ss) @@ -268,7 +283,7 @@ class Class(Block): Block.__init__(self) self.name = name - self.inherits = inherits # array of (viz, Type) pairs + self.inherits = inherits self.interface = interface self.abstract = abstract self.final = final diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 3342b7a48666..5ed5a7fe2343 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -688,6 +688,15 @@ class GenerateProtocolActorHeader(Visitor): self.ns.addstmt(cxx.Whitespace.NL) self.ns.addstmt(cxx.Whitespace.NL) + # generate skeleton implementation of abstract actor class + self.file.addthing(cxx.CppDirective('if', '0')) + + genskeleton = GenerateSkeletonImpl() + genskeleton.fromclass(cls) + [ self.file.addthing(thing) for thing in genskeleton.stuff ] + + self.file.addthing(cxx.CppDirective('endif', '// if 0')) + def visitMessageDecl(self, md): # TODO special handling of constructor messages @@ -1038,3 +1047,61 @@ class GenerateProtocolChildHeader(GenerateProtocolActorHeader): def receivesMessage(self, md): return md.decl.type.isInout() or md.decl.type.isOut() + + +class GenerateSkeletonImpl(cxx.Visitor): + def __init__(self, name='ActorImpl'): + self.name = name + self.stuff = [ ] + self.cls = None + self.methodimpls = [ ] + + def fromclass(self, cls): + cls.accept(self) + self.stuff.append(cxx.Whitespace(''' +//----------------------------------------------------------------------------- +// Skeleton implementation of abstract actor class + +''')) + self.stuff.append(cxx.Whitespace('// Header file contents\n')) + self.stuff.append(self.cls) + + self.stuff.append(cxx.Whitespace.NL) + self.stuff.append(cxx.Whitespace('\n// C++ file contents\n')) + self.stuff.extend(self.methodimpls) + + def visitClass(self, cls): + self.cls = cxx.Class(self.name, inherits=[ cxx.Inherit(cls.name) ]) + cxx.Visitor.visitClass(self, cls) + + def visitMethodDecl(self, md): + if not md.pure: + return + decl = deepcopy(md) + decl.pure = 0 + impl = cxx.MethodDefn(cxx.MethodDecl(self.implname(md.name), + params=md.params, + ret=md.ret)) + impl.addstmt(cxx.StmtReturn(cxx.ExprVar('NS_ERROR_NOT_IMPLEMENTED'))) + + self.cls.addstmt(cxx.StmtDecl(decl)) + self.addmethodimpl(impl) + + def visitConstructorDecl(self, cd): + self.cls.addstmt(cxx.StmtDecl(cxx.ConstructorDecl(self.name))) + self.addmethodimpl( + cxx.ConstructorDefn(cxx.ConstructorDecl(self.implname(self.name)))) + + def visitDestructorDecl(self, dd): + self.cls.addstmt( + cxx.StmtDecl(cxx.DestructorDecl(self.name, virtual=1))) + # FIXME/cjones: hack! + self.addmethodimpl( + cxx.DestructorDefn(cxx.ConstructorDecl(self.implname('~' +self.name)))) + + def addmethodimpl(self, impl): + self.methodimpls.append(impl) + self.methodimpls.append(cxx.Whitespace.NL) + + def implname(self, method): + return self.name +'::'+ method