Add hack to avoid stub ast mismatch when decompiling libraries built with M9 compiler
This commit is contained in:
+1
-1
@@ -36,7 +36,7 @@ import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import java.io.IOException;
|
||||
|
||||
public class JetFileElementType extends IStubFileElementType<KotlinFileStub> {
|
||||
public static final int STUB_VERSION = 33;
|
||||
public static final int STUB_VERSION = 34;
|
||||
|
||||
public JetFileElementType() {
|
||||
super("jet.FILE", JetLanguage.INSTANCE);
|
||||
|
||||
@@ -25,6 +25,7 @@ public final class JvmAbi {
|
||||
* This constant is used to identify binary format (class file) versions
|
||||
* If you change class file metadata format and/or naming conventions, please increase this number
|
||||
*/
|
||||
//TODO: remove clsStubBuilding#sortCallableStubs and this comment when abi version is increased to 20
|
||||
public static final int VERSION = 19;
|
||||
|
||||
public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl";
|
||||
|
||||
+1
-1
@@ -208,7 +208,7 @@ private class ClassClsStubBuilder(
|
||||
|
||||
private fun createCallableMemberStubs(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
val container = ProtoContainer(classProto, null)
|
||||
for (callableProto in classProto.getMemberList()) {
|
||||
for (callableProto in sortCallableStubs(classProto.getMemberList())) {
|
||||
createCallableStub(classBody, callableProto, c, container)
|
||||
}
|
||||
}
|
||||
|
||||
+31
-1
@@ -44,6 +44,7 @@ import org.jetbrains.jet.lang.psi.JetTypeReference
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotatedCallableKind
|
||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.CallableKind
|
||||
import java.util.ArrayList
|
||||
|
||||
fun createTopLevelClassStub(classId: ClassId, classProto: ProtoBuf.Class, context: ClsStubBuilderContext): KotlinFileStubImpl {
|
||||
val fileStub = createFileStub(classId.getPackageFqName())
|
||||
@@ -58,7 +59,7 @@ fun createPackageFacadeFileStub(
|
||||
): KotlinFileStubImpl {
|
||||
val fileStub = createFileStub(packageFqName)
|
||||
val container = ProtoContainer(null, packageFqName)
|
||||
for (callableProto in packageProto.getMemberList()) {
|
||||
for (callableProto in sortCallableStubs(packageProto.getMemberList())) {
|
||||
createCallableStub(fileStub, callableProto, c, container)
|
||||
}
|
||||
return fileStub
|
||||
@@ -202,3 +203,32 @@ val ProtoBuf.Callable.annotatedCallableKind: AnnotatedCallableKind
|
||||
fun Name.ref() = StringRef.fromString(this.asString())
|
||||
|
||||
fun FqName.ref() = StringRef.fromString(this.asString())
|
||||
|
||||
//NOTE: sorting should be removed when stub version is increased next time
|
||||
// this workaround is relevant for abi version 19
|
||||
// this is needed to avoid building stubs in wrong order for compilers built before 77dd027d690c0fe48abccdea04bfeab871c7c6de was introduced
|
||||
fun sortCallableStubs(unordered: List<ProtoBuf.Callable>): List<ProtoBuf.Callable> {
|
||||
val extensionProperties = arrayListOf<ProtoBuf.Callable>()
|
||||
val nonExtensionProperties = arrayListOf<ProtoBuf.Callable>()
|
||||
val extensionFunctions = arrayListOf<ProtoBuf.Callable>()
|
||||
val nonExtensionFunctions = arrayListOf<ProtoBuf.Callable>()
|
||||
for (callable in unordered) {
|
||||
val isExtension = callable.hasReceiverType()
|
||||
when (Flags.CALLABLE_KIND[callable.getFlags()]) {
|
||||
CallableKind.FUN -> {
|
||||
if (isExtension) extensionFunctions.add(callable) else nonExtensionFunctions.add(callable)
|
||||
}
|
||||
CallableKind.VAL, CallableKind.VAR -> {
|
||||
if (isExtension) extensionProperties.add(callable) else nonExtensionProperties.add(callable)
|
||||
}
|
||||
}
|
||||
}
|
||||
val result = ArrayList<ProtoBuf.Callable>(
|
||||
extensionProperties.size() + nonExtensionProperties.size() + extensionFunctions.size() + nonExtensionFunctions.size()
|
||||
)
|
||||
result.addAll(nonExtensionProperties)
|
||||
result.addAll(extensionProperties)
|
||||
result.addAll(nonExtensionFunctions)
|
||||
result.addAll(extensionFunctions)
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user