Package: PTypeFunctionChecker

PTypeFunctionChecker

nameinstructionbranchcomplexitylinemethod
PTypeFunctionChecker(ITypeCheckerAssistantFactory, String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
caseABracketType(ABracketType)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAFunctionType(AFunctionType)
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%
caseAOptionalType(AOptionalType)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAUnionType(AUnionType)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAUnknownType(AUnknownType)
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%
createNewReturnValue(INode)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(Object)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
defaultPType(PType)
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%
defaultSInvariantType(SInvariantType)
M: 3 C: 19
86%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 4
100%
M: 0 C: 1
100%
static {...}
M: 2 C: 6
75%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%

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.utilities;
23:
24: import org.overture.ast.analysis.AnalysisException;
25: import org.overture.ast.analysis.AnswerAdaptor;
26: import org.overture.ast.node.INode;
27: import org.overture.ast.types.ABracketType;
28: import org.overture.ast.types.AFunctionType;
29: import org.overture.ast.types.ANamedInvariantType;
30: import org.overture.ast.types.AOptionalType;
31: import org.overture.ast.types.AUnionType;
32: import org.overture.ast.types.AUnknownType;
33: import org.overture.ast.types.PType;
34: import org.overture.ast.types.SInvariantType;
35: import org.overture.typechecker.TypeChecker;
36: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
37:
38: /**
39: * This class implements a way to check if a node is a function.
40: *
41: * @author kel
42: */
43:•public class PTypeFunctionChecker extends AnswerAdaptor<Boolean>
44: {
45:         protected final ITypeCheckerAssistantFactory af;
46:         protected final String fromModule;
47:
48:         public PTypeFunctionChecker(ITypeCheckerAssistantFactory af, String fromModule)
49:         {
50:                 this.af = af;
51:                 this.fromModule = fromModule;
52:         }
53:
54:         @Override
55:         public Boolean caseABracketType(ABracketType node) throws AnalysisException
56:         {
57:                 return node.getType().apply(THIS);
58:         }
59:
60:         @Override
61:         public Boolean caseAFunctionType(AFunctionType node)
62:                         throws AnalysisException
63:         {
64:                 return true;
65:         }
66:
67:         @Override
68:         public Boolean defaultSInvariantType(SInvariantType node)
69:                         throws AnalysisException
70:         {
71:•                if (node instanceof ANamedInvariantType)
72:                 {
73:•                        if (TypeChecker.isOpaque(node, fromModule)) return false;
74:                         return ((ANamedInvariantType) node).getType().apply(THIS);
75:                 }
76:                 else
77:                 {
78:                         return false;
79:                 }
80:         }
81:
82:         @Override
83:         public Boolean caseAOptionalType(AOptionalType node)
84:                         throws AnalysisException
85:         {
86:                 return node.getType().apply(THIS);
87:         }
88:
89:         @Override
90:         public Boolean caseAUnionType(AUnionType node) throws AnalysisException
91:         {
92:
93:                 // return af.createAUnionTypeAssistant().getFunction(node) != null;
94:•                return node.apply(af.getFunctionTypeFinder()) != null;
95:         }
96:
97:         @Override
98:         public Boolean caseAUnknownType(AUnknownType node) throws AnalysisException
99:         {
100:
101:                 return true;
102:         }
103:
104:         @Override
105:         public Boolean defaultPType(PType node) throws AnalysisException
106:         {
107:                 return false;
108:         }
109:
110:         @Override
111:         public Boolean createNewReturnValue(INode node)
112:         {
113:•                assert false : "should not happen";
114:                 return null;
115:         }
116:
117:         @Override
118:         public Boolean createNewReturnValue(Object node)
119:         {
120:•                assert false : "should not happen";
121:                 return null;
122:         }
123: }