| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 class MetadataCollector { | 7 class MetadataCollector { |
| 8 final Compiler _compiler; | 8 final Compiler _compiler; |
| 9 final Emitter _emitter; | 9 final Emitter _emitter; |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 (variable) { | 105 (variable) { |
| 106 if (ignoreTypeVariables) return new jsAst.LiteralNull(); | 106 if (ignoreTypeVariables) return new jsAst.LiteralNull(); |
| 107 return js.number( | 107 return js.number( |
| 108 _typeVariableHandler.reifyTypeVariable( | 108 _typeVariableHandler.reifyTypeVariable( |
| 109 variable.element)); | 109 variable.element)); |
| 110 }, | 110 }, |
| 111 (TypedefType typedef) { | 111 (TypedefType typedef) { |
| 112 return _backend.isAccessibleByReflection(typedef.element); | 112 return _backend.isAccessibleByReflection(typedef.element); |
| 113 }); | 113 }); |
| 114 | 114 |
| 115 if (representation is jsAst.LiteralString) { |
| 116 // We don't want the representation to be a string, since we use |
| 117 // strings as indicator for non-initialized types in the lazy emitter. |
| 118 _compiler.internalError( |
| 119 NO_LOCATION_SPANNABLE, 'reified types should not be strings.'); |
| 120 } |
| 115 return addTypeInOutputUnit( | 121 return addTypeInOutputUnit( |
| 116 jsAst.prettyPrint(representation, _compiler).getText(), outputUnit); | 122 jsAst.prettyPrint(representation, _compiler).getText(), outputUnit); |
| 117 } | 123 } |
| 118 | 124 |
| 119 int reifyName(String name) { | 125 int reifyName(String name) { |
| 120 return addGlobalMetadata('"$name"'); | 126 return addGlobalMetadata('"$name"'); |
| 121 } | 127 } |
| 122 | 128 |
| 123 int addGlobalMetadata(String string) { | 129 int addGlobalMetadata(String string) { |
| 124 return _globalMetadataMap.putIfAbsent(string, () { | 130 return _globalMetadataMap.putIfAbsent(string, () { |
| 125 globalMetadata.add(string); | 131 globalMetadata.add(string); |
| 126 return globalMetadata.length - 1; | 132 return globalMetadata.length - 1; |
| 127 }); | 133 }); |
| 128 } | 134 } |
| 129 | 135 |
| 130 int addTypeInOutputUnit(String compiledType, OutputUnit outputUnit) { | 136 int addTypeInOutputUnit(String compiledType, OutputUnit outputUnit) { |
| 131 if (_typesMap[outputUnit] == null) { | 137 if (_typesMap[outputUnit] == null) { |
| 132 _typesMap[outputUnit] = <String, int>{}; | 138 _typesMap[outputUnit] = <String, int>{}; |
| 133 } | 139 } |
| 134 return _typesMap[outputUnit].putIfAbsent(compiledType, () { | 140 return _typesMap[outputUnit].putIfAbsent(compiledType, () { |
| 135 | 141 |
| 136 if (types[outputUnit] == null) | 142 if (types[outputUnit] == null) { |
| 137 types[outputUnit] = <String>[]; | 143 types[outputUnit] = <String>[]; |
| 144 } |
| 138 | 145 |
| 139 types[outputUnit].add(compiledType); | 146 types[outputUnit].add(compiledType); |
| 140 return types[outputUnit].length - 1; | 147 return types[outputUnit].length - 1; |
| 141 }); | 148 }); |
| 142 } | 149 } |
| 143 | 150 |
| 144 List<int> computeMetadata(FunctionElement element) { | 151 List<int> computeMetadata(FunctionElement element) { |
| 145 return _compiler.withCurrentElement(element, () { | 152 return _compiler.withCurrentElement(element, () { |
| 146 if (!_mustEmitMetadataFor(element)) return const <int>[]; | 153 if (!_mustEmitMetadataFor(element)) return const <int>[]; |
| 147 List<int> metadata = <int>[]; | 154 List<int> metadata = <int>[]; |
| 148 Link link = element.metadata; | 155 Link link = element.metadata; |
| 149 // TODO(ahe): Why is metadata sometimes null? | 156 // TODO(ahe): Why is metadata sometimes null? |
| 150 if (link != null) { | 157 if (link != null) { |
| 151 for (; !link.isEmpty; link = link.tail) { | 158 for (; !link.isEmpty; link = link.tail) { |
| 152 metadata.add(reifyMetadata(link.head)); | 159 metadata.add(reifyMetadata(link.head)); |
| 153 } | 160 } |
| 154 } | 161 } |
| 155 return metadata; | 162 return metadata; |
| 156 }); | 163 }); |
| 157 } | 164 } |
| 158 } | 165 } |
| OLD | NEW |