Package: AOperationTypeAssistantTC

AOperationTypeAssistantTC

nameinstructionbranchcomplexitylinemethod
AOperationTypeAssistantTC(ITypeCheckerAssistantFactory)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getPostType(AOperationType, AStateDefinition, SClassDefinition, boolean)
M: 0 C: 72
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
getPreType(AOperationType, AStateDefinition, SClassDefinition, boolean)
M: 0 C: 70
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 11
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.assistant.type;
23:
24: import java.util.Collection;
25: import java.util.LinkedList;
26: import java.util.List;
27:
28: import org.overture.ast.assistant.IAstAssistant;
29: import org.overture.ast.assistant.pattern.PTypeList;
30: import org.overture.ast.definitions.AStateDefinition;
31: import org.overture.ast.definitions.SClassDefinition;
32: import org.overture.ast.factory.AstFactory;
33: import org.overture.ast.types.AFunctionType;
34: import org.overture.ast.types.AMapMapType;
35: import org.overture.ast.types.AOperationType;
36: import org.overture.ast.types.AVoidType;
37: import org.overture.ast.types.PType;
38: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
39:
40: public class AOperationTypeAssistantTC implements IAstAssistant
41: {
42:         protected ITypeCheckerAssistantFactory af;
43:
44:         public AOperationTypeAssistantTC(ITypeCheckerAssistantFactory af)
45:         {
46:                 this.af = af;
47:         }
48:
49:         @SuppressWarnings("unchecked")
50:         public AFunctionType getPreType(AOperationType type,
51:                         AStateDefinition state, SClassDefinition classname, boolean isStatic)
52:         {
53:
54:•                if (state != null)
55:                 {
56:                         PTypeList params = new PTypeList();
57:                         params.addAll((LinkedList<PType>) type.getParameters().clone());
58:                         params.add(AstFactory.newAUnresolvedType(state.getName()));
59:                         return AstFactory.newAFunctionType(type.getLocation(), false, params, AstFactory.newABooleanBasicType(type.getLocation()));
60:•                } else if (classname != null && !isStatic)
61:                 {
62:                         PTypeList params = new PTypeList();
63:                         params.addAll((Collection<? extends PType>) type.getParameters().clone());
64:                         params.add(AstFactory.newAUnresolvedType(classname.getName()));
65:                         return AstFactory.newAFunctionType(type.getLocation(), false, params, AstFactory.newABooleanBasicType(type.getLocation()));
66:                 } else
67:                 {
68:                         return AstFactory.newAFunctionType(type.getLocation(), false, (List<PType>) type.getParameters().clone(), AstFactory.newABooleanBasicType(type.getLocation()));
69:                 }
70:         }
71:
72:         @SuppressWarnings("unchecked")
73:         public AFunctionType getPostType(AOperationType type,
74:                         AStateDefinition state, SClassDefinition classname, boolean isStatic)
75:         {
76:
77:                 PTypeList params = new PTypeList();
78:                 params.addAll((LinkedList<PType>) type.getParameters().clone());
79:
80:•                if (!(type.getResult() instanceof AVoidType))
81:                 {
82:                         params.add(type.getResult().clone());
83:                 }
84:
85:•                if (state != null)
86:                 {
87:                         params.add(AstFactory.newAUnresolvedType(state.getName()));
88:                         params.add(AstFactory.newAUnresolvedType(state.getName()));
89:•                } else if (classname != null)
90:                 {
91:                         AMapMapType map = AstFactory.newAMapMapType(type.getLocation(), AstFactory.newASeqSeqType(type.getLocation(), AstFactory.newACharBasicType(type.getLocation())), AstFactory.newAUnknownType(type.getLocation()));
92:                         params.add(map);
93:
94:•                        if (!isStatic)
95:                         {
96:                                 params.add(AstFactory.newAUnresolvedType(classname.getName()));
97:                         }
98:                 }
99:
100:                 return AstFactory.newAFunctionType(type.getLocation(), false, params, AstFactory.newABooleanBasicType(type.getLocation()));
101:         }
102:
103: }