[cfe-commits] r171639 - in /cfe/trunk: lib/Format/UnwrappedLineParser.cpp lib/Format/UnwrappedLineParser.h unittests/Format/FormatTest.cpp

Manuel Klimek klimek at google.com
Sat Jan 5 14:14:16 PST 2013


Author: klimek
Date: Sat Jan  5 16:14:16 2013
New Revision: 171639

URL: http://llvm.org/viewvc/llvm-project?rev=171639&view=rev
Log:
Fixes PR14801 - preprocessor directives shouldn't be indented

Uses indent 0 for macros for now and resets the indent state to the
level prior to the preprocessor directive.

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=171639&r1=171638&r2=171639&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sat Jan  5 16:14:16 2013
@@ -27,10 +27,11 @@
   ScopedMacroState(UnwrappedLine &Line, FormatTokenSource *&TokenSource,
                    FormatToken &ResetToken)
       : Line(Line), TokenSource(TokenSource), ResetToken(ResetToken),
-        PreviousTokenSource(TokenSource) {
+        PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource) {
     TokenSource = this;
     // FIXME: Back up all other state (errors, line indent, etc) and reset after
     // parsing the macro.
+    Line.Level = 0;
     Line.InPPDirective = true;
   }
 
@@ -38,7 +39,7 @@
     TokenSource = PreviousTokenSource;
     ResetToken = Token;
     Line.InPPDirective = false;
-    Line.Level = 0;  // FIXME: Test + this is obviously incorrect
+    Line.Level = PreviousLineLevel;
   }
 
   virtual FormatToken getNextToken() {
@@ -65,7 +66,7 @@
   UnwrappedLine &Line;
   FormatTokenSource *&TokenSource;
   FormatToken &ResetToken;
-
+  unsigned PreviousLineLevel;
   FormatTokenSource *PreviousTokenSource;
 
   FormatToken Token;

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=171639&r1=171638&r2=171639&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Sat Jan  5 16:14:16 2013
@@ -124,6 +124,9 @@
   void nextToken();
   void readToken();
 
+  // FIXME: We are constantly running into bugs where Line.Level is incorrectly
+  // subtracted from beyond 0. Introduce a method to subtract from Line.Level
+  // and use that everywhere in the Parser.
   UnwrappedLine Line;
   FormatToken FormatTok;
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171639&r1=171638&r2=171639&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Jan  5 16:14:16 2013
@@ -466,9 +466,12 @@
                "  }", getLLVMStyleWithColumns(11));
 }
 
+TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
+  EXPECT_EQ("{\n  {\n#define A\n  }\n}", format("{{\n#define A\n}}"));
+}
+
 // FIXME: write test for unbalanced braces in macros...
-// FIXME: test { { #include "a.h" } }
-// FIXME: test # in the middle of a statement without \n before it
+// FIXME: test # inside a normal statement (like {#define A b})
 
 TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) {
   EXPECT_EQ(





More information about the cfe-commits mailing list