<
aspect xmlns:cpp="
http://www.sdml.info/srcML/cpp"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns="
http://control.ee.ethz.ch/XWeaver/AspectX"
xmlns:src="
http://www.sdml.info/srcML/src"
xsi:schemaLocation="
http://control.ee.ethz.ch/XWeaver/AspectX ../../../../src/xsd/aspectX.xsd"
name="
CarBeginEnd">
<
description>
Sample aspect program for "car example" that inserts tracing instructions when
a setter method <
i>
with integer parameter</
i>
is entered and when <
i>
any</
i>
setter method is left.
In this example, the tracing message is output using a output stream that writes a message to
the output device stating the name of the method and the name of the class to which it belongs.
The methods that are to be modified by the aspect are identified using their name.
These methods have to contain substring "set" in their name.
<
author>
I. Birrer, O. Rohlik</
author>
<
see>
CarPostCondition</
see>
<
see>
CarPreCondition</
see>
<
see>
CarSynchronizeWindows</
see>
</
description>
<
pointcut name="
anySetFunction"
type="
src:function"
constraint="
contains(src:name/src:name[2],'set')">
<
description>
Points to all setter methods. These method are recognized as methods that contain
substring "set" in the method name.</
description>
</
pointcut>
<
pointcut name="
setIntFunctions"
type="
src:function"
constraint="
contains(src:name/src:name[2],'set') and src:parameter_list/src:param/src:decl[position() = 1 and src:type/src:name='int']">
<
description>
Points to setter methods with <
CODE>
int</
CODE>
paramter. These method are
recognized as methods that contain substring "set" in the method name and
have formal paramter of type <
CODE>
int</
CODE>
.</
description>
</
pointcut>
<
pointcut type="
src:unit"
name="
units">
<
description>
Point to units that contain setter methods.</
description>
<
or>
<
restriction type="
contain">
<
pointcutRef ref="
setIntFunctions"
type="
src:function" />
</
restriction>
<
restriction type="
contain">
<
pointcutRef ref="
anySetFunction"
type="
src:function" />
</
restriction>
</
or>
</
pointcut>
<
advice type="
begin"
name="
atBegin">
<
description>
Inserts a print instruction at the beginning of the
target method. The print instruction outputs the name of called method, the name of class
and the value of <
code>
int</
code>
parameter.
The names of the method, class and parameter are accessed using "dollar variables".
</
description>
<
pointcutRef ref="
setIntFunctions"
type="
src:function" />
<
codeModifier type="
codeFragment">
<
text>
cout << "Call function: ${functionName} of class ${className} with param: ${paramTypes[1]} ${paramNames[1]} and value " << ${paramNames[1]} << endl;</
text>
</
codeModifier>
</
advice>
<
advice type="
end"
name="
atEnd">
<
description>
Inserts a print instruction at the beginning of the
target method. The print instruction outputs the name of called method and the name of class.
The names of the method and class are accessed using "dollar variables".</
description>
<
pointcutRef ref="
anySetFunction"
type="
src:function" />
<
codeModifier type="
codeFragment">
<
text>
cout << "Called function: ${functionName} of class ${className}" << endl;</
text>
</
codeModifier>
</
advice>
<
advice type="
add"
name="
addIncludes">
<
description>
Inserts <
code>
#include</
code>
and <
code>
namespace</
code>
instructions to the unit (file). Both instructions
are necessary to use the output stream. The advice adds
two lines of code at the beginning of unit: <
code>
#include <iostream></
code>
and <
code>
using namespace std;</
code>
</
description>
<
pointcutRef ref="
units"
type="
src:unit" />
<
codeModifier type="
include">
<
text>
#include <iostream>
using namespace std;</
text>
</
codeModifier>
</
advice>
</
aspect>
v