| OLD | NEW |
| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 7 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
| 8 final Set<HInstruction> boundsChecked; | 8 final Set<HInstruction> boundsChecked; |
| 9 | 9 |
| 10 JavaScriptItemCompilationContext() | 10 JavaScriptItemCompilationContext() |
| (...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 /// Should [name] be retained for reflection? | 1413 /// Should [name] be retained for reflection? |
| 1414 bool shouldRetainName(SourceString name) { | 1414 bool shouldRetainName(SourceString name) { |
| 1415 if (hasInsufficientMirrorsUsed) return mustPreserveNames; | 1415 if (hasInsufficientMirrorsUsed) return mustPreserveNames; |
| 1416 if (name == const SourceString('')) return false; | 1416 if (name == const SourceString('')) return false; |
| 1417 return symbolsUsed.contains(name.slowToString()); | 1417 return symbolsUsed.contains(name.slowToString()); |
| 1418 } | 1418 } |
| 1419 | 1419 |
| 1420 bool get rememberLazies => isTreeShakingDisabled; | 1420 bool get rememberLazies => isTreeShakingDisabled; |
| 1421 | 1421 |
| 1422 bool retainMetadataOf(Element element) { | 1422 bool retainMetadataOf(Element element) { |
| 1423 if (mustRetainMetadata) { | 1423 if (mustRetainMetadata) hasRetainedMetadata = true; |
| 1424 // TODO(ahe): This is a little hacky, but I'll have to rewrite this when | 1424 if (mustRetainMetadata && isNeededForReflection(element)) { |
| 1425 // implementing @MirrorsUsed anyways. | 1425 for (MetadataAnnotation metadata in element.metadata) { |
| 1426 compiler.constantHandler.compiledConstants.addAll( | 1426 metadata.value.accept(new ConstantCopier(compiler.constantHandler)); |
| 1427 compiler.metadataHandler.compiledConstants); | 1427 } |
| 1428 compiler.metadataHandler.compiledConstants.clear(); | 1428 return true; |
| 1429 } | 1429 } |
| 1430 if (mustRetainMetadata) hasRetainedMetadata = true; | 1430 return false; |
| 1431 return mustRetainMetadata; | |
| 1432 } | 1431 } |
| 1433 | 1432 |
| 1434 void onLibraryScanned(LibraryElement library, Uri uri) { | 1433 void onLibraryScanned(LibraryElement library, Uri uri) { |
| 1435 if (uri == Uri.parse('dart:_js_mirrors')) { | 1434 if (uri == Uri.parse('dart:_js_mirrors')) { |
| 1436 disableTreeShakingMarker = | 1435 disableTreeShakingMarker = |
| 1437 library.find(const SourceString('disableTreeShaking')); | 1436 library.find(const SourceString('disableTreeShaking')); |
| 1438 preserveMetadataMarker = | 1437 preserveMetadataMarker = |
| 1439 library.find(const SourceString('preserveMetadata')); | 1438 library.find(const SourceString('preserveMetadata')); |
| 1440 } else if (uri == Uri.parse('dart:_js_names')) { | 1439 } else if (uri == Uri.parse('dart:_js_names')) { |
| 1441 preserveNamesMarker = | 1440 preserveNamesMarker = |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 } | 1501 } |
| 1503 return true; | 1502 return true; |
| 1504 } | 1503 } |
| 1505 | 1504 |
| 1506 if (!metaTargetsUsed.isEmpty) { | 1505 if (!metaTargetsUsed.isEmpty) { |
| 1507 // TODO(ahe): Implement this. | 1506 // TODO(ahe): Implement this. |
| 1508 return registerNameOf(element); | 1507 return registerNameOf(element); |
| 1509 } | 1508 } |
| 1510 | 1509 |
| 1511 if (!targetsUsed.isEmpty) { | 1510 if (!targetsUsed.isEmpty) { |
| 1512 for (Element e = element; e != null; e = e.enclosingElement) { | 1511 if (targetsUsed.contains(element)) return registerNameOf(element); |
| 1513 if (targetsUsed.contains(e)) return registerNameOf(element); | 1512 Element enclosing = element.enclosingElement; |
| 1513 if (enclosing != null && isNeededForReflection(enclosing)) { |
| 1514 return registerNameOf(element); |
| 1514 } | 1515 } |
| 1515 } | 1516 } |
| 1517 |
| 1518 if (element is ClosureClassElement) { |
| 1519 // TODO(ahe): Try to fix the enclosing element of ClosureClassElement |
| 1520 // instead. |
| 1521 ClosureClassElement closureClass = element; |
| 1522 if (isNeededForReflection(closureClass.methodElement)) { |
| 1523 return registerNameOf(element); |
| 1524 } |
| 1525 } |
| 1526 |
| 1516 return false; | 1527 return false; |
| 1517 } | 1528 } |
| 1518 } | 1529 } |
| 1519 | 1530 |
| 1520 /// Records that [type] is used by [user.element]. | 1531 /// Records that [type] is used by [user.element]. |
| 1521 class Dependency { | 1532 class Dependency { |
| 1522 final DartType type; | 1533 final DartType type; |
| 1523 final TreeElements user; | 1534 final TreeElements user; |
| 1524 | 1535 |
| 1525 const Dependency(this.type, this.user); | 1536 const Dependency(this.type, this.user); |
| 1526 } | 1537 } |
| 1538 |
| 1539 /// Used to copy metadata to the the actual constant handler. |
| 1540 class ConstantCopier implements ConstantVisitor { |
| 1541 final ConstantHandler target; |
| 1542 |
| 1543 ConstantCopier(this.target); |
| 1544 |
| 1545 void copy(/* Constant or List<Constant> */ value) { |
| 1546 if (value is Constant) { |
| 1547 target.compiledConstants.add(value); |
| 1548 } else { |
| 1549 target.compiledConstants.addAll(value); |
| 1550 } |
| 1551 } |
| 1552 |
| 1553 void visitFunction(FunctionConstant constant) => copy(constant); |
| 1554 |
| 1555 void visitNull(NullConstant constant) => copy(constant); |
| 1556 |
| 1557 void visitInt(IntConstant constant) => copy(constant); |
| 1558 |
| 1559 void visitDouble(DoubleConstant constant) => copy(constant); |
| 1560 |
| 1561 void visitTrue(TrueConstant constant) => copy(constant); |
| 1562 |
| 1563 void visitFalse(FalseConstant constant) => copy(constant); |
| 1564 |
| 1565 void visitString(StringConstant constant) => copy(constant); |
| 1566 |
| 1567 void visitType(TypeConstant constant) => copy(constant); |
| 1568 |
| 1569 void visitInterceptor(InterceptorConstant constant) => copy(constant); |
| 1570 |
| 1571 void visitList(ListConstant constant) { |
| 1572 copy(constant.entries); |
| 1573 copy(constant); |
| 1574 } |
| 1575 void visitMap(MapConstant constant) { |
| 1576 copy(constant.keys); |
| 1577 copy(constant.values); |
| 1578 copy(constant.protoValue); |
| 1579 copy(constant); |
| 1580 } |
| 1581 |
| 1582 void visitConstructed(ConstructedConstant constant) { |
| 1583 copy(constant.fields); |
| 1584 copy(constant); |
| 1585 } |
| 1586 } |
| OLD | NEW |