Skip to content

Commit 01a982e

Browse files
committed
[clang][bytcode][NFC] Use UnsignedOrNone for global ids
1 parent f58844b commit 01a982e

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,8 @@ bool Compiler<Emitter>::VisitMaterializeTemporaryExpr(
29122912
OptPrimType SubExprT = classify(SubExpr);
29132913
bool IsStatic = E->getStorageDuration() == SD_Static;
29142914
if (IsStatic) {
2915-
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
2915+
2916+
UnsignedOrNone GlobalIndex = P.createGlobal(E);
29162917
if (!GlobalIndex)
29172918
return false;
29182919

@@ -3009,7 +3010,7 @@ bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
30093010
if (T && !E->isLValue())
30103011
return this->delegate(Init);
30113012

3012-
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
3013+
UnsignedOrNone GlobalIndex = P.createGlobal(E);
30133014
if (!GlobalIndex)
30143015
return false;
30153016

@@ -3353,7 +3354,7 @@ bool Compiler<Emitter>::VisitSourceLocExpr(const SourceLocExpr *E) {
33533354

33543355
auto *UGCD = cast<UnnamedGlobalConstantDecl>(BaseDecl);
33553356

3356-
std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(UGCD);
3357+
UnsignedOrNone GlobalIndex = P.getOrCreateGlobal(UGCD);
33573358
if (!GlobalIndex)
33583359
return false;
33593360

@@ -3876,7 +3877,7 @@ bool Compiler<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
38763877
if (!RD->isCompleteDefinition())
38773878
return this->emitDummyPtr(GuidDecl, E);
38783879

3879-
std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(GuidDecl);
3880+
UnsignedOrNone GlobalIndex = P.getOrCreateGlobal(GuidDecl);
38803881
if (!GlobalIndex)
38813882
return false;
38823883
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
@@ -4868,7 +4869,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
48684869
DeclScope<Emitter> LocalScope(this, VD);
48694870

48704871
// We've already seen and initialized this global.
4871-
if (std::optional<unsigned> GlobalIndex = P.getGlobal(VD)) {
4872+
if (UnsignedOrNone GlobalIndex = P.getGlobal(VD)) {
48724873
if (P.getPtrGlobal(*GlobalIndex).isInitialized())
48734874
return checkDecl();
48744875

@@ -4877,7 +4878,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
48774878
return Init && checkDecl() && initGlobal(*GlobalIndex);
48784879
}
48794880

4880-
std::optional<unsigned> GlobalIndex = P.createGlobal(VD, Init);
4881+
UnsignedOrNone GlobalIndex = P.createGlobal(VD, Init);
48814882

48824883
if (!GlobalIndex)
48834884
return false;
@@ -6810,7 +6811,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
68106811
return F && this->emitGetFnPtr(F, E);
68116812
}
68126813
if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
6813-
if (std::optional<unsigned> Index = P.getOrCreateGlobal(D)) {
6814+
if (UnsignedOrNone Index = P.getOrCreateGlobal(D)) {
68146815
if (!this->emitGetPtrGlobal(*Index, E))
68156816
return false;
68166817
if (OptPrimType T = classify(E->getType())) {

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo &Info) {
331331
/// This is what we do here.
332332
void EvalEmitter::updateGlobalTemporaries() {
333333
for (const auto &[E, Temp] : S.SeenGlobalTemporaries) {
334-
if (std::optional<unsigned> GlobalIndex = P.getGlobal(E)) {
334+
if (UnsignedOrNone GlobalIndex = P.getGlobal(E)) {
335335
const Pointer &Ptr = P.getPtrGlobal(*GlobalIndex);
336336
APValue *Cached = Temp->getOrCreateValue(true);
337337

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Pointer Program::getPtrGlobal(unsigned Idx) const {
111111
return Pointer(Globals[Idx]->block());
112112
}
113113

114-
std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
114+
UnsignedOrNone Program::getGlobal(const ValueDecl *VD) {
115115
if (auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
116116
return It->second;
117117

@@ -131,14 +131,14 @@ std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
131131
return std::nullopt;
132132
}
133133

134-
std::optional<unsigned> Program::getGlobal(const Expr *E) {
134+
UnsignedOrNone Program::getGlobal(const Expr *E) {
135135
if (auto It = GlobalIndices.find(E); It != GlobalIndices.end())
136136
return It->second;
137137
return std::nullopt;
138138
}
139139

140-
std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD,
141-
const Expr *Init) {
140+
UnsignedOrNone Program::getOrCreateGlobal(const ValueDecl *VD,
141+
const Expr *Init) {
142142
if (auto Idx = getGlobal(VD))
143143
return Idx;
144144

@@ -195,8 +195,7 @@ unsigned Program::getOrCreateDummy(const DeclTy &D) {
195195
return I;
196196
}
197197

198-
std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
199-
const Expr *Init) {
198+
UnsignedOrNone Program::createGlobal(const ValueDecl *VD, const Expr *Init) {
200199
bool IsStatic, IsExtern;
201200
bool IsWeak = VD->isWeak();
202201
if (const auto *Var = dyn_cast<VarDecl>(VD)) {
@@ -213,7 +212,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
213212

214213
// Register all previous declarations as well. For extern blocks, just replace
215214
// the index with the new variable.
216-
std::optional<unsigned> Idx =
215+
UnsignedOrNone Idx =
217216
createGlobal(VD, VD->getType(), IsStatic, IsExtern, IsWeak, Init);
218217
if (!Idx)
219218
return std::nullopt;
@@ -240,7 +239,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
240239
return *Idx;
241240
}
242241

243-
std::optional<unsigned> Program::createGlobal(const Expr *E) {
242+
UnsignedOrNone Program::createGlobal(const Expr *E) {
244243
if (auto Idx = getGlobal(E))
245244
return Idx;
246245
if (auto Idx = createGlobal(E, E->getType(), /*isStatic=*/true,
@@ -251,9 +250,9 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
251250
return std::nullopt;
252251
}
253252

254-
std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
255-
bool IsStatic, bool IsExtern,
256-
bool IsWeak, const Expr *Init) {
253+
UnsignedOrNone Program::createGlobal(const DeclTy &D, QualType Ty,
254+
bool IsStatic, bool IsExtern, bool IsWeak,
255+
const Expr *Init) {
257256
// Create a descriptor for the global.
258257
Descriptor *Desc;
259258
const bool IsConst = Ty.isConstQualified();

clang/lib/AST/ByteCode/Program.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ class Program final {
7878
}
7979

8080
/// Finds a global's index.
81-
std::optional<unsigned> getGlobal(const ValueDecl *VD);
82-
std::optional<unsigned> getGlobal(const Expr *E);
81+
UnsignedOrNone getGlobal(const ValueDecl *VD);
82+
UnsignedOrNone getGlobal(const Expr *E);
8383

8484
/// Returns or creates a global an creates an index to it.
85-
std::optional<unsigned> getOrCreateGlobal(const ValueDecl *VD,
86-
const Expr *Init = nullptr);
85+
UnsignedOrNone getOrCreateGlobal(const ValueDecl *VD,
86+
const Expr *Init = nullptr);
8787

8888
/// Returns or creates a dummy value for unknown declarations.
8989
unsigned getOrCreateDummy(const DeclTy &D);
9090

9191
/// Creates a global and returns its index.
92-
std::optional<unsigned> createGlobal(const ValueDecl *VD, const Expr *Init);
92+
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init);
9393

9494
/// Creates a global from a lifetime-extended temporary.
95-
std::optional<unsigned> createGlobal(const Expr *E);
95+
UnsignedOrNone createGlobal(const Expr *E);
9696

9797
/// Creates a new function from a code range.
9898
template <typename... Ts>
@@ -165,9 +165,9 @@ class Program final {
165165
private:
166166
friend class DeclScope;
167167

168-
std::optional<unsigned> createGlobal(const DeclTy &D, QualType Ty,
169-
bool IsStatic, bool IsExtern,
170-
bool IsWeak, const Expr *Init = nullptr);
168+
UnsignedOrNone createGlobal(const DeclTy &D, QualType Ty, bool IsStatic,
169+
bool IsExtern, bool IsWeak,
170+
const Expr *Init = nullptr);
171171

172172
/// Reference to the VM context.
173173
Context &Ctx;

0 commit comments

Comments
 (0)