From ca6c6ae0f3e54fa8fc4e232334da4fc7aa8b6931 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Wed, 24 Aug 2016 12:51:34 +0300 Subject: [PATCH] Refactoring. Move creation of functionProcessor into resolution module. --- .../calls/tower/NewResolutionOldInference.kt | 38 ++----------------- .../calls/tower/ScopeTowerProcessors.kt | 35 ++++++++++++++++- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index 3232a78b700..5b73724d455 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -73,7 +73,7 @@ class NewResolutionOldInference( scopeTower: ScopeTower, explicitReceiver: Receiver?, context: BasicCallResolutionContext ): ScopeTowerProcessor> { val functionContext = outer.SimpleContext(scopeTower, name, context, tracing) - return outer.createFunctionTowerProcessor(functionContext, explicitReceiver) + return createFunctionProcessor(functionContext, outer.InvokeContext(functionContext), explicitReceiver) } } @@ -95,7 +95,7 @@ class NewResolutionOldInference( val simpleContextF = outer.SimpleContext(scopeTower, name, context, tracing) val simpleContextV = outer.SimpleContext(scopeTower, name, context, tracing) return CompositeScopeTowerProcessor( - createFunctionProcessor(simpleContextF, explicitReceiver, classValueReceiver = false), + createSimpleFunctionProcessor(simpleContextF, explicitReceiver, classValueReceiver = false), createVariableProcessor(simpleContextV, explicitReceiver, classValueReceiver = false) ) } @@ -111,7 +111,7 @@ class NewResolutionOldInference( val call = (context.call as? CallTransformer.CallForImplicitInvoke).sure { "Call should be CallForImplicitInvoke, but it is: ${context.call}" } - return outer.createProcessorWithReceiverValueOrEmpty(explicitReceiver) { + return createProcessorWithReceiverValueOrEmpty(explicitReceiver) { createCallTowerProcessorForExplicitInvoke(functionContext, call.dispatchReceiver, it) } } @@ -189,38 +189,6 @@ class NewResolutionOldInference( this.allCandidates = allCandidates.map { it.resolvedCall } } - private fun createProcessorWithReceiverValueOrEmpty( - explicitReceiver: Receiver?, - create: (ReceiverValue?) -> ScopeTowerProcessor> - ): ScopeTowerProcessor> { - return if (explicitReceiver is QualifierReceiver) { - (explicitReceiver as? ClassQualifier)?.classValueReceiver?.let(create) - ?: KnownResultProcessor>(listOf()) - } - else { - create(explicitReceiver as ReceiverValue?) - } - } - - private fun createFunctionTowerProcessor( - simpleContext: SimpleContext, - explicitReceiver: Receiver? - ): CompositeScopeTowerProcessor> { - val invokeContext = InvokeContext(simpleContext) - - // a.foo() -- simple function call - val simpleFunction = createFunctionProcessor(simpleContext, explicitReceiver) - - // a.foo() -- property a.foo + foo.invoke() - val invokeProcessor = InvokeTowerProcessor(invokeContext, explicitReceiver) - - // a.foo() -- property foo is extension function with receiver a -- a.invoke() - val invokeExtensionProcessor = createProcessorWithReceiverValueOrEmpty(explicitReceiver) { InvokeExtensionTowerProcessor(invokeContext, it) } - - return CompositeScopeTowerProcessor(simpleFunction, invokeProcessor, invokeExtensionProcessor) - } - - private fun convertToOverloadResults( candidates: Collection>, tracing: TracingStrategy, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTowerProcessors.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTowerProcessors.kt index 5cf3c669fcb..dddbfdd6a27 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTowerProcessors.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTowerProcessors.kt @@ -165,6 +165,39 @@ fun > createVariableAndObjectProcessor( createSimpleProcessor(context, explicitReceiver, classValueReceiver, ScopeTowerLevel::getObjects) ) -fun > createFunctionProcessor( +fun > createSimpleFunctionProcessor( context: TowerContext, explicitReceiver: Receiver?, classValueReceiver: Boolean = true ) = createSimpleProcessor(context, explicitReceiver, classValueReceiver, ScopeTowerLevel::getFunctions) + + +fun , V: Candidate> createFunctionProcessor( + simpleContext: TowerContext, + invokeContext: InvokeTowerContext, + explicitReceiver: Receiver? +): CompositeScopeTowerProcessor { + + // a.foo() -- simple function call + val simpleFunction = createSimpleFunctionProcessor(simpleContext, explicitReceiver) + + // a.foo() -- property a.foo + foo.invoke() + val invokeProcessor = InvokeTowerProcessor(invokeContext, explicitReceiver) + + // a.foo() -- property foo is extension function with receiver a -- a.invoke() + val invokeExtensionProcessor = createProcessorWithReceiverValueOrEmpty(explicitReceiver) { InvokeExtensionTowerProcessor(invokeContext, it) } + + return CompositeScopeTowerProcessor(simpleFunction, invokeProcessor, invokeExtensionProcessor) +} + + +fun > createProcessorWithReceiverValueOrEmpty( + explicitReceiver: Receiver?, + create: (ReceiverValue?) -> ScopeTowerProcessor +): ScopeTowerProcessor { + return if (explicitReceiver is QualifierReceiver) { + explicitReceiver.classValueReceiver?.let(create) + ?: KnownResultProcessor(listOf()) + } + else { + create(explicitReceiver as ReceiverValue?) + } +} \ No newline at end of file