| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #import('dart:uri'); | 5 #import('dart:uri'); |
| 6 | 6 |
| 7 #import("../../../lib/compiler/implementation/leg.dart"); | 7 #import("../../../lib/compiler/implementation/leg.dart"); |
| 8 #import("../../../lib/compiler/implementation/elements/elements.dart"); | 8 #import("../../../lib/compiler/implementation/elements/elements.dart"); |
| 9 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 9 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 10 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart"); | 10 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart"); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 compiler.errors[0].message); | 215 compiler.errors[0].message); |
| 216 } | 216 } |
| 217 | 217 |
| 218 | 218 |
| 219 testLocalsTwo() { | 219 testLocalsTwo() { |
| 220 MockCompiler compiler = new MockCompiler(); | 220 MockCompiler compiler = new MockCompiler(); |
| 221 ResolverVisitor visitor = compiler.resolverVisitor(); | 221 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 222 Node tree = parseStatement("if (true) { var a = 1; var b = 2; }"); | 222 Node tree = parseStatement("if (true) { var a = 1; var b = 2; }"); |
| 223 Element element = visitor.visit(tree); | 223 Element element = visitor.visit(tree); |
| 224 Expect.equals(null, element); | 224 Expect.equals(null, element); |
| 225 BlockScope scope = visitor.scope; | 225 MethodScope scope = visitor.scope; |
| 226 Expect.equals(0, scope.elements.length); | 226 Expect.equals(0, scope.elements.length); |
| 227 Expect.equals(2, map(visitor).length); | 227 Expect.equals(2, map(visitor).length); |
| 228 | 228 |
| 229 List<Element> elements = map(visitor).getValues(); | 229 List<Element> elements = map(visitor).getValues(); |
| 230 Expect.notEquals(elements[0], elements[1]); | 230 Expect.notEquals(elements[0], elements[1]); |
| 231 } | 231 } |
| 232 | 232 |
| 233 testLocalsThree() { | 233 testLocalsThree() { |
| 234 MockCompiler compiler = new MockCompiler(); | 234 MockCompiler compiler = new MockCompiler(); |
| 235 ResolverVisitor visitor = compiler.resolverVisitor(); | 235 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 236 Node tree = parseStatement("{ var a = 1; if (true) { a; } }"); | 236 Node tree = parseStatement("{ var a = 1; if (true) { a; } }"); |
| 237 Element element = visitor.visit(tree); | 237 Element element = visitor.visit(tree); |
| 238 Expect.equals(null, element); | 238 Expect.equals(null, element); |
| 239 BlockScope scope = visitor.scope; | 239 MethodScope scope = visitor.scope; |
| 240 Expect.equals(0, scope.elements.length); | 240 Expect.equals(0, scope.elements.length); |
| 241 Expect.equals(3, map(visitor).length); | 241 Expect.equals(3, map(visitor).length); |
| 242 List<Element> elements = map(visitor).getValues(); | 242 List<Element> elements = map(visitor).getValues(); |
| 243 Expect.equals(elements[0], elements[1]); | 243 Expect.equals(elements[0], elements[1]); |
| 244 } | 244 } |
| 245 | 245 |
| 246 testLocalsFour() { | 246 testLocalsFour() { |
| 247 MockCompiler compiler = new MockCompiler(); | 247 MockCompiler compiler = new MockCompiler(); |
| 248 ResolverVisitor visitor = compiler.resolverVisitor(); | 248 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 249 Node tree = parseStatement("{ var a = 1; if (true) { var a = 1; } }"); | 249 Node tree = parseStatement("{ var a = 1; if (true) { var a = 1; } }"); |
| 250 Element element = visitor.visit(tree); | 250 Element element = visitor.visit(tree); |
| 251 Expect.equals(null, element); | 251 Expect.equals(null, element); |
| 252 BlockScope scope = visitor.scope; | 252 MethodScope scope = visitor.scope; |
| 253 Expect.equals(0, scope.elements.length); | 253 Expect.equals(0, scope.elements.length); |
| 254 Expect.equals(2, map(visitor).length); | 254 Expect.equals(2, map(visitor).length); |
| 255 List<Element> elements = map(visitor).getValues(); | 255 List<Element> elements = map(visitor).getValues(); |
| 256 Expect.notEquals(elements[0], elements[1]); | 256 Expect.notEquals(elements[0], elements[1]); |
| 257 } | 257 } |
| 258 | 258 |
| 259 testLocalsFive() { | 259 testLocalsFive() { |
| 260 MockCompiler compiler = new MockCompiler(); | 260 MockCompiler compiler = new MockCompiler(); |
| 261 ResolverVisitor visitor = compiler.resolverVisitor(); | 261 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 262 If tree = parseStatement("if (true) { var a = 1; a; } else { var a = 2; a;}"); | 262 If tree = parseStatement("if (true) { var a = 1; a; } else { var a = 2; a;}"); |
| 263 Element element = visitor.visit(tree); | 263 Element element = visitor.visit(tree); |
| 264 Expect.equals(null, element); | 264 Expect.equals(null, element); |
| 265 BlockScope scope = visitor.scope; | 265 MethodScope scope = visitor.scope; |
| 266 Expect.equals(0, scope.elements.length); | 266 Expect.equals(0, scope.elements.length); |
| 267 Expect.equals(6, map(visitor).length); | 267 Expect.equals(6, map(visitor).length); |
| 268 | 268 |
| 269 Block thenPart = tree.thenPart; | 269 Block thenPart = tree.thenPart; |
| 270 List statements1 = thenPart.statements.nodes.toList(); | 270 List statements1 = thenPart.statements.nodes.toList(); |
| 271 Node def1 = statements1[0].definitions.nodes.head; | 271 Node def1 = statements1[0].definitions.nodes.head; |
| 272 Node id1 = statements1[1].expression; | 272 Node id1 = statements1[1].expression; |
| 273 Expect.equals(visitor.mapping[def1], visitor.mapping[id1]); | 273 Expect.equals(visitor.mapping[def1], visitor.mapping[id1]); |
| 274 | 274 |
| 275 Block elsePart = tree.elsePart; | 275 Block elsePart = tree.elsePart; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 301 Expect.equals(ElementKind.PARAMETER, visitor.mapping[use].kind); | 301 Expect.equals(ElementKind.PARAMETER, visitor.mapping[use].kind); |
| 302 Expect.equals(visitor.mapping[param], visitor.mapping[use]); | 302 Expect.equals(visitor.mapping[param], visitor.mapping[use]); |
| 303 } | 303 } |
| 304 | 304 |
| 305 testFor() { | 305 testFor() { |
| 306 MockCompiler compiler = new MockCompiler(); | 306 MockCompiler compiler = new MockCompiler(); |
| 307 ResolverVisitor visitor = compiler.resolverVisitor(); | 307 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 308 For tree = parseStatement("for (int i = 0; i < 10; i = i + 1) { i = 5; }"); | 308 For tree = parseStatement("for (int i = 0; i < 10; i = i + 1) { i = 5; }"); |
| 309 visitor.visit(tree); | 309 visitor.visit(tree); |
| 310 | 310 |
| 311 BlockScope scope = visitor.scope; | 311 MethodScope scope = visitor.scope; |
| 312 Expect.equals(0, scope.elements.length); | 312 Expect.equals(0, scope.elements.length); |
| 313 Expect.equals(10, map(visitor).length); | 313 Expect.equals(10, map(visitor).length); |
| 314 | 314 |
| 315 VariableDefinitions initializer = tree.initializer; | 315 VariableDefinitions initializer = tree.initializer; |
| 316 Node iNode = initializer.definitions.nodes.head; | 316 Node iNode = initializer.definitions.nodes.head; |
| 317 Element iElement = visitor.mapping[iNode]; | 317 Element iElement = visitor.mapping[iNode]; |
| 318 | 318 |
| 319 // Check that we have the expected nodes. This test relies on the mapping | 319 // Check that we have the expected nodes. This test relies on the mapping |
| 320 // field to be a linked hash map (preserving insertion order). | 320 // field to be a linked hash map (preserving insertion order). |
| 321 Expect.isTrue(map(visitor) is LinkedHashMap); | 321 Expect.isTrue(map(visitor) is LinkedHashMap); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 Expect.isNotNull(indexedOperator); | 764 Expect.isNotNull(indexedOperator); |
| 765 Expect.isNotNull( | 765 Expect.isNotNull( |
| 766 compiler.enqueuer.resolution.getCachedElements(indexedOperator)); | 766 compiler.enqueuer.resolution.getCachedElements(indexedOperator)); |
| 767 | 767 |
| 768 Element indexedSetOperator = findElement(compiler, 'C') | 768 Element indexedSetOperator = findElement(compiler, 'C') |
| 769 .lookupLocalMember(operatorName('[]=')); | 769 .lookupLocalMember(operatorName('[]=')); |
| 770 Expect.isNotNull(indexedOperator); | 770 Expect.isNotNull(indexedOperator); |
| 771 Expect.isNotNull( | 771 Expect.isNotNull( |
| 772 compiler.enqueuer.resolution.getCachedElements(indexedSetOperator)); | 772 compiler.enqueuer.resolution.getCachedElements(indexedSetOperator)); |
| 773 } | 773 } |
| OLD | NEW |