Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
3befa8ad
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,发现更多精彩内容 >>
提交
3befa8ad
编写于
9月 10, 2011
作者:
A
Alex Tkachman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code polishing
上级
38e81ed2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
98 deletion
+48
-98
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
...kend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+3
-15
compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
.../backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
+45
-83
未找到文件。
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
3befa8ad
...
...
@@ -49,18 +49,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
private
int
myLastLineNumber
=
-
1
;
private
static
final
String
[]
PRIMITIVE_TYPE_INFO_FIELDS
=
{
null
,
"BOOL_TYPE_INFO"
,
"CHAR_TYPE_INFO"
,
"BYTE_TYPE_INFO"
,
"SHORT_TYPE_INFO"
,
"INT_TYPE_INFO"
,
"FLOAT_TYPE_INFO"
,
"LONG_TYPE_INFO"
,
"DOUBLE_TYPE_INFO"
};
private
final
InstructionAdapterEx
v
;
private
final
FrameMap
myMap
;
private
final
JetTypeMapper
typeMapper
;
...
...
@@ -1175,7 +1163,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if
(
isIntRangeExpr
(
expression
.
getRight
()))
{
JetBinaryExpression
rangeExpression
=
(
JetBinaryExpression
)
expression
.
getRight
();
boolean
inverted
=
expression
.
getOperationReference
().
getReferencedNameElementType
()
==
JetTokens
.
NOT_IN
;
getInInt
Test
(
leftValue
,
rangeExpression
,
inverted
);
getInInt
Range
(
leftValue
,
rangeExpression
,
inverted
);
}
else
{
leftValue
.
put
(
JetTypeMapper
.
TYPE_OBJECT
,
v
);
...
...
@@ -1187,7 +1175,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
return
StackValue
.
onStack
(
Type
.
BOOLEAN_TYPE
);
}
private
void
getInInt
Test
(
StackValue
leftValue
,
JetBinaryExpression
rangeExpression
,
boolean
inverted
)
{
private
void
getInInt
Range
(
StackValue
leftValue
,
JetBinaryExpression
rangeExpression
,
boolean
inverted
)
{
v
.
iconst
(
1
);
// 1
leftValue
.
put
(
Type
.
INT_TYPE
,
v
);
...
...
@@ -2065,7 +2053,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
JetWhenConditionInRange
conditionInRange
=
(
JetWhenConditionInRange
)
condition
;
JetExpression
rangeExpression
=
conditionInRange
.
getRangeExpression
();
if
(
isIntRangeExpr
(
rangeExpression
))
{
getInInt
Test
(
new
StackValue
.
Local
(
subjectLocal
,
subjectType
),
(
JetBinaryExpression
)
rangeExpression
,
conditionInRange
.
getOperationReference
().
getReferencedNameElementType
()
==
JetTokens
.
NOT_IN
);
getInInt
Range
(
new
StackValue
.
Local
(
subjectLocal
,
subjectType
),
(
JetBinaryExpression
)
rangeExpression
,
conditionInRange
.
getOperationReference
().
getReferencedNameElementType
()
==
JetTokens
.
NOT_IN
);
}
else
{
FunctionDescriptor
op
=
(
FunctionDescriptor
)
bindingContext
.
get
(
BindingContext
.
REFERENCE_TARGET
,
conditionInRange
.
getOperationReference
());
...
...
compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
浏览文件 @
3befa8ad
...
...
@@ -44,9 +44,12 @@ public class JetTypeMapper {
private
final
Map
<
JetExpression
,
String
>
classNamesForAnonymousClasses
=
new
HashMap
<
JetExpression
,
String
>();
private
final
Map
<
String
,
Integer
>
anonymousSubclassesCount
=
new
HashMap
<
String
,
Integer
>();
private
final
HashMap
<
JetType
,
String
>
knowTypes
=
new
HashMap
<
JetType
,
String
>();
public
JetTypeMapper
(
JetStandardLibrary
standardLibrary
,
BindingContext
bindingContext
)
{
this
.
standardLibrary
=
standardLibrary
;
this
.
bindingContext
=
bindingContext
;
initKnownTypes
();
}
static
String
jvmName
(
PsiClass
psiClass
)
{
...
...
@@ -153,6 +156,7 @@ public class JetTypeMapper {
}
else
{
needsReceiver
=
true
;
assert
containingClass
!=
null
;
if
(
containingClass
.
isInterface
())
{
opcode
=
Opcodes
.
INVOKEINTERFACE
;
}
...
...
@@ -181,7 +185,7 @@ public class JetTypeMapper {
final
ClassDescriptor
containingClassDescriptor
=
bindingContext
.
get
(
BindingContext
.
CLASS
,
containingClass
);
return
jvmName
(
containingClassDescriptor
,
OwnerKind
.
INTERFACE
)
+
"$$ClassObj"
;
}
String
className
=
classNamesForAnonymousClasses
.
get
(
declaration
);
@SuppressWarnings
(
"SuspiciousMethodCalls"
)
String
className
=
classNamesForAnonymousClasses
.
get
(
declaration
);
if
(
className
==
null
)
{
throw
new
UnsupportedOperationException
(
"Unexpected forward reference to anonymous class "
+
declaration
);
}
...
...
@@ -238,10 +242,6 @@ public class JetTypeMapper {
return
Type
.
getType
(
"L"
+
jvmNameForImplementation
(
classDescriptor
)
+
";"
);
}
static
Type
jetDelegatingImplementationType
(
ClassDescriptor
classDescriptor
)
{
return
Type
.
getType
(
"L"
+
jvmNameForDelegatingImplementation
(
classDescriptor
)
+
";"
);
}
public
static
String
jvmName
(
JetNamespace
namespace
)
{
return
NamespaceCodegen
.
getJVMClassName
(
namespace
.
getFQName
());
}
...
...
@@ -272,8 +272,11 @@ public class JetTypeMapper {
if
(
kind
instanceof
OwnerKind
.
DelegateKind
)
{
kind
=
OwnerKind
.
INTERFACE
;
}
else
if
(
classDescriptor
.
getKind
()
==
ClassKind
.
OBJECT
)
{
kind
=
OwnerKind
.
IMPLEMENTATION
;
else
{
assert
classDescriptor
!=
null
;
if
(
classDescriptor
.
getKind
()
==
ClassKind
.
OBJECT
)
{
kind
=
OwnerKind
.
IMPLEMENTATION
;
}
}
owner
=
jvmName
(
classDescriptor
,
kind
);
}
...
...
@@ -378,7 +381,7 @@ public class JetTypeMapper {
throw
new
UnsupportedOperationException
(
"Unknown type "
+
jetType
);
}
public
Type
boxType
(
Type
asmType
)
{
public
static
Type
boxType
(
Type
asmType
)
{
switch
(
asmType
.
getSort
())
{
case
Type
.
VOID
:
return
Type
.
VOID_TYPE
;
...
...
@@ -404,12 +407,6 @@ public class JetTypeMapper {
}
private
static
Type
getBoxedType
(
final
Type
type
)
{
switch
(
type
.
getSort
())
{
}
return
type
;
}
private
Method
mapSignature
(
JetNamedFunction
f
,
List
<
Type
>
valueParameterTypes
)
{
final
JetTypeReference
receiverTypeRef
=
f
.
getReceiverTypeRef
();
final
JetType
receiverType
=
receiverTypeRef
==
null
?
null
:
bindingContext
.
get
(
BindingContext
.
TYPE
,
receiverTypeRef
);
...
...
@@ -423,13 +420,14 @@ public class JetTypeMapper {
valueParameterTypes
.
add
(
type
);
parameterTypes
.
add
(
type
);
}
for
(
JetTypeParameter
p:
f
.
getTypeParameters
()
)
{
for
(
int
n
=
f
.
getTypeParameters
().
size
();
n
>
0
;
n
--
)
{
parameterTypes
.
add
(
TYPE_TYPEINFO
);
}
final
JetTypeReference
returnTypeRef
=
f
.
getReturnTypeRef
();
Type
returnType
;
if
(
returnTypeRef
==
null
)
{
final
FunctionDescriptor
functionDescriptor
=
bindingContext
.
get
(
BindingContext
.
FUNCTION
,
f
);
assert
functionDescriptor
!=
null
;
final
JetType
type
=
functionDescriptor
.
getReturnType
();
returnType
=
mapReturnType
(
type
);
}
...
...
@@ -448,6 +446,7 @@ public class JetTypeMapper {
}
JetNamedFunction
f
=
(
JetNamedFunction
)
declaration
;
final
FunctionDescriptor
functionDescriptor
=
bindingContext
.
get
(
BindingContext
.
FUNCTION
,
f
);
assert
functionDescriptor
!=
null
;
final
DeclarationDescriptor
functionParent
=
functionDescriptor
.
getContainingDeclaration
();
final
List
<
Type
>
valueParameterTypes
=
new
ArrayList
<
Type
>();
Method
descriptor
=
mapSignature
(
f
,
valueParameterTypes
);
...
...
@@ -521,7 +520,7 @@ public class JetTypeMapper {
answer
.
append
(
mapType
(
type
).
getDescriptor
());
// TODO: type parameter references!
}
private
void
appendTypeParameterSignature
(
StringBuffer
answer
,
TypeParameterDescriptor
p
)
{
private
static
void
appendTypeParameterSignature
(
StringBuffer
answer
,
TypeParameterDescriptor
p
)
{
answer
.
append
(
p
.
getName
());
// TODO: BOUND!
}
...
...
@@ -539,7 +538,7 @@ public class JetTypeMapper {
return
new
Method
(
PropertyCodegen
.
setterName
(
descriptor
.
getName
()),
Type
.
VOID_TYPE
,
new
Type
[]
{
paramType
});
}
private
Method
mapConstructorSignature
(
ConstructorDescriptor
descriptor
,
OwnerKind
kind
,
List
<
Type
>
valueParameterTypes
)
{
private
Method
mapConstructorSignature
(
ConstructorDescriptor
descriptor
,
List
<
Type
>
valueParameterTypes
)
{
List
<
ValueParameterDescriptor
>
parameters
=
descriptor
.
getOriginal
().
getValueParameters
();
List
<
Type
>
parameterTypes
=
new
ArrayList
<
Type
>();
ClassDescriptor
classDescriptor
=
descriptor
.
getContainingDeclaration
();
...
...
@@ -554,7 +553,7 @@ public class JetTypeMapper {
}
List
<
TypeParameterDescriptor
>
typeParameters
=
classDescriptor
.
getTypeConstructor
().
getParameters
();
for
(
TypeParameterDescriptor
typeParameter
:
typeParameters
)
{
for
(
int
n
=
typeParameters
.
size
();
n
>
0
;
n
--
)
{
parameterTypes
.
add
(
TYPE_TYPEINFO
);
}
...
...
@@ -563,7 +562,7 @@ public class JetTypeMapper {
public
CallableMethod
mapToCallableMethod
(
ConstructorDescriptor
descriptor
,
OwnerKind
kind
)
{
List
<
Type
>
valueParameterTypes
=
new
ArrayList
<
Type
>();
final
Method
method
=
mapConstructorSignature
(
descriptor
,
kind
,
valueParameterTypes
);
final
Method
method
=
mapConstructorSignature
(
descriptor
,
valueParameterTypes
);
String
owner
=
jvmName
(
descriptor
.
getContainingDeclaration
(),
kind
);
final
CallableMethod
result
=
new
CallableMethod
(
owner
,
method
,
Opcodes
.
INVOKESPECIAL
,
valueParameterTypes
);
result
.
setAcceptsTypeArguments
(
true
);
...
...
@@ -590,15 +589,15 @@ public class JetTypeMapper {
return
name
;
}
JetNamedDeclaration
container
=
PsiTreeUtil
.
getParentOfType
(
expression
,
JetNamespace
.
class
,
JetClass
.
class
,
JetObjectDeclaration
.
class
);
@SuppressWarnings
(
"unchecked"
)
JetNamedDeclaration
container
=
PsiTreeUtil
.
getParentOfType
(
expression
,
JetNamespace
.
class
,
JetClass
.
class
,
JetObjectDeclaration
.
class
);
String
baseName
;
if
(
container
instanceof
JetNamespace
)
{
baseName
=
NamespaceCodegen
.
getJVMClassName
(((
JetNamespace
)
container
).
getFQName
());
}
else
{
ClassDescriptor
aClass
=
bindingContext
.
get
(
BindingContext
.
CLASS
,
(
JetClassOrObject
)
container
);
baseName
=
JetTypeMapper
.
jvmNameForInterface
(
aClass
);
ClassDescriptor
aClass
=
bindingContext
.
get
(
BindingContext
.
CLASS
,
container
);
baseName
=
jvmNameForInterface
(
aClass
);
}
Integer
count
=
anonymousSubclassesCount
.
get
(
baseName
);
...
...
@@ -621,67 +620,30 @@ public class JetTypeMapper {
return
result
;
}
private
void
initKnownTypes
()
{
knowTypes
.
put
(
standardLibrary
.
getIntType
(),
"INT_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableIntType
(),
"NULLABLE_INT_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getLongType
(),
"LONG_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableLongType
(),
"NULLABLE_LONG_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getShortType
(),
"SHORT_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableShortType
(),
"NULLABLE_SHORT_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getByteType
(),
"BYTE_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableByteType
(),
"NULLABLE_BYTE_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getCharType
(),
"CHAR_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableCharType
(),
"NULLABLE_CHAR_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getFloatType
(),
"FLOAT_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableFloatType
(),
"NULLABLE_FLOAT_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getDoubleType
(),
"DOUBLE_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableDoubleType
(),
"NULLABLE_DOUBLE_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getBooleanType
(),
"BOOLEAN_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableBooleanType
(),
"NULLABLE_BOOLEAN_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getStringType
(),
"STRING_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableStringType
(),
"NULLABLE_STRING_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getTuple0Type
(),
"TUPLE0_TYPE_INFO"
);
knowTypes
.
put
(
standardLibrary
.
getNullableTuple0Type
(),
"NULLABLE_TUPLE0_TYPE_INFO"
);
}
public
String
isKnownTypeInfo
(
JetType
jetType
)
{
if
(
jetType
.
equals
(
standardLibrary
.
getIntType
()))
{
return
"INT_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableIntType
()))
{
return
"NULLABLE_INT_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getLongType
()))
{
return
"LONG_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableLongType
()))
{
return
"NULLABLE_LONG_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getShortType
()))
{
return
"SHORT_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableShortType
()))
{
return
"NULLABLE_SHORT_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getByteType
()))
{
return
"BYTE_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableByteType
()))
{
return
"NULLABLE_BYTE_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getCharType
()))
{
return
"CHAR_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableCharType
()))
{
return
"NULLABLE_CHAR_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getFloatType
()))
{
return
"FLOAT_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableFloatType
()))
{
return
"NULLABLE_FLOAT_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getDoubleType
()))
{
return
"DOUBLE_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableDoubleType
()))
{
return
"NULLABLE_DOUBLE_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getBooleanType
()))
{
return
"BOOLEAN_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableBooleanType
()))
{
return
"NULLABLE_BOOLEAN_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getStringType
()))
{
return
"STRING_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableStringType
()))
{
return
"NULLABLE_STRING_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getTuple0Type
()))
{
return
"TUPLE0_TYPE_INFO"
;
}
if
(
jetType
.
equals
(
standardLibrary
.
getNullableTuple0Type
()))
{
return
"NULLABLE_TUPLE0_TYPE_INFO"
;
}
return
null
;
return
knowTypes
.
get
(
jetType
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录