Fixed bug with name clash for package level properties

This commit is contained in:
Igor Chevdar
2017-05-24 14:52:52 +03:00
parent 772e8a33ae
commit 21ad85216f
3 changed files with 8 additions and 6 deletions
@@ -287,13 +287,14 @@ private class DeclarationsGeneratorVisitor(override val context: Context) :
return null
}
val symbolName = if (descriptor.isExported()) {
val isExported = descriptor.isExported()
val symbolName = if (isExported) {
descriptor.objectInstanceFieldSymbolName
} else {
"kobjref:" + qualifyInternalName(descriptor)
}
val instanceFieldRef = addGlobal(
symbolName, getLLVMType(descriptor.defaultType), threadLocal = true)
symbolName, getLLVMType(descriptor.defaultType), isExported = isExported, threadLocal = true)
return SingletonLlvmDeclarations(instanceFieldRef)
}
@@ -320,7 +321,7 @@ private class DeclarationsGeneratorVisitor(override val context: Context) :
val name = "kvar:" + qualifyInternalName(descriptor)
val storage = addGlobal(
name, getLLVMType(descriptor.type), threadLocal = true)
name, getLLVMType(descriptor.type), isExported = false, threadLocal = true)
this.staticFields[descriptor] = StaticFieldLlvmDeclarations(storage)
}
@@ -182,9 +182,10 @@ internal fun getGlobalType(ptrToGlobal: LLVMValueRef): LLVMTypeRef {
return LLVMGetElementType(ptrToGlobal.type)!!
}
internal fun ContextUtils.addGlobal(name: String, type: LLVMTypeRef,
internal fun ContextUtils.addGlobal(name: String, type: LLVMTypeRef, isExported: Boolean,
threadLocal: Boolean = false): LLVMValueRef {
assert(LLVMGetNamedGlobal(context.llvmModule, name) == null)
if (isExported)
assert(LLVMGetNamedGlobal(context.llvmModule, name) == null)
val result = LLVMAddGlobal(context.llvmModule, type, name)!!
if (threadLocal)
LLVMSetThreadLocalMode(result, runtime.tlsMode)
@@ -71,7 +71,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
if (annot != null) {
val nameValue = annot.allValueArguments.values.single() as StringValue
// TODO: use LLVMAddAlias?
val global = addGlobal(nameValue.value, pointerType(runtime.typeInfoType))
val global = addGlobal(nameValue.value, pointerType(runtime.typeInfoType), isExported = true)
LLVMSetInitializer(global, typeInfoGlobal)
}
}