Skip to content

Commit

Permalink
[clang-format] [NFC] clang-format the Format library
Browse files Browse the repository at this point in the history
Previously revisions commited non-clang-formatted changes to the Format library, this means submitting any revision e.g. {D55170} can cause additional whitespace changes to potentially be included in a revision.

Commit a non functional change using latest build Windows clang-format r351376 with no other changes, to remove these differences

All FormatTests
pass [==========] 652 tests from 20 test cases ran.

llvm-svn: 355182
  • Loading branch information
mydeveloperday committed Mar 1, 2019
1 parent fa61ddd commit 5bcf99b
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 123 deletions.
19 changes: 7 additions & 12 deletions clang/lib/Format/BreakableToken.cpp
Expand Up @@ -62,12 +62,10 @@ static StringRef getLineCommentIndentPrefix(StringRef Comment,
return LongestPrefix;
}

static BreakableToken::Split getCommentSplit(StringRef Text,
unsigned ContentStartColumn,
unsigned ColumnLimit,
unsigned TabWidth,
encoding::Encoding Encoding,
const FormatStyle &Style) {
static BreakableToken::Split
getCommentSplit(StringRef Text, unsigned ContentStartColumn,
unsigned ColumnLimit, unsigned TabWidth,
encoding::Encoding Encoding, const FormatStyle &Style) {
LLVM_DEBUG(llvm::dbgs() << "Comment split: \"" << Text
<< "\", Column limit: " << ColumnLimit
<< ", Content start: " << ContentStartColumn << "\n");
Expand Down Expand Up @@ -191,7 +189,7 @@ bool switchesFormatting(const FormatToken &Token) {

unsigned
BreakableToken::getLengthAfterCompression(unsigned RemainingTokenColumns,
Split Split) const {
Split Split) const {
// Example: consider the content
// lala lala
// - RemainingTokenColumns is the original number of columns, 10;
Expand Down Expand Up @@ -870,23 +868,20 @@ void BreakableLineCommentSection::reflow(unsigned LineIndex,
// the next line.
unsigned WhitespaceLength =
Lines[LineIndex].data() - tokenAt(LineIndex).TokenText.data() - Offset;
Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex],
Offset,
Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex], Offset,
/*ReplaceChars=*/WhitespaceLength,
/*PreviousPostfix=*/"",
/*CurrentPrefix=*/"",
/*InPPDirective=*/false,
/*Newlines=*/0,
/*Spaces=*/0);

}
// Replace the indent and prefix of the token with the reflow prefix.
unsigned Offset =
Lines[LineIndex].data() - tokenAt(LineIndex).TokenText.data();
unsigned WhitespaceLength =
Content[LineIndex].data() - Lines[LineIndex].data();
Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex],
Offset,
Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex], Offset,
/*ReplaceChars=*/WhitespaceLength,
/*PreviousPostfix=*/"",
/*CurrentPrefix=*/ReflowPrefix,
Expand Down
8 changes: 2 additions & 6 deletions clang/lib/Format/BreakableToken.h
Expand Up @@ -146,9 +146,7 @@ class BreakableToken {
// * @param loooooooooooooong line
// * continuation
// */
virtual unsigned getContentIndent(unsigned LineIndex) const {
return 0;
}
virtual unsigned getContentIndent(unsigned LineIndex) const { return 0; }

/// Returns a range (offset, length) at which to break the line at
/// \p LineIndex, if previously broken at \p TailOffset. If possible, do not
Expand Down Expand Up @@ -202,9 +200,7 @@ class BreakableToken {

/// Returns whether there will be a line break at the start of the
/// token.
virtual bool introducesBreakBeforeToken() const {
return false;
}
virtual bool introducesBreakBeforeToken() const { return false; }

/// Replaces the whitespace between \p LineIndex-1 and \p LineIndex.
virtual void adaptStartOfLine(unsigned LineIndex,
Expand Down
28 changes: 13 additions & 15 deletions clang/lib/Format/ContinuationIndenter.cpp
Expand Up @@ -403,8 +403,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
// FIXME: We should find a more generic solution to this problem.
!(State.Column <= NewLineColumn &&
Style.Language == FormatStyle::LK_JavaScript) &&
!(Previous.closesScopeAfterBlock() &&
State.Column <= NewLineColumn))
!(Previous.closesScopeAfterBlock() && State.Column <= NewLineColumn))
return true;

// If the template declaration spans multiple lines, force wrap before the
Expand Down Expand Up @@ -835,8 +834,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
// about removing empty lines on closing blocks. Special case them here.
MaxEmptyLinesToKeep = 1;
}
unsigned Newlines = std::max(
1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
unsigned Newlines =
std::max(1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
bool ContinuePPDirective =
State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
Whitespaces.replaceWhitespace(Current, Newlines, State.Column, State.Column,
Expand Down Expand Up @@ -1168,8 +1167,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
State.Column += Current.ColumnWidth;
State.NextToken = State.NextToken->Next;

unsigned Penalty =
handleEndOfLine(Current, State, DryRun, AllowBreak);
unsigned Penalty = handleEndOfLine(Current, State, DryRun, AllowBreak);

if (Current.Role)
Current.Role->formatFromToken(State, this, DryRun);
Expand Down Expand Up @@ -1530,9 +1528,8 @@ unsigned ContinuationIndenter::reformatRawStringLiteral(
// that raw string prefix starts, and
// - if the raw string prefix does not start on a newline, it is the current
// indent.
unsigned LastStartColumn = Current.NewlinesBefore
? FirstStartColumn - NewPrefixSize
: CurrentIndent;
unsigned LastStartColumn =
Current.NewlinesBefore ? FirstStartColumn - NewPrefixSize : CurrentIndent;

std::pair<tooling::Replacements, unsigned> Fixes = internal::reformat(
RawStringStyle, RawText, {tooling::Range(0, RawText.size())},
Expand Down Expand Up @@ -1589,8 +1586,9 @@ unsigned ContinuationIndenter::reformatRawStringLiteral(
// have to manually add the penalty for the prefix R"delim( over the column
// limit.
unsigned PrefixExcessCharacters =
StartColumn + NewPrefixSize > Style.ColumnLimit ?
StartColumn + NewPrefixSize - Style.ColumnLimit : 0;
StartColumn + NewPrefixSize > Style.ColumnLimit
? StartColumn + NewPrefixSize - Style.ColumnLimit
: 0;
bool IsMultiline =
ContentStartsOnNewline || (NewCode->find('\n') != std::string::npos);
if (IsMultiline) {
Expand Down Expand Up @@ -1708,16 +1706,16 @@ ContinuationIndenter::getRawStringStyle(const FormatToken &Current,
return RawStringStyle;
}

std::unique_ptr<BreakableToken> ContinuationIndenter::createBreakableToken(
const FormatToken &Current, LineState &State, bool AllowBreak) {
std::unique_ptr<BreakableToken>
ContinuationIndenter::createBreakableToken(const FormatToken &Current,
LineState &State, bool AllowBreak) {
unsigned StartColumn = State.Column - Current.ColumnWidth;
if (Current.isStringLiteral()) {
// FIXME: String literal breaking is currently disabled for Java and JS, as
// it requires strings to be merged using "+" which we don't support.
if (Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript ||
!Style.BreakStringLiterals ||
!AllowBreak)
!Style.BreakStringLiterals || !AllowBreak)
return nullptr;

// Don't break string literals inside preprocessor directives (except for
Expand Down
39 changes: 15 additions & 24 deletions clang/lib/Format/Format.cpp
Expand Up @@ -149,8 +149,8 @@ struct ScalarEnumerationTraits<FormatStyle::BreakConstructorInitializersStyle> {

template <>
struct ScalarEnumerationTraits<FormatStyle::BreakInheritanceListStyle> {
static void
enumeration(IO &IO, FormatStyle::BreakInheritanceListStyle &Value) {
static void enumeration(IO &IO,
FormatStyle::BreakInheritanceListStyle &Value) {
IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
Expand Down Expand Up @@ -179,7 +179,8 @@ struct ScalarEnumerationTraits<FormatStyle::ReturnTypeBreakingStyle> {

template <>
struct ScalarEnumerationTraits<FormatStyle::BreakTemplateDeclarationsStyle> {
static void enumeration(IO &IO, FormatStyle::BreakTemplateDeclarationsStyle &Value) {
static void enumeration(IO &IO,
FormatStyle::BreakTemplateDeclarationsStyle &Value) {
IO.enumCase(Value, "No", FormatStyle::BTDS_No);
IO.enumCase(Value, "MultiLine", FormatStyle::BTDS_MultiLine);
IO.enumCase(Value, "Yes", FormatStyle::BTDS_Yes);
Expand Down Expand Up @@ -361,10 +362,8 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);

bool BreakBeforeInheritanceComma = false;
IO.mapOptional("BreakBeforeInheritanceComma",
BreakBeforeInheritanceComma);
IO.mapOptional("BreakInheritanceList",
Style.BreakInheritanceList);
IO.mapOptional("BreakBeforeInheritanceComma", BreakBeforeInheritanceComma);
IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList);
// If BreakBeforeInheritanceComma was specified but
// BreakInheritance was not, initialize the latter from the
// former for backwards compatibility.
Expand Down Expand Up @@ -854,15 +853,9 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) {
// See styleguide for import groups:
// https://chromium.googlesource.com/chromium/src/+/master/styleguide/java/java.md#Import-Order
ChromiumStyle.JavaImportGroups = {
"android",
"com",
"dalvik",
"junit",
"org",
"com.google.android.apps.chrome",
"org.chromium",
"java",
"javax",
"android", "com", "dalvik",
"junit", "org", "com.google.android.apps.chrome",
"org.chromium", "java", "javax",
};
ChromiumStyle.SortIncludes = true;
} else if (Language == FormatStyle::LK_JavaScript) {
Expand Down Expand Up @@ -1063,9 +1056,7 @@ void FormatStyle::FormatStyleSet::Add(FormatStyle Style) {
(*Styles)[Style.Language] = std::move(Style);
}

void FormatStyle::FormatStyleSet::Clear() {
Styles.reset();
}
void FormatStyle::FormatStyleSet::Clear() { Styles.reset(); }

llvm::Optional<FormatStyle>
FormatStyle::GetLanguageStyle(FormatStyle::LanguageKind Language) const {
Expand Down Expand Up @@ -1857,8 +1848,7 @@ static unsigned findJavaImportGroup(const FormatStyle &Style,
static void sortJavaImports(const FormatStyle &Style,
const SmallVectorImpl<JavaImportDirective> &Imports,
ArrayRef<tooling::Range> Ranges, StringRef FileName,
StringRef Code,
tooling::Replacements &Replaces) {
StringRef Code, tooling::Replacements &Replaces) {
unsigned ImportsBeginOffset = Imports.front().Offset;
unsigned ImportsEndOffset =
Imports.back().Offset + Imports.back().Text.size();
Expand Down Expand Up @@ -1965,7 +1955,8 @@ tooling::Replacements sortJavaImports(const FormatStyle &Style, StringRef Code,
if (Static.contains("static")) {
IsStatic = true;
}
ImportsInBlock.push_back({Identifier, Line, Prev, AssociatedCommentLines, IsStatic});
ImportsInBlock.push_back(
{Identifier, Line, Prev, AssociatedCommentLines, IsStatic});
AssociatedCommentLines.clear();
} else if (Trimmed.size() > 0 && !ImportsInBlock.empty()) {
// Associating comments within the imports with the nearest import below
Expand Down Expand Up @@ -2094,7 +2085,6 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces,
if (HeaderInsertions.empty() && HeadersToDelete.empty())
return Replaces;


StringRef FileName = Replaces.begin()->getFilePath();
tooling::HeaderIncludes Includes(FileName, Code, Style.IncludeStyle);

Expand Down Expand Up @@ -2127,7 +2117,8 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces,
auto Err = Result.add(*Replace);
if (Err) {
llvm::consumeError(std::move(Err));
unsigned NewOffset = Result.getShiftedCodePosition(Replace->getOffset());
unsigned NewOffset =
Result.getShiftedCodePosition(Replace->getOffset());
auto Shifted = tooling::Replacement(FileName, NewOffset, 0,
Replace->getReplacementText());
Result = Result.merge(tooling::Replacements(Shifted));
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Format/FormatToken.h
Expand Up @@ -489,8 +489,7 @@ struct FormatToken {
bool opensBlockOrBlockTypeList(const FormatStyle &Style) const {
if (is(TT_TemplateString) && opensScope())
return true;
return is(TT_ArrayInitializerLSquare) ||
is(TT_ProtoExtensionLSquare) ||
return is(TT_ArrayInitializerLSquare) || is(TT_ProtoExtensionLSquare) ||
(is(tok::l_brace) &&
(BlockKind == BK_Block || is(TT_DictLiteral) ||
(!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/FormatTokenLexer.h
Expand Up @@ -20,8 +20,8 @@
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h"
#include "llvm/Support/Regex.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/Support/Regex.h"

#include <stack>

Expand Down
28 changes: 15 additions & 13 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -61,7 +61,7 @@ class AnnotatingParser {
if (NonTemplateLess.count(CurrentToken->Previous))
return false;

const FormatToken &Previous = *CurrentToken->Previous; // The '<'.
const FormatToken &Previous = *CurrentToken->Previous; // The '<'.
if (Previous.Previous) {
if (Previous.Previous->Tok.isLiteral())
return false;
Expand Down Expand Up @@ -365,7 +365,7 @@ class AnnotatingParser {
// specifier parameter, although this is technically valid:
// [[foo(:)]]
if (AttrTok->is(tok::colon) ||
AttrTok->startsSequence(tok::identifier, tok::identifier) ||
AttrTok->startsSequence(tok::identifier, tok::identifier) ||
AttrTok->startsSequence(tok::r_paren, tok::identifier))
return false;
if (AttrTok->is(tok::ellipsis))
Expand Down Expand Up @@ -531,11 +531,11 @@ class AnnotatingParser {
// Here, we set FirstObjCSelectorName when the end of the method call is
// reached, in case it was not set already.
if (!Contexts.back().FirstObjCSelectorName) {
FormatToken* Previous = CurrentToken->getPreviousNonComment();
if (Previous && Previous->is(TT_SelectorName)) {
Previous->ObjCSelectorNameParts = 1;
Contexts.back().FirstObjCSelectorName = Previous;
}
FormatToken *Previous = CurrentToken->getPreviousNonComment();
if (Previous && Previous->is(TT_SelectorName)) {
Previous->ObjCSelectorNameParts = 1;
Contexts.back().FirstObjCSelectorName = Previous;
}
} else {
Left->ParameterCount =
Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts;
Expand Down Expand Up @@ -1397,7 +1397,8 @@ class AnnotatingParser {
Current.Type = Current.Previous->Type;
}
} else if (canBeObjCSelectorComponent(Current) &&
// FIXME(bug 36976): ObjC return types shouldn't use TT_CastRParen.
// FIXME(bug 36976): ObjC return types shouldn't use
// TT_CastRParen.
Current.Previous && Current.Previous->is(TT_CastRParen) &&
Current.Previous->MatchingParen &&
Current.Previous->MatchingParen->Previous &&
Expand Down Expand Up @@ -2423,9 +2424,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
if (Right.isOneOf(tok::semi, tok::comma))
return false;
if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) {
bool IsLightweightGeneric =
Right.MatchingParen && Right.MatchingParen->Next &&
Right.MatchingParen->Next->is(tok::colon);
bool IsLightweightGeneric = Right.MatchingParen &&
Right.MatchingParen->Next &&
Right.MatchingParen->Next->is(tok::colon);
return !IsLightweightGeneric && Style.ObjCSpaceBeforeProtocolList;
}
if (Right.is(tok::less) && Left.is(tok::kw_template))
Expand Down Expand Up @@ -2612,7 +2613,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
// Slashes occur in text protocol extension syntax: [type/type] { ... }.
if (Left.is(tok::slash) || Right.is(tok::slash))
return false;
if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
if (Left.MatchingParen &&
Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
Right.isOneOf(tok::l_brace, tok::less))
return !Style.Cpp11BracedListStyle;
// A percent is probably part of a formatting specification, such as %lld.
Expand Down Expand Up @@ -3129,7 +3131,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
// function f(): a is B { ... }
// Do not break before is in these cases.
if (Right.is(Keywords.kw_is)) {
const FormatToken* Next = Right.getNextNonComment();
const FormatToken *Next = Right.getNextNonComment();
// If `is` is followed by a colon, it's likely that it's a dict key, so
// ignore it for this check.
// For example this is common in Polymer:
Expand Down
19 changes: 7 additions & 12 deletions clang/lib/Format/UnwrappedLineFormatter.cpp
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include "NamespaceEndCommentsFixer.h"
#include "UnwrappedLineFormatter.h"
#include "NamespaceEndCommentsFixer.h"
#include "WhitespaceManager.h"
#include "llvm/Support/Debug.h"
#include <queue>
Expand Down Expand Up @@ -690,10 +690,8 @@ class LineFormatter {
/// Formats an \c AnnotatedLine and returns the penalty.
///
/// If \p DryRun is \c false, directly applies the changes.
virtual unsigned formatLine(const AnnotatedLine &Line,
unsigned FirstIndent,
unsigned FirstStartColumn,
bool DryRun) = 0;
virtual unsigned formatLine(const AnnotatedLine &Line, unsigned FirstIndent,
unsigned FirstStartColumn, bool DryRun) = 0;

protected:
/// If the \p State's next token is an r_brace closing a nested block,
Expand Down Expand Up @@ -1008,13 +1006,10 @@ class OptimizingLineFormatter : public LineFormatter {

} // anonymous namespace

unsigned
UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,
bool DryRun, int AdditionalIndent,
bool FixBadIndentation,
unsigned FirstStartColumn,
unsigned NextStartColumn,
unsigned LastStartColumn) {
unsigned UnwrappedLineFormatter::format(
const SmallVectorImpl<AnnotatedLine *> &Lines, bool DryRun,
int AdditionalIndent, bool FixBadIndentation, unsigned FirstStartColumn,
unsigned NextStartColumn, unsigned LastStartColumn) {
LineJoiner Joiner(Style, Keywords, Lines);

// Try to look up already computed penalty in DryRun-mode.
Expand Down

0 comments on commit 5bcf99b

Please sign in to comment.