Skip to content

Commit

Permalink
[clang][NFC] Annotate Sema/ScopeInfo.h with preferred_type
Browse files Browse the repository at this point in the history
This helps debuggers to display values in bit-fields in a more helpful way.
  • Loading branch information
Endilll committed Feb 10, 2024
1 parent 76e3759 commit 4e16a75
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions clang/include/clang/Sema/ScopeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class PossiblyUnreachableDiag {
: PD(PD), Loc(Loc), Stmts(Stmts) {}
};

enum class FirstCoroutineStmtKind { co_return, co_await, co_yield };

/// Retains information about a function, method, or block that is
/// currently being parsed.
class FunctionScopeInfo {
Expand Down Expand Up @@ -170,6 +172,7 @@ class FunctionScopeInfo {

/// An enumeration representing the kind of the first coroutine statement
/// in the function. One of co_return, co_await, or co_yield.
LLVM_PREFERRED_TYPE(FirstCoroutineStmtKind)
unsigned char FirstCoroutineStmtKind : 2;

/// Whether we found an immediate-escalating expression.
Expand Down Expand Up @@ -502,22 +505,30 @@ class FunctionScopeInfo {
assert(FirstCoroutineStmtLoc.isInvalid() &&
"first coroutine statement location already set");
FirstCoroutineStmtLoc = Loc;
FirstCoroutineStmtKind = llvm::StringSwitch<unsigned char>(Keyword)
.Case("co_return", 0)
.Case("co_await", 1)
.Case("co_yield", 2);
FirstCoroutineStmtKind =
llvm::StringSwitch<unsigned char>(Keyword)
.Case("co_return",
llvm::to_underlying(FirstCoroutineStmtKind::co_return))
.Case("co_await",
llvm::to_underlying(FirstCoroutineStmtKind::co_await))
.Case("co_yield",
llvm::to_underlying(FirstCoroutineStmtKind::co_yield));
}

StringRef getFirstCoroutineStmtKeyword() const {
assert(FirstCoroutineStmtLoc.isValid()
&& "no coroutine statement available");
switch (FirstCoroutineStmtKind) {
case 0: return "co_return";
case 1: return "co_await";
case 2: return "co_yield";
default:
llvm_unreachable("FirstCoroutineStmtKind has an invalid value");
auto Value =
static_cast<enum FirstCoroutineStmtKind>(FirstCoroutineStmtKind);
switch (Value) {
case FirstCoroutineStmtKind::co_return:
return "co_return";
case FirstCoroutineStmtKind::co_await:
return "co_await";
case FirstCoroutineStmtKind::co_yield:
return "co_yield";
};
llvm_unreachable("FirstCoroutineStmtKind has an invalid value");
}

void setNeedsCoroutineSuspends(bool value = true) {
Expand Down Expand Up @@ -582,25 +593,31 @@ class Capture {
QualType CaptureType;

/// The CaptureKind of this capture.
LLVM_PREFERRED_TYPE(CaptureKind)
unsigned Kind : 2;

/// Whether this is a nested capture (a capture of an enclosing capturing
/// scope's capture).
LLVM_PREFERRED_TYPE(bool)
unsigned Nested : 1;

/// Whether this is a capture of '*this'.
LLVM_PREFERRED_TYPE(bool)
unsigned CapturesThis : 1;

/// Whether an explicit capture has been odr-used in the body of the
/// lambda.
LLVM_PREFERRED_TYPE(bool)
unsigned ODRUsed : 1;

/// Whether an explicit capture has been non-odr-used in the body of
/// the lambda.
LLVM_PREFERRED_TYPE(bool)
unsigned NonODRUsed : 1;

/// Whether the capture is invalid (a capture was required but the entity is
/// non-capturable).
LLVM_PREFERRED_TYPE(bool)
unsigned Invalid : 1;

public:
Expand Down

0 comments on commit 4e16a75

Please sign in to comment.