Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 package com.google.dart.compiler.backend.js; | 5 package com.google.dart.compiler.backend.js; |
| 6 | 6 |
| 7 import com.google.common.collect.Lists; | 7 import com.google.common.collect.Lists; |
| 8 import com.google.dart.compiler.DartCompilationError; | 8 import com.google.dart.compiler.DartCompilationError; |
| 9 import com.google.dart.compiler.DartCompilerContext; | 9 import com.google.dart.compiler.DartCompilerContext; |
| 10 import com.google.dart.compiler.InternalCompilerException; | 10 import com.google.dart.compiler.InternalCompilerException; |
| (...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 // We do the constructor invocation before we declare the temporary variab le. This is | 1030 // We do the constructor invocation before we declare the temporary variab le. This is |
| 1031 // necessary to ensure that the created temporary does not conflict with t he parameters. | 1031 // necessary to ensure that the created temporary does not conflict with t he parameters. |
| 1032 JsInvocation constructorInvocation = new JsInvocation(); | 1032 JsInvocation constructorInvocation = new JsInvocation(); |
| 1033 JsName constructorJsName = getJsName(element); | 1033 JsName constructorJsName = getJsName(element); |
| 1034 JsNameRef constructorRef = AstUtil.newNameRef(curClassJsName.makeRef(), co nstructorJsName); | 1034 JsNameRef constructorRef = AstUtil.newNameRef(curClassJsName.makeRef(), co nstructorJsName); |
| 1035 constructorInvocation.setQualifier(AstUtil.newNameRef(constructorRef, "cal l")); | 1035 constructorInvocation.setQualifier(AstUtil.newNameRef(constructorRef, "cal l")); |
| 1036 | 1036 |
| 1037 // Add the arguments to the constructor invocation. Note that the construc tor call is still | 1037 // Add the arguments to the constructor invocation. Note that the construc tor call is still |
| 1038 // missing the 'tmp' variable. We will add it later. | 1038 // missing the 'tmp' variable. We will add it later. |
| 1039 List<DartParameter> params = x.getFunction().getParams(); | 1039 List<DartParameter> params = x.getFunction().getParams(); |
| 1040 List<JsName> jsArgNames = new ArrayList<JsName>(); | |
| 1040 for (DartParameter p : params) { | 1041 for (DartParameter p : params) { |
| 1041 // TODO(ngeoffray): We should actually copy the arguments. See b/4424659 . | 1042 // TODO(ngeoffray): We should actually copy the arguments. See b/4424659 . |
| 1042 JsName argName = getJsName(p.getNormalizedNode().getSymbol()); | 1043 JsName argName = getJsName(p.getNormalizedNode().getSymbol()); |
| 1044 jsArgNames.add(argName); | |
| 1043 constructorInvocation.getArguments().add(argName.makeRef()); | 1045 constructorInvocation.getArguments().add(argName.makeRef()); |
| 1044 } | 1046 } |
| 1045 | 1047 |
| 1046 JsName tempVar = factoryScope.declareTemporary(); | 1048 JsName tempVar = factoryScope.declareTemporary(); |
| 1047 // Add the 'tmp' var to the constructor call. | 1049 // Add the 'tmp' var to the constructor call. |
| 1048 constructorInvocation.getArguments().add(0, tempVar.makeRef()); | 1050 constructorInvocation.getArguments().add(0, tempVar.makeRef()); |
| 1049 | 1051 |
| 1050 factoryFunction.setBody(AstUtil.newBlock( | 1052 factoryFunction.setBody(AstUtil.newBlock( |
| 1051 constructorInvocation.makeStmt(), | 1053 constructorInvocation.makeStmt(), |
| 1052 new JsReturn(tempVar.makeRef()))); | 1054 new JsReturn(tempVar.makeRef()))); |
| 1053 | 1055 |
| 1054 if (optStrategy.canInlineInitializers(element)) { | 1056 if (optStrategy.canInlineInitializers(element)) { |
| 1055 rtt.maybeAddClassRuntimeTypeToConstructor(classElement, factoryFunction, tempVar.makeRef()); | 1057 rtt.maybeAddClassRuntimeTypeToConstructor(classElement, factoryFunction, tempVar.makeRef()); |
| 1056 generateInitializersInlined(x, factoryFunction, factoryScope, tempVar); | 1058 generateInitializersInlined(x, factoryFunction, factoryScope, tempVar); |
| 1057 } else { | 1059 } else { |
| 1058 addInitializers(x, factoryFunction, tempVar); | 1060 addInitializers(x, factoryFunction, tempVar); |
| 1059 rtt.maybeAddClassRuntimeTypeToConstructor(classElement, factoryFunction, tempVar.makeRef()); | 1061 rtt.maybeAddClassRuntimeTypeToConstructor(classElement, factoryFunction, tempVar.makeRef()); |
| 1060 JsNew jsNew = new JsNew(curClassJsName.makeRef()); | 1062 JsNew jsNew = new JsNew(curClassJsName.makeRef()); |
| 1063 if (classElement.getNativeName() != null && x.getFunction().getBody() == null) { | |
|
floitsch
2012/01/16 13:23:26
I don't understand this code. (In any case add com
mmendez
2012/01/17 12:48:04
Added a comment in the code to match the comment i
| |
| 1064 List<JsExpression> newArguments = jsNew.getArguments(); | |
| 1065 for (JsName jsArgName : jsArgNames) { | |
| 1066 newArguments.add(jsArgName.makeRef()); | |
| 1067 } | |
| 1068 } | |
| 1061 factoryFunction.getBody().getStatements().add(0, AstUtil.newVar(x, tempV ar, jsNew)); | 1069 factoryFunction.getBody().getStatements().add(0, AstUtil.newVar(x, tempV ar, jsNew)); |
| 1062 } | 1070 } |
| 1063 | 1071 |
| 1064 generateAll(x.getFunction().getParams(), factoryFunction.getParameters(), JsParameter.class); | 1072 generateAll(x.getFunction().getParams(), factoryFunction.getParameters(), JsParameter.class); |
| 1065 | 1073 |
| 1066 assert currentScopeInfo != null; | 1074 assert currentScopeInfo != null; |
| 1067 inFactory = false; | 1075 inFactory = false; |
| 1068 inFactoryOrStaticContext = false; | 1076 inFactoryOrStaticContext = false; |
| 1069 currentScopeInfo = null; | 1077 currentScopeInfo = null; |
| 1070 | 1078 |
| (...skipping 2874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3945 JsBlock blockStatics) { | 3953 JsBlock blockStatics) { |
| 3946 GenerateJavascriptVisitor generator = | 3954 GenerateJavascriptVisitor generator = |
| 3947 new GenerateJavascriptVisitor(unit, context, translationContext, | 3955 new GenerateJavascriptVisitor(unit, context, translationContext, |
| 3948 optStrategy, typeProvider, generateClosureCompatibleCode); | 3956 optStrategy, typeProvider, generateClosureCompatibleCode); |
| 3949 // Generate the Javascript AST. | 3957 // Generate the Javascript AST. |
| 3950 node.accept(generator); | 3958 node.accept(generator); |
| 3951 // Set aside the static initializations | 3959 // Set aside the static initializations |
| 3952 generator.addStaticInitsToBlock(blockStatics); | 3960 generator.addStaticInitsToBlock(blockStatics); |
| 3953 } | 3961 } |
| 3954 } | 3962 } |
| OLD | NEW |