JS backend: Use new CallBuilder for property access
This commit is contained in:
@@ -164,6 +164,7 @@ public final class StaticContext {
|
|||||||
packageFqName.isRoot() ? null : getQualifierForParentPackage(packageFqName.parent()));
|
packageFqName.isRoot() ? null : getQualifierForParentPackage(packageFqName.parent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: usage tracker
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsName getNameForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
public JsName getNameForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
||||||
JsName name = names.get(descriptor.getOriginal());
|
JsName name = names.get(descriptor.getOriginal());
|
||||||
@@ -496,13 +497,13 @@ public final class StaticContext {
|
|||||||
private static class QualifierIsNullGenerator extends Generator<Boolean> {
|
private static class QualifierIsNullGenerator extends Generator<Boolean> {
|
||||||
|
|
||||||
private QualifierIsNullGenerator() {
|
private QualifierIsNullGenerator() {
|
||||||
Rule<Boolean> propertiesHaveNoQualifiers = new Rule<Boolean>() {
|
Rule<Boolean> propertiesInClassHaveNoQualifiers = new Rule<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean apply(@NotNull DeclarationDescriptor descriptor) {
|
public Boolean apply(@NotNull DeclarationDescriptor descriptor) {
|
||||||
if (!(descriptor instanceof PropertyDescriptor)) {
|
if ((descriptor instanceof PropertyDescriptor) && descriptor.getContainingDeclaration() instanceof ClassDescriptor) {
|
||||||
return null;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//TODO: hack!
|
//TODO: hack!
|
||||||
@@ -515,7 +516,7 @@ public final class StaticContext {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
addRule(propertiesHaveNoQualifiers);
|
addRule(propertiesInClassHaveNoQualifiers);
|
||||||
addRule(nativeObjectsHaveNoQualifiers);
|
addRule(nativeObjectsHaveNoQualifiers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-7
@@ -40,11 +40,7 @@ public final class QualifiedExpressionTranslator {
|
|||||||
public static AccessTranslator getAccessTranslator(@NotNull JetQualifiedExpression expression,
|
public static AccessTranslator getAccessTranslator(@NotNull JetQualifiedExpression expression,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
JsExpression receiver = translateReceiver(expression, context);
|
JsExpression receiver = translateReceiver(expression, context);
|
||||||
PropertyAccessTranslator result =
|
return new SimpleWrappedVariableAccessTranslator(context, getNotNullSimpleNameSelector(expression), receiver);
|
||||||
PropertyAccessTranslator.newInstance(getNotNullSimpleNameSelector(expression), receiver,
|
|
||||||
CallType.getCallTypeForQualifiedExpression(expression), context);
|
|
||||||
result.setCallType(CallType.getCallTypeForQualifiedExpression(expression));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -65,8 +61,7 @@ public final class QualifiedExpressionTranslator {
|
|||||||
) {
|
) {
|
||||||
if (PropertyAccessTranslator.canBePropertyGetterCall(selector, context)) {
|
if (PropertyAccessTranslator.canBePropertyGetterCall(selector, context)) {
|
||||||
assert selector instanceof JetSimpleNameExpression : "Selectors for properties must be simple names.";
|
assert selector instanceof JetSimpleNameExpression : "Selectors for properties must be simple names.";
|
||||||
return PropertyAccessTranslator.translateAsPropertyGetterCall
|
return new SimpleWrappedVariableAccessTranslator(context, (JetSimpleNameExpression)selector, receiver).translateAsGet();
|
||||||
((JetSimpleNameExpression)selector, receiver, callType, context);
|
|
||||||
}
|
}
|
||||||
if (selector instanceof JetCallExpression) {
|
if (selector instanceof JetCallExpression) {
|
||||||
return invokeCallExpressionTranslator(receiver, selector, callType, context);
|
return invokeCallExpressionTranslator(receiver, selector, callType, context);
|
||||||
|
|||||||
+1
-1
@@ -71,7 +71,7 @@ public final class ReferenceTranslator {
|
|||||||
return BackingFieldAccessTranslator.newInstance(referenceExpression, context);
|
return BackingFieldAccessTranslator.newInstance(referenceExpression, context);
|
||||||
}
|
}
|
||||||
if (PropertyAccessTranslator.canBePropertyAccess(referenceExpression, context)) {
|
if (PropertyAccessTranslator.canBePropertyAccess(referenceExpression, context)) {
|
||||||
return PropertyAccessTranslator.newInstance(referenceExpression, receiver, CallType.NORMAL, context);
|
return new SimpleWrappedVariableAccessTranslator(context, referenceExpression, receiver);
|
||||||
}
|
}
|
||||||
if (ClassObjectAccessTranslator.isClassObjectReference(referenceExpression, context)) {
|
if (ClassObjectAccessTranslator.isClassObjectReference(referenceExpression, context)) {
|
||||||
return ClassObjectAccessTranslator.newInstance(referenceExpression, context);
|
return ClassObjectAccessTranslator.newInstance(referenceExpression, context);
|
||||||
|
|||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.reference;
|
||||||
|
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||||
|
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||||
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
|
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SimpleWrappedVariableAccessTranslator implements CachedAccessTranslator {
|
||||||
|
private final TranslationContext context;
|
||||||
|
private final ResolvedCall<? extends VariableDescriptor> resolvedCall;
|
||||||
|
private final JsExpression receiver;
|
||||||
|
|
||||||
|
public SimpleWrappedVariableAccessTranslator(
|
||||||
|
@NotNull TranslationContext context,
|
||||||
|
@NotNull JetReferenceExpression referenceExpression,
|
||||||
|
JsExpression receiver
|
||||||
|
) {
|
||||||
|
this.context = context;
|
||||||
|
this.receiver = receiver;
|
||||||
|
ResolvedCall<?> resolvedCall = BindingUtils.getResolvedCallForProperty(context.bindingContext(), referenceExpression);
|
||||||
|
assert resolvedCall.getResultingDescriptor() instanceof VariableDescriptor;
|
||||||
|
this.resolvedCall = (ResolvedCall<? extends VariableDescriptor>) resolvedCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public JsExpression translateAsGet() {
|
||||||
|
return ReferencePackage.buildGet(context, resolvedCall, receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public JsExpression translateAsSet(@NotNull JsExpression setTo) {
|
||||||
|
return ReferencePackage.buildSet(context, resolvedCall, setTo, receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public CachedAccessTranslator getCached() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<TemporaryVariable> declaredTemporaries() { // TODO : fix this
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user