[aspectc-user] Help

Pavlo Korzhyk pavlo.korzhyk at gmail.com
Thu Apr 27 15:05:56 CEST 2006


Why do you think this program is for aspectc?
I googled for the string "pointcut factBase(int x)", and found your example
in the article about aspectj (AOP for Java).
I think checking argument value is impossible in aspectc. At least official
documentation doesn't describe such a feature.
The easiest way to implement factorial in aspectc is checking for argument
value inside the "around" advice.
Below is the source code I wrote when trying to implement your example in
aspectc.

I don't know why, but this code doesn't compile if I use "call" instead
"execution".
The problem seems to be with the recursive call. Will anybody show the way
of using "call" in this program?

Another problem I discovered is probably a bug in ac++. When I replace
recursive call

   *tjp->result()=x*( FactClass::fact(x-1) );

with

   *tjp->result()=x*( *tjp->target()->fact(x-1) );

the program runs fine. When I write "call" instead "execution", recursion
stops working.
The parser doesn't recognize "*tjp->target()->fact(x-1)" as a call to
FactClass::fact method, and this call is
not advised.

According to your email address you are from Lutsk. So greetings from
Vinnytsia :)

======= file aspect.ah ==========
#ifndef _FACT_EXAMPLE_
#define _FACT_EXAMPLE_

#include "FactClass.h"
#include <iostream>

aspect FactExample
{
    advice "FactClass" : slice class
    {
    public:
        static int fact(int x)
        {
            return 1;
        }
    };

    pointcut Fact(int x) = execution("int ...::FactClass::%(int)") &&
args(x);

    advice Fact(x) :around(int x)
    {
        if(x==1)
            *tjp->result()=1;
        else
            tjp->proceed();
    }

    advice Fact(x) :around(int x)
    {
        if(x>1){
            *tjp->result()=x*( FactClass::fact(x-1) );
        }else
            tjp->proceed();
    }
};

#endif
======= end of aspect.ah =========


======= file FactClass.h =========
#ifndef _FACT_
#define _FACT_
class FactClass{};
#endif
======= end of FactClass.h =========


======= file main.cc =========
#include <iostream>
#include "FactClass.h"
using namespace std;
int main()
{
   for(int i=1;i<10;i++)
      cout << FactClass::fact(i) << endl;
   return 0;
}
======= end of FactClass.h =========

> Dear Sir!
> I found a very interesting program (see attachment) with recursion call
> (factorial computation). But, unfortunately, I do not know how to correct
> conditions in advices
> (e.g. advice () ... args(x) && (x==1)). The latter is an error (x==1) how
to
> modify the code?
> Another question is about call such constructed class members. I mean how
to
> call, for example, Fact::fact(4),
> where fact member function is intriduced as aspect?


--
WBR, Pavlo Korzhyk
ICQ#155870780
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20060427/9a6a25f0/attachment.html>


More information about the aspectc-user mailing list