[aspectc-user] Aspect C++ question:how to control the output methods?

Michael, G. g.michael at TUE.nl
Tue Oct 14 14:34:07 CEST 2003


Dear Sir,

I am doing a project using the AspectC++ system.
Curently, I am trying to define an aspect that prints the name of the method on the screen at the start and exit of a method.
Below I include an example of the advice that I have tried.
However, it yields output only after one of the methods called in my program.

I seem to remember that there is an example program (maybe in one of the papers on AspectC++) that illustrates this type of functionality.

Could you please send this example to me and/or tell me how to code such an aspect?
Kind regards,


  Gati Michael.

---------
The aspect code looks like this:
	#ifndef __mytest_h__
	#define __mytest_h__
	#include <stdio.h>
	aspect mytest {

	advice execution((" void %::%()"))&&: before()  
	{ printf(" Function ... has been found\n");
	    }
	advice execution((" void %::%()"))&&: after()  
	{printf(" Function ... has been exit\n");
	    }
	};
	#endif // __mytest_h__

The program code looks like this:
#include <stdio.h>
#include <stdlib.h>
class PBase
 {
   public:
      void abar(int, int) {
        printf("PBase::abar()\n");
         cbar(2,5);  }

void cbar(int, int) {
        printf("PBase::cbar()\n");
      }
 };

class Test : public PBase {
  public:
    void foo() {
      	printf("Test::foo()\n");
	abar(1,2);
}   void abar(int, int) {
   printf("Test::abar()\n");
    }
    void bbar(int, int) {
        printf("Test::bbar()\n");}
};
class subTest : public Test
 {
    void abar(int, int) {
        printf("subTest::abar()\n");
    }
 };

int main()
 {
   subTest test;
  test.foo();
  PBase od;
 od.abar (3, 4);
 PBase nr;  
 nr.cbar(4,6);
  return 0;
 }

Here  is the result:

Function ... has been found
Test::foo()
Test::abar()
Function... has been exit
PBase::abar()
PBase::cbar()
PBase::cbar()

How can I control the  results such that I get all five prints after each method?








More information about the aspectc-user mailing list