| 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 dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Generates the code for all used classes in the program. Static fields (even | 8 * Generates the code for all used classes in the program. Static fields (even |
| 9 * in classes) are ignored, since they can be treated as non-class elements. | 9 * in classes) are ignored, since they can be treated as non-class elements. |
| 10 * | 10 * |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 /// type, and return types. | 42 /// type, and return types. |
| 43 final List<String> globalMetadata = []; | 43 final List<String> globalMetadata = []; |
| 44 | 44 |
| 45 /// A map used to canonicalize the entries of globalMetadata. | 45 /// A map used to canonicalize the entries of globalMetadata. |
| 46 final Map<String, int> globalMetadataMap = <String, int>{}; | 46 final Map<String, int> globalMetadataMap = <String, int>{}; |
| 47 | 47 |
| 48 // TODO(ngeoffray): remove this field. | 48 // TODO(ngeoffray): remove this field. |
| 49 Set<ClassElement> instantiatedClasses; | 49 Set<ClassElement> instantiatedClasses; |
| 50 | 50 |
| 51 JavaScriptBackend get backend => compiler.backend; | 51 JavaScriptBackend get backend => compiler.backend; |
| 52 TypeVariableHandler get typeVariableHandler => backend.typeVariableHandler; |
| 52 | 53 |
| 53 String get _ => space; | 54 String get _ => space; |
| 54 String get space => compiler.enableMinification ? "" : " "; | 55 String get space => compiler.enableMinification ? "" : " "; |
| 55 String get n => compiler.enableMinification ? "" : "\n"; | 56 String get n => compiler.enableMinification ? "" : "\n"; |
| 56 String get N => compiler.enableMinification ? "\n" : ";\n"; | 57 String get N => compiler.enableMinification ? "\n" : ";\n"; |
| 57 | 58 |
| 58 /** | 59 /** |
| 59 * List of expressions and statements that will be included in the | 60 * List of expressions and statements that will be included in the |
| 60 * precompiled function. | 61 * precompiled function. |
| 61 * | 62 * |
| (...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 if (value == null) { | 1615 if (value == null) { |
| 1615 compiler.reportInternalError( | 1616 compiler.reportInternalError( |
| 1616 annotation, 'Internal error: value is null'); | 1617 annotation, 'Internal error: value is null'); |
| 1617 return -1; | 1618 return -1; |
| 1618 } | 1619 } |
| 1619 return addGlobalMetadata( | 1620 return addGlobalMetadata( |
| 1620 jsAst.prettyPrint(constantReference(value), compiler).getText()); | 1621 jsAst.prettyPrint(constantReference(value), compiler).getText()); |
| 1621 } | 1622 } |
| 1622 | 1623 |
| 1623 int reifyType(DartType type) { | 1624 int reifyType(DartType type) { |
| 1624 // TODO(ahe): Handle type variables correctly instead of using "#". | 1625 jsAst.Expression representation = |
| 1625 String representation = backend.rti.getTypeRepresentation(type, (_) {}); | 1626 backend.rti.getTypeRepresentation(type, (variable) { |
| 1626 return addGlobalMetadata(representation.replaceAll('#', 'null')); | 1627 return js.toExpression( |
| 1628 typeVariableHandler.reifyTypeVariable(variable.element)); |
| 1629 }); |
| 1630 |
| 1631 return addGlobalMetadata( |
| 1632 jsAst.prettyPrint(representation, compiler).getText()); |
| 1627 } | 1633 } |
| 1628 | 1634 |
| 1629 int reifyName(SourceString name) { | 1635 int reifyName(SourceString name) { |
| 1630 return addGlobalMetadata('"${name.slowToString()}"'); | 1636 return addGlobalMetadata('"${name.slowToString()}"'); |
| 1631 } | 1637 } |
| 1632 | 1638 |
| 1633 int addGlobalMetadata(String string) { | 1639 int addGlobalMetadata(String string) { |
| 1634 return globalMetadataMap.putIfAbsent(string, () { | 1640 return globalMetadataMap.putIfAbsent(string, () { |
| 1635 globalMetadata.add(string); | 1641 globalMetadata.add(string); |
| 1636 return globalMetadata.length - 1; | 1642 return globalMetadata.length - 1; |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2146 return compiler.deferredLoadTask.isDeferred(element); | 2152 return compiler.deferredLoadTask.isDeferred(element); |
| 2147 } | 2153 } |
| 2148 | 2154 |
| 2149 bool get areAnyElementsDeferred { | 2155 bool get areAnyElementsDeferred { |
| 2150 return compiler.deferredLoadTask.areAnyElementsDeferred; | 2156 return compiler.deferredLoadTask.areAnyElementsDeferred; |
| 2151 } | 2157 } |
| 2152 } | 2158 } |
| 2153 | 2159 |
| 2154 // TODO(ahe): Move code for interceptors to own file. | 2160 // TODO(ahe): Move code for interceptors to own file. |
| 2155 // TODO(ahe): Move code for reifying metadata/types to own file. | 2161 // TODO(ahe): Move code for reifying metadata/types to own file. |
| OLD | NEW |