use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class AsmTypes method getType.
@NotNull
public static Type getType(@NotNull Class<?> javaClass) {
Type type = TYPES_MAP.get(javaClass);
if (type == null) {
type = Type.getType(javaClass);
TYPES_MAP.put(javaClass, type);
}
return type;
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class MappingClassesForWhenByEnumCodegen method generateInitializationForMapping.
private void generateInitializationForMapping(@NotNull ClassBuilder cb, @NotNull InstructionAdapter v, @NotNull WhenByEnumsMapping mapping) {
Type enumType = state.getTypeMapper().mapClass(mapping.getEnumClassDescriptor());
v.invokestatic(enumType.getInternalName(), "values", Type.getMethodDescriptor(Type.getType("[" + enumType.getDescriptor())), false);
v.arraylength();
v.newarray(Type.INT_TYPE);
v.putstatic(cb.getThisName(), mapping.getFieldName(), MAPPINGS_FIELD_DESCRIPTOR);
for (Map.Entry<EnumValue, Integer> item : mapping.enumValuesToIntMapping()) {
EnumValue enumEntry = item.getKey();
int mappedValue = item.getValue();
v.getstatic(cb.getThisName(), mapping.getFieldName(), MAPPINGS_FIELD_DESCRIPTOR);
v.getstatic(enumType.getInternalName(), enumEntry.getValue().getName().asString(), enumType.getDescriptor());
v.invokevirtual(enumType.getInternalName(), "ordinal", Type.getMethodDescriptor(Type.INT_TYPE), false);
v.iconst(mappedValue);
v.astore(Type.INT_TYPE);
}
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class MappingsClassesForWhenByEnum method generateMappingsClassForExpression.
public void generateMappingsClassForExpression(@NotNull KtWhenExpression expression) {
WhenByEnumsMapping mapping = state.getBindingContext().get(CodegenBinding.MAPPING_FOR_WHEN_BY_ENUM, expression);
assert mapping != null : "mapping class should not be requested for non enum when";
if (!generatedMappingClasses.contains(mapping.getMappingsClassInternalName())) {
List<WhenByEnumsMapping> mappings = state.getBindingContext().get(CodegenBinding.MAPPINGS_FOR_WHENS_BY_ENUM_IN_CLASS_FILE, mapping.getOuterClassInternalNameForExpression());
assert mappings != null : "guaranteed by usage contract of EnumSwitchCodegen";
Type mappingsClassType = Type.getObjectType(mapping.getMappingsClassInternalName());
mappingsCodegen.generate(mappings, mappingsClassType, expression.getContainingKtFile());
generatedMappingClasses.add(mapping.getMappingsClassInternalName());
}
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class SwitchCodegenUtil method buildAppropriateSwitchCodegenIfPossible.
@Nullable
public static SwitchCodegen buildAppropriateSwitchCodegenIfPossible(@NotNull KtWhenExpression expression, boolean isStatement, boolean isExhaustive, @NotNull ExpressionCodegen codegen) {
BindingContext bindingContext = codegen.getBindingContext();
boolean shouldInlineConstVals = codegen.getState().getShouldInlineConstVals();
if (!isThereConstantEntriesButNulls(expression, bindingContext, shouldInlineConstVals)) {
return null;
}
Type subjectType = codegen.expressionType(expression.getSubjectExpression());
WhenByEnumsMapping mapping = codegen.getBindingContext().get(CodegenBinding.MAPPING_FOR_WHEN_BY_ENUM, expression);
if (mapping != null) {
return new EnumSwitchCodegen(expression, isStatement, isExhaustive, codegen, mapping);
}
if (isIntegralConstantsSwitch(expression, subjectType, bindingContext, shouldInlineConstVals)) {
return new IntegralConstantsSwitchCodegen(expression, isStatement, isExhaustive, codegen);
}
if (isStringConstantsSwitch(expression, subjectType, bindingContext, shouldInlineConstVals)) {
return new StringSwitchCodegen(expression, isStatement, isExhaustive, codegen);
}
return null;
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ExpressionCodegen method generateInPrimitiveRange.
/*
* Translates x in a..b to a <= x && x <= b
* and x !in a..b to a > x || x > b for any primitive type
*/
private void generateInPrimitiveRange(StackValue argument, KtBinaryExpression rangeExpression, boolean isInverted) {
Type rangeType = argument.type;
int localVarIndex = myFrameMap.enterTemp(rangeType);
// Load left bound
gen(rangeExpression.getLeft(), rangeType);
// Load x into local variable to avoid StackValue#put side-effects
argument.put(rangeType, v);
v.store(localVarIndex, rangeType);
v.load(localVarIndex, rangeType);
// If (x < left) goto L1
Label l1 = new Label();
emitGreaterThan(rangeType, l1);
// If (x > right) goto L1
v.load(localVarIndex, rangeType);
gen(rangeExpression.getRight(), rangeType);
emitGreaterThan(rangeType, l1);
Label l2 = new Label();
v.iconst(isInverted ? 0 : 1);
v.goTo(l2);
v.mark(l1);
v.iconst(isInverted ? 1 : 0);
v.mark(l2);
myFrameMap.leaveTemp(rangeType);
}
Aggregations