Package: AImplicitOperationDefinitionAssistantTC

AImplicitOperationDefinitionAssistantTC

nameinstructionbranchcomplexitylinemethod
AImplicitOperationDefinitionAssistantTC(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%
getListParamPatternList(AImplicitOperationDefinition)
M: 31 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getParamPatternList(AImplicitOperationDefinition)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getPostDefinition(AImplicitOperationDefinition, Environment)
M: 0 C: 145
100%
M: 0 C: 10
100%
M: 0 C: 6
100%
M: 0 C: 21
100%
M: 0 C: 1
100%
getPreDefinition(AImplicitOperationDefinition, Environment)
M: 0 C: 118
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 17
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.definition;
23:
24: import java.util.ArrayList;
25: import java.util.Collection;
26: import java.util.LinkedList;
27: import java.util.List;
28: import java.util.Vector;
29:
30: import org.overture.ast.assistant.IAstAssistant;
31: import org.overture.ast.definitions.AExplicitFunctionDefinition;
32: import org.overture.ast.definitions.AImplicitOperationDefinition;
33: import org.overture.ast.definitions.AStateDefinition;
34: import org.overture.ast.expressions.PExp;
35: import org.overture.ast.factory.AstFactory;
36: import org.overture.ast.patterns.APatternListTypePair;
37: import org.overture.ast.patterns.PPattern;
38: import org.overture.ast.typechecker.NameScope;
39: import org.overture.ast.types.AOperationType;
40: import org.overture.typechecker.Environment;
41: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
42:
43: public class AImplicitOperationDefinitionAssistantTC implements IAstAssistant
44: {
45:         protected ITypeCheckerAssistantFactory af;
46:
47:         public AImplicitOperationDefinitionAssistantTC(
48:                         ITypeCheckerAssistantFactory af)
49:         {
50:                 this.af = af;
51:         }
52:
53:         @SuppressWarnings("unchecked")
54:         public AExplicitFunctionDefinition getPostDefinition(
55:                         AImplicitOperationDefinition d, Environment base)
56:         {
57:
58:                 List<List<PPattern>> parameters = new Vector<List<PPattern>>();
59:                 List<PPattern> plist = new Vector<PPattern>();
60:
61:•                for (APatternListTypePair pl : (LinkedList<APatternListTypePair>) d.getParameterPatterns())
62:                 {
63:                         plist.addAll((Collection<PPattern>) pl.getPatterns().clone());
64:                 }
65:
66:•                if (d.getResult() != null)
67:                 {
68:                         plist.add(d.getResult().getPattern().clone());
69:                 }
70:
71:                 AStateDefinition state = d.getState();
72:
73:•                if (state != null)
74:                 {
75:                         plist.add(AstFactory.newAIdentifierPattern(state.getName().getOldName()));
76:                         plist.add(AstFactory.newAIdentifierPattern(state.getName().clone()));
77:•                } else if (base.isVDMPP())
78:                 {
79:                         plist.add(AstFactory.newAIdentifierPattern(d.getName().getSelfName().getOldName()));
80:
81:•                        if (!af.createPAccessSpecifierAssistant().isStatic(d.getAccess()))
82:                         {
83:                                 plist.add(AstFactory.newAIdentifierPattern(d.getName().getSelfName()));
84:                         }
85:                 }
86:
87:                 parameters.add(plist);
88:                 PExp postop = AstFactory.newAPostOpExp(d.getName().clone(), d.getPrecondition(), d.getPostcondition(), d.getErrors(), d.getState());
89:
90:                 AExplicitFunctionDefinition def = AstFactory.newAExplicitFunctionDefinition(d.getName().getPostName(d.getPostcondition().getLocation()), NameScope.GLOBAL, null, af.createAOperationTypeAssistant().getPostType((AOperationType) d.getType(), state, d.getClassDefinition(), af.createPAccessSpecifierAssistant().isStatic(d.getAccess())), parameters, postop, null, null, false, null);
91:
92:                 // Operation postcondition functions are effectively not static as
93:                 // their expression can directly refer to instance variables, even
94:                 // though at runtime these are passed via a "self" parameter.
95:
96:                 def.setAccess(af.createPAccessSpecifierAssistant().getStatic(d, false));
97:                 def.setClassDefinition(d.getClassDefinition());
98:                 return def;
99:         }
100:
101:         @SuppressWarnings("unchecked")
102:         public AExplicitFunctionDefinition getPreDefinition(
103:                         AImplicitOperationDefinition d, Environment base)
104:         {
105:
106:                 List<List<PPattern>> parameters = new Vector<List<PPattern>>();
107:                 List<PPattern> plist = new Vector<PPattern>();
108:
109:•                for (APatternListTypePair pl : (LinkedList<APatternListTypePair>) d.getParameterPatterns())
110:                 {
111:                         plist.addAll((Collection<PPattern>) pl.getPatterns().clone());
112:                 }
113:
114:                 AStateDefinition state = d.getState();
115:
116:•                if (state != null)
117:                 {
118:                         plist.add(AstFactory.newAIdentifierPattern(state.getName().clone()));
119:•                } else if (base.isVDMPP()
120:•                                && !af.createPAccessSpecifierAssistant().isStatic(d.getAccess()))
121:                 {
122:                         plist.add(AstFactory.newAIdentifierPattern(d.getName().getSelfName()));
123:                 }
124:
125:                 parameters.add(plist);
126:                 PExp preop = AstFactory.newAPreOpExp(d.getName().clone(), d.getPrecondition(), d.getErrors(), d.getState());
127:
128:                 AExplicitFunctionDefinition def = AstFactory.newAExplicitFunctionDefinition(d.getName().getPreName(d.getPrecondition().getLocation()), NameScope.GLOBAL, null, af.createAOperationTypeAssistant().getPreType((AOperationType) d.getType(), state, d.getClassDefinition(), af.createPAccessSpecifierAssistant().isStatic(d.getAccess())), parameters, preop, null, null, false, null);
129:
130:                 // Operation precondition functions are effectively not static as
131:                 // their expression can directly refer to instance variables, even
132:                 // though at runtime these are passed via a "self" parameter.
133:
134:                 def.setAccess(af.createPAccessSpecifierAssistant().getStatic(d, false));
135:                 def.setClassDefinition(d.getClassDefinition());
136:                 return def;
137:         }
138:
139:         public List<PPattern> getParamPatternList(
140:                         AImplicitOperationDefinition definition)
141:         {
142:                 List<PPattern> plist = new ArrayList<PPattern>();
143:
144:•                for (APatternListTypePair pl : definition.getParameterPatterns())
145:                 {
146:                         plist.addAll(pl.getPatterns());
147:                 }
148:
149:                 return plist;
150:         }
151:
152:         public List<List<PPattern>> getListParamPatternList(
153:                         AImplicitOperationDefinition func)
154:         {
155:                 List<List<PPattern>> parameters = new ArrayList<List<PPattern>>();
156:                 List<PPattern> plist = new ArrayList<PPattern>();
157:
158:•                for (APatternListTypePair pl : func.getParameterPatterns())
159:                 {
160:                         plist.addAll(pl.getPatterns());
161:                 }
162:
163:                 parameters.add(plist);
164:                 return parameters;
165:         }
166:
167: }