r179016 - Revert accidental commit r179015.

Daniel Jasper djasper at google.com
Mon Apr 8 03:45:45 PDT 2013


Author: djasper
Date: Mon Apr  8 05:45:44 2013
New Revision: 179016

URL: http://llvm.org/viewvc/llvm-project?rev=179016&view=rev
Log:
Revert accidental commit r179015.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/lib/Format/TokenAnnotator.h
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=179016&r1=179015&r2=179016&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Apr  8 05:45:44 2013
@@ -86,6 +86,12 @@ static bool isTrailingComment(const Anno
          (Tok.Children.empty() || Tok.Children[0].MustBreakBefore);
 }
 
+static bool isComparison(const AnnotatedToken &Tok) {
+  prec::Level Precedence = getPrecedence(Tok);
+  return Tok.Type == TT_BinaryOperator &&
+         (Precedence == prec::Equality || Precedence == prec::Relational);
+}
+
 // Returns the length of everything up to the first possible line break after
 // the ), ], } or > matching \c Tok.
 static unsigned getLengthToMatchingParen(const AnnotatedToken &Tok) {
@@ -486,6 +492,10 @@ public:
     State.StartOfStringLiteral = 0;
     State.StartOfLineLevel = State.ParenLevel;
 
+    DEBUG({
+      DebugTokenState(*State.NextToken);
+    });
+
     // The first token has already been indented and thus consumed.
     moveStateToNextToken(State, /*DryRun=*/ false);
 
@@ -731,7 +741,8 @@ private:
           State.Stack.back().ColonPos =
               State.Column + Current.FormatTok.TokenLength;
         }
