[clang] Use std::nullopt instead of None in comments (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
This commit is contained in:
Kazu Hirata 2022-12-04 15:57:24 -08:00
parent 122efef8ee
commit 35b4fbb559
35 changed files with 57 additions and 52 deletions

View File

@ -533,8 +533,9 @@ public:
bool IgnoreTemplateOrMacroSubstitution = false) const;
/// isIntegerConstantExpr - Return the value if this expression is a valid
/// integer constant expression. If not a valid i-c-e, return None and fill
/// in Loc (if specified) with the location of the invalid expression.
/// integer constant expression. If not a valid i-c-e, return std::nullopt
/// and fill in Loc (if specified) with the location of the invalid
/// expression.
///
/// Note: This does not perform the implicit conversions required by C++11
/// [expr.const]p5.

View File

@ -2268,7 +2268,7 @@ public:
bool isArray() const { return CXXNewExprBits.IsArray; }
/// This might return None even if isArray() returns true,
/// This might return std::nullopt even if isArray() returns true,
/// since there might not be an array size expression.
/// If the result is not-None, it will never wrap a nullptr.
Optional<Expr *> getArraySize() {
@ -2282,7 +2282,7 @@ public:
return std::nullopt;
}
/// This might return None even if isArray() returns true,
/// This might return std::nullopt even if isArray() returns true,
/// since there might not be an array size expression.
/// If the result is not-None, it will never wrap a nullptr.
Optional<const Expr *> getArraySize() const {

View File

@ -2140,7 +2140,7 @@ public:
}
/// If this is an 'if constexpr', determine which substatement will be taken.
/// Otherwise, or if the condition is value-dependent, returns None.
/// Otherwise, or if the condition is value-dependent, returns std::nullopt.
Optional<const Stmt*> getNondiscardedCase(const ASTContext &Ctx) const;
Optional<Stmt *> getNondiscardedCase(const ASTContext &Ctx);

View File

