Skip to content

Commit

Permalink
Updates code for the break after return type with one argument
Browse files Browse the repository at this point in the history
- Updates Format.h
- Updates Format.cpp
- Updates TokenAnnotator.cpp

Bug : https://review.haiku-os.org/c/haiku/+/4098/1/src/preferences/input/MouseView.cpp#149
  • Loading branch information
saloniig committed Jul 2, 2021
1 parent 15a7ccb commit 1c63127
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 39 deletions.
20 changes: 0 additions & 20 deletions clang/include/clang/Format/Format.h
Expand Up @@ -430,26 +430,6 @@ struct FormatStyle {
/// If ``true``, comments indent can be one level more
IndentComment AllowCommentsToIndentOneLevelMore;

// Allow break after return
enum BreakForReturn {
/// Break after return with one parameter
/// \code
/// void
/// foo::foo(a)
/// // It should start from new line
/// \endcode
BFR_True,
/// Don't break after return with one parameter
/// \code
/// void foo::foo(a)
/// // It should be in the same line
/// \endcode
BFR_False
};

/// If ``true``, break after return with one parameter
BreakForReturn AllowBreakAfterReturn;

// Allow multiline indentation for loop
enum IndentMultiLineForLoop {
/// Keep the indent as it is
Expand Down
10 changes: 0 additions & 10 deletions clang/lib/Format/Format.cpp
Expand Up @@ -148,13 +148,6 @@ template <> struct ScalarEnumerationTraits<FormatStyle::IndentComment> {
}
};

template <> struct ScalarEnumerationTraits<FormatStyle::BreakForReturn> {
static void enumeration(IO &IO, FormatStyle::BreakForReturn &Value) {
IO.enumCase(Value, "true", FormatStyle::BFR_True);
IO.enumCase(Value, "false", FormatStyle::BFR_False);
}
};

template <> struct ScalarEnumerationTraits<FormatStyle::IndentMultiLineForLoop> {
static void enumeration(IO &IO, FormatStyle::IndentMultiLineForLoop &Value) {
IO.enumCase(Value, "true", FormatStyle::IML_True);
Expand Down Expand Up @@ -473,8 +466,6 @@ template <> struct MappingTraits<FormatStyle> {
Style.AllowShortFunctionsOnASingleLine);
IO.mapOptional("AllowCommentsToIndentOneLevelMore",
Style.AllowCommentsToIndentOneLevelMore);
IO.mapOptional("AllowBreakAfterReturn",
Style.AllowBreakAfterReturn);
IO.mapOptional("AllowShortLambdasOnASingleLine",
Style.AllowShortLambdasOnASingleLine);
IO.mapOptional("AllowShortIfStatementsOnASingleLine",
Expand Down Expand Up @@ -1323,7 +1314,6 @@ Style.AccessModifierOffset = -4;
Style.SpaceAfterTemplateKeyword = false;
Style.SpaceBeforeParens = FormatStyle::SBPO_Haiku;
Style.AllowCommentsToIndentOneLevelMore = FormatStyle::IC_True;
Style.AllowBreakAfterReturn = FormatStyle::BFR_True;
Style.AllowIndentMultiLineForLoop = FormatStyle::IML_True;

return Style;
Expand Down
11 changes: 2 additions & 9 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -2383,6 +2383,8 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
return true;
if (Next->Next == Next->MatchingParen)
return true; // Empty parentheses.
if (Next->is(tok::l_paren) && Next->Next->Next == Next->MatchingParen)
return true;
// If there is an &/&& after the r_paren, this is likely a function.
if (Next->MatchingParen->Next &&
Next->MatchingParen->Next->is(TT_PointerOrReference))
Expand Down Expand Up @@ -2438,16 +2440,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
: Line.FirstStartColumn + Line.First->ColumnWidth;
FormatToken *Current = Line.First->Next;
bool InFunctionDecl = Line.MightBeFunctionDecl;
bool isFirst = true;
while (Current) {
// Sometimes void foo::foo(a) doesn't break and
// there is need to set type as TT_FunctionDeclarationName
if(!Current->IsFirst && isFirst && Style.AllowBreakAfterReturn == FormatStyle::BFR_True) {
if (Current->is(TT_StartOfName)) {
Current->setType(TT_FunctionDeclarationName);
}
isFirst = false;
}
if (isFunctionDeclarationName(*Current, Line))
Current->setType(TT_FunctionDeclarationName);
if (Current->is(TT_LineComment)) {
Expand Down

0 comments on commit 1c63127

Please sign in to comment.