mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Start naming functions more uniformly.
For any function that has a name, ensure that the name is a compound name with argument names for each of the parameters. Swift SVN r16398
This commit is contained in:
@@ -149,8 +149,11 @@ getBuiltinFunction(Identifier Id,
|
||||
Context, SourceLoc(), ArgPatternElts, SourceLoc());
|
||||
Module *M = Context.TheBuiltinModule;
|
||||
|
||||
llvm::SmallVector<Identifier, 2> ArgNames(ArgPattern->numTopLevelVariables(),
|
||||
Identifier());
|
||||
DeclName Name(Context, Id, ArgNames);
|
||||
return FuncDecl::create(Context, SourceLoc(), StaticSpellingKind::None,
|
||||
SourceLoc(), Id, SourceLoc(),
|
||||
SourceLoc(), Name, SourceLoc(),
|
||||
/*GenericParams=*/nullptr, FnType, ArgPattern,
|
||||
ArgPattern, TypeLoc::withoutLoc(ResType),
|
||||
&M->getMainFile(FileUnitKind::Builtin));
|
||||
@@ -201,8 +204,11 @@ getBuiltinGenericFunction(Identifier Id,
|
||||
Pattern *ArgPattern = TuplePattern::createSimple(
|
||||
Context, SourceLoc(), ArgPatternElts, SourceLoc());
|
||||
Module *M = Context.TheBuiltinModule;
|
||||
llvm::SmallVector<Identifier, 2> ArgNames(ArgPattern->numTopLevelVariables(),
|
||||
Identifier());
|
||||
DeclName Name(Context, Id, ArgNames);
|
||||
auto func = FuncDecl::create(Context, SourceLoc(), StaticSpellingKind::None,
|
||||
SourceLoc(), Id,
|
||||
SourceLoc(), Name,
|
||||
SourceLoc(), GenericParams, FnType, ArgPattern,
|
||||
ArgPattern, TypeLoc::withoutLoc(ResBodyType),
|
||||
&M->getMainFile(FileUnitKind::Builtin));
|
||||
|
||||
@@ -2205,6 +2205,15 @@ void FuncDecl::setDeserializedSignature(ArrayRef<Pattern *> ArgParams,
|
||||
assert(ArgParams.size() == BodyParams.size());
|
||||
assert(NumParamPatterns == ArgParams.size());
|
||||
|
||||
#ifndef NDEBUG
|
||||
unsigned NumParams = getDeclContext()->isTypeContext()
|
||||
? BodyParams[1]->numTopLevelVariables()
|
||||
: BodyParams[0]->numTopLevelVariables();
|
||||
auto Name = getFullName();
|
||||
assert(!Name || !Name.isSimpleName() && "Must have a simple name");
|
||||
assert(!Name || (Name.getArgumentNames().size() == NumParams));
|
||||
#endif
|
||||
|
||||
for (unsigned i = 0; i != NumParamPatterns; ++i)
|
||||
ArgParamsRef[i] = ArgParams[i];
|
||||
for (unsigned i = 0; i != NumParamPatterns; ++i)
|
||||
|
||||
@@ -359,18 +359,7 @@ void Module::lookupValue(AccessPathTy AccessPath, DeclName Name,
|
||||
void BuiltinUnit::lookupValue(Module::AccessPathTy accessPath, DeclName name,
|
||||
NLKind lookupKind,
|
||||
SmallVectorImpl<ValueDecl*> &result) const {
|
||||
// There are currently no builtins with compound names.
|
||||
if (!name.isSimpleName())
|
||||
return;
|
||||
|
||||
getCache().lookupValue(name.getBaseName(), lookupKind, *this, result);
|
||||
|
||||
#ifndef NDEBUG
|
||||
for (auto r : result) {
|
||||
assert(r->getFullName().isSimpleName()
|
||||
&& "please make the builtin lookup cache handle compound name lookup");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
DerivedFileUnit::DerivedFileUnit(Module &M)
|
||||
|
||||
@@ -444,7 +444,7 @@ static FuncDecl *makeOptionSetFactoryMethod(StructDecl *optionSetDecl,
|
||||
break;
|
||||
}
|
||||
|
||||
DeclName name(C, baseName, C.Id_value);
|
||||
DeclName name(C, baseName, argName);
|
||||
auto factoryDecl = FuncDecl::create(C, SourceLoc(), StaticSpellingKind::None,
|
||||
SourceLoc(),
|
||||
name,
|
||||
@@ -1823,14 +1823,6 @@ namespace {
|
||||
return known->second;
|
||||
}
|
||||
|
||||
// If we're not splitting prepositions, the method-name-as-written
|
||||
// has an entry for the first parameter, but shouldn't.
|
||||
// FIXME: This is a hack to keep "x.foo:bar:wibble:" working.
|
||||
if (!Impl.SplitPrepositions && !name.getArgumentNames().empty()) {
|
||||
name = DeclName(Impl.SwiftContext, name.getBaseName(),
|
||||
name.getArgumentNames().slice(1));
|
||||
}
|
||||
|
||||
auto result = FuncDecl::create(
|
||||
Impl.SwiftContext, SourceLoc(), StaticSpellingKind::None,
|
||||
SourceLoc(), name, SourceLoc(), /*GenericParams=*/nullptr, Type(),
|
||||
|
||||
@@ -1076,6 +1076,13 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
|
||||
SmallVector<Identifier, 2> ArgumentNames;
|
||||
|
||||
Locs.push_back({NameLoc, consumeToken(tok::colon)});
|
||||
|
||||
// If we aren't splitting prepositions, add entry for the
|
||||
// unwritten first argument name.
|
||||
if (!Context.LangOpts.SplitPrepositions) {
|
||||
Locs.push_back({SourceLoc(), SourceLoc()});
|
||||
ArgumentNames.push_back(Identifier());
|
||||
}
|
||||
while ((Tok.is(tok::identifier) || Tok.is(tok::kw__)) &&
|
||||
peekToken().is(tok::colon)) {
|
||||
Identifier SelName;
|
||||
|
||||
@@ -397,8 +397,6 @@ parseSelectorArgument(Parser &P,
|
||||
assert(isa<AnyPattern>(ArgPattern) && "Unexpected selector pattern");
|
||||
}
|
||||
|
||||
namePieces.push_back(leadingIdent);
|
||||
|
||||
if (!P.Tok.is(tok::l_paren)) {
|
||||
P.diagnose(P.Tok, diag::func_selector_without_paren);
|
||||
return makeParserError();
|
||||
@@ -434,7 +432,7 @@ parseSelectorArgument(Parser &P,
|
||||
|
||||
bodyElts.push_back(TP->getFields()[0]);
|
||||
}
|
||||
|
||||
namePieces.push_back(leadingIdent);
|
||||
|
||||
TuplePatternElt &TPE = bodyElts.back();
|
||||
ArgPattern = rebuildImplicitPatternAround(TPE.getPattern(), ArgPattern,
|
||||
@@ -505,6 +503,7 @@ parseSelectorFunctionArguments(Parser &P,
|
||||
llvm_unreachable("unexpected function argument pattern!");
|
||||
|
||||
assert(!ArgElts.empty() && !BodyElts.empty());
|
||||
NamePieces.push_back(Identifier());
|
||||
|
||||
// Parse additional selectors as long as we can.
|
||||
ParserStatus Status;
|
||||
@@ -542,7 +541,8 @@ mapParsedParameters(Parser &parser,
|
||||
MutableArrayRef<Parser::ParsedParameter> params,
|
||||
SourceLoc rightParenLoc,
|
||||
Parser::DefaultArgumentInfo &defaultArgs,
|
||||
bool isFirstParameterClause) {
|
||||
bool isFirstParameterClause,
|
||||
SmallVectorImpl<Identifier> *argNames) {
|
||||
auto &ctx = parser.Context;
|
||||
|
||||
// Local function to create a pattern for a single parameter.
|
||||
@@ -634,6 +634,9 @@ mapParsedParameters(Parser &parser,
|
||||
auto defArgKind = getDefaultArgKind(param.DefaultArg);
|
||||
argElements.push_back(TuplePatternElt(arg, param.DefaultArg, defArgKind));
|
||||
bodyElements.push_back(TuplePatternElt(body, param.DefaultArg, defArgKind));
|
||||
|
||||
if (argNames)
|
||||
argNames->push_back(param.FirstName);
|
||||
}
|
||||
|
||||
return { TuplePattern::createSimple(ctx, leftParenLoc, argElements,
|
||||
@@ -688,17 +691,13 @@ Parser::parseFunctionArguments(SmallVectorImpl<Identifier> &NamePieces,
|
||||
// Turn the parameter clause into argument and body patterns.
|
||||
auto mapped = mapParsedParameters(*this, leftParenLoc, params,
|
||||
rightParenLoc, DefaultArgs,
|
||||
isFirstParameterClause);
|
||||
isFirstParameterClause,
|
||||
isFirstParameterClause ? &NamePieces
|
||||
: nullptr);
|
||||
ArgPatterns.push_back(mapped.first);
|
||||
BodyPatterns.push_back(mapped.second);
|
||||
|
||||
if (isFirstParameterClause) {
|
||||
for (const auto ¶m : params) {
|
||||
NamePieces.push_back(param.FirstName);
|
||||
}
|
||||
isFirstParameterClause = false;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -769,6 +768,7 @@ Parser::parseFunctionSignature(Identifier SimpleName,
|
||||
TuplePattern::create(Context, PreviousLoc, {}, PreviousLoc);
|
||||
argPatterns.push_back(EmptyTuplePattern);
|
||||
bodyPatterns.push_back(EmptyTuplePattern);
|
||||
FullName = DeclName(Context, SimpleName, { });
|
||||
}
|
||||
|
||||
// If there's a trailing arrow, parse the rest as the result type.
|
||||
@@ -817,7 +817,8 @@ Parser::parseConstructorArguments(Pattern *&ArgPattern, Pattern *&BodyPattern,
|
||||
std::tie(ArgPattern, BodyPattern)
|
||||
= mapParsedParameters(*this, leftParenLoc, params,
|
||||
rightParenLoc, DefaultArgs,
|
||||
/*isFirstParameterClause=*/true);
|
||||
/*isFirstParameterClause=*/true,
|
||||
/*FIXME:*/nullptr);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user