JS inline: save inline status during translation
This commit is contained in:
committed by
Zalim Bashorov
parent
efac671ae6
commit
3cdae252ef
@@ -9,6 +9,7 @@
|
|||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
||||||
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||||
|
<orderEntry type="module" module-name="descriptors" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ package com.google.dart.compiler.backend.js.ast;
|
|||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import com.intellij.util.SmartList;
|
import com.intellij.util.SmartList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.InlineStrategy;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class JsInvocation extends JsExpressionImpl.JsExpressionHasArguments {
|
public final class JsInvocation extends JsExpressionImpl.JsExpressionHasArguments {
|
||||||
private JsExpression qualifier;
|
private JsExpression qualifier;
|
||||||
|
private InlineStrategy inlineStrategy = InlineStrategy.NOT_INLINE;
|
||||||
|
|
||||||
public JsInvocation() {
|
public JsInvocation() {
|
||||||
super(new SmartList<JsExpression>());
|
super(new SmartList<JsExpression>());
|
||||||
@@ -50,6 +52,14 @@ public final class JsInvocation extends JsExpressionImpl.JsExpressionHasArgument
|
|||||||
this.qualifier = qualifier;
|
this.qualifier = qualifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InlineStrategy getInlineStrategy() {
|
||||||
|
return inlineStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInlineStrategy(InlineStrategy inlineStrategy) {
|
||||||
|
this.inlineStrategy = inlineStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(JsVisitor v) {
|
public void accept(JsVisitor v) {
|
||||||
v.visitInvocation(this);
|
v.visitInvocation(this);
|
||||||
@@ -76,7 +86,7 @@ public final class JsInvocation extends JsExpressionImpl.JsExpressionHasArgument
|
|||||||
JsExpression qualifierCopy = AstUtil.deepCopy(qualifier);
|
JsExpression qualifierCopy = AstUtil.deepCopy(qualifier);
|
||||||
List<JsExpression> argumentsCopy = AstUtil.deepCopy(arguments);
|
List<JsExpression> argumentsCopy = AstUtil.deepCopy(arguments);
|
||||||
JsInvocation copy = new JsInvocation(qualifierCopy, argumentsCopy);
|
JsInvocation copy = new JsInvocation(qualifierCopy, argumentsCopy);
|
||||||
copy.setInlineStatus(getInlineStatus());
|
copy.setInlineStrategy(inlineStrategy);
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-1
@@ -17,9 +17,19 @@
|
|||||||
package org.jetbrains.k2js.translate.reference;
|
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.JsInvocation;
|
||||||
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.CallableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.InlineStrategy;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.InlineUtil;
|
||||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
|
|
||||||
@@ -31,10 +41,39 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
|||||||
@Nullable JsExpression receiver,
|
@Nullable JsExpression receiver,
|
||||||
@NotNull TranslationContext context
|
@NotNull TranslationContext context
|
||||||
) {
|
) {
|
||||||
return (new CallExpressionTranslator(expression, receiver, context)).translate();
|
JsExpression callExpression = (new CallExpressionTranslator(expression, receiver, context)).translate();
|
||||||
|
|
||||||
|
if (shouldBeInlined(expression, context)
|
||||||
|
&& callExpression instanceof JsInvocation) {
|
||||||
|
|
||||||
|
((JsInvocation) callExpression).setInlineStrategy(InlineStrategy.IN_PLACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return callExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldBeInlined(@NotNull JetCallExpression expression, @NotNull TranslationContext context) {
|
public static boolean shouldBeInlined(@NotNull JetCallExpression expression, @NotNull TranslationContext context) {
|
||||||
|
ResolvedCall<?> resolvedCall = CallUtilPackage.getResolvedCall(expression, context.bindingContext());
|
||||||
|
assert resolvedCall != null;
|
||||||
|
|
||||||
|
CallableDescriptor descriptor;
|
||||||
|
|
||||||
|
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
|
descriptor = ((VariableAsFunctionResolvedCall) resolvedCall).getVariableCall().getCandidateDescriptor();
|
||||||
|
} else {
|
||||||
|
descriptor = resolvedCall.getCandidateDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptor instanceof SimpleFunctionDescriptor) {
|
||||||
|
return ((SimpleFunctionDescriptor) descriptor).getInlineStrategy().isInline();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptor instanceof ValueParameterDescriptor) {
|
||||||
|
DeclarationDescriptor containingDescriptor = descriptor.getContainingDeclaration();
|
||||||
|
return InlineUtil.getInlineType(containingDescriptor).isInline()
|
||||||
|
&& !InlineUtil.hasNoinlineAnnotation(descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.k2js.translate.utils
|
||||||
|
|
||||||
|
enum class InlineAnnotation(val fqName: String) {
|
||||||
|
INLINE : InlineAnnotation("kotlin.inline")
|
||||||
|
NO_INLINE : InlineAnnotation("kotlin.noinline")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user