mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Change from ToImplicit to AsDesugared (#5591)
This changes `ToImplicit` to `AsDesugared`, and adds a `GetLocIdForDesugaring` to `InstStore`. In particular, I'm motivated by the latter, to make it clearer what the intended call convention is.
This commit is contained in:
@@ -33,29 +33,29 @@ TEST(IdsTest, LocIdValues) {
|
||||
Eq(-(1 << 30) + 1));
|
||||
}
|
||||
|
||||
// A standard parameterized test for (implicit, index).
|
||||
// A standard parameterized test for (is_desugared, index).
|
||||
class IdsTestWithParam
|
||||
: public testing::TestWithParam<std::tuple<bool, int32_t>> {
|
||||
public:
|
||||
explicit IdsTestWithParam() {
|
||||
llvm::errs() << "implicit=" << is_implicit()
|
||||
<< ", index=" << std::get<1>(GetParam()) << "\n";
|
||||
llvm::errs() << "is_desugared=" << is_desugared() << ", index=" << index()
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
// Returns IdT with its matching LocId form. Sets flags based on test
|
||||
// parameters.
|
||||
template <typename IdT>
|
||||
auto BuildIdAndLocId() -> std::pair<IdT, LocId> {
|
||||
auto [implicit, index] = GetParam();
|
||||
IdT id(index);
|
||||
LocId loc_id(id);
|
||||
if (implicit) {
|
||||
loc_id = loc_id.ToImplicit();
|
||||
IdT id(index());
|
||||
if (is_desugared()) {
|
||||
return {id, LocId(id).AsDesugared()};
|
||||
} else {
|
||||
return {id, LocId(id)};
|
||||
}
|
||||
return {id, loc_id};
|
||||
}
|
||||
|
||||
auto is_implicit() -> bool { return std::get<0>(GetParam()); }
|
||||
auto is_desugared() -> bool { return std::get<0>(GetParam()); }
|
||||
auto index() -> int32_t { return std::get<1>(GetParam()); }
|
||||
};
|
||||
|
||||
// Returns a test case generator for edge-case values.
|
||||
@@ -78,7 +78,7 @@ TEST_P(LocIdAsNoneTestWithParam, Test) {
|
||||
auto [_, loc_id] = BuildIdAndLocId<Parse::NodeId>();
|
||||
EXPECT_FALSE(loc_id.has_value());
|
||||
EXPECT_THAT(loc_id.kind(), Eq(LocId::Kind::None));
|
||||
EXPECT_FALSE(loc_id.is_implicit());
|
||||
EXPECT_FALSE(loc_id.is_desugared());
|
||||
EXPECT_THAT(loc_id.import_ir_inst_id(), Eq(ImportIRInstId::None));
|
||||
EXPECT_THAT(loc_id.inst_id(), Eq(InstId::None));
|
||||
EXPECT_THAT(loc_id.node_id(),
|
||||
@@ -96,7 +96,7 @@ TEST_P(LocIdAsImportIRInstIdTest, Test) {
|
||||
EXPECT_TRUE(loc_id.has_value());
|
||||
ASSERT_THAT(loc_id.kind(), Eq(LocId::Kind::ImportIRInstId));
|
||||
EXPECT_THAT(loc_id.import_ir_inst_id(), import_ir_inst_id);
|
||||
EXPECT_FALSE(loc_id.is_implicit());
|
||||
EXPECT_FALSE(loc_id.is_desugared());
|
||||
}
|
||||
|
||||
class LocIdAsInstIdTest : public IdsTestWithParam {};
|
||||
@@ -111,7 +111,7 @@ TEST_P(LocIdAsInstIdTest, Test) {
|
||||
EXPECT_TRUE(loc_id.has_value());
|
||||
ASSERT_THAT(loc_id.kind(), Eq(LocId::Kind::InstId));
|
||||
EXPECT_THAT(loc_id.inst_id(), inst_id);
|
||||
// Note that `is_implicit` is invalid to use with `InstId`.
|
||||
// Note that `is_desugared` is invalid to use with `InstId`.
|
||||
}
|
||||
|
||||
class LocIdAsNodeIdTest : public IdsTestWithParam {};
|
||||
@@ -124,7 +124,7 @@ TEST_P(LocIdAsNodeIdTest, Test) {
|
||||
EXPECT_TRUE(loc_id.has_value());
|
||||
ASSERT_THAT(loc_id.kind(), Eq(LocId::Kind::NodeId));
|
||||
EXPECT_THAT(loc_id.node_id(), node_id);
|
||||
EXPECT_THAT(loc_id.is_implicit(), Eq(is_implicit()));
|
||||
EXPECT_THAT(loc_id.is_desugared(), Eq(is_desugared()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user