Generate JS source maps for temporary vars declarations and definitions
This commit is contained in:
@@ -55,15 +55,17 @@ public final class DynamicContext {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public TemporaryVariable declareTemporary(@Nullable JsExpression initExpression) {
|
||||
public TemporaryVariable declareTemporary(@Nullable JsExpression initExpression, @Nullable Object sourceInfo) {
|
||||
if (vars == null) {
|
||||
vars = new JsVars();
|
||||
MetadataProperties.setSynthetic(vars, true);
|
||||
currentBlock.getStatements().add(vars);
|
||||
vars.setSource(sourceInfo);
|
||||
}
|
||||
|
||||
JsName temporaryName = JsScope.declareTemporary();
|
||||
JsVar var = new JsVar(temporaryName, null);
|
||||
var.setSource(sourceInfo);
|
||||
MetadataProperties.setSynthetic(var, true);
|
||||
vars.add(var);
|
||||
if (initExpression != null) {
|
||||
|
||||
+4
-4
@@ -399,13 +399,13 @@ public class TranslationContext {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public TemporaryVariable declareTemporary(@Nullable JsExpression initExpression) {
|
||||
return dynamicContext.declareTemporary(initExpression);
|
||||
public TemporaryVariable declareTemporary(@Nullable JsExpression initExpression, @Nullable Object source) {
|
||||
return dynamicContext.declareTemporary(initExpression, source);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression defineTemporary(@NotNull JsExpression initExpression) {
|
||||
TemporaryVariable var = dynamicContext.declareTemporary(initExpression);
|
||||
TemporaryVariable var = dynamicContext.declareTemporary(initExpression, initExpression.getSource());
|
||||
addStatementToCurrentBlock(var.assignmentStatement());
|
||||
return var.reference();
|
||||
}
|
||||
@@ -420,7 +420,7 @@ public class TranslationContext {
|
||||
TemporaryConstVariable tempVar = expressionToTempConstVariableCache.get(expression);
|
||||
|
||||
if (tempVar == null) {
|
||||
TemporaryVariable tmpVar = declareTemporary(expression);
|
||||
TemporaryVariable tmpVar = declareTemporary(expression, expression.getSource());
|
||||
|
||||
tempVar = new TemporaryConstVariable(tmpVar.name(), tmpVar.assignmentExpression());
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ fun translateForExpression(expression: KtForExpression, context: TranslationCont
|
||||
val rangeExpression = context.defineTemporary(Translation.translateAsExpression(loopRange, context))
|
||||
val length = ArrayFIF.LENGTH_PROPERTY_INTRINSIC.apply(rangeExpression, listOf<JsExpression>(), context)
|
||||
val end = context.defineTemporary(length)
|
||||
val index = context.declareTemporary(JsIntLiteral(0))
|
||||
val index = context.declareTemporary(JsIntLiteral(0), expression)
|
||||
|
||||
val arrayAccess = JsArrayAccess(rangeExpression, index.reference()).source(expression)
|
||||
val body = translateBody(arrayAccess)
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
expressionToCast = JsAstUtils.charToBoxedChar(expressionToCast);
|
||||
}
|
||||
|
||||
TemporaryVariable temporary = context().declareTemporary(expressionToCast);
|
||||
TemporaryVariable temporary = context().declareTemporary(expressionToCast, expression);
|
||||
JsExpression isCheck = translateIsCheck(temporary.assignmentExpression(), typeReference);
|
||||
if (isCheck == null) return expressionToCast;
|
||||
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
|
||||
if (type != null && KotlinBuiltIns.isCharOrNullableChar(type)) {
|
||||
if (type.isMarkedNullable()) {
|
||||
TemporaryVariable tmp = context().declareTemporary(translatedExpression);
|
||||
TemporaryVariable tmp = context().declareTemporary(translatedExpression, entry);
|
||||
append(new JsConditional(JsAstUtils.equality(tmp.assignmentExpression(), new JsNullLiteral()),
|
||||
new JsNullLiteral(),
|
||||
JsAstUtils.charToString(tmp.reference())));
|
||||
|
||||
@@ -195,7 +195,7 @@ public final class Translation {
|
||||
|
||||
assert jsNode instanceof JsStatement : "Unexpected node of type: " + jsNode.getClass().toString();
|
||||
if (BindingContextUtilsKt.isUsedAsExpression(expression, context.bindingContext())) {
|
||||
TemporaryVariable result = context.declareTemporary(null);
|
||||
TemporaryVariable result = context.declareTemporary(null, expression);
|
||||
AssignToExpressionMutator saveResultToTemporaryMutator = new AssignToExpressionMutator(result.reference());
|
||||
block.getStatements().add(mutateLastExpression(jsNode, saveResultToTemporaryMutator));
|
||||
return result.reference();
|
||||
|
||||
+1
-1
@@ -212,7 +212,7 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
if (rightExpression instanceof JsNameRef) {
|
||||
result = rightExpression; // Reuse tmp variable
|
||||
} else {
|
||||
result = context().declareTemporary(null).reference();
|
||||
result = context().declareTemporary(null, rightKtExpression).reference();
|
||||
JsExpression rightAssignment = JsAstUtils.assignment(result.deepCopy(), rightExpression).source(rightKtExpression);
|
||||
rightBlock.getStatements().add(JsAstUtils.asSyntheticStatement(rightAssignment));
|
||||
}
|
||||
|
||||
+1
-1
@@ -114,7 +114,7 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
||||
private JsExpression asPostfix() {
|
||||
// code fragment: expr(a++)
|
||||
// generate: expr( (t1 = a, t2 = t1, a = t1.inc(), t2) )
|
||||
TemporaryVariable t1 = context().declareTemporary(accessTranslator.translateAsGet().source(expression));
|
||||
TemporaryVariable t1 = context().declareTemporary(accessTranslator.translateAsGet().source(expression), expression);
|
||||
accessBlock.getStatements().add(t1.assignmentStatement());
|
||||
JsExpression variableReassignment = variableReassignment(context().innerBlock(accessBlock), t1.reference())
|
||||
.source(expression);
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.utils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.newSequence;
|
||||
|
||||
//TODO: look for what should go there
|
||||
public final class TemporariesUtils {
|
||||
private TemporariesUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<TemporaryVariable> fromExpressionList(@NotNull List<JsExpression> expressions,
|
||||
@NotNull TranslationContext context) {
|
||||
List<TemporaryVariable> result = Lists.newArrayList();
|
||||
for (JsExpression expression : expressions) {
|
||||
result.add(context.declareTemporary(expression));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JsExpression> toExpressionList(@NotNull List<TemporaryVariable> temporaries) {
|
||||
List<JsExpression> result = Lists.newArrayList();
|
||||
for (TemporaryVariable temp : temporaries) {
|
||||
result.add(temp.reference());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression temporariesInitialization(@NotNull TemporaryVariable... temporaries) {
|
||||
List<JsExpression> result = Lists.newArrayList();
|
||||
for (TemporaryVariable temporary : temporaries) {
|
||||
result.add(temporary.assignmentExpression());
|
||||
}
|
||||
return newSequence(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JsExpression> temporariesInitialization(@NotNull List<TemporaryVariable> temporaries) {
|
||||
List<JsExpression> result = Lists.newArrayList();
|
||||
for (TemporaryVariable temporary : temporaries) {
|
||||
result.add(temporary.assignmentExpression());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -37,6 +37,8 @@ public final class AssignToExpressionMutator implements Mutator {
|
||||
if (!(node instanceof JsExpression)) {
|
||||
return node;
|
||||
}
|
||||
return assignment(toAssign, (JsExpression) node);
|
||||
JsExpression result = assignment(toAssign, (JsExpression) node);
|
||||
result.setSource(node.getSource());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ fun box(x: Int, y: Int) {
|
||||
|
||||
fun foo(x: Int) = x
|
||||
|
||||
// LINES: 5 * 3 3 3 * 3 3 4 4 4 * 4 4 4 4 2 3 7 7 7
|
||||
// LINES: 5 3 3 4 3 3 3 3 * 3 3 4 4 4 4 * 4 4 4 4 2 3 7 7 7
|
||||
+1
-1
@@ -11,4 +11,4 @@ fun baz() = 1
|
||||
|
||||
fun bar() = 2
|
||||
|
||||
// LINES: 8 * 2 2 3 4 4 5 2 8 8 10 10 10 12 12 12
|
||||
// LINES: 8 3 3 2 2 3 4 4 4 5 5 2 8 8 10 10 10 12 12 12
|
||||
@@ -13,4 +13,4 @@ fun box() {
|
||||
)
|
||||
}
|
||||
|
||||
// LINES: 14 8 3 2 2 3 3 3 8 11 11 * 3 7 12 3 3 4 4
|
||||
// LINES: 14 8 8 7 3 2 2 3 3 3 8 8 11 11 * 3 7 12 3 3 4 4
|
||||
+1
-1
@@ -17,4 +17,4 @@ fun box() {
|
||||
}
|
||||
}
|
||||
|
||||
// LINES: 18 2 10 15 2 2 2 2 2 3 3 6 6 6 6 7 7 10 10 10 10 10 11 11 14 14 15 15 15 15 15 15 15 15 15 15 15 15 16 16
|
||||
// LINES: 18 2 2 10 15 2 2 2 2 2 3 3 6 6 6 6 7 7 10 10 10 10 10 11 11 14 14 15 15 15 15 15 15 15 15 15 15 15 15 16 16
|
||||
+1
-1
@@ -13,4 +13,4 @@ fun foo(): Int = 23
|
||||
|
||||
fun bar(): IntRange = 1000..2000
|
||||
|
||||
// LINES: 10 2 2 2 3 4 4 5 6 6 7 8 8 12 12 12 14 14 14
|
||||
// LINES: 10 2 2 2 2 3 4 4 5 6 6 7 8 8 12 12 12 14 14 14
|
||||
+1
-1
@@ -13,4 +13,4 @@ open class A
|
||||
|
||||
open class B : A()
|
||||
|
||||
// LINES: 10 2 2 2 3 4 4 5 6 6 8 8 12 * 14 14
|
||||
// LINES: 10 2 2 2 2 3 4 4 5 6 6 8 8 12 * 14 14
|
||||
@@ -12,4 +12,4 @@ fun box() {
|
||||
}
|
||||
}
|
||||
|
||||
// LINES: 13 5 2 2 3 5 8 8 * 3 4 9 3 11 11
|
||||
// LINES: 13 5 5 4 2 2 3 5 5 8 8 * 3 4 9 3 11 11
|
||||
Reference in New Issue
Block a user