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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1612863002: Serialize long integers as unsigned 32-bit pieces. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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) 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/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 30 matching lines...) Expand all
41 analysisContext.typeProvider.objectType.element.library, 41 analysisContext.typeProvider.objectType.element.library,
42 analysisContext.typeProvider.futureType.element.library 42 analysisContext.typeProvider.futureType.element.library
43 ]; 43 ];
44 for (LibraryElement library in libraries) { 44 for (LibraryElement library in libraries) {
45 summarize_elements.LibrarySerializationResult serializedLibrary = 45 summarize_elements.LibrarySerializationResult serializedLibrary =
46 summarize_elements.serializeLibrary( 46 summarize_elements.serializeLibrary(
47 library, analysisContext.typeProvider); 47 library, analysisContext.typeProvider);
48 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { 48 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) {
49 uriToNamespace[serializedLibrary.unitUris[i]] = 49 uriToNamespace[serializedLibrary.unitUris[i]] =
50 new UnlinkedUnit.fromBuffer( 50 new UnlinkedUnit.fromBuffer(
51 serializedLibrary.unlinkedUnits[i].toBuffer()).publicNamespace; 51 serializedLibrary.unlinkedUnits[i].toBuffer())
52 .publicNamespace;
52 } 53 }
53 } 54 }
54 return uriToNamespace; 55 return uriToNamespace;
55 } catch (_) { 56 } catch (_) {
56 return null; 57 return null;
57 } 58 }
58 }(); 59 }();
59 60
60 /** 61 /**
61 * Convert a summary object (or a portion of one) into a canonical form that 62 * Convert a summary object (or a portion of one) into a canonical form that
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 {LinkedUnit linkedSourceUnit, UnlinkedUnit unlinkedSourceUnit}) { 541 {LinkedUnit linkedSourceUnit, UnlinkedUnit unlinkedSourceUnit}) {
541 // When serializing from the element model, unresolved type refs lose their 542 // When serializing from the element model, unresolved type refs lose their
542 // name. 543 // name.
543 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null, 544 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null,
544 expectedPrefix: expectedPrefix, 545 expectedPrefix: expectedPrefix,
545 expectedKind: ReferenceKind.unresolved, 546 expectedKind: ReferenceKind.unresolved,
546 linkedSourceUnit: linkedSourceUnit, 547 linkedSourceUnit: linkedSourceUnit,
547 unlinkedSourceUnit: unlinkedSourceUnit); 548 unlinkedSourceUnit: unlinkedSourceUnit);
548 } 549 }
549 550
550 fail_constExpr_pushInt_shiftOr() {
551 UnlinkedVariable variable =
552 serializeVariableText('const v = 0x111222333444555666;');
553 // ^^!!!!^^^^!!!!^^^^
554 _assertUnlinkedConst(variable.constExpr, operators: [
555 UnlinkedConstOperation.pushInt,
556 UnlinkedConstOperation.shiftOr,
557 UnlinkedConstOperation.shiftOr
558 ], ints: [
559 0x11,
560 0x12223334,
561 0x44555666
562 ]);
563 }
564
565 fail_enum_value_documented() { 551 fail_enum_value_documented() {
566 // TODO(paulberry): currently broken because of dartbug.com/25385 552 // TODO(paulberry): currently broken because of dartbug.com/25385
567 String text = ''' 553 String text = '''
568 enum E { 554 enum E {
569 /** 555 /**
570 * Docs 556 * Docs
571 */ 557 */
572 v 558 v
573 }'''; 559 }''';
574 UnlinkedEnumValue value = serializeEnumText(text).values[0]; 560 UnlinkedEnumValue value = serializeEnumText(text).values[0];
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 750
765 /** 751 /**
766 * Serialize a type declaration using the given [text] as a type name, and 752 * Serialize a type declaration using the given [text] as a type name, and
767 * return a summary of the corresponding [TypeRef]. If the type 753 * return a summary of the corresponding [TypeRef]. If the type
768 * declaration needs to refer to types that are not available in core, those 754 * declaration needs to refer to types that are not available in core, those
769 * types may be declared in [otherDeclarations]. 755 * types may be declared in [otherDeclarations].
770 */ 756 */
771 TypeRef serializeTypeText(String text, 757 TypeRef serializeTypeText(String text,
772 {String otherDeclarations: '', bool allowErrors: false}) { 758 {String otherDeclarations: '', bool allowErrors: false}) {
773 return serializeVariableText('$otherDeclarations\n$text v;', 759 return serializeVariableText('$otherDeclarations\n$text v;',
774 allowErrors: allowErrors).type; 760 allowErrors: allowErrors)
761 .type;
775 } 762 }
776 763
777 /** 764 /**
778 * Serialize the given library [text] and return the summary of the variable 765 * Serialize the given library [text] and return the summary of the variable
779 * with the given [variableName]. 766 * with the given [variableName].
780 */ 767 */
781 UnlinkedVariable serializeVariableText(String text, 768 UnlinkedVariable serializeVariableText(String text,
782 {String variableName: 'v', bool allowErrors: false}) { 769 {String variableName: 'v', bool allowErrors: false}) {
783 serializeLibraryText(text, allowErrors: allowErrors); 770 serializeLibraryText(text, allowErrors: allowErrors);
784 return findVariable(variableName, failIfAbsent: true); 771 return findVariable(variableName, failIfAbsent: true);
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 '' 1524 ''
1538 ], referenceValidators: [ 1525 ], referenceValidators: [
1539 (TypeRef r) => checkTypeRef(r, null, null, 'C', 1526 (TypeRef r) => checkTypeRef(r, null, null, 'C',
1540 expectedKind: ReferenceKind.classOrEnum) 1527 expectedKind: ReferenceKind.classOrEnum)
1541 ]); 1528 ]);
1542 } 1529 }
1543 1530
1544 test_constExpr_length() { 1531 test_constExpr_length() {
1545 UnlinkedVariable variable = 1532 UnlinkedVariable variable =
1546 serializeVariableText('const v = "abc".length;'); 1533 serializeVariableText('const v = "abc".length;');
1547 _assertUnlinkedConst(variable.constExpr, 1534 _assertUnlinkedConst(variable.constExpr, operators: [
1548 operators: 1535 UnlinkedConstOperation.pushString,
1549 [UnlinkedConstOperation.pushString, UnlinkedConstOperation.length], 1536 UnlinkedConstOperation.length
1550 strings: ['abc']); 1537 ], strings: [
1538 'abc'
1539 ]);
1551 } 1540 }
1552 1541
1553 test_constExpr_makeList_typed() { 1542 test_constExpr_makeList_typed() {
1554 UnlinkedVariable variable = 1543 UnlinkedVariable variable =
1555 serializeVariableText('const v = const <int>[11, 22, 33];'); 1544 serializeVariableText('const v = const <int>[11, 22, 33];');
1556 _assertUnlinkedConst(variable.constExpr, operators: [ 1545 _assertUnlinkedConst(variable.constExpr, operators: [
1557 UnlinkedConstOperation.pushInt, 1546 UnlinkedConstOperation.pushInt,
1558 UnlinkedConstOperation.pushInt, 1547 UnlinkedConstOperation.pushInt,
1559 UnlinkedConstOperation.pushInt, 1548 UnlinkedConstOperation.pushInt,
1560 UnlinkedConstOperation.makeList 1549 UnlinkedConstOperation.makeList
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 UnlinkedConstOperation.multiply, 1653 UnlinkedConstOperation.multiply,
1665 ], ints: [ 1654 ], ints: [
1666 1, 1655 1,
1667 2, 1656 2,
1668 3 1657 3
1669 ]); 1658 ]);
1670 } 1659 }
1671 1660
1672 test_constExpr_prefix_complement() { 1661 test_constExpr_prefix_complement() {
1673 UnlinkedVariable variable = serializeVariableText('const v = ~2;'); 1662 UnlinkedVariable variable = serializeVariableText('const v = ~2;');
1674 _assertUnlinkedConst(variable.constExpr, 1663 _assertUnlinkedConst(variable.constExpr, operators: [
1675 operators: 1664 UnlinkedConstOperation.pushInt,
1676 [UnlinkedConstOperation.pushInt, UnlinkedConstOperation.complement], 1665 UnlinkedConstOperation.complement
1677 ints: [2]); 1666 ], ints: [
1667 2
1668 ]);
1678 } 1669 }
1679 1670
1680 test_constExpr_prefix_negate() { 1671 test_constExpr_prefix_negate() {
1681 UnlinkedVariable variable = serializeVariableText('const v = -(2);'); 1672 UnlinkedVariable variable = serializeVariableText('const v = -(2);');
1682 _assertUnlinkedConst(variable.constExpr, 1673 _assertUnlinkedConst(variable.constExpr, operators: [
1683 operators: 1674 UnlinkedConstOperation.pushInt,
1684 [UnlinkedConstOperation.pushInt, UnlinkedConstOperation.negate], 1675 UnlinkedConstOperation.negate
1685 ints: [2]); 1676 ], ints: [
1677 2
1678 ]);
1686 } 1679 }
1687 1680
1688 test_constExpr_prefix_not() { 1681 test_constExpr_prefix_not() {
1689 UnlinkedVariable variable = serializeVariableText('const v = !true;'); 1682 UnlinkedVariable variable = serializeVariableText('const v = !true;');
1690 _assertUnlinkedConst(variable.constExpr, operators: 1683 _assertUnlinkedConst(variable.constExpr, operators: [
1691 [UnlinkedConstOperation.pushTrue, UnlinkedConstOperation.not]); 1684 UnlinkedConstOperation.pushTrue,
1685 UnlinkedConstOperation.not
1686 ]);
1692 } 1687 }
1693 1688
1694 test_constExpr_pushDouble() { 1689 test_constExpr_pushDouble() {
1695 UnlinkedVariable variable = serializeVariableText('const v = 123.4567;'); 1690 UnlinkedVariable variable = serializeVariableText('const v = 123.4567;');
1696 _assertUnlinkedConst(variable.constExpr, 1691 _assertUnlinkedConst(variable.constExpr,
1697 operators: [UnlinkedConstOperation.pushDouble], doubles: [123.4567]); 1692 operators: [UnlinkedConstOperation.pushDouble], doubles: [123.4567]);
1698 } 1693 }
1699 1694
1700 test_constExpr_pushFalse() { 1695 test_constExpr_pushFalse() {
1701 UnlinkedVariable variable = serializeVariableText('const v = false;'); 1696 UnlinkedVariable variable = serializeVariableText('const v = false;');
1702 _assertUnlinkedConst(variable.constExpr, 1697 _assertUnlinkedConst(variable.constExpr,
1703 operators: [UnlinkedConstOperation.pushFalse]); 1698 operators: [UnlinkedConstOperation.pushFalse]);
1704 } 1699 }
1705 1700
1706 test_constExpr_pushInt() { 1701 test_constExpr_pushInt() {
1707 UnlinkedVariable variable = serializeVariableText('const v = 1;'); 1702 UnlinkedVariable variable = serializeVariableText('const v = 1;');
1708 _assertUnlinkedConst(variable.constExpr, 1703 _assertUnlinkedConst(variable.constExpr,
1709 operators: [UnlinkedConstOperation.pushInt], ints: [1]); 1704 operators: [UnlinkedConstOperation.pushInt], ints: [1]);
1710 } 1705 }
1711 1706
1707 test_constExpr_pushInt_max() {
1708 UnlinkedVariable variable = serializeVariableText('const v = 0xFFFFFFFF;');
1709 _assertUnlinkedConst(variable.constExpr,
1710 operators: [UnlinkedConstOperation.pushInt,], ints: [0xFFFFFFFF]);
1711 }
1712
1713 test_constExpr_pushInt_negative() {
1714 UnlinkedVariable variable = serializeVariableText('const v = -5;');
1715 _assertUnlinkedConst(variable.constExpr, operators: [
1716 UnlinkedConstOperation.pushInt,
1717 UnlinkedConstOperation.negate
1718 ], ints: [
1719 5
1720 ]);
1721 }
1722
1723 test_constExpr_pushInt_shiftOr_long() {
1724 UnlinkedVariable variable =
1725 serializeVariableText('const v = 0xA123456789ABCDEF012345678;');
1726 _assertUnlinkedConst(variable.constExpr, operators: [
1727 UnlinkedConstOperation.pushInt,
1728 UnlinkedConstOperation.shiftOr,
1729 UnlinkedConstOperation.shiftOr,
1730 UnlinkedConstOperation.shiftOr
1731 ], ints: [
1732 0xA,
1733 0x12345678,
1734 0x9ABCDEF0,
1735 0x12345678
1736 ]);
1737 }
1738
1739 test_constExpr_pushInt_shiftOr_min() {
1740 UnlinkedVariable variable = serializeVariableText('const v = 0x100000000;');
1741 _assertUnlinkedConst(variable.constExpr, operators: [
1742 UnlinkedConstOperation.pushInt,
1743 UnlinkedConstOperation.shiftOr,
1744 ], ints: [
1745 1,
1746 0,
1747 ]);
1748 }
1749
1750 test_constExpr_pushInt_shiftOr_min2() {
1751 UnlinkedVariable variable =
1752 serializeVariableText('const v = 0x10000000000000000;');
1753 _assertUnlinkedConst(variable.constExpr, operators: [
1754 UnlinkedConstOperation.pushInt,
1755 UnlinkedConstOperation.shiftOr,
1756 UnlinkedConstOperation.shiftOr,
1757 ], ints: [
1758 1,
1759 0,
1760 0,
1761 ]);
1762 }
1763
1712 test_constExpr_pushNull() { 1764 test_constExpr_pushNull() {
1713 UnlinkedVariable variable = serializeVariableText('const v = null;'); 1765 UnlinkedVariable variable = serializeVariableText('const v = null;');
1714 _assertUnlinkedConst(variable.constExpr, 1766 _assertUnlinkedConst(variable.constExpr,
1715 operators: [UnlinkedConstOperation.pushNull]); 1767 operators: [UnlinkedConstOperation.pushNull]);
1716 } 1768 }
1717 1769
1718 test_constExpr_pushReference_class() { 1770 test_constExpr_pushReference_class() {
1719 UnlinkedVariable variable = serializeVariableText(''' 1771 UnlinkedVariable variable = serializeVariableText('''
1720 class C {} 1772 class C {}
1721 const v = C; 1773 const v = C;
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 expect(executable.isConst, false); 2570 expect(executable.isConst, false);
2519 expect(executable.isFactory, false); 2571 expect(executable.isFactory, false);
2520 expect(executable.isStatic, false); 2572 expect(executable.isStatic, false);
2521 expect(executable.parameters, hasLength(1)); 2573 expect(executable.parameters, hasLength(1));
2522 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); 2574 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool');
2523 expect(executable.typeParameters, isEmpty); 2575 expect(executable.typeParameters, isEmpty);
2524 } 2576 }
2525 2577
2526 test_executable_operator_index_set() { 2578 test_executable_operator_index_set() {
2527 UnlinkedExecutable executable = serializeClassText( 2579 UnlinkedExecutable executable = serializeClassText(
2528 'class C { void operator[]=(int i, bool v) => null; }').executables[0]; 2580 'class C { void operator[]=(int i, bool v) => null; }')
2581 .executables[0];
2529 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 2582 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
2530 expect(executable.name, '[]='); 2583 expect(executable.name, '[]=');
2531 expect(executable.hasImplicitReturnType, false); 2584 expect(executable.hasImplicitReturnType, false);
2532 expect(executable.isAbstract, false); 2585 expect(executable.isAbstract, false);
2533 expect(executable.isConst, false); 2586 expect(executable.isConst, false);
2534 expect(executable.isFactory, false); 2587 expect(executable.isFactory, false);
2535 expect(executable.isStatic, false); 2588 expect(executable.isStatic, false);
2536 expect(executable.parameters, hasLength(2)); 2589 expect(executable.parameters, hasLength(2));
2537 expect(executable.returnType, isNull); 2590 expect(executable.returnType, isNull);
2538 expect(executable.typeParameters, isEmpty); 2591 expect(executable.typeParameters, isEmpty);
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
3336 checkUnresolvedTypeRef( 3389 checkUnresolvedTypeRef(
3337 serializeTypeText('dynamic.T', allowErrors: true), 'dynamic', 'T'); 3390 serializeTypeText('dynamic.T', allowErrors: true), 'dynamic', 'T');
3338 } 3391 }
3339 3392
3340 test_invalid_prefix_type_parameter() { 3393 test_invalid_prefix_type_parameter() {
3341 if (checkAstDerivedData) { 3394 if (checkAstDerivedData) {
3342 // TODO(paulberry): get this to work properly. 3395 // TODO(paulberry): get this to work properly.
3343 return; 3396 return;
3344 } 3397 }
3345 checkUnresolvedTypeRef( 3398 checkUnresolvedTypeRef(
3346 serializeClassText('class C<T> { T.U x; }', allowErrors: true).fields[0] 3399 serializeClassText('class C<T> { T.U x; }', allowErrors: true)
3400 .fields[0]
3347 .type, 3401 .type,
3348 'T', 3402 'T',
3349 'U'); 3403 'U');
3350 } 3404 }
3351 3405
3352 test_invalid_prefix_void() { 3406 test_invalid_prefix_void() {
3353 if (checkAstDerivedData) { 3407 if (checkAstDerivedData) {
3354 // TODO(paulberry): get this to work properly. 3408 // TODO(paulberry): get this to work properly.
3355 return; 3409 return;
3356 } 3410 }
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
4150 expect(constExpr.operations, operators); 4204 expect(constExpr.operations, operators);
4151 expect(constExpr.ints, ints); 4205 expect(constExpr.ints, ints);
4152 expect(constExpr.doubles, doubles); 4206 expect(constExpr.doubles, doubles);
4153 expect(constExpr.strings, strings); 4207 expect(constExpr.strings, strings);
4154 expect(constExpr.references, hasLength(referenceValidators.length)); 4208 expect(constExpr.references, hasLength(referenceValidators.length));
4155 for (int i = 0; i < referenceValidators.length; i++) { 4209 for (int i = 0; i < referenceValidators.length; i++) {
4156 referenceValidators[i](constExpr.references[i]); 4210 referenceValidators[i](constExpr.references[i]);
4157 } 4211 }
4158 } 4212 }
4159 } 4213 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_const_expr.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698