]> granicus.if.org Git - clang/commitdiff
Remove all computation of structural errors in clang-format's line parser.
authorManuel Klimek <klimek@google.com>
Wed, 6 May 2015 11:56:29 +0000 (11:56 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 6 May 2015 11:56:29 +0000 (11:56 +0000)
We were already ignoring those already.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236591 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
lib/Format/UnwrappedLineParser.cpp
lib/Format/UnwrappedLineParser.h

index 8348a535a43e8e9d699b4c36381cbb332b7514e5..b41528ee5671864c1e0a0603c9a36c7955c14653 100644 (file)
@@ -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<AnnotatedLine *> &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]);
index a1fe9cea3de9eb51bc48ad6652d05ac7a7f07740..41c7fd1b220c84dfefecfca55c13822c7f4a93b2 100644 (file)
@@ -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<FormatToken *> 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();
index 76c62cdc1d8e9d381a076b7a5b975a2c2a7e6385..06c80e1387d7c8cdfecc391022bc15a901c6c4d2 100644 (file)
@@ -65,8 +65,7 @@ public:
                       ArrayRef<FormatToken *> 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<bool> DeclarationScopeStack;
 
-  // Will be true if we encounter an error that leads to possibily incorrect
-  // indentation levels.
-  bool StructuralError;
-
   const FormatStyle &Style;
   const AdditionalKeywords &Keywords;