Skip to content

Commit bd2f48d

Browse files
committed
[NFC] AST: Introduce and use Identifier::isConstructor
1 parent 52615ea commit bd2f48d

15 files changed

+29
-30
lines changed

include/swift/AST/Identifier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ class DeclBaseName {
323323

324324
bool isSubscript() const { return getKind() == Kind::Subscript; }
325325

326+
bool isConstructor() const { return getKind() == Kind::Constructor; }
327+
326328
/// Return the identifier backing the name. Assumes that the name is not
327329
/// special.
328330
Identifier getIdentifier() const {

lib/AST/Decl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5690,7 +5690,7 @@ void NominalTypeDecl::synthesizeSemanticMembersIfNeeded(DeclName member) {
56905690
auto baseName = member.getBaseName();
56915691
auto &Context = getASTContext();
56925692
llvm::Optional<ImplicitMemberAction> action = llvm::None;
5693-
if (baseName == DeclBaseName::createConstructor())
5693+
if (baseName.isConstructor())
56945694
action.emplace(ImplicitMemberAction::ResolveImplicitInit);
56955695

56965696
if (member.isSimpleName() && !baseName.isSpecial()) {
@@ -5700,19 +5700,20 @@ void NominalTypeDecl::synthesizeSemanticMembersIfNeeded(DeclName member) {
57005700
} else {
57015701
auto argumentNames = member.getArgumentNames();
57025702
if (member.isSimpleName() || argumentNames.size() == 1) {
5703-
if (baseName == DeclBaseName::createConstructor()) {
5703+
if (baseName.isConstructor()) {
57045704
if ((member.isSimpleName() || argumentNames.front() == Context.Id_from)) {
57055705
action.emplace(ImplicitMemberAction::ResolveDecodable);
57065706
} else if (argumentNames.front() == Context.Id_system) {
57075707
action.emplace(ImplicitMemberAction::ResolveDistributedActorSystem);
57085708
}
57095709
} else if (!baseName.isSpecial() &&
5710-
baseName.getIdentifier() == Context.Id_encode &&
5711-
(member.isSimpleName() || argumentNames.front() == Context.Id_to)) {
5710+
baseName.getIdentifier() == Context.Id_encode &&
5711+
(member.isSimpleName() ||
5712+
argumentNames.front() == Context.Id_to)) {
57125713
action.emplace(ImplicitMemberAction::ResolveEncodable);
57135714
}
57145715
} else if (member.isSimpleName() || argumentNames.size() == 2) {
5715-
if (baseName == DeclBaseName::createConstructor()) {
5716+
if (baseName.isConstructor()) {
57165717
if (argumentNames[0] == Context.Id_resolve &&
57175718
argumentNames[1] == Context.Id_using) {
57185719
action.emplace(ImplicitMemberAction::ResolveDistributedActor);
@@ -10346,7 +10347,7 @@ ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
1034610347
Bits.ConstructorDecl.HasStubImplementation = 0;
1034710348
Bits.ConstructorDecl.Failable = Failable;
1034810349

10349-
assert(Name.getBaseName() == DeclBaseName::createConstructor());
10350+
assert(Name.getBaseName().isConstructor());
1035010351
}
1035110352

1035210353
ConstructorDecl *ConstructorDecl::createImported(

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ bool swift::removeOverriddenDecls(SmallVectorImpl<ValueDecl*> &decls) {
344344
// C.init overrides B.init overrides A.init, but only C.init and
345345
// A.init are in the chain. Make sure we still remove A.init from the
346346
// set in this case.
347-
if (decl->getBaseName() == DeclBaseName::createConstructor()) {
347+
if (decl->getBaseName().isConstructor()) {
348348
/// FIXME: Avoid the possibility of an infinite loop by fixing the root
349349
/// cause instead (incomplete circularity detection).
350350
assert(decl != overrides && "Circular class inheritance?");
@@ -2494,7 +2494,7 @@ QualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
24942494
// current class permits inheritance. Even then, only find complete
24952495
// object initializers.
24962496
bool visitSuperclass = true;
2497-
if (member.getBaseName() == DeclBaseName::createConstructor()) {
2497+
if (member.getBaseName().isConstructor()) {
24982498
if (classDecl->inheritsSuperclassInitializers())
24992499
onlyCompleteObjectInits = true;
25002500
else

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6267,7 +6267,7 @@ ClangImporter::Implementation::loadNamedMembers(
62676267
}
62686268
}
62696269

6270-
if (N == DeclBaseName::createConstructor()) {
6270+
if (N.isConstructor()) {
62716271
if (auto *classDecl = dyn_cast<ClassDecl>(D)) {
62726272
SmallVector<Decl *, 4> ctors;
62736273
importInheritedConstructors(cast<clang::ObjCInterfaceDecl>(CD),

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,7 @@ namespace {
11371137
}
11381138

11391139
bool isFactoryInit(ImportedName &name) {
1140-
return name &&
1141-
name.getDeclName().getBaseName() == DeclBaseName::createConstructor() &&
1140+
return name && name.getDeclName().getBaseName().isConstructor() &&
11421141
(name.getInitKind() == CtorInitializerKind::Factory ||
11431142
name.getInitKind() == CtorInitializerKind::ConvenienceFactory);
11441143
}
@@ -3503,7 +3502,7 @@ namespace {
35033502
isa<clang::CXXMethodDecl>(decl) && Impl.importSymbolicCXXDecls;
35043503
if (!dc->isModuleScopeContext() && !isa<clang::CXXMethodDecl>(decl)) {
35053504
// Handle initializers.
3506-
if (name.getBaseName() == DeclBaseName::createConstructor()) {
3505+
if (name.getBaseName().isConstructor()) {
35073506
assert(!accessorInfo);
35083507
return importGlobalAsInitializer(decl, name, dc,
35093508
importedName.getInitKind(),

lib/Parse/ParsePattern.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,11 @@ Parser::parseFunctionSignature(DeclBaseName SimpleName,
798798
SmallVector<Identifier, 4> NamePieces;
799799
ParserStatus Status;
800800

801-
ParameterContextKind paramContext = SimpleName.isOperator()
802-
? ParameterContextKind::Operator
803-
: (SimpleName == DeclBaseName::createConstructor()
804-
? ParameterContextKind::Initializer
805-
: ParameterContextKind::Function);
801+
ParameterContextKind paramContext =
802+
SimpleName.isOperator()
803+
? ParameterContextKind::Operator
804+
: (SimpleName.isConstructor() ? ParameterContextKind::Initializer
805+
: ParameterContextKind::Function);
806806
Status |= parseFunctionArguments(NamePieces, bodyParams, paramContext,
807807
defaultArgs);
808808
FullName = DeclName(Context, SimpleName, NamePieces);

lib/SILGen/SILGenLValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ static bool isReadNoneFunction(const Expr *e) {
12191219
if (auto *dre = dyn_cast<DeclRefExpr>(e)) {
12201220
const DeclName name = dre->getDecl()->getName();
12211221
return (name.getArgumentNames().size() == 1 &&
1222-
name.getBaseName() == DeclBaseName::createConstructor() &&
1222+
name.getBaseName().isConstructor() &&
12231223
!name.getArgumentNames()[0].empty() &&
12241224
(name.getArgumentNames()[0].str() == "integerLiteral" ||
12251225
name.getArgumentNames()[0].str() == "_builtinIntegerLiteral"));

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4325,7 +4325,7 @@ bool MissingMemberFailure::diagnoseAsError() {
43254325
correction->addFixits(diagnostic);
43264326
} else if ((instanceTy->getAnyNominal() ||
43274327
instanceTy->is<ExistentialType>()) &&
4328-
getName().getBaseName() == DeclBaseName::createConstructor()) {
4328+
getName().getBaseName().isConstructor()) {
43294329
auto &cs = getConstraintSystem();
43304330

43314331
auto result = cs.performMemberLookup(

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10094,8 +10094,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
1009410094
// the same name, so you could write "foo.init" to look up a
1009510095
// method or property named `init`.
1009610096
if (!ctx.isSwiftVersionAtLeast(5) &&
10097-
memberName.getBaseName() == DeclBaseName::createConstructor() &&
10098-
!isImplicitInit) {
10097+
memberName.getBaseName().isConstructor() && !isImplicitInit) {
1009910098
auto &compatLookup = lookupMember(instanceTy,
1010010099
DeclNameRef(ctx.getIdentifier("init")),
1010110100
memberLoc);

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,7 @@ ValueDecl *DerivedConformance::deriveDecodable(ValueDecl *requirement) {
21422142
!isa<EnumDecl>(Nominal))
21432143
return nullptr;
21442144

2145-
if (requirement->getBaseName() != DeclBaseName::createConstructor()) {
2145+
if (!requirement->getBaseName().isConstructor()) {
21462146
// Unknown requirement.
21472147
requirement->diagnose(diag::broken_decodable_requirement);
21482148
return nullptr;

0 commit comments

Comments
 (0)