mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 19:51:09 +01:00
Addr Keyword Implementation (#1255)
* Implement addr keyword * Add files that were deleted during merge Some files got deleted during merging trunk because of the executable semantics rename. * Implement changes from code review. Major changes: - Rename AddrBindingPattern to AddrPattern - Fix AddrPattern related changes in fuzzing * Update documentation for GetField * Fix AddPattern according to @zygoloid's suggestions * Apply @zygoloid's changes to method comment * Add a multi-component field example * Incorporate AST changes to fuzzer corpus * Refactor the deduced_param_list grammar rule Suggested by @zygoloid
This commit is contained in:
@@ -31,7 +31,7 @@ auto StructValue::FindField(const std::string& name) const
|
||||
|
||||
static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
|
||||
const FieldPath::Component& field,
|
||||
SourceLocation source_loc)
|
||||
SourceLocation source_loc, Nonnull<const Value*> me_value)
|
||||
-> ErrorOr<Nonnull<const Value*>> {
|
||||
const std::string& f = field.name();
|
||||
|
||||
@@ -93,7 +93,7 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
|
||||
} else if ((*func)->declaration().is_method()) {
|
||||
// Found a method. Turn it into a bound method.
|
||||
const FunctionValue& m = cast<FunctionValue>(**func);
|
||||
return arena->New<BoundMethodValue>(&m.declaration(), &object,
|
||||
return arena->New<BoundMethodValue>(&m.declaration(), me_value,
|
||||
class_type.type_args(),
|
||||
class_type.witnesses());
|
||||
} else {
|
||||
@@ -131,12 +131,13 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
|
||||
}
|
||||
|
||||
auto Value::GetMember(Nonnull<Arena*> arena, const FieldPath& path,
|
||||
SourceLocation source_loc) const
|
||||
SourceLocation source_loc,
|
||||
Nonnull<const Value*> me_value) const
|
||||
-> ErrorOr<Nonnull<const Value*>> {
|
||||
Nonnull<const Value*> value(this);
|
||||
for (const FieldPath::Component& field : path.components_) {
|
||||
CARBON_ASSIGN_OR_RETURN(value,
|
||||
Carbon::GetMember(arena, value, field, source_loc));
|
||||
CARBON_ASSIGN_OR_RETURN(
|
||||
value, Carbon::GetMember(arena, value, field, source_loc, me_value));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -216,6 +217,11 @@ void Value::Print(llvm::raw_ostream& out) const {
|
||||
out << ">";
|
||||
break;
|
||||
}
|
||||
case Value::Kind::AddrValue: {
|
||||
const auto& addr = cast<AddrValue>(*this);
|
||||
out << "Addr<" << addr.pattern() << ">";
|
||||
break;
|
||||
}
|
||||
case Value::Kind::AlternativeValue: {
|
||||
const auto& alt = cast<AlternativeValue>(*this);
|
||||
out << "alt " << alt.choice_name() << "." << alt.alt_name() << " "
|
||||
@@ -569,6 +575,7 @@ auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2) -> bool {
|
||||
case Value::Kind::PointerValue:
|
||||
case Value::Kind::LValue:
|
||||
case Value::Kind::BindingPlaceholderValue:
|
||||
case Value::Kind::AddrValue:
|
||||
case Value::Kind::ContinuationValue:
|
||||
case Value::Kind::ParameterizedEntityName:
|
||||
case Value::Kind::MemberName:
|
||||
@@ -679,6 +686,7 @@ auto ValueEqual(Nonnull<const Value*> v1, Nonnull<const Value*> v2) -> bool {
|
||||
case Value::Kind::NominalClassValue:
|
||||
case Value::Kind::AlternativeValue:
|
||||
case Value::Kind::BindingPlaceholderValue:
|
||||
case Value::Kind::AddrValue:
|
||||
case Value::Kind::AlternativeConstructorValue:
|
||||
case Value::Kind::ContinuationValue:
|
||||
case Value::Kind::PointerValue:
|
||||
|
||||
Reference in New Issue
Block a user