translator: optimize and simplify val expression evaluating
This commit is contained in:
@@ -1048,55 +1048,28 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun evaluateValExpression(element: KtProperty, scopeDepth: Int): LLVMVariable? {
|
private fun evaluateValExpression(element: KtProperty, scopeDepth: Int): LLVMVariable? {
|
||||||
|
|
||||||
val variable = state.bindingContext.get(BindingContext.VARIABLE, element)!!
|
val variable = state.bindingContext.get(BindingContext.VARIABLE, element)!!
|
||||||
val identifier = variable.name.toString()
|
val identifier = variable.name.toString()
|
||||||
|
|
||||||
val assignExpression = evaluateExpression(element.delegateExpressionOrInitializer, scopeDepth)
|
val assignExpression = evaluateExpression(element.delegateExpressionOrInitializer, scopeDepth)
|
||||||
val expectedExpressionType = LLVMInstanceOfStandardType("", variable.type, state = state)
|
val expectedExpressionType = LLVMInstanceOfStandardType("", variable.type, state = state)
|
||||||
val assignExpressionType = assignExpression?.type
|
|
||||||
|
|
||||||
val primitivePointer = LLVMMapStandardType(variable.type, state) !is LLVMReferred
|
val primitivePointer = LLVMMapStandardType(variable.type, state) !is LLVMReferred
|
||||||
when (assignExpression) {
|
|
||||||
null,
|
|
||||||
is LLVMVariable -> {
|
|
||||||
val allocVar = variableManager.receiveVariable(identifier, expectedExpressionType.type, LLVMRegisterScope(), pointer =
|
|
||||||
expectedExpressionType.pointer)
|
|
||||||
codeBuilder.allocStackVar(allocVar)
|
|
||||||
allocVar.pointer++
|
|
||||||
allocVar.kotlinName = identifier
|
|
||||||
|
|
||||||
variableManager.addVariable(identifier, allocVar, scopeDepth)
|
val allocVar = variableManager.receiveVariable(identifier, expectedExpressionType.type, LLVMRegisterScope(), pointer =
|
||||||
if (assignExpression != null) {
|
expectedExpressionType.pointer)
|
||||||
if ((primitivePointer) && (assignExpression.type is LLVMReferenceType)) {
|
codeBuilder.allocStackVar(allocVar)
|
||||||
throw UnexpectedException(element.text)
|
allocVar.pointer++
|
||||||
}
|
allocVar.kotlinName = identifier
|
||||||
addPrimitiveBinaryOperation(KtTokens.EQ, null, allocVar, assignExpression)
|
|
||||||
}
|
variableManager.addVariable(identifier, allocVar, scopeDepth)
|
||||||
}
|
if (assignExpression != null) {
|
||||||
is LLVMConstant -> {
|
if ((primitivePointer) && (assignExpression.type is LLVMReferenceType)) {
|
||||||
if (assignExpressionType!! is LLVMNullType) {
|
throw UnexpectedException(element.text)
|
||||||
val reference = LLVMInstanceOfStandardType(identifier, variable.type, state = state)
|
|
||||||
if (state.classes.containsKey(variable.type.toString().dropLast(1))) {
|
|
||||||
(reference.type as LLVMReferenceType).prefix = "class"
|
|
||||||
}
|
|
||||||
|
|
||||||
codeBuilder.allocStaticVar(reference)
|
|
||||||
reference.pointer++
|
|
||||||
|
|
||||||
codeBuilder.storeNull(reference)
|
|
||||||
variableManager.addVariable(identifier, reference, scopeDepth)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
val newVar = variableManager.receiveVariable(identifier, assignExpressionType, LLVMRegisterScope(), pointer = 1)
|
|
||||||
codeBuilder.addConstant(newVar, assignExpression)
|
|
||||||
variableManager.addVariable(identifier, newVar, scopeDepth)
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
}
|
||||||
|
addPrimitiveBinaryOperation(KtTokens.EQ, null, allocVar, assignExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user