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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 228293008: Redo "Construct literal maps using factory constructor." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add constructors to mock libraries for dart2js tests Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 ssa; 5 part of ssa;
6 6
7 /** 7 /**
8 * A special element for the extra parameter taken by intercepted 8 * A special element for the extra parameter taken by intercepted
9 * methods. We need to implement [TypedElement.type] because our 9 * methods. We need to implement [TypedElement.type] because our
10 * optimizers may look at its declared type. 10 * optimizers may look at its declared type.
(...skipping 5021 matching lines...) Expand 10 before | Expand all | Expand 10 after
5032 joinBlock); 5032 joinBlock);
5033 } 5033 }
5034 handler.close(); 5034 handler.close();
5035 } 5035 }
5036 5036
5037 visitLiteralMap(ast.LiteralMap node) { 5037 visitLiteralMap(ast.LiteralMap node) {
5038 if (node.isConst()) { 5038 if (node.isConst()) {
5039 stack.add(addConstant(node)); 5039 stack.add(addConstant(node));
5040 return; 5040 return;
5041 } 5041 }
5042 List<HInstruction> inputs = <HInstruction>[]; 5042 List<HInstruction> listInputs = <HInstruction>[];
5043 for (Link<ast.Node> link = node.entries.nodes; 5043 for (Link<ast.Node> link = node.entries.nodes;
5044 !link.isEmpty; 5044 !link.isEmpty;
5045 link = link.tail) { 5045 link = link.tail) {
5046 visit(link.head); 5046 visit(link.head);
5047 inputs.add(pop()); 5047 listInputs.add(pop());
5048 inputs.add(pop()); 5048 listInputs.add(pop());
5049 } 5049 }
5050 HLiteralList keyValuePairs = buildLiteralList(inputs); 5050
5051 add(keyValuePairs); 5051 Element constructor;
5052 List<HInstruction> inputs = <HInstruction>[];
5053
5054 if (listInputs.isEmpty) {
5055 constructor = backend.mapLiteralConstructorEmpty;
5056 } else {
5057 constructor = backend.mapLiteralConstructor;
5058 HLiteralList keyValuePairs = buildLiteralList(listInputs);
5059 add(keyValuePairs);
5060 inputs.add(keyValuePairs);
5061 }
5062
5063 assert(constructor.isFactoryConstructor());
5064
5065 FunctionElement functionElement = constructor;
5066 constructor = functionElement.redirectionTarget;
5067
5068 InterfaceType type = elements.getType(node);
5069 InterfaceType expectedType = functionElement.computeTargetType(type);
5070
5071 if (constructor.isFactoryConstructor()) {
5072 compiler.enqueuer.codegen.registerFactoryWithTypeArguments(elements);
5073 }
5074
5075 ClassElement cls = constructor.getEnclosingClass();
5076
5077 if (backend.classNeedsRti(cls)) {
5078 Link<DartType> typeVariable = cls.typeVariables;
5079 expectedType.typeArguments.forEach((DartType argument) {
5080 inputs.add(analyzeTypeArgument(argument));
5081 typeVariable = typeVariable.tail;
5082 });
5083 assert(typeVariable.isEmpty);
5084 }
5085
5086 // The instruction type will always be a subtype of the mapLiteralClass, but
5087 // type inference might discover a more specific type, or find nothing (in
5088 // dart2js unit tests).
5052 TypeMask mapType = new TypeMask.nonNullSubtype(backend.mapLiteralClass); 5089 TypeMask mapType = new TypeMask.nonNullSubtype(backend.mapLiteralClass);
5053 pushInvokeStatic(node, backend.getMapMaker(), [keyValuePairs], mapType); 5090 TypeMask returnTypeMask = TypeMaskFactory.inferredReturnTypeForElement(
5054 stack.add(setRtiIfNeeded(pop(), node)); 5091 constructor, compiler);
5092 TypeMask instructionType = mapType.intersection(returnTypeMask, compiler);
5093
5094 addInlinedInstantiation(expectedType);
5095 pushInvokeStatic(node, constructor, inputs, instructionType);
5096 removeInlinedInstantiation(expectedType);
5055 } 5097 }
5056 5098
5057 visitLiteralMapEntry(ast.LiteralMapEntry node) { 5099 visitLiteralMapEntry(ast.LiteralMapEntry node) {
5058 visit(node.value); 5100 visit(node.value);
5059 visit(node.key); 5101 visit(node.key);
5060 } 5102 }
5061 5103
5062 visitNamedArgument(ast.NamedArgument node) { 5104 visitNamedArgument(ast.NamedArgument node) {
5063 visit(node.expression); 5105 visit(node.expression);
5064 } 5106 }
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
6216 DartType unaliased = type.unalias(builder.compiler); 6258 DartType unaliased = type.unalias(builder.compiler);
6217 if (unaliased is TypedefType) throw 'unable to unalias $type'; 6259 if (unaliased is TypedefType) throw 'unable to unalias $type';
6218 unaliased.accept(this, builder); 6260 unaliased.accept(this, builder);
6219 } 6261 }
6220 6262
6221 void visitDynamicType(DynamicType type, SsaBuilder builder) { 6263 void visitDynamicType(DynamicType type, SsaBuilder builder) {
6222 ClassElement cls = builder.compiler.findHelper('DynamicRuntimeType'); 6264 ClassElement cls = builder.compiler.findHelper('DynamicRuntimeType');
6223 builder.push(new HDynamicType(type, new TypeMask.exact(cls))); 6265 builder.push(new HDynamicType(type, new TypeMask.exact(cls)));
6224 } 6266 }
6225 } 6267 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js_backend/backend.dart ('k') | sdk/lib/_internal/lib/collection_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698