mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add typechecking of type declarations (#984)
Also explicitly model the types of expressions whose values are class or choice types, and make those be the static_type of the type declaration. This ensures that the static_type of a NamedEntity consistently corresponds to the static type of an IdentifierExpression using that name.
This commit is contained in:
@@ -58,6 +58,8 @@ class Value {
|
||||
ContinuationValue, // A first-class continuation value.
|
||||
StringType,
|
||||
StringValue,
|
||||
TypeOfClassType,
|
||||
TypeOfChoiceType,
|
||||
};
|
||||
|
||||
Value(const Value&) = delete;
|
||||
@@ -560,6 +562,44 @@ class StringValue : public Value {
|
||||
std::string value_;
|
||||
};
|
||||
|
||||
// The type of an expression whose value is a class type. Currently there is no
|
||||
// way to explicitly name such a type in Carbon code, but we are tentatively
|
||||
// using `typeof(ClassName)` as the debug-printing format, in anticipation of
|
||||
// something like that becoming valid Carbon syntax.
|
||||
class TypeOfClassType : public Value {
|
||||
public:
|
||||
explicit TypeOfClassType(Nonnull<const NominalClassType*> class_type)
|
||||
: Value(Kind::TypeOfClassType), class_type_(class_type) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->kind() == Kind::TypeOfClassType;
|
||||
}
|
||||
|
||||
auto class_type() const -> const NominalClassType& { return *class_type_; }
|
||||
|
||||
private:
|
||||
Nonnull<const NominalClassType*> class_type_;
|
||||
};
|
||||
|
||||
// The type of an expression whose value is a choice type. Currently there is no
|
||||
// way to explicitly name such a type in Carbon code, but we are tentatively
|
||||
// using `typeof(ChoiceName)` as the debug-printing format, in anticipation of
|
||||
// something like that becoming valid Carbon syntax.
|
||||
class TypeOfChoiceType : public Value {
|
||||
public:
|
||||
explicit TypeOfChoiceType(Nonnull<const ChoiceType*> choice_type)
|
||||
: Value(Kind::TypeOfChoiceType), choice_type_(choice_type) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->kind() == Kind::TypeOfChoiceType;
|
||||
}
|
||||
|
||||
auto choice_type() const -> const ChoiceType& { return *choice_type_; }
|
||||
|
||||
private:
|
||||
Nonnull<const ChoiceType*> choice_type_;
|
||||
};
|
||||
|
||||
auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2) -> bool;
|
||||
auto ValueEqual(Nonnull<const Value*> v1, Nonnull<const Value*> v2,
|
||||
SourceLocation source_loc) -> bool;
|
||||
|
||||
Reference in New Issue
Block a user