mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Rename "PatternVariable" names for clarity (#630)
Pretty much any names will be awkward, since these types represent cases where an `Expression` is not an expression, and a `Value` is not a value, but we can at least be more explicit about the fact that they represent bindings rather than variable usages.
This commit is contained in:
@@ -22,9 +22,8 @@ auto Expression::GetIndexExpression() const -> const IndexExpression& {
|
||||
return std::get<IndexExpression>(value);
|
||||
}
|
||||
|
||||
auto Expression::GetPatternVariableExpression() const
|
||||
-> const PatternVariableExpression& {
|
||||
return std::get<PatternVariableExpression>(value);
|
||||
auto Expression::GetBindingExpression() const -> const BindingExpression& {
|
||||
return std::get<BindingExpression>(value);
|
||||
}
|
||||
|
||||
auto Expression::GetIntLiteral() const -> int {
|
||||
@@ -106,12 +105,12 @@ auto Expression::MakeIdentifierExpression(int line_num, std::string var)
|
||||
return v;
|
||||
}
|
||||
|
||||
auto Expression::MakePatternVariableExpression(int line_num, std::string var,
|
||||
const Expression* type)
|
||||
auto Expression::MakeBindingExpression(int line_num, std::string var,
|
||||
const Expression* type)
|
||||
-> const Expression* {
|
||||
auto* v = new Expression();
|
||||
v->line_num = line_num;
|
||||
v->value = PatternVariableExpression({.name = std::move(var), .type = type});
|
||||
v->value = BindingExpression({.name = std::move(var), .type = type});
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -281,10 +280,10 @@ void PrintExp(const Expression* e) {
|
||||
case ExpressionKind::IdentifierExpression:
|
||||
std::cout << e->GetIdentifierExpression().name;
|
||||
break;
|
||||
case ExpressionKind::PatternVariableExpression:
|
||||
PrintExp(e->GetPatternVariableExpression().type);
|
||||
case ExpressionKind::BindingExpression:
|
||||
PrintExp(e->GetBindingExpression().type);
|
||||
std::cout << ": ";
|
||||
std::cout << e->GetPatternVariableExpression().name;
|
||||
std::cout << e->GetBindingExpression().name;
|
||||
break;
|
||||
case ExpressionKind::CallExpression:
|
||||
PrintExp(e->GetCallExpression().function);
|
||||
|
||||
@@ -33,7 +33,7 @@ enum class ExpressionKind {
|
||||
IntTypeLiteral,
|
||||
ContinuationTypeLiteral, // The type of a continuation value.
|
||||
IntLiteral,
|
||||
PatternVariableExpression,
|
||||
BindingExpression,
|
||||
PrimitiveOperatorExpression,
|
||||
TupleLiteral,
|
||||
TypeTypeLiteral,
|
||||
@@ -72,9 +72,8 @@ struct IndexExpression {
|
||||
const Expression* offset;
|
||||
};
|
||||
|
||||
struct PatternVariableExpression {
|
||||
static constexpr ExpressionKind Kind =
|
||||
ExpressionKind::PatternVariableExpression;
|
||||
struct BindingExpression {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::BindingExpression;
|
||||
std::string name;
|
||||
const Expression* type;
|
||||
};
|
||||
@@ -140,8 +139,8 @@ struct Expression {
|
||||
|
||||
static auto MakeIdentifierExpression(int line_num, std::string var)
|
||||
-> const Expression*;
|
||||
static auto MakePatternVariableExpression(int line_num, std::string var,
|
||||
const Expression* type)
|
||||
static auto MakeBindingExpression(int line_num, std::string var,
|
||||
const Expression* type)
|
||||
-> const Expression*;
|
||||
static auto MakeIntLiteral(int line_num, int i) -> const Expression*;
|
||||
static auto MakeBoolLiteral(int line_num, bool b) -> const Expression*;
|
||||
@@ -168,7 +167,7 @@ struct Expression {
|
||||
auto GetIdentifierExpression() const -> const IdentifierExpression&;
|
||||
auto GetFieldAccessExpression() const -> const FieldAccessExpression&;
|
||||
auto GetIndexExpression() const -> const IndexExpression&;
|
||||
auto GetPatternVariableExpression() const -> const PatternVariableExpression&;
|
||||
auto GetBindingExpression() const -> const BindingExpression&;
|
||||
auto GetIntLiteral() const -> int;
|
||||
auto GetBoolLiteral() const -> bool;
|
||||
auto GetTupleLiteral() const -> const TupleLiteral&;
|
||||
@@ -179,7 +178,7 @@ struct Expression {
|
||||
|
||||
private:
|
||||
std::variant<IdentifierExpression, FieldAccessExpression, IndexExpression,
|
||||
PatternVariableExpression, IntLiteral, BoolLiteral, TupleLiteral,
|
||||
BindingExpression, IntLiteral, BoolLiteral, TupleLiteral,
|
||||
PrimitiveOperatorExpression, CallExpression, FunctionTypeLiteral,
|
||||
AutoTypeLiteral, BoolTypeLiteral, IntTypeLiteral,
|
||||
ContinuationTypeLiteral, TypeTypeLiteral>
|
||||
|
||||
Reference in New Issue
Block a user