Skip to content

Commit 06d5265

Browse files
committed
Use nullptr as missing value
1 parent 23dcc6b commit 06d5265

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

llvm/include/llvm/AsmParser/AsmParserContext.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,30 @@ class AsmParserContext {
3636
std::optional<FileLocRange> getFunctionLocation(const Function *) const;
3737
std::optional<FileLocRange> getBlockLocation(const BasicBlock *) const;
3838
std::optional<FileLocRange> getInstructionLocation(const Instruction *) const;
39-
std::optional<Function *> getFunctionAtLocation(const FileLocRange &) const;
40-
std::optional<Function *> getFunctionAtLocation(const FileLoc &) const;
41-
std::optional<BasicBlock *> getBlockAtLocation(const FileLocRange &) const;
42-
std::optional<BasicBlock *> getBlockAtLocation(const FileLoc &) const;
43-
std::optional<Instruction *>
44-
getInstructionAtLocation(const FileLocRange &) const;
45-
std::optional<Instruction *> getInstructionAtLocation(const FileLoc &) const;
39+
/// Get the function at the requested location range.
40+
/// If no single function occupies the queried range, or the record is
41+
/// missing, a nullptr is returned.
42+
Function *getFunctionAtLocation(const FileLocRange &) const;
43+
/// Get the function at the requested location.
44+
/// If no function occupies the queried location, or the record is missing, a
45+
/// nullptr is returned.
46+
Function *getFunctionAtLocation(const FileLoc &) const;
47+
/// Get the block at the requested location range.
48+
/// If no single block occupies the queried range, or the record is missing, a
49+
/// nullptr is returned.
50+
BasicBlock *getBlockAtLocation(const FileLocRange &) const;
51+
/// Get the block at the requested location.
52+
/// If no block occupies the queried location, or the record is missing, a
53+
/// nullptr is returned.
54+
BasicBlock *getBlockAtLocation(const FileLoc &) const;
55+
/// Get the instruction at the requested location range.
56+
/// If no single instruction occupies the queried range, or the record is
57+
/// missing, a nullptr is returned.
58+
Instruction *getInstructionAtLocation(const FileLocRange &) const;
59+
/// Get the instruction at the requested location.
60+
/// If no instruction occupies the queried location, or the record is missing,
61+
/// a nullptr is returned.
62+
Instruction *getInstructionAtLocation(const FileLoc &) const;
4663
bool addFunctionLocation(Function *, const FileLocRange &);
4764
bool addBlockLocation(BasicBlock *, const FileLocRange &);
4865
bool addInstructionLocation(Instruction *, const FileLocRange &);

llvm/lib/AsmParser/AsmParserContext.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,42 @@ AsmParserContext::getInstructionLocation(const Instruction *I) const {
3131
return Instructions.at(I);
3232
}
3333

34-
std::optional<Function *>
34+
Function *
3535
AsmParserContext::getFunctionAtLocation(const FileLocRange &Query) const {
3636
for (auto &[F, Loc] : Functions) {
3737
if (Loc.contains(Query))
3838
return F;
3939
}
40-
return std::nullopt;
40+
return nullptr;
4141
}
4242

43-
std::optional<Function *>
44-
AsmParserContext::getFunctionAtLocation(const FileLoc &Query) const {
43+
Function *AsmParserContext::getFunctionAtLocation(const FileLoc &Query) const {
4544
return getFunctionAtLocation(FileLocRange(Query, Query));
4645
}
4746

48-
std::optional<BasicBlock *>
47+
BasicBlock *
4948
AsmParserContext::getBlockAtLocation(const FileLocRange &Query) const {
5049
for (auto &[BB, Loc] : Blocks) {
5150
if (Loc.contains(Query))
5251
return BB;
5352
}
54-
return std::nullopt;
53+
return nullptr;
5554
}
5655

57-
std::optional<BasicBlock *>
58-
AsmParserContext::getBlockAtLocation(const FileLoc &Query) const {
56+
BasicBlock *AsmParserContext::getBlockAtLocation(const FileLoc &Query) const {
5957
return getBlockAtLocation(FileLocRange(Query, Query));
6058
}
6159

62-
std::optional<Instruction *>
60+
Instruction *
6361
AsmParserContext::getInstructionAtLocation(const FileLocRange &Query) const {
6462
for (auto &[I, Loc] : Instructions) {
6563
if (Loc.contains(Query))
6664
return I;
6765
}
68-
return std::nullopt;
66+
return nullptr;
6967
}
7068

71-
std::optional<Instruction *>
69+
Instruction *
7270
AsmParserContext::getInstructionAtLocation(const FileLoc &Query) const {
7371
return getInstructionAtLocation(FileLocRange(Query, Query));
7472
}

0 commit comments

Comments
 (0)