Skip to content

Commit

Permalink
Merged main:00dc97f16708 into amd-gfx:81b8a3da9777
Browse files Browse the repository at this point in the history
Local branch amd-gfx 81b8a3d Merged main:0b84afa5fcb4 into amd-gfx:1a56045b754d
Remote branch main 00dc97f [clang-format] PR48594 BraceWrapping: SplitEmptyRecord ignored for templates
  • Loading branch information
Sw authored and Sw committed Jan 17, 2021
2 parents 81b8a3d + 00dc97f commit b78cdb3
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 277 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ pythonenv*
/clang/utils/analyzer/projects/*/PatchedSource
/clang/utils/analyzer/projects/*/ScanBuildResults
/clang/utils/analyzer/projects/*/RefScanBuildResults
# automodapi puts generated documentation files here.
/lldb/docs/python_api/
24 changes: 0 additions & 24 deletions clang/docs/ClangFormatStyleOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2181,30 +2181,6 @@ the configuration (without a prefix: ``Auto``).



**IndentPragmas** (``bool``)
Indent pragmas

When ``false``, pragmas are flushed left or follow IndentPPDirectives.
When ``true``, pragmas are indented to the current scope level.

.. code-block:: c++

false: true:
#pragma once vs #pragma once
void foo() { void foo() {
#pragma omp simd #pragma omp simd
for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
#pragma omp simd #pragma omp simd
for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
} }
#if 1 #if 1
#pragma omp simd #pragma omp simd
for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
} }
#endif #endif
} }
} }

**IndentRequires** (``bool``)
Indent the requires clause in a template

Expand Down
24 changes: 0 additions & 24 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1792,29 +1792,6 @@ struct FormatStyle {
/// \endcode
bool IndentGotoLabels;

/// Indent pragmas
///
/// When ``false``, pragmas are flushed left or follow IndentPPDirectives.
/// When ``true``, pragmas are indented to the current scope level.
/// \code
/// false: true:
/// #pragma once vs #pragma once
/// void foo() { void foo() {
/// #pragma omp simd #pragma omp simd
/// for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
/// #pragma omp simd #pragma omp simd
/// for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
/// } }
/// #if 1 #if 1
/// #pragma omp simd #pragma omp simd
/// for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
/// } }
/// #endif #endif
/// } }
/// } }
/// \endcode
bool IndentPragmas;

/// Options for indenting preprocessor directives.
enum PPDirectiveIndentStyle : unsigned char {
/// Does not indent any directives.
Expand Down Expand Up @@ -2790,7 +2767,6 @@ struct FormatStyle {
IndentCaseLabels == R.IndentCaseLabels &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentGotoLabels == R.IndentGotoLabels &&
IndentPragmas == R.IndentPragmas &&
IndentPPDirectives == R.IndentPPDirectives &&
IndentExternBlock == R.IndentExternBlock &&
IndentRequires == R.IndentRequires && IndentWidth == R.IndentWidth &&
Expand Down
6 changes: 0 additions & 6 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,6 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
State.Line->Type == LT_ImportStatement)) {
Spaces += State.FirstIndent;

bool isPragmaLine =
State.Line->First->startsSequence(tok::hash, tok::pp_pragma);
// If indenting pragmas remove the extra space for the #.
if (Style.IndentPragmas && isPragmaLine)
Spaces--;

// For preprocessor indent with tabs, State.Column will be 1 because of the
// hash. This causes second-level indents onward to have an extra space
// after the tabs. We avoid this misalignment by subtracting 1 from the
Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
IO.mapOptional("IndentCaseBlocks", Style.IndentCaseBlocks);
IO.mapOptional("IndentGotoLabels", Style.IndentGotoLabels);
IO.mapOptional("IndentPragmas", Style.IndentPragmas);
IO.mapOptional("IndentPPDirectives", Style.IndentPPDirectives);
IO.mapOptional("IndentExternBlock", Style.IndentExternBlock);
IO.mapOptional("IndentRequires", Style.IndentRequires);
Expand Down Expand Up @@ -926,7 +925,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.IndentCaseLabels = false;
LLVMStyle.IndentCaseBlocks = false;
LLVMStyle.IndentGotoLabels = true;
LLVMStyle.IndentPragmas = false;
LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
LLVMStyle.IndentRequires = false;
LLVMStyle.IndentWrappedFunctionNames = false;
Expand Down
48 changes: 33 additions & 15 deletions clang/lib/Format/UnwrappedLineFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ class LineJoiner {
return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock
? tryMergeSimpleBlock(I, E, Limit)
: 0;

if (Tok && Tok->is(tok::kw_template) &&
Style.BraceWrapping.SplitEmptyRecord && EmptyBlock) {
return 0;
}
}

// FIXME: TheLine->Level != 0 might or might not be the right check to do.
Expand Down Expand Up @@ -355,6 +360,30 @@ class LineJoiner {
if (TheLine->First->is(tok::l_brace) && I != AnnotatedLines.begin() &&
I[-1]->First->isOneOf(tok::kw_case, tok::kw_default))
return 0;

// Don't merge an empty template class or struct if SplitEmptyRecords
// is defined.
if (Style.BraceWrapping.SplitEmptyRecord &&
TheLine->Last->is(tok::l_brace) && I != AnnotatedLines.begin() &&
I[-1]->Last) {
const FormatToken *Previous = I[-1]->Last;
if (Previous) {
if (Previous->is(tok::comment))
Previous = Previous->getPreviousNonComment();
if (Previous) {
if (Previous->is(tok::greater))
return 0;
if (Previous->is(tok::identifier)) {
const FormatToken *PreviousPrevious =
Previous->getPreviousNonComment();
if (PreviousPrevious &&
PreviousPrevious->isOneOf(tok::kw_class, tok::kw_struct))
return 0;
}
}
}
}

// Try to merge a block with left brace wrapped that wasn't yet covered
if (TheLine->Last->is(tok::l_brace)) {
return !Style.BraceWrapping.AfterFunction ||
Expand Down Expand Up @@ -1237,21 +1266,10 @@ void UnwrappedLineFormatter::formatFirstToken(
}

// Preprocessor directives get indented before the hash only if specified
if (Line.Type == LT_PreprocessorDirective ||
Line.Type == LT_ImportStatement) {
switch (Style.IndentPPDirectives) {
case FormatStyle::PPDIS_AfterHash:
Indent = 0;
break;
case FormatStyle::PPDIS_None:
case FormatStyle::PPDIS_BeforeHash: {
// If we want to indent pragmas.
bool isPragmaLine = RootToken.startsSequence(tok::hash, tok::pp_pragma);
if (!Style.IndentPragmas && isPragmaLine)
Indent = 0;
} break;
}
}
if (Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
(Line.Type == LT_PreprocessorDirective ||
Line.Type == LT_ImportStatement))
Indent = 0;

Whitespaces->replaceWhitespace(RootToken, Newlines, Indent, Indent,
/*IsAligned=*/false,
Expand Down
15 changes: 2 additions & 13 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ void UnwrappedLineParser::parseChildBlock() {
nextToken();
}

