diff --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h index d4d53390bdb3..b9c9ce77998f 100644 --- a/clang/include/clang/Basic/IdentifierTable.h +++ b/clang/include/clang/Basic/IdentifierTable.h @@ -19,6 +19,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/TokenKinds.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/PointerLikeTypeTraits.h" @@ -725,13 +726,19 @@ public: /// \brief Return the total amount of memory allocated for managing selectors. size_t getTotalMemory() const; - /// \brief Return the setter name for the given identifier. + /// \brief Return the default setter name for the given identifier. /// /// This is "set" + \p Name where the initial character of \p Name /// has been capitalized. - static Selector constructSetterName(IdentifierTable &Idents, - SelectorTable &SelTable, - const IdentifierInfo *Name); + static SmallString<100> constructSetterName(StringRef Name); + + /// \brief Return the default setter selector for the given identifier. + /// + /// This is "set" + \p Name where the initial character of \p Name + /// has been capitalized. + static Selector constructSetterSelector(IdentifierTable &Idents, + SelectorTable &SelTable, + const IdentifierInfo *Name); }; /// DeclarationNameExtra - Common base of the MultiKeywordSelector, diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 951c718d183a..dc24f9aecfef 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -13,11 +13,10 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/IdentifierTable.h" -#include "clang/Basic/CharInfo.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/CharInfo.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" -#include "llvm/ADT/SmallString.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include @@ -464,15 +463,20 @@ static SelectorTableImpl &getSelectorTableImpl(void *P) { return *static_cast(P); } -/*static*/ Selector -SelectorTable::constructSetterName(IdentifierTable &Idents, - SelectorTable &SelTable, - const IdentifierInfo *Name) { - SmallString<100> SelectorName; - SelectorName = "set"; - SelectorName += Name->getName(); +/*static*/ SmallString<100> +SelectorTable::constructSetterName(StringRef Name) { + SmallString<100> SelectorName("set"); + SelectorName += Name; SelectorName[3] = toUppercase(SelectorName[3]); - IdentifierInfo *SetterName = &Idents.get(SelectorName); + return SelectorName; +} + +/*static*/ Selector +SelectorTable::constructSetterSelector(IdentifierTable &Idents, + SelectorTable &SelTable, + const IdentifierInfo *Name) { + IdentifierInfo *SetterName = + &Idents.get(constructSetterName(Name->getName())); return SelTable.getUnarySelector(SetterName); } diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index d0dcc5305370..beb62362e75f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1472,12 +1472,7 @@ static bool hasDefaultSetterName(const ObjCPropertyDecl *PD, return true; assert(Setter->getDeclName().isObjCOneArgSelector()); - // Construct a setter name like SelectorTable::constructSetterName() - // does, but without entering it into the table. - SmallString<100> DefaultName("set"); - DefaultName += PD->getName(); - DefaultName[3] = toUppercase(DefaultName[3]); - return DefaultName == + return SelectorTable::constructSetterName(PD->getName()) == Setter->getDeclName().getObjCSelector().getNameForSlot(0); } diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 607b953aad41..1e10a8206f16 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -348,9 +348,10 @@ public: if (SetterName) SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); else - SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), - P.PP.getSelectorTable(), - FD.D.getIdentifier()); + SetterSel = + SelectorTable::constructSetterSelector(P.PP.getIdentifierTable(), + P.PP.getSelectorTable(), + FD.D.getIdentifier()); bool isOverridingProperty = false; Decl *Property = P.Actions.ActOnProperty(P.getCurScope(), AtLoc, LParenLoc, diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 6a31a362f055..73ca265fb2dd 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -1362,8 +1362,9 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr, if (DiagnoseUseOfDecl(OMD, MemberLoc)) return ExprError(); Selector SetterSel = - SelectorTable::constructSetterName(PP.getIdentifierTable(), - PP.getSelectorTable(), Member); + SelectorTable::constructSetterSelector(PP.getIdentifierTable(), + PP.getSelectorTable(), + Member); ObjCMethodDecl *SMD = 0; if (Decl *SDecl = FindGetterSetterNameDecl(OPT, /*Property id*/0, SetterSel, Context)) @@ -1410,8 +1411,9 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr, // If we found a getter then this may be a valid dot-reference, we // will look for the matching setter, in case it is needed. Selector SetterSel = - SelectorTable::constructSetterName(PP.getIdentifierTable(), - PP.getSelectorTable(), Member); + SelectorTable::constructSetterSelector(PP.getIdentifierTable(), + PP.getSelectorTable(), + Member); ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel); if (!Setter) { // If this reference is in an @implementation, also check for 'private' diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 3b84acece278..b21f8e70f5de 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -1552,8 +1552,8 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, // If we found a getter then this may be a valid dot-reference, we // will look for the matching setter, in case it is needed. Selector SetterSel = - SelectorTable::constructSetterName(PP.getIdentifierTable(), - PP.getSelectorTable(), Member); + SelectorTable::constructSetterSelector(PP.getIdentifierTable(), + PP.getSelectorTable(), Member); ObjCMethodDecl *Setter = IFace->lookupInstanceMethod(SetterSel); // May be founf in property's qualified list. @@ -1699,8 +1699,9 @@ ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, // Look for the matching setter, in case it is needed. Selector SetterSel = - SelectorTable::constructSetterName(PP.getIdentifierTable(), - PP.getSelectorTable(), &propertyName); + SelectorTable::constructSetterSelector(PP.getIdentifierTable(), + PP.getSelectorTable(), + &propertyName); ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel); if (!Setter) { diff --git a/clang/lib/Sema/SemaPseudoObject.cpp b/clang/lib/Sema/SemaPseudoObject.cpp index fe11b3706887..a10612a8b07b 100644 --- a/clang/lib/Sema/SemaPseudoObject.cpp +++ b/clang/lib/Sema/SemaPseudoObject.cpp @@ -575,9 +575,9 @@ bool ObjCPropertyOpBuilder::findSetter(bool warn) { RefExpr->getImplicitPropertyGetter()->getSelector() .getIdentifierInfoForSlot(0); SetterSelector = - SelectorTable::constructSetterName(S.PP.getIdentifierTable(), - S.PP.getSelectorTable(), - getterName); + SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(), + S.PP.getSelectorTable(), + getterName); return false; } }