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

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

Issue 1537663002: dart2js: Initial implementation of inlining. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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_nodes_sexpr; 5 library dart2js.ir_nodes_sexpr;
6 6
7 import '../constants/values.dart'; 7 import '../constants/values.dart';
8 import '../util/util.dart'; 8 import '../util/util.dart';
9 import 'cps_ir_nodes.dart'; 9 import 'cps_ir_nodes.dart';
10 import '../universe/call_structure.dart' show 10 import '../universe/call_structure.dart' show
(...skipping 30 matching lines...) Expand all
41 return namer.nameParameter(node); 41 return namer.nameParameter(node);
42 } 42 }
43 43
44 String visitMutableVariable(MutableVariable node) { 44 String visitMutableVariable(MutableVariable node) {
45 return namer.nameMutableVariable(node); 45 return namer.nameMutableVariable(node);
46 } 46 }
47 47
48 /// Main entry point for creating a [String] from a [Node]. All recursive 48 /// Main entry point for creating a [String] from a [Node]. All recursive
49 /// calls must go through this method. 49 /// calls must go through this method.
50 String visit(Node node) { 50 String visit(Node node) {
51 if (node == null) return '**** NULL ****';
51 String s = node.accept(this); 52 String s = node.accept(this);
52 return decorator(node, s); 53 return decorator(node, s);
53 } 54 }
54 55
55 String formatThisParameter(Parameter thisParameter) { 56 String formatThisParameter(Parameter thisParameter) {
56 return thisParameter == null ? '()' : '(${visit(thisParameter)})'; 57 return thisParameter == null ? '()' : '(${visit(thisParameter)})';
57 } 58 }
58 59
59 String visitFunctionDefinition(FunctionDefinition node) { 60 String visitFunctionDefinition(FunctionDefinition node) {
60 String name = node.element.name; 61 String name = node.element.name;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 106 }
106 107
107 String visitLetMutable(LetMutable node) { 108 String visitLetMutable(LetMutable node) {
108 String name = visit(node.variable); 109 String name = visit(node.variable);
109 String value = access(node.value); 110 String value = access(node.value);
110 String body = indentBlock(() => visit(node.body)); 111 String body = indentBlock(() => visit(node.body));
111 return '$indentation(LetMutable ($name $value)\n$body)'; 112 return '$indentation(LetMutable ($name $value)\n$body)';
112 } 113 }
113 114
114 String formatArguments(CallStructure call, 115 String formatArguments(CallStructure call,
115 List<Reference<Primitive>> arguments, 116 List<Reference<Primitive>> arguments,
116 [CallingConvention callingConvention = CallingConvention.Normal]) { 117 [CallingConvention callingConvention = CallingConvention.Normal]) {
117 int positionalArgumentCount = call.positionalArgumentCount; 118 int positionalArgumentCount = call.positionalArgumentCount;
118 if (callingConvention == CallingConvention.Intercepted) { 119 if (callingConvention != CallingConvention.Normal) {
asgerf 2015/12/17 15:40:34 Could you add an exception for the new OneShotInte
Kevin Millikin (Google) 2015/12/21 12:28:02 Done.
119 ++positionalArgumentCount; 120 ++positionalArgumentCount;
120 } 121 }
121 List<String> args = 122 List<String> args =
122 arguments.getRange(0, positionalArgumentCount).map(access).toList(); 123 arguments.take(positionalArgumentCount).map(access).toList();
123 List<String> argumentNames = call.getOrderedNamedArguments(); 124 List<String> argumentNames = call.getOrderedNamedArguments();
124 for (int i = 0; i < argumentNames.length; ++i) { 125 for (int i = 0; i < argumentNames.length; ++i) {
125 String name = argumentNames[i]; 126 String name = argumentNames[i];
126 String arg = access(arguments[positionalArgumentCount + i]); 127 String arg = access(arguments[positionalArgumentCount + i]);
127 args.add("($name: $arg)"); 128 args.add("($name: $arg)");
128 } 129 }
130 // Constructors can have type parameter after the named arguments.
131 args.addAll(
132 arguments.skip(positionalArgumentCount + argumentNames.length)
133 .map(access));
129 return '(${args.join(' ')})'; 134 return '(${args.join(' ')})';
130 } 135 }
131 136
132 String visitInvokeStatic(InvokeStatic node) { 137 String visitInvokeStatic(InvokeStatic node) {
133 String name = node.target.name; 138 String name = node.target.name;
134 String args = formatArguments(node.selector.callStructure, node.arguments); 139 String args = formatArguments(node.selector.callStructure, node.arguments);
135 return '(InvokeStatic $name $args)'; 140 return '(InvokeStatic $name $args)';
136 } 141 }
137 142
138 String visitInvokeMethod(InvokeMethod node) { 143 String visitInvokeMethod(InvokeMethod node) {
(...skipping 24 matching lines...) Expand all
163 name = '${name}.${node.target.name}'; 168 name = '${name}.${node.target.name}';
164 } 169 }
165 String args = formatArguments(node.selector.callStructure, node.arguments); 170 String args = formatArguments(node.selector.callStructure, node.arguments);
166 return '(InvokeConstructor $name $args)'; 171 return '(InvokeConstructor $name $args)';
167 } 172 }
168 173
169 String visitInvokeContinuation(InvokeContinuation node) { 174 String visitInvokeContinuation(InvokeContinuation node) {
170 String name = access(node.continuation); 175 String name = access(node.continuation);
171 if (node.isRecursive) name = 'rec $name'; 176 if (node.isRecursive) name = 'rec $name';
172 String args = node.arguments.map(access).join(' '); 177 String args = node.arguments.map(access).join(' ');
173 return '$indentation(InvokeContinuation $name ($args))'; 178 String escaping = node.isEscapingTry ? ' escape' : '';
179 return '$indentation(InvokeContinuation $name ($args)$escaping)';
174 } 180 }
175 181
176 String visitThrow(Throw node) { 182 String visitThrow(Throw node) {
177 String value = access(node.value); 183 String value = access(node.value);
178 return '$indentation(Throw $value)'; 184 return '$indentation(Throw $value)';
179 } 185 }
180 186
181 String visitRethrow(Rethrow node) { 187 String visitRethrow(Rethrow node) {
182 return '$indentation(Rethrow)'; 188 return '$indentation(Rethrow)';
183 } 189 }
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 void setReturnContinuation(Continuation node) { 490 void setReturnContinuation(Continuation node) {
485 assert(!_names.containsKey(node) || _names[node] == 'return'); 491 assert(!_names.containsKey(node) || _names[node] == 'return');
486 _names[node] = 'return'; 492 _names[node] = 'return';
487 } 493 }
488 494
489 String getName(Node node) { 495 String getName(Node node) {
490 if (!_names.containsKey(node)) return 'MISSING_NAME'; 496 if (!_names.containsKey(node)) return 'MISSING_NAME';
491 return _names[node]; 497 return _names[node];
492 } 498 }
493 } 499 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698