Revamps structural error detection / handling.
Previously we'd only detect structural errors on the very first level.
This leads to incorrectly balanced braces not being discovered, and thus
incorrect indentation.
This change fixes the problem by:
- changing the parser to use an error state that can be detected
anywhere inside the productions, for example if we get an eof on
SOME_MACRO({ some block <eof>
- previously we'd never break lines when we discovered a structural
error; now we break even in the case of a structural error if there
are two unwrapped lines within the same line; thus,
void f() { while (true) { g(); y(); } }
will still be re-formatted, even if there's missing braces somewhere
in the file
- still exclude macro definitions from generating structural error;
macro definitions are inbalanced snippets
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179379 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h
index f4fecc5..1326d50 100644
--- a/lib/Format/UnwrappedLineParser.h
+++ b/lib/Format/UnwrappedLineParser.h
@@ -125,9 +125,9 @@
bool parse();
private:
- bool parseFile();
- bool parseLevel(bool HasOpeningBrace);
- bool parseBlock(bool MustBeDeclaration, unsigned AddLevels = 1);
+ void parseFile();
+ void parseLevel(bool HasOpeningBrace);
+ void parseBlock(bool MustBeDeclaration, unsigned AddLevels = 1);
void parsePPDirective();
void parsePPDefine();
void parsePPUnknown();
@@ -187,6 +187,10 @@
// 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;
+
clang::DiagnosticsEngine &Diag;
const FormatStyle &Style;
FormatTokenSource *Tokens;