From: Manuel Klimek Date: Wed, 6 May 2015 11:56:29 +0000 (+0000) Subject: Remove all computation of structural errors in clang-format's line parser. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13e7452f302ea1d047d33963397c9206420813b7;p=clang Remove all computation of structural errors in clang-format's line parser. We were already ignoring those already. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236591 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 8348a535a4..b41528ee56 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1225,7 +1225,7 @@ public: UnwrappedLineParser Parser(Style, Tokens.getKeywords(), Tokens.lex(), *this); - bool StructuralError = Parser.parse(); + Parser.parse(); assert(UnwrappedLines.rbegin()->empty()); for (unsigned Run = 0, RunE = UnwrappedLines.size(); Run + 1 != RunE; ++Run) { @@ -1234,8 +1234,7 @@ public: for (unsigned i = 0, e = UnwrappedLines[Run].size(); i != e; ++i) { AnnotatedLines.push_back(new AnnotatedLine(UnwrappedLines[Run][i])); } - tooling::Replacements RunResult = - format(AnnotatedLines, StructuralError, Tokens); + tooling::Replacements RunResult = format(AnnotatedLines, Tokens); DEBUG({ llvm::dbgs() << "Replacements for run " << Run << ":\n"; for (tooling::Replacements::iterator I = RunResult.begin(), @@ -1254,7 +1253,7 @@ public: } tooling::Replacements format(SmallVectorImpl &AnnotatedLines, - bool StructuralError, FormatTokenLexer &Tokens) { + FormatTokenLexer &Tokens) { TokenAnnotator Annotator(Style, Tokens.getKeywords()); for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) { Annotator.annotate(*AnnotatedLines[i]); diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index a1fe9cea3d..41c7fd1b22 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -58,11 +58,10 @@ private: class ScopedMacroState : public FormatTokenSource { public: ScopedMacroState(UnwrappedLine &Line, FormatTokenSource *&TokenSource, - FormatToken *&ResetToken, bool &StructuralError) + FormatToken *&ResetToken) : Line(Line), TokenSource(TokenSource), ResetToken(ResetToken), PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource), - StructuralError(StructuralError), - PreviousStructuralError(StructuralError), Token(nullptr) { + Token(nullptr) { TokenSource = this; Line.Level = 0; Line.InPPDirective = true; @@ -73,7 +72,6 @@ public: ResetToken = Token; Line.InPPDirective = false; Line.Level = PreviousLineLevel; - StructuralError = PreviousStructuralError; } FormatToken *getNextToken() override { @@ -112,8 +110,6 @@ private: FormatToken *&ResetToken; unsigned PreviousLineLevel; FormatTokenSource *PreviousTokenSource; - bool &StructuralError; - bool PreviousStructuralError; FormatToken *Token; }; @@ -208,9 +204,8 @@ UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style, ArrayRef Tokens, UnwrappedLineConsumer &Callback) : Line(new UnwrappedLine), MustBreakBeforeNextToken(false), - CurrentLines(&Lines), StructuralError(false), Style(Style), - Keywords(Keywords), Tokens(nullptr), Callback(Callback), - AllTokens(Tokens), PPBranchLevel(-1) {} + CurrentLines(&Lines), Style(Style), Keywords(Keywords), Tokens(nullptr), + Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1) {} void UnwrappedLineParser::reset() { PPBranchLevel = -1; @@ -221,11 +216,10 @@ void UnwrappedLineParser::reset() { PreprocessorDirectives.clear(); CurrentLines = &Lines; DeclarationScopeStack.clear(); - StructuralError = false; PPStack.clear(); } -bool UnwrappedLineParser::parse() { +void UnwrappedLineParser::parse() { IndexedTokenSource TokenSource(AllTokens); do { DEBUG(llvm::dbgs() << "----\n"); @@ -258,7 +252,6 @@ bool UnwrappedLineParser::parse() { } } while (!PPLevelBranchIndex.empty()); - return StructuralError; } void UnwrappedLineParser::parseFile() { @@ -291,7 +284,6 @@ void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) { case tok::r_brace: if (HasOpeningBrace) return; - StructuralError = true; nextToken(); addUnwrappedLine(); break; @@ -413,7 +405,6 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel, if (!FormatTok->Tok.is(tok::r_brace)) { Line->Level = InitialLevel; - StructuralError = true; return; } @@ -473,7 +464,7 @@ void UnwrappedLineParser::parseChildBlock() { void UnwrappedLineParser::parsePPDirective() { assert(FormatTok->Tok.is(tok::hash) && "'#' expected"); - ScopedMacroState MacroState(*Line, Tokens, FormatTok, StructuralError); + ScopedMacroState MacroState(*Line, Tokens, FormatTok); nextToken(); if (!FormatTok->Tok.getIdentifierInfo()) { @@ -1216,8 +1207,6 @@ void UnwrappedLineParser::parseTryCatch() { nextToken(); if (FormatTok->is(tok::l_paren)) parseParens(); - else - StructuralError = true; if (FormatTok->is(tok::comma)) nextToken(); } @@ -1240,7 +1229,6 @@ void UnwrappedLineParser::parseTryCatch() { // The C++ standard requires a compound-statement after a try. // If there's none, we try to assume there's a structuralElement // and try to continue. - StructuralError = true; addUnwrappedLine(); ++Line->Level; parseStructuralElement(); diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h index 76c62cdc1d..06c80e1387 100644 --- a/lib/Format/UnwrappedLineParser.h +++ b/lib/Format/UnwrappedLineParser.h @@ -65,8 +65,7 @@ public: ArrayRef Tokens, UnwrappedLineConsumer &Callback); - /// Returns true in case of a structural error. - bool parse(); + void parse(); private: void reset(); @@ -158,10 +157,6 @@ private: // whether we are in a compound statement or not. std::vector DeclarationScopeStack; - // Will be true if we encounter an error that leads to possibily incorrect - // indentation levels. - bool StructuralError; - const FormatStyle &Style; const AdditionalKeywords &Keywords;