FLANG

Fortran-features.h
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 Convert, Dispose, IOListLeadingComma, AbbreviatedEditDescriptor,
26 ProgramParentheses, PercentRefAndVal, OmitFunctionDummies, CrayPointer,
27 Hollerith, ArithmeticIF, Assign, AssignedGOTO, Pause, OpenACC, OpenMP,
28 CruftAfterAmpersand, ClassicCComments, AdditionalFormats, BigIntLiterals,
29 RealDoControls, EquivalenceNumericWithCharacter, AdditionalIntrinsics,
30 AnonymousParents, OldLabelDoEndStatements, LogicalIntegerAssignment,
31 EmptySourceFile, ProgramReturn)
32
33 using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
34
35 class LanguageFeatureControl {
36 public:
37 LanguageFeatureControl() {
38 // These features must be explicitly enabled by command line options.
39 disable_.set(LanguageFeature::OldDebugLines);
40 disable_.set(LanguageFeature::OpenACC);
41 disable_.set(LanguageFeature::OpenMP);
42 // These features, if enabled, conflict with valid standard usage,
43 // so there are disabled here by default.
44 disable_.set(LanguageFeature::BackslashEscapes);
45 disable_.set(LanguageFeature::LogicalAbbreviations);
46 disable_.set(LanguageFeature::XOROperator);
47 }
48 LanguageFeatureControl(const LanguageFeatureControl &) = default;
49 void Enable(LanguageFeature f, bool yes = true) { disable_.set(f, !yes); }
50 void EnableWarning(LanguageFeature f, bool yes = true) { warn_.set(f, yes); }
51 void WarnOnAllNonstandard(bool yes = true) { warnAll_ = yes; }
52 bool IsEnabled(LanguageFeature f) const { return !disable_.test(f); }
53 bool ShouldWarn(LanguageFeature f) const {
54 return (warnAll_ && f != LanguageFeature::OpenMP &&
55 f != LanguageFeature::OpenACC) ||
56 warn_.test(f);
57 }
58 // Return all spellings of operators names, depending on features enabled
59 std::vector<const char *> GetNames(LogicalOperator) const;
60 std::vector<const char *> GetNames(RelationalOperator) const;
61
62 private:
63 LanguageFeatures disable_;
64 LanguageFeatures warn_;
65 bool warnAll_{false};
66 };
67 } // namespace Fortran::common
68 #endif // FORTRAN_COMMON_FORTRAN_FEATURES_H_
Fortran::common::LanguageFeatureControl
Definition: Fortran-features.h:35