Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
232fc89c
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,发现更多精彩内容 >>
提交
232fc89c
编写于
9月 05, 2011
作者:
A
Alex Tkachman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix for KT-80
上级
ab63974f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
10 deletion
+78
-10
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+51
-6
idea/src/org/jetbrains/jet/codegen/StackValue.java
idea/src/org/jetbrains/jet/codegen/StackValue.java
+13
-1
idea/testData/codegen/patternMatching/range.jet
idea/testData/codegen/patternMatching/range.jet
+10
-3
idea/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
.../tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
+4
-0
未找到文件。
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
232fc89c
...
...
@@ -809,7 +809,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
v
.
visitMethodInsn
(
isStatic
?
Opcodes
.
INVOKESTATIC
:
isInterface
?
Opcodes
.
INVOKEINTERFACE
:
Opcodes
.
INVOKEVIRTUAL
,
owner
,
functionDescriptor
.
getName
(),
typeMapper
.
mapSignature
(
functionDescriptor
.
getName
(),
functionDescriptor
).
getDescriptor
());
StackValue
.
onStack
(
typeMapper
.
mapType
(
functionDescriptor
.
getReturnType
())).
coerce
(
type
,
v
);
}
public
StackValue
intermediateValueForProperty
(
PropertyDescriptor
propertyDescriptor
,
final
boolean
forceField
,
boolean
forceInterface
)
{
DeclarationDescriptor
containingDeclaration
=
propertyDescriptor
.
getContainingDeclaration
();
boolean
isStatic
=
containingDeclaration
instanceof
NamespaceDescriptorImpl
;
...
...
@@ -1990,11 +1990,42 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
@Nullable
Label
nextEntry
)
{
StackValue
conditionValue
;
if
(
condition
instanceof
JetWhenConditionInRange
)
{
JetExpression
range
=
((
JetWhenConditionInRange
)
condition
).
getRangeExpression
();
gen
(
range
,
RANGE_TYPE
);
new
StackValue
.
Local
(
subjectLocal
,
subjectType
).
put
(
INTEGER_TYPE
,
v
);
v
.
invokeinterface
(
CLASS_RANGE
,
"contains"
,
"(Ljava/lang/Comparable;)Z"
);
conditionValue
=
new
StackValue
.
OnStack
(
Type
.
BOOLEAN_TYPE
);
JetWhenConditionInRange
conditionInRange
=
(
JetWhenConditionInRange
)
condition
;
JetExpression
rangeExpression
=
conditionInRange
.
getRangeExpression
();
if
(
isIntRangeExpr
(
rangeExpression
))
{
v
.
iconst
(
1
);
//noinspection ConstantConditions
new
StackValue
.
Local
(
subjectLocal
,
subjectType
).
put
(
Type
.
INT_TYPE
,
v
);
JetBinaryExpression
binaryExpression
=
(
JetBinaryExpression
)
rangeExpression
;
gen
(
binaryExpression
.
getLeft
(),
Type
.
INT_TYPE
);
Label
lok
=
new
Label
();
v
.
ificmpge
(
lok
);
v
.
pop
();
v
.
iconst
(
0
);
v
.
mark
(
lok
);
v
.
iconst
(
1
);
new
StackValue
.
Local
(
subjectLocal
,
subjectType
).
put
(
Type
.
INT_TYPE
,
v
);
gen
(
binaryExpression
.
getRight
(),
Type
.
INT_TYPE
);
Label
rok
=
new
Label
();
v
.
ificmple
(
rok
);
v
.
pop
();
v
.
iconst
(
0
);
v
.
mark
(
rok
);
v
.
and
(
Type
.
INT_TYPE
);
if
(
conditionInRange
.
getOperationReference
().
getReferencedNameElementType
()
==
JetTokens
.
NOT_IN
)
{
v
.
iconst
(
1
);
v
.
xor
(
Type
.
INT_TYPE
);
}
}
else
{
FunctionDescriptor
op
=
(
FunctionDescriptor
)
bindingContext
.
get
(
BindingContext
.
REFERENCE_TARGET
,
conditionInRange
.
getOperationReference
());
genToJVMStack
(
rangeExpression
);
new
StackValue
.
Local
(
subjectLocal
,
subjectType
).
put
(
JetTypeMapper
.
TYPE_OBJECT
,
v
);
invokeFunctionNoParams
(
op
,
Type
.
BOOLEAN_TYPE
,
v
);
}
return
StackValue
.
onStack
(
Type
.
BOOLEAN_TYPE
);
}
else
if
(
condition
instanceof
JetWhenConditionIsPattern
)
{
JetWhenConditionIsPattern
patternCondition
=
(
JetWhenConditionIsPattern
)
condition
;
...
...
@@ -2032,6 +2063,20 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
return
conditionValue
;
}
private
boolean
isIntRangeExpr
(
JetExpression
rangeExpression
)
{
if
(
rangeExpression
instanceof
JetBinaryExpression
)
{
JetBinaryExpression
binaryExpression
=
(
JetBinaryExpression
)
rangeExpression
;
if
(
binaryExpression
.
getOperationReference
().
getReferencedNameElementType
()
==
JetTokens
.
RANGE
)
{
JetType
jetType
=
bindingContext
.
get
(
BindingContext
.
EXPRESSION_TYPE
,
rangeExpression
);
final
DeclarationDescriptor
descriptor
=
jetType
.
getConstructor
().
getDeclarationDescriptor
();
if
(
isClass
(
descriptor
,
"IntRange"
))
{
// TODO IntRange subclasses
return
true
;
}
}
}
return
false
;
}
@Override
public
StackValue
visitTupleExpression
(
JetTupleExpression
expression
,
StackValue
receiver
)
{
final
List
<
JetExpression
>
entries
=
expression
.
getEntries
();
...
...
idea/src/org/jetbrains/jet/codegen/StackValue.java
浏览文件 @
232fc89c
...
...
@@ -275,7 +275,19 @@ public abstract class StackValue {
@Override
public
void
put
(
Type
type
,
InstructionAdapter
v
)
{
v
.
aconst
(
value
);
if
(
value
instanceof
Integer
)
v
.
iconst
((
Integer
)
value
);
else
if
(
value
instanceof
Long
)
v
.
lconst
((
Long
)
value
);
else
if
(
value
instanceof
Float
)
v
.
fconst
((
Float
)
value
);
else
if
(
value
instanceof
Double
)
v
.
dconst
((
Double
)
value
);
else
v
.
aconst
(
value
);
coerce
(
type
,
v
);
}
...
...
idea/testData/codegen/patternMatching/range.jet
浏览文件 @
232fc89c
fun isDigit(a: Int) = when(a) {
in 0..9 => "digit"
else => "something"
fun isDigit(a: Int) : String {
val aa = java.util.ArrayList<Int> ()
aa.add(239)
return when(a) {
in aa => "array list"
in 0..9 => "digit"
!in 0..100 => "not small"
else => "something"
}
}
idea/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
浏览文件 @
232fc89c
...
...
@@ -39,8 +39,12 @@ public class PatternMatchingTest extends CodegenTestCase {
loadFile
();
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
();
assertEquals
(
"array list"
,
foo
.
invoke
(
null
,
239
));
assertEquals
(
"digit"
,
foo
.
invoke
(
null
,
0
));
assertEquals
(
"digit"
,
foo
.
invoke
(
null
,
9
));
assertEquals
(
"digit"
,
foo
.
invoke
(
null
,
5
));
assertEquals
(
"something"
,
foo
.
invoke
(
null
,
19
));
assertEquals
(
"not small"
,
foo
.
invoke
(
null
,
190
));
}
public
void
testRangeChar
()
throws
Exception
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录