translator: enums tests, fix fields load in when

This commit is contained in:
e5l
2016-08-10 12:05:41 +03:00
parent a8b2129bb9
commit 74447d59bc
3 changed files with 37 additions and 2 deletions
@@ -174,7 +174,8 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
var receiver = when (receiverExpr) {
is KtCallExpression,
is KtBinaryExpression -> evaluateExpression(receiverExpr, scopeDepth) as LLVMVariable
is KtBinaryExpression,
is KtDotQualifiedExpression-> evaluateExpression(receiverExpr, scopeDepth) as LLVMVariable
is KtNameReferenceExpression -> {
val referenceContext = state.bindingContext.get(BindingContext.REFERENCE_TARGET, receiverExpr)
variableManager[receiverName]
@@ -731,7 +732,11 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
codeBuilder.addUnconditionalJump(if (isElse) successConditionsLabel else elseLabel)
codeBuilder.markWithLabel(successConditionsLabel)
val successExpression = evaluateExpression(item.expression, scopeDepth + 1)
var successExpression = evaluateExpression(item.expression, scopeDepth + 1)
while (successExpression is LLVMVariable && successExpression.pointer > 0) {
successExpression = codeBuilder.loadAndGetVariable(successExpression)
}
codeBuilder.storeVariable(resultVariable, successExpression ?: return)
codeBuilder.addUnconditionalJump(endLabel)
codeBuilder.addComment("end last condition item")
@@ -0,0 +1,2 @@
enum_field_test1_Byte(1) == 1
enum_field_test1_Byte(2) == 2
@@ -0,0 +1,28 @@
enum class WireType(val id: Int) {
VARINT(0), // int32, int64, uint32, uint64, sint32, sint64, bool, enum
FIX_64(1), // fixed64, sfixed64, double
LENGTH_DELIMITED(2), // string, bytes, embedded messages, packed repeated fields
START_GROUP(3), // groups (deprecated)
END_GROUP(4), // groups (deprecated)
FIX_32(5), // fixed32, sfixed32, float
UNDEFINED(6); // indicates error when parsing from Int
companion object {
fun from (value: Byte): WireType {
return when (value) {
0.toByte() -> VARINT
1.toByte() -> FIX_64
2.toByte() -> LENGTH_DELIMITED
3.toByte() -> START_GROUP
4.toByte() -> END_GROUP
5.toByte() -> FIX_32
else -> UNDEFINED
}
}
}
}
fun enum_field_test1(i: Byte): Int {
return WireType.from(i).id
}