Skip to content

Commit 2eb1e75

Browse files
committed
[clang][NFC] Inline some lambdas to their only call site
1 parent 8cb8428 commit 2eb1e75

File tree

1 file changed

+91
-102
lines changed

1 file changed

+91
-102
lines changed

clang/lib/Parse/ParseExprCXX.cpp

Lines changed: 91 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,18 +1311,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
13111311
D.takeAttributes(Attributes);
13121312
}
13131313

1314-
// Helper to emit a warning if we see a CUDA host/device/global attribute
1315-
// after '(...)'. nvcc doesn't accept this.
1316-
auto WarnIfHasCUDATargetAttr = [&] {
1317-
if (getLangOpts().CUDA)
1318-
for (const ParsedAttr &A : Attributes)
1319-
if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1320-
A.getKind() == ParsedAttr::AT_CUDAHost ||
1321-
A.getKind() == ParsedAttr::AT_CUDAGlobal)
1322-
Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1323-
<< A.getAttrName()->getName();
1324-
};
1325-
13261314
MultiParseScope TemplateParamScope(*this);
13271315
if (Tok.is(tok::less)) {
13281316
Diag(Tok, getLangOpts().CPlusPlus20
@@ -1377,91 +1365,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
13771365
bool HasSpecifiers = false;
13781366
SourceLocation MutableLoc;
13791367

1380-
auto ParseConstexprAndMutableSpecifiers = [&] {
1381-
// GNU-style attributes must be parsed before the mutable specifier to
1382-
// be compatible with GCC. MSVC-style attributes must be parsed before
1383-
// the mutable specifier to be compatible with MSVC.
1384-
MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1385-
// Parse mutable-opt and/or constexpr-opt or consteval-opt, and update
1386-
// the DeclEndLoc.
1387-
SourceLocation ConstexprLoc;
1388-
SourceLocation ConstevalLoc;
1389-
SourceLocation StaticLoc;
1390-
1391-
tryConsumeLambdaSpecifierToken(*this, MutableLoc, StaticLoc, ConstexprLoc,
1392-
ConstevalLoc, DeclEndLoc);
1393-
1394-
DiagnoseStaticSpecifierRestrictions(*this, StaticLoc, MutableLoc, Intro);
1395-
1396-
addStaticToLambdaDeclSpecifier(*this, StaticLoc, DS);
1397-
addConstexprToLambdaDeclSpecifier(*this, ConstexprLoc, DS);
1398-
addConstevalToLambdaDeclSpecifier(*this, ConstevalLoc, DS);
1399-
};
1400-
1401-
auto ParseLambdaSpecifiers =
1402-
[&](MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo,
1403-
SourceLocation EllipsisLoc) {
1404-
// Parse exception-specification[opt].
1405-
ExceptionSpecificationType ESpecType = EST_None;
1406-
SourceRange ESpecRange;
1407-
SmallVector<ParsedType, 2> DynamicExceptions;
1408-
SmallVector<SourceRange, 2> DynamicExceptionRanges;
1409-
ExprResult NoexceptExpr;
1410-
CachedTokens *ExceptionSpecTokens;
1411-
1412-
ESpecType = tryParseExceptionSpecification(
1413-
/*Delayed=*/false, ESpecRange, DynamicExceptions,
1414-
DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1415-
1416-
if (ESpecType != EST_None)
1417-
DeclEndLoc = ESpecRange.getEnd();
1418-
1419-
// Parse attribute-specifier[opt].
1420-
if (MaybeParseCXX11Attributes(Attributes))
1421-
DeclEndLoc = Attributes.Range.getEnd();
1422-
1423-
// Parse OpenCL addr space attribute.
1424-
if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1425-
tok::kw___constant, tok::kw___generic)) {
1426-
ParseOpenCLQualifiers(DS.getAttributes());
1427-
ConsumeToken();
1428-
}
1429-
1430-
SourceLocation FunLocalRangeEnd = DeclEndLoc;
1431-
1432-
// Parse trailing-return-type[opt].
1433-
if (Tok.is(tok::arrow)) {
1434-
FunLocalRangeEnd = Tok.getLocation();
1435-
SourceRange Range;
1436-
TrailingReturnType = ParseTrailingReturnType(
1437-
Range, /*MayBeFollowedByDirectInit*/ false);
1438-
TrailingReturnTypeLoc = Range.getBegin();
1439-
if (Range.getEnd().isValid())
1440-
DeclEndLoc = Range.getEnd();
1441-
}
1442-
1443-
SourceLocation NoLoc;
1444-
D.AddTypeInfo(
1445-
DeclaratorChunk::getFunction(
1446-
/*HasProto=*/true,
1447-
/*IsAmbiguous=*/false, LParenLoc, ParamInfo.data(),
1448-
ParamInfo.size(), EllipsisLoc, RParenLoc,
1449-
/*RefQualifierIsLvalueRef=*/true,
1450-
/*RefQualifierLoc=*/NoLoc, MutableLoc, ESpecType, ESpecRange,
1451-
DynamicExceptions.data(), DynamicExceptionRanges.data(),
1452-
DynamicExceptions.size(),
1453-
NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
1454-
/*ExceptionSpecTokens*/ nullptr,
1455-
/*DeclsInPrototype=*/std::nullopt, LParenLoc, FunLocalRangeEnd,
1456-
D, TrailingReturnType, TrailingReturnTypeLoc, &DS),
1457-
std::move(Attributes), DeclEndLoc);
1458-
1459-
Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1460-
1461-
if (HasParentheses && Tok.is(tok::kw_requires))
1462-
ParseTrailingRequiresClause(D);
1463-
};
1464-
14651368
ParseScope Prototype(this, Scope::FunctionPrototypeScope |
14661369
Scope::FunctionDeclarationScope |
14671370
Scope::DeclScope);
@@ -1511,18 +1414,104 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
15111414
<< FixItHint::CreateInsertion(Tok.getLocation(), "() ");
15121415
}
15131416

