mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Give Pattern::clone() an OptionSet rather than a bool; it's going to get more interesting.
Swift SVN r15061
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "swift/AST/Type.h"
|
||||
#include "swift/AST/Types.h"
|
||||
#include "swift/AST/TypeLoc.h"
|
||||
#include "swift/Basic/OptionSet.h"
|
||||
|
||||
namespace swift {
|
||||
class ASTContext;
|
||||
@@ -136,8 +137,13 @@ public:
|
||||
/// this pattern. This is a pre-order traversal.
|
||||
void forEachNode(const std::function<void(Pattern*)> &f);
|
||||
|
||||
/// Flags used to indicate how pattern cloning should operate.
|
||||
enum CloneFlags {
|
||||
Implicit = 0x01,
|
||||
};
|
||||
|
||||
Pattern *clone(ASTContext &context, bool Implicit = false) const;
|
||||
Pattern *clone(ASTContext &context,
|
||||
OptionSet<CloneFlags> options = None) const;
|
||||
|
||||
static bool classof(const Pattern *P) { return true; }
|
||||
|
||||
|
||||
@@ -185,7 +185,8 @@ void Pattern::forEachNode(const std::function<void(Pattern*)> &f) {
|
||||
|
||||
|
||||
|
||||
Pattern *Pattern::clone(ASTContext &context, bool Implicit) const {
|
||||
Pattern *Pattern::clone(ASTContext &context,
|
||||
OptionSet<CloneFlags> options) const {
|
||||
Pattern *result;
|
||||
switch (getKind()) {
|
||||
case PatternKind::Any:
|
||||
@@ -202,7 +203,7 @@ Pattern *Pattern::clone(ASTContext &context, bool Implicit) const {
|
||||
? named->getDecl()->getType()
|
||||
: Type(),
|
||||
named->getDecl()->getDeclContext());
|
||||
if (Implicit || var->isImplicit())
|
||||
if ((options & Implicit) || var->isImplicit())
|
||||
var->setImplicit();
|
||||
result = new (context) NamedPattern(var);
|
||||
break;
|
||||
@@ -212,7 +213,7 @@ Pattern *Pattern::clone(ASTContext &context, bool Implicit) const {
|
||||
auto paren = cast<ParenPattern>(this);
|
||||
result = new (context) ParenPattern(paren->getLParenLoc(),
|
||||
paren->getSubPattern()->clone(context,
|
||||
Implicit),
|
||||
options),
|
||||
paren->getRParenLoc());
|
||||
break;
|
||||
}
|
||||
@@ -222,7 +223,7 @@ Pattern *Pattern::clone(ASTContext &context, bool Implicit) const {
|
||||
SmallVector<TuplePatternElt, 2> elts;
|
||||
elts.reserve(tuple->getNumFields());
|
||||
for (const auto &elt : tuple->getFields())
|
||||
elts.push_back(TuplePatternElt(elt.getPattern()->clone(context, Implicit),
|
||||
elts.push_back(TuplePatternElt(elt.getPattern()->clone(context, options),
|
||||
elt.getInit(),
|
||||
elt.getDefaultArgKind()));
|
||||
result = TuplePattern::create(context, tuple->getLParenLoc(), elts,
|
||||
@@ -235,7 +236,7 @@ Pattern *Pattern::clone(ASTContext &context, bool Implicit) const {
|
||||
case PatternKind::Typed: {
|
||||
auto typed = cast<TypedPattern>(this);
|
||||
result = new(context) TypedPattern(typed->getSubPattern()->clone(context,
|
||||
Implicit),
|
||||
options),
|
||||
typed->getTypeLoc().clone(context));
|
||||
break;
|
||||
}
|
||||
@@ -257,7 +258,7 @@ Pattern *Pattern::clone(ASTContext &context, bool Implicit) const {
|
||||
elt.getProperty(),
|
||||
elt.getColonLoc(),
|
||||
elt.getSubPattern()->clone(context,
|
||||
Implicit)));
|
||||
options)));
|
||||
}
|
||||
|
||||
result = NominalTypePattern::create(nom->getCastTypeLoc().clone(context),
|
||||
@@ -271,7 +272,7 @@ Pattern *Pattern::clone(ASTContext &context, bool Implicit) const {
|
||||
auto oof = cast<EnumElementPattern>(this);
|
||||
Pattern *sub = nullptr;
|
||||
if (oof->hasSubPattern())
|
||||
sub = oof->getSubPattern()->clone(context, Implicit);
|
||||
sub = oof->getSubPattern()->clone(context, options);
|
||||
result = new (context) EnumElementPattern(oof->getParentType()
|
||||
.clone(context),
|
||||
oof->getLoc(),
|
||||
@@ -295,13 +296,13 @@ Pattern *Pattern::clone(ASTContext &context, bool Implicit) const {
|
||||
auto var = cast<VarPattern>(this);
|
||||
result = new(context) VarPattern(var->getLoc(),
|
||||
var->getSubPattern()->clone(context,
|
||||
Implicit));
|
||||
options));
|
||||
}
|
||||
}
|
||||
|
||||
if (hasType())
|
||||
result->setType(getType());
|
||||
if (Implicit || isImplicit())
|
||||
if ((options & Implicit) || isImplicit())
|
||||
result->setImplicit();
|
||||
|
||||
return result;
|
||||
|
||||
@@ -359,8 +359,8 @@ static FuncDecl *makeOptionSetFactoryMethod(StructDecl *optionSetDecl,
|
||||
rawParam->setImplicit();
|
||||
rawParam->setType(rawArgType);
|
||||
|
||||
Pattern *argParams[] = {selfParam->clone(C, /*Implicit=*/true),
|
||||
rawParam->clone(C, /*Implicit=*/true)};
|
||||
Pattern *argParams[] = {selfParam->clone(C, Pattern::Implicit),
|
||||
rawParam->clone(C, Pattern::Implicit)};
|
||||
Pattern *bodyParams[] = {selfParam, rawParam};
|
||||
|
||||
Type retType;
|
||||
|
||||
@@ -1294,7 +1294,7 @@ static FuncDecl *createAccessorFunc(SourceLoc DeclLoc,
|
||||
}
|
||||
|
||||
if (Indices) {
|
||||
Indices = Indices->clone(P->Context, /*Implicit=*/true);
|
||||
Indices = Indices->clone(P->Context, Pattern::Implicit);
|
||||
if (auto *PP = dyn_cast<ParenPattern>(Indices)) {
|
||||
ValueArgElements.push_back(TuplePatternElt(PP->getSubPattern()));
|
||||
} else {
|
||||
|
||||
@@ -110,7 +110,7 @@ static ParserStatus parseDefaultArgument(Parser &P,
|
||||
static Pattern *rebuildImplicitPatternAround(const Pattern *P, Pattern *NewRoot,
|
||||
ASTContext &C) {
|
||||
// We'll return a cloned copy of the pattern.
|
||||
Pattern *Result = P->clone(C, /*isImplicit*/true);
|
||||
Pattern *Result = P->clone(C, Pattern::Implicit);
|
||||
|
||||
class ReplaceRoot : public ASTWalker {
|
||||
Pattern *NewRoot;
|
||||
|
||||
@@ -112,7 +112,7 @@ deriveEquatable_enum_eq(TypeChecker &tc, EnumDecl *enumDecl) {
|
||||
params->setImplicit();
|
||||
params->setType(paramsTy);
|
||||
|
||||
Pattern *argParams = params->clone(C, /*implicit*/ true);
|
||||
Pattern *argParams = params->clone(C, Pattern::Implicit);
|
||||
|
||||
auto genericParams = enumDecl->getGenericParamsOfContext();
|
||||
|
||||
@@ -148,7 +148,7 @@ deriveEquatable_enum_eq(TypeChecker &tc, EnumDecl *enumDecl) {
|
||||
Identifier(), elt,
|
||||
nullptr);
|
||||
aPat->setImplicit();
|
||||
auto bPat = aPat->clone(C, /*implicit*/ true);
|
||||
auto bPat = aPat->clone(C, Pattern::Implicit);
|
||||
|
||||
TuplePatternElt tupleElts[] = {
|
||||
TuplePatternElt(aPat),
|
||||
|
||||
@@ -262,8 +262,8 @@ static FuncDecl *deriveRawRepresentable_fromRaw(TypeChecker &tc,
|
||||
rawParam->setType(rawType);
|
||||
rawParam->setImplicit();
|
||||
|
||||
Pattern *argParams[] = {selfParam->clone(C, /*Implicit=*/true),
|
||||
rawParam->clone(C, /*Implicit=*/true)};
|
||||
Pattern *argParams[] = {selfParam->clone(C, Pattern::Implicit),
|
||||
rawParam->clone(C, Pattern::Implicit)};
|
||||
Pattern *bodyParams[] = {selfParam, rawParam};
|
||||
auto retTy = OptionalType::get(enumType);
|
||||
auto fromRawDecl = FuncDecl::create(
|
||||
|
||||
@@ -3943,9 +3943,9 @@ createSubobjectInitOverride(TypeChecker &tc,
|
||||
|
||||
// Create the initializer parameter patterns.
|
||||
Pattern *argParamPatterns
|
||||
= superclassCtor->getArgParamPatterns()[1]->clone(ctx,/*Implicit=*/true);
|
||||
= superclassCtor->getArgParamPatterns()[1]->clone(ctx, Pattern::Implicit);
|
||||
Pattern *bodyParamPatterns
|
||||
= superclassCtor->getBodyParamPatterns()[1]->clone(ctx,/*Implicit=*/true);
|
||||
= superclassCtor->getBodyParamPatterns()[1]->clone(ctx, Pattern::Implicit);
|
||||
|
||||
// Create the initializer declaration.
|
||||
auto ctor = new (ctx) ConstructorDecl(ctx.Id_init, SourceLoc(),
|
||||
|
||||
Reference in New Issue
Block a user