Hi again,
I was wondering if I can just use a tracematch alone to track the value
of a local variable across throughout the trace itself To illustrate the
problem, I have the following code:
class Account {
private int type; // Integer to determine account type
public Account(int t) {
this.type = t;
}
public void withdraw(double amount) {
System.out.println("Withdraw");
}
public void deposit(double amount) {
System.out.println("Deposit");
}
public static void main(String[] args) {
Account a1 = new Account(1);
Account a2 = new Account(1);
a1.withdraw(5);
a1.deposit(2);
a2.withdraw(2);
a1.deposit(6); // Match to occur here
a1.deposit(1);
}
}
public aspect AccountTM {
tracematch (Account a) {
sym wd after:
call (* Account.withdraw(..)) && target(a);
sym dp after:
call (* Account.deposit(..)) && target(a);
wd dp[2]
{
System.out.println("1 withdraw and 2 deposit method calls
made by " + a);
}
}
}
As we can see the tracematch matches 1 withdraw() and 2 deposit() method
calls on a given object. My question is am I able to use just one
tracematch to track the value of "amount"? i.e. given the following calls
a1.withdraw(5);
a1.deposit(2);
a2.withdraw(2);
a1.deposit(6);
a1.deposit(1);
As the regular expression matches the executions made by a1, I would
like to be able to keep track of the amount that was withdrawn and
deposited. So for that example above, I would have -5 + 2 + 6 = 3 as the
total amount withdrawn and deposited throughout the execution of a1.
I have ideas over how to solve this, but I was wondering if I could do
it all using tracematches only? I was more inclined towards thinking
that it is not possible given the grammar specified for tracematches.
Thanks.
Received on Wed Feb 20 2008 - 15:12:09 GMT
This archive was generated by hypermail 2.2.0 : Wed Feb 20 2008 - 15:30:11 GMT