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 js_backend; | 5 part of js_backend; |
6 | 6 |
7 /** | 7 /** |
8 * Handles construction of TypeVariable constants needed at runtime. | 8 * Handles construction of TypeVariable constants needed at runtime. |
9 */ | 9 */ |
10 class TypeVariableHandler { | 10 class TypeVariableHandler { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 /** | 118 /** |
119 * Adds [c] to [emitter.metadataCollector] and returns the index pointing to | 119 * Adds [c] to [emitter.metadataCollector] and returns the index pointing to |
120 * the entry. | 120 * the entry. |
121 * | 121 * |
122 * If the corresponding type variable has already been encountered an | 122 * If the corresponding type variable has already been encountered an |
123 * entry in the list has already been reserved and the constant is added | 123 * entry in the list has already been reserved and the constant is added |
124 * there, otherwise a new entry for [c] is created. | 124 * there, otherwise a new entry for [c] is created. |
125 */ | 125 */ |
126 int _reifyTypeVariableConstant(ConstantValue c, TypeVariableElement variable)
{ | 126 int _reifyTypeVariableConstant(ConstantValue c, TypeVariableElement variable)
{ |
127 String name = jsAst.prettyPrint(_task.constantReference(c), | 127 jsAst.Expression name = _task.constantReference(c); |
128 _compiler).getText(); | |
129 int index; | 128 int index; |
130 if (_typeVariableConstants.containsKey(variable)) { | 129 if (_typeVariableConstants.containsKey(variable)) { |
131 index = _typeVariableConstants[variable]; | 130 index = _typeVariableConstants[variable]; |
132 _metadataCollector.globalMetadata[index] = name; | 131 _metadataCollector.globalMetadata[index] = name; |
133 } else { | 132 } else { |
134 index = _metadataCollector.addGlobalMetadata(name); | 133 index = _metadataCollector.addGlobalMetadata(name); |
135 _typeVariableConstants[variable] = index; | 134 _typeVariableConstants[variable] = index; |
136 } | 135 } |
137 return index; | 136 return index; |
138 } | 137 } |
139 | 138 |
140 /** | 139 /** |
141 * Returns the index pointing to the constant in [emitter.metadataCollector] | 140 * Returns the index pointing to the constant in [emitter.metadataCollector] |
142 * representing this type variable. | 141 * representing this type variable. |
143 * | 142 * |
144 * If the constant has not yet been constructed, an entry is allocated in | 143 * If the constant has not yet been constructed, an entry is allocated in |
145 * the global metadata list and the index pointing to this entry is returned. | 144 * the global metadata list and the index pointing to this entry is returned. |
146 * When the corresponding constant is constructed later, | 145 * When the corresponding constant is constructed later, |
147 * [reifyTypeVariableConstant] will be called and the constant will be added | 146 * [reifyTypeVariableConstant] will be called and the constant will be added |
148 * on the allocated entry. | 147 * on the allocated entry. |
149 */ | 148 */ |
150 int reifyTypeVariable(TypeVariableElement variable) { | 149 int reifyTypeVariable(TypeVariableElement variable) { |
151 if (_typeVariableConstants.containsKey(variable)) { | 150 if (_typeVariableConstants.containsKey(variable)) { |
152 return _typeVariableConstants[variable]; | 151 return _typeVariableConstants[variable]; |
153 } | 152 } |
154 | 153 |
155 // TODO(15613): Remove quotes. | 154 // TODO(15613): Remove quotes. |
156 _metadataCollector.globalMetadata.add('"Placeholder for ${variable}"'); | 155 _metadataCollector.globalMetadata.add(js('"Placeholder for ${variable}"')); |
157 return _typeVariableConstants[variable] = | 156 return _typeVariableConstants[variable] = |
158 _metadataCollector.globalMetadata.length - 1; | 157 _metadataCollector.globalMetadata.length - 1; |
159 } | 158 } |
160 | 159 |
161 List<int> typeVariablesOf(ClassElement classElement) { | 160 List<int> typeVariablesOf(ClassElement classElement) { |
162 List<int> result = _typeVariables[classElement]; | 161 List<int> result = _typeVariables[classElement]; |
163 if (result == null) { | 162 if (result == null) { |
164 result = const <int>[]; | 163 result = const <int>[]; |
165 } | 164 } |
166 return result; | 165 return result; |
167 } | 166 } |
168 } | 167 } |
OLD | NEW |