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

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

Issue 1602203004: Serialize constant initializers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add new summarize_const_expr.dart file. 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_test; 5 library analyzer.test.src.summary.summary_test;
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 analysisContext.typeProvider.objectType.element.library, 51 analysisContext.typeProvider.objectType.element.library,
52 analysisContext.typeProvider.futureType.element.library 52 analysisContext.typeProvider.futureType.element.library
53 ]; 53 ];
54 for (LibraryElement library in libraries) { 54 for (LibraryElement library in libraries) {
55 summarize_elements.LibrarySerializationResult serializedLibrary = 55 summarize_elements.LibrarySerializationResult serializedLibrary =
56 summarize_elements.serializeLibrary( 56 summarize_elements.serializeLibrary(
57 library, analysisContext.typeProvider); 57 library, analysisContext.typeProvider);
58 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { 58 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) {
59 uriToNamespace[serializedLibrary.unitUris[i]] = 59 uriToNamespace[serializedLibrary.unitUris[i]] =
60 new UnlinkedUnit.fromBuffer( 60 new UnlinkedUnit.fromBuffer(
61 serializedLibrary.unlinkedUnits[i].toBuffer()).publicNamespace; 61 serializedLibrary.unlinkedUnits[i].toBuffer())
62 .publicNamespace;
62 } 63 }
63 } 64 }
64 return uriToNamespace; 65 return uriToNamespace;
65 } catch (_) { 66 } catch (_) {
66 return null; 67 return null;
67 } 68 }
68 }(); 69 }();
69 70
70 /** 71 /**
71 * Convert a summary object (or a portion of one) into a canonical form that 72 * Convert a summary object (or a portion of one) into a canonical form that
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER); 113 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER);
113 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER); 114 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER);
114 parser.parseGenericMethods = true; 115 parser.parseGenericMethods = true;
115 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); 116 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize());
116 UnlinkedPublicNamespace namespace = new UnlinkedPublicNamespace.fromBuffer( 117 UnlinkedPublicNamespace namespace = new UnlinkedPublicNamespace.fromBuffer(
117 public_namespace.computePublicNamespace(unit).toBuffer()); 118 public_namespace.computePublicNamespace(unit).toBuffer());
118 return namespace; 119 return namespace;
119 } 120 }
120 121
121 /** 122 /**
123 * Type of a function that validates an [UnlinkedTypeRef].
124 */
125 typedef bool _UnlinkedTypeRefValidator(UnlinkedTypeRef unlinkedTypeRef);
126
127 /**
122 * Override of [SummaryTest] which verifies the correctness of the prelinker by 128 * Override of [SummaryTest] which verifies the correctness of the prelinker by
123 * creating summaries from the element model, discarding their prelinked 129 * creating summaries from the element model, discarding their prelinked
124 * information, and then recreating it using the prelinker. 130 * information, and then recreating it using the prelinker.
125 */ 131 */
126 @reflectiveTest 132 @reflectiveTest
127 class PrelinkerTest extends SummarizeElementsTest { 133 class PrelinkerTest extends SummarizeElementsTest {
128 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace = 134 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace =
129 <String, UnlinkedPublicNamespace>{}; 135 <String, UnlinkedPublicNamespace>{};
130 136
131 @override 137 @override
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 * type. 583 * type.
578 */ 584 */
579 void checkUnresolvedTypeRef( 585 void checkUnresolvedTypeRef(
580 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) { 586 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) {
581 // When serializing from the element model, unresolved type refs lose their 587 // When serializing from the element model, unresolved type refs lose their
582 // name. 588 // name.
583 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null, 589 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null,
584 expectedPrefix: expectedPrefix, expectedKind: ReferenceKind.unresolved); 590 expectedPrefix: expectedPrefix, expectedKind: ReferenceKind.unresolved);
585 } 591 }
586 592
593 fail_constExpr_pushInt_shiftOr() {
594 UnlinkedVariable variable =
595 serializeVariableText('const v = 0x111222333444555666;');
596 // ^^!!!!^^^^!!!!^^^^
597 _assertUnlinkedConst(variable.constExpr, operators: [
598 UnlinkedConstOperation.pushInt,
599 UnlinkedConstOperation.shiftOr,
600 UnlinkedConstOperation.shiftOr
601 ], ints: [
602 0x11,
603 0x12223334,
604 0x44555666
605 ]);
606 }
607
587 fail_enum_value_documented() { 608 fail_enum_value_documented() {
588 // TODO(paulberry): currently broken because of dartbug.com/25385 609 // TODO(paulberry): currently broken because of dartbug.com/25385
589 String text = ''' 610 String text = '''
590 enum E { 611 enum E {
591 /** 612 /**
592 * Docs 613 * Docs
593 */ 614 */
594 v 615 v
595 }'''; 616 }''';
596 UnlinkedEnumValue value = serializeEnumText(text).values[0]; 617 UnlinkedEnumValue value = serializeEnumText(text).values[0];
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 794
774 /** 795 /**
775 * Serialize a type declaration using the given [text] as a type name, and 796 * Serialize a type declaration using the given [text] as a type name, and
776 * return a summary of the corresponding [UnlinkedTypeRef]. If the type 797 * return a summary of the corresponding [UnlinkedTypeRef]. If the type
777 * declaration needs to refer to types that are not available in core, those 798 * declaration needs to refer to types that are not available in core, those
778 * types may be declared in [otherDeclarations]. 799 * types may be declared in [otherDeclarations].
779 */ 800 */
780 UnlinkedTypeRef serializeTypeText(String text, 801 UnlinkedTypeRef serializeTypeText(String text,
781 {String otherDeclarations: '', bool allowErrors: false}) { 802 {String otherDeclarations: '', bool allowErrors: false}) {
782 return serializeVariableText('$otherDeclarations\n$text v;', 803 return serializeVariableText('$otherDeclarations\n$text v;',
783 allowErrors: allowErrors).type; 804 allowErrors: allowErrors)
805 .type;
784 } 806 }
785 807
786 /** 808 /**
787 * Serialize the given library [text] and return the summary of the variable 809 * Serialize the given library [text] and return the summary of the variable
788 * with the given [variableName]. 810 * with the given [variableName].
789 */ 811 */
790 UnlinkedVariable serializeVariableText(String text, 812 UnlinkedVariable serializeVariableText(String text,
791 {String variableName: 'v', bool allowErrors: false}) { 813 {String variableName: 'v', bool allowErrors: false}) {
792 serializeLibraryText(text, allowErrors: allowErrors); 814 serializeLibraryText(text, allowErrors: allowErrors);
793 return findVariable(variableName, failIfAbsent: true); 815 return findVariable(variableName, failIfAbsent: true);
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 test_class_type_param_no_bound() { 1216 test_class_type_param_no_bound() {
1195 String text = 'class C<T> {}'; 1217 String text = 'class C<T> {}';
1196 UnlinkedClass cls = serializeClassText(text); 1218 UnlinkedClass cls = serializeClassText(text);
1197 expect(cls.typeParameters, hasLength(1)); 1219 expect(cls.typeParameters, hasLength(1));
1198 expect(cls.typeParameters[0].name, 'T'); 1220 expect(cls.typeParameters[0].name, 'T');
1199 expect(cls.typeParameters[0].nameOffset, text.indexOf('T')); 1221 expect(cls.typeParameters[0].nameOffset, text.indexOf('T'));
1200 expect(cls.typeParameters[0].bound, isNull); 1222 expect(cls.typeParameters[0].bound, isNull);
1201 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); 1223 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1);
1202 } 1224 }
1203 1225
1226 test_constExpr_binary_add() {
1227 UnlinkedVariable variable = serializeVariableText('const v = 1 + 2;');
1228 _assertUnlinkedConst(variable.constExpr, operators: [
1229 UnlinkedConstOperation.pushInt,
1230 UnlinkedConstOperation.pushInt,
1231 UnlinkedConstOperation.add
1232 ], ints: [
1233 1,
1234 2
1235 ]);
1236 }
1237
1238 test_constExpr_binary_and() {
1239 UnlinkedVariable variable =
1240 serializeVariableText('const v = true && false;');
1241 _assertUnlinkedConst(variable.constExpr, operators: [
1242 UnlinkedConstOperation.pushTrue,
1243 UnlinkedConstOperation.pushFalse,
1244 UnlinkedConstOperation.and
1245 ]);
1246 }
1247
1248 test_constExpr_binary_bitAnd() {
1249 UnlinkedVariable variable = serializeVariableText('const v = 1 & 2;');
1250 _assertUnlinkedConst(variable.constExpr, operators: [
1251 UnlinkedConstOperation.pushInt,
1252 UnlinkedConstOperation.pushInt,
1253 UnlinkedConstOperation.bitAnd
1254 ], ints: [
1255 1,
1256 2
1257 ]);
1258 }
1259
1260 test_constExpr_binary_bitOr() {
1261 UnlinkedVariable variable = serializeVariableText('const v = 1 | 2;');
1262 _assertUnlinkedConst(variable.constExpr, operators: [
1263 UnlinkedConstOperation.pushInt,
1264 UnlinkedConstOperation.pushInt,
1265 UnlinkedConstOperation.bitOr
1266 ], ints: [
1267 1,
1268 2
1269 ]);
1270 }
1271
1272 test_constExpr_binary_bitShiftLeft() {
1273 UnlinkedVariable variable = serializeVariableText('const v = 1 << 2;');
1274 _assertUnlinkedConst(variable.constExpr, operators: [
1275 UnlinkedConstOperation.pushInt,
1276 UnlinkedConstOperation.pushInt,
1277 UnlinkedConstOperation.bitShiftLeft
1278 ], ints: [
1279 1,
1280 2
1281 ]);
1282 }
1283
1284 test_constExpr_binary_bitShiftRight() {
1285 UnlinkedVariable variable = serializeVariableText('const v = 1 >> 2;');
1286 _assertUnlinkedConst(variable.constExpr, operators: [
1287 UnlinkedConstOperation.pushInt,
1288 UnlinkedConstOperation.pushInt,
1289 UnlinkedConstOperation.bitShiftRight
1290 ], ints: [
1291 1,
1292 2
1293 ]);
1294 }
1295
1296 test_constExpr_binary_bitXor() {
1297 UnlinkedVariable variable = serializeVariableText('const v = 1 ^ 2;');
1298 _assertUnlinkedConst(variable.constExpr, operators: [
1299 UnlinkedConstOperation.pushInt,
1300 UnlinkedConstOperation.pushInt,
1301 UnlinkedConstOperation.bitXor
1302 ], ints: [
1303 1,
1304 2
1305 ]);
1306 }
1307
1308 test_constExpr_binary_divide() {
1309 UnlinkedVariable variable = serializeVariableText('const v = 1 / 2;');
1310 _assertUnlinkedConst(variable.constExpr, operators: [
1311 UnlinkedConstOperation.pushInt,
1312 UnlinkedConstOperation.pushInt,
1313 UnlinkedConstOperation.divide
1314 ], ints: [
1315 1,
1316 2
1317 ]);
1318 }
1319
1320 test_constExpr_binary_equal() {
1321 UnlinkedVariable variable = serializeVariableText('const v = 1 == 2;');
1322 _assertUnlinkedConst(variable.constExpr, operators: [
1323 UnlinkedConstOperation.pushInt,
1324 UnlinkedConstOperation.pushInt,
1325 UnlinkedConstOperation.equal
1326 ], ints: [
1327 1,
1328 2
1329 ]);
1330 }
1331
1332 test_constExpr_binary_equal_not() {
1333 UnlinkedVariable variable = serializeVariableText('const v = 1 != 2;');
1334 _assertUnlinkedConst(variable.constExpr, operators: [
1335 UnlinkedConstOperation.pushInt,
1336 UnlinkedConstOperation.pushInt,
1337 UnlinkedConstOperation.equal,
1338 UnlinkedConstOperation.not
1339 ], ints: [
1340 1,
1341 2
1342 ]);
1343 }
1344
1345 test_constExpr_binary_floorDivide() {
1346 UnlinkedVariable variable = serializeVariableText('const v = 1 ~/ 2;');
1347 _assertUnlinkedConst(variable.constExpr, operators: [
1348 UnlinkedConstOperation.pushInt,
1349 UnlinkedConstOperation.pushInt,
1350 UnlinkedConstOperation.floorDivide
1351 ], ints: [
1352 1,
1353 2
1354 ]);
1355 }
1356
1357 test_constExpr_binary_greater() {
1358 UnlinkedVariable variable = serializeVariableText('const v = 1 > 2;');
1359 _assertUnlinkedConst(variable.constExpr, operators: [
1360 UnlinkedConstOperation.pushInt,
1361 UnlinkedConstOperation.pushInt,
1362 UnlinkedConstOperation.greater
1363 ], ints: [
1364 1,
1365 2
1366 ]);
1367 }
1368
1369 test_constExpr_binary_greaterEqual() {
1370 UnlinkedVariable variable = serializeVariableText('const v = 1 >= 2;');
1371 _assertUnlinkedConst(variable.constExpr, operators: [
1372 UnlinkedConstOperation.pushInt,
1373 UnlinkedConstOperation.pushInt,
1374 UnlinkedConstOperation.greaterEqual
1375 ], ints: [
1376 1,
1377 2
1378 ]);
1379 }
1380
1381 test_constExpr_binary_less() {
1382 UnlinkedVariable variable = serializeVariableText('const v = 1 < 2;');
1383 _assertUnlinkedConst(variable.constExpr, operators: [
1384 UnlinkedConstOperation.pushInt,
1385 UnlinkedConstOperation.pushInt,
1386 UnlinkedConstOperation.less
1387 ], ints: [
1388 1,
1389 2
1390 ]);
1391 }
1392
1393 test_constExpr_binary_lessEqual() {
1394 UnlinkedVariable variable = serializeVariableText('const v = 1 <= 2;');
1395 _assertUnlinkedConst(variable.constExpr, operators: [
1396 UnlinkedConstOperation.pushInt,
1397 UnlinkedConstOperation.pushInt,
1398 UnlinkedConstOperation.lessEqual
1399 ], ints: [
1400 1,
1401 2
1402 ]);
1403 }
1404
1405 test_constExpr_binary_modulo() {
1406 UnlinkedVariable variable = serializeVariableText('const v = 1 % 2;');
1407 _assertUnlinkedConst(variable.constExpr, operators: [
1408 UnlinkedConstOperation.pushInt,
1409 UnlinkedConstOperation.pushInt,
1410 UnlinkedConstOperation.modulo
1411 ], ints: [
1412 1,
1413 2
1414 ]);
1415 }
1416
1417 test_constExpr_binary_multiply() {
1418 UnlinkedVariable variable = serializeVariableText('const v = 1 * 2;');
1419 _assertUnlinkedConst(variable.constExpr, operators: [
1420 UnlinkedConstOperation.pushInt,
1421 UnlinkedConstOperation.pushInt,
1422 UnlinkedConstOperation.multiply
1423 ], ints: [
1424 1,
1425 2
1426 ]);
1427 }
1428
1429 test_constExpr_binary_or() {
1430 UnlinkedVariable variable =
1431 serializeVariableText('const v = false || true;');
1432 _assertUnlinkedConst(variable.constExpr, operators: [
1433 UnlinkedConstOperation.pushFalse,
1434 UnlinkedConstOperation.pushTrue,
1435 UnlinkedConstOperation.or
1436 ]);
1437 }
1438
1439 test_constExpr_binary_subtract() {
1440 UnlinkedVariable variable = serializeVariableText('const v = 1 - 2;');
1441 _assertUnlinkedConst(variable.constExpr, operators: [
1442 UnlinkedConstOperation.pushInt,
1443 UnlinkedConstOperation.pushInt,
1444 UnlinkedConstOperation.subtract
1445 ], ints: [
1446 1,
1447 2
1448 ]);
1449 }
1450
1451 test_constExpr_conditional() {
1452 UnlinkedVariable variable =
1453 serializeVariableText('const v = true ? 1 : 2;', allowErrors: true);
1454 _assertUnlinkedConst(variable.constExpr, operators: [
1455 UnlinkedConstOperation.pushTrue,
1456 UnlinkedConstOperation.pushInt,
1457 UnlinkedConstOperation.pushInt,
1458 UnlinkedConstOperation.conditional
1459 ], ints: [
1460 1,
1461 2
1462 ]);
1463 }
1464
1465 test_constExpr_identical() {
1466 UnlinkedVariable variable =
1467 serializeVariableText('const v = identical(42, null);');
1468 _assertUnlinkedConst(variable.constExpr, operators: [
1469 UnlinkedConstOperation.pushInt,
1470 UnlinkedConstOperation.pushNull,
1471 UnlinkedConstOperation.identical
1472 ], ints: [
1473 42
1474 ]);
1475 }
1476
1477 test_constExpr_invokeConstructor_named() {
1478 UnlinkedVariable variable = serializeVariableText('''
1479 class C {
1480 const C.named();
1481 }
1482 const v = const C.named();
1483 ''');
1484 _assertUnlinkedConst(variable.constExpr, operators: [
1485 UnlinkedConstOperation.invokeConstructor,
1486 ], ints: [
1487 0
1488 ], strings: [
1489 'named'
1490 ], referenceValidators: [
1491 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C',
1492 expectedKind: ReferenceKind.classOrEnum)
1493 ]);
1494 }
1495
1496 test_constExpr_invokeConstructor_named_imported() {
1497 addNamedSource(
1498 '/a.dart',
1499 '''
1500 class C {
1501 const C.named();
1502 }
1503 ''');
1504 UnlinkedVariable variable = serializeVariableText('''
1505 import 'a.dart';
1506 const v = const C.named();
1507 ''');
1508 _assertUnlinkedConst(variable.constExpr, operators: [
1509 UnlinkedConstOperation.invokeConstructor,
1510 ], ints: [
1511 0
1512 ], strings: [
1513 'named'
1514 ], referenceValidators: [
1515 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C',
1516 expectedKind: ReferenceKind.classOrEnum)
1517 ]);
1518 }
1519
1520 test_constExpr_invokeConstructor_named_imported_withPrefix() {
1521 addNamedSource(
1522 '/a.dart',
1523 '''
1524 class C {
1525 const C.named();
1526 }
1527 ''');
1528 UnlinkedVariable variable = serializeVariableText('''
1529 import 'a.dart' as p;
1530 const v = const p.C.named();
1531 ''');
1532 _assertUnlinkedConst(variable.constExpr, operators: [
1533 UnlinkedConstOperation.invokeConstructor,
1534 ], ints: [
1535 0
1536 ], strings: [
1537 'named'
1538 ], referenceValidators: [
1539 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C',
1540 expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'p')
1541 ]);
1542 }
1543
1544 test_constExpr_invokeConstructor_unnamed() {
1545 UnlinkedVariable variable = serializeVariableText('''
1546 class C {
1547 const C(int a, String b);
1548 }
1549 const v = const C(42, 'sss');
1550 ''');
1551 _assertUnlinkedConst(variable.constExpr, operators: [
1552 UnlinkedConstOperation.pushInt,
1553 UnlinkedConstOperation.pushString,
1554 UnlinkedConstOperation.invokeConstructor,
1555 ], ints: [
1556 42,
1557 2
1558 ], strings: [
1559 'sss',
1560 ''
1561 ], referenceValidators: [
1562 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C',
1563 expectedKind: ReferenceKind.classOrEnum)
1564 ]);
1565 }
1566
1567 test_constExpr_length() {
1568 UnlinkedVariable variable =
1569 serializeVariableText('const v = "abc".length;');
1570 _assertUnlinkedConst(variable.constExpr, operators: [
1571 UnlinkedConstOperation.pushString,
1572 UnlinkedConstOperation.length
1573 ], strings: [
1574 'abc'
1575 ]);
1576 }
1577
1578 test_constExpr_makeList_typed() {
1579 UnlinkedVariable variable =
1580 serializeVariableText('const v = const <int>[11, 22, 33];');
1581 _assertUnlinkedConst(variable.constExpr, operators: [
1582 UnlinkedConstOperation.pushInt,
1583 UnlinkedConstOperation.pushInt,
1584 UnlinkedConstOperation.pushInt,
1585 UnlinkedConstOperation.makeList
1586 ], ints: [
1587 11,
1588 22,
1589 33,
1590 3
1591 ], referenceValidators: [
1592 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int',
1593 expectedKind: ReferenceKind.classOrEnum)
1594 ]);
1595 }
1596
1597 test_constExpr_makeList_untyped() {
1598 UnlinkedVariable variable =
1599 serializeVariableText('const v = const [11, 22, 33];');
1600 _assertUnlinkedConst(variable.constExpr, operators: [
1601 UnlinkedConstOperation.pushInt,
1602 UnlinkedConstOperation.pushInt,
1603 UnlinkedConstOperation.pushInt,
1604 UnlinkedConstOperation.makeList
1605 ], ints: [
1606 11,
1607 22,
1608 33,
1609 3
1610 ], referenceValidators: [
1611 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '',
1612 expectedKind: ReferenceKind.classOrEnum)
1613 ]);
1614 }
1615
1616 test_constExpr_makeMap_typed() {
1617 UnlinkedVariable variable = serializeVariableText(
1618 'const v = const <int, String>{11: "aaa", 22: "bbb", 33: "ccc"};');
1619 _assertUnlinkedConst(variable.constExpr, operators: [
1620 UnlinkedConstOperation.pushInt,
1621 UnlinkedConstOperation.pushString,
1622 UnlinkedConstOperation.pushInt,
1623 UnlinkedConstOperation.pushString,
1624 UnlinkedConstOperation.pushInt,
1625 UnlinkedConstOperation.pushString,
1626 UnlinkedConstOperation.makeMap
1627 ], ints: [
1628 11,
1629 22,
1630 33,
1631 3
1632 ], strings: [
1633 'aaa',
1634 'bbb',
1635 'ccc'
1636 ], referenceValidators: [
1637 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int',
1638 expectedKind: ReferenceKind.classOrEnum),
1639 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'String',
1640 expectedKind: ReferenceKind.classOrEnum)
1641 ]);
1642 }
1643
1644 test_constExpr_makeMap_untyped() {
1645 UnlinkedVariable variable = serializeVariableText(
1646 'const v = const {11: "aaa", 22: "bbb", 33: "ccc"};');
1647 _assertUnlinkedConst(variable.constExpr, operators: [
1648 UnlinkedConstOperation.pushInt,
1649 UnlinkedConstOperation.pushString,
1650 UnlinkedConstOperation.pushInt,
1651 UnlinkedConstOperation.pushString,
1652 UnlinkedConstOperation.pushInt,
1653 UnlinkedConstOperation.pushString,
1654 UnlinkedConstOperation.makeMap
1655 ], ints: [
1656 11,
1657 22,
1658 33,
1659 3
1660 ], strings: [
1661 'aaa',
1662 'bbb',
1663 'ccc'
1664 ], referenceValidators: [
1665 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '',
1666 expectedKind: ReferenceKind.classOrEnum),
1667 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '',
1668 expectedKind: ReferenceKind.classOrEnum)
1669 ]);
1670 }
1671
1672 test_constExpr_makeSymbol() {
1673 UnlinkedVariable variable = serializeVariableText('const v = #a.bb.ccc;');
1674 _assertUnlinkedConst(variable.constExpr, operators: [
1675 UnlinkedConstOperation.pushString,
1676 UnlinkedConstOperation.makeSymbol
1677 ], strings: [
1678 'a.bb.ccc'
1679 ]);
1680 }
1681
1682 test_constExpr_parenthesized() {
1683 UnlinkedVariable variable = serializeVariableText('const v = (1 + 2) * 3;');
1684 _assertUnlinkedConst(variable.constExpr, operators: [
1685 UnlinkedConstOperation.pushInt,
1686 UnlinkedConstOperation.pushInt,
1687 UnlinkedConstOperation.add,
1688 UnlinkedConstOperation.pushInt,
1689 UnlinkedConstOperation.multiply,
1690 ], ints: [
1691 1,
1692 2,
1693 3
1694 ]);
1695 }
1696
1697 test_constExpr_prefix_complement() {
1698 UnlinkedVariable variable = serializeVariableText('const v = ~2;');
1699 _assertUnlinkedConst(variable.constExpr, operators: [
1700 UnlinkedConstOperation.pushInt,
1701 UnlinkedConstOperation.complement
1702 ], ints: [
1703 2
1704 ]);
1705 }
1706
1707 test_constExpr_prefix_negate() {
1708 UnlinkedVariable variable = serializeVariableText('const v = -(2);');
1709 _assertUnlinkedConst(variable.constExpr, operators: [
1710 UnlinkedConstOperation.pushInt,
1711 UnlinkedConstOperation.negate
1712 ], ints: [
1713 2
1714 ]);
1715 }
1716
1717 test_constExpr_prefix_not() {
1718 UnlinkedVariable variable = serializeVariableText('const v = !true;');
1719 _assertUnlinkedConst(variable.constExpr, operators: [
1720 UnlinkedConstOperation.pushTrue,
1721 UnlinkedConstOperation.not
1722 ]);
1723 }
1724
1725 test_constExpr_pushDouble() {
1726 UnlinkedVariable variable = serializeVariableText('const v = 123.4567;');
1727 _assertUnlinkedConst(variable.constExpr,
1728 operators: [UnlinkedConstOperation.pushDouble], doubles: [123.4567]);
1729 }
1730
1731 test_constExpr_pushFalse() {
1732 UnlinkedVariable variable = serializeVariableText('const v = false;');
1733 _assertUnlinkedConst(variable.constExpr,
1734 operators: [UnlinkedConstOperation.pushFalse]);
1735 }
1736
1737 test_constExpr_pushInt() {
1738 UnlinkedVariable variable = serializeVariableText('const v = 1;');
1739 _assertUnlinkedConst(variable.constExpr,
1740 operators: [UnlinkedConstOperation.pushInt], ints: [1]);
1741 }
1742
1743 test_constExpr_pushNull() {
1744 UnlinkedVariable variable = serializeVariableText('const v = null;');
1745 _assertUnlinkedConst(variable.constExpr,
1746 operators: [UnlinkedConstOperation.pushNull]);
1747 }
1748
1749 test_constExpr_pushReference_class() {
1750 UnlinkedVariable variable = serializeVariableText('''
1751 class C {}
1752 const v = C;
1753 ''');
1754 _assertUnlinkedConst(variable.constExpr, operators: [
1755 UnlinkedConstOperation.pushReference
1756 ], referenceValidators: [
1757 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C',
1758 expectedKind: ReferenceKind.classOrEnum)
1759 ]);
1760 }
1761
1762 test_constExpr_pushReference_class_field() {
1763 // TODO(scheglov) Not sure for to represent a field reference
1764 // using UnlinkedTypeRef.
1765 // UnlinkedVariable variable = serializeVariableText('''
1766 //class C {
1767 // static const int F = 1;
1768 //}
1769 //const v = C.F;
1770 //''');
1771 // _assertUnlinkedConst(variable.constExpr, operators: [
1772 // UnlinkedConstOperation.pushReference
1773 // ], references: [
1774 // (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'F',
1775 // expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'C')
1776 // ]);
1777 }
1778
1779 test_constExpr_pushReference_enum() {
1780 UnlinkedVariable variable = serializeVariableText('''
1781 enum C {V1, V2, V3}
1782 const v = C;
1783 ''');
1784 _assertUnlinkedConst(variable.constExpr, operators: [
1785 UnlinkedConstOperation.pushReference
1786 ], referenceValidators: [
1787 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C',
1788 expectedKind: ReferenceKind.classOrEnum)
1789 ]);
1790 }
1791
1792 test_constExpr_pushReference_topLevelVariable_imported() {
1793 addNamedSource('/a.dart', 'const int a = 1;');
1794 UnlinkedVariable variable = serializeVariableText('''
1795 import 'a.dart';
1796 const v = a;
1797 ''');
1798 _assertUnlinkedConst(variable.constExpr, operators: [
1799 UnlinkedConstOperation.pushReference
1800 ], referenceValidators: [
1801 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a',
1802 expectedKind: ReferenceKind.topLevelPropertyAccessor)
1803 ]);
1804 }
1805
1806 test_constExpr_pushReference_topLevelVariable_imported_withPrefix() {
1807 addNamedSource('/a.dart', 'const int a = 1;');
1808 UnlinkedVariable variable = serializeVariableText('''
1809 import 'a.dart' as p;
1810 const v = p.a;
1811 ''');
1812 _assertUnlinkedConst(variable.constExpr, operators: [
1813 UnlinkedConstOperation.pushReference
1814 ], referenceValidators: [
1815 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a',
1816 expectedKind: ReferenceKind.topLevelPropertyAccessor,
1817 expectedPrefix: 'p')
1818 ]);
1819 }
1820
1821 test_constExpr_pushReference_topLevelVariable_local() {
1822 // TODO(scheglov) use `a + b`
1823 UnlinkedVariable variable = serializeVariableText('''
1824 const int a = 1;
1825 const v = a;
1826 ''');
1827 _assertUnlinkedConst(variable.constExpr, operators: [
1828 UnlinkedConstOperation.pushReference
1829 ], referenceValidators: [
1830 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'a',
1831 expectedKind: ReferenceKind.topLevelPropertyAccessor)
1832 ]);
1833 }
1834
1835 test_constExpr_pushString_adjacent() {
1836 UnlinkedVariable variable =
1837 serializeVariableText('const v = "aaa" "b" "ccc";');
1838 _assertUnlinkedConst(variable.constExpr,
1839 operators: [UnlinkedConstOperation.pushString], strings: ['aaabccc']);
1840 }
1841
1842 test_constExpr_pushString_adjacent_interpolation() {
1843 UnlinkedVariable variable =
1844 serializeVariableText(r'const v = "aaa" "bb ${42} bbb" "cccc";');
1845 _assertUnlinkedConst(variable.constExpr, operators: [
1846 UnlinkedConstOperation.pushString,
1847 UnlinkedConstOperation.pushString,
1848 UnlinkedConstOperation.pushInt,
1849 UnlinkedConstOperation.pushString,
1850 UnlinkedConstOperation.concatenate,
1851 UnlinkedConstOperation.pushString,
1852 UnlinkedConstOperation.concatenate,
1853 ], ints: [
1854 42,
1855 3,
1856 3,
1857 ], strings: [
1858 'aaa',
1859 'bb ',
1860 ' bbb',
1861 'cccc'
1862 ]);
1863 }
1864
1865 test_constExpr_pushString_interpolation() {
1866 UnlinkedVariable variable =
1867 serializeVariableText(r'const v = "aaa ${42} bbb";');
1868 _assertUnlinkedConst(variable.constExpr, operators: [
1869 UnlinkedConstOperation.pushString,
1870 UnlinkedConstOperation.pushInt,
1871 UnlinkedConstOperation.pushString,
1872 UnlinkedConstOperation.concatenate
1873 ], ints: [
1874 42,
1875 3
1876 ], strings: [
1877 'aaa ',
1878 ' bbb'
1879 ]);
1880 }
1881
1882 test_constExpr_pushString_simple() {
1883 UnlinkedVariable variable = serializeVariableText('const v = "abc";');
1884 _assertUnlinkedConst(variable.constExpr,
1885 operators: [UnlinkedConstOperation.pushString], strings: ['abc']);
1886 }
1887
1888 test_constExpr_pushTrue() {
1889 UnlinkedVariable variable = serializeVariableText('const v = true;');
1890 _assertUnlinkedConst(variable.constExpr,
1891 operators: [UnlinkedConstOperation.pushTrue]);
1892 }
1893
1204 test_constructor() { 1894 test_constructor() {
1205 String text = 'class C { C(); }'; 1895 String text = 'class C { C(); }';
1206 UnlinkedExecutable executable = 1896 UnlinkedExecutable executable =
1207 findExecutable('', executables: serializeClassText(text).executables); 1897 findExecutable('', executables: serializeClassText(text).executables);
1208 expect(executable.kind, UnlinkedExecutableKind.constructor); 1898 expect(executable.kind, UnlinkedExecutableKind.constructor);
1209 expect(executable.hasImplicitReturnType, isFalse); 1899 expect(executable.hasImplicitReturnType, isFalse);
1210 expect(executable.isExternal, isFalse); 1900 expect(executable.isExternal, isFalse);
1211 expect(executable.nameOffset, text.indexOf('C();')); 1901 expect(executable.nameOffset, text.indexOf('C();'));
1212 } 1902 }
1213 1903
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 expect(executable.isConst, false); 2548 expect(executable.isConst, false);
1859 expect(executable.isFactory, false); 2549 expect(executable.isFactory, false);
1860 expect(executable.isStatic, false); 2550 expect(executable.isStatic, false);
1861 expect(executable.parameters, hasLength(1)); 2551 expect(executable.parameters, hasLength(1));
1862 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); 2552 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool');
1863 expect(executable.typeParameters, isEmpty); 2553 expect(executable.typeParameters, isEmpty);
1864 } 2554 }
1865 2555
1866 test_executable_operator_index_set() { 2556 test_executable_operator_index_set() {
1867 UnlinkedExecutable executable = serializeClassText( 2557 UnlinkedExecutable executable = serializeClassText(
1868 'class C { void operator[]=(int i, bool v) => null; }').executables[0]; 2558 'class C { void operator[]=(int i, bool v) => null; }')
2559 .executables[0];
1869 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 2560 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1870 expect(executable.name, '[]='); 2561 expect(executable.name, '[]=');
1871 expect(executable.hasImplicitReturnType, false); 2562 expect(executable.hasImplicitReturnType, false);
1872 expect(executable.isAbstract, false); 2563 expect(executable.isAbstract, false);
1873 expect(executable.isConst, false); 2564 expect(executable.isConst, false);
1874 expect(executable.isFactory, false); 2565 expect(executable.isFactory, false);
1875 expect(executable.isStatic, false); 2566 expect(executable.isStatic, false);
1876 expect(executable.parameters, hasLength(2)); 2567 expect(executable.parameters, hasLength(2));
1877 expect(executable.returnType, isNull); 2568 expect(executable.returnType, isNull);
1878 expect(executable.typeParameters, isEmpty); 2569 expect(executable.typeParameters, isEmpty);
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 expect(variable.isStatic, isFalse); 3016 expect(variable.isStatic, isFalse);
2326 expect(variable.isFinal, isFalse); 3017 expect(variable.isFinal, isFalse);
2327 expect(findExecutable('i', executables: cls.executables), isNull); 3018 expect(findExecutable('i', executables: cls.executables), isNull);
2328 expect(findExecutable('i=', executables: cls.executables), isNull); 3019 expect(findExecutable('i=', executables: cls.executables), isNull);
2329 } 3020 }
2330 3021
2331 test_field_const() { 3022 test_field_const() {
2332 UnlinkedVariable variable = 3023 UnlinkedVariable variable =
2333 serializeClassText('class C { static const int i = 0; }').fields[0]; 3024 serializeClassText('class C { static const int i = 0; }').fields[0];
2334 expect(variable.isConst, isTrue); 3025 expect(variable.isConst, isTrue);
3026 _assertUnlinkedConst(variable.constExpr,
3027 operators: [UnlinkedConstOperation.pushInt], ints: [0]);
2335 } 3028 }
2336 3029
2337 test_field_documented() { 3030 test_field_documented() {
2338 String text = ''' 3031 String text = '''
2339 class C { 3032 class C {
2340 /** 3033 /**
2341 * Docs 3034 * Docs
2342 */ 3035 */
2343 var v; 3036 var v;
2344 }'''; 3037 }''';
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 checkUnresolvedTypeRef( 3326 checkUnresolvedTypeRef(
2634 serializeTypeText('dynamic.T', allowErrors: true), 'dynamic', 'T'); 3327 serializeTypeText('dynamic.T', allowErrors: true), 'dynamic', 'T');
2635 } 3328 }
2636 3329
2637 test_invalid_prefix_type_parameter() { 3330 test_invalid_prefix_type_parameter() {
2638 if (checkAstDerivedData) { 3331 if (checkAstDerivedData) {
2639 // TODO(paulberry): get this to work properly. 3332 // TODO(paulberry): get this to work properly.
2640 return; 3333 return;
2641 } 3334 }
2642 checkUnresolvedTypeRef( 3335 checkUnresolvedTypeRef(
2643 serializeClassText('class C<T> { T.U x; }', allowErrors: true).fields[0] 3336 serializeClassText('class C<T> { T.U x; }', allowErrors: true)
3337 .fields[0]
2644 .type, 3338 .type,
2645 'T', 3339 'T',
2646 'U'); 3340 'U');
2647 } 3341 }
2648 3342
2649 test_invalid_prefix_void() { 3343 test_invalid_prefix_void() {
2650 if (checkAstDerivedData) { 3344 if (checkAstDerivedData) {
2651 // TODO(paulberry): get this to work properly. 3345 // TODO(paulberry): get this to work properly.
2652 return; 3346 return;
2653 } 3347 }
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
3266 expect(variable.isStatic, isFalse); 3960 expect(variable.isStatic, isFalse);
3267 } 3961 }
3268 3962
3269 test_variable_non_static_top_level() { 3963 test_variable_non_static_top_level() {
3270 // Top level variables are considered non-static. 3964 // Top level variables are considered non-static.
3271 UnlinkedVariable variable = 3965 UnlinkedVariable variable =
3272 serializeVariableText('int i;', variableName: 'i'); 3966 serializeVariableText('int i;', variableName: 'i');
3273 expect(variable.isStatic, isFalse); 3967 expect(variable.isStatic, isFalse);
3274 } 3968 }
3275 3969
3970 test_variable_private() {
3971 serializeVariableText('int _i;', variableName: '_i');
3972 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
3973 }
3974
3276 test_variable_static() { 3975 test_variable_static() {
3277 UnlinkedVariable variable = 3976 UnlinkedVariable variable =
3278 serializeClassText('class C { static int i; }').fields[0]; 3977 serializeClassText('class C { static int i; }').fields[0];
3279 expect(variable.isStatic, isTrue); 3978 expect(variable.isStatic, isTrue);
3280 } 3979 }
3281 3980
3282 test_variable_type() { 3981 test_variable_type() {
3283 UnlinkedVariable variable = 3982 UnlinkedVariable variable =
3284 serializeVariableText('int i;', variableName: 'i'); 3983 serializeVariableText('int i;', variableName: 'i');
3285 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 3984 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
3286 } 3985 }
3287 3986
3288 test_varible_private() { 3987 void _assertUnlinkedConst(UnlinkedConst constExpr,
3289 serializeVariableText('int _i;', variableName: '_i'); 3988 {List<UnlinkedConstOperation> operators,
3290 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 3989 List<int> ints: const <int>[],
3990 List<double> doubles: const <double>[],
3991 List<String> strings: const <String>[],
3992 List<_UnlinkedTypeRefValidator> referenceValidators:
3993 const <_UnlinkedTypeRefValidator>[]}) {
3994 expect(constExpr, isNotNull);
3995 expect(constExpr.operations, operators);
3996 expect(constExpr.ints, ints);
3997 expect(constExpr.doubles, doubles);
3998 expect(constExpr.strings, strings);
3999 expect(constExpr.references, hasLength(referenceValidators.length));
4000 for (int i = 0; i < referenceValidators.length; i++) {
4001 referenceValidators[i](constExpr.references[i]);
4002 }
3291 } 4003 }
3292 } 4004 }
3293 4005
3294 /** 4006 /**
3295 * Override of [SummaryTest] which creates unlinked summaries directly from the 4007 * Override of [SummaryTest] which creates unlinked summaries directly from the
3296 * AST. 4008 * AST.
3297 */ 4009 */
3298 @reflectiveTest 4010 @reflectiveTest
3299 class UnlinkedSummarizeAstTest extends Object with SummaryTest { 4011 class UnlinkedSummarizeAstTest extends Object with SummaryTest {
3300 @override 4012 @override
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3361 if (unit == null) { 4073 if (unit == null) {
3362 if (!allowMissingFiles) { 4074 if (!allowMissingFiles) {
3363 fail('Test referred to unknown unit $relativeUri'); 4075 fail('Test referred to unknown unit $relativeUri');
3364 } 4076 }
3365 } else { 4077 } else {
3366 unlinkedUnits.add(unit); 4078 unlinkedUnits.add(unit);
3367 } 4079 }
3368 } 4080 }
3369 } 4081 }
3370 4082
4083 @override
4084 void test_constExpr_invokeConstructor_named() {
4085 // TODO(scheglov) remove this method to enable the test
4086 }
4087
4088 @override
4089 void test_constExpr_invokeConstructor_named_imported() {
4090 // TODO(scheglov) remove this method to enable the test
4091 }
4092
4093 @override
4094 void test_constExpr_invokeConstructor_named_imported_withPrefix() {
4095 // TODO(scheglov) remove this method to enable the test
4096 }
4097
4098 @override
4099 void test_constExpr_invokeConstructor_unnamed() {
4100 // TODO(scheglov) remove this method to enable the test
4101 }
4102
4103 @override
4104 void test_constExpr_makeList_typed() {
4105 // TODO(scheglov) remove this method to enable the test
4106 }
4107
4108 @override
4109 void test_constExpr_makeList_untyped() {
4110 // TODO(scheglov) remove this method to enable the test
4111 }
4112
4113 @override
4114 void test_constExpr_makeMap_typed() {
4115 // TODO(scheglov) remove this method to enable the test
4116 }
4117
4118 @override
4119 void test_constExpr_makeMap_untyped() {
4120 // TODO(scheglov) remove this method to enable the test
4121 }
4122
4123 @override
4124 void test_constExpr_pushReference_class() {
4125 // TODO(scheglov) remove this method to enable the test
4126 }
4127
4128 @override
4129 void test_constExpr_pushReference_enum() {
4130 // TODO(scheglov) remove this method to enable the test
4131 }
4132
4133 @override
4134 void test_constExpr_pushReference_topLevelVariable_imported() {
4135 // TODO(scheglov) remove this method to enable the test
4136 }
4137
4138 @override
4139 void test_constExpr_pushReference_topLevelVariable_imported_withPrefix() {
4140 // TODO(scheglov) remove this method to enable the test
4141 }
4142
4143 @override
4144 void test_constExpr_pushReference_topLevelVariable_local() {
4145 // TODO(scheglov) remove this method to enable the test
4146 }
4147
3371 CompilationUnit _parseText(String text) { 4148 CompilationUnit _parseText(String text) {
3372 CharSequenceReader reader = new CharSequenceReader(text); 4149 CharSequenceReader reader = new CharSequenceReader(text);
3373 Scanner scanner = 4150 Scanner scanner =
3374 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); 4151 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER);
3375 Token token = scanner.tokenize(); 4152 Token token = scanner.tokenize();
3376 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); 4153 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER);
3377 parser.parseGenericMethods = true; 4154 parser.parseGenericMethods = true;
3378 return parser.parseCompilationUnit(token); 4155 return parser.parseCompilationUnit(token);
3379 } 4156 }
3380 } 4157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698