diff options
author | Manuel Klimek <klimek@google.com> | 2013-10-11 21:25:45 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-10-11 21:25:45 +0000 |
commit | 71814b44658523f5fc747475ad8b40c9197565e2 (patch) | |
tree | fa39904587c053d3ec68c96d7d11de801ddfd182 /clang/lib/Format/WhitespaceManager.cpp | |
parent | 4c42732cf869d167e48a15afe280cb847984e7a5 (diff) | |
download | llvm-71814b44658523f5fc747475ad8b40c9197565e2.zip llvm-71814b44658523f5fc747475ad8b40c9197565e2.tar.gz llvm-71814b44658523f5fc747475ad8b40c9197565e2.tar.bz2 |
Support formatting of preprocessor branches.
We now correctly format:
void SomeFunction(int param1,
#ifdef X
NoTemplate param2,
#else
template <
#ifdef A
MyType<Some> >
#else
Type1, Type2>
#endif
param2,
#endif
param3) {
f();
}
llvm-svn: 192503
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 16d80ea..c24ccdf 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -39,11 +39,18 @@ WhitespaceManager::Change::Change( ContinuesPPDirective(ContinuesPPDirective), IndentLevel(IndentLevel), Spaces(Spaces) {} -void WhitespaceManager::replaceWhitespace(const FormatToken &Tok, - unsigned Newlines, +void WhitespaceManager::reset() { + Changes.clear(); + Replaces.clear(); +} + +void WhitespaceManager::replaceWhitespace(FormatToken &Tok, unsigned Newlines, unsigned IndentLevel, unsigned Spaces, unsigned StartOfTokenColumn, bool InPPDirective) { + if (Tok.Finalized) + return; + Tok.Decision = (Newlines > 0) ? FD_Break : FD_Continue; Changes.push_back(Change(true, Tok.WhitespaceRange, IndentLevel, Spaces, StartOfTokenColumn, Newlines, "", "", Tok.Tok.getKind(), InPPDirective && !Tok.IsFirst)); @@ -51,6 +58,8 @@ void WhitespaceManager::replaceWhitespace(const FormatToken &Tok, void WhitespaceManager::addUntouchableToken(const FormatToken &Tok, bool InPPDirective) { + if (Tok.Finalized) + return; Changes.push_back(Change(false, Tok.WhitespaceRange, /*IndentLevel=*/0, /*Spaces=*/0, Tok.OriginalColumn, Tok.NewlinesBefore, "", "", Tok.Tok.getKind(), @@ -61,6 +70,8 @@ void WhitespaceManager::replaceWhitespaceInToken( const FormatToken &Tok, unsigned Offset, unsigned ReplaceChars, StringRef PreviousPostfix, StringRef CurrentPrefix, bool InPPDirective, unsigned Newlines, unsigned IndentLevel, unsigned Spaces) { + if (Tok.Finalized) + return; Changes.push_back(Change( true, SourceRange(Tok.getStartOfNonWhitespace().getLocWithOffset(Offset), Tok.getStartOfNonWhitespace().getLocWithOffset( |