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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 24745003: Implement invoking methods with optional arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | dart/tests/lib/lib.status » ('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) 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 js_backend; 5 part of js_backend;
6 6
7 /// Enables debugging of fast/slow objects using V8-specific primitives. 7 /// Enables debugging of fast/slow objects using V8-specific primitives.
8 const DEBUG_FAST_OBJECTS = false; 8 const DEBUG_FAST_OBJECTS = false;
9 9
10 /** 10 /**
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 // (2) foo$3$c(a, b, c) => foo$4$c$d(a, b, c, null); 1127 // (2) foo$3$c(a, b, c) => foo$4$c$d(a, b, c, null);
1128 // (3) foo$3$d(a, b, d) => foo$4$c$d(a, b, null, d); 1128 // (3) foo$3$d(a, b, d) => foo$4$c$d(a, b, null, d);
1129 // (4) No stub generated, call is direct. 1129 // (4) No stub generated, call is direct.
1130 // (5) No stub generated, call is direct. 1130 // (5) No stub generated, call is direct.
1131 1131
1132 // Keep a cache of which stubs have already been generated, to 1132 // Keep a cache of which stubs have already been generated, to
1133 // avoid duplicates. Note that even if selectors are 1133 // avoid duplicates. Note that even if selectors are
1134 // canonicalized, we would still need this cache: a typed selector 1134 // canonicalized, we would still need this cache: a typed selector
1135 // on A and a typed selector on B could yield the same stub. 1135 // on A and a typed selector on B could yield the same stub.
1136 Set<String> generatedStubNames = new Set<String>(); 1136 Set<String> generatedStubNames = new Set<String>();
1137 if (compiler.enabledFunctionApply 1137 if (backend.isNeededForReflection(member) ||
1138 && member.name == namer.closureInvocationSelectorName) { 1138 (compiler.enabledFunctionApply &&
1139 member.name == namer.closureInvocationSelectorName)) {
1139 // If [Function.apply] is called, we pessimistically compile all 1140 // If [Function.apply] is called, we pessimistically compile all
1140 // possible stubs for this closure. 1141 // possible stubs for this closure.
1141 FunctionSignature signature = member.computeSignature(compiler); 1142 FunctionSignature signature = member.computeSignature(compiler);
1142 Set<Selector> selectors = signature.optionalParametersAreNamed 1143 Set<Selector> selectors = signature.optionalParametersAreNamed
1143 ? computeSeenNamedSelectors(member) 1144 ? computeSeenNamedSelectors(member)
1144 : computeOptionalSelectors(signature, member); 1145 : computeOptionalSelectors(signature, member);
1145 for (Selector selector in selectors) { 1146 for (Selector selector in selectors) {
1146 addParameterStub(member, selector, defineStub, generatedStubNames); 1147 addParameterStub(member, selector, defineStub, generatedStubNames);
1147 } 1148 }
1148 if (signature.optionalParametersAreNamed) { 1149 if (signature.optionalParametersAreNamed) {
ngeoffray 2013/09/26 12:32:04 This should only be for closures.
ahe 2013/09/26 12:43:21 Done.
1149 addCatchAllParameterStub(member, signature, defineStub); 1150 addCatchAllParameterStub(member, signature, defineStub);
1150 } 1151 }
1151 } else { 1152 } else {
1152 Set<Selector> selectors = compiler.codegenWorld.invokedNames[member.name]; 1153 Set<Selector> selectors = compiler.codegenWorld.invokedNames[member.name];
1153 if (selectors == null) return; 1154 if (selectors == null) return;
1154 for (Selector selector in selectors) { 1155 for (Selector selector in selectors) {
1155 if (!selector.applies(member, compiler)) continue; 1156 if (!selector.applies(member, compiler)) continue;
1156 addParameterStub(member, selector, defineStub, generatedStubNames); 1157 addParameterStub(member, selector, defineStub, generatedStubNames);
1157 } 1158 }
1158 } 1159 }
1159 } 1160 }
1160 1161
1161 Set<Selector> computeSeenNamedSelectors(FunctionElement element) { 1162 Set<Selector> computeSeenNamedSelectors(FunctionElement element) {
1162 Set<Selector> selectors = compiler.codegenWorld.invokedNames[element.name]; 1163 Set<Selector> selectors = compiler.codegenWorld.invokedNames[element.name];
1163 if (selectors == null) return null;
1164 Set<Selector> result = new Set<Selector>(); 1164 Set<Selector> result = new Set<Selector>();
1165 if (selectors == null) return result;
1165 for (Selector selector in selectors) { 1166 for (Selector selector in selectors) {
1166 if (!selector.applies(element, compiler)) continue; 1167 if (!selector.applies(element, compiler)) continue;
1167 result.add(selector); 1168 result.add(selector);
1168 } 1169 }
1169 return result; 1170 return result;
1170 } 1171 }
1171 1172
1172 void addCatchAllParameterStub(FunctionElement member, 1173 void addCatchAllParameterStub(FunctionElement member,
1173 FunctionSignature signature, 1174 FunctionSignature signature,
1174 DefineStubFunction defineStub) { 1175 DefineStubFunction defineStub) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 var names = []; 1355 var names = [];
1355 for (Element e in signature.optionalParameters) { 1356 for (Element e in signature.optionalParameters) {
1356 names.add(e.name); 1357 names.add(e.name);
1357 } 1358 }
1358 Selector selector = new Selector.call( 1359 Selector selector = new Selector.call(
1359 function.name, 1360 function.name,
1360 function.getLibrary(), 1361 function.getLibrary(),
1361 requiredParameterCount, 1362 requiredParameterCount,
1362 names); 1363 names);
1363 namedArguments = namedParametersAsReflectionNames(selector); 1364 namedArguments = namedParametersAsReflectionNames(selector);
1365 } else {
1366 // Named parameters are handled differently by mirrors. For unnamed
1367 // parameters, they are actually required if invoked
1368 // reflectively. Also, if you have a method c(x) and c([x]) they both
1369 // get the same mangled name, so they must have the same reflection
1370 // name.
1371 requiredParameterCount += optionalParameterCount;
1372 optionalParameterCount = 0;
ngeoffray 2013/09/26 12:32:04 Add a TODO/FIXME: is optionalParameterCount used?
ahe 2013/09/26 12:43:21 Done.
1364 } 1373 }
1365 } 1374 }
1366 String suffix = 1375 String suffix =
1367 '$name:$requiredParameterCount:$optionalParameterCount' 1376 '$name:$requiredParameterCount:$optionalParameterCount'
1368 '$namedArguments'; 1377 '$namedArguments';
1369 return (isConstructor) ? 'new $suffix' : suffix; 1378 return (isConstructor) ? 'new $suffix' : suffix;
1370 } 1379 }
1371 Element element = elementOrSelector; 1380 Element element = elementOrSelector;
1372 if (element.isGenerativeConstructorBody()) { 1381 if (element.isGenerativeConstructorBody()) {
1373 return null; 1382 return null;
(...skipping 3037 matching lines...) Expand 10 before | Expand all | Expand 10 after
4411 4420
4412 const String HOOKS_API_USAGE = """ 4421 const String HOOKS_API_USAGE = """
4413 // The code supports the following hooks: 4422 // The code supports the following hooks:
4414 // dartPrint(message) - if this function is defined it is called 4423 // dartPrint(message) - if this function is defined it is called
4415 // instead of the Dart [print] method. 4424 // instead of the Dart [print] method.
4416 // dartMainRunner(main) - if this function is defined, the Dart [main] 4425 // dartMainRunner(main) - if this function is defined, the Dart [main]
4417 // method will not be invoked directly. 4426 // method will not be invoked directly.
4418 // Instead, a closure that will invoke [main] is 4427 // Instead, a closure that will invoke [main] is
4419 // passed to [dartMainRunner]. 4428 // passed to [dartMainRunner].
4420 """; 4429 """;
OLDNEW
« no previous file with comments | « no previous file | dart/tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698