- call multifile class members (compiling against binaries)
- inline multifile class members
This commit is contained in:
@@ -88,25 +88,29 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
for (PackageCodegen codegen : packageCodegens) {
|
||||
codegen.done();
|
||||
}
|
||||
for (MultifileClassCodegen codegen : multifileClass2codegen.values()) {
|
||||
Collection<MultifileClassCodegen> multifileClassCodegens = multifileClass2codegen.values();
|
||||
for (MultifileClassCodegen codegen : multifileClassCodegens) {
|
||||
codegen.done();
|
||||
}
|
||||
// TODO module mappings for multifile classes
|
||||
writeModuleMappings(packageCodegens);
|
||||
writeModuleMappings(packageCodegens, multifileClassCodegens);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeModuleMappings(Collection<PackageCodegen> values) {
|
||||
private void writeModuleMappings(
|
||||
@NotNull Collection<PackageCodegen> packageCodegens,
|
||||
@NotNull Collection<MultifileClassCodegen> multifileClassCodegens
|
||||
) {
|
||||
final JvmPackageTable.PackageTable.Builder builder = JvmPackageTable.PackageTable.newBuilder();
|
||||
String outputFilePath = getMappingFileName(state.getModuleName());
|
||||
|
||||
List<PackageParts> parts = ContainerUtil.newArrayList();
|
||||
List<PackageParts> parts = collectGeneratedPackageParts(packageCodegens, multifileClassCodegens);
|
||||
|
||||
Set<File> sourceFiles = new HashSet<File>();
|
||||
|
||||
for (PackageCodegen codegen : values) {
|
||||
parts.add(codegen.getPackageParts());
|
||||
|
||||
// TODO extract common logic
|
||||
// TODO extract common logic
|
||||
for (PackageCodegen codegen : packageCodegens) {
|
||||
sourceFiles.addAll(toIoFilesIgnoringNonPhysical(PackagePartClassUtils.getFilesWithCallables(codegen.getFiles())));
|
||||
}
|
||||
for (MultifileClassCodegen codegen : multifileClassCodegens) {
|
||||
sourceFiles.addAll(toIoFilesIgnoringNonPhysical(PackagePartClassUtils.getFilesWithCallables(codegen.getFiles())));
|
||||
}
|
||||
|
||||
@@ -152,6 +156,34 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<PackageParts> collectGeneratedPackageParts(
|
||||
@NotNull Collection<PackageCodegen> packageCodegens,
|
||||
@NotNull Collection<MultifileClassCodegen> multifileClassCodegens
|
||||
) {
|
||||
Map<String, PackageParts> mergedPartsByPackageName = new LinkedHashMap<String, PackageParts>();
|
||||
|
||||
for (PackageCodegen packageCodegen : packageCodegens) {
|
||||
PackageParts generatedParts = packageCodegen.getPackageParts();
|
||||
PackageParts premergedParts = new PackageParts(generatedParts.getPackageFqName());
|
||||
mergedPartsByPackageName.put(generatedParts.getPackageFqName(), premergedParts);
|
||||
premergedParts.getParts().addAll(generatedParts.getParts());
|
||||
}
|
||||
|
||||
for (MultifileClassCodegen multifileClassCodegen : multifileClassCodegens) {
|
||||
PackageParts multifileClassParts = multifileClassCodegen.getPackageParts();
|
||||
PackageParts premergedParts = mergedPartsByPackageName.get(multifileClassParts.getPackageFqName());
|
||||
if (premergedParts == null) {
|
||||
premergedParts = new PackageParts(multifileClassParts.getPackageFqName());
|
||||
mergedPartsByPackageName.put(multifileClassParts.getPackageFqName(), premergedParts);
|
||||
}
|
||||
premergedParts.getParts().addAll(multifileClassParts.getParts());
|
||||
}
|
||||
|
||||
List<PackageParts> result = new ArrayList<PackageParts>();
|
||||
result.addAll(mergedPartsByPackageName.values());
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<OutputFile> asList() {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageParts
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackageFragmentProvider
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
|
||||
@@ -41,7 +42,7 @@ import java.util.*
|
||||
|
||||
public class MultifileClassCodegen(
|
||||
private val state: GenerationState,
|
||||
private val files: Collection<JetFile>,
|
||||
public val files: Collection<JetFile>,
|
||||
private val facadeFqName: FqName
|
||||
) {
|
||||
private val facadeClassType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(facadeFqName)
|
||||
@@ -50,6 +51,8 @@ public class MultifileClassCodegen(
|
||||
|
||||
private val compiledPackageFragment = getCompiledPackageFragment(facadeFqName.parent(), state)
|
||||
|
||||
public val packageParts = PackageParts(facadeFqName.parent().asString())
|
||||
|
||||
// TODO incremental compilation support
|
||||
// TODO previouslyCompiledCallables
|
||||
// We can do this (probably without 'compiledPackageFragment') after modifications to part codegen.
|
||||
@@ -159,8 +162,8 @@ public class MultifileClassCodegen(
|
||||
|
||||
partFqNames.add(partClassInfo.fileClassFqName)
|
||||
|
||||
// val name = partType.internalName
|
||||
// packageParts.parts.add(name.substring(name.lastIndexOf('/') + 1))
|
||||
val name = partType.internalName
|
||||
packageParts.parts.add(name.substring(name.lastIndexOf('/') + 1))
|
||||
|
||||
val builder = state.factory.newVisitor(MultifileClassPart(file, packageFragment, facadeFqName), partType, file)
|
||||
|
||||
|
||||
@@ -110,9 +110,9 @@ public class PropertyCodegen {
|
||||
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
|
||||
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
|
||||
|
||||
Type implClassType = CodegenContextUtil.getImplementationOwnerClassType(context);
|
||||
if (implClassType != null) {
|
||||
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, shortNameByAsmType(implClassType));
|
||||
String implClassName = CodegenContextUtil.getImplementationClassShortName(context);
|
||||
if (implClassName != null) {
|
||||
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, implClassName);
|
||||
}
|
||||
|
||||
if (CodegenContextUtil.isImplClassOwner(context)) {
|
||||
|
||||
@@ -23,12 +23,9 @@ import org.jetbrains.org.objectweb.asm.Type
|
||||
public object CodegenContextUtil {
|
||||
public @JvmStatic fun getImplementationOwnerClassType(owner: CodegenContext<*>): Type? =
|
||||
when (owner) {
|
||||
is DelegatingFacadeContext ->
|
||||
owner.delegateToClassType
|
||||
is DelegatingToPartContext ->
|
||||
owner.implementationOwnerClassType
|
||||
else ->
|
||||
null
|
||||
is DelegatingFacadeContext -> owner.delegateToClassType
|
||||
is DelegatingToPartContext -> owner.implementationOwnerClassType
|
||||
else -> null
|
||||
}
|
||||
|
||||
public @JvmStatic fun getImplementationClassShortName(owner: CodegenContext<*>): String? =
|
||||
|
||||
+1
-1
@@ -21,5 +21,5 @@ import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
public interface DelegatingFacadeContext {
|
||||
@Nullable
|
||||
public Type getDelegateToClassType();
|
||||
Type getDelegateToClassType();
|
||||
}
|
||||
|
||||
@@ -30,16 +30,13 @@ import org.jetbrains.kotlin.codegen.binding.PsiCodegenPredictor;
|
||||
import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
||||
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeDeclarationsPackage;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope;
|
||||
import org.jetbrains.kotlin.name.*;
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
@@ -59,6 +56,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedType;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
@@ -142,10 +140,7 @@ public class JetTypeMapper {
|
||||
|
||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||
if (container instanceof PackageFragmentDescriptor) {
|
||||
boolean effectiveInsideModule = isInsideModule && !NativeDeclarationsPackage.hasNativeAnnotation(descriptor);
|
||||
return Type.getObjectType(internalNameForPackage(
|
||||
(CallableMemberDescriptor) descriptor
|
||||
));
|
||||
return Type.getObjectType(internalNameForPackage((CallableMemberDescriptor) descriptor));
|
||||
}
|
||||
else if (container instanceof ClassDescriptor) {
|
||||
return mapClass((ClassDescriptor) container);
|
||||
@@ -174,9 +169,19 @@ public class JetTypeMapper {
|
||||
CallableMemberDescriptor directMember = getDirectMember(descriptor);
|
||||
|
||||
if (directMember instanceof DeserializedCallableMemberDescriptor) {
|
||||
// TODO private vs public
|
||||
FqName packagePartFqName = PackagePartClassUtils.getPackagePartFqName((DeserializedCallableMemberDescriptor) directMember);
|
||||
return internalNameByFqNameWithoutInnerClasses(packagePartFqName);
|
||||
Name implClassName = JvmFileClassUtil.getImplClassName((DeserializedCallableMemberDescriptor) directMember);
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof PackageFragmentDescriptor) {
|
||||
PackageFragmentDescriptor packageFragmentDescriptor = (PackageFragmentDescriptor) containingDeclaration;
|
||||
JetScope scope = packageFragmentDescriptor.getMemberScope();
|
||||
if (scope instanceof LazyJavaPackageScope) {
|
||||
String facadeShortName = ((LazyJavaPackageScope) scope).getFacadeSimpleNameForPartSimpleName(implClassName.asString());
|
||||
if (facadeShortName != null) {
|
||||
FqName facadeFqName = packageFragmentDescriptor.getFqName().child(Name.identifier(facadeShortName));
|
||||
return internalNameByFqNameWithoutInnerClasses(facadeFqName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unreachable state");
|
||||
|
||||
Reference in New Issue
Block a user