Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
64353f34
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
64353f34
编写于
3月 04, 2021
作者:
M
Mikhail Glukhikh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIR: extract BodyResolveContext.withProperty
上级
06b3a0d5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
107 addition
and
66 deletion
+107
-66
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt
...r/resolve/transformers/body/resolve/BodyResolveContext.kt
+61
-0
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt
...formers/body/resolve/FirDeclarationsResolveTransformer.kt
+46
-66
未找到文件。
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt
浏览文件 @
64353f34
...
...
@@ -12,11 +12,15 @@ import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import
org.jetbrains.kotlin.fir.PrivateForInline
import
org.jetbrains.kotlin.fir.declarations.*
import
org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import
org.jetbrains.kotlin.fir.expressions.FirExpression
import
org.jetbrains.kotlin.fir.resolve.*
import
org.jetbrains.kotlin.fir.resolve.calls.ImplicitExtensionReceiverValue
import
org.jetbrains.kotlin.fir.resolve.calls.ImplicitReceiverValue
import
org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext
import
org.jetbrains.kotlin.fir.resolve.dfa.DataFlowAnalyzerContext
import
org.jetbrains.kotlin.fir.resolve.dfa.PersistentFlow
import
org.jetbrains.kotlin.fir.resolve.inference.FirCallCompleter
import
org.jetbrains.kotlin.fir.resolve.inference.FirDelegatedPropertyInferenceSession
import
org.jetbrains.kotlin.fir.resolve.inference.FirInferenceSession
import
org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
import
org.jetbrains.kotlin.fir.resolve.transformers.withScopeCleanup
...
...
@@ -28,6 +32,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousFunctionSymbol
import
org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
import
org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import
org.jetbrains.kotlin.fir.types.ConeKotlinType
import
org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
import
org.jetbrains.kotlin.fir.types.coneType
import
org.jetbrains.kotlin.name.Name
...
...
@@ -383,6 +388,62 @@ class BodyResolveContext(
}
}
inline
fun
<
T
>
withProperty
(
property
:
FirProperty
,
crossinline
f
:
()
->
T
):
T
{
return
withTypeParametersOf
(
property
)
{
withContainer
(
property
,
f
)
}
}
inline
fun
<
T
>
withPropertyAccessor
(
property
:
FirProperty
,
holder
:
SessionHolder
,
crossinline
f
:
()
->
T
):
T
{
return
withTowerDataCleanup
{
val
receiverTypeRef
=
property
.
receiverTypeRef
if
(
receiverTypeRef
==
null
&&
property
.
returnTypeRef
!
is
FirImplicitTypeRef
&&
!
property
.
isLocal
&&
property
.
delegate
==
null
)
{
addLocalScope
(
FirLocalScope
())
storeBackingField
(
property
)
}
if
(
receiverTypeRef
!=
null
)
{
withLabelAndReceiverType
(
property
.
name
,
property
,
receiverTypeRef
.
coneType
,
holder
,
f
)
}
else
{
f
()
}
}
}
inline
fun
<
T
>
forPropertyInitializer
(
crossinline
f
:
()
->
T
):
T
{
return
withTowerDataCleanup
{
getPrimaryConstructorPureParametersScope
()
?.
let
{
addLocalScope
(
it
)
}
f
()
}
}
inline
fun
<
T
>
forPropertyDelegateAccessors
(
property
:
FirProperty
,
delegateExpression
:
FirExpression
,
resolutionContext
:
ResolutionContext
,
callCompleter
:
FirCallCompleter
,
crossinline
f
:
FirDelegatedPropertyInferenceSession
.()
->
T
)
{
val
inferenceSession
=
FirDelegatedPropertyInferenceSession
(
property
,
delegateExpression
,
resolutionContext
,
callCompleter
.
createPostponedArgumentsAnalyzer
(
resolutionContext
)
)
withInferenceSession
(
inferenceSession
)
{
inferenceSession
.
f
()
}
}
inline
fun
<
T
>
withLabelAndReceiverType
(
labelName
:
Name
?,
owner
:
FirCallableDeclaration
<
*
>,
...
...
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt
浏览文件 @
64353f34
...
...
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
import
org.jetbrains.kotlin.fir.resolve.calls.ImplicitExtensionReceiverValue
import
org.jetbrains.kotlin.fir.resolve.calls.InaccessibleImplicitReceiverValue
import
org.jetbrains.kotlin.fir.resolve.dfa.FirControlFlowGraphReferenceImpl
import
org.jetbrains.kotlin.fir.resolve.inference.FirDelegatedPropertyInferenceSession
import
org.jetbrains.kotlin.fir.resolve.inference.extractLambdaInfoFromFunctionalType
import
org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType
import
org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
...
...
@@ -136,40 +135,39 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
return
transformLocalVariable
(
property
)
}
return
withTypeParametersOf
(
property
)
{
val
returnTypeRef
=
property
.
returnTypeRef
if
(
returnTypeRef
!
is
FirImplicitTypeRef
&&
implicitTypeOnly
)
return
@withTypeParametersOf
property
.
compose
()
if
(
property
.
resolvePhase
==
FirResolvePhase
.
BODY_RESOLVE
||
property
.
resolvePhase
==
transformerPhase
)
{
return
@withTypeParametersOf
property
.
compose
()
}
dataFlowAnalyzer
.
enterProperty
(
property
)
withFullBodyResolve
{
context
.
withContainer
(
property
)
{
withPrimaryConstructorParameters
(
includeProperties
=
false
)
{
if
(
property
.
delegate
!=
null
)
{
transformPropertyWithDelegate
(
property
)
}
else
{
property
.
transformChildrenWithoutAccessors
(
returnTypeRef
)
if
(
property
.
initializer
!=
null
)
{
storeVariableReturnType
(
property
)
}
}
}
if
(
property
.
delegate
==
null
)
{
withNewLocalScope
{
if
(
property
.
receiverTypeRef
==
null
&&
property
.
returnTypeRef
!
is
FirImplicitTypeRef
)
{
context
.
storeBackingField
(
property
)
}
property
.
transformAccessors
()
}
val
returnTypeRef
=
property
.
returnTypeRef
if
(
returnTypeRef
!
is
FirImplicitTypeRef
&&
implicitTypeOnly
)
return
property
.
compose
()
if
(
property
.
resolvePhase
==
transformerPhase
)
return
property
.
compose
()
if
(
property
.
resolvePhase
==
FirResolvePhase
.
BODY_RESOLVE
||
property
.
resolvePhase
==
transformerPhase
)
{
return
@withTypeParametersOf
property
.
compose
()
}
dataFlowAnalyzer
.
enterProperty
(
property
)
doTransformTypeParameters
(
property
)
return
withFullBodyResolve
{
context
.
withProperty
(
property
)
{
context
.
forPropertyInitializer
{
property
.
transformDelegate
(
transformer
,
ResolutionMode
.
ContextDependentDelegate
)
property
.
transformChildrenWithoutAccessors
(
returnTypeRef
)
if
(
property
.
initializer
!=
null
)
{
storeVariableReturnType
(
property
)
}
}
transformer
.
replaceDeclarationResolvePhaseIfNeeded
(
property
,
transformerPhase
)
dataFlowAnalyzer
.
exitProperty
(
property
)
?.
let
{
property
.
replaceControlFlowGraphReference
(
FirControlFlowGraphReferenceImpl
(
it
))
val
delegate
=
property
.
delegate
if
(
delegate
!=
null
)
{
transformPropertyAccessorsWithDelegate
(
property
,
delegate
)
if
(
property
.
delegateFieldSymbol
!=
null
)
{
replacePropertyReferenceTypeInDelegateAccessors
(
property
)
}
}
else
{
property
.
transformAccessors
()
}
property
.
compose
()
}
transformer
.
replaceDeclarationResolvePhaseIfNeeded
(
property
,
transformerPhase
)
dataFlowAnalyzer
.
exitProperty
(
property
)
?.
let
{
property
.
replaceControlFlowGraphReference
(
FirControlFlowGraphReferenceImpl
(
it
))
}
property
.
compose
()
}
}
...
...
@@ -236,23 +234,12 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
(
property
.
delegate
as
?
FirFunctionCall
)
?.
replacePropertyReferenceTypeInDelegateAccessors
(
property
)
}
private
fun
transformPropertyWithDelegate
(
property
:
FirProperty
)
{
property
.
transformDelegate
(
transformer
,
ResolutionMode
.
ContextDependentDelegate
)
val
delegateExpression
=
property
.
delegate
!!
val
inferenceSession
=
FirDelegatedPropertyInferenceSession
(
property
,
delegateExpression
,
resolutionContext
,
callCompleter
.
createPostponedArgumentsAnalyzer
(
resolutionContext
)
)
context
.
withInferenceSession
(
inferenceSession
)
{
private
fun
transformPropertyAccessorsWithDelegate
(
property
:
FirProperty
,
delegateExpression
:
FirExpression
)
{
context
.
forPropertyDelegateAccessors
(
property
,
delegateExpression
,
resolutionContext
,
callCompleter
)
{
property
.
transformAccessors
()
val
completedCalls
=
inferenceSession
.
completeCandidates
()
val
finalSubstitutor
=
inferenceSession
.
createFinalSubstitutor
()
val
callCompletionResultsWriter
=
c
omponents
.
c
allCompleter
.
createCompletionResultsWriter
(
val
completedCalls
=
completeCandidates
()
val
finalSubstitutor
=
createFinalSubstitutor
()
val
callCompletionResultsWriter
=
callCompleter
.
createCompletionResultsWriter
(
finalSubstitutor
,
mode
=
FirCallCompletionResultsWriterTransformer
.
Mode
.
DelegatedPropertyCompletion
)
...
...
@@ -262,11 +249,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
val
declarationCompletionResultsWriter
=
FirDeclarationCompletionResultsWriter
(
finalSubstitutor
)
property
.
transformSingle
(
declarationCompletionResultsWriter
,
null
)
}
if
(
property
.
delegateFieldSymbol
!=
null
)
{
replacePropertyReferenceTypeInDelegateAccessors
(
property
)
}
property
.
transformTypeParameters
(
transformer
,
ResolutionMode
.
ContextIndependent
)
.
transformOtherChildren
(
transformer
,
ResolutionMode
.
ContextIndependent
)
}
override
fun
transformWrappedDelegateExpression
(
...
...
@@ -298,19 +280,22 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
private
fun
transformLocalVariable
(
variable
:
FirProperty
):
CompositeTransformResult
<
FirProperty
>
{
assert
(
variable
.
isLocal
)
if
(
variable
.
delegate
!=
null
)
{
transformPropertyWithDelegate
(
variable
)
variable
.
transformDelegate
(
transformer
,
ResolutionMode
.
ContextDependentDelegate
)
val
delegate
=
variable
.
delegate
if
(
delegate
!=
null
)
{
transformPropertyAccessorsWithDelegate
(
variable
,
delegate
)
if
(
variable
.
delegateFieldSymbol
!=
null
)
{
replacePropertyReferenceTypeInDelegateAccessors
(
variable
)
}
}
else
{
val
resolutionMode
=
withExpectedType
(
variable
.
returnTypeRef
)
variable
.
transformInitializer
(
transformer
,
resolutionMode
)
.
transformDelegate
(
transformer
,
resolutionMode
)
.
transformTypeParameters
(
transformer
,
resolutionMode
)
.
transformOtherChildren
(
transformer
,
resolutionMode
)
if
(
variable
.
initializer
!=
null
)
{
variable
.
transformInitializer
(
transformer
,
resolutionMode
)
storeVariableReturnType
(
variable
)
}
variable
.
transformAccessors
()
}
variable
.
transformOtherChildren
(
transformer
,
ResolutionMode
.
ContextIndependent
)
context
.
storeVariable
(
variable
)
transformer
.
replaceDeclarationResolvePhaseIfNeeded
(
variable
,
transformerPhase
)
dataFlowAnalyzer
.
exitLocalVariableDeclaration
(
variable
)
...
...
@@ -326,7 +311,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
.
transformOtherChildren
(
transformer
,
data
)
}
private
fun
<
F
:
FirVariable
<
F
>>
FirVariable
<
F
>
.
transformAccessors
()
{
private
fun
FirProperty
.
transformAccessors
()
{
var
enhancedTypeRef
=
returnTypeRef
getter
?.
let
{
transformAccessor
(
it
,
enhancedTypeRef
,
this
)
...
...
@@ -346,7 +331,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
private
fun
transformAccessor
(
accessor
:
FirPropertyAccessor
,
enhancedTypeRef
:
FirTypeRef
,
owner
:
Fir
Variable
<
*
>
owner
:
Fir
Property
)
{
if
(
accessor
is
FirDefaultPropertyAccessor
||
accessor
.
body
==
null
)
{
transformFunction
(
accessor
,
withExpectedType
(
enhancedTypeRef
))
...
...
@@ -364,12 +349,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
withExpectedType
(
expectedReturnTypeRef
)
}
val
receiverTypeRef
=
owner
.
receiverTypeRef
if
(
receiverTypeRef
!=
null
)
{
withLabelAndReceiverType
(
owner
.
name
,
owner
,
receiverTypeRef
.
coneType
)
{
transformFunctionWithGivenSignature
(
accessor
,
resolutionMode
)
}
}
else
{
context
.
withPropertyAccessor
(
owner
,
components
)
{
transformFunctionWithGivenSignature
(
accessor
,
resolutionMode
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录