| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 /// Source information strategy that concurrently builds sourcemaps for each of |
| 6 /// child strategies. |
| 7 |
| 8 library dart2js.dual_source_information; |
| 9 |
| 10 import '../common.dart'; |
| 11 import '../elements/elements.dart'; |
| 12 import '../js/js_source_mapping.dart'; |
| 13 import '../js/js.dart' as js; |
| 14 import '../tree/nodes.dart'; |
| 15 import 'code_output.dart' show BufferedCodeOutput; |
| 16 import 'source_information.dart'; |
| 17 |
| 18 class MultiSourceInformationStrategy |
| 19 implements JavaScriptSourceInformationStrategy { |
| 20 final List<JavaScriptSourceInformationStrategy> strategies; |
| 21 |
| 22 const MultiSourceInformationStrategy(this.strategies); |
| 23 |
| 24 @override |
| 25 SourceInformationBuilder createBuilderForContext(ResolvedAst resolvedAst) { |
| 26 return new MultiSourceInformationBuilder( |
| 27 strategies.map((s) => s.createBuilderForContext(resolvedAst)).toList()); |
| 28 } |
| 29 |
| 30 @override |
| 31 void onComplete() { |
| 32 strategies.forEach((s) => s.onComplete()); |
| 33 } |
| 34 |
| 35 @override |
| 36 SourceInformation buildSourceMappedMarker() { |
| 37 return new MultiSourceInformation( |
| 38 strategies.map((s) => s.buildSourceMappedMarker()).toList()); |
| 39 } |
| 40 |
| 41 @override |
| 42 SourceInformationProcessor createProcessor( |
| 43 SourceMapperProvider sourceMapperProvider, |
| 44 SourceInformationReader reader) { |
| 45 return new MultiSourceInformationProcessor( |
| 46 new List<SourceInformationProcessor>.generate(strategies.length, |
| 47 (int index) { |
| 48 return strategies[index].createProcessor(sourceMapperProvider, |
| 49 new MultiSourceInformationReader(reader, index)); |
| 50 })); |
| 51 } |
| 52 } |
| 53 |
| 54 class MultiSourceInformationProcessor implements SourceInformationProcessor { |
| 55 final List<SourceInformationProcessor> processors; |
| 56 |
| 57 MultiSourceInformationProcessor(this.processors); |
| 58 |
| 59 @override |
| 60 void onStartPosition(js.Node node, int startPosition) { |
| 61 processors.forEach((p) => p.onStartPosition(node, startPosition)); |
| 62 } |
| 63 |
| 64 @override |
| 65 void onPositions( |
| 66 js.Node node, int startPosition, int endPosition, int closingPosition) { |
| 67 processors.forEach((p) => |
| 68 p.onPositions(node, startPosition, endPosition, closingPosition)); |
| 69 } |
| 70 |
| 71 @override |
| 72 void process(js.Node node, BufferedCodeOutput code) { |
| 73 processors.forEach((p) => p.process(node, code)); |
| 74 } |
| 75 } |
| 76 |
| 77 class MultiSourceInformationBuilder implements SourceInformationBuilder { |
| 78 final List<SourceInformationBuilder> builders; |
| 79 |
| 80 MultiSourceInformationBuilder(this.builders); |
| 81 |
| 82 @override |
| 83 SourceInformationBuilder forContext(ResolvedAst resolvedAst) { |
| 84 return new MultiSourceInformationBuilder( |
| 85 builders.map((b) => b.forContext(resolvedAst)).toList()); |
| 86 } |
| 87 |
| 88 @override |
| 89 SourceInformation buildSwitchCase(Node node) { |
| 90 return new MultiSourceInformation( |
| 91 builders.map((b) => b.buildSwitchCase(node)).toList()); |
| 92 } |
| 93 |
| 94 @override |
| 95 SourceInformation buildSwitch(Node node) { |
| 96 return new MultiSourceInformation( |
| 97 builders.map((b) => b.buildSwitch(node)).toList()); |
| 98 } |
| 99 |
| 100 @override |
| 101 SourceInformation buildAs(Node node) { |
| 102 return new MultiSourceInformation( |
| 103 builders.map((b) => b.buildAs(node)).toList()); |
| 104 } |
| 105 |
| 106 @override |
| 107 SourceInformation buildIs(Node node) { |
| 108 return new MultiSourceInformation( |
| 109 builders.map((b) => b.buildIs(node)).toList()); |
| 110 } |
| 111 |
| 112 @override |
| 113 SourceInformation buildCatch(Node node) { |
| 114 return new MultiSourceInformation( |
| 115 builders.map((b) => b.buildCatch(node)).toList()); |
| 116 } |
| 117 |
| 118 @override |
| 119 SourceInformation buildBinary(Node node) { |
| 120 return new MultiSourceInformation( |
| 121 builders.map((b) => b.buildBinary(node)).toList()); |
| 122 } |
| 123 |
| 124 @override |
| 125 SourceInformation buildIndexSet(Node node) { |
| 126 return new MultiSourceInformation( |
| 127 builders.map((b) => b.buildIndexSet(node)).toList()); |
| 128 } |
| 129 |
| 130 @override |
| 131 SourceInformation buildIndex(Node node) { |
| 132 return new MultiSourceInformation( |
| 133 builders.map((b) => b.buildIndex(node)).toList()); |
| 134 } |
| 135 |
| 136 @override |
| 137 SourceInformation buildForInSet(Node node) { |
| 138 return new MultiSourceInformation( |
| 139 builders.map((b) => b.buildForInSet(node)).toList()); |
| 140 } |
| 141 |
| 142 @override |
| 143 SourceInformation buildForInCurrent(Node node) { |
| 144 return new MultiSourceInformation( |
| 145 builders.map((b) => b.buildForInCurrent(node)).toList()); |
| 146 } |
| 147 |
| 148 @override |
| 149 SourceInformation buildForInMoveNext(Node node) { |
| 150 return new MultiSourceInformation( |
| 151 builders.map((b) => b.buildForInMoveNext(node)).toList()); |
| 152 } |
| 153 |
| 154 @override |
| 155 SourceInformation buildForInIterator(Node node) { |
| 156 return new MultiSourceInformation( |
| 157 builders.map((b) => b.buildForInIterator(node)).toList()); |
| 158 } |
| 159 |
| 160 @override |
| 161 SourceInformation buildStringInterpolation(Node node) { |
| 162 return new MultiSourceInformation( |
| 163 builders.map((b) => b.buildStringInterpolation(node)).toList()); |
| 164 } |
| 165 |
| 166 @override |
| 167 SourceInformation buildForeignCode(Node node) { |
| 168 return new MultiSourceInformation( |
| 169 builders.map((b) => b.buildForeignCode(node)).toList()); |
| 170 } |
| 171 |
| 172 @override |
| 173 SourceInformation buildVariableDeclaration() { |
| 174 return new MultiSourceInformation( |
| 175 builders.map((b) => b.buildVariableDeclaration()).toList()); |
| 176 } |
| 177 |
| 178 @override |
| 179 SourceInformation buildAssignment(Node node) { |
| 180 return new MultiSourceInformation( |
| 181 builders.map((b) => b.buildAssignment(node)).toList()); |
| 182 } |
| 183 |
| 184 @override |
| 185 SourceInformation buildThrow(Node node) { |
| 186 return new MultiSourceInformation( |
| 187 builders.map((b) => b.buildThrow(node)).toList()); |
| 188 } |
| 189 |
| 190 @override |
| 191 SourceInformation buildNew(Node node) { |
| 192 return new MultiSourceInformation( |
| 193 builders.map((b) => b.buildNew(node)).toList()); |
| 194 } |
| 195 |
| 196 @override |
| 197 SourceInformation buildIf(Node node) { |
| 198 return new MultiSourceInformation( |
| 199 builders.map((b) => b.buildIf(node)).toList()); |
| 200 } |
| 201 |
| 202 @override |
| 203 SourceInformation buildCall(Node receiver, Node call) { |
| 204 return new MultiSourceInformation( |
| 205 builders.map((b) => b.buildCall(receiver, call)).toList()); |
| 206 } |
| 207 |
| 208 @override |
| 209 SourceInformation buildGet(Node node) { |
| 210 return new MultiSourceInformation( |
| 211 builders.map((b) => b.buildGet(node)).toList()); |
| 212 } |
| 213 |
| 214 @override |
| 215 SourceInformation buildLoop(Node node) { |
| 216 return new MultiSourceInformation( |
| 217 builders.map((b) => b.buildLoop(node)).toList()); |
| 218 } |
| 219 |
| 220 @override |
| 221 SourceInformation buildImplicitReturn(AstElement element) { |
| 222 return new MultiSourceInformation( |
| 223 builders.map((b) => b.buildImplicitReturn(element)).toList()); |
| 224 } |
| 225 |
| 226 @override |
| 227 SourceInformation buildReturn(Node node) { |
| 228 return new MultiSourceInformation( |
| 229 builders.map((b) => b.buildReturn(node)).toList()); |
| 230 } |
| 231 |
| 232 @override |
| 233 SourceInformation buildCreate(Node node) { |
| 234 return new MultiSourceInformation( |
| 235 builders.map((b) => b.buildCreate(node)).toList()); |
| 236 } |
| 237 |
| 238 @override |
| 239 SourceInformation buildGeneric(Node node) { |
| 240 return new MultiSourceInformation( |
| 241 builders.map((b) => b.buildGeneric(node)).toList()); |
| 242 } |
| 243 |
| 244 @override |
| 245 SourceInformation buildDeclaration(ResolvedAst resolvedAst) { |
| 246 return new MultiSourceInformation( |
| 247 builders.map((b) => b.buildDeclaration(resolvedAst)).toList()); |
| 248 } |
| 249 } |
| 250 |
| 251 class MultiSourceInformation implements SourceInformation { |
| 252 final List<SourceInformation> infos; |
| 253 |
| 254 MultiSourceInformation(this.infos); |
| 255 |
| 256 @override |
| 257 String get shortText => infos.first?.shortText; |
| 258 |
| 259 @override |
| 260 List<SourceLocation> get sourceLocations => infos.first?.sourceLocations; |
| 261 |
| 262 @override |
| 263 SourceLocation get endPosition => infos.first?.endPosition; |
| 264 |
| 265 @override |
| 266 SourceLocation get closingPosition => infos.first?.closingPosition; |
| 267 |
| 268 @override |
| 269 SourceLocation get startPosition => infos.first?.startPosition; |
| 270 |
| 271 @override |
| 272 SourceSpan get sourceSpan => infos.first?.sourceSpan; |
| 273 |
| 274 String toString() => '$infos'; |
| 275 } |
| 276 |
| 277 class MultiSourceInformationReader implements SourceInformationReader { |
| 278 final SourceInformationReader reader; |
| 279 final int index; |
| 280 |
| 281 MultiSourceInformationReader(this.reader, this.index); |
| 282 |
| 283 @override |
| 284 SourceInformation getSourceInformation(js.Node node) { |
| 285 MultiSourceInformation sourceInformation = |
| 286 reader.getSourceInformation(node); |
| 287 if (sourceInformation == null) return null; |
| 288 return sourceInformation.infos[index]; |
| 289 } |
| 290 } |
| OLD | NEW |