Warning: This file is not a C or C++ file. It does not have highlighting.
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 | #include <vector> |
16 | |
17 | namespace Fortran::common { |
18 | |
19 | // Non-conforming extensions & legacies |
20 | ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines, |
21 | FixedFormContinuationWithColumn1Ampersand, LogicalAbbreviations, |
22 | XOROperator, PunctuationInNames, OptionalFreeFormSpace, BOZExtensions, |
23 | EmptyStatement, AlternativeNE, ExecutionPartNamelist, DECStructures, |
24 | DoubleComplex, Byte, StarKind, ExponentMatchingKindParam, QuadPrecision, |
25 | SlashInitialization, TripletInArrayConstructor, MissingColons, |
26 | SignedComplexLiteral, OldStyleParameter, ComplexConstructor, PercentLOC, |
27 | SignedPrimary, FileName, Carriagecontrol, Convert, Dispose, |
28 | IOListLeadingComma, AbbreviatedEditDescriptor, ProgramParentheses, |
29 | PercentRefAndVal, OmitFunctionDummies, CrayPointer, Hollerith, ArithmeticIF, |
30 | Assign, AssignedGOTO, Pause, OpenACC, OpenMP, CUDA, CruftAfterAmpersand, |
31 | ClassicCComments, AdditionalFormats, BigIntLiterals, RealDoControls, |
32 | EquivalenceNumericWithCharacter, EquivalenceNonDefaultNumeric, |
33 | EquivalenceSameNonSequence, AdditionalIntrinsics, AnonymousParents, |
34 | OldLabelDoEndStatements, LogicalIntegerAssignment, EmptySourceFile, |
35 | ProgramReturn, ImplicitNoneTypeNever, ImplicitNoneTypeAlways, |
36 | ForwardRefImplicitNone, OpenAccessAppend, BOZAsDefaultInteger, |
37 | DistinguishableSpecifics, DefaultSave, PointerInSeqType, NonCharacterFormat, |
38 | SaveMainProgram, SaveBigMainProgramVariables, |
39 | DistinctArrayConstructorLengths, PPCVector, RelaxedIntentInChecking, |
40 | ForwardRefImplicitNoneData, NullActualForAllocatable, |
41 | ActualIntegerConvertedToSmallerKind, HollerithOrCharacterAsBOZ, |
42 | BindingAsProcedure, StatementFunctionExtensions, |
43 | UseGenericIntrinsicWhenSpecificDoesntMatch, DataStmtExtensions, |
44 | RedundantContiguous, InitBlankCommon, EmptyBindCDerivedType, |
45 | MiscSourceExtensions, AllocateToOtherLength, LongNames, IntrinsicAsSpecific, |
46 | BenignNameClash, BenignRedundancy, NullMoldAllocatableComponentValue, |
47 | NopassScalarBase, MiscUseExtensions, ImpliedDoIndexScope, |
48 | DistinctCommonSizes, OddIndexVariableRestrictions, |
49 | IndistinguishableSpecifics) |
50 | |
51 | // Portability and suspicious usage warnings for conforming code |
52 | ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable, |
53 | NonTargetPassedToTarget, PointerToPossibleNoncontiguous, |
54 | ShortCharacterActual, ExprPassedToVolatile, ImplicitInterfaceActual, |
55 | PolymorphicTransferArg, PointerComponentTransferArg, TransferSizePresence, |
56 | F202XAllocatableBreakingChange, DimMustBePresent, CommonBlockPadding, |
57 | LogicalVsCBool, BindCCharLength, ProcDummyArgShapes, ExternalNameConflict) |
58 | |
59 | using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>; |
60 | using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>; |
61 | |
62 | class LanguageFeatureControl { |
63 | public: |
64 | LanguageFeatureControl() { |
65 | // These features must be explicitly enabled by command line options. |
66 | disable_.set(LanguageFeature::OldDebugLines); |
67 | disable_.set(LanguageFeature::OpenACC); |
68 | disable_.set(LanguageFeature::OpenMP); |
69 | disable_.set(LanguageFeature::CUDA); // !@cuf |
70 | disable_.set(LanguageFeature::ImplicitNoneTypeNever); |
71 | disable_.set(LanguageFeature::ImplicitNoneTypeAlways); |
72 | disable_.set(LanguageFeature::DefaultSave); |
73 | disable_.set(LanguageFeature::SaveMainProgram); |
74 | // These features, if enabled, conflict with valid standard usage, |
75 | // so there are disabled here by default. |
76 | disable_.set(LanguageFeature::BackslashEscapes); |
77 | disable_.set(LanguageFeature::LogicalAbbreviations); |
78 | disable_.set(LanguageFeature::XOROperator); |
79 | disable_.set(LanguageFeature::OldStyleParameter); |
80 | } |
81 | LanguageFeatureControl(const LanguageFeatureControl &) = default; |
82 | void Enable(LanguageFeature f, bool yes = true) { disable_.set(f, !yes); } |
83 | void EnableWarning(LanguageFeature f, bool yes = true) { |
84 | warnLanguage_.set(f, yes); |
85 | } |
86 | void EnableWarning(UsageWarning w, bool yes = true) { |
87 | warnUsage_.set(w, yes); |
88 | } |
89 | void WarnOnAllNonstandard(bool yes = true) { warnAllLanguage_ = yes; } |
90 | void WarnOnAllUsage(bool yes = true) { warnAllUsage_ = yes; } |
91 | bool IsEnabled(LanguageFeature f) const { return !disable_.test(f); } |
92 | bool ShouldWarn(LanguageFeature f) const { |
93 | return (warnAllLanguage_ && f != LanguageFeature::OpenMP && |
94 | f != LanguageFeature::OpenACC) || |
95 | warnLanguage_.test(f); |
96 | } |
97 | bool ShouldWarn(UsageWarning w) const { |
98 | return warnAllUsage_ || warnUsage_.test(w); |
99 | } |
100 | // Return all spellings of operators names, depending on features enabled |
101 | std::vector<const char *> GetNames(LogicalOperator) const; |
102 | std::vector<const char *> GetNames(RelationalOperator) const; |
103 | |
104 | private: |
105 | LanguageFeatures disable_; |
106 | LanguageFeatures warnLanguage_; |
107 | bool warnAllLanguage_{false}; |
108 | UsageWarnings warnUsage_; |
109 | bool warnAllUsage_{false}; |
110 | }; |
111 | } // namespace Fortran::common |
112 | #endif // FORTRAN_COMMON_FORTRAN_FEATURES_H_ |
113 |
Warning: This file is not a C or C++ file. It does not have highlighting.