Skip to content

Commit

Permalink
[clang][NFC] Inline some lambdas to their only call site
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Dec 14, 2023
1 parent 8cb8428 commit 2eb1e75
Showing 1 changed file with 91 additions and 102 deletions.
193 changes: 91 additions & 102 deletions clang/lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,18 +1311,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
D.takeAttributes(Attributes);
}

// Helper to emit a warning if we see a CUDA host/device/global attribute
// after '(...)'. nvcc doesn't accept this.
auto WarnIfHasCUDATargetAttr = [&] {
if (getLangOpts().CUDA)
for (const ParsedAttr &A : Attributes)
if (A.getKind() == ParsedAttr::AT_CUDADevice ||
A.getKind() == ParsedAttr::AT_CUDAHost ||
A.getKind() == ParsedAttr::AT_CUDAGlobal)
Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
<< A.getAttrName()->getName();
};

MultiParseScope TemplateParamScope(*this);
if (Tok.is(tok::less)) {
Diag(Tok, getLangOpts().CPlusPlus20
Expand Down Expand Up @@ -1377,91 +1365,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
bool HasSpecifiers = false;
SourceLocation MutableLoc;

auto ParseConstexprAndMutableSpecifiers = [&] {
// GNU-style attributes must be parsed before the mutable specifier to
// be compatible with GCC. MSVC-style attributes must be parsed before
// the mutable specifier to be compatible with MSVC.
MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
// Parse mutable-opt and/or constexpr-opt or consteval-opt, and update
// the DeclEndLoc.
SourceLocation ConstexprLoc;
SourceLocation ConstevalLoc;
SourceLocation StaticLoc;

tryConsumeLambdaSpecifierToken(*this, MutableLoc, StaticLoc, ConstexprLoc,
ConstevalLoc, DeclEndLoc);

DiagnoseStaticSpecifierRestrictions(*this, StaticLoc, MutableLoc, Intro);

addStaticToLambdaDeclSpecifier(*this, StaticLoc, DS);
addConstexprToLambdaDeclSpecifier(*this, ConstexprLoc, DS);
addConstevalToLambdaDeclSpecifier(*this, ConstevalLoc, DS);
};

auto ParseLambdaSpecifiers =
[&](MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo,
SourceLocation EllipsisLoc) {
// Parse exception-specification[opt].
ExceptionSpecificationType ESpecType = EST_None;
SourceRange ESpecRange;
SmallVector<ParsedType, 2> DynamicExceptions;
SmallVector<SourceRange, 2> DynamicExceptionRanges;
ExprResult NoexceptExpr;
CachedTokens *ExceptionSpecTokens;

ESpecType = tryParseExceptionSpecification(
/*Delayed=*/false, ESpecRange, DynamicExceptions,
DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);

if (ESpecType != EST_None)
DeclEndLoc = ESpecRange.getEnd();

// Parse attribute-specifier[opt].
if (MaybeParseCXX11Attributes(Attributes))
DeclEndLoc = Attributes.Range.getEnd();

// Parse OpenCL addr space attribute.
if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
tok::kw___constant, tok::kw___generic)) {
ParseOpenCLQualifiers(DS.getAttributes());
ConsumeToken();
}

SourceLocation FunLocalRangeEnd = DeclEndLoc;

// Parse trailing-return-type[opt].
if (Tok.is(tok::arrow)) {
FunLocalRangeEnd = Tok.getLocation();
SourceRange Range;
TrailingReturnType = ParseTrailingReturnType(
Range, /*MayBeFollowedByDirectInit*/ false);
TrailingReturnTypeLoc = Range.getBegin();
if (Range.getEnd().isValid())
DeclEndLoc = Range.getEnd();
}

SourceLocation NoLoc;
D.AddTypeInfo(
DeclaratorChunk::getFunction(
/*HasProto=*/true,
/*IsAmbiguous=*/false, LParenLoc, ParamInfo.data(),
ParamInfo.size(), EllipsisLoc, RParenLoc,
/*RefQualifierIsLvalueRef=*/true,
/*RefQualifierLoc=*/NoLoc, MutableLoc, ESpecType, ESpecRange,
DynamicExceptions.data(), DynamicExceptionRanges.data(),
DynamicExceptions.size(),
NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
/*ExceptionSpecTokens*/ nullptr,
/*DeclsInPrototype=*/std::nullopt, LParenLoc, FunLocalRangeEnd,
D, TrailingReturnType, TrailingReturnTypeLoc, &DS),
std::move(Attributes), DeclEndLoc);

Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);

if (HasParentheses && Tok.is(tok::kw_requires))
ParseTrailingRequiresClause(D);
};

