1 // Copyright (c) 2018-2019, NVIDIA CORPORATION.  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 #ifndef FORTRAN_PARSER_FEATURES_H_
16 #define FORTRAN_PARSER_FEATURES_H_
17 
18 #include "../common/enum-set.h"
19 #include "../common/idioms.h"
20 
21 namespace Fortran::parser {
22 
23 ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
24     FixedFormContinuationWithColumn1Ampersand, LogicalAbbreviations,
25     XOROperator, PunctuationInNames, OptionalFreeFormSpace, BOZExtensions,
26     EmptyStatement, AlternativeNE, ExecutionPartNamelist, DECStructures,
27     DoubleComplex, Byte, StarKind, QuadPrecision, SlashInitialization,
28     TripletInArrayConstructor, MissingColons, SignedComplexLiteral,
29     OldStyleParameter, ComplexConstructor, PercentLOC, SignedPrimary, FileName,
30     Convert, Dispose, IOListLeadingComma, AbbreviatedEditDescriptor,
31     ProgramParentheses, PercentRefAndVal, OmitFunctionDummies, CrayPointer,
32     Hollerith, ArithmeticIF, Assign, AssignedGOTO, Pause, OpenMP,
33     CruftAfterAmpersand, ClassicCComments, AdditionalFormats, BigIntLiterals,
34     RealDoControls, EquivalenceNumericWithCharacter, AdditionalIntrinsics,
35     AnonymousParents, OldLabelDoEndStatements)
36 
37 using LanguageFeatures =
38     common::EnumSet<LanguageFeature, LanguageFeature_enumSize>;
39 
40 class LanguageFeatureControl {
41 public:
LanguageFeatureControl()42   LanguageFeatureControl() {
43     // These features must be explicitly enabled by command line options.
44     disable_.set(LanguageFeature::OldDebugLines);
45     disable_.set(LanguageFeature::OpenMP);
46     // These features, if enabled, conflict with valid standard usage,
47     // so there are disabled here by default.
48     disable_.set(LanguageFeature::BackslashEscapes);
49     disable_.set(LanguageFeature::LogicalAbbreviations);
50     disable_.set(LanguageFeature::XOROperator);
51   }
52   LanguageFeatureControl(const LanguageFeatureControl &) = default;
53   void Enable(LanguageFeature f, bool yes = true) { disable_.set(f, !yes); }
54   void EnableWarning(LanguageFeature f, bool yes = true) { warn_.set(f, yes); }
55   void WarnOnAllNonstandard(bool yes = true) { warnAll_ = yes; }
IsEnabled(LanguageFeature f)56   bool IsEnabled(LanguageFeature f) const { return !disable_.test(f); }
ShouldWarn(LanguageFeature f)57   bool ShouldWarn(LanguageFeature f) const {
58     return (warnAll_ && f != LanguageFeature::OpenMP) || warn_.test(f);
59   }
60 
61 private:
62   LanguageFeatures disable_;
63   LanguageFeatures warn_;
64   bool warnAll_{false};
65 };
66 }
67 #endif  // FORTRAN_PARSER_FEATURES_H_
68