mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Initial support for generic parameters that are introduced in a function parameter list (#1247)
In order for this to work, we need to always use the argument deduction code path for function calls, instead of only using it when there is a `[...]` list, which means that argument deduction now needs to support implicit conversion. Co-authored-by: Jon Meow <jperkins@google.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
parent
b27aa21a88
commit
c29f56e667
@@ -198,9 +198,9 @@ auto FunctionDeclaration::Create(
|
||||
<< "illegal AST node in implicit parameter list";
|
||||
}
|
||||
}
|
||||
return arena->New<FunctionDeclaration>(source_loc, name, resolved_params,
|
||||
me_pattern, param_pattern, return_term,
|
||||
body);
|
||||
return arena->New<FunctionDeclaration>(source_loc, name,
|
||||
std::move(resolved_params), me_pattern,
|
||||
param_pattern, return_term, body);
|
||||
}
|
||||
|
||||
void FunctionDeclaration::PrintDepth(int depth, llvm::raw_ostream& out) const {
|
||||
|
||||
+16
-23
@@ -93,40 +93,33 @@ void Pattern::PrintID(llvm::raw_ostream& out) const {
|
||||
}
|
||||
}
|
||||
|
||||
// Equivalent to `GetBindings`, but stores its output in `bindings` instead of
|
||||
// returning it.
|
||||
static void GetBindingsImpl(
|
||||
const Pattern& pattern,
|
||||
std::vector<Nonnull<const BindingPattern*>>& bindings) {
|
||||
auto VisitNestedPatterns(const Pattern& pattern,
|
||||
llvm::function_ref<bool(const Pattern&)> visitor)
|
||||
-> bool {
|
||||
if (!visitor(pattern)) {
|
||||
return false;
|
||||
}
|
||||
switch (pattern.kind()) {
|
||||
case PatternKind::BindingPattern:
|
||||
bindings.push_back(&cast<BindingPattern>(pattern));
|
||||
return;
|
||||
case PatternKind::TuplePattern:
|
||||
for (const Pattern* field : cast<TuplePattern>(pattern).fields()) {
|
||||
GetBindingsImpl(*field, bindings);
|
||||
if (!VisitNestedPatterns(*field, visitor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
case PatternKind::AlternativePattern:
|
||||
GetBindingsImpl(cast<AlternativePattern>(pattern).arguments(), bindings);
|
||||
return;
|
||||
return VisitNestedPatterns(cast<AlternativePattern>(pattern).arguments(),
|
||||
visitor);
|
||||
case PatternKind::VarPattern:
|
||||
return VisitNestedPatterns(cast<VarPattern>(pattern).pattern(), visitor);
|
||||
case PatternKind::BindingPattern:
|
||||
case PatternKind::AutoPattern:
|
||||
case PatternKind::ExpressionPattern:
|
||||
case PatternKind::GenericBinding:
|
||||
return;
|
||||
case PatternKind::VarPattern:
|
||||
GetBindingsImpl(cast<VarPattern>(pattern).pattern(), bindings);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
auto GetBindings(const Pattern& pattern)
|
||||
-> std::vector<Nonnull<const BindingPattern*>> {
|
||||
std::vector<Nonnull<const BindingPattern*>> result;
|
||||
GetBindingsImpl(pattern, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
auto PatternFromParenContents(Nonnull<Arena*> arena, SourceLocation source_loc,
|
||||
const ParenContents<Pattern>& paren_contents)
|
||||
-> Nonnull<Pattern*> {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "explorer/ast/value_category.h"
|
||||
#include "explorer/common/source_location.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/STLFunctionalExtras.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -88,11 +89,12 @@ class Pattern : public AstNode {
|
||||
std::optional<Nonnull<const Value*>> value_;
|
||||
};
|
||||
|
||||
class BindingPattern;
|
||||
|
||||
// Returns all `BindingPattern`s in the AST subtree rooted at `pattern`.
|
||||
auto GetBindings(const Pattern& pattern)
|
||||
-> std::vector<Nonnull<const BindingPattern*>>;
|
||||
// Call the given `visitor` on all patterns nested within the given pattern,
|
||||
// including `pattern` itself. Aborts and returns `false` if `visitor` returns
|
||||
// `false`, otherwise returns `true`.
|
||||
auto VisitNestedPatterns(const Pattern& pattern,
|
||||
llvm::function_ref<bool(const Pattern&)> visitor)
|
||||
-> bool;
|
||||
|
||||
// A pattern consisting of the `auto` keyword.
|
||||
class AutoPattern : public Pattern {
|
||||
|
||||
Reference in New Issue
Block a user