Rename PointerType::type to pointee_type. (#2468)

This avoids the confusion that can arise from the natural assumption that `foo->type()` returns the type of the value `foo`.
This commit is contained in:
Geoff Romer
2022-12-13 13:08:08 -08:00
committed by GitHub
parent 43283cb516
commit 493eb75e7f
3 changed files with 14 additions and 13 deletions
+5 -5
View File
@@ -366,7 +366,7 @@ static auto TypeContainsAuto(Nonnull<const Value*> type) -> bool {
case Value::Kind::TupleType:
return llvm::any_of(cast<TupleType>(type)->elements(), TypeContainsAuto);
case Value::Kind::PointerType:
return TypeContainsAuto(&cast<PointerType>(type)->type());
return TypeContainsAuto(&cast<PointerType>(type)->pointee_type());
case Value::Kind::StaticArrayType:
return TypeContainsAuto(&cast<StaticArrayType>(type)->element_type());
}
@@ -987,8 +987,8 @@ auto TypeChecker::ArgumentDeduction::Deduce(Nonnull<const Value*> param,
if (arg->kind() != Value::Kind::PointerType) {
return handle_non_deduced_type();
}
return Deduce(&cast<PointerType>(*param).type(),
&cast<PointerType>(*arg).type(),
return Deduce(&cast<PointerType>(*param).pointee_type(),
&cast<PointerType>(*arg).pointee_type(),
/*allow_implicit_conversion=*/false);
}
// Nothing to do in the case for `auto`.
@@ -3077,7 +3077,7 @@ auto TypeChecker::TypeCheckExp(Nonnull<Expression*> e,
case Operator::Deref:
CARBON_RETURN_IF_ERROR(
ExpectPointerType(e->source_loc(), "*", ts[0]));
op.set_static_type(&cast<PointerType>(*ts[0]).type());
op.set_static_type(&cast<PointerType>(*ts[0]).pointee_type());
op.set_value_category(ValueCategory::Var);
return Success();
case Operator::Ptr:
@@ -3889,7 +3889,7 @@ auto TypeChecker::TypeCheckPattern(
if (const auto* inner_binding_type =
dyn_cast<PointerType>(&addr_pattern.binding().static_type())) {
addr_pattern.set_static_type(&inner_binding_type->type());
addr_pattern.set_static_type(&inner_binding_type->pointee_type());
} else {
return ProgramError(addr_pattern.source_loc())
<< "Type associated with addr must be a pointer type.";
+3 -3
View File
@@ -450,7 +450,7 @@ void Value::Print(llvm::raw_ostream& out) const {
out << "Continuation";
break;
case Value::Kind::PointerType:
out << cast<PointerType>(*this).type() << "*";
out << cast<PointerType>(*this).pointee_type() << "*";
break;
case Value::Kind::FunctionType: {
const auto& fn_type = cast<FunctionType>(*this);
@@ -722,8 +722,8 @@ auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2,
}
switch (t1->kind()) {
case Value::Kind::PointerType:
return TypeEqual(&cast<PointerType>(*t1).type(),
&cast<PointerType>(*t2).type(), equality_ctx);
return TypeEqual(&cast<PointerType>(*t1).pointee_type(),
&cast<PointerType>(*t2).pointee_type(), equality_ctx);
case Value::Kind::FunctionType: {
const auto& fn1 = cast<FunctionType>(*t1);
const auto& fn2 = cast<FunctionType>(*t2);
+6 -5
View File
@@ -670,8 +670,9 @@ class FunctionType : public Value {
// A pointer type.
class PointerType : public Value {
public:
explicit PointerType(Nonnull<const Value*> type)
: Value(Kind::PointerType), type_(type) {}
// Constructs a pointer type with the given pointee type.
explicit PointerType(Nonnull<const Value*> pointee_type)
: Value(Kind::PointerType), pointee_type_(pointee_type) {}
static auto classof(const Value* value) -> bool {
return value->kind() == Kind::PointerType;
@@ -679,13 +680,13 @@ class PointerType : public Value {
template <typename F>
auto Decompose(F f) const {
return f(type_);
return f(pointee_type_);
}
auto type() const -> const Value& { return *type_; }
auto pointee_type() const -> const Value& { return *pointee_type_; }
private:
Nonnull<const Value*> type_;
Nonnull<const Value*> pointee_type_;
};
// The `auto` type.