[cfe-commits] r169151 - /cfe/trunk/lib/Format/Format.cpp
Manuel Klimek
klimek at google.com
Mon Dec 3 12:55:42 PST 2012
Author: klimek
Date: Mon Dec 3 14:55:42 2012
New Revision: 169151
URL: http://llvm.org/viewvc/llvm-project?rev=169151&view=rev
Log:
Fixes a compile warning and crash in the tests.
The necessity of this fix points to a problem with the design
of the addToken during the optimiation phase, which we need to address
in a much more principled way.
Modified:
cfe/trunk/lib/Format/Format.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=169151&r1=169150&r2=169151&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Dec 3 14:55:42 2012
@@ -167,13 +167,14 @@
State.Column = State.Column - Previous.Tok.getLength();
else if (Previous.Tok.is(tok::equal) && ParenLevel != 0)
State.Column = State.Indent[ParenLevel] + 4;
- else
+ else if (ParenLevel < State.Indent.size())
State.Column = State.Indent[ParenLevel];
if (!DryRun)
replaceWhitespace(Current, 1, State.Column);
State.Column += Current.Tok.getLength();
- State.LastSpace[ParenLevel] = State.Indent[ParenLevel];
+ if (ParenLevel < State.LastSpace.size())
+ State.LastSpace[ParenLevel] = State.Indent[ParenLevel];
if (Current.Tok.is(tok::colon) &&
Annotations[Index].Type != TokenAnnotation::TT_ConditionalExpr) {
State.Indent[ParenLevel] += 2;
@@ -189,20 +190,23 @@
if (Previous.Tok.is(tok::l_paren))
State.Indent[ParenLevel] = State.Column;
if (Previous.Tok.is(tok::less) &&
- Annotations[Index - 1].Type == TokenAnnotation::TT_TemplateOpener)
+ Annotations[Index - 1].Type == TokenAnnotation::TT_TemplateOpener &&
+ ParenLevel < State.Indent.size())
State.Indent[ParenLevel] = State.Column;
if (Current.Tok.is(tok::colon)) {
State.Indent[ParenLevel] = State.Column + 3;
State.InCtorInitializer = true;
}
// Top-level spaces are exempt as that mostly leads to better results.
- if (Spaces > 0 && ParenLevel != 0)
+ if (Spaces > 0 && ParenLevel != 0 &&
+ ParenLevel < State.LastSpace.size())
State.LastSpace[ParenLevel] = State.Column + Spaces;
State.Column += Current.Tok.getLength() + Spaces;
}
- if (Current.Tok.is(tok::r_paren) || Current.Tok.is(tok::r_square) ||
- Annotations[Index].Type == TokenAnnotation::TT_TemplateOpener) {
+ if (!DryRun &&
+ (Current.Tok.is(tok::r_paren) || Current.Tok.is(tok::r_square) ||
+ Annotations[Index].Type == TokenAnnotation::TT_TemplateOpener)) {
State.Indent.pop_back();
State.LastSpace.pop_back();
}
@@ -341,11 +345,9 @@
/// into template parameter lists.
class AnnotatingParser {
public:
- AnnotatingParser(const SourceManager &SourceMgr,
- const SmallVector<FormatToken, 16> &Tokens,
+ AnnotatingParser(const SmallVector<FormatToken, 16> &Tokens,
std::vector<TokenAnnotation> &Annotations)
- : SourceMgr(SourceMgr),
- Tokens(Tokens),
+ : Tokens(Tokens),
Annotations(Annotations),
Index(0) {
}
@@ -457,7 +459,6 @@
}
private:
- const SourceManager &SourceMgr;
const SmallVector<FormatToken, 16> &Tokens;
std::vector<TokenAnnotation> &Annotations;
unsigned Index;
@@ -469,7 +470,7 @@
Annotations.push_back(TokenAnnotation());
}
- AnnotatingParser Parser(SourceMgr, Line.Tokens, Annotations);
+ AnnotatingParser Parser(Line.Tokens, Annotations);
Parser.parseLine();
determineTokenTypes();
More information about the cfe-commits
mailing list