1514-
if (HasParentheses || HasSpecifiers)
1515-
ParseConstexprAndMutableSpecifiers();
1417+
if (HasParentheses || HasSpecifiers) {
1418+
// GNU-style attributes must be parsed before the mutable specifier to
1419+
// be compatible with GCC. MSVC-style attributes must be parsed before
1420+
// the mutable specifier to be compatible with MSVC.
1421+
MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1422+
// Parse mutable-opt and/or constexpr-opt or consteval-opt, and update
1423+
// the DeclEndLoc.
1424+
SourceLocation ConstexprLoc;
1425+
SourceLocation ConstevalLoc;
1426+
SourceLocation StaticLoc;
1427+
1428+
tryConsumeLambdaSpecifierToken(*this, MutableLoc, StaticLoc, ConstexprLoc,
1429+
ConstevalLoc, DeclEndLoc);
1430+
1431+
DiagnoseStaticSpecifierRestrictions(*this, StaticLoc, MutableLoc, Intro);
1432+
1433+
addStaticToLambdaDeclSpecifier(*this, StaticLoc, DS);
1434+
addConstexprToLambdaDeclSpecifier(*this, ConstexprLoc, DS);
1435+
addConstevalToLambdaDeclSpecifier(*this, ConstevalLoc, DS);
1436+
}
15161437

15171438
Actions.ActOnLambdaClosureParameters(getCurScope(), ParamInfo);
15181439

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

1522-
if (HasSpecifiers || HasParentheses)
1523-
ParseLambdaSpecifiers(ParamInfo, EllipsisLoc);
1443+
if (HasSpecifiers || HasParentheses) {
1444+
// Parse exception-specification[opt].
1445+
ExceptionSpecificationType ESpecType = EST_None;
1446+
SourceRange ESpecRange;
1447+
SmallVector<ParsedType, 2> DynamicExceptions;
1448+
SmallVector<SourceRange, 2> DynamicExceptionRanges;
1449+
ExprResult NoexceptExpr;
1450+
CachedTokens *ExceptionSpecTokens;
1451+
1452+
ESpecType = tryParseExceptionSpecification(
1453+
/*Delayed=*/false, ESpecRange, DynamicExceptions,
1454+
DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1455+
1456+
if (ESpecType != EST_None)
1457+
DeclEndLoc = ESpecRange.getEnd();
1458+
1459+
// Parse attribute-specifier[opt].
1460+
if (MaybeParseCXX11Attributes(Attributes))
1461+
DeclEndLoc = Attributes.Range.getEnd();
1462+
1463+
// Parse OpenCL addr space attribute.
1464+
if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1465+
tok::kw___constant, tok::kw___generic)) {
1466+
ParseOpenCLQualifiers(DS.getAttributes());
1467+
ConsumeToken();
1468+
}
1469+
1470+
SourceLocation FunLocalRangeEnd = DeclEndLoc;
1471+
1472+
// Parse trailing-return-type[opt].
1473+
if (Tok.is(tok::arrow)) {
1474+
FunLocalRangeEnd = Tok.getLocation();
1475+
SourceRange Range;
1476+
TrailingReturnType =
1477+
ParseTrailingReturnType(Range, /*MayBeFollowedByDirectInit=*/false);
1478+
TrailingReturnTypeLoc = Range.getBegin();
1479+
if (Range.getEnd().isValid())
1480+
DeclEndLoc = Range.getEnd();
1481+
}
1482+
1483+
SourceLocation NoLoc;
1484+
D.AddTypeInfo(DeclaratorChunk::getFunction(
1485+
/*HasProto=*/true,
1486+
/*IsAmbiguous=*/false, LParenLoc, ParamInfo.data(),
1487+
ParamInfo.size(), EllipsisLoc, RParenLoc,
1488+
/*RefQualifierIsLvalueRef=*/true,
1489+
/*RefQualifierLoc=*/NoLoc, MutableLoc, ESpecType,
1490+
ESpecRange, DynamicExceptions.data(),
1491+
DynamicExceptionRanges.data(), DynamicExceptions.size(),
1492+
NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
1493+
/*ExceptionSpecTokens*/ nullptr,
1494+
/*DeclsInPrototype=*/std::nullopt, LParenLoc,
1495+
FunLocalRangeEnd, D, TrailingReturnType,
1496+
TrailingReturnTypeLoc, &DS),
1497+
std::move(Attributes), DeclEndLoc);
15241498

1525-
WarnIfHasCUDATargetAttr();
1499+
Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1500+
1501+
if (HasParentheses && Tok.is(tok::kw_requires))
1502+
ParseTrailingRequiresClause(D);
1503+
}
1504+
1505+
// Emit a warning if we see a CUDA host/device/global attribute
1506+
// after '(...)'. nvcc doesn't accept this.
1507+
if (getLangOpts().CUDA) {
1508+
for (const ParsedAttr &A : Attributes)
1509+
if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1510+
A.getKind() == ParsedAttr::AT_CUDAHost ||
1511+
A.getKind() == ParsedAttr::AT_CUDAGlobal)
1512+
Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1513+
<< A.getAttrName()->getName();
1514+
}
15261515

15271516
Prototype.Exit();
15281517

0 commit comments

Comments
 (0)