clang-format clang/lib/Format

llvm-svn: 367225
This commit is contained in:
Nico Weber 2019-07-29 13:26:48 +00:00
parent 5483f4225e
commit ff9f4b5489
5 changed files with 17 additions and 19 deletions

View File

@ -342,8 +342,8 @@ BreakableBlockComment::BreakableBlockComment(
StringRef TokenText(Tok.TokenText); StringRef TokenText(Tok.TokenText);
assert(TokenText.startswith("/*") && TokenText.endswith("*/")); assert(TokenText.startswith("/*") && TokenText.endswith("*/"));
TokenText.substr(2, TokenText.size() - 4).split(Lines, TokenText.substr(2, TokenText.size() - 4)
UseCRLF ? "\r\n" : "\n"); .split(Lines, UseCRLF ? "\r\n" : "\n");
int IndentDelta = StartColumn - OriginalStartColumn; int IndentDelta = StartColumn - OriginalStartColumn;
Content.resize(Lines.size()); Content.resize(Lines.size());
@ -456,10 +456,9 @@ BreakableBlockComment::BreakableBlockComment(
}); });
} }
BreakableToken::Split BreakableToken::Split BreakableBlockComment::getSplit(
BreakableBlockComment::getSplit(unsigned LineIndex, unsigned TailOffset, unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit,
unsigned ColumnLimit, unsigned ContentStartColumn, unsigned ContentStartColumn, llvm::Regex &CommentPragmasRegex) const {
llvm::Regex &CommentPragmasRegex) const {
// Don't break lines matching the comment pragmas regex. // Don't break lines matching the comment pragmas regex.
if (CommentPragmasRegex.match(Content[LineIndex])) if (CommentPragmasRegex.match(Content[LineIndex]))
return Split(StringRef::npos, 0); return Split(StringRef::npos, 0);

View File

@ -608,8 +608,8 @@ static FormatStyle expandPresets(const FormatStyle &Style) {
return Style; return Style;
FormatStyle Expanded = Style; FormatStyle Expanded = Style;
Expanded.BraceWrapping = {false, false, false, false, false, false, Expanded.BraceWrapping = {false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false, false,
false, false, true, true, true}; false, true, true, true};
switch (Style.BreakBeforeBraces) { switch (Style.BreakBeforeBraces) {
case FormatStyle::BS_Linux: case FormatStyle::BS_Linux:
Expanded.BraceWrapping.AfterClass = true; Expanded.BraceWrapping.AfterClass = true;
@ -687,8 +687,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.BreakBeforeTernaryOperators = true; LLVMStyle.BreakBeforeTernaryOperators = true;
LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach; LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
LLVMStyle.BraceWrapping = {false, false, false, false, false, false, LLVMStyle.BraceWrapping = {false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false, false,
false, false, true, true, true}; false, true, true, true};
LLVMStyle.BreakAfterJavaFieldAnnotations = false; LLVMStyle.BreakAfterJavaFieldAnnotations = false;
LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon; LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon; LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
@ -1774,8 +1774,8 @@ FindCursorIndex(const SmallVectorImpl<IncludeDirective> &Includes,
static void sortCppIncludes(const FormatStyle &Style, static void sortCppIncludes(const FormatStyle &Style,
const SmallVectorImpl<IncludeDirective> &Includes, const SmallVectorImpl<IncludeDirective> &Includes,
ArrayRef<tooling::Range> Ranges, StringRef FileName, ArrayRef<tooling::Range> Ranges, StringRef FileName,
StringRef Code, StringRef Code, tooling::Replacements &Replaces,
tooling::Replacements &Replaces, unsigned *Cursor) { unsigned *Cursor) {
unsigned IncludesBeginOffset = Includes.front().Offset; unsigned IncludesBeginOffset = Includes.front().Offset;
unsigned IncludesEndOffset = unsigned IncludesEndOffset =
Includes.back().Offset + Includes.back().Text.size(); Includes.back().Offset + Includes.back().Text.size();

View File

@ -114,8 +114,7 @@ public:
/// \c true if this line starts a namespace definition. /// \c true if this line starts a namespace definition.
bool startsWithNamespace() const { bool startsWithNamespace() const {
return startsWith(tok::kw_namespace) || return startsWith(tok::kw_namespace) || startsWith(TT_NamespaceMacro) ||
startsWith(TT_NamespaceMacro) ||
startsWith(tok::kw_inline, tok::kw_namespace) || startsWith(tok::kw_inline, tok::kw_namespace) ||
startsWith(tok::kw_export, tok::kw_namespace); startsWith(tok::kw_export, tok::kw_namespace);
} }

View File

@ -174,8 +174,7 @@ public:
const FormatStyle &Style, unsigned &LineLevel) const FormatStyle &Style, unsigned &LineLevel)
: CompoundStatementIndenter(Parser, LineLevel, : CompoundStatementIndenter(Parser, LineLevel,
Style.BraceWrapping.AfterControlStatement, Style.BraceWrapping.AfterControlStatement,
Style.BraceWrapping.IndentBraces) { Style.BraceWrapping.IndentBraces) {}
}
CompoundStatementIndenter(UnwrappedLineParser *Parser, unsigned &LineLevel, CompoundStatementIndenter(UnwrappedLineParser *Parser, unsigned &LineLevel,
bool WrapBrace, bool IndentBrace) bool WrapBrace, bool IndentBrace)
: LineLevel(LineLevel), OldLineLevel(LineLevel) { : LineLevel(LineLevel), OldLineLevel(LineLevel) {
@ -1216,7 +1215,8 @@ void UnwrappedLineParser::parseStructuralElement() {
nextToken(); nextToken();
if (FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS, if (FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS, Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS,
Keywords.kw_CF_CLOSED_ENUM, Keywords.kw_NS_CLOSED_ENUM)) Keywords.kw_CF_CLOSED_ENUM,
Keywords.kw_NS_CLOSED_ENUM))
parseEnum(); parseEnum();
break; break;
case tok::kw_struct: case tok::kw_struct:

View File

@ -17,8 +17,8 @@
namespace clang { namespace clang {
namespace format { namespace format {
bool WhitespaceManager::Change::IsBeforeInFile:: bool WhitespaceManager::Change::IsBeforeInFile::operator()(
operator()(const Change &C1, const Change &C2) const { const Change &C1, const Change &C2) const {
return SourceMgr.isBeforeInTranslationUnit( return SourceMgr.isBeforeInTranslationUnit(
C1.OriginalWhitespaceRange.getBegin(), C1.OriginalWhitespaceRange.getBegin(),
C2.OriginalWhitespaceRange.getBegin()); C2.OriginalWhitespaceRange.getBegin());