aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2012-12-06 18:03:27 +0000
committerAlexander Kornienko <alexfh@google.com>2012-12-06 18:03:27 +0000
commit15757316d67cb7a854d53a0402d67ad58347600a (patch)
treefc3e055fa4fbe5539cab47209eb3840611a6a971 /lib/Format/UnwrappedLineParser.cpp
parent762661a077ffa73580d556a9dd149830662d972e (diff)
Clang-format: IndentCaseLabels option, proper namespace handling
Summary: + tests arranged in groups, as their number is already quite large. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D185 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169520 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--lib/Format/UnwrappedLineParser.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 425e15b81f..ebebece7eb 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -22,9 +22,11 @@
namespace clang {
namespace format {
-UnwrappedLineParser::UnwrappedLineParser(Lexer &Lex, SourceManager &SourceMgr,
+UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style, Lexer &Lex,
+ SourceManager &SourceMgr,
UnwrappedLineConsumer &Callback)
: GreaterStashed(false),
+ Style(Style),
Lex(Lex),
SourceMgr(SourceMgr),
IdentTable(Lex.getLangOpts()),
@@ -62,20 +64,16 @@ bool UnwrappedLineParser::parseLevel() {
return Error;
}
-bool UnwrappedLineParser::parseBlock() {
+bool UnwrappedLineParser::parseBlock(unsigned AddLevels) {
assert(FormatTok.Tok.is(tok::l_brace) && "'{' expected");
nextToken();
- // FIXME: Remove this hack to handle namespaces.
- bool IsNamespace = Line.Tokens[0].Tok.is(tok::kw_namespace);
-
addUnwrappedLine();
- if (!IsNamespace)
- ++Line.Level;
+ Line.Level += AddLevels;
parseLevel();
- if (!IsNamespace)
- --Line.Level;
+ Line.Level -= AddLevels;
+
// FIXME: Add error handling.
if (!FormatTok.Tok.is(tok::r_brace))
return true;
@@ -114,6 +112,9 @@ void UnwrappedLineParser::parseStatement() {
}
switch (FormatTok.Tok.getKind()) {
+ case tok::kw_namespace:
+ parseNamespace();
+ return;
case tok::kw_public:
case tok::kw_protected:
case tok::kw_private:
@@ -224,6 +225,18 @@ void UnwrappedLineParser::parseIfThenElse() {
}
}
+void UnwrappedLineParser::parseNamespace() {
+ assert(FormatTok.Tok.is(tok::kw_namespace) && "'namespace' expected");
+ nextToken();
+ if (FormatTok.Tok.is(tok::identifier))
+ nextToken();
+ if (FormatTok.Tok.is(tok::l_brace)) {
+ parseBlock(0);
+ addUnwrappedLine();
+ }
+ // FIXME: Add error handling.
+}
+
void UnwrappedLineParser::parseForOrWhileLoop() {
assert((FormatTok.Tok.is(tok::kw_for) || FormatTok.Tok.is(tok::kw_while)) &&
"'for' or 'while' expected");
@@ -290,13 +303,13 @@ void UnwrappedLineParser::parseSwitch() {
nextToken();
parseParens();
if (FormatTok.Tok.is(tok::l_brace)) {
- parseBlock();
+ parseBlock(Style.IndentCaseLabels ? 2 : 1);
addUnwrappedLine();
} else {
addUnwrappedLine();
- ++Line.Level;
+ Line.Level += (Style.IndentCaseLabels ? 2 : 1);
parseStatement();
- --Line.Level;
+ Line.Level -= (Style.IndentCaseLabels ? 2 : 1);
}
}