mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 11:41:06 +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:
@@ -185,12 +185,13 @@ void ReturnTerm::Print(llvm::raw_ostream& out) const {
|
||||
}
|
||||
}
|
||||
|
||||
auto FunctionDeclaration::Create(
|
||||
Nonnull<Arena*> arena, SourceLocation source_loc, std::string name,
|
||||
std::vector<Nonnull<AstNode*>> deduced_params,
|
||||
std::optional<Nonnull<BindingPattern*>> me_pattern,
|
||||
Nonnull<TuplePattern*> param_pattern, ReturnTerm return_term,
|
||||
std::optional<Nonnull<Block*>> body)
|
||||
auto FunctionDeclaration::Create(Nonnull<Arena*> arena,
|
||||
SourceLocation source_loc, std::string name,
|
||||
std::vector<Nonnull<AstNode*>> deduced_params,
|
||||
std::optional<Nonnull<Pattern*>> me_pattern,
|
||||
Nonnull<TuplePattern*> param_pattern,
|
||||
ReturnTerm return_term,
|
||||
std::optional<Nonnull<Block*>> body)
|
||||
-> ErrorOr<Nonnull<FunctionDeclaration*>> {
|
||||
std::vector<Nonnull<GenericBinding*>> resolved_params;
|
||||
// Look for the `me` parameter in the `deduced_parameters`
|
||||
@@ -209,6 +210,16 @@ auto FunctionDeclaration::Create(
|
||||
me_pattern = bp;
|
||||
break;
|
||||
}
|
||||
case AstNodeKind::AddrPattern: {
|
||||
Nonnull<AddrPattern*> abp = &cast<AddrPattern>(*param);
|
||||
Nonnull<BindingPattern*> bp = &cast<BindingPattern>(abp->binding());
|
||||
if (me_pattern.has_value() || bp->name() != "me") {
|
||||
return CompilationError(source_loc)
|
||||
<< "illegal binding pattern in implicit parameter list";
|
||||
}
|
||||
me_pattern = abp;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return CompilationError(source_loc)
|
||||
<< "illegal AST node in implicit parameter list";
|
||||
|
||||
Reference in New Issue
Block a user