Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
5e5b793b
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,发现更多精彩内容 >>
提交
5e5b793b
编写于
11月 01, 2011
作者:
A
Alex Tkachman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
varargs
上级
c371bd1e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
73 addition
and
24 deletion
+73
-24
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
...kend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+19
-2
compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
.../backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
+6
-15
compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java
...ler/backend/src/org/jetbrains/jet/codegen/StackValue.java
+3
-0
compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java
...frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java
+5
-0
compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java
compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java
+40
-7
未找到文件。
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
5e5b793b
...
...
@@ -79,7 +79,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
this
.
intrinsics
=
state
.
getIntrinsics
();
}
private
CallableMethod
asCallableMethod
(
FunctionDescriptor
fd
)
{
private
static
CallableMethod
asCallableMethod
(
FunctionDescriptor
fd
)
{
Method
descriptor
=
ClosureCodegen
.
erasedInvokeSignature
(
fd
);
String
owner
=
ClosureCodegen
.
getInternalClassName
(
fd
);
final
CallableMethod
result
=
new
CallableMethod
(
owner
,
descriptor
,
INVOKEVIRTUAL
,
Arrays
.
asList
(
descriptor
.
getArgumentTypes
()));
...
...
@@ -1187,7 +1187,24 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
mask
|=
(
1
<<
index
);
}
else
if
(
resolvedValueArgument
instanceof
VarargValueArgument
)
{
throw
new
UnsupportedOperationException
(
"Varargs are not supported yet"
);
VarargValueArgument
valueArgument
=
(
VarargValueArgument
)
resolvedValueArgument
;
JetType
outType
=
valueParameterDescriptor
.
getOutType
();
Type
type
=
typeMapper
.
mapType
(
outType
);
assert
type
.
getSort
()
==
Type
.
ARRAY
;
Type
elementType
=
type
.
getElementType
();
int
size
=
valueArgument
.
getArgumentExpressions
().
size
();
v
.
iconst
(
valueArgument
.
getArgumentExpressions
().
size
());
v
.
newarray
(
elementType
);
for
(
int
i
=
0
;
i
!=
size
;
++
i
)
{
v
.
dup
();
v
.
iconst
(
i
);
gen
(
valueArgument
.
getArgumentExpressions
().
get
(
i
),
elementType
);
StackValue
.
arrayElement
(
elementType
,
false
).
store
(
v
);
}
// throw new UnsupportedOperationException("Varargs are not supported yet");
}
else
{
throw
new
UnsupportedOperationException
();
...
...
compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
浏览文件 @
5e5b793b
...
...
@@ -361,10 +361,6 @@ public class JetTypeMapper {
if
(
jetType
.
equals
(
standardLibrary
.
getNullableBooleanType
()))
{
return
JL_BOOLEAN_TYPE
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getStringType
())
||
jetType
.
equals
(
standardLibrary
.
getNullableStringType
()))
{
return
Type
.
getType
(
String
.
class
);
}
if
(
jetType
.
equals
(
standardLibrary
.
getByteArrayType
())){
return
ARRAY_BYTE_TYPE
;
}
...
...
@@ -390,6 +386,10 @@ public class JetTypeMapper {
return
ARRAY_BOOL_TYPE
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getStringType
())
||
jetType
.
equals
(
standardLibrary
.
getNullableStringType
()))
{
return
Type
.
getType
(
String
.
class
);
}
DeclarationDescriptor
descriptor
=
jetType
.
getConstructor
().
getDeclarationDescriptor
();
if
(
standardLibrary
.
getArray
().
equals
(
descriptor
))
{
if
(
jetType
.
getArguments
().
size
()
!=
1
)
{
...
...
@@ -491,9 +491,6 @@ public class JetTypeMapper {
}
for
(
ValueParameterDescriptor
parameter
:
parameters
)
{
Type
type
=
mapType
(
parameter
.
getOutType
());
if
(
parameter
.
getVarargElementType
()
!=
null
)
{
type
=
Type
.
getType
(
"["
+
type
.
getDescriptor
());
}
valueParameterTypes
.
add
(
type
);
parameterTypes
.
add
(
type
);
}
...
...
@@ -517,7 +514,7 @@ public class JetTypeMapper {
return
mapToCallableMethod
(
functionDescriptor
,
kind
);
}
CallableMethod
mapToCallableMethod
(
PsiMethod
method
)
{
static
CallableMethod
mapToCallableMethod
(
PsiMethod
method
)
{
final
PsiClass
containingClass
=
method
.
getContainingClass
();
String
owner
=
jvmName
(
containingClass
);
Method
signature
=
getMethodDescriptor
(
method
);
...
...
@@ -591,13 +588,7 @@ public class JetTypeMapper {
parameterTypes
.
add
(
mapType
(
receiver
.
getType
()));
}
for
(
ValueParameterDescriptor
parameter
:
parameters
)
{
if
(
parameter
.
getVarargElementType
()
!=
null
)
{
Type
type
=
mapType
(
parameter
.
getOutType
());
type
=
Type
.
getType
(
"["
+
type
.
getDescriptor
());
parameterTypes
.
add
(
type
);
}
else
parameterTypes
.
add
(
mapType
(
parameter
.
getOutType
()));
parameterTypes
.
add
(
mapType
(
parameter
.
getOutType
()));
}
Type
returnType
=
mapReturnType
(
f
.
getReturnType
());
return
new
Method
(
name
,
returnType
,
parameterTypes
.
toArray
(
new
Type
[
parameterTypes
.
size
()]));
...
...
compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java
浏览文件 @
5e5b793b
...
...
@@ -681,6 +681,9 @@ public abstract class StackValue {
case
Type
.
INT
:
return
JetTypeMapper
.
TYPE_SHARED_INT
;
case
Type
.
LONG
:
return
JetTypeMapper
.
TYPE_SHARED_LONG
;
case
Type
.
BOOLEAN
:
return
JetTypeMapper
.
TYPE_SHARED_BOOLEAN
;
...
...
compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java
浏览文件 @
5e5b793b
...
...
@@ -59,6 +59,11 @@ public class JetParameter extends JetNamedDeclaration {
return
findChildByType
(
JetTokens
.
VAR_KEYWORD
)
!=
null
||
isRef
();
}
public
boolean
isVarArg
()
{
JetModifierList
modifierList
=
getModifierList
();
return
modifierList
!=
null
&&
modifierList
.
getModifierNode
(
JetTokens
.
VARARG_KEYWORD
)
!=
null
;
}
@Nullable
public
ASTNode
getValOrVarNode
()
{
ASTNode
val
=
getNode
().
findChildByType
(
JetTokens
.
VAL_KEYWORD
);
...
...
compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java
浏览文件 @
5e5b793b
...
...
@@ -8,22 +8,55 @@ import java.lang.reflect.Method;
*/
public
class
VarArgTest
extends
CodegenTestCase
{
public
void
testStringArray
()
throws
InvocationTargetException
,
IllegalAccessException
{
/*
loadText
(
"fun test(vararg ts: String) = ts"
);
System
.
out
.
println
(
generateToText
());
final
Method
main
=
generateFunction
();
Object[] args = {"mama", "papa"};
assertTrue(args == main.invoke(null, args));
*/
String
[]
args
=
{
"mama"
,
"papa"
};
assertTrue
(
args
==
main
.
invoke
(
null
,
new
Object
[]{
args
}
));
}
public
void
testIntArray
()
throws
InvocationTargetException
,
IllegalAccessException
{
/*
loadText
(
"fun test(vararg ts: Int) = ts"
);
System
.
out
.
println
(
generateToText
());
final
Method
main
=
generateFunction
();
int
[]
args
=
{
3
,
4
};
assertTrue(args == main.invoke(null, args));
*/
assertTrue
(
args
==
main
.
invoke
(
null
,
new
Object
[]{
args
}));
}
public
void
testIntArrayKotlinNoArgs
()
throws
InvocationTargetException
,
IllegalAccessException
{
loadText
(
"fun test() = testf(); fun testf(vararg ts: Int) = ts"
);
System
.
out
.
println
(
generateToText
());
final
Method
main
=
generateFunction
();
Object
res
=
main
.
invoke
(
null
,
new
Object
[]{});
assertTrue
(((
int
[])
res
).
length
==
0
);
}
public
void
testIntArrayKotlin
()
throws
InvocationTargetException
,
IllegalAccessException
{
loadText
(
"fun test() = testf(239, 7); fun testf(vararg ts: Int) = ts"
);
System
.
out
.
println
(
generateToText
());
final
Method
main
=
generateFunction
();
Object
res
=
main
.
invoke
(
null
,
new
Object
[]{});
assertTrue
(((
int
[])
res
).
length
==
2
);
assertTrue
(((
int
[])
res
)[
0
]
==
239
);
assertTrue
(((
int
[])
res
)[
1
]
==
7
);
}
public
void
testNullableIntArrayKotlin
()
throws
InvocationTargetException
,
IllegalAccessException
{
loadText
(
"fun test() = testf(239.byt, 7.byt); fun testf(vararg ts: Byte?) = ts"
);
System
.
out
.
println
(
generateToText
());
final
Method
main
=
generateFunction
();
Object
res
=
main
.
invoke
(
null
,
new
Object
[]{});
assertTrue
(((
Byte
[])
res
).
length
==
2
);
assertTrue
(((
Byte
[])
res
)[
0
]
==
(
byte
)
239
);
assertTrue
(((
Byte
[])
res
)[
1
]
==
7
);
}
public
void
testIntArrayKotlinObj
()
throws
InvocationTargetException
,
IllegalAccessException
{
loadText
(
"fun test() = testf(\"239\"); fun testf(vararg ts: String) = ts"
);
System
.
out
.
println
(
generateToText
());
final
Method
main
=
generateFunction
();
Object
res
=
main
.
invoke
(
null
,
new
Object
[]{});
assertTrue
(((
String
[])
res
).
length
==
1
);
assertTrue
(((
String
[])
res
)[
0
].
equals
(
"239"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录