summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-12-02 15:21:38 +0000
committerAlexander Kornienko <alexfh@google.com>2013-12-02 15:21:38 +0000
commitbc4ae44928f5b96c554b83f926c4caebe728d18f (patch)
tree416010eb1dde963e76606a0e4e3d7c0ba6bff719 /clang/lib/Format
parent9beb517307aa5617e7597af6d8b64eebf21d8e68 (diff)
downloadbcm5719-llvm-bc4ae44928f5b96c554b83f926c4caebe728d18f.tar.gz
bcm5719-llvm-bc4ae44928f5b96c554b83f926c4caebe728d18f.zip
Added an option to specify fallback style.
Summary: Added -fallback-style option. Changed clang-format to stop searching for .clang-format when an invalid file is found. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2292 llvm-svn: 196108
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/Format.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 28ef19e192f..ee9fe7625db 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1661,12 +1661,14 @@ static void fillLanguageByFileName(StringRef FileName, FormatStyle *Style) {
}
}
-FormatStyle getStyle(StringRef StyleName, StringRef FileName) {
- // FIXME: Configure fallback style from outside (add a command line option).
- // Fallback style in case the rest of this function can't determine a style.
- StringRef FallbackStyle = "LLVM";
+FormatStyle getStyle(StringRef StyleName, StringRef FileName,
+ StringRef FallbackStyle) {
FormatStyle Style;
- getPredefinedStyle(FallbackStyle, &Style);
+ if (!getPredefinedStyle(FallbackStyle, &Style)) {
+ llvm::errs() << "Invalid fallback style \"" << FallbackStyle
+ << "\" using LLVM style\n";
+ return getLLVMStyle();
+ }
fillLanguageByFileName(FileName, &Style);
if (StyleName.startswith("{")) {
@@ -1715,18 +1717,18 @@ FormatStyle getStyle(StringRef StyleName, StringRef FileName) {
if (llvm::error_code ec =
llvm::MemoryBuffer::getFile(ConfigFile.c_str(), Text)) {
llvm::errs() << ec.message() << "\n";
- continue;
+ break;
}
if (llvm::error_code ec = parseConfiguration(Text->getBuffer(), &Style)) {
if (ec == llvm::errc::not_supported) {
if (!UnsuitableConfigFiles.empty())
UnsuitableConfigFiles.append(", ");
UnsuitableConfigFiles.append(ConfigFile);
- } else {
- llvm::errs() << "Error reading " << ConfigFile << ": " << ec.message()
- << "\n";
+ continue;
}
- continue;
+ llvm::errs() << "Error reading " << ConfigFile << ": " << ec.message()
+ << "\n";
+ break;
}
DEBUG(llvm::dbgs() << "Using configuration file " << ConfigFile << "\n");
return Style;
OpenPOWER on IntegriCloud