summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-01-06 20:07:31 +0000
committerManuel Klimek <klimek@google.com>2013-01-06 20:07:31 +0000
commit1058d987f98b942aa5919f5e2fab3c5b734b68a6 (patch)
tree806765e38c952630f361ab93814b5707ced3d376 /clang/lib/Format/UnwrappedLineParser.cpp
parent3fb03e23a42b064877497bb9c045b99693d14c95 (diff)
downloadbcm5719-llvm-1058d987f98b942aa5919f5e2fab3c5b734b68a6.tar.gz
bcm5719-llvm-1058d987f98b942aa5919f5e2fab3c5b734b68a6.zip
Fixes handling of unbalances braces.
If we find an unexpected closing brace, we must not stop parsing, as we'd otherwise not layout anything beyond that point. If we find a structural error on the highest level we'll not re-indent anyway, but we'll still want to format within unwrapped lines. Needed to introduce a differentiation between an expected and unexpected closing brace. llvm-svn: 171666
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 72b47503ee8..00710827c2a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -84,13 +84,13 @@ bool UnwrappedLineParser::parse() {
}
bool UnwrappedLineParser::parseFile() {
- bool Error = parseLevel();
+ bool Error = parseLevel(/*HasOpeningBrace=*/false);
// Make sure to format the remaining tokens.
addUnwrappedLine();
return Error;
}
-bool UnwrappedLineParser::parseLevel() {
+bool UnwrappedLineParser::parseLevel(bool HasOpeningBrace) {
bool Error = false;
do {
switch (FormatTok.Tok.getKind()) {
@@ -103,8 +103,15 @@ bool UnwrappedLineParser::parseLevel() {
addUnwrappedLine();
break;
case tok::r_brace:
- // Stray '}' is an error.
- return true;
+ if (HasOpeningBrace) {
+ return false;
+ } else {
+ // Stray '}' is an error.
+ Error = true;
+ nextToken();
+ addUnwrappedLine();
+ }
+ break;
default:
parseStatement();
break;
@@ -120,7 +127,7 @@ bool UnwrappedLineParser::parseBlock(unsigned AddLevels) {
addUnwrappedLine();
Line.Level += AddLevels;
- parseLevel();
+ parseLevel(/*HasOpeningBrace=*/true);
Line.Level -= AddLevels;
// FIXME: Add error handling.
OpenPOWER on IntegriCloud