Package: TypeCheckInfo

TypeCheckInfo

nameinstructionbranchcomplexitylinemethod
TypeCheckInfo()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
TypeCheckInfo(ITypeCheckerAssistantFactory, Environment)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
TypeCheckInfo(ITypeCheckerAssistantFactory, Environment, NameScope)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
TypeCheckInfo(ITypeCheckerAssistantFactory, Environment, NameScope, LinkedList)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
TypeCheckInfo(ITypeCheckerAssistantFactory, Environment, NameScope, LinkedList, PType, PType, String, boolean)
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
clearContext()
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%
contextGet(Class)
M: 19 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
contextRem(Class)
M: 19 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
contextSet(Class, Object)
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
lookupListForType(Class)
M: 30 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
newConstraint(PType)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
newInfo(Environment)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
newInfo(Environment, NameScope)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
newMandatory(boolean)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
newModule(String)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
newScope(List)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
newScope(List, NameScope)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
newScope(NameScope)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 15 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;
23:
24: import java.util.HashMap;
25: import java.util.LinkedList;
26: import java.util.List;
27: import java.util.Map;
28: import java.util.Stack;
29:
30: import org.overture.ast.definitions.PDefinition;
31: import org.overture.ast.typechecker.NameScope;
32: import org.overture.ast.types.PType;
33: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
34:
35: public class TypeCheckInfo
36: {
37:         public final ITypeCheckerAssistantFactory assistantFactory;
38:         /*
39:          * Added by RWL The Context allows us to resolve the following: (AnotherChecker,AnotherQuestion) ->
40:          * (OvertureChecker,OvertureQuestion) -> (AnotherChecker, OvertureQuestion) Now the AnotherChecker is aware that
41:          * only a OvertureQuestion is available here, however it may need its AnotherQuestion, right, to resolve that we
42:          * have this context: (AnotherChecker,AnotherQuestion) -> Create Overture Question with AnotherQuestion in its
43:          * context -> (OverutreChecker,OvertureQuestion) work as it should (AnotherChecker,OverTureQuestion) -> Get from the
44:          * context the earlier AnotherQuestion. Other things can be added to the context and it may be used for any purpose.
45:          * It is not used by Overture. (Remove this comment it is starts getting used by overture !)
46:          */
47:         private static final Map<Class<?>, Object> context = new HashMap<Class<?>, Object>();
48:
49:         public static void clearContext()
50:         {
51:                 context.clear();
52:         }
53:
54:         @SuppressWarnings("unchecked")
55:         private static <T> Stack<T> lookupListForType(Class<T> clz)
56:         {
57:                 Object o = context.get(clz);
58:•                if (o instanceof List<?>)
59:                 {
60:                         List<?> list = List.class.cast(o);
61:•                        if (list.size() > 0)
62:                         {
63:                                 Object first = list.get(0);
64:•                                if (first != null && clz.isInstance(first))
65:                                 {
66:                                         return (Stack<T>) list;
67:                                 }
68:                         }
69:                 }
70:                 return null;
71:         }
72:
73:         /**
74:          * Returns the value associated with key. Implementation detail: Notice the map is shared between all instances.
75:          *
76:          * @param <T>
77:          * @param key
78:          * @return
79:          */
80:         public <T> T contextGet(Class<T> key)
81:         {
82:                 synchronized (TypeCheckInfo.class)
83:                 {
84:                         Stack<T> contextStack = lookupListForType(key);
85:•                        if (contextStack != null)
86:                         {
87:                                 return contextStack.peek();
88:                         }
89:
90:                 }
91:                 return null;
92:         }
93:
94:         /**
95:          * Associates the given key with the given value.
96:          *
97:          * @param <T>
98:          * @param key
99:          * @param value
100:          */
101:         public <T> void contextSet(Class<T> key, T value)
102:         {
103:                 synchronized (TypeCheckInfo.class)
104:                 {
105:                         Stack<T> contextStack = lookupListForType(key);
106:•                        if (contextStack == null)
107:                         {
108:                                 contextStack = new Stack<T>();
109:                                 context.put(key, contextStack);
110:                         }
111:                         contextStack.push(value);
112:                 }
113:         }
114:
115:         /**
116:          * Returns the value associated with key, and removes that binding from the context.
117:          *
118:          * @param <T>
119:          * @param key
120:          * @return value
121:          */
122:         public <T> T contextRem(Class<T> key)
123:         {
124:                 synchronized (TypeCheckInfo.class)
125:                 {
126:                         Stack<T> contextStack = lookupListForType(key);
127:•                        if (contextStack != null)
128:                         {
129:                                 return contextStack.pop();
130:                         }
131:                 }
132:                 return null;
133:         }
134:
135:         public final Environment env;
136:         public NameScope scope;
137:         public LinkedList<PType> qualifiers;
138:         public final PType constraint; // expressions
139:         public final PType returnType; // statements
140:         public final boolean mandatory; // statements
141:         public final String fromModule;
142:
143:         public TypeCheckInfo(ITypeCheckerAssistantFactory assistantFactory,
144:                         Environment env, NameScope scope, LinkedList<PType> qualifiers,
145:                         PType constraint, PType returnType, String fromModule, boolean mandatory)
146:         {
147:                 this.assistantFactory = assistantFactory;
148:                 this.env = env;
149:                 this.scope = scope;
150:                 this.qualifiers = qualifiers;
151:                 this.constraint = constraint;
152:                 this.returnType = returnType;
153:                 this.fromModule = fromModule;
154:                 this.mandatory = mandatory;
155:         }
156:
157:         public TypeCheckInfo(ITypeCheckerAssistantFactory assistantFactory,
158:                         Environment env, NameScope scope, LinkedList<PType> qualifiers)
159:         {
160:                 this(assistantFactory, env, scope, qualifiers, null, null, null, false);
161:         }
162:
163:         public TypeCheckInfo(ITypeCheckerAssistantFactory assistantFactory,
164:                         Environment env, NameScope scope)
165:         {
166:                 this(assistantFactory, env, scope, null, null, null, null, false);
167:         }
168:
169:         public TypeCheckInfo(ITypeCheckerAssistantFactory assistantFactory,
170:                         Environment env)
171:         {
172:                 this(assistantFactory, env, null, null, null, null, null, false);
173:         }
174:
175:         public TypeCheckInfo()
176:         {
177:                 this(null, null, null, null, null, null, null, false);
178:         }
179:
180:         @Override
181:         public String toString()
182:         {
183:                 return "Scope: " + scope + "\n" + env;
184:         }
185:
186:         public TypeCheckInfo newConstraint(PType newConstraint)
187:         {
188:                 TypeCheckInfo info = new TypeCheckInfo(assistantFactory, env, scope, qualifiers, newConstraint, returnType, fromModule, mandatory);
189:                 return info;
190:         }
191:
192:         public TypeCheckInfo newScope(NameScope newScope)
193:         {
194:                 TypeCheckInfo info = new TypeCheckInfo(assistantFactory, env, newScope, qualifiers, constraint, returnType, fromModule, mandatory);
195:                 return info;
196:         }
197:
198:         public TypeCheckInfo newScope(List<PDefinition> definitions)
199:         {
200:                 return newScope(definitions, scope);
201:         }
202:
203:         public TypeCheckInfo newInfo(Environment newEnv)
204:         {
205:                 TypeCheckInfo info = new TypeCheckInfo(assistantFactory, newEnv, scope, qualifiers, constraint, returnType, fromModule, mandatory);
206:                 return info;
207:         }
208:
209:         public TypeCheckInfo newInfo(Environment newEnv, NameScope newScope)
210:         {
211:                 TypeCheckInfo info = new TypeCheckInfo(assistantFactory, newEnv, newScope, qualifiers, constraint, returnType, fromModule, mandatory);
212:                 return info;
213:         }
214:
215:         public TypeCheckInfo newScope(List<PDefinition> definitions,
216:                         NameScope newScope)
217:         {
218:                 Environment newEnv = new FlatCheckedEnvironment(assistantFactory, definitions, env, newScope);
219:                 TypeCheckInfo info = new TypeCheckInfo(assistantFactory, newEnv, newScope);
220:                 return info;
221:         }
222:
223:         public TypeCheckInfo newModule(String fromModule)
224:         {
225:                 TypeCheckInfo info = new TypeCheckInfo(assistantFactory, env, scope, qualifiers, constraint, returnType, fromModule, mandatory);
226:                 return info;
227:         }
228:
229:         public TypeCheckInfo newMandatory(boolean mandatory)
230:         {
231:                 TypeCheckInfo info = new TypeCheckInfo(assistantFactory, env, scope, qualifiers, constraint, returnType, fromModule, mandatory);
232:                 return info;
233:         }
234: }