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

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

Issue 10363003: Compute function types together with the parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 updateLocal(boxElement, newBox); 296 updateLocal(boxElement, newBox);
297 } 297 }
298 298
299 void startFunction(FunctionElement function, 299 void startFunction(FunctionElement function,
300 FunctionExpression node) { 300 FunctionExpression node) {
301 301
302 ClosureTranslator translator = 302 ClosureTranslator translator =
303 new ClosureTranslator(builder.compiler, builder.elements); 303 new ClosureTranslator(builder.compiler, builder.elements);
304 closureData = translator.translate(node); 304 closureData = translator.translate(node);
305 305
306 FunctionParameters params = function.computeParameters(builder.compiler); 306 FunctionSignature params = function.computeSignature(builder.compiler);
307 params.forEachParameter((Element element) { 307 params.forEachParameter((Element element) {
308 HParameterValue parameter = new HParameterValue(element); 308 HParameterValue parameter = new HParameterValue(element);
309 builder.add(parameter); 309 builder.add(parameter);
310 directLocals[element] = parameter; 310 directLocals[element] = parameter;
311 }); 311 });
312 312
313 enterScope(node); 313 enterScope(node);
314 314
315 // If the freeVariableMapping is not empty, then this function was a 315 // If the freeVariableMapping is not empty, then this function was a
316 // nested closure that captures variables. Redirect the captured 316 // nested closure that captures variables. Redirect the captured
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 compiledArguments); 857 compiledArguments);
858 if (!succeeded) { 858 if (!succeeded) {
859 // Non-matching super and redirects are compile-time errors and thus 859 // Non-matching super and redirects are compile-time errors and thus
860 // checked by the resolver. 860 // checked by the resolver.
861 compiler.internalError( 861 compiler.internalError(
862 "Parameters and arguments didn't match for super/redirect call", 862 "Parameters and arguments didn't match for super/redirect call",
863 element: constructor); 863 element: constructor);
864 } 864 }
865 865
866 int index = 0; 866 int index = 0;
867 FunctionParameters parameters = constructor.computeParameters(compiler); 867 FunctionSignature parameters = constructor.computeSignature(compiler);
868 parameters.forEachParameter((Element parameter) { 868 parameters.forEachParameter((Element parameter) {
869 HInstruction argument = compiledArguments[index++]; 869 HInstruction argument = compiledArguments[index++];
870 localsHandler.updateLocal(parameter, argument); 870 localsHandler.updateLocal(parameter, argument);
871 // Don't forget to update the field, if the parameter is of the 871 // Don't forget to update the field, if the parameter is of the
872 // form [:this.x:]. 872 // form [:this.x:].
873 if (parameter.kind == ElementKind.FIELD_PARAMETER) { 873 if (parameter.kind == ElementKind.FIELD_PARAMETER) {
874 FieldParameterElement fieldParameterElement = parameter; 874 FieldParameterElement fieldParameterElement = parameter;
875 fieldValues[fieldParameterElement.fieldElement] = argument; 875 fieldValues[fieldParameterElement.fieldElement] = argument;
876 } 876 }
877 }); 877 });
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 FunctionElement functionElement) { 956 FunctionElement functionElement) {
957 FunctionExpression function = functionElement.parseNode(compiler); 957 FunctionExpression function = functionElement.parseNode(compiler);
958 // Note that constructors (like any other static function) do not need 958 // Note that constructors (like any other static function) do not need
959 // to deal with optional arguments. It is the callers job to provide all 959 // to deal with optional arguments. It is the callers job to provide all
960 // arguments as if they were positional. 960 // arguments as if they were positional.
961 961
962 // The initializer list could contain closures. 962 // The initializer list could contain closures.
963 openFunction(functionElement, function); 963 openFunction(functionElement, function);
964 964
965 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); 965 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>();
966 FunctionParameters parameters = functionElement.computeParameters(compiler); 966 FunctionSignature parameters = functionElement.computeSignature(compiler);
967 parameters.forEachParameter((Element element) { 967 parameters.forEachParameter((Element element) {
968 if (element.kind == ElementKind.FIELD_PARAMETER) { 968 if (element.kind == ElementKind.FIELD_PARAMETER) {
969 // If the [element] is a field-parameter (such as [:this.x:] then 969 // If the [element] is a field-parameter (such as [:this.x:] then
970 // initialize the field element with its value. 970 // initialize the field element with its value.
971 FieldParameterElement fieldParameterElement = element; 971 FieldParameterElement fieldParameterElement = element;
972 HInstruction parameterValue = localsHandler.readLocal(element); 972 HInstruction parameterValue = localsHandler.readLocal(element);
973 fieldValues[fieldParameterElement.fieldElement] = parameterValue; 973 fieldValues[fieldParameterElement.fieldElement] = parameterValue;
974 } 974 }
975 }); 975 });
976 976
(...skipping 23 matching lines...) Expand all
1000 1000
1001 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); 1001 HForeignNew newObject = new HForeignNew(classElement, constructorArguments);
1002 add(newObject); 1002 add(newObject);
1003 // Generate calls to the constructor bodies. 1003 // Generate calls to the constructor bodies.
1004 for (int index = constructors.length - 1; index >= 0; index--) { 1004 for (int index = constructors.length - 1; index >= 0; index--) {
1005 FunctionElement constructor = constructors[index]; 1005 FunctionElement constructor = constructors[index];
1006 ConstructorBodyElement body = getConstructorBody(constructor); 1006 ConstructorBodyElement body = getConstructorBody(constructor);
1007 if (body === null) continue; 1007 if (body === null) continue;
1008 List bodyCallInputs = <HInstruction>[]; 1008 List bodyCallInputs = <HInstruction>[];
1009 bodyCallInputs.add(newObject); 1009 bodyCallInputs.add(newObject);
1010 body.functionParameters.forEachParameter((parameter) { 1010 body.functionSignature.forEachParameter((parameter) {
1011 bodyCallInputs.add(localsHandler.readLocal(parameter)); 1011 bodyCallInputs.add(localsHandler.readLocal(parameter));
1012 }); 1012 });
1013 // TODO(ahe): The constructor name is statically resolved. See 1013 // TODO(ahe): The constructor name is statically resolved. See
1014 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner 1014 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner
1015 // way to do this? 1015 // way to do this?
1016 SourceString methodName = new SourceString(compiler.namer.getName(body)); 1016 SourceString methodName = new SourceString(compiler.namer.getName(body));
1017 add(new HInvokeDynamicMethod(null, methodName, bodyCallInputs)); 1017 add(new HInvokeDynamicMethod(null, methodName, bodyCallInputs));
1018 } 1018 }
1019 close(new HReturn(newObject)).addSuccessor(graph.exit); 1019 close(new HReturn(newObject)).addSuccessor(graph.exit);
1020 return closeFunction(); 1020 return closeFunction();
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 node: node.argumentsNode); 2125 node: node.argumentsNode);
2126 } 2126 }
2127 Node closure = node.arguments.head; 2127 Node closure = node.arguments.head;
2128 Element element = elements[closure]; 2128 Element element = elements[closure];
2129 if (!Elements.isStaticOrTopLevelFunction(element)) { 2129 if (!Elements.isStaticOrTopLevelFunction(element)) {
2130 compiler.cancel( 2130 compiler.cancel(
2131 'JS_TO_CLOSURE requires a static or top-level method', 2131 'JS_TO_CLOSURE requires a static or top-level method',
2132 node: closure); 2132 node: closure);
2133 } 2133 }
2134 FunctionElement function = element; 2134 FunctionElement function = element;
2135 FunctionParameters parameters = function.computeParameters(compiler); 2135 FunctionSignature parameters = function.computeSignature(compiler);
2136 if (parameters.optionalParameterCount !== 0) { 2136 if (parameters.optionalParameterCount !== 0) {
2137 compiler.cancel( 2137 compiler.cancel(
2138 'JS_TO_CLOSURE does not handle closure with optional parameters', 2138 'JS_TO_CLOSURE does not handle closure with optional parameters',
2139 node: closure); 2139 node: closure);
2140 } 2140 }
2141 visit(closure); 2141 visit(closure);
2142 List<HInstruction> inputs = <HInstruction>[pop()]; 2142 List<HInstruction> inputs = <HInstruction>[pop()];
2143 String invocationName = compiler.namer.closureInvocationName( 2143 String invocationName = compiler.namer.closureInvocationName(
2144 new Selector(SelectorKind.INVOCATION, 2144 new Selector(SelectorKind.INVOCATION,
2145 parameters.requiredParameterCount)); 2145 parameters.requiredParameterCount));
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
3244 <HInstruction>[target, input], 3244 <HInstruction>[target, input],
3245 HType.STRING)); 3245 HType.STRING));
3246 return builder.pop(); 3246 return builder.pop();
3247 } 3247 }
3248 3248
3249 HInstruction result() { 3249 HInstruction result() {
3250 flushLiterals(); 3250 flushLiterals();
3251 return prefix; 3251 return prefix;
3252 } 3252 }
3253 } 3253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698