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

Unified Diff: sdk/lib/_internal/compiler/implementation/universe/universe.dart

Issue 19754002: Rewrite how we handle synthesized constructors in the compiler. This was motivated by issue https:/… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/universe/universe.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/universe/universe.dart (revision 25147)
+++ sdk/lib/_internal/compiler/implementation/universe/universe.dart (working copy)
@@ -376,7 +376,7 @@
* of an argument located in [arguments].
*
* [compileConstant] is a function that returns a compiled constant
- * of an optional argument that is not in [arguments.
+ * of an optional argument that is not in [arguments].
*
* Returns [:true:] if the selector and the [element] match; [:false:]
* otherwise.
@@ -429,6 +429,79 @@
return true;
}
+ /**
+ * Fills [list] with the arguments in the order expected by
+ * [callee], and where [caller] is a synthesized element
+ *
+ * [compileArgument] is a function that returns a compiled version
+ * of a parameter of [callee].
+ *
+ * [compileConstant] is a function that returns a compiled constant
+ * of an optional argument that is not in the parameters of [callee].
+ *
+ * Returns [:true:] if the signature of the [caller] matches the
+ * signature of the [callee], [:false:] otherwise.
+ */
+ static bool addForwardingElementArgumentsToList(
+ FunctionElement caller,
+ List list,
+ FunctionElement callee,
+ compileArgument(Element element),
+ compileConstant(Element element),
+ Compiler compiler) {
+
+ FunctionSignature signature = caller.computeSignature(compiler);
+ Map mapping = new Map();
+
+ // TODO(ngeoffray): This is a hack that fakes up AST nodes, so
+ // that we can call [addArgumentsToList].
+ Link computeCallNodesFromParameters() {
+ LinkBuilder builder = new LinkBuilder();
+ signature.forEachRequiredParameter((Element element) {
+ Node node = element.parseNode(compiler);
+ mapping[node] = element;
+ builder.addLast(node);
+ });
+ if (signature.optionalParametersAreNamed) {
+ signature.forEachOptionalParameter((Element element) {
+ Node node = element.parseNode(compiler);
+ mapping[node] = element;
+ builder.addLast(new NamedArgument(null, null, node));
+ });
+ } else {
+ signature.forEachOptionalParameter((Element element) {
+ Node node = element.parseNode(compiler);
+ mapping[node] = element;
+ builder.addLast(node);
+ });
+ }
+ return builder.toLink();
+ }
+
+ internalCompileArgument(Node node) => compileArgument(mapping[node]);
+
+ Link<Node> nodes = computeCallNodesFromParameters();
+
+ // Synthesize a selector for the call.
+ // TODO(ngeoffray): Should the resolver do it instead?
+ List<SourceString> namedParameters;
+ if (signature.optionalParametersAreNamed) {
+ namedParameters =
+ signature.optionalParameters.toList().map((e) => e.name).toList();
+ }
+ Selector selector = new Selector.call(callee.name,
+ caller.getLibrary(),
+ signature.parameterCount,
+ namedParameters);
+
+ return selector.addArgumentsToList(nodes,
+ list,
+ callee,
+ internalCompileArgument,
+ compileConstant,
+ compiler);
+ }
+
static bool sameNames(List<SourceString> first, List<SourceString> second) {
for (int i = 0; i < first.length; i++) {
if (first[i] != second[i]) return false;
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698