Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
22b6f286
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,发现更多精彩内容 >>
提交
22b6f286
编写于
9月 04, 2011
作者:
A
Alex Tkachman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix for KT-152
上级
58765f23
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
1 deletion
+45
-1
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+30
-0
idea/src/org/jetbrains/jet/codegen/JetTypeMapper.java
idea/src/org/jetbrains/jet/codegen/JetTypeMapper.java
+4
-0
idea/src/org/jetbrains/jet/codegen/StackValue.java
idea/src/org/jetbrains/jet/codegen/StackValue.java
+1
-1
idea/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java
...ests/org/jetbrains/jet/codegen/ControlStructuresTest.java
+10
-0
未找到文件。
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
22b6f286
...
...
@@ -1202,6 +1202,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
private
StackValue
generateEquals
(
JetExpression
left
,
JetExpression
right
,
IElementType
opToken
)
{
Type
leftType
=
expressionType
(
left
);
Type
rightType
=
expressionType
(
right
);
if
(
leftType
==
JetTypeMapper
.
TYPE_NOTHING
)
{
return
genCmpWithNull
(
right
,
rightType
,
opToken
);
}
if
(
rightType
==
JetTypeMapper
.
TYPE_NOTHING
)
{
return
genCmpWithNull
(
left
,
leftType
,
opToken
);
}
if
(
JetTypeMapper
.
isPrimitive
(
leftType
)
!=
JetTypeMapper
.
isPrimitive
(
rightType
))
{
gen
(
left
,
leftType
);
v
.
valueOf
(
leftType
);
...
...
@@ -1217,6 +1225,28 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
return
generateEqualsForExpressionsOnStack
(
opToken
,
leftType
,
rightType
);
}
private
StackValue
genCmpWithNull
(
JetExpression
exp
,
Type
expType
,
IElementType
opToken
)
{
gen
(
exp
,
typeMapper
.
boxType
(
expType
));
Label
fail
=
new
Label
(),
end
=
new
Label
();
if
(
JetTokens
.
EQEQ
==
opToken
||
JetTokens
.
EQEQEQ
==
opToken
)
{
v
.
ifnonnull
(
fail
);
v
.
iconst
(
1
);
v
.
goTo
(
end
);
v
.
mark
(
fail
);
v
.
iconst
(
0
);
v
.
mark
(
end
);
}
else
{
v
.
ifnull
(
fail
);
v
.
iconst
(
1
);
v
.
goTo
(
end
);
v
.
mark
(
fail
);
v
.
iconst
(
0
);
v
.
mark
(
end
);
}
return
StackValue
.
onStack
(
Type
.
BOOLEAN_TYPE
);
}
private
StackValue
generateEqualsForExpressionsOnStack
(
IElementType
opToken
,
Type
leftType
,
Type
rightType
)
{
if
(
isNumberPrimitive
(
leftType
)
&&
leftType
==
rightType
)
{
return
compareExpressionsOnStack
(
opToken
,
leftType
);
...
...
idea/src/org/jetbrains/jet/codegen/JetTypeMapper.java
浏览文件 @
22b6f286
...
...
@@ -25,6 +25,7 @@ public class JetTypeMapper {
public
static
final
Type
TYPE_TYPEINFO
=
Type
.
getType
(
TypeInfo
.
class
);
public
static
final
Type
TYPE_JET_OBJECT
=
Type
.
getType
(
JetObject
.
class
);
public
static
final
Type
TYPE_CLASS
=
Type
.
getType
(
Class
.
class
);
public
static
final
Type
TYPE_NOTHING
=
Type
.
getObjectType
(
"jet/Nothing"
);
private
final
JetStandardLibrary
standardLibrary
;
private
final
BindingContext
bindingContext
;
...
...
@@ -289,6 +290,9 @@ public class JetTypeMapper {
}
public
Type
mapType
(
@NotNull
final
JetType
jetType
,
OwnerKind
kind
)
{
if
(
jetType
.
equals
(
JetStandardClasses
.
getNothingType
())
||
jetType
.
equals
(
JetStandardClasses
.
getNullableNothingType
()))
{
return
TYPE_NOTHING
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getIntType
()))
{
return
Type
.
INT_TYPE
;
}
...
...
idea/src/org/jetbrains/jet/codegen/StackValue.java
浏览文件 @
22b6f286
...
...
@@ -282,7 +282,7 @@ public abstract class StackValue {
@Override
public
void
condJump
(
Label
label
,
boolean
jumpIfFalse
,
InstructionAdapter
v
)
{
if
(
value
instanceof
Boolean
)
{
boolean
boolValue
=
(
(
Boolean
)
value
).
booleanValue
()
;
boolean
boolValue
=
(
Boolean
)
value
;
if
(
boolValue
^
jumpIfFalse
)
{
v
.
goTo
(
label
);
}
...
...
idea/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java
浏览文件 @
22b6f286
...
...
@@ -148,4 +148,14 @@ public class ControlStructuresTest extends CodegenTestCase {
public
void
testKt237
()
throws
Exception
{
blackBoxFile
(
"regressions/kt237.jet"
);
}
public
void
testCompareToNull
()
throws
Exception
{
loadText
(
"fun foo(a: String?, b: String?): Boolean = a == null && b !== null"
);
String
text
=
generateToText
();
assertTrue
(!
text
.
contains
(
"java/lang/Object.equals"
));
System
.
out
.
println
(
text
);
final
Method
main
=
generateFunction
();
assertEquals
(
true
,
main
.
invoke
(
null
,
null
,
"lala"
));
assertEquals
(
false
,
main
.
invoke
(
null
,
null
,
null
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录