summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorBen Hamilton <benhamilton@google.com>2018-02-27 15:56:40 +0000
committerBen Hamilton <benhamilton@google.com>2018-02-27 15:56:40 +0000
commit6e066350d8dcfac70e8a038e9ea580dacb56d08d (patch)
tree0013dd76f4e78b81968f924f04d31052bdbd6ae1 /clang/lib/Format/Format.cpp
parent497fd98af2fff16b5b885f1bdac3b9b039f5080f (diff)
downloadbcm5719-llvm-6e066350d8dcfac70e8a038e9ea580dacb56d08d.tar.gz
bcm5719-llvm-6e066350d8dcfac70e8a038e9ea580dacb56d08d.zip
[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
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index b82aab97113..9229e224ea8 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2295,8 +2295,8 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
}
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 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
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,
OpenPOWER on IntegriCloud