Skip to content

Commit

Permalink
[clang, clang-tools-extra] Use has_value instead of hasValue (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Jul 13, 2022
1 parent 3361a36 commit 53daa17
Show file tree
Hide file tree
Showing 29 changed files with 109 additions and 112 deletions.
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/AST.cpp
Expand Up @@ -745,15 +745,15 @@ class ForwardingCallVisitor
if (Callee) {
handleCall(Callee, E->arguments());
}
return !Info.hasValue();
return !Info.has_value();
}

bool VisitCXXConstructExpr(CXXConstructExpr *E) {
auto *Callee = E->getConstructor();
if (Callee) {
handleCall(Callee, E->arguments());
}
return !Info.hasValue();
return !Info.has_value();
}

// The expanded parameter pack to be resolved
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/CodeComplete.cpp
Expand Up @@ -394,7 +394,7 @@ struct CodeCompletionBuilder {
std::stable_partition(Completion.Includes.begin(),
Completion.Includes.end(),
[](const CodeCompletion::IncludeCandidate &I) {
return !I.Insertion.hasValue();
return !I.Insertion.has_value();
});
}

Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/ConfigCompile.cpp
Expand Up @@ -358,8 +358,8 @@ struct FragmentCompiler {
}
#endif
// Make sure exactly one of the Sources is set.
unsigned SourceCount = External.File.hasValue() +
External.Server.hasValue() + *External.IsNone;
unsigned SourceCount = External.File.has_value() +
External.Server.has_value() + *External.IsNone;
if (SourceCount != 1) {
diag(Error, "Exactly one of File, Server or None must be set.",
BlockRange);
Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clangd/index/YAMLSerialization.cpp
Expand Up @@ -354,23 +354,23 @@ template <> struct MappingTraits<CompileCommandYAML> {

template <> struct MappingTraits<VariantEntry> {
static void mapping(IO &IO, VariantEntry &Variant) {
if (IO.mapTag("!Symbol", Variant.Symbol.hasValue())) {
if (IO.mapTag("!Symbol", Variant.Symbol.has_value())) {
if (!IO.outputting())
Variant.Symbol.emplace();
MappingTraits<Symbol>::mapping(IO, *Variant.Symbol);
} else if (IO.mapTag("!Refs", Variant.Refs.hasValue())) {
} else if (IO.mapTag("!Refs", Variant.Refs.has_value())) {
if (!IO.outputting())
Variant.Refs.emplace();
MappingTraits<RefBundle>::mapping(IO, *Variant.Refs);
} else if (IO.mapTag("!Relations", Variant.Relation.hasValue())) {
} else if (IO.mapTag("!Relations", Variant.Relation.has_value())) {
if (!IO.outputting())
Variant.Relation.emplace();
MappingTraits<Relation>::mapping(IO, *Variant.Relation);
} else if (IO.mapTag("!Source", Variant.Source.hasValue())) {
} else if (IO.mapTag("!Source", Variant.Source.has_value())) {
if (!IO.outputting())
Variant.Source.emplace();
MappingTraits<IncludeGraphNode>::mapping(IO, *Variant.Source);
} else if (IO.mapTag("!Cmd", Variant.Cmd.hasValue())) {
} else if (IO.mapTag("!Cmd", Variant.Cmd.has_value())) {
if (!IO.outputting())
Variant.Cmd.emplace();
MappingTraits<CompileCommandYAML>::mapping(
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
Expand Up @@ -163,9 +163,9 @@ TEST(ParseYAML, ExternalBlockNone) {
ASSERT_THAT(Diags.Diagnostics, IsEmpty());
ASSERT_EQ(Results.size(), 1u);
ASSERT_TRUE(Results[0].Index.External);
EXPECT_FALSE(Results[0].Index.External.getValue()->File.hasValue());
EXPECT_FALSE(Results[0].Index.External.getValue()->MountPoint.hasValue());
EXPECT_FALSE(Results[0].Index.External.getValue()->Server.hasValue());
EXPECT_FALSE(Results[0].Index.External.getValue()->File.has_value());
EXPECT_FALSE(Results[0].Index.External.getValue()->MountPoint.has_value());
EXPECT_FALSE(Results[0].Index.External.getValue()->Server.has_value());
EXPECT_THAT(*Results[0].Index.External.getValue()->IsNone, testing::Eq(true));
}

Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/unittests/FSTests.cpp
Expand Up @@ -28,10 +28,10 @@ TEST(FSTests, PreambleStatusCache) {
EXPECT_TRUE(ProduceFS->status("y"));
EXPECT_TRUE(ProduceFS->status("main"));

EXPECT_TRUE(StatCache.lookup(testPath("x")).hasValue());
EXPECT_TRUE(StatCache.lookup(testPath("y")).hasValue());
EXPECT_TRUE(StatCache.lookup(testPath("x")).has_value());
EXPECT_TRUE(StatCache.lookup(testPath("y")).has_value());
// Main file is not cached.
EXPECT_FALSE(StatCache.lookup(testPath("main")).hasValue());
EXPECT_FALSE(StatCache.lookup(testPath("main")).has_value());

llvm::vfs::Status S("fake", llvm::sys::fs::UniqueID(123, 456),
std::chrono::system_clock::now(), 0, 0, 1024,
Expand Down
Expand Up @@ -331,7 +331,7 @@ TEST(GlobalCompilationDatabaseTest, CompileFlagsDirectory) {
FS.Files[testPath("x/compile_flags.txt")] = "-DFOO";
DirectoryBasedGlobalCompilationDatabase CDB(FS);
auto Commands = CDB.getCompileCommand(testPath("x/y.cpp"));
ASSERT_TRUE(Commands.hasValue());
ASSERT_TRUE(Commands.has_value());
EXPECT_THAT(Commands.getValue().CommandLine, Contains("-DFOO"));
// Make sure we pick the right working directory.
EXPECT_EQ(testPath("x"), Commands.getValue().Directory);
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
Expand Up @@ -33,11 +33,11 @@ TEST(HeaderSourceSwitchTest, FileHeuristic) {
FS.Files[Invalid];
Optional<Path> PathResult =
getCorrespondingHeaderOrSource(FooCpp, FS.view(llvm::None));
EXPECT_TRUE(PathResult.hasValue());
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(PathResult.getValue(), FooH);

PathResult = getCorrespondingHeaderOrSource(FooH, FS.view(llvm::None));
EXPECT_TRUE(PathResult.hasValue());
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(PathResult.getValue(), FooCpp);

// Test with header file in capital letters and different extension, source
Expand All @@ -48,7 +48,7 @@ TEST(HeaderSourceSwitchTest, FileHeuristic) {
FS.Files[FooC];
FS.Files[FooHH];
PathResult = getCorrespondingHeaderOrSource(FooC, FS.view(llvm::None));
EXPECT_TRUE(PathResult.hasValue());
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(PathResult.getValue(), FooHH);

// Test with both capital letters
Expand All @@ -57,7 +57,7 @@ TEST(HeaderSourceSwitchTest, FileHeuristic) {
FS.Files[Foo2C];
FS.Files[Foo2HH];
PathResult = getCorrespondingHeaderOrSource(Foo2C, FS.view(llvm::None));
EXPECT_TRUE(PathResult.hasValue());
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(PathResult.getValue(), Foo2HH);

// Test with source file as capital letter and .hxx header file
Expand All @@ -67,13 +67,13 @@ TEST(HeaderSourceSwitchTest, FileHeuristic) {
FS.Files[Foo3C];
FS.Files[Foo3HXX];
PathResult = getCorrespondingHeaderOrSource(Foo3C, FS.view(llvm::None));
EXPECT_TRUE(PathResult.hasValue());
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(PathResult.getValue(), Foo3HXX);

// Test if asking for a corresponding file that doesn't exist returns an empty
// string.
PathResult = getCorrespondingHeaderOrSource(Invalid, FS.view(llvm::None));
EXPECT_FALSE(PathResult.hasValue());
EXPECT_FALSE(PathResult.has_value());
}

MATCHER_P(declNamed, Name, "") {
Expand Down
14 changes: 7 additions & 7 deletions clang-tools-extra/clangd/unittests/LSPBinderTests.cpp
Expand Up @@ -93,18 +93,18 @@ TEST(LSPBinderTest, IncomingCalls) {

auto &RawPlusOne = RawHandlers.MethodHandlers["plusOne"];
RawPlusOne(1, capture(Reply));
ASSERT_TRUE(Reply.hasValue());
ASSERT_TRUE(Reply.has_value());
EXPECT_THAT_EXPECTED(Reply.getValue(), llvm::HasValue(2));
RawPlusOne("foo", capture(Reply));
ASSERT_TRUE(Reply.hasValue());
ASSERT_TRUE(Reply.has_value());
EXPECT_THAT_EXPECTED(
Reply.getValue(),
llvm::FailedWithMessage(
HasSubstr("failed to decode plusOne request: expected integer")));

auto &RawFail = RawHandlers.MethodHandlers["fail"];
RawFail(2, capture(Reply));
ASSERT_TRUE(Reply.hasValue());
ASSERT_TRUE(Reply.has_value());
EXPECT_THAT_EXPECTED(Reply.getValue(), llvm::FailedWithMessage("X=2"));

auto &RawNotify = RawHandlers.NotificationHandlers["notify"];
Expand All @@ -117,7 +117,7 @@ TEST(LSPBinderTest, IncomingCalls) {

auto &RawCmdPlusOne = RawHandlers.CommandHandlers["cmdPlusOne"];
RawCmdPlusOne(1, capture(Reply));
ASSERT_TRUE(Reply.hasValue());
ASSERT_TRUE(Reply.has_value());
EXPECT_THAT_EXPECTED(Reply.getValue(), llvm::HasValue(2));

// None of this generated any outgoing traffic.
Expand All @@ -139,22 +139,22 @@ TEST(LSPBinderTest, OutgoingCalls) {
llvm::Optional<llvm::Expected<Foo>> Reply;
Echo(Foo{2}, capture(Reply));
EXPECT_THAT(RawOutgoing.take("echo"), ElementsAre(llvm::json::Value(2)));
ASSERT_TRUE(Reply.hasValue());
ASSERT_TRUE(Reply.has_value());
EXPECT_THAT_EXPECTED(Reply.getValue(), llvm::HasValue(Foo{2}));

// JSON response is integer, can't be parsed as string.
llvm::Optional<llvm::Expected<std::string>> WrongTypeReply;
WrongSignature(Foo{2}, capture(WrongTypeReply));
EXPECT_THAT(RawOutgoing.take("wrongSignature"),
ElementsAre(llvm::json::Value(2)));
ASSERT_TRUE(Reply.hasValue());
ASSERT_TRUE(Reply.has_value());
EXPECT_THAT_EXPECTED(WrongTypeReply.getValue(),
llvm::FailedWithMessage(
HasSubstr("failed to decode wrongSignature reply")));

Fail(Foo{2}, capture(Reply));
EXPECT_THAT(RawOutgoing.take("fail"), ElementsAre(llvm::json::Value(2)));
ASSERT_TRUE(Reply.hasValue());
ASSERT_TRUE(Reply.has_value());
EXPECT_THAT_EXPECTED(Reply.getValue(), llvm::FailedWithMessage("Params=2"));
}

Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/unittests/TidyProviderTests.cpp
Expand Up @@ -37,18 +37,18 @@ TEST(TidyProvider, NestedDirectories) {
TidyProvider Provider = provideClangTidyFiles(FS);

auto BaseOptions = getTidyOptionsForFile(Provider, testPath("File.cpp"));
ASSERT_TRUE(BaseOptions.Checks.hasValue());
ASSERT_TRUE(BaseOptions.Checks.has_value());
EXPECT_EQ(*BaseOptions.Checks, "llvm-*");
EXPECT_EQ(BaseOptions.CheckOptions.lookup("TestKey").Value, "1");

auto Sub1Options = getTidyOptionsForFile(Provider, testPath("sub1/File.cpp"));
ASSERT_TRUE(Sub1Options.Checks.hasValue());
ASSERT_TRUE(Sub1Options.Checks.has_value());
EXPECT_EQ(*Sub1Options.Checks, "misc-*");
EXPECT_EQ(Sub1Options.CheckOptions.lookup("TestKey").Value, "2");

auto Sub2Options =
getTidyOptionsForFile(Provider, testPath("sub1/sub2/File.cpp"));
ASSERT_TRUE(Sub2Options.Checks.hasValue());
ASSERT_TRUE(Sub2Options.Checks.has_value());
EXPECT_EQ(*Sub2Options.Checks, "misc-*,bugprone-*");
EXPECT_EQ(Sub2Options.CheckOptions.lookup("TestKey").Value, "3");
}
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/pseudo/lib/GLR.cpp
Expand Up @@ -499,7 +499,7 @@ class GLRReduce {
FamilySequences.emplace_back(Sequences.top().first.Rule, *Push.Seq);
for (const GSS::Node *Base : Push.LastPop->parents()) {
auto NextState = Lang.Table.getGoToState(Base->State, F.Symbol);
assert(NextState.hasValue() && "goto must succeed after reduce!");
assert(NextState.has_value() && "goto must succeed after reduce!");
FamilyBases.emplace_back(*NextState, Base);
}

Expand Down Expand Up @@ -555,7 +555,7 @@ class GLRReduce {
const GSS::Node *Head = Heads->back();
llvm::Optional<RuleID> RID;
for (RuleID R : Lang.Table.getReduceRules(Head->State)) {
if (RID.hasValue())
if (RID.has_value())
return false;
RID = R;
}
Expand All @@ -577,7 +577,7 @@ class GLRReduce {
const ForestNode *Parsed =
&Params.Forest.createSequence(Rule.Target, *RID, TempSequence);
auto NextState = Lang.Table.getGoToState(Base->State, Rule.Target);
assert(NextState.hasValue() && "goto must succeed after reduce!");
assert(NextState.has_value() && "goto must succeed after reduce!");
Heads->push_back(Params.GSStack.addNode(*NextState, Parsed, {Base}));
return true;
}
Expand Down Expand Up @@ -642,7 +642,7 @@ const ForestNode &glrParse(const ParseParams &Params, SymbolID StartSymbol,

// The parse was successful if we're in state `_ := start-symbol .`
auto AcceptState = Lang.Table.getGoToState(StartState, StartSymbol);
assert(AcceptState.hasValue() && "goto must succeed after start symbol!");
assert(AcceptState.has_value() && "goto must succeed after start symbol!");
auto SearchForAccept = [&](llvm::ArrayRef<const GSS::Node *> Heads) {
const ForestNode *Result = nullptr;
for (const auto *Head : Heads) {
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
Expand Up @@ -95,8 +95,8 @@ void CheckBaseInfo(Info *Expected, Info *Actual) {

void CheckSymbolInfo(SymbolInfo *Expected, SymbolInfo *Actual) {
CheckBaseInfo(Expected, Actual);
EXPECT_EQ(Expected->DefLoc.hasValue(), Actual->DefLoc.hasValue());
if (Expected->DefLoc && Actual->DefLoc.hasValue()) {
EXPECT_EQ(Expected->DefLoc.has_value(), Actual->DefLoc.has_value());
if (Expected->DefLoc && Actual->DefLoc.has_value()) {
EXPECT_EQ(Expected->DefLoc->LineNumber, Actual->DefLoc->LineNumber);
EXPECT_EQ(Expected->DefLoc->Filename, Actual->DefLoc->Filename);
}
Expand Down
24 changes: 12 additions & 12 deletions clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
Expand Up @@ -129,14 +129,14 @@ TEST(ParseConfiguration, MergeConfigurations) {
EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
EXPECT_EQ("user2", *Options.User);
ASSERT_TRUE(Options.ExtraArgs.hasValue());
ASSERT_TRUE(Options.ExtraArgs.has_value());
EXPECT_EQ("arg1,arg2,arg3,arg4", llvm::join(Options.ExtraArgs->begin(),
Options.ExtraArgs->end(), ","));
ASSERT_TRUE(Options.ExtraArgsBefore.hasValue());
ASSERT_TRUE(Options.ExtraArgsBefore.has_value());
EXPECT_EQ("arg-before1,arg-before2,arg-before3,arg-before4",
llvm::join(Options.ExtraArgsBefore->begin(),
Options.ExtraArgsBefore->end(), ","));
ASSERT_TRUE(Options.UseColor.hasValue());
ASSERT_TRUE(Options.UseColor.has_value());
EXPECT_TRUE(*Options.UseColor);
}

Expand Down Expand Up @@ -325,9 +325,9 @@ TEST(CheckOptionsValidation, ValidIntOptions) {

CHECK_VAL(TestCheck.getIntLocal("IntExpected"), 1);
CHECK_VAL(TestCheck.getIntGlobal("GlobalIntExpected"), 1);
EXPECT_FALSE(TestCheck.getIntLocal("IntInvalid1").hasValue());
EXPECT_FALSE(TestCheck.getIntLocal("IntInvalid2").hasValue());
EXPECT_FALSE(TestCheck.getIntGlobal("GlobalIntInvalid").hasValue());
EXPECT_FALSE(TestCheck.getIntLocal("IntInvalid1").has_value());
EXPECT_FALSE(TestCheck.getIntLocal("IntInvalid2").has_value());
EXPECT_FALSE(TestCheck.getIntGlobal("GlobalIntInvalid").has_value());
ASSERT_EQ(TestCheck.getIntLocal("DefaultedIntInvalid", 1), 1);

CHECK_VAL(TestCheck.getIntLocal<bool>("BoolITrueValue"), true);
Expand Down Expand Up @@ -395,14 +395,14 @@ TEST(ValidConfiguration, ValidEnumOptions) {
/*IgnoreCase*/ true),
Colours::Violet);

EXPECT_FALSE(TestCheck.getIntLocal<Colours>("ValidWrongCase").hasValue());
EXPECT_FALSE(TestCheck.getIntLocal<Colours>("NearMiss").hasValue());
EXPECT_FALSE(TestCheck.getIntGlobal<Colours>("GlobalInvalid").hasValue());
EXPECT_FALSE(TestCheck.getIntLocal<Colours>("ValidWrongCase").has_value());
EXPECT_FALSE(TestCheck.getIntLocal<Colours>("NearMiss").has_value());
EXPECT_FALSE(TestCheck.getIntGlobal<Colours>("GlobalInvalid").has_value());
EXPECT_FALSE(
TestCheck.getIntGlobal<Colours>("GlobalValidWrongCase").hasValue());
EXPECT_FALSE(TestCheck.getIntGlobal<Colours>("GlobalNearMiss").hasValue());
TestCheck.getIntGlobal<Colours>("GlobalValidWrongCase").has_value());
EXPECT_FALSE(TestCheck.getIntGlobal<Colours>("GlobalNearMiss").has_value());

EXPECT_FALSE(TestCheck.getIntLocal<Colours>("Invalid").hasValue());
EXPECT_FALSE(TestCheck.getIntLocal<Colours>("Invalid").has_value());
EXPECT_THAT(
DiagConsumer.take(),
UnorderedElementsAre(
Expand Down
Expand Up @@ -53,9 +53,9 @@ TEST(ClangTidyOptionsProvider, InMemoryFileSystems) {
ClangTidyOptions File3Options =
FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp");

ASSERT_TRUE(File1Options.Checks.hasValue());
ASSERT_TRUE(File1Options.Checks.has_value());
EXPECT_EQ(*File1Options.Checks, "-*,clang-diagnostic-*,readability-*");
ASSERT_TRUE(File2Options.Checks.hasValue());
ASSERT_TRUE(File2Options.Checks.has_value());
EXPECT_EQ(*File2Options.Checks, "bugprone-*,misc-*,clang-diagnostic-*");

// 2 and 3 should use the same config so these should also be the same.
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/APINotes/Types.h
Expand Up @@ -76,7 +76,7 @@ class CommonEntityInfo {
}

void setSwiftPrivate(llvm::Optional<bool> Private) {
SwiftPrivateSpecified = Private.hasValue();
SwiftPrivateSpecified = Private.has_value();
SwiftPrivate = Private ? *Private : 0;
}

Expand Down
Expand Up @@ -414,7 +414,8 @@ class CallEvent {
bool isArgumentConstructedDirectly(unsigned Index) const {
// This assumes that the object was not yet removed from the state.
return ExprEngine::getObjectUnderConstruction(
getState(), {getOriginExpr(), Index}, getLocationContext()).hasValue();
getState(), {getOriginExpr(), Index}, getLocationContext())
.has_value();
}

/// Some calls have parameter numbering mismatched from argument numbering.
Expand Down
Expand Up @@ -59,15 +59,11 @@ class ConditionTruthVal {
bool isConstrainedFalse() const { return Val && !Val.getValue(); }

/// Return true if the constrained is perfectly constrained.
bool isConstrained() const {
return Val.hasValue();
}
bool isConstrained() const { return Val.has_value(); }

/// Return true if the constrained is underconstrained and we do not know
/// if the constraint is true of value.
bool isUnderconstrained() const {
return !Val.hasValue();
}
bool isUnderconstrained() const { return !Val.has_value(); }
};

class ConstraintManager {
Expand Down
Expand Up @@ -94,7 +94,7 @@ class CachedFileSystemEntry {
assert(!isDirectory() && "not a file");
assert(Contents && "contents not initialized");
if (auto *Directives = Contents->DepDirectives.load()) {
if (Directives->hasValue())
if (Directives->has_value())
return ArrayRef<dependency_directives_scan::Directive>(
Directives->getValue());
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaCodeComplete.cpp
Expand Up @@ -5362,8 +5362,8 @@ class ConceptInfo {
// Overwrite existing if the new member has more info.
// The preference of . vs :: vs -> is fairly arbitrary.
if (/*Inserted*/ R.second ||
std::make_tuple(M.ArgTypes.hasValue(), M.ResultType != nullptr,
M.Operator) > std::make_tuple(O.ArgTypes.hasValue(),
std::make_tuple(M.ArgTypes.has_value(), M.ResultType != nullptr,
M.Operator) > std::make_tuple(O.ArgTypes.has_value(),
O.ResultType != nullptr,
O.Operator))
O = std::move(M);
Expand Down

0 comments on commit 53daa17

Please sign in to comment.