JS backend: Move CallInfo extension to separate file.

This commit is contained in:
Erokhin Stanislav
2014-01-30 22:27:00 +04:00
parent a4436806f7
commit 47ed126aa4
2 changed files with 81 additions and 52 deletions
@@ -78,58 +78,6 @@ fun TranslationContext.getCallInfo(resolvedCall: ResolvedCall<out FunctionDescri
return FunctionCallInfo(callInfo, argumentsInfo)
}
val CallInfo.callableDescriptor: CallableDescriptor
get() = resolvedCall.getResultingDescriptor().getOriginal()
fun CallInfo.isExtension(): Boolean = receiverObject != null
fun CallInfo.isMemberCall(): Boolean = thisObject != null
fun CallInfo.isNative(): Boolean = AnnotationsUtils.isNativeObject(callableDescriptor)
fun CallInfo.isSuperInvocation(): Boolean {
val thisObject = resolvedCall.getThisObject()
return thisObject is ExpressionReceiver && ((thisObject as ExpressionReceiver)).getExpression() is JetSuperExpression
}
fun CallInfo.constructSafeCallIsNeeded(result: JsExpression): JsExpression {
if (!resolvedCall.isSafeCall())
return result
val nullableReceiverForSafeCall = when (resolvedCall.getExplicitReceiverKind()) {
BOTH_RECEIVERS, RECEIVER_ARGUMENT -> receiverObject
else -> thisObject
}
return CallType.SAFE.constructCall(nullableReceiverForSafeCall, object : CallType.CallConstructor {
override fun construct(receiver: JsExpression?): JsExpression {
return result
}
}, context)
}
val VariableAccessInfo.variableDescriptor: VariableDescriptor
get() = callableDescriptor as VariableDescriptor
val VariableAccessInfo.variableName: JsName
get() = context.getNameForDescriptor(variableDescriptor)
fun VariableAccessInfo.isGetAccess(): Boolean = value == null
fun VariableAccessInfo.getAccessFunctionName(): String = Namer.getNameForAccessor(variableName.getIdent()!!, isGetAccess(), false)
fun VariableAccessInfo.constructAccessExpression(ref: JsNameRef): JsExpression {
if (isGetAccess()) {
return ref
} else {
return JsAstUtils.assignment(ref, value!!)
}
}
val FunctionCallInfo.functionName: JsName
get() = context.getNameForDescriptor(callableDescriptor)
fun FunctionCallInfo.hasSpreadOperator(): Boolean = argumentsInfo.isHasSpreadOperator()
private fun TranslationContext.getThisObject(receiverValue: ReceiverValue): JsExpression {
assert(receiverValue.exists(), "receiverValue must be exist here")
return getThisObject(getDeclarationDescriptorForReceiver(receiverValue))
@@ -0,0 +1,81 @@
/*
* 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.reference
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
import org.jetbrains.k2js.translate.utils.AnnotationsUtils
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.jet.lang.psi.JetSuperExpression
import com.google.dart.compiler.backend.js.ast.JsExpression
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
import com.google.dart.compiler.backend.js.ast.JsName
import org.jetbrains.k2js.translate.context.Namer
import com.google.dart.compiler.backend.js.ast.JsNameRef
import org.jetbrains.k2js.translate.utils.JsAstUtils
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.*
val CallInfo.callableDescriptor: CallableDescriptor
get() = resolvedCall.getResultingDescriptor().getOriginal()
fun CallInfo.isExtension(): Boolean = receiverObject != null
fun CallInfo.isMemberCall(): Boolean = thisObject != null
fun CallInfo.isNative(): Boolean = AnnotationsUtils.isNativeObject(callableDescriptor)
fun CallInfo.isSuperInvocation(): Boolean {
val thisObject = resolvedCall.getThisObject()
return thisObject is ExpressionReceiver && ((thisObject as ExpressionReceiver)).getExpression() is JetSuperExpression
}
fun CallInfo.constructSafeCallIsNeeded(result: JsExpression): JsExpression {
if (!resolvedCall.isSafeCall())
return result
val nullableReceiverForSafeCall = when (resolvedCall.getExplicitReceiverKind()) {
BOTH_RECEIVERS, RECEIVER_ARGUMENT -> receiverObject
else -> thisObject
}
return CallType.SAFE.constructCall(nullableReceiverForSafeCall, object : CallType.CallConstructor {
override fun construct(receiver: JsExpression?): JsExpression {
return result
}
}, context)
}
val VariableAccessInfo.variableDescriptor: VariableDescriptor
get() = callableDescriptor as VariableDescriptor
val VariableAccessInfo.variableName: JsName
get() = context.getNameForDescriptor(variableDescriptor)
fun VariableAccessInfo.isGetAccess(): Boolean = value == null
fun VariableAccessInfo.getAccessFunctionName(): String = Namer.getNameForAccessor(variableName.getIdent()!!, isGetAccess(), false)
fun VariableAccessInfo.constructAccessExpression(ref: JsNameRef): JsExpression {
if (isGetAccess()) {
return ref
} else {
return JsAstUtils.assignment(ref, value!!)
}
}
val FunctionCallInfo.functionName: JsName
get() = context.getNameForDescriptor(callableDescriptor)
fun FunctionCallInfo.hasSpreadOperator(): Boolean = argumentsInfo.isHasSpreadOperator()