clang  14.0.0git
LangStandard.h
Go to the documentation of this file.
1 //===--- LangStandard.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 LLVM_CLANG_BASIC_LANGSTANDARD_H
10 #define LLVM_CLANG_BASIC_LANGSTANDARD_H
11 
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/StringRef.h"
14 
15 namespace clang {
16 
17 /// The language for the input, used to select and validate the language
18 /// standard and possible actions.
19 enum class Language : uint8_t {
20  Unknown,
21 
22  /// Assembly: we accept this only so that we can preprocess it.
23  Asm,
24 
25  /// LLVM IR: we accept this so that we can run the optimizer on it,
26  /// and compile it to assembly or object code.
27  LLVM_IR,
28 
29  ///@{ Languages that the frontend can parse and compile.
30  C,
31  CXX,
32  ObjC,
33  ObjCXX,
34  OpenCL,
35  OpenCLCXX,
36  CUDA,
38  HIP,
39  ///@}
40 };
41 
43  LineComment = (1 << 0),
44  C99 = (1 << 1),
45  C11 = (1 << 2),
46  C17 = (1 << 3),
47  C2x = (1 << 4),
48  CPlusPlus = (1 << 5),
49  CPlusPlus11 = (1 << 6),
50  CPlusPlus14 = (1 << 7),
51  CPlusPlus17 = (1 << 8),
52  CPlusPlus20 = (1 << 9),
53  CPlusPlus2b = (1 << 10),
54  Digraphs = (1 << 11),
55  GNUMode = (1 << 12),
56  HexFloat = (1 << 13),
57  ImplicitInt = (1 << 14),
58  OpenCL = (1 << 15)
59 };
60 
61 /// LangStandard - Information about the properties of a particular language
62 /// standard.
63 struct LangStandard {
64  enum Kind {
65 #define LANGSTANDARD(id, name, lang, desc, features) \
66  lang_##id,
67 #include "clang/Basic/LangStandards.def"
69  };
70 
71  const char *ShortName;
72  const char *Description;
73  unsigned Flags;
75 
76 public:
77  /// getName - Get the name of this standard.
78  const char *getName() const { return ShortName; }
79 
80  /// getDescription - Get the description of this standard.
81  const char *getDescription() const { return Description; }
82 
83  /// Get the language that this standard describes.
84  clang::Language getLanguage() const { return Language; }
85 
86  /// Language supports '//' comments.
87  bool hasLineComments() const { return Flags & LineComment; }
88 
89  /// isC99 - Language is a superset of C99.
90  bool isC99() const { return Flags & C99; }
91 
92  /// isC11 - Language is a superset of C11.
93  bool isC11() const { return Flags & C11; }
94 
95  /// isC17 - Language is a superset of C17.
96  bool isC17() const { return Flags & C17; }
97 
98  /// isC2x - Language is a superset of C2x.
99  bool isC2x() const { return Flags & C2x; }
100 
101  /// isCPlusPlus - Language is a C++ variant.
102  bool isCPlusPlus() const { return Flags & CPlusPlus; }
103 
104  /// isCPlusPlus11 - Language is a C++11 variant (or later).
105  bool isCPlusPlus11() const { return Flags & CPlusPlus11; }
106 
107  /// isCPlusPlus14 - Language is a C++14 variant (or later).
108  bool isCPlusPlus14() const { return Flags & CPlusPlus14; }
109 
110  /// isCPlusPlus17 - Language is a C++17 variant (or later).
111  bool isCPlusPlus17() const { return Flags & CPlusPlus17; }
112 
113  /// isCPlusPlus20 - Language is a C++20 variant (or later).
114  bool isCPlusPlus20() const { return Flags & CPlusPlus20; }
115 
116  /// isCPlusPlus2b - Language is a post-C++20 variant (or later).
117  bool isCPlusPlus2b() const { return Flags & CPlusPlus2b; }
118 
119  /// hasDigraphs - Language supports digraphs.
120  bool hasDigraphs() const { return Flags & Digraphs; }
121 
122  /// isGNUMode - Language includes GNU extensions.
123  bool isGNUMode() const { return Flags & GNUMode; }
124 
125  /// hasHexFloats - Language supports hexadecimal float constants.
126  bool hasHexFloats() const { return Flags & HexFloat; }
127 
128  /// hasImplicitInt - Language allows variables to be typed as int implicitly.
129  bool hasImplicitInt() const { return Flags & ImplicitInt; }
130 
131  /// isOpenCL - Language is a OpenCL variant.
132  bool isOpenCL() const { return Flags & OpenCL; }
133 
134  static Kind getLangKind(StringRef Name);
135  static const LangStandard &getLangStandardForKind(Kind K);
136  static const LangStandard *getLangStandardForName(StringRef Name);
137 };
138 
139 } // end namespace clang
140 
141 #endif
clang::OpenCL
@ OpenCL
Definition: LangStandard.h:58
clang::Language::CUDA
@ CUDA
clang::LangStandard::isC99
bool isC99() const
isC99 - Language is a superset of C99.
Definition: LangStandard.h:90
clang::LangStandard::isCPlusPlus14
bool isCPlusPlus14() const
isCPlusPlus14 - Language is a C++14 variant (or later).
Definition: LangStandard.h:108
clang::LangStandard::hasDigraphs
bool hasDigraphs() const
hasDigraphs - Language supports digraphs.
Definition: LangStandard.h:120
clang::Language::OpenCLCXX
@ OpenCLCXX
clang::C99
@ C99
Definition: LangStandard.h:44
clang::CPlusPlus14
@ CPlusPlus14
Definition: LangStandard.h:50
clang::Language::Asm
@ Asm
Assembly: we accept this only so that we can preprocess it.
clang::LangStandard::isOpenCL
bool isOpenCL() const
isOpenCL - Language is a OpenCL variant.
Definition: LangStandard.h:132
clang::LangStandard::isCPlusPlus2b
bool isCPlusPlus2b() const
isCPlusPlus2b - Language is a post-C++20 variant (or later).
Definition: LangStandard.h:117
clang::LangStandard::Flags
unsigned Flags
Definition: LangStandard.h:73
clang::CPlusPlus17
@ CPlusPlus17
Definition: LangStandard.h:51
clang::Digraphs
@ Digraphs
Definition: LangStandard.h:54
clang::LangStandard::Kind
Kind
Definition: LangStandard.h:64
clang::LangStandard::getLangKind
static Kind getLangKind(StringRef Name)
Definition: LangStandards.cpp:29
clang::Language::RenderScript
@ RenderScript
clang::LangStandard::getName
const char * getName() const
getName - Get the name of this standard.
Definition: LangStandard.h:78
clang::C11
@ C11
Definition: LangStandard.h:45
clang::LangStandard::hasLineComments
bool hasLineComments() const
Language supports '//' comments.
Definition: LangStandard.h:87
clang::HexFloat
@ HexFloat
Definition: LangStandard.h:56
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:48
clang::LangStandard::hasHexFloats
bool hasHexFloats() const
hasHexFloats - Language supports hexadecimal float constants.
Definition: LangStandard.h:126
clang::LangStandard::isCPlusPlus
bool isCPlusPlus() const
isCPlusPlus - Language is a C++ variant.
Definition: LangStandard.h:102
clang::CPlusPlus20
@ CPlusPlus20
Definition: LangStandard.h:52
clang::Language::C
@ C
Languages that the frontend can parse and compile.
clang::LangStandard::isCPlusPlus20
bool isCPlusPlus20() const
isCPlusPlus20 - Language is a C++20 variant (or later).
Definition: LangStandard.h:114
clang::CPlusPlus2b
@ CPlusPlus2b
Definition: LangStandard.h:53
clang::LangStandard::ShortName
const char * ShortName
Definition: LangStandard.h:71
clang::LangStandard::isC2x
bool isC2x() const
isC2x - Language is a superset of C2x.
Definition: LangStandard.h:99
clang::ImplicitInt
@ ImplicitInt
Definition: LangStandard.h:57
clang::Language
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:19
clang::LangStandard::isCPlusPlus11
bool isCPlusPlus11() const
isCPlusPlus11 - Language is a C++11 variant (or later).
Definition: LangStandard.h:105
clang::LangStandard::isC11
bool isC11() const
isC11 - Language is a superset of C11.
Definition: LangStandard.h:93
clang::LangStandard::getLanguage
clang::Language getLanguage() const
Get the language that this standard describes.
Definition: LangStandard.h:84
clang::Language::CXX
@ CXX
clang::C2x
@ C2x
Definition: LangStandard.h:47
clang::Language::ObjCXX
@ ObjCXX
clang::LangStandard::hasImplicitInt
bool hasImplicitInt() const
hasImplicitInt - Language allows variables to be typed as int implicitly.
Definition: LangStandard.h:129
clang::Language::LLVM_IR
@ LLVM_IR
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
clang::LangStandard::getLangStandardForName
static const LangStandard * getLangStandardForName(StringRef Name)
Definition: LangStandards.cpp:37
LLVM.h
clang::Language::ObjC
@ ObjC
clang::LangStandard::lang_unspecified
@ lang_unspecified
Definition: LangStandard.h:68
clang::LangStandard::isC17
bool isC17() const
isC17 - Language is a superset of C17.
Definition: LangStandard.h:96
clang::LangStandard
LangStandard - Information about the properties of a particular language standard.
Definition: LangStandard.h:63
clang::LangFeatures
LangFeatures
Definition: LangStandard.h:42
clang
Definition: CalledOnceCheck.h:17
clang::LangStandard::Description
const char * Description
Definition: LangStandard.h:72
clang::CPlusPlus11
@ CPlusPlus11
Definition: LangStandard.h:49
clang::Language::Unknown
@ Unknown
clang::Language::HIP
@ HIP
clang::LangStandard::Language
clang::Language Language
Definition: LangStandard.h:74
clang::GNUMode
@ GNUMode
Definition: LangStandard.h:55
clang::LineComment
@ LineComment
Definition: LangStandard.h:43
clang::C17
@ C17
Definition: LangStandard.h:46
clang::LangStandard::isCPlusPlus17
bool isCPlusPlus17() const
isCPlusPlus17 - Language is a C++17 variant (or later).
Definition: LangStandard.h:111
clang::LangStandard::isGNUMode
bool isGNUMode() const
isGNUMode - Language includes GNU extensions.
Definition: LangStandard.h:123
clang::LangStandard::getDescription
const char * getDescription() const
getDescription - Get the description of this standard.
Definition: LangStandard.h:81
clang::LangStandard::getLangStandardForKind
static const LangStandard & getLangStandardForKind(Kind K)
Definition: LangStandards.cpp:18
clang::OpenCL
@ OpenCL