Skip to content

Commit 555cfc8

Browse files
EndilllGeorgeARM
authored andcommitted
[clang][NFC] Reland "Convert Sema::TryCaptureKind to scoped enum"
1 parent 0e64ad2 commit 555cfc8

File tree

6 files changed

+41
-46
lines changed

6 files changed

+41
-46
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ enum class TrivialABIHandling {
646646
ConsiderTrivialABI
647647
};
648648

649+
enum class TryCaptureKind { Implicit, ExplicitByVal, ExplicitByRef };
650+
649651
/// Sema - This implements semantic analysis and AST building for C.
650652
/// \nosubgrouping
651653
class Sema final : public SemaBase {
@@ -6776,12 +6778,6 @@ class Sema final : public SemaBase {
67766778
ExprResult CheckLValueToRValueConversionOperand(Expr *E);
67776779
void CleanupVarDeclMarking();
67786780

6779-
enum TryCaptureKind {
6780-
TryCapture_Implicit,
6781-
TryCapture_ExplicitByVal,
6782-
TryCapture_ExplicitByRef
6783-
};
6784-
67856781
/// Try to capture the given variable.
67866782
///
67876783
/// \param Var The variable to capture.
@@ -6823,7 +6819,7 @@ class Sema final : public SemaBase {
68236819

68246820
/// Try to capture the given variable.
68256821
bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc,
6826-
TryCaptureKind Kind = TryCapture_Implicit,
6822+
TryCaptureKind Kind = TryCaptureKind::Implicit,
68276823
SourceLocation EllipsisLoc = SourceLocation());
68286824

68296825
/// Checks if the variable must be captured.

clang/lib/Sema/SemaExpr.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18539,7 +18539,7 @@ MarkVarDeclODRUsed(ValueDecl *V, SourceLocation Loc, Sema &SemaRef,
1853918539
QualType CaptureType, DeclRefType;
1854018540
if (SemaRef.LangOpts.OpenMP)
1854118541
SemaRef.OpenMP().tryCaptureOpenMPLambdas(V);
18542-
SemaRef.tryCaptureVariable(V, Loc, Sema::TryCapture_Implicit,
18542+
SemaRef.tryCaptureVariable(V, Loc, TryCaptureKind::Implicit,
1854318543
/*EllipsisLoc*/ SourceLocation(),
1854418544
/*BuildAndDiagnose*/ true, CaptureType,
1854518545
DeclRefType, FunctionScopeIndexToStopAt);
@@ -18844,12 +18844,12 @@ static bool captureInBlock(BlockScopeInfo *BSI, ValueDecl *Var,
1884418844
static bool captureInCapturedRegion(
1884518845
CapturedRegionScopeInfo *RSI, ValueDecl *Var, SourceLocation Loc,
1884618846
const bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType,
18847-
const bool RefersToCapturedVariable, Sema::TryCaptureKind Kind,
18848-
bool IsTopScope, Sema &S, bool Invalid) {
18847+
const bool RefersToCapturedVariable, TryCaptureKind Kind, bool IsTopScope,
18848+
Sema &S, bool Invalid) {
1884918849
// By default, capture variables by reference.
1885018850
bool ByRef = true;
18851-
if (IsTopScope && Kind != Sema::TryCapture_Implicit) {
18852-
ByRef = (Kind == Sema::TryCapture_ExplicitByRef);
18851+
if (IsTopScope && Kind != TryCaptureKind::Implicit) {
18852+
ByRef = (Kind == TryCaptureKind::ExplicitByRef);
1885318853
} else if (S.getLangOpts().OpenMP && RSI->CapRegionKind == CR_OpenMP) {
1885418854
// Using an LValue reference type is consistent with Lambdas (see below).
1885518855
if (S.OpenMP().isOpenMPCapturedDecl(Var)) {
@@ -18885,13 +18885,13 @@ static bool captureInLambda(LambdaScopeInfo *LSI, ValueDecl *Var,
1888518885
SourceLocation Loc, const bool BuildAndDiagnose,
1888618886
QualType &CaptureType, QualType &DeclRefType,
1888718887
const bool RefersToCapturedVariable,
18888-
const Sema::TryCaptureKind Kind,
18888+
const TryCaptureKind Kind,
1888918889
SourceLocation EllipsisLoc, const bool IsTopScope,
1889018890
Sema &S, bool Invalid) {
1889118891
// Determine whether we are capturing by reference or by value.
1889218892
bool ByRef = false;
18893-
if (IsTopScope && Kind != Sema::TryCapture_Implicit) {
18894-
ByRef = (Kind == Sema::TryCapture_ExplicitByRef);
18893+
if (IsTopScope && Kind != TryCaptureKind::Implicit) {
18894+
ByRef = (Kind == TryCaptureKind::ExplicitByRef);
1889518895
} else {
1889618896
ByRef = (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
1889718897
}
@@ -19169,7 +19169,7 @@ bool Sema::tryCaptureVariable(
1916919169
CaptureType = Var->getType();
1917019170
DeclRefType = CaptureType.getNonReferenceType();
1917119171
bool Nested = false;
19172-
bool Explicit = (Kind != TryCapture_Implicit);
19172+
bool Explicit = (Kind != TryCaptureKind::Implicit);
1917319173
unsigned FunctionScopesIndex = MaxFunctionScopesIndex;
1917419174
do {
1917519175

@@ -19411,9 +19411,9 @@ bool Sema::tryCaptureVariable(ValueDecl *Var, SourceLocation Loc,
1941119411
bool Sema::NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc) {
1941219412
QualType CaptureType;
1941319413
QualType DeclRefType;
19414-
return !tryCaptureVariable(Var, Loc, TryCapture_Implicit, SourceLocation(),
19415-
/*BuildAndDiagnose=*/false, CaptureType,
19416-
DeclRefType, nullptr);
19414+
return !tryCaptureVariable(
19415+
Var, Loc, TryCaptureKind::Implicit, SourceLocation(),
19416+
/*BuildAndDiagnose=*/false, CaptureType, DeclRefType, nullptr);
1941719417
}
1941819418

1941919419
QualType Sema::getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc) {
@@ -19423,9 +19423,9 @@ QualType Sema::getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc) {
1942319423
QualType DeclRefType;
1942419424

1942519425
// Determine whether we can capture this variable.
19426-
if (tryCaptureVariable(Var, Loc, TryCapture_Implicit, SourceLocation(),
19427-
/*BuildAndDiagnose=*/false, CaptureType,
19428-
DeclRefType, nullptr))
19426+
if (tryCaptureVariable(Var, Loc, TryCaptureKind::Implicit, SourceLocation(),
19427+
/*BuildAndDiagnose=*/false, CaptureType, DeclRefType,
19428+
nullptr))
1942919429
return QualType();
1943019430

1943119431
return DeclRefType;
@@ -20082,7 +20082,7 @@ static void DoMarkBindingDeclReferenced(Sema &SemaRef, SourceLocation Loc,
2008220082
OdrUseContext OdrUse = isOdrUseContext(SemaRef);
2008320083
if (OdrUse == OdrUseContext::Used) {
2008420084
QualType CaptureType, DeclRefType;
20085-
SemaRef.tryCaptureVariable(BD, Loc, Sema::TryCapture_Implicit,
20085+
SemaRef.tryCaptureVariable(BD, Loc, TryCaptureKind::Implicit,
2008620086
/*EllipsisLoc*/ SourceLocation(),
2008720087
/*BuildAndDiagnose*/ true, CaptureType,
2008820088
DeclRefType,

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9119,16 +9119,16 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(
91199119
// error would get diagnosed when the lambda becomes capture ready.
91209120
QualType CaptureType, DeclRefType;
91219121
SourceLocation ExprLoc = VarExpr->getExprLoc();
9122-
if (S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit,
9123-
/*EllipsisLoc*/ SourceLocation(),
9124-
/*BuildAndDiagnose*/false, CaptureType,
9125-
DeclRefType, nullptr)) {
9122+
if (S.tryCaptureVariable(Var, ExprLoc, TryCaptureKind::Implicit,
9123+
/*EllipsisLoc*/ SourceLocation(),
9124+
/*BuildAndDiagnose*/ false, CaptureType,
9125+
DeclRefType, nullptr)) {
91269126
// We will never be able to capture this variable, and we need
91279127
// to be able to in any and all instantiations, so diagnose it.
9128-
S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit,
9129-
/*EllipsisLoc*/ SourceLocation(),
9130-
/*BuildAndDiagnose*/true, CaptureType,
9131-
DeclRefType, nullptr);
9128+
S.tryCaptureVariable(Var, ExprLoc, TryCaptureKind::Implicit,
9129+
/*EllipsisLoc*/ SourceLocation(),
9130+
/*BuildAndDiagnose*/ true, CaptureType,
9131+
DeclRefType, nullptr);
91329132
}
91339133
}
91349134
});

clang/lib/Sema/SemaLambda.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,12 @@ UnsignedOrNone clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(
207207
// checking whether all enclosing lambdas of the capture-ready lambda allow
208208
// the capture - i.e. make sure it is capture-capable.
209209
QualType CaptureType, DeclRefType;
210-
const bool CanCaptureVariable =
211-
!S.tryCaptureVariable(VarToCapture,
212-
/*ExprVarIsUsedInLoc*/ SourceLocation(),
213-
clang::Sema::TryCapture_Implicit,
214-
/*EllipsisLoc*/ SourceLocation(),
215-
/*BuildAndDiagnose*/ false, CaptureType,
216-
DeclRefType, &IndexOfCaptureReadyLambda);
210+
const bool CanCaptureVariable = !S.tryCaptureVariable(
211+
VarToCapture,
212+
/*ExprVarIsUsedInLoc*/ SourceLocation(), TryCaptureKind::Implicit,
213+
/*EllipsisLoc*/ SourceLocation(),
214+
/*BuildAndDiagnose*/ false, CaptureType, DeclRefType,
215+
&IndexOfCaptureReadyLambda);
217216
if (!CanCaptureVariable)
218217
return NoLambdaIsCaptureCapable;
219218
} else {
@@ -1348,8 +1347,9 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
13481347
if (C->Init.isUsable()) {
13491348
addInitCapture(LSI, cast<VarDecl>(Var), C->Kind == LCK_ByRef);
13501349
} else {
1351-
TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef
1352-
: TryCapture_ExplicitByVal;
1350+
TryCaptureKind Kind = C->Kind == LCK_ByRef
1351+
? TryCaptureKind::ExplicitByRef
1352+
: TryCaptureKind::ExplicitByVal;
13531353
tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
13541354
}
13551355
if (!LSI->Captures.empty())

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5546,7 +5546,7 @@ static CapturedStmt *buildLoopVarFunc(Sema &Actions, QualType LoopVarTy,
55465546
// it in every iteration, capture it by value before it is modified.
55475547
VarDecl *StartVar = cast<VarDecl>(StartExpr->getDecl());
55485548
bool Invalid = Actions.tryCaptureVariable(StartVar, {},
5549-
Sema::TryCapture_ExplicitByVal, {});
5549+
TryCaptureKind::ExplicitByVal, {});
55505550
(void)Invalid;
55515551
assert(!Invalid && "Expecting capture-by-value to work.");
55525552

clang/lib/Sema/TreeTransform.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15577,11 +15577,10 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
1557715577
assert(C->capturesVariable() && "unexpected kind of lambda capture");
1557815578

1557915579
// Determine the capture kind for Sema.
15580-
Sema::TryCaptureKind Kind
15581-
= C->isImplicit()? Sema::TryCapture_Implicit
15582-
: C->getCaptureKind() == LCK_ByCopy
15583-
? Sema::TryCapture_ExplicitByVal
15584-
: Sema::TryCapture_ExplicitByRef;
15580+
TryCaptureKind Kind = C->isImplicit() ? TryCaptureKind::Implicit
15581+
: C->getCaptureKind() == LCK_ByCopy
15582+
? TryCaptureKind::ExplicitByVal
15583+
: TryCaptureKind::ExplicitByRef;
1558515584
SourceLocation EllipsisLoc;
1558615585
if (C->isPackExpansion()) {
1558715586
UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());

0 commit comments

Comments
 (0)