Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
49b60c3a
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,发现更多精彩内容 >>
提交
49b60c3a
编写于
6月 10, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More cases for nullability analysis
上级
9d3abf78
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
345 addition
and
112 deletion
+345
-112
idea/src/org/jetbrains/jet/lang/cfg/BlockInfo.java
idea/src/org/jetbrains/jet/lang/cfg/BlockInfo.java
+6
-0
idea/src/org/jetbrains/jet/lang/cfg/BreakableBlockInfo.java
idea/src/org/jetbrains/jet/lang/cfg/BreakableBlockInfo.java
+30
-0
idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java
...src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java
+1
-1
idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java
.../jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java
+2
-2
idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java
...c/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java
+21
-9
idea/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java
...rg/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java
+15
-0
idea/src/org/jetbrains/jet/lang/cfg/LoopInfo.java
idea/src/org/jetbrains/jet/lang/cfg/LoopInfo.java
+25
-0
idea/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java
...g/cfg/pseudocode/JetControlFlowInstructionsGenerator.java
+11
-33
idea/src/org/jetbrains/jet/lang/cfg/pseudocode/JetPseudocodeTrace.java
...jetbrains/jet/lang/cfg/pseudocode/JetPseudocodeTrace.java
+8
-0
idea/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java
...src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java
+5
-0
idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
...g/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
+40
-6
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
+27
-4
idea/testData/cfg/Finally.instructions
idea/testData/cfg/Finally.instructions
+62
-50
idea/testData/cfg/OnlyWhileInFunctionBody.instructions
idea/testData/cfg/OnlyWhileInFunctionBody.instructions
+11
-7
idea/testData/checker/Nullability.jet
idea/testData/checker/Nullability.jet
+75
-0
idea/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java
idea/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java
+6
-0
未找到文件。
idea/src/org/jetbrains/jet/lang/cfg/BlockInfo.java
0 → 100644
浏览文件 @
49b60c3a
package
org.jetbrains.jet.lang.cfg
;
/**
* @author abreslav
*/
public
abstract
class
BlockInfo
{}
idea/src/org/jetbrains/jet/lang/cfg/BreakableBlockInfo.java
0 → 100644
浏览文件 @
49b60c3a
package
org.jetbrains.jet.lang.cfg
;
import
org.jetbrains.jet.lang.psi.JetElement
;
/**
* @author abreslav
*/
public
class
BreakableBlockInfo
extends
BlockInfo
{
private
final
JetElement
element
;
private
final
Label
entryPoint
;
private
final
Label
exitPoint
;
public
BreakableBlockInfo
(
JetElement
element
,
Label
entryPoint
,
Label
exitPoint
)
{
this
.
element
=
element
;
this
.
entryPoint
=
entryPoint
;
this
.
exitPoint
=
exitPoint
;
}
public
JetElement
getElement
()
{
return
element
;
}
public
Label
getEntryPoint
()
{
return
entryPoint
;
}
public
Label
getExitPoint
()
{
return
exitPoint
;
}
}
idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java
浏览文件 @
49b60c3a
...
...
@@ -31,7 +31,7 @@ public interface JetControlFlowBuilder {
Label
getExitPoint
(
@NotNull
JetElement
labelElement
);
// Loops
L
abel
enterLoop
(
@NotNull
JetExpression
expression
,
Label
loopExit
Point
);
L
oopInfo
enterLoop
(
@NotNull
JetExpression
expression
,
@Nullable
Label
loopExitPoint
,
@Nullable
Label
conditionEntry
Point
);
void
exitLoop
(
@NotNull
JetExpression
expression
);
@Nullable
...
...
idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java
浏览文件 @
49b60c3a
...
...
@@ -73,8 +73,8 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
}
@Override
public
L
abel
enterLoop
(
@NotNull
JetExpression
expression
,
Label
loopExit
Point
)
{
return
builder
.
enterLoop
(
expression
,
loopExitPoint
);
public
L
oopInfo
enterLoop
(
@NotNull
JetExpression
expression
,
Label
loopExitPoint
,
Label
conditionEntry
Point
)
{
return
builder
.
enterLoop
(
expression
,
loopExitPoint
,
conditionEntryPoint
);
}
@Override
...
...
idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java
浏览文件 @
49b60c3a
...
...
@@ -350,35 +350,40 @@ public class JetControlFlowProcessor {
@Override
public
void
visitWhileExpression
(
JetWhileExpression
expression
)
{
Label
loopExitPoint
=
builder
.
createUnboundLabel
();
Label
loopEntryPoint
=
builder
.
enterLoop
(
expression
,
loopExitPoint
);
LoopInfo
loopInfo
=
builder
.
enterLoop
(
expression
,
null
,
null
);
builder
.
bindLabel
(
loopInfo
.
getConditionEntryPoint
());
JetExpression
condition
=
expression
.
getCondition
();
if
(
condition
!=
null
)
{
value
(
condition
,
false
,
true
);
}
builder
.
jumpOnFalse
(
loopExitPoint
);
builder
.
jumpOnFalse
(
loopInfo
.
getExitPoint
());
builder
.
bindLabel
(
loopInfo
.
getBodyEntryPoint
());
JetExpression
body
=
expression
.
getBody
();
if
(
body
!=
null
)
{
value
(
body
,
true
,
false
);
}
builder
.
jump
(
loop
EntryPoint
);
builder
.
jump
(
loop
Info
.
getEntryPoint
()
);
builder
.
exitLoop
(
expression
);
builder
.
readUnit
(
expression
);
}
@Override
public
void
visitDoWhileExpression
(
JetDoWhileExpression
expression
)
{
Label
loopExitPoint
=
builder
.
createUnboundLabel
();
Label
loopEntryPoint
=
builder
.
enterLoop
(
expression
,
loopExitPoint
);
LoopInfo
loopInfo
=
builder
.
enterLoop
(
expression
,
null
,
null
);
builder
.
bindLabel
(
loopInfo
.
getBodyEntryPoint
());
JetExpression
body
=
expression
.
getBody
();
if
(
body
!=
null
)
{
value
(
body
,
true
,
false
);
}
builder
.
bindLabel
(
loopInfo
.
getConditionEntryPoint
());
JetExpression
condition
=
expression
.
getCondition
();
if
(
condition
!=
null
)
{
value
(
condition
,
false
,
true
);
}
builder
.
jumpOnTrue
(
loop
EntryPoint
);
builder
.
jumpOnTrue
(
loop
Info
.
getEntryPoint
()
);
builder
.
exitLoop
(
expression
);
builder
.
readUnit
(
expression
);
}
...
...
@@ -391,13 +396,20 @@ public class JetControlFlowProcessor {
}
// TODO : primitive cases
Label
loopExitPoint
=
builder
.
createUnboundLabel
();
Label
conditionEntryPoint
=
builder
.
createUnboundLabel
();
builder
.
bindLabel
(
conditionEntryPoint
);
builder
.
nondeterministicJump
(
loopExitPoint
);
Label
loopEntryPoint
=
builder
.
enterLoop
(
expression
,
loopExitPoint
);
LoopInfo
loopInfo
=
builder
.
enterLoop
(
expression
,
loopExitPoint
,
conditionEntryPoint
);
builder
.
bindLabel
(
loopInfo
.
getBodyEntryPoint
());
JetExpression
body
=
expression
.
getBody
();
if
(
body
!=
null
)
{
value
(
body
,
true
,
false
);
}
builder
.
nondeterministicJump
(
loopEntryPoint
);
builder
.
nondeterministicJump
(
loopInfo
.
getEntryPoint
());
builder
.
exitLoop
(
expression
);
builder
.
readUnit
(
expression
);
}
...
...
idea/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java
浏览文件 @
49b60c3a
...
...
@@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.cfg;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.psi.JetElement
;
import
org.jetbrains.jet.lang.psi.JetExpression
;
import
org.jetbrains.jet.lang.psi.JetLoopExpression
;
import
java.util.Collection
;
...
...
@@ -25,6 +26,12 @@ public interface JetFlowInformationProvider {
public
void
collectDominatedExpressions
(
@NotNull
JetExpression
dominator
,
@NotNull
Collection
<
JetElement
>
dominated
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
boolean
isBreakable
(
JetLoopExpression
loop
)
{
throw
new
UnsupportedOperationException
();
}
};
JetFlowInformationProvider
NONE
=
new
JetFlowInformationProvider
()
{
...
...
@@ -42,6 +49,12 @@ public interface JetFlowInformationProvider {
public
void
collectDominatedExpressions
(
@NotNull
JetExpression
dominator
,
@NotNull
Collection
<
JetElement
>
dominated
)
{
}
@Override
public
boolean
isBreakable
(
JetLoopExpression
loop
)
{
return
false
;
}
};
void
collectReturnedInformation
(
...
...
@@ -56,4 +69,6 @@ public interface JetFlowInformationProvider {
void
collectDominatedExpressions
(
@NotNull
JetExpression
dominator
,
@NotNull
Collection
<
JetElement
>
dominated
);
boolean
isBreakable
(
JetLoopExpression
loop
);
}
idea/src/org/jetbrains/jet/lang/cfg/LoopInfo.java
0 → 100644
浏览文件 @
49b60c3a
package
org.jetbrains.jet.lang.cfg
;
import
org.jetbrains.jet.lang.psi.JetElement
;
/**
* @author abreslav
*/
public
class
LoopInfo
extends
BreakableBlockInfo
{
private
final
Label
bodyEntryPoint
;
private
final
Label
conditionEntryPoint
;
public
LoopInfo
(
JetElement
element
,
Label
entryPoint
,
Label
exitPoint
,
Label
bodyEntryPoint
,
Label
conditionEntryPoint
)
{
super
(
element
,
entryPoint
,
exitPoint
);
this
.
bodyEntryPoint
=
bodyEntryPoint
;
this
.
conditionEntryPoint
=
conditionEntryPoint
;
}
public
Label
getBodyEntryPoint
()
{
return
bodyEntryPoint
;
}
public
Label
getConditionEntryPoint
()
{
return
conditionEntryPoint
;
}
}
idea/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java
浏览文件 @
49b60c3a
package
org.jetbrains.jet.lang.cfg.pseudocode
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.cfg.GenerationTrigger
;
import
org.jetbrains.jet.lang.cfg.JetControlFlowBuilder
;
import
org.jetbrains.jet.lang.cfg.JetControlFlowBuilderAdapter
;
import
org.jetbrains.jet.lang.cfg.Label
;
import
org.jetbrains.jet.lang.cfg.*
;
import
org.jetbrains.jet.lang.psi.JetElement
;
import
org.jetbrains.jet.lang.psi.JetExpression
;
import
org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
;
...
...
@@ -101,14 +98,20 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
}
@Override
public
final
L
abel
enterLoop
(
@NotNull
JetExpression
expression
,
Label
loopExit
Point
)
{
public
final
L
oopInfo
enterLoop
(
@NotNull
JetExpression
expression
,
Label
loopExitPoint
,
Label
conditionEntry
Point
)
{
Label
label
=
createUnboundLabel
();
bindLabel
(
label
);
BreakableBlockInfo
blockInfo
=
new
BreakableBlockInfo
(
expression
,
label
,
loopExitPoint
);
LoopInfo
blockInfo
=
new
LoopInfo
(
expression
,
label
,
loopExitPoint
!=
null
?
loopExitPoint
:
createUnboundLabel
(),
createUnboundLabel
(),
conditionEntryPoint
!=
null
?
conditionEntryPoint
:
createUnboundLabel
());
loopInfo
.
push
(
blockInfo
);
elementToBlockInfo
.
put
(
expression
,
blockInfo
);
allBlocks
.
push
(
blockInfo
);
return
label
;
trace
.
recordLoopInfo
(
expression
,
blockInfo
);
return
blockInfo
;
}
@Override
...
...
@@ -265,9 +268,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
}
}
private
static
abstract
class
BlockInfo
{}
private
static
class
TryFinallyBlockInfo
extends
BlockInfo
{
public
static
class
TryFinallyBlockInfo
extends
BlockInfo
{
private
final
GenerationTrigger
finallyBlock
;
private
TryFinallyBlockInfo
(
GenerationTrigger
finallyBlock
)
{
...
...
@@ -279,27 +280,4 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
}
}
private
static
class
BreakableBlockInfo
extends
BlockInfo
{
private
final
JetElement
element
;
private
final
Label
entryPoint
;
private
final
Label
exitPoint
;
private
BreakableBlockInfo
(
JetElement
element
,
Label
entryPoint
,
Label
exitPoint
)
{
this
.
element
=
element
;
this
.
entryPoint
=
entryPoint
;
this
.
exitPoint
=
exitPoint
;
}
public
JetElement
getElement
()
{
return
element
;
}
public
Label
getEntryPoint
()
{
return
entryPoint
;
}
public
Label
getExitPoint
()
{
return
exitPoint
;
}
}
}
idea/src/org/jetbrains/jet/lang/cfg/pseudocode/JetPseudocodeTrace.java
浏览文件 @
49b60c3a
package
org.jetbrains.jet.lang.cfg.pseudocode
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.cfg.LoopInfo
;
import
org.jetbrains.jet.lang.psi.JetElement
;
import
org.jetbrains.jet.lang.psi.JetExpression
;
/**
* @author abreslav
...
...
@@ -21,10 +23,16 @@ public interface JetPseudocodeTrace {
@Override
public
void
close
()
{
}
@Override
public
void
recordLoopInfo
(
JetExpression
expression
,
LoopInfo
blockInfo
)
{
}
};
void
recordControlFlowData
(
@NotNull
JetElement
element
,
@NotNull
Pseudocode
pseudocode
);
void
recordRepresentativeInstruction
(
@NotNull
JetElement
element
,
@NotNull
Instruction
instruction
);
void
close
();
void
recordLoopInfo
(
JetExpression
expression
,
LoopInfo
blockInfo
);
}
idea/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java
浏览文件 @
49b60c3a
...
...
@@ -46,6 +46,11 @@ public class Pseudocode {
return
instructions
.
subList
(
getTargetInstructionIndex
(),
instructions
.
size
());
}
public
Instruction
resolveToInstruction
()
{
assert
targetInstructionIndex
!=
null
;
return
instructions
.
get
(
targetInstructionIndex
);
}
}
private
final
List
<
Instruction
>
instructions
=
new
ArrayList
<
Instruction
>();
...
...
idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
浏览文件 @
49b60c3a
...
...
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.resolve;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Sets
;
import
com.intellij.lang.ASTNode
;
import
com.intellij.psi.PsiElement
;
import
org.jetbrains.annotations.NotNull
;
...
...
@@ -9,6 +10,7 @@ import org.jetbrains.annotations.Nullable;
import
org.jetbrains.jet.lang.JetSemanticServices
;
import
org.jetbrains.jet.lang.cfg.JetControlFlowProcessor
;
import
org.jetbrains.jet.lang.cfg.JetFlowInformationProvider
;
import
org.jetbrains.jet.lang.cfg.LoopInfo
;
import
org.jetbrains.jet.lang.cfg.pseudocode.*
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.psi.*
;
...
...
@@ -721,6 +723,7 @@ public class ClassDescriptorResolver {
final
JetPseudocodeTrace
pseudocodeTrace
=
flowDataTraceFactory
.
createTrace
(
declaration
);
final
Map
<
JetElement
,
Pseudocode
>
pseudocodeMap
=
new
HashMap
<
JetElement
,
Pseudocode
>();
final
Map
<
JetElement
,
Instruction
>
representativeInstructions
=
new
HashMap
<
JetElement
,
Instruction
>();
final
Map
<
JetExpression
,
LoopInfo
>
loopInfo
=
Maps
.
newHashMap
();
JetPseudocodeTrace
wrappedTrace
=
new
JetPseudocodeTrace
()
{
@Override
public
void
recordControlFlowData
(
@NotNull
JetElement
element
,
@NotNull
Pseudocode
pseudocode
)
{
...
...
@@ -732,6 +735,13 @@ public class ClassDescriptorResolver {
public
void
recordRepresentativeInstruction
(
@NotNull
JetElement
element
,
@NotNull
Instruction
instruction
)
{
Instruction
oldValue
=
representativeInstructions
.
put
(
element
,
instruction
);
// assert oldValue == null : element.getText();
pseudocodeTrace
.
recordRepresentativeInstruction
(
element
,
instruction
);
}
@Override
public
void
recordLoopInfo
(
JetExpression
expression
,
LoopInfo
blockInfo
)
{
loopInfo
.
put
(
expression
,
blockInfo
);
pseudocodeTrace
.
recordLoopInfo
(
expression
,
blockInfo
);
}
@Override
...
...
@@ -762,7 +772,7 @@ public class ClassDescriptorResolver {
SubroutineEnterInstruction
enterInstruction
=
pseudocode
.
getEnterInstruction
();
Set
<
Instruction
>
visited
=
new
HashSet
<
Instruction
>();
collectReachable
(
enterInstruction
,
visited
);
collectReachable
(
enterInstruction
,
visited
,
null
);
for
(
Instruction
instruction
:
pseudocode
.
getInstructions
())
{
if
(!
visited
.
contains
(
instruction
)
&&
...
...
@@ -783,11 +793,11 @@ public class ClassDescriptorResolver {
SubroutineEnterInstruction
enterInstruction
=
dominatorInstruction
.
getOwner
().
getEnterInstruction
();
Set
<
Instruction
>
reachable
=
new
HashSet
<
Instruction
>();
collectReachable
(
enterInstruction
,
reachable
);
collectReachable
(
enterInstruction
,
reachable
,
null
);
Set
<
Instruction
>
reachableWithDominatorProhibited
=
new
HashSet
<
Instruction
>();
reachableWithDominatorProhibited
.
add
(
dominatorInstruction
);
collectReachable
(
enterInstruction
,
reachableWithDominatorProhibited
);
collectReachable
(
enterInstruction
,
reachableWithDominatorProhibited
,
null
);
for
(
Instruction
instruction
:
reachable
)
{
if
(
instruction
instanceof
JetElementInstruction
...
...
@@ -798,15 +808,39 @@ public class ClassDescriptorResolver {
}
}
}
@Override
public
boolean
isBreakable
(
JetLoopExpression
loop
)
{
LoopInfo
info
=
loopInfo
.
get
(
loop
);
Pseudocode
.
PseudocodeLabel
bodyEntryPoint
=
(
Pseudocode
.
PseudocodeLabel
)
info
.
getBodyEntryPoint
();
Pseudocode
.
PseudocodeLabel
exitPoint
=
(
Pseudocode
.
PseudocodeLabel
)
info
.
getExitPoint
();
HashSet
<
Instruction
>
visited
=
Sets
.
newHashSet
();
Pseudocode
.
PseudocodeLabel
conditionEntryPoint
=
(
Pseudocode
.
PseudocodeLabel
)
info
.
getConditionEntryPoint
();
visited
.
add
(
conditionEntryPoint
.
resolveToInstruction
());
return
collectReachable
(
bodyEntryPoint
.
resolveToInstruction
(),
visited
,
exitPoint
.
resolveToInstruction
());
}
public
boolean
isReachable
(
JetExpression
from
,
JetExpression
to
)
{
Instruction
fromInstr
=
representativeInstructions
.
get
(
from
);
assert
fromInstr
!=
null
:
"No representative instruction for "
+
from
.
getText
();
Instruction
toInstr
=
representativeInstructions
.
get
(
to
);
assert
toInstr
!=
null
:
"No representative instruction for "
+
to
.
getText
();
return
collectReachable
(
fromInstr
,
Sets
.<
Instruction
>
newHashSet
(),
toInstr
);
}
};
}
private
void
collectReachable
(
Instruction
current
,
Set
<
Instruction
>
visited
)
{
if
(!
visited
.
add
(
current
))
return
;
private
boolean
collectReachable
(
Instruction
current
,
Set
<
Instruction
>
visited
,
@Nullable
Instruction
lookFor
)
{
if
(!
visited
.
add
(
current
))
return
false
;
if
(
current
==
lookFor
)
return
true
;
for
(
Instruction
nextInstruction
:
current
.
getNextInstructions
())
{
collectReachable
(
nextInstruction
,
visited
);
if
(
collectReachable
(
nextInstruction
,
visited
,
lookFor
))
{
return
true
;
}
}
return
false
;
}
private
void
processPreviousInstructions
(
Instruction
previousFor
,
final
Set
<
Instruction
>
visited
,
final
Collection
<
JetExpression
>
returnedExpressions
,
final
Collection
<
JetElement
>
elementsReturningUnit
)
{
...
...
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
浏览文件 @
49b60c3a
...
...
@@ -1307,12 +1307,16 @@ public class JetTypeInferrer {
}
}
else
if
(
thenBranch
==
null
)
{
getType
(
scope
,
elseBranch
,
true
,
elseInfo
);
JetType
type
=
getType
(
scope
,
elseBranch
,
true
,
elseInfo
);
if
(
type
!=
null
&&
JetStandardClasses
.
isNothing
(
type
))
{
resultDataFlowInfo
=
thenInfo
;
}
result
=
JetStandardClasses
.
getUnitType
();
}
else
{
JetType
thenType
=
getType
(
scope
,
thenBranch
,
true
,
thenInfo
);
JetType
elseType
=
getType
(
scope
,
elseBranch
,
true
,
elseInfo
);
if
(
thenType
==
null
)
{
result
=
elseType
;
}
...
...
@@ -1322,10 +1326,22 @@ public class JetTypeInferrer {
else
{
result
=
semanticServices
.
getTypeChecker
().
commonSupertype
(
Arrays
.
asList
(
thenType
,
elseType
));
}
boolean
jumpInThen
=
thenType
!=
null
&&
JetStandardClasses
.
isNothing
(
thenType
);
boolean
jumpInElse
=
elseType
!=
null
&&
JetStandardClasses
.
isNothing
(
elseType
);
if
(
jumpInThen
&&
!
jumpInElse
)
{
resultDataFlowInfo
=
elseInfo
;
}
else
if
(
jumpInElse
&&
!
jumpInThen
)
{
resultDataFlowInfo
=
thenInfo
;
}
}
}
private
DataFlowInfo
extractDataFlowInfoFromCondition
(
@NotNull
JetExpression
condition
,
final
boolean
conditionValue
)
{
private
DataFlowInfo
extractDataFlowInfoFromCondition
(
@Nullable
JetExpression
condition
,
final
boolean
conditionValue
)
{
if
(
condition
==
null
)
return
dataFlowInfo
;
final
DataFlowInfo
[]
result
=
new
DataFlowInfo
[]
{
dataFlowInfo
};
condition
.
accept
(
new
JetVisitor
()
{
@Override
...
...
@@ -1410,7 +1426,9 @@ public class JetTypeInferrer {
DataFlowInfo
conditionInfo
=
condition
==
null
?
dataFlowInfo
:
extractDataFlowInfoFromCondition
(
condition
,
true
);
getType
(
scope
,
body
,
true
,
conditionInfo
);
}
resultDataFlowInfo
=
condition
==
null
?
null
:
extractDataFlowInfoFromCondition
(
condition
,
false
);
if
(!
flowInformationProvider
.
isBreakable
(
expression
))
{
resultDataFlowInfo
=
extractDataFlowInfoFromCondition
(
condition
,
false
);
}
result
=
JetStandardClasses
.
getUnitType
();
}
...
...
@@ -1434,7 +1452,11 @@ public class JetTypeInferrer {
conditionScope
=
writableScope
;
getBlockReturnedTypeWithWritableScope
(
writableScope
,
Collections
.
singletonList
(
body
),
dataFlowInfo
);
}
checkCondition
(
conditionScope
,
expression
.
getCondition
());
JetExpression
condition
=
expression
.
getCondition
();
checkCondition
(
conditionScope
,
condition
);
if
(!
flowInformationProvider
.
isBreakable
(
expression
))
{
resultDataFlowInfo
=
extractDataFlowInfoFromCondition
(
condition
,
false
);
}
result
=
JetStandardClasses
.
getUnitType
();
}
...
...
@@ -1918,6 +1940,7 @@ public class JetTypeInferrer {
if
(
receiverType
!=
null
)
{
FunctionDescriptor
functionDescriptor
=
lookupFunction
(
scope
,
expression
,
"get"
,
receiverType
,
argumentTypes
,
true
);
if
(
functionDescriptor
!=
null
)
{
// checkNullSafety(receiverType, expression.getIndexExpressions().get(0).getNode(), functionDescriptor);
result
=
functionDescriptor
.
getUnsubstitutedReturnType
();
}
}
...
...
idea/testData/cfg/Finally.instructions
浏览文件 @
49b60c3a
...
...
@@ -224,26 +224,28 @@ fun t3() {
---------------------
l0:
<START>
l3:
l2:
l5:
r(true)
jf(l2)
jmp?(l4)
jf(l3)
l4:
jmp?(l6)
r(1)
r(2)
r(3)
r(>)
r(2 > 3)
jf(l
5
)
jf(l
7
)
r(2)
jmp(l
2
)
jmp(l
6
)
l
5
:
jmp(l
3
)
jmp(l
8
)
l
7
:
read (Unit)
l4:
l6:
l8:
r(2)
jmp(l
3
)
l
2
:
jmp(l
2
)
l
3
:
read (Unit)
l1:
<END>
...
...
@@ -268,22 +270,24 @@ fun t3() {
l0:
<START>
jmp?(l2)
l4:
l3:
l6:
r(true)
jf(l3)
jf(l4)
l5:
r(1)
r(2)
r(3)
r(>)
r(2 > 3)
jf(l5)
jmp(l3)
jmp(l6)
l5:
read (Unit)
l6:
jf(l7)
jmp(l4)
l3:
jmp(l8)
l7:
read (Unit)
l8:
jmp(l3)
l4:
read (Unit)
r(5)
l2:
...
...
@@ -310,22 +314,24 @@ fun t3() {
l0:
<START>
jmp?(l2)
l4:
l3:
l6:
r(true)
jf(l3)
jf(l4)
l5:
r(1)
r(2)
r(3)
r(>)
r(2 > 3)
jf(l5)
jmp(l3)
jmp(l6)
l5:
read (Unit)
l6:
jf(l7)
jmp(l4)
l3:
jmp(l8)
l7:
read (Unit)
l8:
jmp(l3)
l4:
read (Unit)
l2:
r(2)
...
...
@@ -354,24 +360,26 @@ l0:
r(a)
r(..)
r(1..a)
jmp?(l2)
l3:
jmp?(l4)
jmp?(l2)
l4:
l5:
jmp?(l6)
r(1)
r(2)
r(3)
r(>)
r(2 > 3)
jf(l
5
)
jf(l
7
)
r(2)
jmp(l
3
)
jmp(l
6
)
l
5
:
jmp(l
4
)
jmp(l
8
)
l
7
:
read (Unit)
l4:
l6:
l8:
r(2)
jmp?(l
3
)
jmp?(l
4
)
l2:
read (Unit)
l1:
...
...
@@ -401,20 +409,22 @@ l0:
r(a)
r(..)
r(1..a)
jmp?(l3)
l4:
jmp?(l3)
l5:
l6:
r(1)
r(2)
r(3)
r(>)
r(2 > 3)
jf(l
5
)
jmp(l
4
)
jmp(l
6
)
l
5
:
jf(l
7
)
jmp(l
5
)
jmp(l
8
)
l
7
:
read (Unit)
l
6
:
jmp?(l
4
)
l
8
:
jmp?(l
5
)
l3:
read (Unit)
r(5)
...
...
@@ -446,20 +456,22 @@ l0:
r(a)
r(..)
r(1..a)
jmp?(l3)
l4:
jmp?(l3)
l5:
l6:
r(1)
r(2)
r(3)
r(>)
r(2 > 3)
jf(l
5
)
jmp(l
4
)
jmp(l
6
)
l
5
:
jf(l
7
)
jmp(l
5
)
jmp(l
8
)
l
7
:
read (Unit)
l
6
:
jmp?(l
4
)
l
8
:
jmp?(l
5
)
l3:
read (Unit)
l2:
...
...
idea/testData/cfg/OnlyWhileInFunctionBody.instructions
浏览文件 @
49b60c3a
...
...
@@ -7,15 +7,17 @@ fun main() {
---------------------
l0:
<START>
l3:
l2:
l5:
r(1)
r(0)
r(>)
r(1 > 0)
jf(l2)
jf(l3)
l4:
r(2)
jmp(l
3
)
l
2
:
jmp(l
2
)
l
3
:
read (Unit)
l1:
<END>
...
...
@@ -30,14 +32,16 @@ fun dowhile() {
---------------------
l0:
<START>
l3:
l2:
l4:
ret l1
l5:
r(1)
r(0)
r(>)
r(1 > 0)
jt(l
3
)
l
2
:
jt(l
2
)
l
3
:
read (Unit)
l1:
<END>
...
...
idea/testData/checker/Nullability.jet
浏览文件 @
49b60c3a
...
...
@@ -139,3 +139,78 @@ fun test() {
out.println()
}
fun f(out : String?) {
out?.get(0)
if (out != null) else return;
out.get(0)
}
fun f1(out : String?) {
out?.get(0)
if (out != null) else {
1 + 2
return;
}
out.get(0)
}
fun f2(out : String?) {
out?.get(0)
if (out == null) {
1 + 2
return;
}
out.get(0)
}
fun f3(out : String?) {
out?.get(0)
if (out == null) {
1 + 2
return;
}
else {
1 + 2
}
out.get(0)
}
fun f4(s : String?) {
s?.get(0)
while (1 < 2 && s != null) {
s.get(0)
}
s?.get(0)
while (s == null || 1 < 2) {
s?.get(0)
}
s.get(0)
}
fun f5(s : String?) {
s?.get(0)
while (1 < 2 && s != null) {
s.get(0)
}
s?.get(0)
while (s == null || 1 < 2) {
if (1 > 2) break
s?.get(0)
}
s?.get(0);
}
fun f6(s : String?) {
s?.get(0)
do {
s?.get(0)
if (1 < 2) break;
} while (s == null)
s?.get(0)
do {
s?.get(0)
} while (s == null)
s.get(0)
}
idea/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java
浏览文件 @
49b60c3a
...
...
@@ -8,11 +8,13 @@ import junit.framework.Test;
import
junit.framework.TestSuite
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.JetTestCaseBase
;
import
org.jetbrains.jet.lang.cfg.LoopInfo
;
import
org.jetbrains.jet.lang.cfg.pseudocode.Instruction
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetPseudocodeTrace
;
import
org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode
;
import
org.jetbrains.jet.lang.psi.JetElement
;
import
org.jetbrains.jet.lang.psi.JetExpression
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetNamedDeclaration
;
import
org.jetbrains.jet.lang.resolve.AnalyzingUtils
;
...
...
@@ -55,6 +57,10 @@ public class JetControlFlowTest extends JetTestCaseBase {
}
}
@Override
public
void
recordLoopInfo
(
JetExpression
expression
,
LoopInfo
blockInfo
)
{
}
@Override
public
void
recordRepresentativeInstruction
(
@NotNull
JetElement
element
,
@NotNull
Instruction
instruction
)
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录