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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169151 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Manuel Klimek 2012-12-03 20:55:42 +00:00
Родитель 91ecfa6af5
Коммит 0be4b36830
1 изменённых файлов: 13 добавлений и 12 удалений

Просмотреть файл

@ -167,13 +167,14 @@ private:
State.Column = State.Column - Previous.Tok.getLength(); State.Column = State.Column - Previous.Tok.getLength();
else if (Previous.Tok.is(tok::equal) && ParenLevel != 0) else if (Previous.Tok.is(tok::equal) && ParenLevel != 0)
State.Column = State.Indent[ParenLevel] + 4; State.Column = State.Indent[ParenLevel] + 4;
else else if (ParenLevel < State.Indent.size())
State.Column = State.Indent[ParenLevel]; State.Column = State.Indent[ParenLevel];
if (!DryRun) if (!DryRun)
replaceWhitespace(Current, 1, State.Column); replaceWhitespace(Current, 1, State.Column);
State.Column += Current.Tok.getLength(); 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) && if (Current.Tok.is(tok::colon) &&
Annotations[Index].Type != TokenAnnotation::TT_ConditionalExpr) { Annotations[Index].Type != TokenAnnotation::TT_ConditionalExpr) {
State.Indent[ParenLevel] += 2; State.Indent[ParenLevel] += 2;
@ -189,20 +190,23 @@ private:
if (Previous.Tok.is(tok::l_paren)) if (Previous.Tok.is(tok::l_paren))
State.Indent[ParenLevel] = State.Column; State.Indent[ParenLevel] = State.Column;
if (Previous.Tok.is(tok::less) && 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; State.Indent[ParenLevel] = State.Column;
if (Current.Tok.is(tok::colon)) { if (Current.Tok.is(tok::colon)) {
State.Indent[ParenLevel] = State.Column + 3; State.Indent[ParenLevel] = State.Column + 3;
State.InCtorInitializer = true; State.InCtorInitializer = true;
} }
// Top-level spaces are exempt as that mostly leads to better results. // 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.LastSpace[ParenLevel] = State.Column + Spaces;
State.Column += Current.Tok.getLength() + Spaces; State.Column += Current.Tok.getLength() + Spaces;
} }
if (Current.Tok.is(tok::r_paren) || Current.Tok.is(tok::r_square) || if (!DryRun &&
Annotations[Index].Type == TokenAnnotation::TT_TemplateOpener) { (Current.Tok.is(tok::r_paren) || Current.Tok.is(tok::r_square) ||
Annotations[Index].Type == TokenAnnotation::TT_TemplateOpener)) {
State.Indent.pop_back(); State.Indent.pop_back();
State.LastSpace.pop_back(); State.LastSpace.pop_back();
} }
@ -341,11 +345,9 @@ public:
/// into template parameter lists. /// into template parameter lists.
class AnnotatingParser { class AnnotatingParser {
public: public:
AnnotatingParser(const SourceManager &SourceMgr, AnnotatingParser(const SmallVector<FormatToken, 16> &Tokens,
const SmallVector<FormatToken, 16> &Tokens,
std::vector<TokenAnnotation> &Annotations) std::vector<TokenAnnotation> &Annotations)
: SourceMgr(SourceMgr), : Tokens(Tokens),
Tokens(Tokens),
Annotations(Annotations), Annotations(Annotations),
Index(0) { Index(0) {
} }
@ -457,7 +459,6 @@ public:
} }
private: private:
const SourceManager &SourceMgr;
const SmallVector<FormatToken, 16> &Tokens; const SmallVector<FormatToken, 16> &Tokens;
std::vector<TokenAnnotation> &Annotations; std::vector<TokenAnnotation> &Annotations;
unsigned Index; unsigned Index;
@ -469,7 +470,7 @@ public:
Annotations.push_back(TokenAnnotation()); Annotations.push_back(TokenAnnotation());
} }
AnnotatingParser Parser(SourceMgr, Line.Tokens, Annotations); AnnotatingParser Parser(Line.Tokens, Annotations);
Parser.parseLine(); Parser.parseLine();
determineTokenTypes(); determineTokenTypes();