r236591 - Remove all computation of structural errors in clang-format's line parser.
Manuel Klimek
klimek at google.com
Wed May 6 04:56:30 PDT 2015
Author: klimek
Date: Wed May 6 06:56:29 2015
New Revision: 236591
URL: http://llvm.org/viewvc/llvm-project?rev=236591&view=rev
Log:
Remove all computation of structural errors in clang-format's line parser.
We were already ignoring those already.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=236591&r1=236590&r2=236591&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed May 6 06:56:29 2015
@@ -1225,7 +1225,7 @@ public:
UnwrappedLineParser Parser(Style, Tokens.getKeywords(), Tokens.lex(),
*this);
- bool StructuralError = Parser.parse();
+ Parser.parse();
assert(UnwrappedLines.rbegin()->empty());
for (unsigned Run = 0, RunE = UnwrappedLines.size(); Run + 1 != RunE;
++Run) {
@@ -1234,8 +1234,7 @@ public:
for (unsigned i = 0, e = UnwrappedLines[Run].size(); i != e; ++i) {
AnnotatedLines.push_back(new AnnotatedLine(UnwrappedLines[Run][i]));
}
- tooling::Replacements RunResult =
- format(AnnotatedLines, StructuralError, Tokens);
+ tooling::Replacements RunResult = format(AnnotatedLines, Tokens);
DEBUG({
llvm::dbgs() << "Replacements for run " << Run << ":\n";
for (tooling::Replacements::iterator I = RunResult.begin(),
@@ -1254,7 +1253,7 @@ public:
}
tooling::Replacements format(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
- bool StructuralError, FormatTokenLexer &Tokens) {
+ FormatTokenLexer &Tokens) {
TokenAnnotator Annotator(Style, Tokens.getKeywords());
for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
Annotator.annotate(*AnnotatedLines[i]);
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=236591&r1=236590&r2=236591&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed May 6 06:56:29 2015
@@ -58,11 +58,10 @@ private:
class ScopedMacroState : public FormatTokenSource {
public:
ScopedMacroState(UnwrappedLine &Line, FormatTokenSource *&TokenSource,
- FormatToken *&ResetToken, bool &StructuralError)
+ FormatToken *&ResetToken)
: Line(Line), TokenSource(TokenSource), ResetToken(ResetToken),
PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource),
- StructuralError(StructuralError),
- PreviousStructuralError(StructuralError), Token(nullptr) {
+ Token(nullptr) {
TokenSource = this;
Line.Level = 0;
Line.InPPDirective = true;
@@ -73,7 +72,6 @@ public:
ResetToken = Token;
Line.InPPDirective = false;
Line.Level = PreviousLineLevel;
- StructuralError = PreviousStructuralError;
}
FormatToken *getNextToken() override {
@@ -112,8 +110,6 @@ private:
FormatToken *&ResetToken;
unsigned PreviousLineLevel;
FormatTokenSource *PreviousTokenSource;
- bool &StructuralError;
- bool PreviousStructuralError;
FormatToken *Token;
};
@@ -208,9 +204,8 @@ UnwrappedLineParser::UnwrappedLineParser
ArrayRef<FormatToken *> Tokens,
UnwrappedLineConsumer &Callback)
: Line(new UnwrappedLine), MustBreakBeforeNextToken(false),
- CurrentLines(&Lines), StructuralError(false), Style(Style),
- Keywords(Keywords), Tokens(nullptr), Callback(Callback),
- AllTokens(Tokens), PPBranchLevel(-1) {}
+ CurrentLines(&Lines), Style(Style), Keywords(Keywords), Tokens(nullptr),
+ Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1) {}
void UnwrappedLineParser::reset() {
PPBranchLevel = -1;
@@ -221,11 +216,10 @@ void UnwrappedLineParser::reset() {
PreprocessorDirectives.clear();
CurrentLines = &Lines;
DeclarationScopeStack.clear();
- StructuralError = false;
PPStack.clear();
}
-bool UnwrappedLineParser::parse() {
+void UnwrappedLineParser::parse() {
IndexedTokenSource TokenSource(AllTokens);
do {
DEBUG(llvm::dbgs() << "----\n");
@@ -258,7 +252,6 @@ bool UnwrappedLineParser::parse() {
}
} while (!PPLevelBranchIndex.empty());
- return StructuralError;
}
void UnwrappedLineParser::parseFile() {
@@ -291,7 +284,6 @@ void UnwrappedLineParser::parseLevel(boo
case tok::r_brace:
if (HasOpeningBrace)
return;
- StructuralError = true;
nextToken();
addUnwrappedLine();
break;
@@ -413,7 +405,6 @@ void UnwrappedLineParser::parseBlock(boo
if (!FormatTok->Tok.is(tok::r_brace)) {
Line->Level = InitialLevel;
- StructuralError = true;
return;
}
@@ -473,7 +464,7 @@ void UnwrappedLineParser::parseChildBloc
void UnwrappedLineParser::parsePPDirective() {
assert(FormatTok->Tok.is(tok::hash) && "'#' expected");
- ScopedMacroState MacroState(*Line, Tokens, FormatTok, StructuralError);
+ ScopedMacroState MacroState(*Line, Tokens, FormatTok);
nextToken();
if (!FormatTok->Tok.getIdentifierInfo()) {
@@ -1216,8 +1207,6 @@ void UnwrappedLineParser::parseTryCatch(
nextToken();
if (FormatTok->is(tok::l_paren))
parseParens();
- else
- StructuralError = true;
if (FormatTok->is(tok::comma))
nextToken();
}
@@ -1240,7 +1229,6 @@ void UnwrappedLineParser::parseTryCatch(
// The C++ standard requires a compound-statement after a try.
// If there's none, we try to assume there's a structuralElement
// and try to continue.
- StructuralError = true;
addUnwrappedLine();
++Line->Level;
parseStructuralElement();
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=236591&r1=236590&r2=236591&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Wed May 6 06:56:29 2015
@@ -65,8 +65,7 @@ public:
ArrayRef<FormatToken *> Tokens,
UnwrappedLineConsumer &Callback);
- /// Returns true in case of a structural error.
- bool parse();
+ void parse();
private:
void reset();
@@ -158,10 +157,6 @@ private:
// 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;
-
const FormatStyle &Style;
const AdditionalKeywords &Keywords;
More information about the cfe-commits
mailing list