Introduce CompilerConfiguration#getNotNull and getBoolean

To reduce boilerplate at call sites
This commit is contained in:
Alexander Udalov
2016-05-23 15:02:07 +03:00
parent 81a0fa5f47
commit 8c0f78db50
10 changed files with 36 additions and 29 deletions
@@ -614,7 +614,7 @@ public class AsmUtil {
@NotNull FunctionDescriptor descriptor,
@NotNull FrameMap frameMap
) {
if (!state.isParamAssertionsEnabled()) return;
if (state.isParamAssertionsDisabled()) return;
// Private method is not accessible from other classes, no assertions needed
if (getVisibilityAccessFlag(descriptor) == ACC_PRIVATE) return;
@@ -655,7 +655,7 @@ public class AsmUtil {
@NotNull final StackValue stackValue,
@Nullable final RuntimeAssertionInfo runtimeAssertionInfo
) {
if (!state.isCallAssertionsEnabled()) return stackValue;
if (state.isCallAssertionsDisabled()) return stackValue;
if (runtimeAssertionInfo == null || !runtimeAssertionInfo.getNeedNotNullAssertion()) return stackValue;
return new StackValue(stackValue.type) {
@@ -1879,7 +1879,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
CallableMemberDescriptor descriptor = getContext().getContextDescriptor();
NonLocalReturnInfo nonLocalReturn = getNonLocalReturnInfo(descriptor, expression);
boolean isNonLocalReturn = nonLocalReturn != null;
if (isNonLocalReturn && !state.isInlineEnabled()) {
if (isNonLocalReturn && state.isInlineDisabled()) {
state.getDiagnostics().report(Errors.NON_LOCAL_RETURN_IN_DISABLED_INLINE.on(expression));
genThrow(v, "java/lang/UnsupportedOperationException",
"Non-local returns are not allowed with inlining disabled");
@@ -2520,7 +2520,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
// We should inline callable containing reified type parameters even if inline is disabled
// because they may contain something to reify and straight call will probably fail at runtime
boolean isInline = (state.isInlineEnabled() || InlineUtil.containsReifiedTypeParameters(descriptor)) &&
boolean isInline = (!state.isInlineDisabled() || InlineUtil.containsReifiedTypeParameters(descriptor)) &&
(InlineUtil.isInline(descriptor) || InlineUtil.isArrayConstructorWithLambda(descriptor));
if (!isInline) return defaultCallGenerator;
@@ -155,7 +155,7 @@ public class InlineCodegenUtil {
public static void initDefaultSourceMappingIfNeeded(
@NotNull CodegenContext context, @NotNull MemberCodegen codegen, @NotNull GenerationState state
) {
if (!state.isInlineEnabled()) return;
if (state.isInlineDisabled()) return;
CodegenContext<?> parentContext = context.getParentContext();
while (parentContext != null) {
@@ -147,11 +147,11 @@ class GenerationState @JvmOverloads constructor(
var hasResult: Boolean = false
}
val isCallAssertionsEnabled: Boolean = !configuration.get(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, false)
val isParamAssertionsEnabled: Boolean = !configuration.get(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, false)
val isInlineEnabled: Boolean = !configuration.get(JVMConfigurationKeys.DISABLE_INLINE, false)
val useTypeTableInSerializer: Boolean = configuration.get(JVMConfigurationKeys.USE_TYPE_TABLE, false)
val inheritMultifileParts: Boolean = configuration.get(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, false)
val isCallAssertionsDisabled: Boolean = configuration.getBoolean(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS)
val isParamAssertionsDisabled: Boolean = configuration.getBoolean(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS)
val isInlineDisabled: Boolean = configuration.getBoolean(JVMConfigurationKeys.DISABLE_INLINE)
val useTypeTableInSerializer: Boolean = configuration.getBoolean(JVMConfigurationKeys.USE_TYPE_TABLE)
val inheritMultifileParts: Boolean = configuration.getBoolean(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS)
val rootContext: CodegenContext<*> = RootContext(this)