Chromium Code Reviews| 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 |
| 11 /// A list of JS expressions that represent metadata, parameter names and | 11 /// A list of JS expressions that represent metadata, parameter names and |
| 12 /// type, and return types. | 12 /// type variable types. |
| 13 final List<String> globalMetadata = []; | 13 final List<String> globalMetadata = []; |
| 14 | 14 |
| 15 /// A map used to canonicalize the entries of globalMetadata. | 15 /// A map used to canonicalize the entries of globalMetadata. |
| 16 final Map<String, int> _globalMetadataMap = <String, int>{}; | 16 final Map<String, int> _globalMetadataMap = <String, int>{}; |
| 17 | 17 |
| 18 /// A list of JS expression representing types including function types and | |
| 19 /// typedefs. | |
| 20 final List<String> types = []; | |
|
floitsch
2015/03/06 12:48:50
Make it typed? (same for the globalMetadata)
zarah
2015/03/06 13:05:51
Done.
| |
| 21 | |
| 22 /// A map used to canonicalize the entries of types. | |
| 23 final Map<String, int> _typesMap = <String, int>{}; | |
| 24 | |
| 18 MetadataCollector(this._compiler, this._emitter); | 25 MetadataCollector(this._compiler, this._emitter); |
| 19 | 26 |
| 20 JavaScriptBackend get _backend => _compiler.backend; | 27 JavaScriptBackend get _backend => _compiler.backend; |
| 21 TypeVariableHandler get _typeVariableHandler => _backend.typeVariableHandler; | 28 TypeVariableHandler get _typeVariableHandler => _backend.typeVariableHandler; |
| 22 | 29 |
| 23 bool _mustEmitMetadataFor(Element element) { | 30 bool _mustEmitMetadataFor(Element element) { |
| 24 return _backend.mustRetainMetadata && | 31 return _backend.mustRetainMetadata && |
| 25 _backend.referencedFromMirrorSystem(element); | 32 _backend.referencedFromMirrorSystem(element); |
| 26 } | 33 } |
| 27 | 34 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 type, | 96 type, |
| 90 (variable) { | 97 (variable) { |
| 91 return js.number( | 98 return js.number( |
| 92 _typeVariableHandler.reifyTypeVariable( | 99 _typeVariableHandler.reifyTypeVariable( |
| 93 variable.element)); | 100 variable.element)); |
| 94 }, | 101 }, |
| 95 (TypedefType typedef) { | 102 (TypedefType typedef) { |
| 96 return _backend.isAccessibleByReflection(typedef.element); | 103 return _backend.isAccessibleByReflection(typedef.element); |
| 97 }); | 104 }); |
| 98 | 105 |
| 99 return addGlobalMetadata( | 106 return addType( |
| 100 jsAst.prettyPrint(representation, _compiler).getText()); | 107 jsAst.prettyPrint(representation, _compiler).getText()); |
| 101 } | 108 } |
| 102 | 109 |
| 103 int reifyName(String name) { | 110 int reifyName(String name) { |
| 104 return addGlobalMetadata('"$name"'); | 111 return addGlobalMetadata('"$name"'); |
| 105 } | 112 } |
| 106 | 113 |
| 107 int addGlobalMetadata(String string) { | 114 int addGlobalMetadata(String string) { |
| 108 return _globalMetadataMap.putIfAbsent(string, () { | 115 return _globalMetadataMap.putIfAbsent(string, () { |
| 109 globalMetadata.add(string); | 116 globalMetadata.add(string); |
| 110 return globalMetadata.length - 1; | 117 return globalMetadata.length - 1; |
| 111 }); | 118 }); |
| 112 } | 119 } |
| 113 | 120 |
| 121 int addType(String string) { | |
|
floitsch
2015/03/06 12:48:50
Not this CL, but we should consider storing the js
floitsch
2015/03/06 12:48:50
s/string/code
s/string/compiledType
?
zarah
2015/03/06 13:05:51
Acknowledged.
zarah
2015/03/06 13:05:52
I like compiledType.
| |
| 122 return _typesMap.putIfAbsent(string, () { | |
| 123 types.add(string); | |
| 124 return types.length - 1; | |
| 125 }); | |
| 126 } | |
| 127 | |
| 114 List<int> computeMetadata(FunctionElement element) { | 128 List<int> computeMetadata(FunctionElement element) { |
| 115 return _compiler.withCurrentElement(element, () { | 129 return _compiler.withCurrentElement(element, () { |
| 116 if (!_mustEmitMetadataFor(element)) return const <int>[]; | 130 if (!_mustEmitMetadataFor(element)) return const <int>[]; |
| 117 List<int> metadata = <int>[]; | 131 List<int> metadata = <int>[]; |
| 118 Link link = element.metadata; | 132 Link link = element.metadata; |
| 119 // TODO(ahe): Why is metadata sometimes null? | 133 // TODO(ahe): Why is metadata sometimes null? |
| 120 if (link != null) { | 134 if (link != null) { |
| 121 for (; !link.isEmpty; link = link.tail) { | 135 for (; !link.isEmpty; link = link.tail) { |
| 122 metadata.add(reifyMetadata(link.head)); | 136 metadata.add(reifyMetadata(link.head)); |
| 123 } | 137 } |
| 124 } | 138 } |
| 125 return metadata; | 139 return metadata; |
| 126 }); | 140 }); |
| 127 } | 141 } |
| 128 } | 142 } |
| OLD | NEW |