
Aspect-Oriented Programming with C++ Olaf Spinczyk University of Erlangen-Nuremberg The AspectC++ Project ACOomPpute rw Sciietnche 4 C++ © 2005 Olaf Spinczyk 1 This talk is about ... ➢ the importance of C++ for the success of AOP ➢ different AOP approaches for C++ – language independent vs. pure C++ vs. extension ➢ the AspectC++ project – history, language, implementation ➢ the future AOP with C++ © 2005 Olaf Spinczyk 2 Observations: AOP Products ➢ IBM: AspectJ and AJDT ➢ BEA: AspectWerkz ➢ JBoss: JBoss AOP AOP with C++ © 2005 Olaf Spinczyk 3 Observations: AOP Products ➢ IBM: AspectJ and AJDT ➢ BEA: AspectWerkz ➢ JBoss: JBoss AOP AOP with C++ © 2005 Olaf Spinczyk 4 Observations: AOP Products ... for C++ developers: ➢ Semantic Designs: DMS ➢ P&P Software: XWeaver ➢ pure-systems: AspectC++ Add-In AOP with C++ © 2005 Olaf Spinczyk 5 Observations: AOP Products ... for C++ developers: ➢ Semantic Designs: DMS ➢ P&P Software: XWeaver ➢ pure-systems: AspectC++ Add-In these teams play in a different league AOP with C++ © 2005 Olaf Spinczyk 6 Observations: AOP Research Java vs. C++ at AOSD 10 7,5 other 5 Java C/C++ 2,5 0 2003 2004 2005 C++ is almost invisible! AOP with C++ © 2005 Olaf Spinczyk 7 Java vs. C++ in the Real World open source projects 40000 30000 34,91% Java 20000 C/C++ 37,71% 10000 C only 27,38% 0 2004/09/09 (source- forge) AOP with C++ © 2005 Olaf Spinczyk 8 Java vs. C++ in the Real World requested skills 100,00% 35 38 75,00% Java C++ 50,00% 41 41 C 25,00% 26 21 0,00% 2003 2004 AOP with C++ © 2005 Olaf Spinczyk 9 Java vs. C++ in the Real World requested skills 100,00% 35 38 75,00% Java C++ 50,00% 41 41 C 25,00% 26 21 0,00% 2003 2004 C and C++ are still dominating! AOP with C++ © 2005 Olaf Spinczyk 10 Java vs. C++ in the Real World AOP research & products don't reflect the real world. Why? AOP with C++ © 2005 Olaf Spinczyk 11 Reasons C++ is one of the most complex languages today developing tools and extensions is painfully hard C++ is not common in academic research no transfer from academia to industry AOP with C++ © 2005 Olaf Spinczyk 12 The Problem AOP research & products don't reflect the real world. ➢ the unwanted message is: AOP is Java. ➢ the unwanted consequences are: – no large scale adoption by the IT industry – billions lines of C/C++ code don't benefit from AOP AOP with C++ © 2005 Olaf Spinczyk 13 * WANTED * DEAD OR ALIVE AspectC++ AOP with C++ © 2005 Olaf Spinczyk 14 Requirements an AOP solution for C++ has to ... ➢ support full obliviousness and quantification – no preparation of the component code – rich pointcut language ➢ be strong were C++ is strong – no runtime system – support for procedural, object-oriented, and generic code – exploit and support the powerful static type system – efficient code ➢ be usable – simple – easy integration AOP with C++ © 2005 Olaf Spinczyk 15 Technical Approaches idea coding source source code code transformation compilation (virtual) binary code machine code transformation execution process AOP with C++ © 2005 Olaf Spinczyk 16 Technical Approaches idea AOP with pure C++ coding • patterns source sourc• ete cmodpelates, macros code transformation compilation (virtual) binary code machine code transformation execution process AOP with C++ © 2005 Olaf Spinczyk 17 AOP with pure C++ (1) C. Czarnecki, U. Eisenecker, L. Dominick: // generic wrapper (aspect) that adds counting to // any queue class Q, as long as it implements the // proper interface template <class Q> class Counting_Aspect : public Q { int counter; // introduction public: void enqueue(Item* item) { // after advice Q::enqueue(item); counter++; } }; AOP with C++ © 2005 Olaf Spinczyk 18 AOP with pure C++ (2) aspect weaving by template instantiation // component code class Queue { ... } // wrappers (aspects) template <class Q> class Counting_Aspect : public Q { ... } template <class Q> class Tracing_Aspect : public Q { ... } // template instantiation (weaving) typedef Counting_Aspect<Queue> CountingQueue; typedef Trace_Aspect<Counting_Queue> TraceCountingQueue; AOP with C++ © 2005 Olaf Spinczyk 19 AOP with pure C++ (3) obliviousness for the client code namespace components { class Queue { ... }; } namespace aspects { template <class Q> class Counting_Aspect : public Q { ... }; } namespace configuration { // select counting queue typedef aspects::Counting_Aspect<components::Queue> Queue; } using namespace configuration; void client_code () { Queue queue; // Queue with all configured aspects queue.enqueue (new MyItem); } AOP with C++ © 2005 Olaf Spinczyk 20 AOP with pure C++ (4) C. Diggins: macros hide the template “magic” // the CountingAspect as before struct CountingAspect { // Inc and Dec is advice struct Inc { template<...> virtual void OnAfter (...) { ... } }; }; // the DEF_POINTCUT macro describes sets of member functions DEF_POINTCUT(EnqueuePointcut) SET_PROCJOINPOINT1(enqueue, Item*, item) END_POINTCUT // the CROSSCUT macro combines a class, a pointcut, and an aspect typedef CROSSCUT(Queue,EnqueuePointcut, CountingAspect::Inc) CountingQueue; AOP with C++ © 2005 Olaf Spinczyk 21 AOP with pure C++ - Review obliviousness: not given – component code has to be “prepared” quantification: not given – aspects have to be applied manually strong: not really – basically supports weaving in public (virtual) class member functions usable: not often + no special tool support required – code is hard to develop, understand, and maintain AOP with C++ © 2005 Olaf Spinczyk 22 AOP with pure C++ - Review obliviousness: not given – component code has to be “prepared” quantification: not given – aspects have to be applied manually sntroo ntogo: nl onte reedalelyd, but too many restrictions – basically supports weaving in public (virtual) class member functions usable: not often + no special tool support required – code is hard to develop, understand, and maintain AOP with C++ © 2005 Olaf Spinczyk 23 Technical Approaches idea coding source source code code transformation compilation Code Transformers (virtual) binary code machine code trans• fAorsmpaeticotCn ++ execution • XWeaver • DMS process AOP with C++ © 2005 Olaf Spinczyk 24 XWeaver (1) XML Model .xml XML Model .xml .xml .xml of Modified .xml of Base Code .xml Code XWeaver .xml AspectX Program AOP with C++ © 2005 Olaf Spinczyk 25 XWeaver (1) * a piece of code in XML * <?xml version="1.0" encoding="ISO-8859-1"?> ... XML Model .xml XML Model .xml .xml <function> .xml of Modified .xml of B a s<type><name>int</name></type>e Code .xml Code <name>main</name> <parameter_list>()</parameter_list> <block>{}</block> </function>XWeaver ... a concrete syntax tree .xml AspectX Program AOP with C++ © 2005 Olaf Spinczyk 26 XWeaver (2) ➢ the language-dependent part .cpp .cpp C++ .cp.cppp Modified .cpp.h .cpp .h Base Code .h.h Code .h .h srcML XML Model .xml XML Model .xml .xml .xml of Modified of Base Code .xml .xml Code XWeaver .xml AspectX Program AOP with C++ © 2005 Olaf Spinczyk 27 XWeaver (3) current limitations: ➢ only supports “embedded C++” ➢ strongly limited join point model – function/constructor/destructor execution only reason: srcML parser problems ➢ no semantic analysis, no function call resolution no call advice! ➢ E.g. “int (*f())(long) {}” yields nonsense AOP with C++ © 2005 Olaf Spinczyk 28 XWeaver (3) current limitations: ➢ only supports “embedded C++” ➢ strongly limited join point model – function/constructor/destructor execution only rTeahseo ntr: asrncsMfoL rpmaarsetior pnro abplepmrsoach is only viable ➢wnitho s aem fuanllytic-f alenadglysise,d n oC fu+n+c tpaion rcsaell rr/aesnaolutlyionzer. no call advice! ➢ E.g. “int (*f())(long) {}” yields nonsense AOP with C++ © 2005 Olaf Spinczyk 29 Code Transformation - Review obliviousness: possible + weaver has full control quantification: possible + only a matter of aspect language features strong: definitely + generated code can be as efficient as tangled code usable: yes + AspectJ-like programming model possible + easy integration into existing tool chains + platform-independent AOP with C++ © 2005 Olaf Spinczyk 30 Technical Approaches idea coding source source code code transformation compilation Compiler Integration (virtual) binary code machine code transformation execution process AOP with C++ © 2005 Olaf Spinczyk 31 Compiler Integration Could an AOP extension for C++ make it into... – commercial compilers? – the C++ standardization? ISO/IEC JTC1/SC22/WG21 – very busy with problems like “A<B<C>>” – Detlef Vollmann summarizes “Aspects of Reflection in C++” – Daveed Vandevoorde presents a “Metaprogramming Extension” at the ACCU conference – besides that: no revolutions AOP with C++ © 2005 Olaf Spinczyk 32 Compiler Integration Could an AOP extension for C++ make it into... – commercial compilers? – Tthhee C t+ra+n sstaitniodnar dfrizoamtio Cn? to C++ took many years. ISO/IEC JTC1/SC22/WG21 We should not expect this process to be – very busy with problems like “A<B<C>>” faster in the case of AOP. – Detlef Vollmann summarizes “Aspects of Reflection in C++” – Daveed Vandevoorde presents a “Metaprogramming Extension” at ACCU – besides that: no revolutions AOP with C++ © 2005 Olaf Spinczyk 33 Technical Approaches idea coding source sLaoungrceu caogde-independent code tAraOnsPformation compilation (virtual) binary code machine code transformation execution Runtime Weaving process • Arachne AOP with C++ © 2005 Olaf Spinczyk 34 Weaving in Byte/Machine Code completely decouples the weaver from the parser, but ... ➢ aspect weaving in machine code ... – strictly limits available AOP features – has to be implemented for numerous
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages59 Page
-
File Size-