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

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

Issue 1011403003: cps-ir: Set runtime type information for new objects that require it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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) 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; 5 library dart2js.ir_builder;
6 6
7 import '../constants/expressions.dart'; 7 import '../constants/expressions.dart';
8 import '../constants/values.dart' show PrimitiveConstantValue; 8 import '../constants/values.dart' show PrimitiveConstantValue;
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../dart2jslib.dart'; 10 import '../dart2jslib.dart';
11 import '../elements/elements.dart'; 11 import '../elements/elements.dart';
12 import '../io/source_information.dart'; 12 import '../io/source_information.dart';
13 import '../tree/tree.dart' as ast; 13 import '../tree/tree.dart' as ast;
14 import '../closure.dart' hide ClosureScope; 14 import '../closure.dart' hide ClosureScope;
15 import 'cps_ir_nodes.dart' as ir; 15 import 'cps_ir_nodes.dart' as ir;
16 import 'cps_ir_builder_task.dart' show DartCapturedVariables; 16 import 'cps_ir_builder_task.dart' show DartCapturedVariables,
17 GlobalProgramInformation;
17 18
18 /// A mapping from variable elements to their compile-time values. 19 /// A mapping from variable elements to their compile-time values.
19 /// 20 ///
20 /// Map elements denoted by parameters and local variables to the 21 /// Map elements denoted by parameters and local variables to the
21 /// [ir.Primitive] that is their value. Parameters and locals are 22 /// [ir.Primitive] that is their value. Parameters and locals are
22 /// assigned indexes which can be used to refer to them. 23 /// assigned indexes which can be used to refer to them.
23 class Environment { 24 class Environment {
24 /// A map from locals to their environment index. 25 /// A map from locals to their environment index.
25 final Map<Local, int> variable2index; 26 final Map<Local, int> variable2index;
26 27
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 _buildInvokeStatic( 781 _buildInvokeStatic(
781 element, selector, <ir.Primitive>[value], sourceInformation); 782 element, selector, <ir.Primitive>[value], sourceInformation);
782 return value; 783 return value;
783 } 784 }
784 785
785 /// Create a constructor invocation of [element] on [type] where the 786 /// Create a constructor invocation of [element] on [type] where the
786 /// constructor name and argument structure are defined by [selector] and the 787 /// constructor name and argument structure are defined by [selector] and the
787 /// argument values are defined by [arguments]. 788 /// argument values are defined by [arguments].
788 ir.Primitive buildConstructorInvocation(FunctionElement element, 789 ir.Primitive buildConstructorInvocation(FunctionElement element,
789 Selector selector, 790 Selector selector,
790 DartType type, 791 InterfaceType type,
791 List<ir.Primitive> arguments) { 792 List<ir.Primitive> arguments);
792 assert(isOpen);
793 return _continueWithExpression(
794 (k) => new ir.InvokeConstructor(type, element, selector, k, arguments));
795 }
796 793
797 /// Create a string concatenation of the [arguments]. 794 /// Create a string concatenation of the [arguments].
798 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) { 795 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) {
799 assert(isOpen); 796 assert(isOpen);
800 return _continueWithExpression( 797 return _continueWithExpression(
801 (k) => new ir.ConcatenateStrings(k, arguments)); 798 (k) => new ir.ConcatenateStrings(k, arguments));
802 } 799 }
803 800
804 /// Create an invocation of the `call` method of [functionExpression], where 801 /// Create an invocation of the `call` method of [functionExpression], where
805 /// the named arguments are given by [selector]. 802 /// the named arguments are given by [selector].
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 add(new ir.LetPrim(thisPrim)); 2103 add(new ir.LetPrim(thisPrim));
2107 return thisPrim; 2104 return thisPrim;
2108 } 2105 }
2109 2106
2110 ir.Primitive buildSuperInvocation(Element target, 2107 ir.Primitive buildSuperInvocation(Element target,
2111 Selector selector, 2108 Selector selector,
2112 List<ir.Primitive> arguments) { 2109 List<ir.Primitive> arguments) {
2113 return _buildInvokeSuper(target, selector, arguments); 2110 return _buildInvokeSuper(target, selector, arguments);
2114 } 2111 }
2115 2112
2113 @override
2114 ir.Primitive buildConstructorInvocation(FunctionElement element,
2115 Selector selector,
2116 InterfaceType type,
2117 List<ir.Primitive> arguments) {
2118 assert(isOpen);
2119 return _continueWithExpression(
2120 (k) => new ir.InvokeConstructor.byType(type, element, selector, k,
2121 arguments));
2122 }
2116 } 2123 }
2117 2124
2118 /// State shared between JsIrBuilders within the same function. 2125 /// State shared between JsIrBuilders within the same function.
2119 /// 2126 ///
2120 /// Note that this is not shared between builders of nested functions. 2127 /// Note that this is not shared between builders of nested functions.
2121 class JsIrBuilderSharedState { 2128 class JsIrBuilderSharedState {
2122 /// Maps boxed locals to their location. These locals are not part of 2129 /// Maps boxed locals to their location. These locals are not part of
2123 /// the environment. 2130 /// the environment.
2124 final Map<Local, ClosureLocation> boxedVariables = {}; 2131 final Map<Local, ClosureLocation> boxedVariables = {};
2125 2132
2126 /// If non-null, this refers to the receiver (`this`) in the enclosing method. 2133 /// If non-null, this refers to the receiver (`this`) in the enclosing method.
2127 ir.Primitive receiver; 2134 ir.Primitive receiver;
2128 } 2135 }
2129 2136
2130 /// JS-specific subclass of [IrBuilder]. 2137 /// JS-specific subclass of [IrBuilder].
2131 /// 2138 ///
2132 /// Inner functions are represented by a [ClosureClassElement], and captured 2139 /// Inner functions are represented by a [ClosureClassElement], and captured
2133 /// variables are boxed as necessary using [CreateBox], [GetField], [SetField]. 2140 /// variables are boxed as necessary using [CreateBox], [GetField], [SetField].
2134 class JsIrBuilder extends IrBuilder { 2141 class JsIrBuilder extends IrBuilder {
2135 final JsIrBuilderSharedState jsState; 2142 final JsIrBuilderSharedState jsState;
2143 final GlobalProgramInformation program;
2136 2144
2137 IrBuilder _makeInstance() => new JsIrBuilder._blank(jsState); 2145 IrBuilder _makeInstance() => new JsIrBuilder._blank(program, jsState);
2138 JsIrBuilder._blank(this.jsState); 2146 JsIrBuilder._blank(this.program, this.jsState);
2139 2147
2140 JsIrBuilder(ConstantSystem constantSystem, ExecutableElement currentElement) 2148 JsIrBuilder(this.program, ConstantSystem constantSystem,
2149 ExecutableElement currentElement)
2141 : jsState = new JsIrBuilderSharedState() { 2150 : jsState = new JsIrBuilderSharedState() {
2142 _init(constantSystem, currentElement); 2151 _init(constantSystem, currentElement);
2143 } 2152 }
2144 2153
2145 Map<ast.TryStatement, TryStatementInfo> get tryStatements => null; 2154 Map<ast.TryStatement, TryStatementInfo> get tryStatements => null;
2146 Set<Local> get mutableCapturedVariables => null; 2155 Set<Local> get mutableCapturedVariables => null;
2147 bool isInMutableVariable(Local local) => false; 2156 bool isInMutableVariable(Local local) => false;
2148 void makeMutableVariable(Local local) {} 2157 void makeMutableVariable(Local local) {}
2149 void removeMutableVariable(Local local) {} 2158 void removeMutableVariable(Local local) {}
2150 2159
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 void buildConstructorBodyHeader(Iterable<Local> parameters, 2380 void buildConstructorBodyHeader(Iterable<Local> parameters,
2372 ClosureScope closureScope) { 2381 ClosureScope closureScope) {
2373 for (Local param in parameters) { 2382 for (Local param in parameters) {
2374 ir.Parameter parameter = createLocalParameter(param); 2383 ir.Parameter parameter = createLocalParameter(param);
2375 state.functionParameters.add(parameter); 2384 state.functionParameters.add(parameter);
2376 } 2385 }
2377 if (closureScope != null) { 2386 if (closureScope != null) {
2378 jsState.boxedVariables.addAll(closureScope.capturedVariables); 2387 jsState.boxedVariables.addAll(closureScope.capturedVariables);
2379 } 2388 }
2380 } 2389 }
2390
2391 @override
2392 ir.Primitive buildConstructorInvocation(FunctionElement element,
2393 Selector selector,
2394 InterfaceType type,
2395 List<ir.Primitive> arguments) {
2396 assert(isOpen);
2397 // TODO(karlklose): resolve effective target and type here or inline later?
2398 ClassElement cls = element.enclosingClass;
2399 List<ir.TypeExpression> typeArguments = const <ir.TypeExpression>[];
2400 if (program.requiresRuntimeTypesFor(cls) && !type.treatAsRaw) {
2401 typeArguments = type.typeArguments.map(buildTypeExpression).toList();
2402 }
2403 return _continueWithExpression(
2404 (k) => new ir.InvokeConstructor.withTypeArguments(element, selector, k,
2405 arguments, typeArguments));
2406 }
2407
2408 ir.Primitive buildTypeExpression(DartType type) {
2409 ir.Primitive expression;
2410 if (type is TypeVariableType) {
2411 expression = new ir.ReadTypeVariable(type, buildThis());
2412 } else {
2413 assert(type is InterfaceType);
2414 List<ir.Primitive> arguments = <ir.Primitive>[];
2415 type.forEachTypeVariable((TypeVariableType variable) {
2416 ir.Primitive value = buildTypeExpression(variable);
2417 arguments.add(value);
2418 });
2419 expression = new ir.TypeExpression(type, arguments);
2420 }
2421 add(new ir.LetPrim(expression));
2422 return expression;
2423 }
2381 } 2424 }
2382 2425
2383 2426
2384 /// Location of a variable relative to a given closure. 2427 /// Location of a variable relative to a given closure.
2385 class ClosureLocation { 2428 class ClosureLocation {
2386 /// If not `null`, this location is [box].[field]. 2429 /// If not `null`, this location is [box].[field].
2387 /// The location of [box] can be obtained separately from an 2430 /// The location of [box] can be obtained separately from an
2388 /// enclosing [ClosureEnvironment] or [ClosureScope]. 2431 /// enclosing [ClosureEnvironment] or [ClosureScope].
2389 /// If `null`, then the location is [field] on the enclosing function object. 2432 /// If `null`, then the location is [field] on the enclosing function object.
2390 final BoxLocal box; 2433 final BoxLocal box;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 // TODO(johnniwinther): Support passing of [DartType] for the exception. 2485 // TODO(johnniwinther): Support passing of [DartType] for the exception.
2443 class CatchClauseInfo { 2486 class CatchClauseInfo {
2444 final LocalVariableElement exceptionVariable; 2487 final LocalVariableElement exceptionVariable;
2445 final LocalVariableElement stackTraceVariable; 2488 final LocalVariableElement stackTraceVariable;
2446 final SubbuildFunction buildCatchBlock; 2489 final SubbuildFunction buildCatchBlock;
2447 2490
2448 CatchClauseInfo({this.exceptionVariable, 2491 CatchClauseInfo({this.exceptionVariable,
2449 this.stackTraceVariable, 2492 this.stackTraceVariable,
2450 this.buildCatchBlock}); 2493 this.buildCatchBlock});
2451 } 2494 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698