summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-07-09 09:06:29 +0000
committerDaniel Jasper <djasper@google.com>2013-07-09 09:06:29 +0000
commitb1f74a815294822f32b80210df64c6cf1492952d (patch)
tree5a534c94edf8d6ebee78a35f187692c209980741 /clang/lib/Format/UnwrappedLineParser.cpp
parentf7f252d025ed6592fc0d999b069ab772517ad765 (diff)
downloadbcm5719-llvm-b1f74a815294822f32b80210df64c6cf1492952d.tar.gz
bcm5719-llvm-b1f74a815294822f32b80210df64c6cf1492952d.zip
Fix alignment of closing brace in braced initializers.
Before: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); After: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); To do so, the UnwrappedLineParser now stores the information about the kind of brace in the FormatToken. llvm-svn: 185914
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 98a5a8ae075..77f98bffda2 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -183,9 +183,7 @@ UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style,
UnwrappedLineConsumer &Callback)
: Line(new UnwrappedLine), MustBreakBeforeNextToken(false),
CurrentLines(&Lines), StructuralError(false), Style(Style), Tokens(NULL),
- Callback(Callback), AllTokens(Tokens) {
- LBraces.resize(Tokens.size(), BS_Unknown);
-}
+ Callback(Callback), AllTokens(Tokens) {}
bool UnwrappedLineParser::parse() {
DEBUG(llvm::dbgs() << "----\n");
@@ -252,7 +250,7 @@ void UnwrappedLineParser::calculateBraceTypes() {
// Keep a stack of positions of lbrace tokens. We will
// update information about whether an lbrace starts a
// braced init list or a different block during the loop.
- SmallVector<unsigned, 8> LBraceStack;
+ SmallVector<FormatToken *, 8> LBraceStack;
assert(Tok->Tok.is(tok::l_brace));
do {
// Get next none-comment token.
@@ -265,11 +263,11 @@ void UnwrappedLineParser::calculateBraceTypes() {
switch (Tok->Tok.getKind()) {
case tok::l_brace:
- LBraceStack.push_back(Position);
+ LBraceStack.push_back(Tok);
break;
case tok::r_brace:
if (!LBraceStack.empty()) {
- if (LBraces[LBraceStack.back()] == BS_Unknown) {
+ if (LBraceStack.back()->BlockKind == BK_Unknown) {
// If there is a comma, semicolon or right paren after the closing
// brace, we assume this is a braced initializer list.
@@ -279,10 +277,13 @@ void UnwrappedLineParser::calculateBraceTypes() {
// brace blocks inside it braced init list. That works good enough
// for now, but we will need to fix it to correctly handle lambdas.
if (NextTok->isOneOf(tok::comma, tok::semi, tok::r_paren,
- tok::l_brace, tok::colon))
- LBraces[LBraceStack.back()] = BS_BracedInit;
- else
- LBraces[LBraceStack.back()] = BS_Block;
+ tok::l_brace, tok::colon)) {
+ Tok->BlockKind = BK_BracedInit;
+ LBraceStack.back()->BlockKind = BK_BracedInit;
+ } else {
+ Tok->BlockKind = BK_Block;
+ LBraceStack.back()->BlockKind = BK_Block;
+ }
}
LBraceStack.pop_back();
}
@@ -294,7 +295,7 @@ void UnwrappedLineParser::calculateBraceTypes() {
case tok::kw_switch:
case tok::kw_try:
if (!LBraceStack.empty())
- LBraces[LBraceStack.back()] = BS_Block;
+ LBraceStack.back()->BlockKind = BK_Block;
break;
default:
break;
@@ -304,8 +305,8 @@ void UnwrappedLineParser::calculateBraceTypes() {
} while (Tok->Tok.isNot(tok::eof));
// Assume other blocks for all unclosed opening braces.
for (unsigned i = 0, e = LBraceStack.size(); i != e; ++i) {
- if (LBraces[LBraceStack[i]] == BS_Unknown)
- LBraces[LBraceStack[i]] = BS_Block;
+ if (LBraceStack[i]->BlockKind == BK_Unknown)
+ LBraceStack[i]->BlockKind = BK_Block;
}
FormatTok = Tokens->setPosition(StoredPosition);
}
@@ -632,10 +633,10 @@ void UnwrappedLineParser::parseStructuralElement() {
}
bool UnwrappedLineParser::tryToParseBracedList() {
- if (LBraces[Tokens->getPosition()] == BS_Unknown)
+ if (FormatTok->BlockKind == BK_Unknown)
calculateBraceTypes();
- assert(LBraces[Tokens->getPosition()] != BS_Unknown);
- if (LBraces[Tokens->getPosition()] == BS_Block)
+ assert(FormatTok->BlockKind != BK_Unknown);
+ if (FormatTok->BlockKind == BK_Block)
return false;
parseBracedList();
return true;
OpenPOWER on IntegriCloud