Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1616143003: Lower map literals to constructor or function calls in builder (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library dart2js.ir_builder_task; 5 library dart2js.ir_builder_task;
6 6
7 import '../closure.dart' as closure; 7 import '../closure.dart' as closure;
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/names.dart' show 9 import '../common/names.dart' show
10 Names, 10 Names,
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 InterfaceType type = elements.getType(node); 1327 InterfaceType type = elements.getType(node);
1328 return irBuilder.buildListLiteral(type, values, 1328 return irBuilder.buildListLiteral(type, values,
1329 allocationSiteType: getAllocationSiteType(node)); 1329 allocationSiteType: getAllocationSiteType(node));
1330 } 1330 }
1331 1331
1332 ir.Primitive visitLiteralMap(ast.LiteralMap node) { 1332 ir.Primitive visitLiteralMap(ast.LiteralMap node) {
1333 assert(irBuilder.isOpen); 1333 assert(irBuilder.isOpen);
1334 if (node.isConst) { 1334 if (node.isConst) {
1335 return translateConstant(node); 1335 return translateConstant(node);
1336 } 1336 }
1337
1337 InterfaceType type = elements.getType(node); 1338 InterfaceType type = elements.getType(node);
1338 List<ir.LiteralMapEntry> entries = 1339
1339 node.entries.nodes.mapToList((ast.LiteralMapEntry e) { 1340 if (node.entries.nodes.isEmpty) {
1340 return new ir.LiteralMapEntry(visit(e.key), visit(e.value)); 1341 if (type.treatAsRaw) {
1341 }); 1342 return irBuilder.buildStaticFunctionInvocation(
1342 return irBuilder.addPrimitive(new ir.LiteralMap(type, entries)); 1343 helpers.mapLiteralUntypedEmptyMaker,
1344 <ir.Primitive>[],
1345 sourceInformation: sourceInformationBuilder.buildNew(node));
1346 } else {
1347 ConstructorElement constructor = helpers.mapLiteralConstructorEmpty;
1348 return irBuilder.buildConstructorInvocation(
1349 constructor.effectiveTarget,
1350 CallStructure.NO_ARGS,
1351 constructor.computeEffectiveTargetType(type),
1352 <ir.Primitive>[],
1353 sourceInformationBuilder.buildNew(node));
1354 }
1355 }
1356
1357 List<ir.Primitive> keysAndValues = <ir.Primitive>[];
1358 for (ast.LiteralMapEntry entry in node.entries.nodes.toList()) {
1359 keysAndValues.add(visit(entry.key));
1360 keysAndValues.add(visit(entry.value));
1361 }
1362 ir.Primitive keysAndValuesList =
1363 irBuilder.buildListLiteral(null, keysAndValues);
1364
1365 if (type.treatAsRaw) {
1366 return irBuilder.buildStaticFunctionInvocation(
1367 helpers.mapLiteralUntypedMaker,
1368 <ir.Primitive>[keysAndValuesList],
1369 sourceInformation: sourceInformationBuilder.buildNew(node));
1370 } else {
1371 ConstructorElement constructor = helpers.mapLiteralConstructor;
1372 return irBuilder.buildConstructorInvocation(
1373 constructor.effectiveTarget,
1374 CallStructure.ONE_ARG,
1375 constructor.computeEffectiveTargetType(type),
1376 <ir.Primitive>[keysAndValuesList],
1377 sourceInformationBuilder.buildNew(node));
1378 }
1343 } 1379 }
1344 1380
1345 ir.Primitive visitLiteralSymbol(ast.LiteralSymbol node) { 1381 ir.Primitive visitLiteralSymbol(ast.LiteralSymbol node) {
1346 assert(irBuilder.isOpen); 1382 assert(irBuilder.isOpen);
1347 return translateConstant(node); 1383 return translateConstant(node);
1348 } 1384 }
1349 1385
1350 ir.Primitive visitParenthesizedExpression( 1386 ir.Primitive visitParenthesizedExpression(
1351 ast.ParenthesizedExpression node) { 1387 ast.ParenthesizedExpression node) {
1352 assert(irBuilder.isOpen); 1388 assert(irBuilder.isOpen);
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3553 } 3589 }
3554 3590
3555 Element get closureConverter { 3591 Element get closureConverter {
3556 return _backend.helpers.closureConverter; 3592 return _backend.helpers.closureConverter;
3557 } 3593 }
3558 3594
3559 void addNativeMethod(FunctionElement function) { 3595 void addNativeMethod(FunctionElement function) {
3560 _backend.emitter.nativeEmitter.nativeMethods.add(function); 3596 _backend.emitter.nativeEmitter.nativeMethods.add(function);
3561 } 3597 }
3562 } 3598 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698