diff options
| author | Alexander Kornienko <alexfh@google.com> | 2013-05-10 11:56:10 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2013-05-10 11:56:10 +0000 |
| commit | 49149677d96672a598a05e56ea105035ff777a76 (patch) | |
| tree | 6da81faf18971fbc0aa1f4bee45340df3bc8da39 /clang/lib/Format/Format.cpp | |
| parent | 3154a10bcb440bfbf5b1b918bc2b649cb9eb5ce0 (diff) | |
| download | bcm5719-llvm-49149677d96672a598a05e56ea105035ff777a76.tar.gz bcm5719-llvm-49149677d96672a598a05e56ea105035ff777a76.zip | |
Config file support for clang-format, part 2.
Summary:
Adds actual config file reading to the clang-format utility.
Configuration file name is .clang-format. It is looked up for each input file
in its parent directories starting from immediate one. First found .clang-format
file is used. When using standard input, .clang-format is searched starting from
the current directory.
Added -dump-config option to easily create configuration files.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, jordan_rose, kimgr
Differential Revision: http://llvm-reviews.chandlerc.com/D758
llvm-svn: 181589
Diffstat (limited to 'clang/lib/Format/Format.cpp')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 2413e43b138..fe8567de64b 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -46,10 +46,19 @@ struct ScalarEnumerationTraits<clang::format::FormatStyle::LanguageStandard> { template <> struct MappingTraits<clang::format::FormatStyle> { static void mapping(llvm::yaml::IO &IO, clang::format::FormatStyle &Style) { - if (!IO.outputting()) { + if (IO.outputting()) { + StringRef StylesArray[] = { "LLVM", "Google", "Chromium", "Mozilla" }; + ArrayRef<StringRef> Styles(StylesArray); + for (size_t i = 0, e = Styles.size(); i < e; ++i) { + StringRef StyleName(Styles[i]); + if (Style == clang::format::getPredefinedStyle(StyleName)) { + IO.mapOptional("# BasedOnStyle", StyleName); + break; + } + } + } else { StringRef BasedOnStyle; IO.mapOptional("BasedOnStyle", BasedOnStyle); - if (!BasedOnStyle.empty()) Style = clang::format::getPredefinedStyle(BasedOnStyle); } @@ -245,9 +254,9 @@ public: private: void DebugTokenState(const AnnotatedToken &AnnotatedTok) { const Token &Tok = AnnotatedTok.FormatTok.Tok; - llvm::errs() << StringRef(SourceMgr.getCharacterData(Tok.getLocation()), + llvm::dbgs() << StringRef(SourceMgr.getCharacterData(Tok.getLocation()), Tok.getLength()); - llvm::errs(); + llvm::dbgs(); } struct ParenState { @@ -825,7 +834,7 @@ private: unsigned Penalty = Queue.top().first.first; StateNode *Node = Queue.top().second; if (Node->State.NextToken == NULL) { - DEBUG(llvm::errs() << "\n---\nPenalty for line: " << Penalty << "\n"); + DEBUG(llvm::dbgs() << "\n---\nPenalty for line: " << Penalty << "\n"); break; } Queue.pop(); @@ -845,8 +854,8 @@ private: // Reconstruct the solution. reconstructPath(InitialState, Queue.top().second); - DEBUG(llvm::errs() << "Total number of analyzed states: " << Count << "\n"); - DEBUG(llvm::errs() << "---\n"); + DEBUG(llvm::dbgs() << "Total number of analyzed states: " << Count << "\n"); + DEBUG(llvm::dbgs() << "---\n"); // Return the column after the last token of the solution. return Queue.top().second->State.Column; @@ -862,7 +871,7 @@ private: reconstructPath(State, Current->Previous); DEBUG({ if (Current->NewLine) { - llvm::errs() + llvm::dbgs() << "Penalty for splitting before " << Current->Previous->State.NextToken->FormatTok.Tok.getName() << ": " << Current->Previous->State.NextToken->SplitPenalty << "\n"; |

