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;
}
TokenSource = PreviousTokenSource;
ResetToken = Token;
Line.InPPDirective = false;
- Line.Level = 0; // FIXME: Test + this is obviously incorrect
+ Line.Level = PreviousLineLevel;
}
virtual FormatToken getNextToken() {
UnwrappedLine &Line;
FormatTokenSource *&TokenSource;
FormatToken &ResetToken;
-
+ unsigned PreviousLineLevel;
FormatTokenSource *PreviousTokenSource;
FormatToken Token;
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;
" }", 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(