mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Consistent naming for Expression and Value. (#621)
- `Kind` enumerator names always match the corresponding factory function, accessor, and type names (if any). - All abbreviations in those names are expanded. - Those names always have a suffix to disambiguate expressions from values. `VarTV` is excluded from these changes because there's a pending PR to remove it.
This commit is contained in:
@@ -23,21 +23,21 @@ struct FieldInitializer {
|
||||
};
|
||||
|
||||
enum class ExpressionKind {
|
||||
AutoT,
|
||||
BoolT,
|
||||
Boolean,
|
||||
Call,
|
||||
FunctionT,
|
||||
GetField,
|
||||
Index,
|
||||
IntT,
|
||||
ContinuationT, // The type of a continuation value.
|
||||
Integer,
|
||||
PatternVariable,
|
||||
PrimitiveOp,
|
||||
Tuple,
|
||||
TypeT,
|
||||
Variable,
|
||||
AutoTypeLiteral,
|
||||
BoolTypeLiteral,
|
||||
BoolLiteral,
|
||||
CallExpression,
|
||||
FunctionTypeLiteral,
|
||||
FieldAccessExpression,
|
||||
IndexExpression,
|
||||
IntTypeLiteral,
|
||||
ContinuationTypeLiteral, // The type of a continuation value.
|
||||
IntLiteral,
|
||||
PatternVariableExpression,
|
||||
PrimitiveOperatorExpression,
|
||||
TupleLiteral,
|
||||
TypeTypeLiteral,
|
||||
IdentifierExpression,
|
||||
};
|
||||
|
||||
enum class Operator {
|
||||
@@ -55,124 +55,134 @@ enum class Operator {
|
||||
|
||||
struct Expression;
|
||||
|
||||
struct Variable {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::Variable;
|
||||
struct IdentifierExpression {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::IdentifierExpression;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct FieldAccess {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::GetField;
|
||||
struct FieldAccessExpression {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::FieldAccessExpression;
|
||||
const Expression* aggregate;
|
||||
std::string field;
|
||||
};
|
||||
|
||||
struct Index {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::Index;
|
||||
struct IndexExpression {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::IndexExpression;
|
||||
const Expression* aggregate;
|
||||
const Expression* offset;
|
||||
};
|
||||
|
||||
struct PatternVariable {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::PatternVariable;
|
||||
struct PatternVariableExpression {
|
||||
static constexpr ExpressionKind Kind =
|
||||
ExpressionKind::PatternVariableExpression;
|
||||
std::string name;
|
||||
const Expression* type;
|
||||
};
|
||||
|
||||
struct IntLiteral {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::Integer;
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::IntLiteral;
|
||||
int value;
|
||||
};
|
||||
|
||||
struct BoolLiteral {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::Boolean;
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::BoolLiteral;
|
||||
bool value;
|
||||
};
|
||||
|
||||
struct Tuple {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::Tuple;
|
||||
struct TupleLiteral {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::TupleLiteral;
|
||||
std::vector<FieldInitializer> fields;
|
||||
};
|
||||
|
||||
struct PrimitiveOperator {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::PrimitiveOp;
|
||||
struct PrimitiveOperatorExpression {
|
||||
static constexpr ExpressionKind Kind =
|
||||
ExpressionKind::PrimitiveOperatorExpression;
|
||||
Operator op;
|
||||
std::vector<const Expression*> arguments;
|
||||
};
|
||||
|
||||
struct Call {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::Call;
|
||||
struct CallExpression {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::CallExpression;
|
||||
const Expression* function;
|
||||
const Expression* argument;
|
||||
};
|
||||
|
||||
struct FunctionType {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::FunctionT;
|
||||
struct FunctionTypeLiteral {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::FunctionTypeLiteral;
|
||||
const Expression* parameter;
|
||||
const Expression* return_type;
|
||||
};
|
||||
|
||||
struct AutoT {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::AutoT;
|
||||
struct AutoTypeLiteral {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::AutoTypeLiteral;
|
||||
};
|
||||
|
||||
struct BoolT {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::BoolT;
|
||||
struct BoolTypeLiteral {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::BoolTypeLiteral;
|
||||
};
|
||||
|
||||
struct IntT {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::IntT;
|
||||
struct IntTypeLiteral {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::IntTypeLiteral;
|
||||
};
|
||||
|
||||
struct ContinuationT {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::ContinuationT;
|
||||
struct ContinuationTypeLiteral {
|
||||
static constexpr ExpressionKind Kind =
|
||||
ExpressionKind::ContinuationTypeLiteral;
|
||||
};
|
||||
|
||||
struct TypeT {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::TypeT;
|
||||
struct TypeTypeLiteral {
|
||||
static constexpr ExpressionKind Kind = ExpressionKind::TypeTypeLiteral;
|
||||
};
|
||||
|
||||
struct Expression {
|
||||
int line_num;
|
||||
inline auto tag() const -> ExpressionKind;
|
||||
|
||||
static auto MakeVar(int line_num, std::string var) -> const Expression*;
|
||||
static auto MakeVarPat(int line_num, std::string var, const Expression* type)
|
||||
static auto MakeIdentifierExpression(int line_num, std::string var)
|
||||
-> const Expression*;
|
||||
static auto MakeInt(int line_num, int i) -> const Expression*;
|
||||
static auto MakeBool(int line_num, bool b) -> const Expression*;
|
||||
static auto MakeOp(int line_num, Operator op,
|
||||
std::vector<const Expression*> args) -> const Expression*;
|
||||
static auto MakeCall(int line_num, const Expression* fun,
|
||||
const Expression* arg) -> const Expression*;
|
||||
static auto MakeGetField(int line_num, const Expression* exp,
|
||||
std::string field) -> const Expression*;
|
||||
static auto MakeTuple(int line_num, std::vector<FieldInitializer> args)
|
||||
static auto MakePatternVariableExpression(int line_num, std::string var,
|
||||
const Expression* type)
|
||||
-> const Expression*;
|
||||
static auto MakeIndex(int line_num, const Expression* exp,
|
||||
const Expression* i) -> const Expression*;
|
||||
static auto MakeTypeType(int line_num) -> const Expression*;
|
||||
static auto MakeIntType(int line_num) -> const Expression*;
|
||||
static auto MakeBoolType(int line_num) -> const Expression*;
|
||||
static auto MakeFunType(int line_num, const Expression* param,
|
||||
const Expression* ret) -> const Expression*;
|
||||
static auto MakeAutoType(int line_num) -> const Expression*;
|
||||
static auto MakeContinuationType(int line_num) -> const Expression*;
|
||||
static auto MakeIntLiteral(int line_num, int i) -> const Expression*;
|
||||
static auto MakeBoolLiteral(int line_num, bool b) -> const Expression*;
|
||||
static auto MakePrimitiveOperatorExpression(
|
||||
int line_num, Operator op, std::vector<const Expression*> args)
|
||||
-> const Expression*;
|
||||
static auto MakeCallExpression(int line_num, const Expression* fun,
|
||||
const Expression* arg) -> const Expression*;
|
||||
static auto MakeFieldAccessExpression(int line_num, const Expression* exp,
|
||||
std::string field) -> const Expression*;
|
||||
static auto MakeTupleLiteral(int line_num, std::vector<FieldInitializer> args)
|
||||
-> const Expression*;
|
||||
static auto MakeIndexExpression(int line_num, const Expression* exp,
|
||||
const Expression* i) -> const Expression*;
|
||||
static auto MakeTypeTypeLiteral(int line_num) -> const Expression*;
|
||||
static auto MakeIntTypeLiteral(int line_num) -> const Expression*;
|
||||
static auto MakeBoolTypeLiteral(int line_num) -> const Expression*;
|
||||
static auto MakeFunctionTypeLiteral(int line_num, const Expression* param,
|
||||
const Expression* ret)
|
||||
-> const Expression*;
|
||||
static auto MakeAutoTypeLiteral(int line_num) -> const Expression*;
|
||||
static auto MakeContinuationTypeLiteral(int line_num) -> const Expression*;
|
||||
|
||||
auto GetVariable() const -> const Variable&;
|
||||
auto GetFieldAccess() const -> const FieldAccess&;
|
||||
auto GetIndex() const -> const Index&;
|
||||
auto GetPatternVariable() const -> const PatternVariable&;
|
||||
auto GetInteger() const -> int;
|
||||
auto GetBoolean() const -> bool;
|
||||
auto GetTuple() const -> const Tuple&;
|
||||
auto GetPrimitiveOperator() const -> const PrimitiveOperator&;
|
||||
auto GetCall() const -> const Call&;
|
||||
auto GetFunctionType() const -> const FunctionType&;
|
||||
auto GetIdentifierExpression() const -> const IdentifierExpression&;
|
||||
auto GetFieldAccessExpression() const -> const FieldAccessExpression&;
|
||||
auto GetIndexExpression() const -> const IndexExpression&;
|
||||
auto GetPatternVariableExpression() const -> const PatternVariableExpression&;
|
||||
auto GetIntLiteral() const -> int;
|
||||
auto GetBoolLiteral() const -> bool;
|
||||
auto GetTupleLiteral() const -> const TupleLiteral&;
|
||||
auto GetPrimitiveOperatorExpression() const
|
||||
-> const PrimitiveOperatorExpression&;
|
||||
auto GetCallExpression() const -> const CallExpression&;
|
||||
auto GetFunctionTypeLiteral() const -> const FunctionTypeLiteral&;
|
||||
|
||||
private:
|
||||
std::variant<Variable, FieldAccess, Index, PatternVariable, IntLiteral,
|
||||
BoolLiteral, Tuple, PrimitiveOperator, Call, FunctionType, AutoT,
|
||||
BoolT, IntT, ContinuationT, TypeT>
|
||||
std::variant<IdentifierExpression, FieldAccessExpression, IndexExpression,
|
||||
PatternVariableExpression, IntLiteral, BoolLiteral, TupleLiteral,
|
||||
PrimitiveOperatorExpression, CallExpression, FunctionTypeLiteral,
|
||||
AutoTypeLiteral, BoolTypeLiteral, IntTypeLiteral,
|
||||
ContinuationTypeLiteral, TypeTypeLiteral>
|
||||
value;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user