aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/RAIIObjectsForParser.h
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-06-17 10:52:18 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-06-17 10:52:18 +0000
commit36d36806f1972f7ec1d2a3f59155187278c56508 (patch)
tree192bc210f97918d96aa56b1f9e3bd8bc273dfe8f /lib/Parse/RAIIObjectsForParser.h
parent2574f6f35a54c1c1b5bcef1e69417fe58f566c11 (diff)
Make sure parens/braces/brackets are correctly balanced.
In a line like: (; the semicolon leaves Parser:ParenCount unbalanced (it's 1 even though we stopped looking for a right paren). This may affect later parsing and result in bad recovery for parsing errors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106213 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/RAIIObjectsForParser.h')
-rw-r--r--lib/Parse/RAIIObjectsForParser.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Parse/RAIIObjectsForParser.h b/lib/Parse/RAIIObjectsForParser.h
index 06bbbc23a0..addc795083 100644
--- a/lib/Parse/RAIIObjectsForParser.h
+++ b/lib/Parse/RAIIObjectsForParser.h
@@ -80,6 +80,23 @@ namespace clang {
}
};
+ /// \brief RAII object that makes sure paren/bracket/brace count is correct
+ /// after declaration/statement parsing, even when there's a parsing error.
+ class ParenBraceBracketBalancer {
+ Parser &P;
+ unsigned short ParenCount, BracketCount, BraceCount;
+ public:
+ ParenBraceBracketBalancer(Parser &p)
+ : P(p), ParenCount(p.ParenCount), BracketCount(p.BracketCount),
+ BraceCount(p.BraceCount) { }
+
+ ~ParenBraceBracketBalancer() {
+ P.ParenCount = ParenCount;
+ P.BracketCount = BracketCount;
+ P.BraceCount = BraceCount;
+ }
+ };
+
} // end namespace clang
#endif