1 //===-- include/flang/Common/Fortran-features.h -----------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef FORTRAN_COMMON_FORTRAN_FEATURES_H_ 10 #define FORTRAN_COMMON_FORTRAN_FEATURES_H_ 11 12 #include "flang/Common/Fortran.h" 13 #include "flang/Common/enum-set.h" 14 #include "flang/Common/idioms.h" 15 16 namespace Fortran::common { 17 18 ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines, 19 FixedFormContinuationWithColumn1Ampersand, LogicalAbbreviations, 20 XOROperator, PunctuationInNames, OptionalFreeFormSpace, BOZExtensions, 21 EmptyStatement, AlternativeNE, ExecutionPartNamelist, DECStructures, 22 DoubleComplex, Byte, StarKind, QuadPrecision, SlashInitialization, 23 TripletInArrayConstructor, MissingColons, SignedComplexLiteral, 24 OldStyleParameter, ComplexConstructor, PercentLOC, SignedPrimary, FileName, 25 Carriagecontrol, Convert, Dispose, IOListLeadingComma, 26 AbbreviatedEditDescriptor, ProgramParentheses, PercentRefAndVal, 27 OmitFunctionDummies, CrayPointer, Hollerith, ArithmeticIF, Assign, 28 AssignedGOTO, Pause, OpenACC, OpenMP, CruftAfterAmpersand, ClassicCComments, 29 AdditionalFormats, BigIntLiterals, RealDoControls, 30 EquivalenceNumericWithCharacter, AdditionalIntrinsics, AnonymousParents, 31 OldLabelDoEndStatements, LogicalIntegerAssignment, EmptySourceFile, 32 ProgramReturn, ImplicitNoneTypeNever, ImplicitNoneTypeAlways) 33 34 using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>; 35 36 class LanguageFeatureControl { 37 public: LanguageFeatureControl()38 LanguageFeatureControl() { 39 // These features must be explicitly enabled by command line options. 40 disable_.set(LanguageFeature::OldDebugLines); 41 disable_.set(LanguageFeature::OpenACC); 42 disable_.set(LanguageFeature::OpenMP); 43 disable_.set(LanguageFeature::ImplicitNoneTypeNever); 44 disable_.set(LanguageFeature::ImplicitNoneTypeAlways); 45 // These features, if enabled, conflict with valid standard usage, 46 // so there are disabled here by default. 47 disable_.set(LanguageFeature::BackslashEscapes); 48 disable_.set(LanguageFeature::LogicalAbbreviations); 49 disable_.set(LanguageFeature::XOROperator); 50 } 51 LanguageFeatureControl(const LanguageFeatureControl &) = default; 52 void Enable(LanguageFeature f, bool yes = true) { disable_.set(f, !yes); } 53 void EnableWarning(LanguageFeature f, bool yes = true) { warn_.set(f, yes); } 54 void WarnOnAllNonstandard(bool yes = true) { warnAll_ = yes; } IsEnabled(LanguageFeature f)55 bool IsEnabled(LanguageFeature f) const { return !disable_.test(f); } ShouldWarn(LanguageFeature f)56 bool ShouldWarn(LanguageFeature f) const { 57 return (warnAll_ && f != LanguageFeature::OpenMP && 58 f != LanguageFeature::OpenACC) || 59 warn_.test(f); 60 } 61 // Return all spellings of operators names, depending on features enabled 62 std::vector<const char *> GetNames(LogicalOperator) const; 63 std::vector<const char *> GetNames(RelationalOperator) const; 64 65 private: 66 LanguageFeatures disable_; 67 LanguageFeatures warn_; 68 bool warnAll_{false}; 69 }; 70 } // namespace Fortran::common 71 #endif // FORTRAN_COMMON_FORTRAN_FEATURES_H_ 72