void UnwrappedLineParser::parsePPDirective(unsigned Level) {
void UnwrappedLineParser::parsePPDirective() {
assert(FormatTok->Tok.is(tok::hash) && "'#' expected");
ScopedMacroState MacroState(*Line, Tokens, FormatTok);

Expand Down Expand Up @@ -745,17 +745,6 @@ void UnwrappedLineParser::parsePPDirective(unsigned Level) {
case tok::pp_endif:
parsePPEndIf();
break;
case tok::pp_pragma: {
bool IndentPPDirectives =
Style.IndentPPDirectives != FormatStyle::PPDIS_None;
unsigned CurrentLevel = Line->Level;
Line->Level =
Style.IndentPragmas
? (IndentPPDirectives ? (Level - (PPBranchLevel + 1)) : Level)
: CurrentLevel;
parsePPUnknown();
Line->Level = CurrentLevel;
} break;
default:
parsePPUnknown();
break;
Expand Down Expand Up @@ -3184,7 +3173,7 @@ void UnwrappedLineParser::readToken(int LevelDifference) {
PPBranchLevel > 0)
Line->Level += PPBranchLevel;
flushComments(isOnNewLine(*FormatTok));
parsePPDirective(Line->Level);
parsePPDirective();
}
while (FormatTok->getType() == TT_ConflictStart ||
FormatTok->getType() == TT_ConflictEnd ||
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/UnwrappedLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class UnwrappedLineParser {
void parseBlock(bool MustBeDeclaration, bool AddLevel = true,
bool MunchSemi = true);
void parseChildBlock();
void parsePPDirective(unsigned Level);
void parsePPDirective();
void parsePPDefine();
void parsePPIf(bool IfDef);
void parsePPElIf();
Expand Down
Loading

0 comments on commit b78cdb3

Please sign in to comment.