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

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

Issue 1303503002: Refactor updates of locals. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 419 }
420 420
421 Future testFor() { 421 Future testFor() {
422 return MockCompiler.create((MockCompiler compiler) { 422 return MockCompiler.create((MockCompiler compiler) {
423 ResolverVisitor visitor = compiler.resolverVisitor(); 423 ResolverVisitor visitor = compiler.resolverVisitor();
424 For tree = parseStatement("for (int i = 0; i < 10; i = i + 1) { i = 5; }"); 424 For tree = parseStatement("for (int i = 0; i < 10; i = i + 1) { i = 5; }");
425 visitor.visit(tree); 425 visitor.visit(tree);
426 426
427 MethodScope scope = visitor.scope; 427 MethodScope scope = visitor.scope;
428 Expect.equals(0, scope.elements.length); 428 Expect.equals(0, scope.elements.length);
429 Expect.equals(7, map(visitor).length); 429 Expect.equals(5, map(visitor).length);
430 430
431 VariableDefinitions initializer = tree.initializer; 431 VariableDefinitions initializer = tree.initializer;
432 Node iNode = initializer.definitions.nodes.head; 432 Node iNode = initializer.definitions.nodes.head;
433 Element iElement = visitor.registry.mapping[iNode]; 433 Element iElement = visitor.registry.mapping[iNode];
434 434
435 // Check that we have the expected nodes. This test relies on the mapping 435 // Check that we have the expected nodes. This test relies on the mapping
436 // field to be a linked hash map (preserving insertion order). 436 // field to be a linked hash map (preserving insertion order).
437 Expect.isTrue(map(visitor) is LinkedHashMap); 437 Expect.isTrue(map(visitor) is LinkedHashMap);
438 List<Node> nodes = map(visitor).keys.toList(); 438 List<Node> nodes = map(visitor).keys.toList();
439 List<Element> elements = map(visitor).values.toList(); 439 List<Element> elements = map(visitor).values.toList();
440 440
441 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 441 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
442 // ^^^^^ 442 // ^^^^^
443 checkSendSet(iElement, nodes[0], elements[0]); 443 checkSendSet(iElement, nodes[0], elements[0]);
444 444
445 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 445 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
446 // ^ 446 // ^
447 checkSend(iElement, nodes[1], elements[1]); 447 checkSend(iElement, nodes[1], elements[1]);
448 448
449 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 449 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
450 // ^
451 checkIdentifier(iElement, nodes[2], elements[2]);
452
453 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
454 // ^ 450 // ^
455 checkSend(iElement, nodes[3], elements[3]); 451 checkSend(iElement, nodes[2], elements[2]);
456 452
457 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 453 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
458 // ^^^^^^^^^ 454 // ^^^^^^^^^
459 checkSendSet(iElement, nodes[4], elements[4]); 455 checkSendSet(iElement, nodes[3], elements[3]);
460
461 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
462 // ^
463 checkIdentifier(iElement, nodes[5], elements[5]);
464 456
465 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 457 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
466 // ^^^^^ 458 // ^^^^^
467 checkSendSet(iElement, nodes[6], elements[6]); 459 checkSendSet(iElement, nodes[4], elements[4]);
468 }); 460 });
469 } 461 }
470 462
471 checkIdentifier(Element expected, Node node, Element actual) { 463 checkIdentifier(Element expected, Node node, Element actual) {
472 Expect.isTrue(node is Identifier, node.toDebugString()); 464 Expect.isTrue(node is Identifier, node.toDebugString());
473 Expect.equals(expected, actual); 465 Expect.equals(expected, actual);
474 } 466 }
475 467
476 checkSend(Element expected, Node node, Element actual) { 468 checkSend(Element expected, Node node, Element actual) {
477 Expect.isTrue(node is Send, node.toDebugString()); 469 Expect.isTrue(node is Send, node.toDebugString());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 588
597 Future testTwoInterfaces() { 589 Future testTwoInterfaces() {
598 return MockCompiler.create((MockCompiler compiler) { 590 return MockCompiler.create((MockCompiler compiler) {
599 compiler.parseScript( 591 compiler.parseScript(
600 """abstract class I1 {} 592 """abstract class I1 {}
601 abstract class I2 {} 593 abstract class I2 {}
602 class C implements I1, I2 {}"""); 594 class C implements I1, I2 {}""");
603 compiler.resolveStatement("Foo bar;"); 595 compiler.resolveStatement("Foo bar;");
604 596
605 ClassElement c = compiler.mainApp.find('C'); 597 ClassElement c = compiler.mainApp.find('C');
606 Element i1 = compiler.mainApp.find('I1'); 598 ClassElement i1 = compiler.mainApp.find('I1');
607 Element i2 = compiler.mainApp.find('I2'); 599 ClassElement i2 = compiler.mainApp.find('I2');
608 600
609 Expect.equals(2, length(c.interfaces)); 601 Expect.equals(2, length(c.interfaces));
610 Expect.equals(i1.computeType(compiler), at(c.interfaces, 0)); 602 Expect.equals(i1.computeType(compiler), at(c.interfaces, 0));
611 Expect.equals(i2.computeType(compiler), at(c.interfaces, 1)); 603 Expect.equals(i2.computeType(compiler), at(c.interfaces, 1));
612 }); 604 });
613 } 605 }
614 606
615 Future testFunctionExpression() { 607 Future testFunctionExpression() {
616 return MockCompiler.create((MockCompiler compiler) { 608 return MockCompiler.create((MockCompiler compiler) {
617 ResolverVisitor visitor = compiler.resolverVisitor(); 609 ResolverVisitor visitor = compiler.resolverVisitor();
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 } 1404 }
1413 main() => A.m(); 1405 main() => A.m();
1414 ''', functionName: 'm'); 1406 ''', functionName: 'm');
1415 check(''' 1407 check('''
1416 class A { 1408 class A {
1417 m() => () => await - 3; 1409 m() => () => await - 3;
1418 } 1410 }
1419 main() => new A().m(); 1411 main() => new A().m();
1420 ''', className: 'A'); 1412 ''', className: 'A');
1421 } 1413 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | tests/compiler/dart2js/semantic_visitor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698