@ -117,7 +117,7 @@ class VariantMatcher {
/// Constructs a variadic typed matcher from \p InnerMatchers.
/// Will try to convert each inner matcher to the destination type and
/// return llvm::None if it fails to do so.
/// return std::nullopt if it fails to do so.
llvm::Optional<DynTypedMatcher>
constructVariadicOperator(DynTypedMatcher::VariadicOperator Op,
ArrayRef<VariantMatcher> InnerMatchers) const;

View File

@ -108,7 +108,7 @@ public:
}
/// If @c E is a generic call (to ObjC method /function/block/etc),
/// return a constructed @c AnyCall object. Return None otherwise.
/// return a constructed @c AnyCall object. Return std::nullopt otherwise.
static Optional<AnyCall> forExpr(const Expr *E) {
if (const auto *ME = dyn_cast<ObjCMessageExpr>(E)) {
return AnyCall(ME);
@ -128,7 +128,7 @@ public:
}
/// If @c D is a callable (Objective-C method or a function), return
/// a constructed @c AnyCall object. Return None otherwise.
/// a constructed @c AnyCall object. Return std::nullopt otherwise.
// FIXME: block support.
static Optional<AnyCall> forDecl(const Decl *D) {
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {

View File

@ -85,13 +85,13 @@ public:
/// \param MacroExpansionLoc Must be the expansion location of a macro.
/// \return The textual representation of the token sequence which was
/// substituted in place of the macro after the preprocessing.
/// If no macro was expanded at that location, returns llvm::None.
/// If no macro was expanded at that location, returns std::nullopt.
Optional<StringRef> getExpandedText(SourceLocation MacroExpansionLoc) const;
/// \param MacroExpansionLoc Must be the expansion location of a macro.
/// \return The text from the original source code which were substituted by
/// the macro expansion chain from the given location.
/// If no macro was expanded at that location, returns llvm::None.
/// If no macro was expanded at that location, returns std::nullopt.
Optional<StringRef> getOriginalText(SourceLocation MacroExpansionLoc) const;
LLVM_DUMP_METHOD void dumpExpansionRangesToStream(raw_ostream &OS) const;

View File

@ -939,7 +939,7 @@ public:
/// Retrieve the memory buffer associated with the given file.
///
/// Returns None if the buffer is not valid.
/// Returns std::nullopt if the buffer is not valid.
llvm::Optional<llvm::MemoryBufferRef>
getMemoryBufferForFileOrNone(const FileEntry *File);
@ -999,8 +999,8 @@ public:
}
/// Bypass the overridden contents of a file. This creates a new FileEntry
/// and initializes the content cache for it. Returns None if there is no
/// such file in the filesystem.
/// and initializes the content cache for it. Returns std::nullopt if there
/// is no such file in the filesystem.
///
/// This should be called before parsing has begun.
Optional<FileEntryRef> bypassFileContentsOverride(FileEntryRef File);
@ -1020,7 +1020,8 @@ public:
/// Return the buffer for the specified FileID.
///
/// If there is an error opening this buffer the first time, return None.
/// If there is an error opening this buffer the first time, return
/// std::nullopt.
llvm::Optional<llvm::MemoryBufferRef>
getBufferOrNone(FileID FID, SourceLocation Loc = SourceLocation()) const {
if (auto *Entry = getSLocEntryForFile(FID))
@ -1057,7 +1058,7 @@ public:
/// Returns the filename for the provided FileID, unless it's a built-in
/// buffer that's not represented by a filename.
///
/// Returns None for non-files and built-in files.
/// Returns std::nullopt for non-files and built-in files.
Optional<StringRef> getNonBuiltinFilenameForID(FileID FID) const;
/// Returns the FileEntry record for the provided SLocEntry.

View File

@ -48,7 +48,7 @@ std::string getCanonicalTargetID(llvm::StringRef Processor,
/// Get the conflicted pair of target IDs for a compilation or a bundled code
/// object, assuming \p TargetIDs are canonicalized. If there is no conflicts,
/// returns None.
/// returns std::nullopt.
std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
getConflictTargetIDCombination(const std::set<llvm::StringRef> &TargetIDs);

View File

@ -1513,7 +1513,7 @@ public:
/// Return an AST address space which can be used opportunistically
/// for constant global memory. It must be possible to convert pointers into
/// this address space to LangAS::Default. If no such address space exists,
/// this may return None, and such optimizations will be disabled.
/// this may return std::nullopt, and such optimizations will be disabled.
virtual llvm::Optional<LangAS> getConstantAddressSpace() const {
return LangAS::Default;
}
@ -1653,8 +1653,8 @@ public:
/// space \p AddressSpace to be converted in order to be used, then return the
/// corresponding target specific DWARF address space.
///
/// \returns Otherwise return None and no conversion will be emitted in the
/// DWARF.
/// \returns Otherwise return std::nullopt and no conversion will be emitted
/// in the DWARF.
virtual std::optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace)
const {
return std::nullopt;

View File

@ -75,7 +75,7 @@ private:
HMapBucket getBucket(unsigned BucketNo) const;
/// Look up the specified string in the string table. If the string index is
/// not valid, return None.
/// not valid, return std::nullopt.
Optional<StringRef> getString(unsigned StrTabIdx) const;
};

View File

@ -2242,7 +2242,7 @@ public:
/// Given a "foo" or \<foo> reference, look up the indicated file.
///
/// Returns None on failure. \p isAngled indicates whether the file
/// Returns std::nullopt on failure. \p isAngled indicates whether the file
/// reference is for system \#include's or not (i.e. using <> instead of "").
Optional<FileEntryRef>
LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled,

View File

@ -11590,8 +11590,9 @@ public:
/// \param TI The trait info object representing the match clause.
/// \param NumAppendArgs The number of omp_interop_t arguments to account for
/// in checking.
/// \returns None, if the function/variant function are not compatible with
/// the pragma, pair of original function/variant ref expression otherwise.
/// \returns std::nullopt, if the function/variant function are not compatible
/// with the pragma, pair of original function/variant ref expression
/// otherwise.
Optional<std::pair<FunctionDecl *, Expr *>>
checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef,
OMPTraitInfo &TI, unsigned NumAppendArgs,

View File

@ -420,7 +420,7 @@ public:
/// Some calls have parameter numbering mismatched from argument numbering.
/// This function converts an argument index to the corresponding
/// parameter index. Returns None is the argument doesn't correspond
/// parameter index. Returns std::nullopt is the argument doesn't correspond
/// to any parameter variable.
virtual Optional<unsigned>
getAdjustedParameterIndex(unsigned ASTArgumentIndex) const {

View File

@ -369,7 +369,7 @@ public:
return loc::ConcreteInt(BasicVals.getValue(integer));
}
/// Return MemRegionVal on success cast, otherwise return None.
/// Return MemRegionVal on success cast, otherwise return std::nullopt.
Optional<loc::MemRegionVal> getCastedMemRegionVal(const MemRegion *region,
QualType type);

View File

@ -69,7 +69,7 @@ public:
/// this will simply insert the #include in front of the first #include of the
/// same category in the code that should be sorted after \p IncludeName. If
/// \p IncludeName already exists (with exactly the same spelling), this
/// returns None.
/// returns std::nullopt.
llvm::Optional<tooling::Replacement> insert(llvm::StringRef Header,
bool IsAngled) const;

View File

@ -65,8 +65,8 @@ struct SelectedASTNode {
/// Traverses the given ASTContext and creates a tree of selected AST nodes.
///
/// \returns None if no nodes are selected in the AST, or a selected AST node
/// that corresponds to the TranslationUnitDecl otherwise.
/// \returns std::nullopt if no nodes are selected in the AST, or a selected AST
/// node that corresponds to the TranslationUnitDecl otherwise.
Optional<SelectedASTNode> findSelectedASTNodes(const ASTContext &Context,
SourceRange SelectionRange);

View File

@ -6739,7 +6739,7 @@ static const FunctionDecl *getVirtualOperatorDelete(QualType T) {
/// still exists and is of the right kind for the purpose of a deletion.
///
/// On success, returns the heap allocation to deallocate. On failure, produces
/// a diagnostic and returns None.
/// a diagnostic and returns std::nullopt.
static Optional<DynAlloc *> CheckDeleteKind(EvalInfo &Info, const Expr *E,
const LValue &Pointer,
DynAlloc::Kind DeallocKind) {

View File

@ -997,7 +997,7 @@ private:
/// Return true/false if 'swift_async' attribute states that the given
/// parameter is conventionally called once.
/// Return llvm::None if the given declaration doesn't have 'swift_async'
/// Return std::nullopt if the given declaration doesn't have 'swift_async'
/// attribute.
static llvm::Optional<bool> isConventionalSwiftAsync(const Decl *D,
unsigned ParamIndex) {

View File

@ -101,7 +101,7 @@ MacroExpansionContext::getExpandedText(SourceLocation MacroExpansionLoc) const {
if (MacroExpansionLoc.isMacroID())
return std::nullopt;
// If there was no macro expansion at that location, return None.
// If there was no macro expansion at that location, return std::nullopt.
if (ExpansionRanges.find_as(MacroExpansionLoc) == ExpansionRanges.end())
return std::nullopt;

View File

@ -29,7 +29,7 @@ std::optional<VersionTuple> DarwinSDKInfo::RelatedTargetVersionMapping::map(
// the major-only check.
if (Key.getMinor())
return map(VersionTuple(Key.getMajor()), MinimumValue, MaximumValue);
// If this a major only key, return None for a missing entry.
// If this a major only key, return std::nullopt for a missing entry.
return std::nullopt;
}

View File

@ -392,8 +392,8 @@ public:
/// space \p AddressSpace to be converted in order to be used, then return the
/// corresponding target specific DWARF address space.
///
/// \returns Otherwise return None and no conversion will be emitted in the
/// DWARF.
/// \returns Otherwise return std::nullopt and no conversion will be emitted
/// in the DWARF.
std::optional<unsigned>
getDWARFAddressSpace(unsigned AddressSpace) const override {
const unsigned DWARF_Private = 1;

View File

@ -157,8 +157,8 @@ public:
/// space \p AddressSpace to be converted in order to be used, then return the
/// corresponding target specific DWARF address space.
///
/// \returns Otherwise return None and no conversion will be emitted in the
/// DWARF.
/// \returns Otherwise return std::nullopt and no conversion will be emitted
/// in the DWARF.
std::optional<unsigned>
getDWARFAddressSpace(unsigned AddressSpace) const override {
if (AddressSpace >= std::size(NVPTXDWARFAddrSpaceMap) ||

View File

@ -283,7 +283,7 @@ bool ConstantAggregateBuilder::addBits(llvm::APInt Bits, uint64_t OffsetInBits,
/// Returns a position within Elems and Offsets such that all elements
/// before the returned index end before Pos and all elements at or after
/// the returned index begin at or after Pos. Splits elements as necessary
/// to ensure this. Returns None if we find something we can't split.
/// to ensure this. Returns std::nullopt if we find something we can't split.
Optional<size_t> ConstantAggregateBuilder::splitAt(CharUnits Pos) {
if (Pos >= Size)
return Offsets.size();

View File

@ -325,7 +325,7 @@ public:
/// Get the coverage mapping file ID for \c Loc.
///
/// If such file id doesn't exist, return None.
/// If such file id doesn't exist, return std::nullopt.
Optional<unsigned> getCoverageFileID(SourceLocation Loc) {
auto Mapping = FileIDMapping.find(SM.getFileID(Loc));
if (Mapping != FileIDMapping.end())
@ -335,7 +335,7 @@ public:
/// This shrinks the skipped range if it spans a line that contains a
/// non-comment token. If shrinking the skipped range would make it empty,
/// this returns None.
/// this returns std::nullopt.
/// Note this function can potentially be expensive because
/// getSpellingLineNumber uses getLineNumber, which is expensive.
Optional<SpellingRegion> adjustSkippedRange(SourceManager &SM,

View File

@ -23,7 +23,7 @@ std::vector<DirectoryWatcher::Event>
getAsFileEvents(const std::vector<std::string> &Scan);
/// Gets status of file (or directory) at \p Path.
/// \returns llvm::None if \p Path doesn't exist or can't get the status.
/// \returns std::nullopt if \p Path doesn't exist or can't get the status.
llvm::Optional<llvm::sys::fs::file_status> getFileStatus(llvm::StringRef Path);
} // namespace clang

View File

@ -329,7 +329,8 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
continue;
bool IsSystem = Dir.isSystemHeaderDirectory();
// Only returns None if not a normal directory, which we just checked
// Only returns std::nullopt if not a normal directory, which we just
// checked
DirectoryEntryRef NormalDir = *Dir.getDirRef();
// Search for a module map file in this directory.
if (loadModuleMapFile(NormalDir, IsSystem,

View File

@ -273,7 +273,7 @@ static bool warnByDefaultOnWrongCase(StringRef Include) {
/// \param Candidates the candidates to find a similar string.
///
/// \returns a similar string if exists. If no similar string exists,
/// returns None.
/// returns std::nullopt.
static Optional<StringRef> findSimilarStr(
StringRef LHS, const std::vector<StringRef> &Candidates) {
// We need to check if `Candidates` has the exact case-insensitive string

View File

@ -6193,7 +6193,7 @@ QualType Sema::ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args,
// Only aggregate initialization is possible, but we can't assist with it.
// Returns an out-of-range index.
// - we saw no designators, just positional arguments.
// Returns None.
// Returns std::nullopt.
static llvm::Optional<unsigned>
getNextAggregateIndexAfterDesignatedInit(const ResultCandidate &Aggregate,
ArrayRef<Expr *> Args) {

View File

@ -9733,8 +9733,8 @@ isBetterMultiversionCandidate(const OverloadCandidate &Cand1,
}
/// Compute the type of the implicit object parameter for the given function,
/// if any. Returns None if there is no implicit object parameter, and a null
/// QualType if there is a 'matches anything' implicit object parameter.
/// if any. Returns std::nullopt if there is no implicit object parameter, and a
/// null QualType if there is a 'matches anything' implicit object parameter.
static Optional<QualType> getImplicitObjectParamType(ASTContext &Context,
const FunctionDecl *F) {
if (!isa<CXXMethodDecl>(F) || isa<CXXConstructorDecl>(F))

View File

@ -165,7 +165,7 @@ static bool shouldGenerateNote(llvm::raw_string_ostream &os,
/// Finds argument index of the out paramter in the call @c S
/// corresponding to the symbol @c Sym.
/// If none found, returns None.
/// If none found, returns std::nullopt.
static Optional<unsigned> findArgIdxOfSymbol(ProgramStateRef CurrSt,
const LocationContext *LCtx,
SymbolRef &Sym,

View File

@ -221,7 +221,7 @@ class PathDiagnosticBuilder : public BugReporterContext {
public:
/// Find a non-invalidated report for a given equivalence class, and returns
/// a PathDiagnosticBuilder able to construct bug reports for different
/// consumers. Returns None if no valid report is found.
/// consumers. Returns std::nullopt if no valid report is found.
static Optional<PathDiagnosticBuilder>
findValidReport(ArrayRef<PathSensitiveBugReport *> &bugReports,
PathSensitiveBugReporter &Reporter);
@ -1566,7 +1566,8 @@ static void simplifySimpleBranches(PathPieces &pieces) {
/// Returns the number of bytes in the given (character-based) SourceRange.
///
/// If the locations in the range are not on the same line, returns None.
/// If the locations in the range are not on the same line, returns
/// std::nullopt.
///
/// Note that this does not do a precise user-visible character or column count.
static Optional<size_t> getLengthOnSingleLine(const SourceManager &SM,

View File

@ -1361,7 +1361,7 @@ private:
/// Try to convert given range into the given type.
///
/// It will return llvm::None only when the trivial conversion is possible.
/// It will return std::nullopt only when the trivial conversion is possible.
llvm::Optional<Range> convert(const Range &Origin, APSIntType To) {
if (To.testInRange(Origin.From(), false) != APSIntType::RTR_Within ||
To.testInRange(Origin.To(), false) != APSIntType::RTR_Within) {

View File

@ -1674,7 +1674,7 @@ getElementRegionOffsetsWithBase(const ElementRegion *ER) {
/// const int arr[10][20][30] = {}; // ArrayExtents { 10, 20, 30 }
/// int x1 = arr[4][5][6]; // SrcOffsets { NonLoc(6), NonLoc(5), NonLoc(4) }
/// // DstOffsets { 4, 5, 6 }
/// // returns None
/// // returns std::nullopt
/// int x2 = arr[42][5][-6]; // returns UndefinedVal
/// int x3 = arr[4][5][x2]; // returns UnknownVal
static Optional<SVal>

View File

@ -529,7 +529,7 @@ void compare_same_symbol_minus_left_minus_right_int_less(void) {
//
// // Rearrange signed symbolic expressions only
// if (!SingleTy->isSignedIntegerOrEnumerationType())
// return None;
// return std::nullopt;
//
// Without the symbolic casts, the SVal for `x` in `unsigned x = f()` will be
// the signed `int`. However, with the symbolic casts it will be `unsigned`.

View File

@ -93,7 +93,7 @@ struct TestSelectionRangesInFile {
/// because clang-refactor should return zero on exit when the group results are
/// consistent.
///
/// \returns None on failure (errors are emitted to stderr), or a set of
/// \returns std::nullopt on failure (errors are emitted to stderr), or a set of
/// grouped source ranges in the given file otherwise.
Optional<TestSelectionRangesInFile> findTestSelectionRanges(StringRef Filename);