1 /**
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions are
4 * met :
5 *
6 * . Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 *
9 * . Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * . The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 package cppncss.counter;
30
31 import cppast.AstCaseStatement;
32 import cppast.AstCatchBlock;
33 import cppast.AstConditionalExpression;
34 import cppast.AstFunctionBody;
35 import cppast.AstIfStatement;
36 import cppast.AstIterationStatement;
37 import cppast.AstLogicalAndExpression;
38 import cppast.AstLogicalOrExpression;
39
40 /**
41 * Implements a CCN counter.
42 *
43 * @author Mathieu Champlon
44 */
45 public final class CcnCounter extends AbstractCounter
46 {
47 /**
48 * Create a CCN counter.
49 *
50 * @param observer a counter observer
51 */
52 public CcnCounter( final CounterObserver observer )
53 {
54 super( "CCN", observer );
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 public Object visit( final AstFunctionBody node, final Object data )
61 {
62 increment();
63 return node.accept( this, data );
64 }
65
66 /**
67 * {@inheritDoc}
68 */
69 public Object visit( final AstIfStatement node, final Object data )
70 {
71 increment();
72 return node.accept( this, data );
73 }
74
75 /**
76 * {@inheritDoc}
77 */
78 public Object visit( final AstIterationStatement node, final Object data )
79 {
80 increment();
81 return node.accept( this, data );
82 }
83
84 /**
85 * {@inheritDoc}
86 */
87 public Object visit( final AstCaseStatement node, final Object data )
88 {
89 increment();
90 return node.accept( this, data );
91 }
92
93 /**
94 * {@inheritDoc}
95 */
96 public Object visit( final AstCatchBlock node, final Object data )
97 {
98 increment();
99 return node.accept( this, data );
100 }
101
102 /**
103 * {@inheritDoc}
104 */
105 public Object visit( final AstLogicalAndExpression node, final Object data )
106 {
107 increment();
108 return node.accept( this, data );
109 }
110
111 /**
112 * {@inheritDoc}
113 */
114 public Object visit( final AstLogicalOrExpression node, final Object data )
115 {
116 increment();
117 return node.accept( this, data );
118 }
119
120 /**
121 * {@inheritDoc}
122 */
123 public Object visit( final AstConditionalExpression node, final Object data )
124 {
125 increment();
126 return node.accept( this, data );
127 }
128 }