summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-01-05 22:56:06 +0000
committerManuel Klimek <klimek@google.com>2013-01-05 22:56:06 +0000
commit52d0fd8961ef4d03e042ac9eb1b30610518e3016 (patch)
tree66f1f3dd31828000ce6c155da69c284c020ced81 /clang/lib/Format/Format.cpp
parentef2cfb110d776dd9fc34c4154a1e6d5f774df25f (diff)
downloadbcm5719-llvm-52d0fd8961ef4d03e042ac9eb1b30610518e3016.tar.gz
bcm5719-llvm-52d0fd8961ef4d03e042ac9eb1b30610518e3016.zip
Fixes parsing of hash tokens in the middle of a line.
To parse # correctly, we need to know whether it is the first token in a line - we can deduct this either from the whitespace or seeing that the token is the first in the file - we already calculate this information. This patch moves the identification of the first token into the getNextToken method and stores it inside the FormatToken, so the UnwrappedLineParser can stay independent of the SourceManager. llvm-svn: 171640
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index effe0bc2482..4d401a5be9e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -483,8 +483,7 @@ private:
unsigned Newlines =
std::min(Token.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
- unsigned Offset = SourceMgr.getFileOffset(Token.WhiteSpaceStart);
- if (Newlines == 0 && Offset != 0)
+ if (Newlines == 0 && !Token.IsFirst)
Newlines = 1;
unsigned Indent = Line.Level * 2;
if ((Token.Tok.is(tok::kw_public) || Token.Tok.is(tok::kw_protected) ||
@@ -685,9 +684,10 @@ public:
next();
if (Index >= Tokens.size())
return;
- // It is the responsibility of the UnwrappedLineParser to make sure
- // this sequence is not produced inside an unwrapped line.
- assert(Tokens[Index].Tok.getIdentifierInfo() != NULL);
+ // Hashes in the middle of a line can lead to any strange token
+ // sequence.
+ if (Tokens[Index].Tok.getIdentifierInfo() == NULL)
+ return;
switch (Tokens[Index].Tok.getIdentifierInfo()->getPPKeywordID()) {
case tok::pp_include:
case tok::pp_import:
@@ -1033,6 +1033,8 @@ public:
Lex.LexFromRawLexer(FormatTok.Tok);
StringRef Text = tokenText(FormatTok.Tok);
FormatTok.WhiteSpaceStart = FormatTok.Tok.getLocation();
+ if (SourceMgr.getFileOffset(FormatTok.WhiteSpaceStart) == 0)
+ FormatTok.IsFirst = true;
// Consume and record whitespace until we find a significant token.
while (FormatTok.Tok.is(tok::unknown)) {
OpenPOWER on IntegriCloud