Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
8a927d70
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,发现更多精彩内容 >>
提交
8a927d70
编写于
9月 28, 2011
作者:
A
Alex Tkachman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
array codegen bugs
上级
a06aa17a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
120 addition
and
17 deletion
+120
-17
compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java
...er/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java
+7
-4
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
...kend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+15
-4
compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
.../backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
+16
-0
compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java
...ckend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java
+1
-1
compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java
...ler/backend/src/org/jetbrains/jet/codegen/StackValue.java
+2
-1
idea/testData/codegen/regressions/kt326.jet
idea/testData/codegen/regressions/kt326.jet
+25
-0
idea/tests/org/jetbrains/jet/codegen/ArrayGenTest.java
idea/tests/org/jetbrains/jet/codegen/ArrayGenTest.java
+49
-0
idea/tests/org/jetbrains/jet/codegen/ArrayGenTestCase.java
idea/tests/org/jetbrains/jet/codegen/ArrayGenTestCase.java
+0
-7
stdlib/src/jet/typeinfo/TypeInfo.java
stdlib/src/jet/typeinfo/TypeInfo.java
+5
-0
未找到文件。
compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java
浏览文件 @
8a927d70
package
org.jetbrains.jet.codegen
;
import
com.intellij.psi.PsiClass
;
import
com.intellij.psi.PsiElement
;
import
org.jetbrains.jet.lang.descriptors.ClassDescriptor
;
import
org.jetbrains.jet.lang.descriptors.ClassKind
;
import
org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
;
import
org.jetbrains.jet.lang.psi.JetClass
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
;
import
org.jetbrains.jet.lang.types.JetType
;
import
org.jetbrains.jet.lang.types.TypeProjection
;
import
org.objectweb.asm.Type
;
/**
* @author abreslav
...
...
@@ -54,4 +53,8 @@ public class CodegenUtil {
}
return
(
ClassDescriptor
)
outerDescriptor
;
}
public
static
Type
arrayElementType
(
Type
type
)
{
return
Type
.
getType
(
type
.
getDescriptor
().
substring
(
1
));
}
}
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
8a927d70
...
...
@@ -378,8 +378,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
gen
(
expression
.
getLoopRange
(),
loopRangeType
);
// array
v
.
load
(
myIndexVar
,
Type
.
INT_TYPE
);
v
.
aload
(
loopRangeType
.
getElementType
(
));
StackValue
.
onStack
(
loopRangeType
.
getElementType
(
)).
put
(
asmParamType
,
v
);
v
.
aload
(
CodegenUtil
.
arrayElementType
(
loopRangeType
));
StackValue
.
onStack
(
CodegenUtil
.
arrayElementType
(
loopRangeType
)).
put
(
asmParamType
,
v
);
v
.
store
(
lookupLocal
(
parameterDescriptor
),
asmParamType
);
}
...
...
@@ -1683,12 +1683,23 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
}
private
void
generateNewArray
(
JetCallExpression
expression
,
Type
type
)
{
JetType
arrayType
=
bindingContext
.
get
(
BindingContext
.
EXPRESSION_TYPE
,
expression
);
List
<?
extends
ValueArgument
>
args
=
expression
.
getValueArguments
();
if
(
args
.
size
()
!=
1
)
{
throw
new
CompilationException
(
"array constructor requires one value argument"
);
}
gen
(
args
.
get
(
0
).
getArgumentExpression
(),
Type
.
INT_TYPE
);
v
.
newarray
(
type
.
getElementType
());
JetType
elementType
=
typeMapper
.
getGenericsElementType
(
arrayType
);
if
(
elementType
!=
null
)
{
generateTypeInfo
(
elementType
);
v
.
invokestatic
(
"jet/typeinfo/TypeInfo"
,
"newArray"
,
"(ILjet/typeinfo/TypeInfo;)[Ljava/lang/Object;"
);
v
.
checkcast
(
type
);
}
else
{
v
.
newarray
(
CodegenUtil
.
arrayElementType
(
type
));
}
}
@Override
...
...
@@ -1698,7 +1709,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
gen
(
array
,
arrayType
);
generateArrayIndex
(
expression
);
if
(
arrayType
.
getSort
()
==
Type
.
ARRAY
)
{
final
Type
elementType
=
arrayType
.
getElementType
(
);
final
Type
elementType
=
CodegenUtil
.
arrayElementType
(
arrayType
);
return
StackValue
.
arrayElement
(
elementType
);
}
else
{
...
...
compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
浏览文件 @
8a927d70
...
...
@@ -670,4 +670,20 @@ public class JetTypeMapper {
public
String
isKnownTypeInfo
(
JetType
jetType
)
{
return
knowTypes
.
get
(
jetType
);
}
public
boolean
isGenericsArray
(
JetType
type
)
{
DeclarationDescriptor
declarationDescriptor
=
type
.
getConstructor
().
getDeclarationDescriptor
();
if
(
declarationDescriptor
instanceof
TypeParameterDescriptor
)
return
true
;
if
(
standardLibrary
.
getArray
().
equals
(
declarationDescriptor
))
return
isGenericsArray
(
type
.
getArguments
().
get
(
0
).
getType
());
return
false
;
}
public
JetType
getGenericsElementType
(
JetType
arrayType
)
{
JetType
type
=
arrayType
.
getArguments
().
get
(
0
).
getType
();
return
isGenericsArray
(
type
)
?
type
:
null
;
}
}
compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java
浏览文件 @
8a927d70
...
...
@@ -152,7 +152,7 @@ public class NamespaceCodegen {
v
.
aconst
(
jvmType
);
v
.
iconst
(
jetType
.
isNullable
()
?
1
:
0
);
List
<
TypeProjection
>
arguments
=
jetType
.
getArguments
();
if
(
arguments
.
size
()
>
0
)
{
if
(
arguments
.
size
()
>
0
&&
!(
jvmType
.
getSort
()
==
Type
.
ARRAY
&&
jvmType
.
getElementType
().
getSort
()
!=
Type
.
OBJECT
)
)
{
v
.
iconst
(
arguments
.
size
());
v
.
newarray
(
JetTypeMapper
.
TYPE_TYPEINFOPROJECTION
);
...
...
compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java
浏览文件 @
8a927d70
...
...
@@ -186,7 +186,7 @@ public abstract class StackValue {
else
v
.
iconst
(
0
);
}
else
if
(
type
.
getSort
()
==
Type
.
OBJECT
&&
this
.
type
.
equals
(
JetTypeMapper
.
TYPE_OBJECT
))
{
else
if
(
type
.
getSort
()
==
Type
.
OBJECT
&&
this
.
type
.
equals
(
JetTypeMapper
.
TYPE_OBJECT
)
||
type
.
getSort
()
==
Type
.
ARRAY
)
{
v
.
checkcast
(
type
);
}
else
if
(
type
.
getSort
()
==
Type
.
OBJECT
)
{
...
...
@@ -431,6 +431,7 @@ public abstract class StackValue {
@Override
public
void
put
(
Type
type
,
InstructionAdapter
v
)
{
v
.
aload
(
type
);
// assumes array and index are on the stack
coerce
(
type
,
v
);
}
@Override
...
...
idea/testData/codegen/regressions/kt326.jet
0 → 100644
浏览文件 @
8a927d70
namespace test
class List<T>() {
val a : Array<T> = Array<T>(1)
}
fun box() : String {
val a = List<String>()
a.a[0] = "1"
println(a.a[0])
val b = List<Int?>()
b.a[0] = 10
println(b.a[0])
val c = List<Array<Int>>()
c.a[0] = Array<Int>(4)
println(c.a[0].size)
return "OK"
}
fun println(s : Any?) {
System.out?.println(s);
}
idea/tests/org/jetbrains/jet/codegen/ArrayGenTest.java
0 → 100644
浏览文件 @
8a927d70
package
org.jetbrains.jet.codegen
;
import
java.lang.reflect.Method
;
public
class
ArrayGenTest
extends
CodegenTestCase
{
public
void
testKt238
()
throws
Exception
{
blackBoxFile
(
"regressions/kt238.jet"
);
}
public
void
testKt326
()
throws
Exception
{
blackBoxFile
(
"regressions/kt326.jet"
);
}
public
void
testCreateMultiInt
()
throws
Exception
{
loadText
(
"fun foo() = Array<Array<Int>> (5)"
);
Method
foo
=
generateFunction
();
Object
invoke
=
foo
.
invoke
(
null
);
System
.
out
.
println
(
invoke
.
getClass
());
assertTrue
(
invoke
instanceof
int
[][]);
}
public
void
testCreateMultiString
()
throws
Exception
{
loadText
(
"fun foo() = Array<Array<String>> (5)"
);
Method
foo
=
generateFunction
();
Object
invoke
=
foo
.
invoke
(
null
);
System
.
out
.
println
(
invoke
.
getClass
());
assertTrue
(
invoke
instanceof
String
[][]);
}
public
void
testCreateMultiGenerics
()
throws
Exception
{
/*
loadText("class L<T>() { val a = Array<T>(5) } fun foo() = L<Int>.a");
System.out.println(generateToText());
Method foo = generateFunction();
Object invoke = foo.invoke(null);
System.out.println(invoke.getClass());
assertTrue(invoke instanceof Integer[]);
*/
}
public
void
testIntGenerics
()
throws
Exception
{
loadText
(
"class L<T>(var a : T) {} fun foo() = L<Int>(5).a"
);
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
();
Object
invoke
=
foo
.
invoke
(
null
);
System
.
out
.
println
(
invoke
.
getClass
());
assertTrue
(
invoke
instanceof
Integer
);
}
}
idea/tests/org/jetbrains/jet/codegen/ArrayGenTestCase.java
已删除
100644 → 0
浏览文件 @
a06aa17a
package
org.jetbrains.jet.codegen
;
public
class
ArrayGenTestCase
extends
CodegenTestCase
{
public
void
testKt238
()
throws
Exception
{
blackBoxFile
(
"regressions/kt238.jet"
);
}
}
stdlib/src/jet/typeinfo/TypeInfo.java
浏览文件 @
8a927d70
...
...
@@ -3,6 +3,7 @@ package jet.typeinfo;
import
jet.JetObject
;
import
jet.Tuple0
;
import
java.lang.reflect.Array
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.TypeVariable
;
import
java.util.*
;
...
...
@@ -37,6 +38,10 @@ public abstract class TypeInfo<T> implements JetObject {
public
static
final
TypeInfo
<
Double
>
NULLABLE_DOUBLE_TYPE_INFO
=
getTypeInfo
(
Double
.
class
,
true
);
public
static
final
TypeInfo
<
String
>
NULLABLE_STRING_TYPE_INFO
=
getTypeInfo
(
String
.
class
,
true
);
public
static
final
TypeInfo
<
Tuple0
>
NULLABLE_TUPLE0_TYPE_INFO
=
getTypeInfo
(
Tuple0
.
class
,
true
);
public
static
Object
[]
newArray
(
int
length
,
TypeInfo
typeInfo
)
{
return
(
Object
[])
Array
.
newInstance
(((
TypeInfoImpl
)
typeInfo
).
signature
.
klazz
,
length
);
}
public
static
<
T
>
TypeInfoProjection
invariantProjection
(
final
TypeInfo
<
T
>
typeInfo
)
{
return
(
TypeInfoProjection
)
typeInfo
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录