generate static field accesses
This commit is contained in:
@@ -250,12 +250,27 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visitSimpleNameExpression(JetSimpleNameExpression expression) {
|
public void visitSimpleNameExpression(JetSimpleNameExpression expression) {
|
||||||
final DeclarationDescriptor descriptor = bindingContext.resolveReferenceExpression(expression);
|
final DeclarationDescriptor descriptor = bindingContext.resolveReferenceExpression(expression);
|
||||||
int index = myMap.getIndex(descriptor);
|
PsiElement declaration = bindingContext.getDeclarationPsiElement(descriptor);
|
||||||
if (index >= 0) {
|
if (declaration instanceof PsiField) {
|
||||||
v.visitVarInsn(Opcodes.ALOAD, index);
|
PsiField psiField = (PsiField) declaration;
|
||||||
|
if (psiField.hasModifierProperty(PsiModifier.STATIC)) {
|
||||||
|
v.visitFieldInsn(Opcodes.GETSTATIC,
|
||||||
|
jvmName(psiField.getContainingClass()),
|
||||||
|
psiField.getName(),
|
||||||
|
psiTypeToAsm(psiField.getType()).getDescriptor());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new UnsupportedOperationException("don't know how to generate field reference " + descriptor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("don't know how to generate reference " + descriptor);
|
int index = myMap.getIndex(descriptor);
|
||||||
|
if (index >= 0) {
|
||||||
|
v.visitVarInsn(Opcodes.ALOAD, index);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new UnsupportedOperationException("don't know how to generate reference " + descriptor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,8 +290,10 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
if (declarationPsiElement instanceof PsiMethod) {
|
if (declarationPsiElement instanceof PsiMethod) {
|
||||||
PsiMethod method = (PsiMethod) declarationPsiElement;
|
PsiMethod method = (PsiMethod) declarationPsiElement;
|
||||||
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||||
PsiClass containingClass = method.getContainingClass();
|
v.visitMethodInsn(Opcodes.INVOKESTATIC,
|
||||||
v.visitMethodInsn(Opcodes.INVOKESTATIC, jvmName(containingClass), method.getName(), getMethodDescriptor(method));
|
jvmName(method.getContainingClass()),
|
||||||
|
method.getName(),
|
||||||
|
getMethodDescriptor(method));
|
||||||
boxIfNeeded(method.getReturnType());
|
boxIfNeeded(method.getReturnType());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
fun f() : Any { return System.out; }
|
||||||
@@ -88,6 +88,14 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
|||||||
assertEquals(returnValue, System.identityHashCode(o));
|
assertEquals(returnValue, System.identityHashCode(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSystemOut() throws Exception {
|
||||||
|
loadFile("systemOut.jet");
|
||||||
|
final Class aClass = generateToClass();
|
||||||
|
final Method main = firstMethod(aClass);
|
||||||
|
final Object returnValue = main.invoke(null);
|
||||||
|
assertEquals(returnValue, System.out);
|
||||||
|
}
|
||||||
|
|
||||||
private void loadFile(final String name) {
|
private void loadFile(final String name) {
|
||||||
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user