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

Side by Side Diff: tests/compiler/dart2js/resolver_test.dart

Issue 1149403009: Refactoring resolution of local access and unqualified access of statics (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix after rebase Created 5 years, 6 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
OLDNEW
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:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 7
8 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
9 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 import 'package:compiler/src/constants/expressions.dart'; 10 import 'package:compiler/src/constants/expressions.dart';
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 330 }
331 331
332 Future testLocalsThree() { 332 Future testLocalsThree() {
333 return MockCompiler.create((MockCompiler compiler) { 333 return MockCompiler.create((MockCompiler compiler) {
334 ResolverVisitor visitor = compiler.resolverVisitor(); 334 ResolverVisitor visitor = compiler.resolverVisitor();
335 Node tree = parseStatement("{ var a = 1; if (true) { a; } }"); 335 Node tree = parseStatement("{ var a = 1; if (true) { a; } }");
336 ResolutionResult result = visitor.visit(tree); 336 ResolutionResult result = visitor.visit(tree);
337 Expect.equals(const NoneResult(), result); 337 Expect.equals(const NoneResult(), result);
338 MethodScope scope = visitor.scope; 338 MethodScope scope = visitor.scope;
339 Expect.equals(0, scope.elements.length); 339 Expect.equals(0, scope.elements.length);
340 Expect.equals(3, map(visitor).length); 340 Expect.equals(2, map(visitor).length);
341 List<Element> elements = map(visitor).values.toList(); 341 List<Element> elements = map(visitor).values.toList();
342 Expect.equals(elements[0], elements[1]); 342 Expect.equals(elements[0], elements[1]);
343 }); 343 });
344 } 344 }
345 345
346 Future testLocalsFour() { 346 Future testLocalsFour() {
347 return MockCompiler.create((MockCompiler compiler) { 347 return MockCompiler.create((MockCompiler compiler) {
348 ResolverVisitor visitor = compiler.resolverVisitor(); 348 ResolverVisitor visitor = compiler.resolverVisitor();
349 Node tree = parseStatement("{ var a = 1; if (true) { var a = 1; } }"); 349 Node tree = parseStatement("{ var a = 1; if (true) { var a = 1; } }");
350 ResolutionResult result = visitor.visit(tree); 350 ResolutionResult result = visitor.visit(tree);
351 Expect.equals(const NoneResult(), result); 351 Expect.equals(const NoneResult(), result);
352 MethodScope scope = visitor.scope; 352 MethodScope scope = visitor.scope;
353 Expect.equals(0, scope.elements.length); 353 Expect.equals(0, scope.elements.length);
354 Expect.equals(2, map(visitor).length); 354 Expect.equals(2, map(visitor).length);
355 List<Element> elements = map(visitor).values.toList(); 355 List<Element> elements = map(visitor).values.toList();
356 Expect.notEquals(elements[0], elements[1]); 356 Expect.notEquals(elements[0], elements[1]);
357 }); 357 });
358 } 358 }
359 359
360 Future testLocalsFive() { 360 Future testLocalsFive() {
361 return MockCompiler.create((MockCompiler compiler) { 361 return MockCompiler.create((MockCompiler compiler) {
362 ResolverVisitor visitor = compiler.resolverVisitor(); 362 ResolverVisitor visitor = compiler.resolverVisitor();
363 If tree = 363 If tree =
364 parseStatement("if (true) { var a = 1; a; } else { var a = 2; a;}"); 364 parseStatement("if (true) { var a = 1; a; } else { var a = 2; a;}");
365 ResolutionResult result = visitor.visit(tree); 365 ResolutionResult result = visitor.visit(tree);
366 Expect.equals(const NoneResult(), result); 366 Expect.equals(const NoneResult(), result);
367 MethodScope scope = visitor.scope; 367 MethodScope scope = visitor.scope;
368 Expect.equals(0, scope.elements.length); 368 Expect.equals(0, scope.elements.length);
369 Expect.equals(6, map(visitor).length); 369 Expect.equals(4, map(visitor).length);
370 370
371 Block thenPart = tree.thenPart; 371 Block thenPart = tree.thenPart;
372 List statements1 = thenPart.statements.nodes.toList(); 372 List statements1 = thenPart.statements.nodes.toList();
373 Node def1 = statements1[0].definitions.nodes.head; 373 Node def1 = statements1[0].definitions.nodes.head;
374 Node id1 = statements1[1].expression; 374 Node id1 = statements1[1].expression;
375 Expect.equals(visitor.registry.mapping[def1], 375 Expect.equals(visitor.registry.mapping[def1],
376 visitor.registry.mapping[id1]); 376 visitor.registry.mapping[id1]);
377 377
378 Block elsePart = tree.elsePart; 378 Block elsePart = tree.elsePart;
379 List statements2 = elsePart.statements.nodes.toList(); 379 List statements2 = elsePart.statements.nodes.toList();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 412 }
413 413
414 Future testFor() { 414 Future testFor() {
415 return MockCompiler.create((MockCompiler compiler) { 415 return MockCompiler.create((MockCompiler compiler) {
416 ResolverVisitor visitor = compiler.resolverVisitor(); 416 ResolverVisitor visitor = compiler.resolverVisitor();
417 For tree = parseStatement("for (int i = 0; i < 10; i = i + 1) { i = 5; }"); 417 For tree = parseStatement("for (int i = 0; i < 10; i = i + 1) { i = 5; }");
418 visitor.visit(tree); 418 visitor.visit(tree);
419 419
420 MethodScope scope = visitor.scope; 420 MethodScope scope = visitor.scope;
421 Expect.equals(0, scope.elements.length); 421 Expect.equals(0, scope.elements.length);
422 Expect.equals(9, map(visitor).length); 422 Expect.equals(7, map(visitor).length);
423 423
424 VariableDefinitions initializer = tree.initializer; 424 VariableDefinitions initializer = tree.initializer;
425 Node iNode = initializer.definitions.nodes.head; 425 Node iNode = initializer.definitions.nodes.head;
426 Element iElement = visitor.registry.mapping[iNode]; 426 Element iElement = visitor.registry.mapping[iNode];
427 427
428 // Check that we have the expected nodes. This test relies on the mapping 428 // Check that we have the expected nodes. This test relies on the mapping
429 // field to be a linked hash map (preserving insertion order). 429 // field to be a linked hash map (preserving insertion order).
430 Expect.isTrue(map(visitor) is LinkedHashMap); 430 Expect.isTrue(map(visitor) is LinkedHashMap);
431 List<Node> nodes = map(visitor).keys.toList(); 431 List<Node> nodes = map(visitor).keys.toList();
432 List<Element> elements = map(visitor).values.toList(); 432 List<Element> elements = map(visitor).values.toList();
433 433
434 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 434 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
435 // ^^^^^ 435 // ^^^^^
436 checkSendSet(iElement, nodes[0], elements[0]); 436 checkSendSet(iElement, nodes[0], elements[0]);
437 437
438 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 438 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
439 // ^ 439 // ^
440 checkIdentifier(iElement, nodes[1], elements[1]); 440 checkSend(iElement, nodes[1], elements[1]);
441
442 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
443 // ^
444 checkSend(iElement, nodes[2], elements[2]);
445 441
446 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 442 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
447 // ^ 443 // ^
448 checkIdentifier(iElement, nodes[3], elements[3]); 444 checkIdentifier(iElement, nodes[2], elements[2]);
449 445
450 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 446 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
451 // ^ 447 // ^
452 checkIdentifier(iElement, nodes[4], elements[4]); 448 checkSend(iElement, nodes[3], elements[3]);
453
454 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
455 // ^
456 checkSend(iElement, nodes[5], elements[5]);
457 449
458 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 450 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
459 // ^^^^^^^^^ 451 // ^^^^^^^^^
460 checkSendSet(iElement, nodes[6], elements[6]); 452 checkSendSet(iElement, nodes[4], elements[4]);
461 453
462 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 454 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
463 // ^ 455 // ^
464 checkIdentifier(iElement, nodes[7], elements[7]); 456 checkIdentifier(iElement, nodes[5], elements[5]);
465 457
466 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 458 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
467 // ^^^^^ 459 // ^^^^^
468 checkSendSet(iElement, nodes[8], elements[8]); 460 checkSendSet(iElement, nodes[6], elements[6]);
469 }); 461 });
470 } 462 }
471 463
472 checkIdentifier(Element expected, Node node, Element actual) { 464 checkIdentifier(Element expected, Node node, Element actual) {
473 Expect.isTrue(node is Identifier, node.toDebugString()); 465 Expect.isTrue(node is Identifier, node.toDebugString());
474 Expect.equals(expected, actual); 466 Expect.equals(expected, actual);
475 } 467 }
476 468
477 checkSend(Element expected, Node node, Element actual) { 469 checkSend(Element expected, Node node, Element actual) {
478 Expect.isTrue(node is Send, node.toDebugString()); 470 Expect.isTrue(node is Send, node.toDebugString());
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 expectedWarnings: [], 912 expectedWarnings: [],
921 expectedErrors: [MessageKind.CANNOT_RESOLVE]); 913 expectedErrors: [MessageKind.CANNOT_RESOLVE]);
922 }, 914 },
923 () { 915 () {
924 String script = 916 String script =
925 """class A { 917 """class A {
926 int foo; 918 int foo;
927 int bar; 919 int bar;
928 A() : this.foo = bar; 920 A() : this.foo = bar;
929 }"""; 921 }""";
930 return resolveConstructor(script, "A a = new A();", "A", "", 3, 922 return resolveConstructor(script, "A a = new A();", "A", "", 2,
931 expectedWarnings: [], 923 expectedWarnings: [],
932 expectedErrors: [MessageKind.NO_INSTANCE_AVAILABLE]); 924 expectedErrors: [MessageKind.NO_INSTANCE_AVAILABLE]);
933 }, 925 },
934 () { 926 () {
935 String script = 927 String script =
936 """class A { 928 """class A {
937 int foo() => 42; 929 int foo() => 42;
938 A() : foo(); 930 A() : foo();
939 }"""; 931 }""";
940 return resolveConstructor(script, "A a = new A();", "A", "", 0, 932 return resolveConstructor(script, "A a = new A();", "A", "", 0,
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 } 1381 }
1390 main() => A.m(); 1382 main() => A.m();
1391 ''', functionName: 'm'); 1383 ''', functionName: 'm');
1392 check(''' 1384 check('''
1393 class A { 1385 class A {
1394 m() => () => await - 3; 1386 m() => () => await - 3;
1395 } 1387 }
1396 main() => new A().m(); 1388 main() => new A().m();
1397 ''', className: 'A'); 1389 ''', className: 'A');
1398 } 1390 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/diagnose_ambiguous_test.dart ('k') | tests/compiler/dart2js/semantic_visitor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698