Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
93d5a3b5
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,发现更多精彩内容 >>
提交
93d5a3b5
编写于
11月 01, 2011
作者:
A
Alex Tkachman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lazy initialization of classes
上级
503f1cf9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
136 addition
and
63 deletion
+136
-63
compiler/frontend/src/jet/Library.jet
compiler/frontend/src/jet/Library.jet
+4
-0
compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
.../src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
+122
-63
compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java
compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java
+10
-0
未找到文件。
compiler/frontend/src/jet/Library.jet
浏览文件 @
93d5a3b5
...
@@ -40,6 +40,10 @@ fun Any?.equals(other : Any?) : Boolean// = this === other
...
@@ -40,6 +40,10 @@ fun Any?.equals(other : Any?) : Boolean// = this === other
// Returns "null" for null
// Returns "null" for null
fun Any?.toString() : String// = this === other
fun Any?.toString() : String// = this === other
// fun <T> array(vararg elements : T) : Array<T>
// fun array(vararg elements : Int) : IntArray
fun String?.plus(other: Any?) : String
fun String?.plus(other: Any?) : String
trait Iterator<out T> {
trait Iterator<out T> {
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
浏览文件 @
93d5a3b5
...
@@ -47,68 +47,70 @@ public class JetStandardLibrary {
...
@@ -47,68 +47,70 @@ public class JetStandardLibrary {
// return standardLibrary;
// return standardLibrary;
}
}
private
final
JetScope
libraryScope
;
private
JetScope
libraryScope
;
private
final
ClassDescriptor
byteClass
;
private
ClassDescriptor
byteClass
;
private
final
ClassDescriptor
charClass
;
private
ClassDescriptor
charClass
;
private
final
ClassDescriptor
shortClass
;
private
ClassDescriptor
shortClass
;
private
final
ClassDescriptor
intClass
;
private
ClassDescriptor
intClass
;
private
final
ClassDescriptor
longClass
;
private
ClassDescriptor
longClass
;
private
final
ClassDescriptor
floatClass
;
private
ClassDescriptor
floatClass
;
private
final
ClassDescriptor
doubleClass
;
private
ClassDescriptor
doubleClass
;
private
final
ClassDescriptor
booleanClass
;
private
ClassDescriptor
booleanClass
;
private
final
ClassDescriptor
stringClass
;
private
final
ClassDescriptor
arrayClass
;
private
ClassDescriptor
stringClass
;
private
final
ClassDescriptor
iterableClass
;
private
ClassDescriptor
arrayClass
;
private
final
ClassDescriptor
typeInfoClass
;
private
ClassDescriptor
iterableClass
;
private
ClassDescriptor
typeInfoClass
;
private
final
JetType
byteType
;
private
final
JetType
charType
;
private
JetType
byteType
;
private
final
JetType
shortType
;
private
JetType
charType
;
private
final
JetType
intType
;
private
JetType
shortType
;
private
final
JetType
longType
;
private
JetType
intType
;
private
final
JetType
floatType
;
private
JetType
longType
;
private
final
JetType
doubleType
;
private
JetType
floatType
;
private
final
JetType
booleanType
;
private
JetType
doubleType
;
private
final
JetType
stringType
;
private
JetType
booleanType
;
private
final
JetType
nullableByteType
;
private
JetType
stringType
;
private
final
JetType
nullableCharType
;
private
final
JetType
nullableShortType
;
private
JetType
nullableByteType
;
private
final
JetType
nullableIntType
;
private
JetType
nullableCharType
;
private
final
JetType
nullableLongType
;
private
JetType
nullableShortType
;
private
final
JetType
nullableFloatType
;
private
JetType
nullableIntType
;
private
final
JetType
nullableDoubleType
;
private
JetType
nullableLongType
;
private
final
JetType
nullableBooleanType
;
private
JetType
nullableFloatType
;
private
final
JetType
nullableTuple0Type
;
private
JetType
nullableDoubleType
;
private
JetType
nullableBooleanType
;
private
final
ClassDescriptor
byteArrayClass
;
private
JetType
nullableTuple0Type
;
private
final
ClassDescriptor
charArrayClass
;
private
final
ClassDescriptor
shortArrayClass
;
private
ClassDescriptor
byteArrayClass
;
private
final
ClassDescriptor
intArrayClass
;
private
ClassDescriptor
charArrayClass
;
private
final
ClassDescriptor
longArrayClass
;
private
ClassDescriptor
shortArrayClass
;
private
final
ClassDescriptor
floatArrayClass
;
private
ClassDescriptor
intArrayClass
;
private
final
ClassDescriptor
doubleArrayClass
;
private
ClassDescriptor
longArrayClass
;
private
final
ClassDescriptor
booleanArrayClass
;
private
ClassDescriptor
floatArrayClass
;
private
ClassDescriptor
doubleArrayClass
;
private
final
JetType
byteArrayType
;
private
ClassDescriptor
booleanArrayClass
;
private
final
JetType
charArrayType
;
private
final
JetType
shortArrayType
;
private
JetType
byteArrayType
;
private
final
JetType
intArrayType
;
private
JetType
charArrayType
;
private
final
JetType
longArrayType
;
private
JetType
shortArrayType
;
private
final
JetType
floatArrayType
;
private
JetType
intArrayType
;
private
final
JetType
doubleArrayType
;
private
JetType
longArrayType
;
private
final
JetType
booleanArrayType
;
private
JetType
floatArrayType
;
private
JetType
doubleArrayType
;
private
JetType
booleanArrayType
;
public
JetType
getTuple0Type
()
{
public
JetType
getTuple0Type
()
{
return
tuple0Type
;
return
tuple0Type
;
}
}
private
final
JetType
tuple0Type
;
private
JetType
tuple0Type
;
private
final
JetType
nullableStringType
;
private
JetType
nullableStringType
;
private
final
NamespaceDescriptor
typeInfoNamespace
;
private
NamespaceDescriptor
typeInfoNamespace
;
private
final
Set
<
FunctionDescriptor
>
typeInfoFunction
;
private
Set
<
FunctionDescriptor
>
typeInfoFunction
;
private
JetStandardLibrary
(
@NotNull
Project
project
)
{
private
JetStandardLibrary
(
@NotNull
Project
project
)
{
// TODO : review
// TODO : review
...
@@ -124,10 +126,23 @@ public class JetStandardLibrary {
...
@@ -124,10 +126,23 @@ public class JetStandardLibrary {
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
TopDownAnalyzer
.
processStandardLibraryNamespace
(
bootstrappingSemanticServices
,
bindingTraceContext
,
writableScope
,
JetStandardClasses
.
STANDARD_CLASSES_NAMESPACE
,
file
.
getRootNamespace
());
TopDownAnalyzer
.
processStandardLibraryNamespace
(
bootstrappingSemanticServices
,
bindingTraceContext
,
writableScope
,
JetStandardClasses
.
STANDARD_CLASSES_NAMESPACE
,
file
.
getRootNamespace
());
this
.
libraryScope
=
JetStandardClasses
.
STANDARD_CLASSES_NAMESPACE
.
getMemberScope
();
//
this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
AnalyzingUtils
.
throwExceptionOnErrors
(
bindingTraceContext
.
getBindingContext
());
AnalyzingUtils
.
throwExceptionOnErrors
(
bindingTraceContext
.
getBindingContext
());
initStdClasses
();
}
catch
(
IOException
e
)
{
throw
new
IllegalStateException
(
e
);
}
}
public
JetScope
getLibraryScope
()
{
initStdClasses
();
return
libraryScope
;
}
private
void
initStdClasses
()
{
if
(
libraryScope
==
null
)
{
this
.
libraryScope
=
JetStandardClasses
.
STANDARD_CLASSES_NAMESPACE
.
getMemberScope
();
this
.
byteClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Byte"
);
this
.
byteClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Byte"
);
this
.
charClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Char"
);
this
.
charClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Char"
);
this
.
shortClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Short"
);
this
.
shortClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Short"
);
...
@@ -138,6 +153,7 @@ public class JetStandardLibrary {
...
@@ -138,6 +153,7 @@ public class JetStandardLibrary {
this
.
booleanClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Boolean"
);
this
.
booleanClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Boolean"
);
this
.
stringClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"String"
);
this
.
stringClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"String"
);
this
.
arrayClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Array"
);
this
.
arrayClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Array"
);
this
.
iterableClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Iterable"
);
this
.
iterableClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Iterable"
);
typeInfoNamespace
=
libraryScope
.
getNamespace
(
"typeinfo"
);
typeInfoNamespace
=
libraryScope
.
getNamespace
(
"typeinfo"
);
this
.
typeInfoClass
=
(
ClassDescriptor
)
typeInfoNamespace
.
getMemberScope
().
getClassifier
(
"TypeInfo"
);
this
.
typeInfoClass
=
(
ClassDescriptor
)
typeInfoNamespace
.
getMemberScope
().
getClassifier
(
"TypeInfo"
);
...
@@ -182,79 +198,87 @@ public class JetStandardLibrary {
...
@@ -182,79 +198,87 @@ public class JetStandardLibrary {
this
.
nullableBooleanType
=
TypeUtils
.
makeNullable
(
booleanType
);
this
.
nullableBooleanType
=
TypeUtils
.
makeNullable
(
booleanType
);
this
.
nullableStringType
=
TypeUtils
.
makeNullable
(
stringType
);
this
.
nullableStringType
=
TypeUtils
.
makeNullable
(
stringType
);
this
.
nullableTuple0Type
=
TypeUtils
.
makeNullable
(
tuple0Type
);
this
.
nullableTuple0Type
=
TypeUtils
.
makeNullable
(
tuple0Type
);
}
catch
(
IOException
e
)
{
throw
new
IllegalStateException
(
e
);
}
}
}
}
public
JetScope
getLibraryScope
()
{
return
libraryScope
;
}
@NotNull
@NotNull
public
ClassDescriptor
getByte
()
{
public
ClassDescriptor
getByte
()
{
initStdClasses
();
return
byteClass
;
return
byteClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getChar
()
{
public
ClassDescriptor
getChar
()
{
initStdClasses
();
return
charClass
;
return
charClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getShort
()
{
public
ClassDescriptor
getShort
()
{
initStdClasses
();
return
shortClass
;
return
shortClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getInt
()
{
public
ClassDescriptor
getInt
()
{
initStdClasses
();
return
intClass
;
return
intClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getLong
()
{
public
ClassDescriptor
getLong
()
{
initStdClasses
();
return
longClass
;
return
longClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getFloat
()
{
public
ClassDescriptor
getFloat
()
{
initStdClasses
();
return
floatClass
;
return
floatClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getDouble
()
{
public
ClassDescriptor
getDouble
()
{
initStdClasses
();
return
doubleClass
;
return
doubleClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getBoolean
()
{
public
ClassDescriptor
getBoolean
()
{
initStdClasses
();
return
booleanClass
;
return
booleanClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getString
()
{
public
ClassDescriptor
getString
()
{
initStdClasses
();
return
stringClass
;
return
stringClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getArray
()
{
public
ClassDescriptor
getArray
()
{
initStdClasses
();
return
arrayClass
;
return
arrayClass
;
}
}
@NotNull
@NotNull
public
ClassDescriptor
getIterable
()
{
public
ClassDescriptor
getIterable
()
{
initStdClasses
();
return
iterableClass
;
return
iterableClass
;
}
}
public
NamespaceDescriptor
getTypeInfoNamespace
()
{
public
NamespaceDescriptor
getTypeInfoNamespace
()
{
initStdClasses
();
return
typeInfoNamespace
;
return
typeInfoNamespace
;
}
}
public
ClassDescriptor
getTypeInfo
()
{
public
ClassDescriptor
getTypeInfo
()
{
initStdClasses
();
return
typeInfoClass
;
return
typeInfoClass
;
}
}
public
Set
<
FunctionDescriptor
>
getTypeInfoFunctions
()
{
public
Set
<
FunctionDescriptor
>
getTypeInfoFunctions
()
{
initStdClasses
();
return
typeInfoFunction
;
return
typeInfoFunction
;
}
}
...
@@ -267,46 +291,55 @@ public class JetStandardLibrary {
...
@@ -267,46 +291,55 @@ public class JetStandardLibrary {
@NotNull
@NotNull
public
JetType
getIntType
()
{
public
JetType
getIntType
()
{
initStdClasses
();
return
intType
;
return
intType
;
}
}
@NotNull
@NotNull
public
JetType
getLongType
()
{
public
JetType
getLongType
()
{
initStdClasses
();
return
longType
;
return
longType
;
}
}
@NotNull
@NotNull
public
JetType
getDoubleType
()
{
public
JetType
getDoubleType
()
{
initStdClasses
();
return
doubleType
;
return
doubleType
;
}
}
@NotNull
@NotNull
public
JetType
getFloatType
()
{
public
JetType
getFloatType
()
{
initStdClasses
();
return
floatType
;
return
floatType
;
}
}
@NotNull
@NotNull
public
JetType
getCharType
()
{
public
JetType
getCharType
()
{
initStdClasses
();
return
charType
;
return
charType
;
}
}
@NotNull
@NotNull
public
JetType
getBooleanType
()
{
public
JetType
getBooleanType
()
{
initStdClasses
();
return
booleanType
;
return
booleanType
;
}
}
@NotNull
@NotNull
public
JetType
getStringType
()
{
public
JetType
getStringType
()
{
initStdClasses
();
return
stringType
;
return
stringType
;
}
}
@NotNull
@NotNull
public
JetType
getByteType
()
{
public
JetType
getByteType
()
{
initStdClasses
();
return
byteType
;
return
byteType
;
}
}
@NotNull
@NotNull
public
JetType
getShortType
()
{
public
JetType
getShortType
()
{
initStdClasses
();
return
shortType
;
return
shortType
;
}
}
...
@@ -340,106 +373,132 @@ public class JetStandardLibrary {
...
@@ -340,106 +373,132 @@ public class JetStandardLibrary {
}
}
public
JetType
getNullableStringType
()
{
public
JetType
getNullableStringType
()
{
initStdClasses
();
return
nullableStringType
;
return
nullableStringType
;
}
}
public
JetType
getNullableByteType
()
{
public
JetType
getNullableByteType
()
{
initStdClasses
();
return
nullableByteType
;
return
nullableByteType
;
}
}
public
JetType
getNullableCharType
()
{
public
JetType
getNullableCharType
()
{
initStdClasses
();
return
nullableCharType
;
return
nullableCharType
;
}
}
public
JetType
getNullableShortType
()
{
public
JetType
getNullableShortType
()
{
initStdClasses
();
return
nullableShortType
;
return
nullableShortType
;
}
}
public
JetType
getNullableIntType
()
{
public
JetType
getNullableIntType
()
{
initStdClasses
();
return
nullableIntType
;
return
nullableIntType
;
}
}
public
JetType
getNullableLongType
()
{
public
JetType
getNullableLongType
()
{
initStdClasses
();
return
nullableLongType
;
return
nullableLongType
;
}
}
public
JetType
getNullableFloatType
()
{
public
JetType
getNullableFloatType
()
{
initStdClasses
();
return
nullableFloatType
;
return
nullableFloatType
;
}
}
public
JetType
getNullableDoubleType
()
{
public
JetType
getNullableDoubleType
()
{
initStdClasses
();
return
nullableDoubleType
;
return
nullableDoubleType
;
}
}
public
JetType
getNullableBooleanType
()
{
public
JetType
getNullableBooleanType
()
{
initStdClasses
();
return
nullableBooleanType
;
return
nullableBooleanType
;
}
}
public
JetType
getNullableTuple0Type
()
{
public
JetType
getNullableTuple0Type
()
{
initStdClasses
();
return
nullableTuple0Type
;
return
nullableTuple0Type
;
}
}
public
JetType
getBooleanArrayType
()
{
public
JetType
getBooleanArrayType
()
{
initStdClasses
();
return
booleanArrayType
;
return
booleanArrayType
;
}
}
public
JetType
getByteArrayType
()
{
public
JetType
getByteArrayType
()
{
initStdClasses
();
return
byteArrayType
;
return
byteArrayType
;
}
}
public
JetType
getCharArrayType
()
{
public
JetType
getCharArrayType
()
{
initStdClasses
();
return
charArrayType
;
return
charArrayType
;
}
}
public
JetType
getShortArrayType
()
{
public
JetType
getShortArrayType
()
{
initStdClasses
();
return
shortArrayType
;
return
shortArrayType
;
}
}
public
JetType
getIntArrayType
()
{
public
JetType
getIntArrayType
()
{
initStdClasses
();
return
intArrayType
;
return
intArrayType
;
}
}
public
JetType
getLongArrayType
()
{
public
JetType
getLongArrayType
()
{
initStdClasses
();
return
longArrayType
;
return
longArrayType
;
}
}
public
JetType
getFloatArrayType
()
{
public
JetType
getFloatArrayType
()
{
initStdClasses
();
return
floatArrayType
;
return
floatArrayType
;
}
}
public
JetType
getDoubleArrayType
()
{
public
JetType
getDoubleArrayType
()
{
initStdClasses
();
return
doubleArrayType
;
return
doubleArrayType
;
}
}
public
ClassDescriptor
getByteArrayClass
()
{
public
ClassDescriptor
getByteArrayClass
()
{
initStdClasses
();
return
byteArrayClass
;
return
byteArrayClass
;
}
}
public
ClassDescriptor
getCharArrayClass
()
{
public
ClassDescriptor
getCharArrayClass
()
{
initStdClasses
();
return
charArrayClass
;
return
charArrayClass
;
}
}
public
ClassDescriptor
getShortArrayClass
()
{
public
ClassDescriptor
getShortArrayClass
()
{
initStdClasses
();
return
shortArrayClass
;
return
shortArrayClass
;
}
}
public
ClassDescriptor
getIntArrayClass
()
{
public
ClassDescriptor
getIntArrayClass
()
{
initStdClasses
();
return
intArrayClass
;
return
intArrayClass
;
}
}
public
ClassDescriptor
getLongArrayClass
()
{
public
ClassDescriptor
getLongArrayClass
()
{
initStdClasses
();
return
longArrayClass
;
return
longArrayClass
;
}
}
public
ClassDescriptor
getFloatArrayClass
()
{
public
ClassDescriptor
getFloatArrayClass
()
{
initStdClasses
();
return
floatArrayClass
;
return
floatArrayClass
;
}
}
public
ClassDescriptor
getDoubleArrayClass
()
{
public
ClassDescriptor
getDoubleArrayClass
()
{
initStdClasses
();
return
doubleArrayClass
;
return
doubleArrayClass
;
}
}
public
ClassDescriptor
getBooleanArrayClass
()
{
public
ClassDescriptor
getBooleanArrayClass
()
{
initStdClasses
();
return
booleanArrayClass
;
return
booleanArrayClass
;
}
}
}
}
compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java
浏览文件 @
93d5a3b5
...
@@ -59,4 +59,14 @@ public class VarArgTest extends CodegenTestCase {
...
@@ -59,4 +59,14 @@ public class VarArgTest extends CodegenTestCase {
assertTrue
(((
String
[])
res
).
length
==
1
);
assertTrue
(((
String
[])
res
).
length
==
1
);
assertTrue
(((
String
[])
res
)[
0
].
equals
(
"239"
));
assertTrue
(((
String
[])
res
)[
0
].
equals
(
"239"
));
}
}
public
void
testArrayT
()
throws
InvocationTargetException
,
IllegalAccessException
{
loadText
(
"fun test() = _array(2, 4); fun <T> _array(vararg elements : T) = elements"
);
System
.
out
.
println
(
generateToText
());
final
Method
main
=
generateFunction
();
Object
res
=
main
.
invoke
(
null
,
new
Object
[]{});
assertTrue
(((
Integer
[])
res
).
length
==
2
);
assertTrue
(((
Integer
[])
res
)[
0
].
equals
(
2
));
assertTrue
(((
Integer
[])
res
)[
1
].
equals
(
4
));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录