mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
When we have selector-style syntax for functions, make the argument patterns implicit.
Argument patterns create pseudo-named patterns, so make them implicit and ignore them when scanning for explicit source information. Also make sure that the clang importer sets the HasSelectorStyleSignature bit appropriately. Swift SVN r8803
This commit is contained in:
@@ -940,6 +940,7 @@ namespace {
|
||||
selfPat->setType(selfVar->getType());
|
||||
argPatterns.push_back(selfPat);
|
||||
bodyPatterns.push_back(selfPat);
|
||||
bool hasSelectorStyleSignature;
|
||||
|
||||
// Import the type that this method will have.
|
||||
auto type = Impl.importFunctionType(decl->getResultType(),
|
||||
@@ -948,6 +949,7 @@ namespace {
|
||||
decl->isVariadic(),
|
||||
argPatterns,
|
||||
bodyPatterns,
|
||||
&hasSelectorStyleSignature,
|
||||
decl->getSelector());
|
||||
if (!type)
|
||||
return nullptr;
|
||||
@@ -967,6 +969,9 @@ namespace {
|
||||
TypeLoc::withoutLoc(resultTy), dc);
|
||||
result->setBodyResultType(resultTy);
|
||||
|
||||
if (hasSelectorStyleSignature)
|
||||
result->setHasSelectorStyleSignature();
|
||||
|
||||
setVarDeclContexts(argPatterns, result);
|
||||
setVarDeclContexts(bodyPatterns, result);
|
||||
|
||||
@@ -1191,6 +1196,7 @@ namespace {
|
||||
|
||||
argPatterns.push_back(selfPat);
|
||||
bodyPatterns.push_back(selfPat);
|
||||
bool hasSelectorStyleSignature;
|
||||
|
||||
// Import the type that this method will have.
|
||||
auto type = Impl.importFunctionType(objcMethod->getResultType(),
|
||||
@@ -1199,6 +1205,7 @@ namespace {
|
||||
objcMethod->isVariadic(),
|
||||
argPatterns,
|
||||
bodyPatterns,
|
||||
&hasSelectorStyleSignature,
|
||||
objcMethod->getSelector(),
|
||||
/*isConstructor=*/true);
|
||||
assert(type && "Type has already been successfully converted?");
|
||||
@@ -1216,6 +1223,7 @@ namespace {
|
||||
|
||||
VarDecl *selfVar = new (Impl.SwiftContext) VarDecl(SourceLoc(),
|
||||
selfName, selfTy, dc);
|
||||
selfVar->isImplicit();
|
||||
|
||||
// Create the actual constructor.
|
||||
auto result = new (Impl.SwiftContext) ConstructorDecl(name, loc,
|
||||
@@ -1229,6 +1237,9 @@ namespace {
|
||||
result->setIsObjC(true);
|
||||
result->setClangNode(objcMethod);
|
||||
|
||||
if (hasSelectorStyleSignature)
|
||||
result->setHasSelectorStyleSignature();
|
||||
|
||||
selfVar->setDeclContext(result);
|
||||
setVarDeclContexts(argPatterns, result);
|
||||
setVarDeclContexts(bodyPatterns, result);
|
||||
|
||||
@@ -598,8 +598,13 @@ Type ClangImporter::Implementation::importFunctionType(
|
||||
bool isVariadic,
|
||||
SmallVectorImpl<Pattern*> &argPatterns,
|
||||
SmallVectorImpl<Pattern*> &bodyPatterns,
|
||||
bool *pHasSelectorStyleSignature,
|
||||
clang::Selector selector,
|
||||
bool isConstructor) {
|
||||
|
||||
if (pHasSelectorStyleSignature)
|
||||
*pHasSelectorStyleSignature = false;
|
||||
|
||||
// Cannot import variadic types.
|
||||
if (isVariadic)
|
||||
return Type();
|
||||
@@ -672,11 +677,13 @@ Type ClangImporter::Implementation::importFunctionType(
|
||||
Pattern *argPattern = bodyPattern;
|
||||
if (bodyName != name) {
|
||||
if (name.empty()) {
|
||||
argPattern = new (SwiftContext) AnyPattern(SourceLoc());
|
||||
argPattern = new (SwiftContext) AnyPattern(SourceLoc(),
|
||||
/*Implicit=*/true);
|
||||
} else {
|
||||
auto argVar = new (SwiftContext) VarDecl(SourceLoc(), name,
|
||||
swiftParamTy,
|
||||
firstClangModule);
|
||||
argVar->setImplicit();
|
||||
argVar->setClangNode(param);
|
||||
argPattern = new (SwiftContext) NamedPattern(argVar);
|
||||
}
|
||||
@@ -684,11 +691,15 @@ Type ClangImporter::Implementation::importFunctionType(
|
||||
|
||||
argPattern
|
||||
= new (SwiftContext) TypedPattern(argPattern,
|
||||
TypeLoc::withoutLoc(swiftParamTy));
|
||||
TypeLoc::withoutLoc(swiftParamTy),
|
||||
/*Implicit=*/true);
|
||||
argPattern->setType(swiftParamTy);
|
||||
}
|
||||
argPatternElts.push_back(TuplePatternElt(argPattern));
|
||||
|
||||
if (argPattern != bodyPattern && pHasSelectorStyleSignature)
|
||||
*pHasSelectorStyleSignature = true;
|
||||
|
||||
// Add the tuple elements for the function types.
|
||||
swiftArgParams.push_back(TupleTypeElt(swiftParamTy, name));
|
||||
swiftBodyParams.push_back(TupleTypeElt(swiftParamTy, bodyName));
|
||||
@@ -730,7 +741,9 @@ Type ClangImporter::Implementation::importFunctionType(
|
||||
bodyPatternElts, SourceLoc()));
|
||||
bodyPatterns.back()->setType(bodyParamsTy);
|
||||
argPatterns.push_back(TuplePattern::create(SwiftContext, SourceLoc(),
|
||||
argPatternElts, SourceLoc()));
|
||||
argPatternElts, SourceLoc(),
|
||||
false, SourceLoc(),
|
||||
/*Implicit=*/true));
|
||||
argPatterns.back()->setType(argParamsTy);
|
||||
|
||||
// Form the function type.
|
||||
|
||||
@@ -384,6 +384,8 @@ public:
|
||||
/// \param isVariadic Whether the function is variadic.
|
||||
/// \param argPatterns The externally-visible patterns for the parameters.
|
||||
/// \param bodyPatterns The patterns visible inside the function body.
|
||||
/// \param pHasSelectorStyleSignature if non-null it accepts a boolean for
|
||||
/// whether the created arg/body patterns are different (selector-style).
|
||||
/// \param selector The Objective-C method selector to use for the names.
|
||||
/// \param isConstructor Whether we're building a function type for a
|
||||
/// constructor.
|
||||
@@ -395,6 +397,7 @@ public:
|
||||
bool isVariadic,
|
||||
SmallVectorImpl<Pattern*> &argPatterns,
|
||||
SmallVectorImpl<Pattern*> &bodyPatterns,
|
||||
bool *pHasSelectorStyleSignature = nullptr,
|
||||
clang::Selector selector = clang::Selector(),
|
||||
bool isConstructor = false);
|
||||
|
||||
|
||||
@@ -87,11 +87,13 @@ parseSelectorArgument(Parser &P,
|
||||
assert(ArgPatternRes.isNonNull() &&
|
||||
"selector argument did not start with an identifier!");
|
||||
Pattern *ArgPattern = ArgPatternRes.get();
|
||||
ArgPattern->setImplicit();
|
||||
|
||||
// Check that a selector name isn't used multiple times, which would
|
||||
// lead to the function type having multiple arguments with the same name.
|
||||
if (NamedPattern *name = dyn_cast<NamedPattern>(ArgPattern)) {
|
||||
VarDecl *decl = name->getDecl();
|
||||
decl->setImplicit();
|
||||
StringRef id = decl->getName().str();
|
||||
auto prevName = selectorNames.find(id);
|
||||
if (prevName != selectorNames.end()) {
|
||||
@@ -132,7 +134,8 @@ parseSelectorArgument(Parser &P,
|
||||
recoverFromBadSelectorArgument(P);
|
||||
}
|
||||
|
||||
ArgPattern = new (P.Context) TypedPattern(ArgPattern, type.get());
|
||||
ArgPattern = new (P.Context) TypedPattern(ArgPattern, type.get(),
|
||||
/*Implicit=*/true);
|
||||
BodyPattern = new (P.Context) TypedPattern(BodyPattern, type.get());
|
||||
if (Status.isError())
|
||||
return Status;
|
||||
@@ -176,9 +179,10 @@ static Pattern *getFirstSelectorPattern(ASTContext &Context,
|
||||
const Pattern *argPattern,
|
||||
SourceLoc loc)
|
||||
{
|
||||
Pattern *pattern = new (Context) AnyPattern(loc);
|
||||
Pattern *pattern = new (Context) AnyPattern(loc, /*Implicit=*/true);
|
||||
if (auto typed = dyn_cast<TypedPattern>(argPattern)) {
|
||||
pattern = new (Context) TypedPattern(pattern, typed->getTypeLoc());
|
||||
pattern = new (Context) TypedPattern(pattern, typed->getTypeLoc(),
|
||||
/*Implicit=*/true);
|
||||
}
|
||||
return pattern;
|
||||
}
|
||||
@@ -256,7 +260,8 @@ parseSelectorFunctionArguments(Parser &P,
|
||||
}
|
||||
|
||||
ArgPatterns.push_back(
|
||||
TuplePattern::create(P.Context, LParenLoc, ArgElts, RParenLoc));
|
||||
TuplePattern::create(P.Context, LParenLoc, ArgElts, RParenLoc,
|
||||
/*hasVarArg=*/false,SourceLoc(), /*Implicit=*/true));
|
||||
BodyPatterns.push_back(
|
||||
TuplePattern::create(P.Context, LParenLoc, BodyElts, RParenLoc));
|
||||
return Status;
|
||||
|
||||
Reference in New Issue
Block a user