Aspect Oriented Programming in C++ - Current supported alternatives

前端 未结 2 1401
挽巷
挽巷 2021-02-10 01:19

I have used AspectJ before for Java, and I recently have thought about checking which possibilities exist for the C++ language.

I heard about AspectC++, but unlike Aspec

2条回答
  •  死守一世寂寞
    2021-02-10 01:52

    AspectC++ was a worthy try but university projects don't often continue because the products tend not to be robust, the original academics lose interest and the graduate students that build it move on. That appeared to be case when I wrote this answer in 2010. To my surprise in 2017, AspectC++ still seems to have active development. If you want just aspects for C++, this is probably worth a look.

    Aspect-oriented programming is a just a special kind of program transformation ("find places that match this condition ('pointcut') and do this to the code at that place"). So, if you have a program transformation tool, you can emulate AOP pretty easily. To do transformation on C++ you need a strong C++ front end and as well as ability to transform and regenerate code. OpenC++ was a project to do C++ transformations, where the transformations are coded purely as procedural AST-walks with procedural AST modifications. A particular issue had to do with which dialect of C++ was handled by OpenC++; in particular, I'm not sure OpenC++ handled templates or full common dialects (GCC, MS) of C+; however I have no direct experience with it, just a keen aficionado of such tools.

    Our DMS Software Reengineering Toolkit is a general purpose program transformation parameterized by language definitions. It has robust definitions for GCC and MS dialects of C++. You can implement program transformations procedurally as OpenC++ does, or more conveniently you can write source-to-source pattern-directed transformations (or more usually, mix these to achieve complex effects). DMS has been used to carry out massive restructuring of large scale C++ codes (see Case study: Re-engineering C++ component models via automatic program transformation ). DMS is actively maintained, but it is commercial.

    EDIT March, 2015: Now does C++14 in GCC and MS dialects.

    EDIT July 2017: Now does C++17 in GCC and MS dialects.

提交回复
热议问题