Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
9969b8d7
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,发现更多精彩内容 >>
提交
9969b8d7
编写于
5月 27, 2011
作者:
D
Dmitry Jemerov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
put values of correct type on stack for checking if character is in range
上级
6dfa8ca8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
31 addition
and
12 deletion
+31
-12
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+5
-8
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
+4
-3
idea/testData/codegen/patternMatching/rangeChar.jet
idea/testData/codegen/patternMatching/rangeChar.jet
+4
-0
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
+6
-1
idea/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
.../tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
+8
-0
未找到文件。
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
9969b8d7
...
...
@@ -51,6 +51,7 @@ public class ExpressionCodegen extends JetVisitor {
private
static
final
String
INT_RANGE_CONSTRUCTOR_DESCRIPTOR
=
"(II)V"
;
private
static
final
Type
OBJECT_TYPE
=
Type
.
getType
(
Object
.
class
);
private
static
final
Type
INTEGER_TYPE
=
Type
.
getType
(
Integer
.
class
);
private
static
final
Type
ITERATOR_TYPE
=
Type
.
getType
(
Iterator
.
class
);
private
static
final
Type
THROWABLE_TYPE
=
Type
.
getType
(
Throwable
.
class
);
...
...
@@ -1026,7 +1027,7 @@ public class ExpressionCodegen extends JetVisitor {
private
void
generateRange
(
JetBinaryExpression
expression
)
{
final
Type
leftType
=
expressionType
(
expression
.
getLeft
());
if
(
isIntPrimitive
(
leftType
))
{
if
(
JetTypeMapper
.
isIntPrimitive
(
leftType
))
{
v
.
anew
(
INT_RANGE_TYPE
);
v
.
dup
();
gen
(
expression
.
getLeft
(),
Type
.
INT_TYPE
);
...
...
@@ -1058,11 +1059,7 @@ public class ExpressionCodegen extends JetVisitor {
}
private
static
boolean
isNumberPrimitive
(
Type
type
)
{
return
isIntPrimitive
(
type
)
||
type
==
Type
.
FLOAT_TYPE
||
type
==
Type
.
DOUBLE_TYPE
||
type
==
Type
.
LONG_TYPE
;
}
private
static
boolean
isIntPrimitive
(
Type
type
)
{
return
type
==
Type
.
INT_TYPE
||
type
==
Type
.
SHORT_TYPE
||
type
==
Type
.
BYTE_TYPE
||
type
==
Type
.
CHAR_TYPE
;
return
JetTypeMapper
.
isIntPrimitive
(
type
)
||
type
==
Type
.
FLOAT_TYPE
||
type
==
Type
.
DOUBLE_TYPE
||
type
==
Type
.
LONG_TYPE
;
}
private
static
int
opcodeForMethod
(
final
String
name
)
{
...
...
@@ -1242,7 +1239,7 @@ public class ExpressionCodegen extends JetVisitor {
int
increment
=
op
.
getName
().
equals
(
"inc"
)
?
1
:
-
1
;
if
(
operand
instanceof
JetReferenceExpression
)
{
final
int
index
=
indexOfLocal
((
JetReferenceExpression
)
operand
);
if
(
index
>=
0
&&
isIntPrimitive
(
asmType
))
{
if
(
index
>=
0
&&
JetTypeMapper
.
isIntPrimitive
(
asmType
))
{
v
.
iinc
(
index
,
increment
);
return
StackValue
.
local
(
index
,
asmType
);
}
...
...
@@ -1617,7 +1614,7 @@ public class ExpressionCodegen extends JetVisitor {
else
if
(
condition
instanceof
JetWhenConditionInRange
)
{
JetExpression
range
=
((
JetWhenConditionInRange
)
condition
).
getRangeExpression
();
gen
(
range
,
RANGE_TYPE
);
new
StackValue
.
Local
(
subjectLocal
,
subjectType
).
put
(
OBJECT
_TYPE
,
v
);
new
StackValue
.
Local
(
subjectLocal
,
subjectType
).
put
(
INTEGER
_TYPE
,
v
);
v
.
invokeinterface
(
CLASS_RANGE
,
"contains"
,
"(Ljava/lang/Comparable;)Z"
);
myStack
.
push
(
new
StackValue
.
OnStack
(
Type
.
BOOLEAN_TYPE
));
}
...
...
idea/src/org/jetbrains/jet/codegen/JetTypeMapper.java
浏览文件 @
9969b8d7
...
...
@@ -40,6 +40,10 @@ public class JetTypeMapper {
return
qName
.
replace
(
"."
,
"/"
);
}
static
boolean
isIntPrimitive
(
Type
type
)
{
return
type
==
Type
.
INT_TYPE
||
type
==
Type
.
SHORT_TYPE
||
type
==
Type
.
BYTE_TYPE
||
type
==
Type
.
CHAR_TYPE
;
}
public
String
jvmName
(
ClassDescriptor
jetClass
,
OwnerKind
kind
)
{
PsiElement
declaration
=
bindingContext
.
getDeclarationPsiElement
(
jetClass
);
if
(
declaration
instanceof
PsiClass
)
{
...
...
idea/src/org/jetbrains/jet/codegen/StackValue.java
浏览文件 @
9969b8d7
...
...
@@ -75,8 +75,9 @@ public abstract class StackValue {
return
new
Property
(
name
,
fieldOwner
,
interfaceOwner
,
getter
,
setter
,
isStatic
,
type
);
}
private
static
void
box
(
final
Type
type
,
InstructionAdapter
v
)
{
if
(
type
==
Type
.
INT_TYPE
)
{
private
static
void
box
(
final
Type
type
,
final
Type
toType
,
InstructionAdapter
v
)
{
// TODO handle toType correctly
if
(
type
==
Type
.
INT_TYPE
||
(
JetTypeMapper
.
isIntPrimitive
(
type
)
&&
toType
.
getInternalName
().
equals
(
"java/lang/Integer"
)))
{
v
.
invokestatic
(
"java/lang/Integer"
,
"valueOf"
,
"(I)Ljava/lang/Integer;"
);
}
else
if
(
type
==
Type
.
BOOLEAN_TYPE
)
{
...
...
@@ -131,7 +132,7 @@ public abstract class StackValue {
protected
void
coerce
(
Type
type
,
InstructionAdapter
v
)
{
if
(
type
.
getSort
()
==
Type
.
OBJECT
)
{
box
(
this
.
type
,
v
);
box
(
this
.
type
,
type
,
v
);
}
else
if
(
this
.
type
.
getSort
()
==
Type
.
OBJECT
&&
type
.
getSort
()
<=
Type
.
DOUBLE
)
{
unbox
(
type
,
v
);
...
...
idea/testData/codegen/patternMatching/rangeChar.jet
0 → 100644
浏览文件 @
9969b8d7
fun isDigit(a: Char) = when(a) {
in '0'..'9' => "digit"
else => "something"
}
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
浏览文件 @
9969b8d7
...
...
@@ -155,7 +155,12 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
protected
Method
generateFunction
()
{
Class
aClass
=
generateNamespaceClass
();
return
aClass
.
getMethods
()[
0
];
try
{
return
aClass
.
getMethods
()[
0
];
}
catch
(
Error
e
)
{
System
.
out
.
println
(
generateToText
());
throw
e
;
}
}
protected
Method
generateFunction
(
String
name
)
{
...
...
idea/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
浏览文件 @
9969b8d7
...
...
@@ -42,6 +42,14 @@ public class PatternMatchingTest extends CodegenTestCase {
assertEquals
(
"something"
,
foo
.
invoke
(
null
,
19
));
}
public
void
testRangeChar
()
throws
Exception
{
loadFile
();
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
();
assertEquals
(
"digit"
,
foo
.
invoke
(
null
,
'0'
));
assertEquals
(
"something"
,
foo
.
invoke
(
null
,
'A'
));
}
public
void
testWildcardPattern
()
throws
Exception
{
loadText
(
"fun foo(x: String) = when(x) { is * => \"something\" }"
);
Method
foo
=
generateFunction
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录