[clang-format] Tidy up new API guessLanguage()
Summary:
This fixes a few issues djasper@ brought up in his review of D43522.
Test Plan:
make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43598
llvm-svn: 326205
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index b82aab9..9229e22 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2295,8 +2295,8 @@
}
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
- FormatStyle::LanguageKind result = getLanguageByFileName(FileName);
- if (result == FormatStyle::LK_Cpp) {
+ const auto GuessedLanguage = getLanguageByFileName(FileName);
+ if (GuessedLanguage == FormatStyle::LK_Cpp) {
auto Extension = llvm::sys::path::extension(FileName);
// If there's no file extension (or it's .h), we need to check the contents
// of the code to see if it contains Objective-C.
@@ -2306,12 +2306,11 @@
Environment::CreateVirtualEnvironment(Code, NonEmptyFileName, /*Ranges=*/{});
ObjCHeaderStyleGuesser Guesser(*Env, getLLVMStyle());
Guesser.process();
- if (Guesser.isObjC()) {
- result = FormatStyle::LK_ObjC;
- }
+ if (Guesser.isObjC())
+ return FormatStyle::LK_ObjC;
}
}
- return result;
+ return GuessedLanguage;
}
llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,