ParseScope Prototype(this, Scope::FunctionPrototypeScope |
Scope::FunctionDeclarationScope |
Scope::DeclScope);
Expand Down Expand Up @@ -1511,18 +1414,104 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
<< FixItHint::CreateInsertion(Tok.getLocation(), "() ");
}

if (HasParentheses || HasSpecifiers)
ParseConstexprAndMutableSpecifiers();
if (HasParentheses || HasSpecifiers) {
// GNU-style attributes must be parsed before the mutable specifier to
// be compatible with GCC. MSVC-style attributes must be parsed before
// the mutable specifier to be compatible with MSVC.
MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
// Parse mutable-opt and/or constexpr-opt or consteval-opt, and update
// the DeclEndLoc.
SourceLocation ConstexprLoc;
SourceLocation ConstevalLoc;
SourceLocation StaticLoc;

tryConsumeLambdaSpecifierToken(*this, MutableLoc, StaticLoc, ConstexprLoc,
ConstevalLoc, DeclEndLoc);

DiagnoseStaticSpecifierRestrictions(*this, StaticLoc, MutableLoc, Intro);

addStaticToLambdaDeclSpecifier(*this, StaticLoc, DS);
addConstexprToLambdaDeclSpecifier(*this, ConstexprLoc, DS);
addConstevalToLambdaDeclSpecifier(*this, ConstevalLoc, DS);
}

Actions.ActOnLambdaClosureParameters(getCurScope(), ParamInfo);

if (!HasParentheses)
Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);

if (HasSpecifiers || HasParentheses)
ParseLambdaSpecifiers(ParamInfo, EllipsisLoc);
if (HasSpecifiers || HasParentheses) {
// Parse exception-specification[opt].
ExceptionSpecificationType ESpecType = EST_None;
SourceRange ESpecRange;
SmallVector<ParsedType, 2> DynamicExceptions;
SmallVector<SourceRange, 2> DynamicExceptionRanges;
ExprResult NoexceptExpr;
CachedTokens *ExceptionSpecTokens;

ESpecType = tryParseExceptionSpecification(
/*Delayed=*/false, ESpecRange, DynamicExceptions,
DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);

if (ESpecType != EST_None)
DeclEndLoc = ESpecRange.getEnd();

// Parse attribute-specifier[opt].
if (MaybeParseCXX11Attributes(Attributes))
DeclEndLoc = Attributes.Range.getEnd();

// Parse OpenCL addr space attribute.
if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
tok::kw___constant, tok::kw___generic)) {
ParseOpenCLQualifiers(DS.getAttributes());
ConsumeToken();
}

SourceLocation FunLocalRangeEnd = DeclEndLoc;

// Parse trailing-return-type[opt].
if (Tok.is(tok::arrow)) {
FunLocalRangeEnd = Tok.getLocation();
SourceRange Range;
TrailingReturnType =
ParseTrailingReturnType(Range, /*MayBeFollowedByDirectInit=*/false);
TrailingReturnTypeLoc = Range.getBegin();
if (Range.getEnd().isValid())
DeclEndLoc = Range.getEnd();
}

SourceLocation NoLoc;
D.AddTypeInfo(DeclaratorChunk::getFunction(
/*HasProto=*/true,
/*IsAmbiguous=*/false, LParenLoc, ParamInfo.data(),
ParamInfo.size(), EllipsisLoc, RParenLoc,
/*RefQualifierIsLvalueRef=*/true,
/*RefQualifierLoc=*/NoLoc, MutableLoc, ESpecType,
ESpecRange, DynamicExceptions.data(),
DynamicExceptionRanges.data(), DynamicExceptions.size(),
NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
/*ExceptionSpecTokens*/ nullptr,
/*DeclsInPrototype=*/std::nullopt, LParenLoc,
FunLocalRangeEnd, D, TrailingReturnType,
TrailingReturnTypeLoc, &DS),
std::move(Attributes), DeclEndLoc);

WarnIfHasCUDATargetAttr();
Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);

if (HasParentheses && Tok.is(tok::kw_requires))
ParseTrailingRequiresClause(D);
}

// Emit a warning if we see a CUDA host/device/global attribute
// after '(...)'. nvcc doesn't accept this.
if (getLangOpts().CUDA) {
for (const ParsedAttr &A : Attributes)
if (A.getKind() == ParsedAttr::AT_CUDADevice ||
A.getKind() == ParsedAttr::AT_CUDAHost ||
A.getKind() == ParsedAttr::AT_CUDAGlobal)
Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
<< A.getAttrName()->getName();
}

Prototype.Exit();

Expand Down

0 comments on commit 2eb1e75

Please sign in to comment.