diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-12-02 15:21:38 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-12-02 15:21:38 +0000 |
commit | 34451b1a84817de73e4db3bd5e15db1a91c9009b (patch) | |
tree | ae9346efce8e35f9d41f7ef6d79be6aaddffd9db /tools/clang-format/ClangFormat.cpp | |
parent | ad6ee4b59967d864aa59723bce473a97b2465a19 (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196108 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format/ClangFormat.cpp')
-rw-r--r-- | tools/clang-format/ClangFormat.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index 768165b92e..513439649d 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/tools/clang-format/ClangFormat.cpp @@ -62,6 +62,12 @@ static cl::opt<std::string> Style("style", cl::desc(clang::format::StyleOptionHelpDescription), cl::init("file"), cl::cat(ClangFormatCategory)); +static cl::opt<std::string> +FallbackStyle("fallback-style", + cl::desc("The name of the predefined style used as a fallback in " + "case clang-format is invoked with -style=file, but can " + "not find the .clang-format file to use."), + cl::init("LLVM"), cl::cat(ClangFormatCategory)); static cl::opt<std::string> AssumeFilename("assume-filename", @@ -192,8 +198,8 @@ static bool format(StringRef FileName) { if (fillRanges(Sources, ID, Code.get(), Ranges)) return true; - FormatStyle FormatStyle = - getStyle(Style, (FileName == "-") ? AssumeFilename : FileName); + FormatStyle FormatStyle = getStyle( + Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle); Lexer Lex(ID, Sources.getBuffer(ID), Sources, getFormattingLangOpts(FormatStyle.Standard)); tooling::Replacements Replaces = reformat(FormatStyle, Lex, Sources, Ranges); @@ -256,7 +262,8 @@ int main(int argc, const char **argv) { if (DumpConfig) { std::string Config = clang::format::configurationAsText(clang::format::getStyle( - Style, FileNames.empty() ? AssumeFilename : FileNames[0])); + Style, FileNames.empty() ? AssumeFilename : FileNames[0], + FallbackStyle)); llvm::outs() << Config << "\n"; return 0; } |