OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.test.src.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
6 | 6 |
7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
9 import 'package:analyzer/error/listener.dart'; | 9 import 'package:analyzer/error/listener.dart'; |
10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
(...skipping 7081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7092 strings: [ | 7092 strings: [ |
7093 'f' | 7093 'f' |
7094 ], | 7094 ], |
7095 referenceValidators: [ | 7095 referenceValidators: [ |
7096 (EntityRef r) => checkTypeRef(r, null, 'C', | 7096 (EntityRef r) => checkTypeRef(r, null, 'C', |
7097 expectedKind: ReferenceKind.classOrEnum) | 7097 expectedKind: ReferenceKind.classOrEnum) |
7098 ]); | 7098 ]); |
7099 } | 7099 } |
7100 | 7100 |
7101 test_expr_functionExpression_asArgument() { | 7101 test_expr_functionExpression_asArgument() { |
7102 if (skipNonConstInitializers) { | |
7103 return; | |
7104 } | |
7105 UnlinkedVariable variable = serializeVariableText(''' | 7102 UnlinkedVariable variable = serializeVariableText(''' |
7106 final v = foo(5, () => 42); | 7103 final v = foo(5, () => 42); |
7107 foo(a, b) {} | 7104 foo(a, b) {} |
7108 '''); | 7105 '''); |
7109 assertUnlinkedConst(variable.initializer.bodyExpr, | 7106 assertUnlinkedConst(variable.initializer.bodyExpr, |
7110 isValidConst: false, | 7107 isValidConst: false, |
7111 operators: [ | 7108 operators: [ |
7112 UnlinkedExprOperation.pushInt, | |
7113 UnlinkedExprOperation.pushLocalFunctionReference, | |
7114 UnlinkedExprOperation.invokeMethodRef | 7109 UnlinkedExprOperation.invokeMethodRef |
7115 ], | 7110 ], |
7116 ints: [ | 7111 ints: [ |
7117 5, | |
7118 0, | 7112 0, |
7119 0, | 7113 0, |
7120 0, | |
7121 2, | |
7122 0 | 7114 0 |
7123 ], | 7115 ], |
7124 referenceValidators: [ | 7116 referenceValidators: [ |
7125 (EntityRef r) => checkTypeRef(r, null, 'foo', | 7117 (EntityRef r) => checkTypeRef(r, null, 'foo', |
7126 expectedKind: ReferenceKind.topLevelFunction) | 7118 expectedKind: ReferenceKind.topLevelFunction) |
7127 ]); | 7119 ]); |
7128 } | 7120 } |
7129 | 7121 |
7130 test_expr_functionExpression_asArgument_multiple() { | 7122 test_expr_functionExpression_asArgument_multiple() { |
7131 if (skipNonConstInitializers) { | |
7132 return; | |
7133 } | |
7134 UnlinkedVariable variable = serializeVariableText(''' | 7123 UnlinkedVariable variable = serializeVariableText(''' |
7135 final v = foo(5, () => 42, () => 43); | 7124 final v = foo(5, () => 42, () => 43); |
7136 foo(a, b, c) {} | 7125 foo(a, b, c) {} |
7137 '''); | 7126 '''); |
7138 assertUnlinkedConst(variable.initializer.bodyExpr, | 7127 assertUnlinkedConst(variable.initializer.bodyExpr, |
7139 isValidConst: false, | 7128 isValidConst: false, |
7140 operators: [ | 7129 operators: [ |
7141 UnlinkedExprOperation.pushInt, | |
7142 UnlinkedExprOperation.pushLocalFunctionReference, | |
7143 UnlinkedExprOperation.pushLocalFunctionReference, | |
7144 UnlinkedExprOperation.invokeMethodRef | 7130 UnlinkedExprOperation.invokeMethodRef |
7145 ], | 7131 ], |
7146 ints: [ | 7132 ints: [ |
7147 5, | |
7148 0, | 7133 0, |
7149 0, | 7134 0, |
7150 0, | |
7151 1, | |
7152 0, | |
7153 3, | |
7154 0 | 7135 0 |
7155 ], | 7136 ], |
7156 referenceValidators: [ | 7137 referenceValidators: [ |
7157 (EntityRef r) => checkTypeRef(r, null, 'foo', | 7138 (EntityRef r) => checkTypeRef(r, null, 'foo', |
7158 expectedKind: ReferenceKind.topLevelFunction) | 7139 expectedKind: ReferenceKind.topLevelFunction) |
7159 ]); | 7140 ]); |
7160 } | 7141 } |
7161 | 7142 |
7162 test_expr_functionExpression_withBlockBody() { | 7143 test_expr_functionExpression_withBlockBody() { |
7163 if (skipNonConstInitializers) { | 7144 if (skipNonConstInitializers) { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7405 var c = serializeClassText(''' | 7386 var c = serializeClassText(''' |
7406 class C<T> { | 7387 class C<T> { |
7407 final f = T.k; | 7388 final f = T.k; |
7408 } | 7389 } |
7409 '''); | 7390 '''); |
7410 assertUnlinkedConst(c.fields[0].initializer.bodyExpr, | 7391 assertUnlinkedConst(c.fields[0].initializer.bodyExpr, |
7411 isValidConst: false, operators: []); | 7392 isValidConst: false, operators: []); |
7412 } | 7393 } |
7413 | 7394 |
7414 test_expr_invokeMethod_instance() { | 7395 test_expr_invokeMethod_instance() { |
7415 if (skipNonConstInitializers) { | |
7416 return; | |
7417 } | |
7418 UnlinkedVariable variable = serializeVariableText(''' | 7396 UnlinkedVariable variable = serializeVariableText(''' |
7419 class C { | 7397 class C { |
7420 int m(a, {b, c}) => 42; | 7398 int m(a, {b, c}) => 42; |
7421 } | 7399 } |
7422 final v = new C().m(1, b: 2, c: 3); | 7400 final v = new C().m(1, b: 2, c: 3); |
7423 '''); | 7401 '''); |
7424 assertUnlinkedConst(variable.initializer.bodyExpr, | 7402 assertUnlinkedConst(variable.initializer.bodyExpr, |
7425 isValidConst: false, | 7403 isValidConst: false, |
7426 operators: [ | 7404 operators: [ |
7427 UnlinkedExprOperation.invokeConstructor, | 7405 UnlinkedExprOperation.invokeConstructor, |
7428 UnlinkedExprOperation.pushInt, | |
7429 UnlinkedExprOperation.pushInt, | |
7430 UnlinkedExprOperation.pushInt, | |
7431 UnlinkedExprOperation.invokeMethod, | 7406 UnlinkedExprOperation.invokeMethod, |
7432 ], | 7407 ], |
7433 ints: [ | 7408 ints: [ |
7434 0, | 7409 0, |
7435 0, | 7410 0, |
7436 1, | 7411 0, |
7437 2, | 7412 0, |
7438 3, | |
7439 2, | |
7440 1, | |
7441 0 | 7413 0 |
7442 ], | 7414 ], |
7443 strings: [ | 7415 strings: [ |
7444 'b', | |
7445 'c', | |
7446 'm' | 7416 'm' |
7447 ], | 7417 ], |
7448 referenceValidators: [ | 7418 referenceValidators: [ |
7449 (EntityRef r) => checkTypeRef(r, null, 'C', | 7419 (EntityRef r) => checkTypeRef(r, null, 'C', |
7450 expectedKind: ReferenceKind.classOrEnum) | 7420 expectedKind: ReferenceKind.classOrEnum) |
7451 ]); | 7421 ]); |
7452 } | 7422 } |
7453 | 7423 |
7454 test_expr_invokeMethod_withTypeParameters() { | 7424 test_expr_invokeMethod_withTypeParameters() { |
7455 if (skipNonConstInitializers) { | 7425 if (skipNonConstInitializers) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7497 } | 7467 } |
7498 class C { | 7468 class C { |
7499 int m(int a, int b) => a + b; | 7469 int m(int a, int b) => a + b; |
7500 } | 7470 } |
7501 A a = new A(); | 7471 A a = new A(); |
7502 final v = a.b.c.m(10, 20); | 7472 final v = a.b.c.m(10, 20); |
7503 '''); | 7473 '''); |
7504 assertUnlinkedConst(variable.initializer.bodyExpr, | 7474 assertUnlinkedConst(variable.initializer.bodyExpr, |
7505 isValidConst: false, | 7475 isValidConst: false, |
7506 operators: [ | 7476 operators: [ |
7507 UnlinkedExprOperation.pushInt, | |
7508 UnlinkedExprOperation.pushInt, | |
7509 UnlinkedExprOperation.invokeMethodRef, | 7477 UnlinkedExprOperation.invokeMethodRef, |
7510 ], | 7478 ], |
7511 ints: [ | 7479 ints: [ |
7512 10, | |
7513 20, | |
7514 0, | 7480 0, |
7515 2, | 7481 0, |
7516 0 | 7482 0 |
7517 ], | 7483 ], |
7518 strings: [], | 7484 strings: [], |
7519 referenceValidators: [ | 7485 referenceValidators: [ |
7520 (EntityRef r) => checkTypeRef(r, null, 'm', | 7486 (EntityRef r) => checkTypeRef(r, null, 'm', |
7521 expectedKind: ReferenceKind.unresolved, | 7487 expectedKind: ReferenceKind.unresolved, |
7522 prefixExpectations: [ | 7488 prefixExpectations: [ |
7523 new _PrefixExpectation(ReferenceKind.unresolved, 'c'), | 7489 new _PrefixExpectation(ReferenceKind.unresolved, 'c'), |
7524 new _PrefixExpectation(ReferenceKind.unresolved, 'b'), | 7490 new _PrefixExpectation(ReferenceKind.unresolved, 'b'), |
7525 new _PrefixExpectation( | 7491 new _PrefixExpectation( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7570 return; | 7536 return; |
7571 } | 7537 } |
7572 UnlinkedVariable variable = serializeVariableText(''' | 7538 UnlinkedVariable variable = serializeVariableText(''' |
7573 f(x) => null; | 7539 f(x) => null; |
7574 final u = null; | 7540 final u = null; |
7575 final v = f(u); | 7541 final v = f(u); |
7576 '''); | 7542 '''); |
7577 assertUnlinkedConst(variable.initializer.bodyExpr, | 7543 assertUnlinkedConst(variable.initializer.bodyExpr, |
7578 isValidConst: false, | 7544 isValidConst: false, |
7579 operators: [ | 7545 operators: [ |
7580 UnlinkedExprOperation.pushReference, | |
7581 UnlinkedExprOperation.invokeMethodRef | 7546 UnlinkedExprOperation.invokeMethodRef |
7582 ], | 7547 ], |
7583 ints: [ | 7548 ints: [ |
7584 0, | 7549 0, |
7585 1, | 7550 0, |
7586 0 | 7551 0 |
7587 ], | 7552 ], |
7588 referenceValidators: [ | 7553 referenceValidators: [ |
7589 (EntityRef r) => checkTypeRef(r, null, 'u', | |
7590 expectedKind: ReferenceKind.topLevelPropertyAccessor), | |
7591 (EntityRef r) => checkTypeRef(r, null, 'f', | 7554 (EntityRef r) => checkTypeRef(r, null, 'f', |
7592 expectedKind: ReferenceKind.topLevelFunction) | 7555 expectedKind: ReferenceKind.topLevelFunction) |
7593 ]); | 7556 ]); |
7594 } | 7557 } |
7595 | 7558 |
7596 test_expr_invokeMethodRef_withTypeParameters() { | 7559 test_expr_invokeMethodRef_withTypeParameters() { |
7597 if (skipNonConstInitializers) { | 7560 if (skipNonConstInitializers) { |
7598 return; | 7561 return; |
7599 } | 7562 } |
7600 UnlinkedVariable variable = serializeVariableText(''' | 7563 UnlinkedVariable variable = serializeVariableText(''' |
(...skipping 12 matching lines...) Expand all Loading... |
7613 ], | 7576 ], |
7614 referenceValidators: [ | 7577 referenceValidators: [ |
7615 (EntityRef r) => checkTypeRef(r, null, 'f', | 7578 (EntityRef r) => checkTypeRef(r, null, 'f', |
7616 expectedKind: ReferenceKind.topLevelFunction, | 7579 expectedKind: ReferenceKind.topLevelFunction, |
7617 numTypeParameters: 2), | 7580 numTypeParameters: 2), |
7618 (EntityRef r) => checkTypeRef(r, 'dart:core', 'int'), | 7581 (EntityRef r) => checkTypeRef(r, 'dart:core', 'int'), |
7619 (EntityRef r) => checkTypeRef(r, 'dart:core', 'String') | 7582 (EntityRef r) => checkTypeRef(r, 'dart:core', 'String') |
7620 ]); | 7583 ]); |
7621 } | 7584 } |
7622 | 7585 |
| 7586 test_expr_makeTypedList() { |
| 7587 UnlinkedVariable variable = |
| 7588 serializeVariableText('var v = <int>[11, 22, 33];'); |
| 7589 assertUnlinkedConst(variable.initializer.bodyExpr, operators: [ |
| 7590 UnlinkedExprOperation.makeTypedList |
| 7591 ], ints: [ |
| 7592 0 |
| 7593 ], referenceValidators: [ |
| 7594 (EntityRef r) => checkTypeRef(r, 'dart:core', 'int', |
| 7595 expectedKind: ReferenceKind.classOrEnum) |
| 7596 ]); |
| 7597 } |
| 7598 |
| 7599 test_expr_makeTypedMap() { |
| 7600 UnlinkedVariable variable = serializeVariableText( |
| 7601 'var v = <int, String>{11: "aaa", 22: "bbb", 33: "ccc"};'); |
| 7602 assertUnlinkedConst(variable.initializer.bodyExpr, operators: [ |
| 7603 UnlinkedExprOperation.makeTypedMap |
| 7604 ], ints: [ |
| 7605 0 |
| 7606 ], referenceValidators: [ |
| 7607 (EntityRef r) => checkTypeRef(r, 'dart:core', 'int', |
| 7608 expectedKind: ReferenceKind.classOrEnum), |
| 7609 (EntityRef r) => checkTypeRef(r, 'dart:core', 'String', |
| 7610 expectedKind: ReferenceKind.classOrEnum) |
| 7611 ]); |
| 7612 } |
| 7613 |
| 7614 test_expr_makeUntypedList() { |
| 7615 UnlinkedVariable variable = serializeVariableText('var v = [11, 22, 33];'); |
| 7616 assertUnlinkedConst(variable.initializer.bodyExpr, operators: [ |
| 7617 UnlinkedExprOperation.pushInt, |
| 7618 UnlinkedExprOperation.pushInt, |
| 7619 UnlinkedExprOperation.pushInt, |
| 7620 UnlinkedExprOperation.makeUntypedList |
| 7621 ], ints: [ |
| 7622 11, |
| 7623 22, |
| 7624 33, |
| 7625 3 |
| 7626 ]); |
| 7627 } |
| 7628 |
| 7629 test_expr_makeUntypedMap() { |
| 7630 UnlinkedVariable variable = |
| 7631 serializeVariableText('var v = {11: "aaa", 22: "bbb", 33: "ccc"};'); |
| 7632 assertUnlinkedConst(variable.initializer.bodyExpr, operators: [ |
| 7633 UnlinkedExprOperation.pushInt, |
| 7634 UnlinkedExprOperation.pushString, |
| 7635 UnlinkedExprOperation.pushInt, |
| 7636 UnlinkedExprOperation.pushString, |
| 7637 UnlinkedExprOperation.pushInt, |
| 7638 UnlinkedExprOperation.pushString, |
| 7639 UnlinkedExprOperation.makeUntypedMap |
| 7640 ], ints: [ |
| 7641 11, |
| 7642 22, |
| 7643 33, |
| 7644 3 |
| 7645 ], strings: [ |
| 7646 'aaa', |
| 7647 'bbb', |
| 7648 'ccc' |
| 7649 ]); |
| 7650 } |
| 7651 |
7623 test_expr_super() { | 7652 test_expr_super() { |
7624 if (skipNonConstInitializers) { | 7653 if (skipNonConstInitializers) { |
7625 return; | 7654 return; |
7626 } | 7655 } |
7627 UnlinkedVariable variable = serializeVariableText(''' | 7656 UnlinkedVariable variable = serializeVariableText(''' |
7628 final v = super; | 7657 final v = super; |
7629 '''); | 7658 '''); |
7630 assertUnlinkedConst(variable.initializer.bodyExpr, operators: [ | 7659 assertUnlinkedConst(variable.initializer.bodyExpr, operators: [ |
7631 UnlinkedExprOperation.pushSuper, | 7660 UnlinkedExprOperation.pushSuper, |
7632 ]); | 7661 ]); |
(...skipping 2982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10615 */ | 10644 */ |
10616 class _PrefixExpectation { | 10645 class _PrefixExpectation { |
10617 final ReferenceKind kind; | 10646 final ReferenceKind kind; |
10618 final String name; | 10647 final String name; |
10619 final String absoluteUri; | 10648 final String absoluteUri; |
10620 final int numTypeParameters; | 10649 final int numTypeParameters; |
10621 | 10650 |
10622 _PrefixExpectation(this.kind, this.name, | 10651 _PrefixExpectation(this.kind, this.name, |
10623 {this.absoluteUri, this.numTypeParameters: 0}); | 10652 {this.absoluteUri, this.numTypeParameters: 0}); |
10624 } | 10653 } |
OLD | NEW |