Initial internal member mangling
This commit is contained in:
+1
-1
@@ -47,7 +47,7 @@ public class AccessorForConstructorDescriptor(
|
||||
copyValueParameters(calleeDescriptor),
|
||||
calleeDescriptor.returnType,
|
||||
Modality.FINAL,
|
||||
Visibilities.INTERNAL,
|
||||
Visibilities.LOCAL,
|
||||
false,
|
||||
false
|
||||
)
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public class AccessorForFunctionDescriptor extends AbstractAccessorForFunctionDe
|
||||
copyValueParameters(descriptor),
|
||||
descriptor.getReturnType(),
|
||||
Modality.FINAL,
|
||||
Visibilities.INTERNAL,
|
||||
Visibilities.LOCAL,
|
||||
descriptor.isOperator(),
|
||||
descriptor.isInfix());
|
||||
}
|
||||
|
||||
@@ -2234,14 +2234,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
fieldName = ((FieldOwnerContext) backingFieldContext).getFieldName(propertyDescriptor, isDelegatedProperty);
|
||||
}
|
||||
else {
|
||||
Name name;
|
||||
if (propertyDescriptor instanceof AccessorForPropertyDescriptor) {
|
||||
name = ((AccessorForPropertyDescriptor) propertyDescriptor).getCalleeDescriptor().getName();
|
||||
}
|
||||
else {
|
||||
name = propertyDescriptor.getName();
|
||||
}
|
||||
fieldName = JvmAbi.getDefaultFieldNameForProperty(name, isDelegatedProperty);
|
||||
fieldName = JetTypeMapper.mapDefaultFieldName(propertyDescriptor, isDelegatedProperty);
|
||||
}
|
||||
|
||||
return StackValue.property(propertyDescriptor, backingFieldOwner,
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleMapping;
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityUtilsKt;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.JetFunction;
|
||||
@@ -233,4 +234,9 @@ public class JvmCodegenUtil {
|
||||
// TODO: drop after some time
|
||||
av.visit(JvmAnnotationNames.OLD_ABI_VERSION_FIELD_NAME, JvmAbi.VERSION.getMinor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String sanitizeAsJavaIdentifier(@NotNull String str) {
|
||||
return PackagePartClassUtils.sanitizeAsJavaIdentifier(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ package org.jetbrains.kotlin.codegen.context;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor;
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind;
|
||||
import org.jetbrains.kotlin.codegen.binding.MutableClosure;
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -45,10 +46,14 @@ public abstract class FieldOwnerContext<T extends DeclarationDescriptor> extends
|
||||
|
||||
@NotNull
|
||||
public String getFieldName(@NotNull PropertyDescriptor possiblySubstitutedDescriptor, boolean isDelegated) {
|
||||
if (possiblySubstitutedDescriptor instanceof AccessorForPropertyDescriptor) {
|
||||
possiblySubstitutedDescriptor = ((AccessorForPropertyDescriptor) possiblySubstitutedDescriptor).getCalleeDescriptor();
|
||||
}
|
||||
|
||||
PropertyDescriptor descriptor = possiblySubstitutedDescriptor.getOriginal();
|
||||
assert descriptor.getKind().isReal() : "Only declared properties can have backing fields: " + descriptor;
|
||||
|
||||
String defaultPropertyName = JvmAbi.getDefaultFieldNameForProperty(descriptor.getName(), isDelegated);
|
||||
String defaultPropertyName = JetTypeMapper.mapDefaultFieldName(descriptor, isDelegated);
|
||||
|
||||
Map<PropertyDescriptor, String> descriptor2Name = fieldNames.get(defaultPropertyName);
|
||||
if (descriptor2Name == null) {
|
||||
|
||||
+2
-2
@@ -20,13 +20,13 @@ import org.jetbrains.kotlin.codegen.ClassBuilderMode
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.fileClasses.NoResolveFileClassesProvider
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.KotlinToJvmSignatureMapper
|
||||
|
||||
public class KotlinToJvmSignatureMapperImpl : KotlinToJvmSignatureMapper {
|
||||
// We use empty BindingContext, because it is only used by JetTypeMapper for purposes irrelevant to the needs of this class
|
||||
private val typeMapper: JetTypeMapper = JetTypeMapper(
|
||||
BindingContext.EMPTY, ClassBuilderMode.LIGHT_CLASSES, NoResolveFileClassesProvider, null)
|
||||
private val typeMapper: JetTypeMapper = JetTypeMapper(BindingContext.EMPTY, ClassBuilderMode.LIGHT_CLASSES, NoResolveFileClassesProvider, null, JvmAbi.DEFAULT_MODULE_NAME)
|
||||
|
||||
override fun mapToJvmMethodSignature(function: FunctionDescriptor) = typeMapper.mapSignature(function)
|
||||
}
|
||||
|
||||
+3
-2
@@ -44,11 +44,12 @@ class BuilderFactoryForDuplicateSignatureDiagnostics(
|
||||
bindingContext: BindingContext,
|
||||
private val diagnostics: DiagnosticSink,
|
||||
fileClassesProvider: JvmFileClassesProvider,
|
||||
incrementalCache: IncrementalCache?
|
||||
incrementalCache: IncrementalCache?,
|
||||
moduleName: String
|
||||
) : SignatureCollectingClassBuilderFactory(builderFactory) {
|
||||
|
||||
// Avoid errors when some classes are not loaded for some reason
|
||||
private val typeMapper = JetTypeMapper(bindingContext, ClassBuilderMode.LIGHT_CLASSES, fileClassesProvider, incrementalCache)
|
||||
private val typeMapper = JetTypeMapper(bindingContext, ClassBuilderMode.LIGHT_CLASSES, fileClassesProvider, incrementalCache, moduleName)
|
||||
|
||||
override fun handleClashingSignatures(data: ConflictingJvmDeclarationsData) {
|
||||
val noOwnImplementations = data.signatureOrigins.all { it.originKind in EXTERNAL_SOURCES_KINDS }
|
||||
|
||||
@@ -92,11 +92,11 @@ public class GenerationState @JvmOverloads constructor(
|
||||
incrementalCompilationComponents.getIncrementalCache(targetId)
|
||||
else null
|
||||
|
||||
public val moduleName: String = moduleName ?: JvmCodegenUtil.getModuleName(module)
|
||||
public val classBuilderMode: ClassBuilderMode = builderFactory.getClassBuilderMode()
|
||||
public val bindingTrace: BindingTrace = DelegatingBindingTrace(bindingContext, "trace in GenerationState")
|
||||
public val bindingContext: BindingContext = bindingTrace.getBindingContext()
|
||||
public val typeMapper: JetTypeMapper = JetTypeMapper(this.bindingContext, classBuilderMode, fileClassesProvider,
|
||||
getIncrementalCacheForThisTarget())
|
||||
public val typeMapper: JetTypeMapper = JetTypeMapper(this.bindingContext, classBuilderMode, fileClassesProvider, getIncrementalCacheForThisTarget(), this.moduleName)
|
||||
public val intrinsics: IntrinsicMethods = IntrinsicMethods()
|
||||
public val samWrapperClasses: SamWrapperClasses = SamWrapperClasses(this)
|
||||
public val inlineCycleReporter: InlineCycleReporter = InlineCycleReporter(diagnostics)
|
||||
@@ -117,7 +117,6 @@ public class GenerationState @JvmOverloads constructor(
|
||||
public val isInlineEnabled: Boolean = !disableInline
|
||||
@JvmName("isInlineEnabled") get
|
||||
|
||||
public val moduleName: String = moduleName ?: JvmCodegenUtil.getModuleName(module)
|
||||
|
||||
public val rootContext: CodegenContext<*> = RootContext(this)
|
||||
|
||||
@@ -125,7 +124,8 @@ public class GenerationState @JvmOverloads constructor(
|
||||
val optimizationClassBuilderFactory = OptimizationClassBuilderFactory(builderFactory, disableOptimization)
|
||||
var interceptedBuilderFactory: ClassBuilderFactory = BuilderFactoryForDuplicateSignatureDiagnostics(
|
||||
optimizationClassBuilderFactory, this.bindingContext, diagnostics, fileClassesProvider,
|
||||
getIncrementalCacheForThisTarget())
|
||||
getIncrementalCacheForThisTarget(),
|
||||
this.moduleName)
|
||||
|
||||
interceptedBuilderFactory = BuilderFactoryForDuplicateClassNameDiagnostics(interceptedBuilderFactory, diagnostics);
|
||||
|
||||
|
||||
@@ -87,17 +87,20 @@ public class JetTypeMapper {
|
||||
private final ClassBuilderMode classBuilderMode;
|
||||
private final JvmFileClassesProvider fileClassesProvider;
|
||||
private final IncrementalCache incrementalCache;
|
||||
private final String moduleName;
|
||||
|
||||
public JetTypeMapper(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull ClassBuilderMode classBuilderMode,
|
||||
@NotNull JvmFileClassesProvider fileClassesProvider,
|
||||
@Nullable IncrementalCache incrementalCache
|
||||
@Nullable IncrementalCache incrementalCache,
|
||||
@NotNull String moduleName
|
||||
) {
|
||||
this.bindingContext = bindingContext;
|
||||
this.classBuilderMode = classBuilderMode;
|
||||
this.fileClassesProvider = fileClassesProvider;
|
||||
this.incrementalCache = incrementalCache;
|
||||
this.moduleName = moduleName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -828,7 +831,7 @@ public class JetTypeMapper {
|
||||
? JvmAbi.getterName(propertyName)
|
||||
: JvmAbi.setterName(propertyName);
|
||||
|
||||
return isAccessor ? "access$" + accessorName : accessorName;
|
||||
return updateMemberNameIfInternal(isAccessor ? "access$" + accessorName : accessorName, descriptor);
|
||||
}
|
||||
else if (isFunctionLiteral(descriptor)) {
|
||||
PsiElement element = DescriptorToSourceUtils.getSourceFromDescriptor(descriptor);
|
||||
@@ -848,10 +851,40 @@ public class JetTypeMapper {
|
||||
return OperatorConventions.INVOKE.asString();
|
||||
}
|
||||
else {
|
||||
return descriptor.getName().asString();
|
||||
return updateMemberNameIfInternal(descriptor.getName().asString(), descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String mapDefaultFieldName(@NotNull PropertyDescriptor propertyDescriptor, boolean isDelegated) {
|
||||
String name;
|
||||
if (propertyDescriptor instanceof AccessorForPropertyDescriptor) {
|
||||
name = ((AccessorForPropertyDescriptor) propertyDescriptor).getCalleeDescriptor().getName().asString();
|
||||
}
|
||||
else {
|
||||
name = propertyDescriptor.getName().asString();
|
||||
}
|
||||
return isDelegated ? name + JvmAbi.DELEGATED_PROPERTY_NAME_SUFFIX : name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String updateMemberNameIfInternal(@NotNull String name, @NotNull CallableMemberDescriptor descriptor) {
|
||||
if (descriptor.getContainingDeclaration() instanceof ScriptDescriptor) {
|
||||
//script properties should be public
|
||||
return name;
|
||||
}
|
||||
|
||||
if (DescriptorUtils.isTopLevelDeclaration(descriptor)) {
|
||||
return name;
|
||||
}
|
||||
|
||||
if (!(descriptor instanceof ConstructorDescriptor) && descriptor.getVisibility() == Visibilities.INTERNAL) {
|
||||
return name + "$" + JvmCodegenUtil.sanitizeAsJavaIdentifier(moduleName);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull FunctionDescriptor descriptor) {
|
||||
return mapSignature(descriptor, OwnerKind.IMPLEMENTATION);
|
||||
|
||||
Reference in New Issue
Block a user