From 5a343841d98b6d58ca08d7da69eb5c4049d57e46 Mon Sep 17 00:00:00 2001 From: Erokhin Stanislav Date: Thu, 30 Jan 2014 17:56:14 +0400 Subject: [PATCH] JS backend: add debug info for CallInfo --- .../k2js/translate/reference/CallInfo.kt | 7 +++++++ .../k2js/translate/reference/CallTranslator.kt | 18 ++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallInfo.kt b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallInfo.kt index 036eda910c3..6d23ea76d32 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallInfo.kt +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallInfo.kt @@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.jet.lang.descriptors.PropertyDescriptor import org.jetbrains.jet.lang.descriptors.VariableDescriptor import com.google.dart.compiler.backend.js.ast.JsName +import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils trait CallInfo { @@ -38,6 +39,12 @@ trait CallInfo { val thisObject: JsExpression? val receiverObject: JsExpression? + + fun toString(): String { + val location = DiagnosticUtils.atLocation(context.bindingContext(), callableDescriptor) + val name = callableDescriptor.getName().asString() + return "callableDescriptor: $name at $location; thisObject: $thisObject; receiverObject: $receiverObject" + } } // if value == null, it is get access diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.kt b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.kt index 976e278e630..bf2f2f2d5a1 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.kt +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.kt @@ -31,6 +31,7 @@ import org.jetbrains.k2js.translate.utils.JsAstUtils import org.jetbrains.k2js.translate.context.Namer import org.jetbrains.k2js.translate.utils.ErrorReportingUtils import org.jetbrains.k2js.translate.utils.AnnotationsUtils +import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils val functionCallCases: CallCaseDispatcher = createFunctionCases() @@ -68,7 +69,7 @@ fun ResolvedCall.expectedReceivers(): Boolean { private fun TranslationContext.buildCall(resolvedCall: ResolvedCall, explicitReceivers: ExplicitReceivers): JsExpression { if (resolvedCall is VariableAsFunctionResolvedCall) { - assert(explicitReceivers.receiverObject == null, "VariableAsFunctionResolvedCall must have one receiver") // TODO: add debug info + assert(explicitReceivers.receiverObject == null, "VariableAsFunctionResolvedCall must have one receiver") val variableCall = resolvedCall.getVariableCall() if (variableCall.expectedReceivers()) { val newReceiver = buildGet(variableCall, explicitReceivers.receiverOrThisObject) @@ -90,27 +91,24 @@ private fun TranslationContext.buildCall(resolvedCall: ResolvedCall { val callInfo: I - protected fun unsupported(message: String = "") : Exception { - val stackTrace = Thread.currentThread().getStackTrace() - val methodName = stackTrace.get(stackTrace.lastIndex - 1).getMethodName() - val caseName = javaClass.getName() - return UnsupportedOperationException("this case unsopported: $message [$methodName; $caseName; $callInfo]") + protected fun unsupported(message: String = "") : Nothing { + throw UnsupportedOperationException("this case unsopported. $callInfo") } protected fun I.noReceivers(): JsExpression { - throw unsupported() + unsupported() } protected fun I.thisObject(): JsExpression { - throw unsupported() + unsupported() } protected fun I.receiverArgument(): JsExpression { - throw unsupported() + unsupported() } protected fun I.bothReceivers(): JsExpression { - throw unsupported() + unsupported() } final fun translate(): JsExpression {