<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="TraceConstructorEntry">
        
<description>Sample aspect program to insert tracing instructions when a construtor is
                entered. This aspect program shows an example of how the implementation of class's constructors 
                can be modified to output a tracing message every time the construtor is executed.
                In this example, the tracing message is output using a 
<code>printf</code> instruction that
                writes a message to the output device stating the name of the class
                to which it belongs. In this example, the identification of the constructors for which tracing is to
                be performed (and which therefore must be modified by the aspect) is done "by class name". This is
                probably the simplest approach in AspectX. 
<p /> This aspect defines four advices that describe four separate but related
                changes. The first advice inserts the tracing code in the target constructors. The second advice
                inserts a new 
<code>include</code> statement to include the <code>stdio</code> library that is
                required by the 
<code>printf</code> method. The third advice modifies the comments of the
                classes that are affected by the change to include a comment that the class code has been
                automatically modified by an aspect program. The fourth advice modifies the comment of the
                methods that are affected by the change to include a description of the type of change that has
                been woven into the code. 
<p /> This sample aspect program targets constructor(s) of all classes 
                in the base code
                
<author>A. Pasetti, o. Rohlik</author>
                
<see>TraceClassEntry</see>
                
<see>TraceMethodEntry</see>
        
</description>
        
        
<pointcut name="targetConstructorImplementation" type="src:constructor">
                
<description>Points to the implementations of the constructors that must be modified. This particular
                    pointcut targets all constructors in the base code. However, it is possible to restrict pointcut 
                    to include only constructors that belong to a target class -- this is shown in another sample 
                    aspect: TraceClassEntry. 
                        
<p />This pointcut only points to the method <i>implementation</i>. A second pointcut
                        (
<code>targetConstructorDeclaration</code>) points to the method declarations.</description>
        
</pointcut>
        
        
<pointcut name="targetConstructorDeclaration" type="src:constructor_decl">
                
<description>Points to all declarations of the target constructors. Similarily to the
                        pointcut 
<code>targetConstructorImplementation</code> it targets all 
                        constructors in the base code.
</description>
        
</pointcut>
        
        
<pointcut name="targetConstructorComment" type="src:comment">
                
<description>Points to the constructor comments that must be modified. The constructor comments that must
                        be modified are those that are followed by a 
<code>targetConstructorDeclaration</code> pointcut. </description>
                
<restriction type="followedBy">
                        
<pointcutRef type="src:constructor_decl" ref="targetConstructorDeclaration" />
                
</restriction>
        
</pointcut>
        
        
<pointcut name="targetClass" type="src:class">
                
<description>Points to all classes that contain a target constructor. The identification is done by
                        taking all the classes that contains a 
<code>targetConstructorDeclaration</code> pointcut </description>
                
<restriction type="contain">
                        
<pointcutRef ref="targetConstructorDeclaration" type="src:constructor_decl" />
                
</restriction>
        
</pointcut>
        
        
<pointcut name="targetClassComment" type="src:comment">
                
<description>&lt;p&gt; Points to the class comments that must be modified. The class
                        comments that must be modified are those that are followed by a 
<code>targetClass</code>
                        pointcut. 
</description>
                
<restriction type="followedBy">
                        
<pointcutRef type="src:class" ref="targetClass" />
                
</restriction>
        
</pointcut>
        
        
<pointcut name="targetImplementationUnit" type="src:unit">
                
<description>Points to all the units that contain implementations of constructors that must be
                        modified. In srcML, a 
<i>unit</i> is a source file (a definition file, a declaration file, or
                        an inline file). This pointcut therefore identifies all the source files that contain an
                        implementation of the target constructor.
</description>
                
<restriction type="contain">
                        
<pointcutRef type="src:constructor" ref="targetConstructorImplementation" />
                
</restriction>
        
</pointcut>
        
        
<advice name="insertClassComment" type="end">
                
<description>Add a comment at the end of the comment of the classes that are modified by other advices.</description>
                
<pointcutRef ref="targetClassComment" type="src:comment" />
                
<codeModifier type="comment">
                        
<text>The implementation of this class has been modified by an aspect
program. The aspect program adds code to trace the execution of constructors. See
the constructor comment for more details.
</text>
                
</codeModifier>
        
</advice>
        
        
<advice name="insertConstructorComment" type="end">
                
<description>Add a comment at the end of the comment of the constructors that are modified by other advices.</description>
                
<pointcutRef ref="targetConstructorComment" type="src:comment" />
                
<codeModifier type="comment">
                        
<text>The implementation of this constructor has been modified by an aspect
program. The aspect program adds a statement that prints a message to the standard output
stating the name of the class. The statement is inserted at the very
beginning of the constructor. This message can be used to trace observe the class 
instantiation during debugging.
</text>
                
</codeModifier>
        
</advice>
        
        
<advice type="begin" name="insertTrace">
                
<description>Insert the tracing instruction in the target constructor. This advice inserts a printf
                        instruction at the beginning of the target constructor. The printf instruction prints a message
                        stating the name of the target class. The name of the target class is accessed using 
                        XSL instruction 
<code>value-of</code> with XPath expression that extracts the class name
                        from scrML. See also the pointcut 
<code>targetConstructorImplementation</code>.</description>
                
<pointcutRef ref="targetConstructorImplementation" type="src:constructor" />
                
<codeModifier type="codeFragment">
                        
<xsl>printf("Execution starts for constructor of class <xsl:value-of select="substring-before(src:name,'::')" />\n"); // code WOVEN by ASPECT</xsl>
                
</codeModifier>
        
</advice>
        
        
<advice type="add" name="addInclude">
                
<description>Add the <code>#include</code> statement for the <code>stdio</code> library.
                        Inclusion of this library is necessary because the code that is woven into the target constructors
                        calls the stdio function 
<code>printf</code>. Note that the code to be added by this advice is
                        specified using the CDATA section because otherwise the braces around "stdio" would be
                        interpreted as xml braces by the XWeaver program.
</description>
                
<pointcutRef ref="targetImplementationUnit" type="src:unit" />
                
<codeModifier type="include">
                        
<text>#include &lt;stdio.h&gt; // code WOVEN by ASPECT</text>
                
</codeModifier>
        
</advice>
</aspect>






































v