Package: QualificationVisitor

QualificationVisitor

nameinstructionbranchcomplexitylinemethod
QualificationVisitor()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAAndBooleanBinaryExp(AAndBooleanBinaryExp, TypeCheckInfo)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAIsExp(AIsExp, TypeCheckInfo)
M: 0 C: 75
100%
M: 4 C: 12
75%
M: 4 C: 5
56%
M: 0 C: 16
100%
M: 0 C: 1
100%
caseAPreOpExp(APreOpExp, TypeCheckInfo)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createNewReturnValue(INode, TypeCheckInfo)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createNewReturnValue(Object, TypeCheckInfo)
M: 4 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: * The VDM Type Checker
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.typechecker.visitor;
23:
24: import java.util.List;
25: import java.util.Vector;
26:
27: import org.overture.ast.analysis.AnalysisException;
28: import org.overture.ast.analysis.QuestionAnswerAdaptor;
29: import org.overture.ast.definitions.PDefinition;
30: import org.overture.ast.expressions.AAndBooleanBinaryExp;
31: import org.overture.ast.expressions.AIsExp;
32: import org.overture.ast.expressions.APreOpExp;
33: import org.overture.ast.expressions.AVariableExp;
34: import org.overture.ast.node.INode;
35: import org.overture.ast.typechecker.NameScope;
36: import org.overture.typechecker.TypeCheckInfo;
37: import org.overture.typechecker.utilities.type.QualifiedDefinition;
38:
39: /**
40: * Visitor to search for is_() expressions and return a list of definitions with qualified type information for the
41: * variable(s) concerned.
42: */
43: public class QualificationVisitor extends
44:                 QuestionAnswerAdaptor<TypeCheckInfo, List<QualifiedDefinition>>
45: {
46:         public List<QualifiedDefinition> caseAIsExp(AIsExp node,
47:                         TypeCheckInfo question) throws AnalysisException
48:         {
49:                 List<QualifiedDefinition> result = new Vector<QualifiedDefinition>();
50:
51:•                if (node.getTest() instanceof AVariableExp)
52:                 {
53:                         AVariableExp exp = (AVariableExp) node.getTest();
54:                         PDefinition existing = question.env.findName(exp.getName(), NameScope.NAMESANDSTATE);
55:
56:•                        if (existing != null
57:•                                        && existing.getNameScope().matches(NameScope.NAMES))
58:                         {
59:•                                if (node.getBasicType() != null)
60:                                 {
61:                                         result.add(new QualifiedDefinition(existing, node.getBasicType()));
62:•                                } else if (node.getTypeName() != null)
63:                                 {
64:•                                        if (node.getTypedef() == null)
65:                                         {
66:                                                 PDefinition typedef = question.env.findType(node.getTypeName(), node.getLocation().getModule());
67:                                                 
68:•                                                if (typedef != null)
69:                                                 {
70:                                                         node.setTypedef(typedef.clone());
71:                                                 }
72:                                         }
73:
74:•                                        if (node.getTypedef() != null)
75:                                         {
76:                                                 result.add(new QualifiedDefinition(existing, node.getTypedef().getType()));
77:                                         }
78:                                 }
79:                         }
80:                 }
81:
82:                 return result;
83:         }
84:
85:         public List<QualifiedDefinition> caseAPreOpExp(APreOpExp node,
86:                         TypeCheckInfo question) throws AnalysisException
87:         {
88:                 return node.getExpression().apply(THIS, question);
89:         }
90:
91:         public List<QualifiedDefinition> caseAAndBooleanBinaryExp(
92:                         AAndBooleanBinaryExp node, TypeCheckInfo question)
93:                         throws AnalysisException
94:         {
95:                 List<QualifiedDefinition> result = node.getLeft().apply(THIS, question);
96:                 result.addAll(node.getRight().apply(THIS, question));
97:                 return result;
98:         }
99:
100:         @Override
101:         public List<QualifiedDefinition> createNewReturnValue(INode node,
102:                         TypeCheckInfo question) throws AnalysisException
103:         {
104:                 return new Vector<QualifiedDefinition>();
105:         }
106:
107:         @Override
108:         public List<QualifiedDefinition> createNewReturnValue(Object node,
109:                         TypeCheckInfo question) throws AnalysisException
110:         {
111:                 return new Vector<QualifiedDefinition>();
112:         }
113: }