-      } else if (Current.Type == TT_StartOfName || Previous.is(tok::equal) ||
+      } else if (Current.Type == TT_StartOfName || Current.is(tok::question) ||
+                 Previous.is(tok::equal) || isComparison(Previous) ||
                  Previous.Type == TT_ObjCMethodExpr) {
         State.Column = ContinuationIndent;
       } else {
@@ -868,13 +879,10 @@ private:
       State.Stack.back().StartOfFunctionCall =
           Current.LastInChainOfCalls ? 0 : State.Column;
     if (Current.Type == TT_CtorInitializerColon) {
-      State.Stack.back().Indent = State.Column + 2;
       if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
         State.Stack.back().AvoidBinPacking = true;
       State.Stack.back().BreakBeforeParameter = false;
     }
-    if (Current.is(tok::kw_return))
-      State.Stack.back().LastSpace = State.Column + 7;
 
     // In ObjC method declaration we align on the ":" of parameters, but we need
     // to ensure that we indent parameters on subsequent lines by at least 4.
@@ -882,15 +890,9 @@ private:
       State.Stack.back().Indent += 4;
 
     // Insert scopes created by fake parenthesis.
-    for (SmallVector<unsigned, 4>::const_reverse_iterator
-             I = Current.FakeLParens.rbegin(),
-             E = Current.FakeLParens.rend();
-         I != E; ++I) {
+    for (unsigned i = 0, e = Current.FakeLParens; i != e; ++i) {
       ParenState NewParenState = State.Stack.back();
-      NewParenState.Indent = //State.Stack.back().LastSpace;
-          std::max(State.Column, State.Stack.back().LastSpace);
-      if ((*I > 3 && State.ParenLevel != 0) || *I == 4)
-        NewParenState.Indent += 4;
+      NewParenState.Indent = std::max(State.Column, State.Stack.back().Indent);
       NewParenState.BreakBeforeParameter = false;
       State.Stack.push_back(NewParenState);
     }

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=179016&r1=179015&r2=179016&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Apr  8 05:45:44 2013
@@ -16,7 +16,6 @@
 #include "TokenAnnotator.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
-#include "llvm/Support/Debug.h"
 
 namespace clang {
 namespace format {
@@ -783,9 +782,12 @@ public:
     if (Precedence > prec::PointerToMember || Current == NULL)
       return;
 
+    // Skip over "return" until we can properly parse it.
+    if (Current->is(tok::kw_return))
+      next();
+
     // Eagerly consume trailing comments.
-    while (Current && Current->FormatTok.NewlinesBefore == 0 &&
-           isTrailingComment(Current)) {
+    while (isTrailingComment(Current)) {
       next();
     }
 
@@ -800,7 +802,8 @@ public:
       if (Current) {
         if (Current->Type == TT_ConditionalExpr)
           CurrentPrecedence = 1 + (int) prec::Conditional;
-        else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon)
+        else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon ||
+                 Current->Type == TT_CtorInitializerColon)
           CurrentPrecedence = 1;
         else if (Current->Type == TT_BinaryOperator || Current->is(tok::comma))
           CurrentPrecedence = 1 + (int) getPrecedence(*Current);
@@ -811,7 +814,7 @@ public:
       if (Current == NULL || closesScope(*Current) ||
           (CurrentPrecedence != 0 && CurrentPrecedence < Precedence)) {
         if (OperatorFound) {
-          Start->FakeLParens.push_back(Precedence);
+          ++Start->FakeLParens;
           if (Current)
             ++Current->Parent->FakeRParens;
         }
@@ -826,9 +829,9 @@ public:
           parse();
         }
         // Remove fake parens that just duplicate the real parens.
-        if (Current && !Left->Children[0].FakeLParens.empty() &&
+        if (Current && Left->Children[0].FakeLParens > 0 &&
             Current->Parent->FakeRParens > 0) {
-          Left->Children[0].FakeLParens.pop_back();
+          --Left->Children[0].FakeLParens;
           --Current->Parent->FakeRParens;
         }
         next();
@@ -860,10 +863,6 @@ void TokenAnnotator::annotate(AnnotatedL
   ExpressionParser ExprParser(Line);
   ExprParser.parse();
 
-  DEBUG({
-    printDebugInfo(Line);
-  });
-
   if (Line.First.Type == TT_ObjCMethodSpecifier)
     Line.Type = LT_ObjCMethodDecl;
   else if (Line.First.Type == TT_ObjCDecl)
@@ -1188,19 +1187,5 @@ bool TokenAnnotator::canBreakBefore(cons
          (Left.is(tok::l_square) && !Right.is(tok::r_square));
 }
 
-void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) {
-  llvm::errs() << "AnnotatedTokens:\n";
-  const AnnotatedToken *Tok = &Line.First;
-  while (Tok) {
-    llvm::errs() << Tok->FormatTok.Tok.getName() << ":"
-                 << " Type=" << Tok->Type << " FakeLParens=";
-    for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i)
-      llvm::errs() << Tok->FakeLParens[i] << "/";
-    llvm::errs() << " FakeRParens=" << Tok->FakeRParens << "\n";
-    Tok = Tok->Children.empty() ? NULL : &Tok->Children[0];
-  }
-  llvm::errs() << "----\n";
-}
-
 } // namespace format
 } // namespace clang

Modified: cfe/trunk/lib/Format/TokenAnnotator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=179016&r1=179015&r2=179016&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.h (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.h Mon Apr  8 05:45:44 2013
@@ -75,7 +75,7 @@ public:
         CanBreakBefore(false), MustBreakBefore(false),
         ClosesTemplateDeclaration(false), MatchingParen(NULL),
         ParameterCount(0), BindingStrength(0), SplitPenalty(0),
-        LongestObjCSelectorName(0), Parent(NULL),
+        LongestObjCSelectorName(0), Parent(NULL), FakeLParens(0),
         FakeRParens(0), LastInChainOfCalls(false),
         PartOfMultiVariableDeclStmt(false) {}
 
@@ -158,9 +158,8 @@ public:
   std::vector<AnnotatedToken> Children;
   AnnotatedToken *Parent;
 
-  /// \brief Stores the number of required fake parenthesis and the
-  /// corresponding operator precedence.
-  SmallVector<unsigned, 4>  FakeLParens;
+  /// \brief Insert this many fake ( before this token for correct indentation.
+  unsigned FakeLParens;
   /// \brief Insert this many fake ) after this token for correct indentation.
   unsigned FakeRParens;
 
@@ -249,8 +248,6 @@ private:
 
   bool canBreakBefore(const AnnotatedLine &Line, const AnnotatedToken &Right);
 
-  void printDebugInfo(const AnnotatedLine &Line);
-
   const FormatStyle &Style;
   SourceManager &SourceMgr;
   Lexer &Lex;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=179016&r1=179015&r2=179016&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr  8 05:45:44 2013
@@ -1562,7 +1562,7 @@ TEST_F(FormatTest, BreaksAsHighAsPossibl
       "    f();\n"
       "}");
   verifyFormat("if (Intervals[i].getRange().getFirst() <\n"
-               "    Intervals[i - 1].getRange().getLast()) {\n}");
+               "        Intervals[i - 1].getRange().getLast()) {\n}");
 }
 
 TEST_F(FormatTest, BreaksDesireably) {
@@ -1681,13 +1681,13 @@ TEST_F(FormatTest, FormatsOneParameterPe
 TEST_F(FormatTest, FormatsBuilderPattern) {
   verifyFormat(
       "return llvm::StringSwitch<Reference::Kind>(name)\n"
-      "           .StartsWith(\".eh_frame_hdr\", ORDER_EH_FRAMEHDR)\n"
-      "           .StartsWith(\".eh_frame\", ORDER_EH_FRAME)\n"
-      "           .StartsWith(\".init\", ORDER_INIT).StartsWith(\".fini\", ORDER_FINI)\n"
-      "           .StartsWith(\".hash\", ORDER_HASH).Default(ORDER_TEXT);\n");
+      "    .StartsWith(\".eh_frame_hdr\", ORDER_EH_FRAMEHDR)\n"
+      "    .StartsWith(\".eh_frame\", ORDER_EH_FRAME).StartsWith(\".init\", ORDER_INIT)\n"
+      "    .StartsWith(\".fini\", ORDER_FINI).StartsWith(\".hash\", ORDER_HASH)\n"
+      "    .Default(ORDER_TEXT);\n");
 
   verifyFormat("return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <\n"
-               "       aaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();");
+               "           aaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();");
   verifyFormat(
       "aaaaaaa->aaaaaaa\n"
       "    ->aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
@@ -1784,10 +1784,10 @@ TEST_F(FormatTest, AlignsAfterReturn) {
       "        aaaaaaaaaaaaaaaaaaaaaaaaa);");
   verifyFormat(
       "return aaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >=\n"
-      "       aaaaaaaaaaaaaaaaaaaaaa();");
+      "           aaaaaaaaaaaaaaaaaaaaaa();");
   verifyFormat(
       "return (aaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >=\n"
-      "        aaaaaaaaaaaaaaaaaaaaaa());");
+      "            aaaaaaaaaaaaaaaaaaaaaa());");
 }
 
 TEST_F(FormatTest, BreaksConditionalExpressions) {
@@ -1831,9 +1831,9 @@ TEST_F(FormatTest, BreaksConditionalExpr
       "    ? aaaaaaaaaaaaaaa\n"
       "    : aaaaaaaaaaaaaaa;");
   verifyFormat("f(aaaaaaaaaaaaaaaa == // force break\n"
-               "      aaaaaaaaa\n"
-               "  ? b\n"
-               "  : c);");
+               "  aaaaaaaaa\n"
+               "      ? b\n"
+               "      : c);");
   verifyFormat(
       "unsigned Indent =\n"
       "    format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"





More information about the cfe-commits mailing list