Package: TraceAnnotation

TraceAnnotation

nameinstructionbranchcomplexitylinemethod
TraceAnnotation()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkArgs(INode)
M: 22 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
inAfter(PExp, Value, Context)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
inAfter(PStm, Value, Context)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
inBefore(PExp, Context)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
inBefore(PStm, Context)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
printArgs(Context)
M: 64 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
tcAfter(AModuleModules, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcAfter(PDefinition, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcAfter(PExp, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcAfter(PStm, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcAfter(SClassDefinition, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcBefore(AModuleModules, TypeCheckInfo)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tcBefore(PDefinition, TypeCheckInfo)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tcBefore(PExp, TypeCheckInfo)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tcBefore(PStm, TypeCheckInfo)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tcBefore(SClassDefinition, TypeCheckInfo)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
typecheckArgs()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (c) 2019 Nick Battle.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of Overture
8: *
9: ******************************************************************************/
10:
11: package org.overture.annotations.provided;
12:
13: import org.overture.ast.analysis.AnalysisException;
14: import org.overture.ast.definitions.PDefinition;
15: import org.overture.ast.definitions.SClassDefinition;
16: import org.overture.ast.expressions.AVariableExp;
17: import org.overture.ast.expressions.PExp;
18: import org.overture.ast.modules.AModuleModules;
19: import org.overture.ast.node.INode;
20: import org.overture.ast.statements.PStm;
21: import org.overture.interpreter.annotations.INAnnotation;
22: import org.overture.interpreter.eval.ExpressionEvaluator;
23: import org.overture.interpreter.messages.Console;
24: import org.overture.interpreter.runtime.Context;
25: import org.overture.interpreter.values.Value;
26: import org.overture.parser.annotations.ASTAnnotationAdapter;
27: import org.overture.typechecker.TypeCheckInfo;
28: import org.overture.typechecker.TypeChecker;
29: import org.overture.typechecker.annotations.TCAnnotation;
30:
31: public class TraceAnnotation extends ASTAnnotationAdapter implements TCAnnotation, INAnnotation
32: {
33:         public TraceAnnotation()
34:         {
35:                 super();
36:         }
37:         
38:         @Override
39:         public boolean typecheckArgs()
40:         {
41:                 return true;        // Check args
42:         }
43:         
44:         /**
45:          * Type checker...
46:          */
47:
48:         @Override
49:         public void tcBefore(PDefinition node, TypeCheckInfo question)
50:         {
51:                 TypeChecker.report(6005, "@Trace only applies to expressions and statements", ast.getName().getLocation());
52:         }
53:
54:         @Override
55:         public void tcBefore(PExp node, TypeCheckInfo question)
56:         {
57:                 checkArgs(node);
58:         }
59:
60:         @Override
61:         public void tcBefore(PStm node, TypeCheckInfo question)
62:         {
63:                 checkArgs(node);
64:         }
65:
66:         @Override
67:         public void tcBefore(AModuleModules node, TypeCheckInfo question)
68:         {
69:                 TypeChecker.report(6005, "@Trace only applies to expressions and statements", ast.getName().getLocation());
70:         }
71:
72:         @Override
73:         public void tcBefore(SClassDefinition node, TypeCheckInfo question)
74:         {
75:                 TypeChecker.report(6005, "@Trace only applies to expressions and statements", ast.getName().getLocation());
76:         }
77:
78:         public void checkArgs(INode node)
79:         {
80:•                for (PExp arg: ast.getArgs())
81:                 {
82:•                        if (!(arg instanceof AVariableExp))
83:                         {
84:                                 TypeChecker.report(6006, "@Trace argument must be an identifier", arg.getLocation());
85:                         }
86:                 }
87:         }
88:
89:         @Override
90:         public void tcAfter(PDefinition node, TypeCheckInfo question)
91:         {
92:                 // Nothing
93:         }
94:
95:         @Override
96:         public void tcAfter(PExp node, TypeCheckInfo question)
97:         {
98:                 // Nothing
99:         }
100:
101:         @Override
102:         public void tcAfter(PStm node, TypeCheckInfo question)
103:         {
104:                 // Nothing
105:         }
106:
107:         @Override
108:         public void tcAfter(AModuleModules node, TypeCheckInfo question)
109:         {
110:                 // Nothing
111:         }
112:
113:         @Override
114:         public void tcAfter(SClassDefinition node, TypeCheckInfo question)
115:         {
116:                 // Nothing
117:         }
118:         
119:         /**
120:          * Interpreter...
121:          */
122:
123:         @Override
124:         public void inBefore(PStm node, Context ctxt) throws AnalysisException
125:         {
126:                 printArgs(ctxt);
127:         }
128:
129:         @Override
130:         public void inAfter(PStm node, Value value, Context ctxt)
131:         {
132:                 // Nothing
133:         }
134:
135:         @Override
136:         public void inBefore(PExp node, Context ctxt) throws AnalysisException
137:         {
138:                 printArgs(ctxt);
139:         }
140:
141:         @Override
142:         public void inAfter(PExp node, Value value, Context ctxt)
143:         {
144:                 // Nothing
145:         }
146:
147:         private void printArgs(Context ctxt) throws AnalysisException
148:         {
149:•                if (ast.getArgs().isEmpty())
150:                 {
151:                         Console.err.println("Trace: " + ast.getName().getLocation());
152:                 }
153:                 else
154:                 {
155:                         ExpressionEvaluator eval = new ExpressionEvaluator();
156:
157:•                        for (PExp arg: ast.getArgs())
158:                         {
159:                                 Value v = arg.apply(eval, ctxt);
160:                                 Console.err.println("Trace: " + ast.getName().getLocation() + ", " + arg + " = " + v);
161:                         }
162:                 }
163:         }
164: }