Explorer: rename value categories to expression categories (#2744)

Rename value categories to expression categories based on [Discord discussion](https://discord.com/channels/655572317891461132/753021843459538996/1092924035517665332) regarding naming and behavior.

>* let expression -> value expression
>* var expression -> reference expression
>* located expression -> initializing expression
>So:
>- "value expressions" produce values (with no associated location). "reference expressions" produce a location of an existing value. "initializing expressions" take a location and initialize it.
>- A let binding is initialized by a value expression, because lets represent values (with category conversions performed as needed, but if a conversion is performed from a different category of expression, the value of the object is pinned for the lifetime of the let).
>- A var binding is initialized by an initializing expression, without performing a copy (with category conversions performed as needed, calling a copy constructor if the initializer is a different expression category).
>- The & operator requires a reference expression, and it's an error to give it other kinds.
>- The left-hand side of . requires a value expression when calling a function with a non-addr receiver, and requires a reference expression when calling a function with an addr receiver (it's an error to give it a value expression, and for an initializing expression, a temporary is materialized).

Changes
* Rename "value category" to "expression category"
* Rename Var and Let value categories to Value, Reference, and Initializing expression
* Rename `lvalue` to `location` (most of the time)
This commit is contained in:
Adrien Leravat
2023-04-05 16:16:10 -07:00
committed by GitHub
parent 3f1515af55
commit d0645c6a85
32 changed files with 376 additions and 320 deletions
+6 -6
View File
@@ -34,8 +34,8 @@ TEST_F(ElementTest, NamedElementType) {
src_loc,
arena.New<BindingPattern>(src_loc, "valuename",
arena.New<AutoPattern>(src_loc),
ValueCategory::Var),
std::nullopt, ValueCategory::Var};
ExpressionCategory::Reference),
std::nullopt, ExpressionCategory::Reference};
const auto* static_type = arena.New<IntValue>(1);
decl.set_static_type(static_type);
NamedElement element_decl(&decl);
@@ -53,8 +53,8 @@ TEST_F(ElementTest, NamedElementDeclaration) {
src_loc,
arena.New<BindingPattern>(src_loc, "valuename",
arena.New<AutoPattern>(src_loc),
ValueCategory::Var),
std::nullopt, ValueCategory::Var};
ExpressionCategory::Reference),
std::nullopt, ExpressionCategory::Reference};
const auto* static_type = arena.New<IntValue>(1);
NamedElement element_decl(&decl);
@@ -71,8 +71,8 @@ TEST_F(ElementTest, NamedElementIsNamed) {
src_loc,
arena.New<BindingPattern>(src_loc, "valuename",
arena.New<AutoPattern>(src_loc),
ValueCategory::Var),
std::nullopt, ValueCategory::Var};
ExpressionCategory::Reference),
std::nullopt, ExpressionCategory::Reference};
NamedElement member_decl(&decl);
EXPECT_TRUE(member_decl.IsNamed("valuename"));
EXPECT_FALSE(member_decl.IsNamed("anything"));