codegen: fix calls to global functions when loaded from java descriptors
This commit is contained in:
@@ -35,7 +35,7 @@ public class ClassFileFactory {
|
||||
String fqName = JetPsiUtil.getFQName(file);
|
||||
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
||||
if (codegen == null) {
|
||||
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassName(fqName) + ".class");
|
||||
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassName(fqName, true) + ".class");
|
||||
codegen = new NamespaceCodegen(builder, fqName, state, file.getContainingFile());
|
||||
ns2codegen.put(fqName, codegen);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public abstract class CodegenContext {
|
||||
while(!(descriptor instanceof NamespaceDescriptor)) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
}
|
||||
return NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(descriptor));
|
||||
return NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(descriptor), true);
|
||||
}
|
||||
|
||||
public OwnerKind getContextKind() {
|
||||
|
||||
@@ -310,7 +310,7 @@ public class FunctionCodegen {
|
||||
int flags = ACC_PUBLIC; // TODO.
|
||||
|
||||
String ownerInternalName = contextClass instanceof NamespaceDescriptor ?
|
||||
NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(contextClass)) :
|
||||
NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(contextClass), true) :
|
||||
state.getTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName();
|
||||
|
||||
String descriptor = jvmSignature.getDescriptor().replace(")","I)");
|
||||
|
||||
@@ -92,8 +92,11 @@ public class JetTypeMapper {
|
||||
public String getOwner(DeclarationDescriptor descriptor, OwnerKind kind) {
|
||||
String owner;
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName((NamespaceDescriptor) containingDeclaration));
|
||||
if (containingDeclaration instanceof JavaNamespaceDescriptor) {
|
||||
JavaNamespaceDescriptor javaNamespaceDescriptor = (JavaNamespaceDescriptor) containingDeclaration;
|
||||
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName((NamespaceDescriptor) containingDeclaration), javaNamespaceDescriptor.isNamespace());
|
||||
} else if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName((NamespaceDescriptor) containingDeclaration), true);
|
||||
}
|
||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
@@ -365,7 +368,11 @@ public class JetTypeMapper {
|
||||
ClassDescriptor thisClass;
|
||||
if (functionParent instanceof NamespaceDescriptor) {
|
||||
assert !superCall;
|
||||
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(functionParent));
|
||||
boolean namespace = true;
|
||||
if (functionParent instanceof JavaNamespaceDescriptor) {
|
||||
namespace = ((JavaNamespaceDescriptor) functionParent).isNamespace();
|
||||
}
|
||||
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(functionParent), namespace);
|
||||
invokeOpcode = INVOKESTATIC;
|
||||
thisClass = null;
|
||||
}
|
||||
@@ -711,7 +718,7 @@ public class JetTypeMapper {
|
||||
|
||||
String baseName;
|
||||
if (container instanceof JetFile) {
|
||||
baseName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(((JetFile) container)));
|
||||
baseName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(((JetFile) container)), true);
|
||||
}
|
||||
else {
|
||||
ClassDescriptor aClass = bindingContext.get(BindingContext.CLASS, container);
|
||||
|
||||
@@ -34,7 +34,7 @@ public class NamespaceCodegen {
|
||||
|
||||
v.defineClass(sourceFile, V1_6,
|
||||
ACC_PUBLIC/*|ACC_SUPER*/,
|
||||
getJVMClassName(fqName),
|
||||
getJVMClassName(fqName, true),
|
||||
null,
|
||||
//"jet/lang/Namespace",
|
||||
"java/lang/Object",
|
||||
@@ -118,7 +118,7 @@ public class NamespaceCodegen {
|
||||
|
||||
private void generateTypeInfoFields(JetFile file, CodegenContext context) {
|
||||
if(context.typeInfoConstants != null) {
|
||||
String jvmClassName = getJVMClassName(JetPsiUtil.getFQName(file));
|
||||
String jvmClassName = getJVMClassName(JetPsiUtil.getFQName(file), true);
|
||||
for(int index = 0; index != context.typeInfoConstantsCount; index++) {
|
||||
JetType type = context.reverseTypeInfoConstants.get(index);
|
||||
String fieldName = "$typeInfoCache$" + index;
|
||||
@@ -205,14 +205,20 @@ public class NamespaceCodegen {
|
||||
v.done();
|
||||
}
|
||||
|
||||
public static String getJVMClassName(String fqName) {
|
||||
/**
|
||||
* @param namespace true for "namespace" suffix
|
||||
*/
|
||||
public static String getJVMClassName(String fqName, boolean namespace) {
|
||||
if (fqName.length() == 0) {
|
||||
return JvmAbi.PACKAGE_CLASS;
|
||||
}
|
||||
|
||||
String name = fqName.replace('.', '/') + "/" + JvmAbi.PACKAGE_CLASS;
|
||||
String name = fqName.replace('.', '/');
|
||||
if(name.startsWith("<java_root>")) {
|
||||
name = name.substring("<java_root>".length() + 1, name.length() - 1 - JvmAbi.PACKAGE_CLASS.length());
|
||||
name = name.substring("<java_root>".length() + 1, name.length());
|
||||
}
|
||||
if (namespace) {
|
||||
name += "/" + JvmAbi.PACKAGE_CLASS;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user