Using new ast instead of utilities.
Adapted from https://github.com/develar/kotlin/commit/a9e0a42fb1347fa8e21c86b5a073ef8a7c873da0.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.translate.expression;
|
package org.jetbrains.k2js.translate.expression;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsBlock;
|
import com.google.dart.compiler.backend.js.ast.JsBlock;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsCatch;
|
import com.google.dart.compiler.backend.js.ast.JsCatch;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||||
@@ -27,7 +28,6 @@ import org.jetbrains.k2js.translate.context.TranslationContext;
|
|||||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||||
import org.jetbrains.k2js.translate.general.Translation;
|
import org.jetbrains.k2js.translate.general.Translation;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.convertToBlock;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.convertToBlock;
|
||||||
@@ -55,11 +55,7 @@ public final class TryTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsTry translate() {
|
private JsTry translate() {
|
||||||
JsTry result = new JsTry();
|
return new JsTry(translateTryBlock(), translateCatches(), translateFinallyBlock());
|
||||||
result.setTryBlock(translateTryBlock());
|
|
||||||
result.setFinallyBlock(translateFinallyBlock());
|
|
||||||
result.getCatches().addAll(translateCatches());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -75,10 +71,9 @@ public final class TryTranslator extends AbstractTranslator {
|
|||||||
return convertToBlock(Translation.translateAsStatement(expression.getTryBlock(), context()));
|
return convertToBlock(Translation.translateAsStatement(expression.getTryBlock(), context()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<JsCatch> translateCatches() {
|
private List<JsCatch> translateCatches() {
|
||||||
List<JsCatch> result = new ArrayList<JsCatch>();
|
List<JsCatch> result = Lists.newArrayList();
|
||||||
for (JetCatchClause catchClause : expression.getCatchClauses()) {
|
for (JetCatchClause catchClause : expression.getCatchClauses()) {
|
||||||
result.add(translateCatchClause(catchClause));
|
result.add(translateCatchClause(catchClause));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public final class WhenTranslator extends AbstractTranslator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
JsNode translate() {
|
JsNode translate() {
|
||||||
JsFor resultingFor = generateDummyFor();
|
JsFor resultingFor = generateDummyFor();
|
||||||
resultingFor.setBody(newBlock(translateEntries()));
|
resultingFor.setBody(new JsBlock(translateEntries()));
|
||||||
context().addStatementToCurrentBlock(resultingFor);
|
context().addStatementToCurrentBlock(resultingFor);
|
||||||
return result.reference();
|
return result.reference();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,7 @@ public final class ArrayForTranslator extends ForTranslator {
|
|||||||
List<JsStatement> blockStatements = Lists.newArrayList();
|
List<JsStatement> blockStatements = Lists.newArrayList();
|
||||||
blockStatements.add(temporariesInitialization(loopRange, end).makeStmt());
|
blockStatements.add(temporariesInitialization(loopRange, end).makeStmt());
|
||||||
blockStatements.add(generateForExpression(getInitExpression(), getCondition(), getIncrementExpression(), getBody()));
|
blockStatements.add(generateForExpression(getInitExpression(), getCondition(), getIncrementExpression(), getBody()));
|
||||||
return newBlock(blockStatements);
|
return new JsBlock(blockStatements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -86,7 +86,7 @@ public final class RangeLiteralForTranslator extends ForTranslator {
|
|||||||
getCondition(),
|
getCondition(),
|
||||||
getIncrExpression(),
|
getIncrExpression(),
|
||||||
translateOriginalBodyExpression()));
|
translateOriginalBodyExpression()));
|
||||||
return newBlock(blockStatements);
|
return new JsBlock(blockStatements);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -101,6 +101,6 @@ public final class RangeLiteralForTranslator extends ForTranslator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression getIncrExpression() {
|
private JsExpression getIncrExpression() {
|
||||||
return new JsPrefixOperation(JsUnaryOperator.INC, parameterName.makeRef());
|
return new JsPostfixOperation(JsUnaryOperator.INC, parameterName.makeRef());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -34,7 +34,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.*;
|
import static org.jetbrains.k2js.translate.utils.BindingUtils.*;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.*;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.convertToStatement;
|
||||||
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setParameters;
|
||||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getPrimaryConstructorParameters;
|
import static org.jetbrains.k2js.translate.utils.PsiUtils.getPrimaryConstructorParameters;
|
||||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.translateArgumentList;
|
import static org.jetbrains.k2js.translate.utils.TranslationUtils.translateArgumentList;
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JsName superMethodName = context().scope().declareName(Namer.superMethodName());
|
JsName superMethodName = context().scope().declareName(Namer.superMethodName());
|
||||||
initializerStatements.add(convertToStatement(newInvocation(thisQualifiedReference(superMethodName), arguments)));
|
initializerStatements.add(convertToStatement(new JsInvocation(new JsNameRef(superMethodName, JsLiteral.THIS), arguments)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-7
@@ -17,17 +17,14 @@
|
|||||||
package org.jetbrains.k2js.translate.intrinsic.functions.basic;
|
package org.jetbrains.k2js.translate.intrinsic.functions.basic;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsInvocation;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.newInvocation;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
@@ -45,8 +42,6 @@ public final class BuiltInFunctionIntrinsic extends FunctionIntrinsic {
|
|||||||
public JsExpression apply(@Nullable JsExpression receiver, @NotNull List<JsExpression> arguments,
|
public JsExpression apply(@Nullable JsExpression receiver, @NotNull List<JsExpression> arguments,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
assert receiver != null;
|
assert receiver != null;
|
||||||
JsNameRef functionReference = AstUtil.newQualifiedNameRef(functionName);
|
return new JsInvocation(new JsNameRef(functionName, receiver), arguments);
|
||||||
setQualifier(functionReference, receiver);
|
|
||||||
return newInvocation(functionReference, arguments);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-6
@@ -2,15 +2,12 @@ package org.jetbrains.k2js.translate.intrinsic.functions.basic;
|
|||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
@@ -30,8 +27,6 @@ public final class BuiltInPropertyIntrinsic extends FunctionIntrinsic {
|
|||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
assert receiver != null;
|
assert receiver != null;
|
||||||
assert arguments.isEmpty() : "Properties can't have arguments.";
|
assert arguments.isEmpty() : "Properties can't have arguments.";
|
||||||
JsNameRef propertyReference = AstUtil.newQualifiedNameRef(propertyName);
|
return new JsNameRef(propertyName, receiver);
|
||||||
setQualifier(propertyReference, receiver);
|
|
||||||
return propertyReference;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-9
@@ -18,8 +18,8 @@ package org.jetbrains.k2js.translate.intrinsic.functions.basic;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsInvocation;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
@@ -27,20 +27,18 @@ import org.jetbrains.k2js.translate.context.TranslationContext;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.ErrorReportingUtils.atLocation;
|
import static org.jetbrains.k2js.translate.utils.ErrorReportingUtils.atLocation;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.newInvocation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
public final class CallStandardMethodIntrinsic extends FunctionIntrinsic {
|
public final class CallStandardMethodIntrinsic extends FunctionIntrinsic {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String methodName;
|
private final JsNameRef methodName;
|
||||||
|
|
||||||
private final boolean receiverShouldBeNotNull;
|
private final boolean receiverShouldBeNotNull;
|
||||||
private final int expectedParamsNumber;
|
private final int expectedParamsNumber;
|
||||||
|
|
||||||
public CallStandardMethodIntrinsic(@NotNull String methodName, boolean receiverShouldBeNotNull, int expectedParamsNumber) {
|
public CallStandardMethodIntrinsic(@NotNull JsNameRef methodName, boolean receiverShouldBeNotNull, int expectedParamsNumber) {
|
||||||
this.methodName = methodName;
|
this.methodName = methodName;
|
||||||
this.receiverShouldBeNotNull = receiverShouldBeNotNull;
|
this.receiverShouldBeNotNull = receiverShouldBeNotNull;
|
||||||
this.expectedParamsNumber = expectedParamsNumber;
|
this.expectedParamsNumber = expectedParamsNumber;
|
||||||
@@ -53,14 +51,13 @@ public final class CallStandardMethodIntrinsic extends FunctionIntrinsic {
|
|||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
assert (receiver != null == receiverShouldBeNotNull);
|
assert (receiver != null == receiverShouldBeNotNull);
|
||||||
assert arguments.size() == expectedParamsNumber : errorMessage(receiver, arguments);
|
assert arguments.size() == expectedParamsNumber : errorMessage(receiver, arguments);
|
||||||
JsNameRef iteratorFunName = AstUtil.newQualifiedNameRef(methodName);
|
return new JsInvocation(methodName, composeArguments(receiver, arguments));
|
||||||
return newInvocation(iteratorFunName, composeArguments(receiver, arguments));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String errorMessage(@Nullable JsExpression receiver, @NotNull List<JsExpression> arguments) {
|
private String errorMessage(@Nullable JsExpression receiver, @NotNull List<JsExpression> arguments) {
|
||||||
return "Incorrect number of arguments " + arguments.size() + " when expected " + expectedParamsNumber + " on method " + methodName + " " +
|
return "Incorrect number of arguments " + arguments.size() + " when expected " + expectedParamsNumber + " on method " + methodName + " " +
|
||||||
atLocation(receiver, arguments);
|
atLocation(receiver, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -75,4 +72,4 @@ public final class CallStandardMethodIntrinsic extends FunctionIntrinsic {
|
|||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -19,6 +19,7 @@ package org.jetbrains.k2js.translate.intrinsic.functions.factories;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsArrayAccess;
|
import com.google.dart.compiler.backend.js.ast.JsArrayAccess;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
@@ -91,8 +92,8 @@ public final class ArrayFIF extends CompositeFIF {
|
|||||||
add(pattern(ARRAYS, "get"), GET_INTRINSIC);
|
add(pattern(ARRAYS, "get"), GET_INTRINSIC);
|
||||||
add(pattern(ARRAYS, "set"), SET_INTRINSIC);
|
add(pattern(ARRAYS, "set"), SET_INTRINSIC);
|
||||||
add(pattern(ARRAYS, "<get-size>"), ARRAY_LENGTH_INTRINSIC);
|
add(pattern(ARRAYS, "<get-size>"), ARRAY_LENGTH_INTRINSIC);
|
||||||
add(pattern(ARRAYS, "<get-indices>"), new CallStandardMethodIntrinsic("Kotlin.arrayIndices", true, 0));
|
add(pattern(ARRAYS, "<get-indices>"), new CallStandardMethodIntrinsic(new JsNameRef("arrayIndices", "Kotlin"), true, 0));
|
||||||
add(pattern(ARRAYS, "iterator"), new CallStandardMethodIntrinsic("Kotlin.arrayIterator", true, 0));
|
add(pattern(ARRAYS, "iterator"), new CallStandardMethodIntrinsic(new JsNameRef("arrayIterator", "Kotlin"), true, 0));
|
||||||
add(pattern(ARRAYS, "<init>"), new CallStandardMethodIntrinsic("Kotlin.arrayFromFun", false, 2));
|
add(pattern(ARRAYS, "<init>"), new CallStandardMethodIntrinsic(new JsNameRef("arrayFromFun", "Kotlin"), false, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.translate.intrinsic.functions.factories;
|
package org.jetbrains.k2js.translate.intrinsic.functions.factories;
|
||||||
|
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.CallStandardMethodIntrinsic;
|
import org.jetbrains.k2js.translate.intrinsic.functions.basic.CallStandardMethodIntrinsic;
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ public final class RangesFIF extends CompositeFIF {
|
|||||||
public static final FunctionIntrinsicFactory INSTANCE = new RangesFIF();
|
public static final FunctionIntrinsicFactory INSTANCE = new RangesFIF();
|
||||||
|
|
||||||
private RangesFIF() {
|
private RangesFIF() {
|
||||||
add(pattern("Int.upto"), new CallStandardMethodIntrinsic("Kotlin.intUpto", true, 1));
|
add(pattern("Int.upto"), new CallStandardMethodIntrinsic(new JsNameRef("intUpto", "Kotlin"), true, 1));
|
||||||
add(pattern("Int.downto"), new CallStandardMethodIntrinsic("Kotlin.intDownto", true, 1));
|
add(pattern("Int.downto"), new CallStandardMethodIntrinsic(new JsNameRef("intDownto", "Kotlin"), true, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.k2js.translate.intrinsic.functions.factories;
|
package org.jetbrains.k2js.translate.intrinsic.functions.factories;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsInvocation;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -29,7 +30,6 @@ import org.jetbrains.k2js.translate.intrinsic.functions.patterns.DescriptorPredi
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.intrinsic.functions.patterns.PatternBuilder.pattern;
|
import static org.jetbrains.k2js.translate.intrinsic.functions.patterns.PatternBuilder.pattern;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.newInvocation;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +52,7 @@ public final class StringOperationFIF extends CompositeFIF {
|
|||||||
//TODO: provide better way
|
//TODO: provide better way
|
||||||
JsNameRef charAtReference = AstUtil.newQualifiedNameRef("charAt");
|
JsNameRef charAtReference = AstUtil.newQualifiedNameRef("charAt");
|
||||||
setQualifier(charAtReference, receiver);
|
setQualifier(charAtReference, receiver);
|
||||||
return newInvocation(charAtReference, arguments);
|
return new JsInvocation(charAtReference, arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.translate.intrinsic.functions.factories;
|
package org.jetbrains.k2js.translate.intrinsic.functions.factories;
|
||||||
|
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.BuiltInFunctionIntrinsic;
|
import org.jetbrains.k2js.translate.intrinsic.functions.basic.BuiltInFunctionIntrinsic;
|
||||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.CallStandardMethodIntrinsic;
|
import org.jetbrains.k2js.translate.intrinsic.functions.basic.CallStandardMethodIntrinsic;
|
||||||
@@ -28,7 +29,7 @@ import static org.jetbrains.k2js.translate.intrinsic.functions.patterns.PatternB
|
|||||||
*/
|
*/
|
||||||
public final class TopLevelFIF extends CompositeFIF {
|
public final class TopLevelFIF extends CompositeFIF {
|
||||||
@NotNull
|
@NotNull
|
||||||
public static final CallStandardMethodIntrinsic EQUALS = new CallStandardMethodIntrinsic("Kotlin.equals", true, 1);
|
public static final CallStandardMethodIntrinsic EQUALS = new CallStandardMethodIntrinsic(new JsNameRef("equals", "Kotlin"), true, 1);
|
||||||
@NotNull
|
@NotNull
|
||||||
public static final FunctionIntrinsicFactory INSTANCE = new TopLevelFIF();
|
public static final FunctionIntrinsicFactory INSTANCE = new TopLevelFIF();
|
||||||
|
|
||||||
@@ -37,6 +38,6 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
add(pattern("equals"), EQUALS);
|
add(pattern("equals"), EQUALS);
|
||||||
add(pattern(NamePredicate.PRIMITIVE_NUMBERS, "equals"), EQUALS);
|
add(pattern(NamePredicate.PRIMITIVE_NUMBERS, "equals"), EQUALS);
|
||||||
add(pattern("String|Boolean|Char|Number.equals"), EQUALS);
|
add(pattern("String|Boolean|Char|Number.equals"), EQUALS);
|
||||||
add(pattern("arrayOfNulls"), new CallStandardMethodIntrinsic("Kotlin.nullArray", false, 1));
|
add(pattern("arrayOfNulls"), new CallStandardMethodIntrinsic(new JsNameRef("nullArray", "Kotlin"), false, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -17,6 +17,8 @@
|
|||||||
package org.jetbrains.k2js.translate.operation;
|
package org.jetbrains.k2js.translate.operation;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsBinaryOperation;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsBinaryOperator;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -89,7 +91,7 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
|||||||
JsExpression getExpression = accessTranslator.translateAsGet();
|
JsExpression getExpression = accessTranslator.translateAsGet();
|
||||||
JsExpression reassignment = variableReassignment(getExpression);
|
JsExpression reassignment = variableReassignment(getExpression);
|
||||||
JsExpression getNewValue = accessTranslator.translateAsGet();
|
JsExpression getNewValue = accessTranslator.translateAsGet();
|
||||||
return AstUtil.newSequence(reassignment, getNewValue);
|
return new JsBinaryOperation(JsBinaryOperator.COMMA, reassignment, getNewValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: decide if this expression can be optimised in case of direct access (not property)
|
//TODO: decide if this expression can be optimised in case of direct access (not property)
|
||||||
|
|||||||
+1
-3
@@ -96,8 +96,6 @@ public abstract class AbstractCallExpressionTranslator extends AbstractTranslato
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<JsExpression> wrapInArrayLiteral(@NotNull List<JsExpression> translatedArgs) {
|
private static List<JsExpression> wrapInArrayLiteral(@NotNull List<JsExpression> translatedArgs) {
|
||||||
JsArrayLiteral argsWrappedInArray = new JsArrayLiteral();
|
return Collections.<JsExpression>singletonList(new JsArrayLiteral(translatedArgs));
|
||||||
argsWrappedInArray.getExpressions().addAll(translatedArgs);
|
|
||||||
return Arrays.<JsExpression>asList(argsWrappedInArray);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,9 +196,7 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression constructExtensionLiteralCall(@NotNull JsExpression realReceiver) {
|
private JsExpression constructExtensionLiteralCall(@NotNull JsExpression realReceiver) {
|
||||||
List<JsExpression> callArguments = generateExtensionCallArgumentList(realReceiver);
|
List<JsExpression> callArguments = generateExtensionCallArgumentList(realReceiver);
|
||||||
JsInvocation callMethodInvocation = generateCallMethodInvocation();
|
return new JsInvocation(new JsNameRef("call", callParameters.getFunctionReference()), callArguments);
|
||||||
setArguments(callMethodInvocation, callArguments);
|
|
||||||
return callMethodInvocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -233,7 +231,7 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
List<JsExpression> argumentList = generateExtensionCallArgumentList(receiver);
|
List<JsExpression> argumentList = generateExtensionCallArgumentList(receiver);
|
||||||
JsExpression functionReference = callParameters.getFunctionReference();
|
JsExpression functionReference = callParameters.getFunctionReference();
|
||||||
setQualifier(functionReference, getThisObjectOrQualifier());
|
setQualifier(functionReference, getThisObjectOrQualifier());
|
||||||
return newInvocation(functionReference, argumentList);
|
return new JsInvocation(functionReference, argumentList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -256,7 +254,7 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
return ecma5PropertyAccess(qualifiedCallee);
|
return ecma5PropertyAccess(qualifiedCallee);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newInvocation(qualifiedCallee, arguments);
|
return new JsInvocation(qualifiedCallee, arguments);
|
||||||
}
|
}
|
||||||
}, context());
|
}, context());
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -18,6 +18,7 @@ package org.jetbrains.k2js.translate.reference;
|
|||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
@@ -25,7 +26,6 @@ import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
|||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.assignment;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.assignment;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.qualified;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getExpectedThisDescriptor;
|
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getExpectedThisDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +71,7 @@ public final class NativePropertyAccessTranslator extends PropertyAccessTranslat
|
|||||||
private JsExpression doTranslateAsGet(JsExpression receiver) {
|
private JsExpression doTranslateAsGet(JsExpression receiver) {
|
||||||
JsName nativePropertyName = context().getNameForDescriptor(propertyDescriptor);
|
JsName nativePropertyName = context().getNameForDescriptor(propertyDescriptor);
|
||||||
if (receiver != null) {
|
if (receiver != null) {
|
||||||
return qualified(nativePropertyName, receiver);
|
return new JsNameRef(nativePropertyName, receiver);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nativePropertyName.makeRef();
|
return nativePropertyName.makeRef();
|
||||||
|
|||||||
+2
-2
@@ -18,13 +18,13 @@ package org.jetbrains.k2js.translate.reference;
|
|||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.qualified;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.isBackingFieldReference;
|
import static org.jetbrains.k2js.translate.utils.PsiUtils.isBackingFieldReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +49,7 @@ public final class ReferenceTranslator {
|
|||||||
return translateAsLocalNameReference(referencedDescriptor, context);
|
return translateAsLocalNameReference(referencedDescriptor, context);
|
||||||
}
|
}
|
||||||
JsName referencedName = context.getNameForDescriptor(referencedDescriptor);
|
JsName referencedName = context.getNameForDescriptor(referencedDescriptor);
|
||||||
return qualified(referencedName, qualifier);
|
return new JsNameRef(referencedName, qualifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public final class TranslationUtils {
|
|||||||
public static JsNameRef backingFieldReference(@NotNull TranslationContext context,
|
public static JsNameRef backingFieldReference(@NotNull TranslationContext context,
|
||||||
@NotNull PropertyDescriptor descriptor) {
|
@NotNull PropertyDescriptor descriptor) {
|
||||||
JsName backingFieldName = context.getNameForDescriptor(descriptor);
|
JsName backingFieldName = context.getNameForDescriptor(descriptor);
|
||||||
return qualified(backingFieldName, JsLiteral.THIS);
|
return new JsNameRef(backingFieldName, JsLiteral.THIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -110,7 +110,7 @@ public final class TranslationUtils {
|
|||||||
@NotNull PropertyDescriptor descriptor,
|
@NotNull PropertyDescriptor descriptor,
|
||||||
@NotNull JsExpression assignTo) {
|
@NotNull JsExpression assignTo) {
|
||||||
JsNameRef backingFieldReference = backingFieldReference(context, descriptor);
|
JsNameRef backingFieldReference = backingFieldReference(context, descriptor);
|
||||||
return JsAstUtils.assignment(backingFieldReference, assignTo);
|
return assignment(backingFieldReference, assignTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -125,37 +125,8 @@ public final class TranslationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsNameRef getQualifiedReference(@NotNull TranslationContext context,
|
public static JsNameRef getQualifiedReference(@NotNull TranslationContext context, @NotNull DeclarationDescriptor descriptor) {
|
||||||
@NotNull DeclarationDescriptor descriptor) {
|
return new JsNameRef(context.getNameForDescriptor(descriptor), context.getQualifierForDescriptor(descriptor));
|
||||||
JsName name = context.getNameForDescriptor(descriptor);
|
|
||||||
JsNameRef reference = name.makeRef();
|
|
||||||
JsNameRef qualifier = context.getQualifierForDescriptor(descriptor);
|
|
||||||
if (qualifier != null) {
|
|
||||||
setQualifier(reference, qualifier);
|
|
||||||
}
|
|
||||||
return reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: refactor
|
|
||||||
@NotNull
|
|
||||||
public static JsExpression getThisObject(@NotNull TranslationContext context,
|
|
||||||
@NotNull DeclarationDescriptor correspondingDeclaration) {
|
|
||||||
if (correspondingDeclaration instanceof ClassDescriptor) {
|
|
||||||
JsName alias = context.aliasingContext().getAliasForThis(correspondingDeclaration);
|
|
||||||
if (alias != null) {
|
|
||||||
return alias.makeRef();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (correspondingDeclaration instanceof CallableDescriptor) {
|
|
||||||
DeclarationDescriptor receiverDescriptor =
|
|
||||||
getExpectedReceiverDescriptor((CallableDescriptor) correspondingDeclaration);
|
|
||||||
assert receiverDescriptor != null;
|
|
||||||
JsName alias = context.aliasingContext().getAliasForThis(receiverDescriptor);
|
|
||||||
if (alias != null) {
|
|
||||||
return alias.makeRef();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return JsLiteral.THIS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user