aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c699a96..b5f1241 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3942,34 +3942,42 @@ tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
LangOptions getFormattingLangOpts(const FormatStyle &Style) {
LangOptions LangOpts;
- FormatStyle::LanguageStandard LexingStd = Style.Standard;
- if (LexingStd == FormatStyle::LS_Auto)
- LexingStd = FormatStyle::LS_Latest;
- if (LexingStd == FormatStyle::LS_Latest)
+ auto LexingStd = Style.Standard;
+ if (LexingStd == FormatStyle::LS_Auto || LexingStd == FormatStyle::LS_Latest)
LexingStd = FormatStyle::LS_Cpp20;
- LangOpts.CPlusPlus = 1;
- LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
- LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
- LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
- LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
- LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
+
+ const bool SinceCpp11 = LexingStd >= FormatStyle::LS_Cpp11;
+ const bool SinceCpp20 = LexingStd >= FormatStyle::LS_Cpp20;
+
+ switch (Style.Language) {
+ case FormatStyle::LK_C:
+ LangOpts.C17 = 1;
+ break;
+ case FormatStyle::LK_Cpp:
+ case FormatStyle::LK_ObjC:
+ LangOpts.CXXOperatorNames = 1;
+ LangOpts.CPlusPlus11 = SinceCpp11;
+ LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
+ LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
+ LangOpts.CPlusPlus20 = SinceCpp20;
+ [[fallthrough]];
+ default:
+ LangOpts.CPlusPlus = 1;
+ }
+
+ LangOpts.Char8 = SinceCpp20;
// Turning on digraphs in standards before C++0x is error-prone, because e.g.
// the sequence "<::" will be unconditionally treated as "[:".
// Cf. Lexer::LexTokenInternal.
- LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
+ LangOpts.Digraphs = SinceCpp11;
LangOpts.LineComment = 1;
-
- const auto Language = Style.Language;
- LangOpts.C17 = Language == FormatStyle::LK_C;
- LangOpts.CXXOperatorNames =
- Language == FormatStyle::LK_Cpp || Language == FormatStyle::LK_ObjC;
-
LangOpts.Bool = 1;
LangOpts.ObjC = 1;
LangOpts.MicrosoftExt = 1; // To get kw___try, kw___finally.
LangOpts.DeclSpecKeyword = 1; // To get __declspec.
LangOpts.C99 = 1; // To get kw_restrict for non-underscore-prefixed restrict.
+
return LangOpts;
}