diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-05 22:14:16 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-05 22:14:16 +0000 |
commit | ef2cfb110d776dd9fc34c4154a1e6d5f774df25f (patch) | |
tree | c82efb543df9a485449b8c2bd6dca90e5da8bf1b | |
parent | feb9ae59d2f94b06897bb6f39f90f2486698523e (diff) | |
download | llvm-ef2cfb110d776dd9fc34c4154a1e6d5f774df25f.zip llvm-ef2cfb110d776dd9fc34c4154a1e6d5f774df25f.tar.gz llvm-ef2cfb110d776dd9fc34c4154a1e6d5f774df25f.tar.bz2 |
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.
llvm-svn: 171639
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.h | 3 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 7 |
3 files changed, 12 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index c1bafa9..2f3a603 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -27,10 +27,11 @@ public: 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 @@ public: 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 @@ private: UnwrappedLine &Line; FormatTokenSource *&TokenSource; FormatToken &ResetToken; - + unsigned PreviousLineLevel; FormatTokenSource *PreviousTokenSource; FormatToken Token; diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h index 69ac768..a8e5b73 100644 --- a/clang/lib/Format/UnwrappedLineParser.h +++ b/clang/lib/Format/UnwrappedLineParser.h @@ -124,6 +124,9 @@ private: 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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 89fe71c..2165056 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -466,9 +466,12 @@ TEST_F(FormatTest, HashInMacroDefinition) { " }", 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( |