Package: GhostAnnotation

GhostAnnotation

nameinstructionbranchcomplexitylinemethod
GhostAnnotation()
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%
parse(LexTokenReader)
M: 60 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 15 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.examples;
12:
13: import java.util.List;
14: import java.util.Vector;
15:
16: import org.overture.ast.expressions.AEqualsBinaryExp;
17: import org.overture.ast.expressions.AVariableExp;
18: import org.overture.ast.expressions.PExp;
19: import org.overture.ast.lex.VDMToken;
20: import org.overture.parser.annotations.ASTAnnotationAdapter;
21: import org.overture.parser.lex.LexException;
22: import org.overture.parser.lex.LexTokenReader;
23: import org.overture.parser.syntax.ExpressionReader;
24: import org.overture.parser.syntax.ParserException;
25:
26: /**
27: * A test of an annotation with an overridden parse function.
28: */
29: public class GhostAnnotation extends ASTAnnotationAdapter
30: {
31:         public GhostAnnotation()
32:         {
33:                 super();
34:         }
35:
36:         
37:         public boolean typecheckArgs()
38:         {
39:                 return false;                // Ghosts must be new variables and so non-existent anyway
40:         }
41:
42:         /**
43:          * Override the default parse, and look for {@literal}Ghost NAME = EXP;
44:          */
45:         @Override
46:         public List<PExp> parse(LexTokenReader ltr) throws LexException, ParserException
47:         {
48:                 ltr.nextToken();
49:                 List<PExp> args = new Vector<PExp>();
50:                 ExpressionReader er = new ExpressionReader(ltr);
51:                 PExp exp = er.readExpression();
52:                 
53:•                if (exp instanceof AEqualsBinaryExp)                // Should parse as an equals expression
54:                 {
55:                         AEqualsBinaryExp eqexp = (AEqualsBinaryExp)exp;
56:                         
57:•                        if (eqexp.getLeft() instanceof AVariableExp)
58:                         {
59:                                 args.add(eqexp.getLeft());
60:                                 args.add(eqexp.getRight());
61:                         }
62:                         else
63:                         {
64:                                 parseException("expecting <name> = <exp>", eqexp.getLocation());
65:                         }
66:                 }
67:                 else
68:                 {
69:                         parseException("expecting <name> = <exp>", exp.getLocation());
70:                 }
71:                 
72:•                if (ltr.getLast().isNot(VDMToken.SEMICOLON))
73:                 {
74:                         parseException("missing ;", ltr.getLast().getLocation());
75:                 }
76:                 
77:                 return args;
78:         }
79: }