зеркало из https://github.com/microsoft/clang-1.git
Replace workarounds with correct fixes.
Also fix header guard. http://llvm-reviews.chandlerc.com/D159 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169254 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
30bc63ffba
Коммит
a88bb45f11
|
@ -15,7 +15,7 @@
|
||||||
///
|
///
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef LLVM_CLANG_FORMAT_FORMAT_H_
|
#ifndef LLVM_CLANG_FORMAT_FORMAT_H
|
||||||
#define LLVM_CLANG_FORMAT_FORMAT_H
|
#define LLVM_CLANG_FORMAT_FORMAT_H
|
||||||
|
|
||||||
#include "clang/Frontend/FrontendAction.h"
|
#include "clang/Frontend/FrontendAction.h"
|
||||||
|
|
|
@ -26,9 +26,10 @@ namespace format {
|
||||||
|
|
||||||
// FIXME: Move somewhere sane.
|
// FIXME: Move somewhere sane.
|
||||||
struct TokenAnnotation {
|
struct TokenAnnotation {
|
||||||
enum TokenType { TT_Unknown, TT_TemplateOpener, TT_BinaryOperator,
|
enum TokenType { TT_Unknown, TT_TemplateOpener, TT_TemplateCloser,
|
||||||
TT_UnaryOperator, TT_OverloadedOperator, TT_PointerOrReference,
|
TT_BinaryOperator, TT_UnaryOperator, TT_OverloadedOperator,
|
||||||
TT_ConditionalExpr, TT_LineComment, TT_BlockComment };
|
TT_PointerOrReference, TT_ConditionalExpr, TT_LineComment,
|
||||||
|
TT_BlockComment };
|
||||||
|
|
||||||
TokenType Type;
|
TokenType Type;
|
||||||
|
|
||||||
|
@ -165,14 +166,13 @@ 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 if (ParenLevel < State.Indent.size())
|
else
|
||||||
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();
|
||||||
if (ParenLevel < State.LastSpace.size())
|
State.LastSpace[ParenLevel] = State.Indent[ParenLevel];
|
||||||
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;
|
||||||
|
@ -187,24 +187,20 @@ private:
|
||||||
replaceWhitespace(Current, 0, Spaces);
|
replaceWhitespace(Current, 0, Spaces);
|
||||||
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 (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 (!DryRun &&
|
if (Current.Tok.is(tok::r_paren) || Current.Tok.is(tok::r_square) ||
|
||||||
(Current.Tok.is(tok::r_paren) || Current.Tok.is(tok::r_square) ||
|
Annotations[Index].Type == TokenAnnotation::TT_TemplateCloser) {
|
||||||
Annotations[Index].Type == TokenAnnotation::TT_TemplateOpener)) {
|
|
||||||
State.Indent.pop_back();
|
State.Indent.pop_back();
|
||||||
State.LastSpace.pop_back();
|
State.LastSpace.pop_back();
|
||||||
}
|
}
|
||||||
|
@ -353,7 +349,7 @@ public:
|
||||||
bool parseAngle(unsigned Level) {
|
bool parseAngle(unsigned Level) {
|
||||||
while (Index < Tokens.size()) {
|
while (Index < Tokens.size()) {
|
||||||
if (Tokens[Index].Tok.is(tok::greater)) {
|
if (Tokens[Index].Tok.is(tok::greater)) {
|
||||||
Annotations[Index].Type = TokenAnnotation::TT_TemplateOpener;
|
Annotations[Index].Type = TokenAnnotation::TT_TemplateCloser;
|
||||||
Annotations[Index].ParenLevel = Level;
|
Annotations[Index].ParenLevel = Level;
|
||||||
next();
|
next();
|
||||||
return true;
|
return true;
|
||||||
|
@ -426,6 +422,7 @@ public:
|
||||||
if (parseAngle(Level + 1))
|
if (parseAngle(Level + 1))
|
||||||
Annotations[CurrentIndex].Type = TokenAnnotation::TT_TemplateOpener;
|
Annotations[CurrentIndex].Type = TokenAnnotation::TT_TemplateOpener;
|
||||||
else {
|
else {
|
||||||
|
Annotations[CurrentIndex].ParenLevel = Level;
|
||||||
Annotations[CurrentIndex].Type = TokenAnnotation::TT_BinaryOperator;
|
Annotations[CurrentIndex].Type = TokenAnnotation::TT_BinaryOperator;
|
||||||
Index = CurrentIndex + 1;
|
Index = CurrentIndex + 1;
|
||||||
}
|
}
|
||||||
|
@ -495,6 +492,9 @@ public:
|
||||||
if (Annotation.Type == TokenAnnotation::TT_TemplateOpener &&
|
if (Annotation.Type == TokenAnnotation::TT_TemplateOpener &&
|
||||||
Annotations[i - 1].Type == TokenAnnotation::TT_TemplateOpener)
|
Annotations[i - 1].Type == TokenAnnotation::TT_TemplateOpener)
|
||||||
Annotation.SpaceRequiredBefore = Style.SplitTemplateClosingGreater;
|
Annotation.SpaceRequiredBefore = Style.SplitTemplateClosingGreater;
|
||||||
|
else if (Annotation.Type == TokenAnnotation::TT_TemplateCloser &&
|
||||||
|
Annotations[i - 1].Type == TokenAnnotation::TT_TemplateCloser)
|
||||||
|
Annotation.SpaceRequiredBefore = Style.SplitTemplateClosingGreater;
|
||||||
else
|
else
|
||||||
Annotation.SpaceRequiredBefore = false;
|
Annotation.SpaceRequiredBefore = false;
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -502,7 +502,7 @@ public:
|
||||||
Annotations[i - 1].Type == TokenAnnotation::TT_BinaryOperator) {
|
Annotations[i - 1].Type == TokenAnnotation::TT_BinaryOperator) {
|
||||||
Annotation.SpaceRequiredBefore = true;
|
Annotation.SpaceRequiredBefore = true;
|
||||||
} else if (
|
} else if (
|
||||||
Annotations[i - 1].Type == TokenAnnotation::TT_TemplateOpener &&
|
Annotations[i - 1].Type == TokenAnnotation::TT_TemplateCloser &&
|
||||||
Line.Tokens[i].Tok.is(tok::l_paren)) {
|
Line.Tokens[i].Tok.is(tok::l_paren)) {
|
||||||
Annotation.SpaceRequiredBefore = false;
|
Annotation.SpaceRequiredBefore = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -256,6 +256,12 @@ TEST_F(FormatTest, BreaksDesireably) {
|
||||||
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
|
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
|
||||||
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
|
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
|
||||||
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa));");
|
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa));");
|
||||||
|
|
||||||
|
verifyFormat(
|
||||||
|
"aaaaaaaa(aaaaaaaaaaaaa, aaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
|
||||||
|
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)),\n"
|
||||||
|
" aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
|
||||||
|
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)));");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatTest, AlignsStringLiterals) {
|
TEST_F(FormatTest, AlignsStringLiterals) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче