aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-08-26 02:32:45 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-08-26 02:32:45 +0000
commit4d7da2f4a39adcc2ea211fb30600fabde4f3a0b1 (patch)
treefddd36e47c0ae4341469136aacd5ec8e6cb2bad3
parenta56f7460baf475151e03b1249a1343349328e39c (diff)
Synthesize property setter method as we do for getter.
- Also, fix Parser to construct proper SetterName selector (should be lifted out of parser though). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55352 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/DeclObjC.cpp52
-rw-r--r--lib/Parse/ParseObjc.cpp26
2 files changed, 60 insertions, 18 deletions
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 0d921e3c0e..ce56b94613 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -387,24 +387,48 @@ void ObjCInterfaceDecl::addPropertyMethods(
llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods) {
// Find the default getter and if one not found, add one.
ObjCMethodDecl *GetterDecl = getInstanceMethod(property->getGetterName());
- if (GetterDecl) {
- // An instance method with same name as property getter name found.
- property->setGetterMethodDecl(GetterDecl);
- }
- else {
+ if (!GetterDecl) {
// No instance method of same name as property getter name was found.
// Declare a getter method and add it to the list of methods
// for this class.
- QualType resultDeclType = property->getType();
- ObjCMethodDecl* ObjCMethod =
- ObjCMethodDecl::Create(Context, property->getLocation(),
- property->getLocation(),
- property->getGetterName(), resultDeclType,
- this,
- true, false, true, ObjCMethodDecl::Required);
- property->setGetterMethodDecl(ObjCMethod);
- insMethods.push_back(ObjCMethod);
+ GetterDecl =
+ ObjCMethodDecl::Create(Context, property->getLocation(),
+ property->getLocation(),
+ property->getGetterName(),
+ property->getType(),
+ this,
+ true, false, true, ObjCMethodDecl::Required);
+ insMethods.push_back(GetterDecl);
+ }
+ property->setGetterMethodDecl(GetterDecl);
+
+ // Find the default setter and if one not found, add one.
+ ObjCMethodDecl *SetterDecl = getInstanceMethod(property->getSetterName());
+ if (!SetterDecl) {
+ // No instance method of same name as property setter name was found.
+ // Declare a setter method and add it to the list of methods
+ // for this class.
+ SetterDecl =
+ ObjCMethodDecl::Create(Context, property->getLocation(),
+ property->getLocation(),
+ property->getSetterName(),
+ property->getType(),
+ this,
+ true, false, true, ObjCMethodDecl::Required);
+ insMethods.push_back(SetterDecl);
+
+ // Invent the arguments for the setter. We don't bother making a
+ // nice name for the argument.
+ ParmVarDecl *Argument = ParmVarDecl::Create(Context,
+ SetterDecl,
+ SourceLocation(),
+ property->getIdentifier(),
+ property->getType(),
+ VarDecl::None,
+ 0, 0);
+ SetterDecl->setMethodParams(&Argument, 1);
}
+ property->setSetterMethodDecl(SetterDecl);
}
/// addProperties - Insert property declaration AST nodes into
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 5758460412..a2f4eb2508 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -212,6 +212,23 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
return 0;
}
+/// constructSetterName - Return the setter name for the given
+/// identifier, i.e. "set" + Name where the initial character of Name
+/// has been capitalized.
+static IdentifierInfo *constructSetterName(IdentifierTable &Idents,
+ const IdentifierInfo *Name) {
+ unsigned N = Name->getLength();
+ char *SelectorName = new char[3 + N];
+ memcpy(SelectorName, "set", 3);
+ memcpy(&SelectorName[3], Name->getName(), N);
+ SelectorName[3] = toupper(SelectorName[3]);
+
+ IdentifierInfo *Setter =
+ &Idents.get(SelectorName, &SelectorName[3 + N]);
+ delete[] SelectorName;
+ return Setter;
+}
+
/// objc-interface-decl-list:
/// empty
/// objc-interface-decl-list objc-property-decl [OBJC2]
@@ -276,11 +293,12 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
PP.getSelectorTable().getNullarySelector(OCDS.getGetterName()
? OCDS.getGetterName()
: FD.D.getIdentifier());
+ IdentifierInfo *SetterName = OCDS.getSetterName();
+ if (!SetterName)
+ SetterName = constructSetterName(PP.getIdentifierTable(),
+ FD.D.getIdentifier());
Selector SetterSel =
- PP.getSelectorTable().getNullarySelector(OCDS.getSetterName()
- ? OCDS.getSetterName()
- // FIXME. This is not right!
- : FD.D.getIdentifier());
+ PP.getSelectorTable().getUnarySelector(SetterName);
DeclTy *Property = Actions.ActOnProperty(CurScope,
AtLoc, FD, OCDS,
GetterSel, SetterSel,