| 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 "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart" | 7 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart" |
| 8 hide TreeElementMapping, TreeElements, SourceString; | 8 hide TreeElementMapping, TreeElements, SourceString; |
| 9 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; | 9 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; |
| 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; | 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 compiler.resolveStatement("Foo foo;"); | 167 compiler.resolveStatement("Foo foo;"); |
| 168 ClassElement fooElement = compiler.mainApp.find(buildSourceString("Foo")); | 168 ClassElement fooElement = compiler.mainApp.find(buildSourceString("Foo")); |
| 169 FunctionElement funElement = | 169 FunctionElement funElement = |
| 170 fooElement.lookupLocalMember(buildSourceString("foo")); | 170 fooElement.lookupLocalMember(buildSourceString("foo")); |
| 171 ResolverVisitor visitor = | 171 ResolverVisitor visitor = |
| 172 new ResolverVisitor(compiler, funElement, | 172 new ResolverVisitor(compiler, funElement, |
| 173 new CollectingTreeElements(funElement)); | 173 new CollectingTreeElements(funElement)); |
| 174 FunctionExpression function = funElement.parseNode(compiler); | 174 FunctionExpression function = funElement.parseNode(compiler); |
| 175 visitor.visit(function.body); | 175 visitor.visit(function.body); |
| 176 Map mapping = map(visitor); | 176 Map mapping = map(visitor); |
| 177 List<Element> values = mapping.values; | 177 List<Element> values = mapping.values.toList(); |
| 178 Expect.equals(0, mapping.length); | 178 Expect.equals(0, mapping.length); |
| 179 Expect.equals(0, compiler.warnings.length); | 179 Expect.equals(0, compiler.warnings.length); |
| 180 | 180 |
| 181 compiler = new MockCompiler(); | 181 compiler = new MockCompiler(); |
| 182 compiler.resolveStatement("main() { return this; }"); | 182 compiler.resolveStatement("main() { return this; }"); |
| 183 Expect.equals(0, compiler.warnings.length); | 183 Expect.equals(0, compiler.warnings.length); |
| 184 Expect.equals(1, compiler.errors.length); | 184 Expect.equals(1, compiler.errors.length); |
| 185 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, | 185 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, |
| 186 compiler.errors[0].message.kind); | 186 compiler.errors[0].message.kind); |
| 187 | 187 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 testLocalsThree() { | 239 testLocalsThree() { |
| 240 MockCompiler compiler = new MockCompiler(); | 240 MockCompiler compiler = new MockCompiler(); |
| 241 ResolverVisitor visitor = compiler.resolverVisitor(); | 241 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 242 Node tree = parseStatement("{ var a = 1; if (true) { a; } }"); | 242 Node tree = parseStatement("{ var a = 1; if (true) { a; } }"); |
| 243 Element element = visitor.visit(tree); | 243 Element element = visitor.visit(tree); |
| 244 Expect.equals(null, element); | 244 Expect.equals(null, element); |
| 245 MethodScope scope = visitor.scope; | 245 MethodScope scope = visitor.scope; |
| 246 Expect.equals(0, scope.elements.length); | 246 Expect.equals(0, scope.elements.length); |
| 247 Expect.equals(3, map(visitor).length); | 247 Expect.equals(3, map(visitor).length); |
| 248 List<Element> elements = map(visitor).values; | 248 List<Element> elements = map(visitor).values.toList(); |
| 249 Expect.equals(elements[0], elements[1]); | 249 Expect.equals(elements[0], elements[1]); |
| 250 } | 250 } |
| 251 | 251 |
| 252 testLocalsFour() { | 252 testLocalsFour() { |
| 253 MockCompiler compiler = new MockCompiler(); | 253 MockCompiler compiler = new MockCompiler(); |
| 254 ResolverVisitor visitor = compiler.resolverVisitor(); | 254 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 255 Node tree = parseStatement("{ var a = 1; if (true) { var a = 1; } }"); | 255 Node tree = parseStatement("{ var a = 1; if (true) { var a = 1; } }"); |
| 256 Element element = visitor.visit(tree); | 256 Element element = visitor.visit(tree); |
| 257 Expect.equals(null, element); | 257 Expect.equals(null, element); |
| 258 MethodScope scope = visitor.scope; | 258 MethodScope scope = visitor.scope; |
| 259 Expect.equals(0, scope.elements.length); | 259 Expect.equals(0, scope.elements.length); |
| 260 Expect.equals(2, map(visitor).length); | 260 Expect.equals(2, map(visitor).length); |
| 261 List<Element> elements = map(visitor).values; | 261 List<Element> elements = map(visitor).values.toList(); |
| 262 Expect.notEquals(elements[0], elements[1]); | 262 Expect.notEquals(elements[0], elements[1]); |
| 263 } | 263 } |
| 264 | 264 |
| 265 testLocalsFive() { | 265 testLocalsFive() { |
| 266 MockCompiler compiler = new MockCompiler(); | 266 MockCompiler compiler = new MockCompiler(); |
| 267 ResolverVisitor visitor = compiler.resolverVisitor(); | 267 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 268 If tree = parseStatement("if (true) { var a = 1; a; } else { var a = 2; a;}"); | 268 If tree = parseStatement("if (true) { var a = 1; a; } else { var a = 2; a;}"); |
| 269 Element element = visitor.visit(tree); | 269 Element element = visitor.visit(tree); |
| 270 Expect.equals(null, element); | 270 Expect.equals(null, element); |
| 271 MethodScope scope = visitor.scope; | 271 MethodScope scope = visitor.scope; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 Expect.equals(0, scope.elements.length); | 318 Expect.equals(0, scope.elements.length); |
| 319 Expect.equals(10, map(visitor).length); | 319 Expect.equals(10, map(visitor).length); |
| 320 | 320 |
| 321 VariableDefinitions initializer = tree.initializer; | 321 VariableDefinitions initializer = tree.initializer; |
| 322 Node iNode = initializer.definitions.nodes.head; | 322 Node iNode = initializer.definitions.nodes.head; |
| 323 Element iElement = visitor.mapping[iNode]; | 323 Element iElement = visitor.mapping[iNode]; |
| 324 | 324 |
| 325 // Check that we have the expected nodes. This test relies on the mapping | 325 // Check that we have the expected nodes. This test relies on the mapping |
| 326 // field to be a linked hash map (preserving insertion order). | 326 // field to be a linked hash map (preserving insertion order). |
| 327 Expect.isTrue(map(visitor) is LinkedHashMap); | 327 Expect.isTrue(map(visitor) is LinkedHashMap); |
| 328 List<Node> nodes = map(visitor).keys; | 328 List<Node> nodes = map(visitor).keys.toList(); |
| 329 List<Element> elements = map(visitor).values; | 329 List<Element> elements = map(visitor).values.toList(); |
| 330 | 330 |
| 331 | 331 |
| 332 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; | 332 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; |
| 333 // ^^^ | 333 // ^^^ |
| 334 Expect.isTrue(nodes[0] is TypeAnnotation); | 334 Expect.isTrue(nodes[0] is TypeAnnotation); |
| 335 | 335 |
| 336 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; | 336 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; |
| 337 // ^^^^^ | 337 // ^^^^^ |
| 338 checkSendSet(iElement, nodes[1], elements[1]); | 338 checkSendSet(iElement, nodes[1], elements[1]); |
| 339 | 339 |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 var d = new D(); | 838 var d = new D(); |
| 839 --d; | 839 --d; |
| 840 }"""; | 840 }"""; |
| 841 final compiler = compileScript(script); | 841 final compiler = compileScript(script); |
| 842 | 842 |
| 843 checkMemberResolved(compiler, 'A', operatorName('+', false)); | 843 checkMemberResolved(compiler, 'A', operatorName('+', false)); |
| 844 checkMemberResolved(compiler, 'B', operatorName('+', false)); | 844 checkMemberResolved(compiler, 'B', operatorName('+', false)); |
| 845 checkMemberResolved(compiler, 'C', operatorName('-', false)); | 845 checkMemberResolved(compiler, 'C', operatorName('-', false)); |
| 846 checkMemberResolved(compiler, 'D', operatorName('-', false)); | 846 checkMemberResolved(compiler, 'D', operatorName('-', false)); |
| 847 } | 847 } |
| OLD | NEW |