brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.devtools.build.lib.syntax; |
| 16 | |
| 17 | import com.google.auto.value.AutoValue; |
| 18 | |
| 19 | /** |
| 20 | * Options that affect Skylark semantics. |
| 21 | * |
| 22 | * <p>For descriptions of what these options do, see {@link SkylarkSemanticsOptions}. |
| 23 | */ |
| 24 | // TODO(brandjon): User error messages that reference options should maybe be substituted with the |
| 25 | // option name outside of the core Skylark interpreter? |
| 26 | // TODO(brandjon): Eventually these should be documented in full here, and SkylarkSemanticsOptions |
| 27 | // should refer to this class for documentation. But this doesn't play nice with the options |
| 28 | // parser's annotation mechanism. |
| 29 | @AutoValue |
| 30 | public abstract class SkylarkSemantics { |
| 31 | |
brandjon | 617f8ff | 2017-10-06 06:07:13 +0200 | [diff] [blame] | 32 | /** |
| 33 | * The AutoValue-generated concrete class implementing this one. |
| 34 | * |
| 35 | * <p>AutoValue implementation classes are usually package-private. We expose it here for the |
| 36 | * benefit of code that relies on reflection. |
| 37 | */ |
| 38 | public static final Class<? extends SkylarkSemantics> IMPL_CLASS = |
| 39 | AutoValue_SkylarkSemantics.class; |
| 40 | |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 41 | // <== Add new options here in alphabetic order ==> |
| 42 | public abstract boolean incompatibleBzlDisallowLoadAfterStatement(); |
| 43 | public abstract boolean incompatibleCheckedArithmetic(); |
| 44 | public abstract boolean incompatibleComprehensionVariablesDoNotLeak(); |
| 45 | public abstract boolean incompatibleDepsetIsNotIterable(); |
laurentlb | 2bbda4a | 2017-12-07 10:38:46 -0800 | [diff] [blame] | 46 | |
| 47 | public abstract boolean incompatibleDepsetUnion(); |
| 48 | |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 49 | public abstract boolean incompatibleDictLiteralHasNoDuplicates(); |
| 50 | public abstract boolean incompatibleDisallowDictPlus(); |
| 51 | public abstract boolean incompatibleDisallowKeywordOnlyArgs(); |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 52 | public abstract boolean incompatibleDisallowToplevelIfStatement(); |
vladmos | 9bb93ee | 2017-11-21 04:40:08 -0800 | [diff] [blame] | 53 | public abstract boolean incompatibleDisallowUncalledSetConstructor(); |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 54 | public abstract boolean incompatibleLoadArgumentIsLabel(); |
| 55 | public abstract boolean incompatibleNewActionsApi(); |
vladmos | 1df4635 | 2017-11-30 03:02:36 -0800 | [diff] [blame] | 56 | public abstract boolean incompatibleShowAllPrintMessages(); |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 57 | public abstract boolean incompatibleStringIsNotIterable(); |
| 58 | public abstract boolean internalDoNotExportBuiltins(); |
| 59 | public abstract boolean internalSkylarkFlagTestCanary(); |
| 60 | |
brandjon | 6ac92f9 | 2017-12-06 13:57:15 -0800 | [diff] [blame] | 61 | /** Returns a {@link Builder} initialized with the values of this instance. */ |
| 62 | public abstract Builder toBuilder(); |
| 63 | |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 64 | public static Builder builder() { |
| 65 | return new AutoValue_SkylarkSemantics.Builder(); |
| 66 | } |
| 67 | |
brandjon | 6ac92f9 | 2017-12-06 13:57:15 -0800 | [diff] [blame] | 68 | /** Returns a {@link Builder} initialized with default values for all options. */ |
| 69 | public static Builder builderWithDefaults() { |
| 70 | return DEFAULT_SEMANTICS.toBuilder(); |
| 71 | } |
| 72 | |
vladmos | 1df4635 | 2017-11-30 03:02:36 -0800 | [diff] [blame] | 73 | public static final SkylarkSemantics DEFAULT_SEMANTICS = |
| 74 | builder() |
| 75 | // <== Add new options here in alphabetic order ==> |
| 76 | .incompatibleBzlDisallowLoadAfterStatement(false) |
| 77 | .incompatibleCheckedArithmetic(true) |
| 78 | .incompatibleComprehensionVariablesDoNotLeak(true) |
| 79 | .incompatibleDepsetIsNotIterable(false) |
laurentlb | 2bbda4a | 2017-12-07 10:38:46 -0800 | [diff] [blame] | 80 | .incompatibleDepsetUnion(false) |
vladmos | 1df4635 | 2017-11-30 03:02:36 -0800 | [diff] [blame] | 81 | .incompatibleDictLiteralHasNoDuplicates(true) |
| 82 | .incompatibleDisallowDictPlus(false) |
| 83 | .incompatibleDisallowKeywordOnlyArgs(true) |
| 84 | .incompatibleDisallowToplevelIfStatement(true) |
vladmos | 3132024 | 2017-12-06 06:02:01 -0800 | [diff] [blame] | 85 | .incompatibleDisallowUncalledSetConstructor(true) |
laurentlb | 7cf1c69 | 2017-12-04 05:44:54 -0800 | [diff] [blame] | 86 | .incompatibleLoadArgumentIsLabel(true) |
vladmos | 1df4635 | 2017-11-30 03:02:36 -0800 | [diff] [blame] | 87 | .incompatibleNewActionsApi(false) |
| 88 | .incompatibleShowAllPrintMessages(true) |
| 89 | .incompatibleStringIsNotIterable(false) |
| 90 | .internalDoNotExportBuiltins(false) |
| 91 | .internalSkylarkFlagTestCanary(false) |
| 92 | .build(); |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 93 | |
| 94 | /** Builder for {@link SkylarkSemantics}. All fields are mandatory. */ |
| 95 | @AutoValue.Builder |
| 96 | public abstract static class Builder { |
| 97 | |
| 98 | // <== Add new options here in alphabetic order ==> |
| 99 | public abstract Builder incompatibleBzlDisallowLoadAfterStatement(boolean value); |
| 100 | public abstract Builder incompatibleCheckedArithmetic(boolean value); |
| 101 | public abstract Builder incompatibleComprehensionVariablesDoNotLeak(boolean value); |
| 102 | public abstract Builder incompatibleDepsetIsNotIterable(boolean value); |
laurentlb | 2bbda4a | 2017-12-07 10:38:46 -0800 | [diff] [blame] | 103 | |
| 104 | public abstract Builder incompatibleDepsetUnion(boolean value); |
| 105 | |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 106 | public abstract Builder incompatibleDictLiteralHasNoDuplicates(boolean value); |
| 107 | public abstract Builder incompatibleDisallowDictPlus(boolean value); |
| 108 | public abstract Builder incompatibleDisallowKeywordOnlyArgs(boolean value); |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 109 | public abstract Builder incompatibleDisallowToplevelIfStatement(boolean value); |
vladmos | 9bb93ee | 2017-11-21 04:40:08 -0800 | [diff] [blame] | 110 | public abstract Builder incompatibleDisallowUncalledSetConstructor(boolean value); |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 111 | public abstract Builder incompatibleLoadArgumentIsLabel(boolean value); |
| 112 | public abstract Builder incompatibleNewActionsApi(boolean value); |
vladmos | 1df4635 | 2017-11-30 03:02:36 -0800 | [diff] [blame] | 113 | public abstract Builder incompatibleShowAllPrintMessages(boolean value); |
brandjon | 60be531 | 2017-10-04 23:06:41 +0200 | [diff] [blame] | 114 | public abstract Builder incompatibleStringIsNotIterable(boolean value); |
| 115 | public abstract Builder internalDoNotExportBuiltins(boolean value); |
| 116 | public abstract Builder internalSkylarkFlagTestCanary(boolean value); |
| 117 | |
| 118 | public abstract SkylarkSemantics build(); |
| 119 | } |
| 120 | } |