summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-01-02 16:30:12 +0000
committerManuel Klimek <klimek@google.com>2013-01-02 16:30:12 +0000
commita71e5d811575921da9b8e80c123bd58134d67feb (patch)
tree8f07e391926af7100929ed6dc73e36f8034251f6 /clang/lib/Format/UnwrappedLineParser.cpp
parent542de16e5064bfaf33023483f1b40f8e51bcb632 (diff)
downloadbcm5719-llvm-a71e5d811575921da9b8e80c123bd58134d67feb.tar.gz
bcm5719-llvm-a71e5d811575921da9b8e80c123bd58134d67feb.zip
Fixes use of unescaped newlines when formatting preprocessor directives.
This is the first step towards handling preprocessor directives. This patch only fixes the most pressing issue, namely correctly escaping newlines for tokens within a sequence of a preprocessor directive. The next step will be to fix incorrect format decisions on #define directives. llvm-svn: 171393
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 78a1abdcf8d..614125b9437 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -80,13 +80,25 @@ bool UnwrappedLineParser::parseBlock(unsigned AddLevels) {
}
void UnwrappedLineParser::parsePPDirective() {
- while (!eof()) {
- nextToken();
- if (FormatTok.NewlinesBefore > 0) {
- addUnwrappedLine();
- return;
- }
+ assert(FormatTok.Tok.is(tok::hash) && "'#' expected");
+ nextToken();
+
+ Line.InPPDirective = true;
+ if (FormatTok.Tok.getIdentifierInfo() == NULL) {
+ addUnwrappedLine();
+ Line.InPPDirective = false;
+ return;
}
+
+ do {
+ if (FormatTok.NewlinesBefore > 0 &&
+ FormatTok.HasUnescapedNewline) {
+ break;
+ }
+ nextToken();
+ } while (!eof());
+ addUnwrappedLine();
+ Line.InPPDirective = false;
}
void UnwrappedLineParser::parseComments() {
OpenPOWER on IntegriCloud