Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java

Issue 8231031: Check for compile-time constants in DartCompiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Feedback from floitsch Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 package com.google.dart.compiler.resolver; 5 package com.google.dart.compiler.resolver;
6 6
7 import com.google.common.base.Joiner; 7 import com.google.common.base.Joiner;
8 import com.google.common.base.Splitter; 8 import com.google.common.base.Splitter;
9 import com.google.common.collect.Lists; 9 import com.google.common.collect.Lists;
10 import com.google.dart.compiler.DartCompilationError; 10 import com.google.dart.compiler.DartCompilationError;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 static class MockCoreTypeProvider implements CoreTypeProvider { 96 static class MockCoreTypeProvider implements CoreTypeProvider {
97 97
98 private final InterfaceType boolType; 98 private final InterfaceType boolType;
99 private final InterfaceType intType; 99 private final InterfaceType intType;
100 private final InterfaceType doubleType; 100 private final InterfaceType doubleType;
101 private final InterfaceType numType; 101 private final InterfaceType numType;
102 private final InterfaceType stringType; 102 private final InterfaceType stringType;
103 private final InterfaceType functionType; 103 private final InterfaceType functionType;
104 private final InterfaceType dynamicType; 104 private final InterfaceType dynamicType;
105 private final InterfaceType defaultMapType; 105 private final InterfaceType defaultMapLiteralType;
106 private final InterfaceType defaultArrayType; 106 private final InterfaceType defaultListType;
107 private final ClassElement objectElement; 107 private final ClassElement objectElement;
108 108
109 109
110 { 110 {
111 ClassElement dynamicElement = Elements.classNamed("Dynamic");
112 dynamicType = Types.interfaceType(dynamicElement, Collections.<Type>emptyL ist());
113 dynamicElement.setType(dynamicType);
114
111 ClassElement boolElement = Elements.classNamed("bool"); 115 ClassElement boolElement = Elements.classNamed("bool");
112 boolType = Types.interfaceType(boolElement, Collections.<Type>emptyList()) ; 116 boolType = Types.interfaceType(boolElement, Collections.<Type>emptyList()) ;
117 boolElement.setType(boolType);
118
113 ClassElement intElement = Elements.classNamed("int"); 119 ClassElement intElement = Elements.classNamed("int");
114 intType = Types.interfaceType(intElement, Collections.<Type>emptyList()); 120 intType = Types.interfaceType(intElement, Collections.<Type>emptyList());
121 intElement.setType(intType);
122
115 ClassElement doubleElement = Elements.classNamed("double"); 123 ClassElement doubleElement = Elements.classNamed("double");
116 doubleType = Types.interfaceType(doubleElement, Collections.<Type>emptyLis t()); 124 doubleType = Types.interfaceType(doubleElement, Collections.<Type>emptyLis t());
125 doubleElement.setType(doubleType);
126
117 ClassElement numElement = Elements.classNamed("num"); 127 ClassElement numElement = Elements.classNamed("num");
118 numType = Types.interfaceType(numElement, Collections.<Type>emptyList()); 128 numType = Types.interfaceType(numElement, Collections.<Type>emptyList());
129 numElement.setType(numType);
130
119 ClassElement stringElement = Elements.classNamed("String"); 131 ClassElement stringElement = Elements.classNamed("String");
120 stringType = Types.interfaceType(stringElement, Collections.<Type>emptyLis t()); 132 stringType = Types.interfaceType(stringElement, Collections.<Type>emptyLis t());
121 intElement.setType(intType); 133 intElement.setType(intType);
134
122 ClassElement functionElement = Elements.classNamed("Function"); 135 ClassElement functionElement = Elements.classNamed("Function");
123 functionType = Types.interfaceType(functionElement, Collections.<Type>empt yList()); 136 functionType = Types.interfaceType(functionElement, Collections.<Type>empt yList());
124 ClassElement dynamicElement = Elements.classNamed("Dynamic"); 137 functionElement.setType(functionType);
125 dynamicType = Types.interfaceType(dynamicElement, Collections.<Type>emptyL ist()); 138
126 ClassElement mapElement = Elements.classNamed("Map"); 139 ClassElement mapElement = Elements.classNamed("Map");
127 defaultMapType = Types.interfaceType(mapElement, Lists.newArrayList(string Type, dynamicType)); 140 defaultMapLiteralType = Types.interfaceType(mapElement, Lists.newArrayList (stringType, dynamicType));
141 mapElement.setType(defaultMapLiteralType);
142
128 ClassElement listElement = Elements.classNamed("List"); 143 ClassElement listElement = Elements.classNamed("List");
129 defaultArrayType = Types.interfaceType(listElement, Lists.newArrayList(dyn amicType)); 144 defaultListType = Types.interfaceType(listElement, Lists.newArrayList(dyna micType));
130 functionElement.setType(functionType); 145 listElement.setType(defaultListType);
131 } 146 }
132 147
133 MockCoreTypeProvider(ClassElement objectElement) { 148 MockCoreTypeProvider(ClassElement objectElement) {
134 this.objectElement = objectElement; 149 this.objectElement = objectElement;
135 } 150 }
136 151
137 @Override 152 @Override
138 public InterfaceType getIntType() { 153 public InterfaceType getIntType() {
139 return intType; 154 return intType;
140 } 155 }
(...skipping 18 matching lines...) Expand all
159 return stringType; 174 return stringType;
160 } 175 }
161 176
162 @Override 177 @Override
163 public InterfaceType getFunctionType() { 178 public InterfaceType getFunctionType() {
164 return functionType; 179 return functionType;
165 } 180 }
166 181
167 @Override 182 @Override
168 public InterfaceType getArrayType(Type elementType) { 183 public InterfaceType getArrayType(Type elementType) {
169 return defaultArrayType; 184 return defaultListType;
170 } 185 }
171 186
172 @Override 187 @Override
173 public Type getNullType() { 188 public Type getNullType() {
174 throw new AssertionError(); 189 throw new AssertionError();
175 } 190 }
176 191
177 @Override 192 @Override
178 public Type getVoidType() { 193 public Type getVoidType() {
179 throw new AssertionError(); 194 throw new AssertionError();
180 } 195 }
181 196
182 @Override 197 @Override
183 public DynamicType getDynamicType() { 198 public DynamicType getDynamicType() {
184 return Types.newDynamicType(); 199 return Types.newDynamicType();
185 } 200 }
186 201
187 @Override 202 @Override
188 public InterfaceType getFallThroughError() { 203 public InterfaceType getFallThroughError() {
189 throw new AssertionError(); 204 throw new AssertionError();
190 } 205 }
191 206
192 @Override 207 @Override
193 public InterfaceType getMapType(Type key, Type value) { 208 public InterfaceType getMapType(Type key, Type value) {
194 return defaultMapType; 209 return defaultMapLiteralType;
195 } 210 }
196 211
197 @Override 212 @Override
198 public InterfaceType getObjectArrayType() { 213 public InterfaceType getObjectArrayType() {
199 throw new AssertionError(); 214 throw new AssertionError();
200 } 215 }
201 216
202 @Override 217 @Override
203 public InterfaceType getObjectType() { 218 public InterfaceType getObjectType() {
204 return objectElement.getType(); 219 return objectElement.getType();
205 } 220 }
206 221
207 @Override 222 @Override
208 public InterfaceType getArrayLiteralType(Type value) { 223 public InterfaceType getArrayLiteralType(Type value) {
209 return defaultArrayType; 224 return defaultListType;
210 } 225 }
211 226
212 @Override 227 @Override
213 public InterfaceType getMapLiteralType(Type key, Type value) { 228 public InterfaceType getMapLiteralType(Type key, Type value) {
214 return defaultMapType; 229 return defaultMapLiteralType;
215 } 230 }
216 231
217 @Override 232 @Override
218 public InterfaceType getStringImplementationType() { 233 public InterfaceType getStringImplementationType() {
219 throw new AssertionError(); 234 throw new AssertionError();
220 } 235 }
221 236
222 @Override 237 @Override
223 public InterfaceType getIsolateType() { 238 public InterfaceType getIsolateType() {
224 throw new AssertionError(); 239 throw new AssertionError();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 TestCompilerContext ctx = new TestCompilerContext() { 384 TestCompilerContext ctx = new TestCompilerContext() {
370 @Override 385 @Override
371 public void compilationError(DartCompilationError event) { 386 public void compilationError(DartCompilationError event) {
372 encountered.add(event); 387 encountered.add(event);
373 } 388 }
374 }; 389 };
375 DartUnit unit = parseUnit(source); 390 DartUnit unit = parseUnit(source);
376 if (encounteredErrors.size() != 0) { 391 if (encounteredErrors.size() != 0) {
377 printSource(source); 392 printSource(source);
378 printEncountered(encounteredErrors); 393 printEncountered(encounteredErrors);
379 assertEquals("Expected no errors in parse step:", 0, encountered.size()); 394 assertEquals("Expected no errors in parse step:", 0, encounteredErrors.siz e());
380 } 395 }
381 resolve(unit, ctx); 396 resolve(unit, ctx);
382 checkExpectedErrors(encountered, errorCodes, source); 397 checkExpectedErrors(encountered, errorCodes, source);
383 } 398 }
384 } 399 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698