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 | dd256314cf391063329e504f0ece46ee51bbfa2a (patch) | |
| tree | 54d11f2326b3c476466868b05738a2c6ff185b8a /lib/Format/Format.cpp | |
| parent | acf02715ab1aa1e5a791f20e0d1ca217af256823 (diff) | |
| download | clang-dd256314cf391063329e504f0ece46ee51bbfa2a.tar.gz clang-dd256314cf391063329e504f0ece46ee51bbfa2a.tar.bz2 clang-dd256314cf391063329e504f0ece46ee51bbfa2a.tar.xz | |
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181589 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
| -rw-r--r-- | lib/Format/Format.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 2413e43b13..fe8567de64 100644 --- a/lib/Format/Format.cpp +++ b/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"; |
