[cfe-commits] r62028 - in /cfe/trunk: lib/AST/DeclObjC.cpp test/SemaObjC/property-user-setter.m

Daniel Dunbar daniel at zuster.org
Sat Jan 10 12:03:43 PST 2009


Sure; my question is, can we safely implement isPropertyReadonly this way?

 - Daniel

On Sat, Jan 10, 2009 at 11:54 AM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>
> On Jan 10, 2009, at 11:40 AM, Daniel Dunbar wrote:
>
>> What I meant was, this is essentially looking for a method which
>> matches PDecl->getSetterName(). Could we just implement this function
>> as:
>> --
>> bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const
>> {
>>  return lookupMethod(PDecl->getSetterName()) != NULL;
>> }
>> --
>> Then we only have to worry about making lookupMethod fast. Similarly,
>> I think there are other checks we do on properties that could be
>> implemented in this fashion.
>>
>> Did that make more sense?
>
> I see what you say now. But the low level routine to speed up is lookup(sel)
> which is called in several
> places, including by getInstanceMethod.  lookup(sel) is what you really want
> to speed up.
>
> - Fariborz
>
>>
>>
>> - Daniel
>>
>> On Sat, Jan 10, 2009 at 11:27 AM, Fariborz Jahanian <fjahanian at apple.com>
>> wrote:
>>>
>>> I am not sure what you mean. This is how we look up any instance methods
>>> in
>>> general.
>>> I don't know what you mean by majority of semantic checks. Majority of
>>> semantics
>>> check for property assignment syntax is than by the caller. Are you
>>> saying
>>> to move all that in
>>> one function and call that? If so, I will add a FIXME syntax. But I don't
>>> think it is necessary.
>>>
>>> - Fariborz
>>>
>>>
>>> On Jan 10, 2009, at 11:13 AM, Daniel Dunbar wrote:
>>>
>>>> Hi Fariborz,
>>>>
>>>> Could we simply implement this check in terms of a more general
>>>> function by doing a lookup to see if the setter method is defined? My
>>>> thought is that if we can implement the majority of semantic checks in
>>>> terms of that function, then there will only be one thing we need to
>>>> focus on making efficient.
>>>>
>>>> - Daniel
>>>>
>>>> On Sat, Jan 10, 2009 at 10:43 AM, Fariborz Jahanian
>>>> <fjahanian at apple.com>
>>>> wrote:
>>>>>
>>>>> Author: fjahanian
>>>>> Date: Sat Jan 10 12:43:55 2009
>>>>> New Revision: 62028
>>>>>
>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=62028&view=rev
>>>>> Log:
>>>>> Explicit declaration of property setters over-ride
>>>>> prohibition of 'readonly' properties in an assignment.
>>>>>
>>>>> Added:
>>>>> cfe/trunk/test/SemaObjC/property-user-setter.m
>>>>> Modified:
>>>>> cfe/trunk/lib/AST/DeclObjC.cpp
>>>>>
>>>>> Modified: cfe/trunk/lib/AST/DeclObjC.cpp
>>>>> URL:
>>>>>
>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=62028&r1=62027&r2=62028&view=diff
>>>>>
>>>>>
>>>>>
>>>>> ==============================================================================
>>>>> --- cfe/trunk/lib/AST/DeclObjC.cpp (original)
>>>>> +++ cfe/trunk/lib/AST/DeclObjC.cpp Sat Jan 10 12:43:55 2009
>>>>> @@ -257,7 +257,9 @@
>>>>> ///
>>>>> bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl)
>>>>> const
>>>>> {
>>>>> -  if (!PDecl->isReadOnly())
>>>>> +  // Even if property is ready only, if interface has a user defined
>>>>> setter,
>>>>> +  // it is not considered read only.
>>>>> +  if (!PDecl->isReadOnly() ||
>>>>> getInstanceMethod(PDecl->getSetterName()))
>>>>>  return false;
>>>>>
>>>>> // Main class has the property as 'readonly'. Must search
>>>>> @@ -265,6 +267,10 @@
>>>>> // attribute has been over-ridden to 'readwrite'.
>>>>> for (ObjCCategoryDecl *Category = getCategoryList();
>>>>>    Category; Category = Category->getNextClassCategory()) {
>>>>> +    // Even if property is ready only, if a category has a user
>>>>> defined
>>>>> setter,
>>>>> +    // it is not considered read only.
>>>>> +    if (Category->getInstanceMethod(PDecl->getSetterName()))
>>>>> +      return false;
>>>>>  ObjCPropertyDecl *P =
>>>>>   Category->FindPropertyDeclaration(PDecl->getIdentifier());
>>>>>  if (P && !P->isReadOnly())
>>>>>
>>>>> Added: cfe/trunk/test/SemaObjC/property-user-setter.m
>>>>> URL:
>>>>>
>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-user-setter.m?rev=62028&view=auto
>>>>>
>>>>>
>>>>>
>>>>> ==============================================================================
>>>>> --- cfe/trunk/test/SemaObjC/property-user-setter.m (added)
>>>>> +++ cfe/trunk/test/SemaObjC/property-user-setter.m Sat Jan 10 12:43:55
>>>>> 2009
>>>>> @@ -0,0 +1,25 @@
>>>>> +// RUN: clang -fsyntax-only -verify %s
>>>>> +
>>>>> + at interface I0
>>>>> + at property(readonly) int x;
>>>>> + at property(readonly) int y;
>>>>> + at property(readonly) int z;
>>>>> +-(void) setY: (int) y0;
>>>>> + at end
>>>>> +
>>>>> + at interface I0 (Cat0)
>>>>> +-(void) setX: (int) a0;
>>>>> + at end
>>>>> +
>>>>> + at implementation I0
>>>>> + at dynamic x;
>>>>> + at dynamic y;
>>>>> + at dynamic z;
>>>>> +-(void) setY: (int) y0{}
>>>>> +
>>>>> +-(void) im0 {
>>>>> +  self.x = 0;
>>>>> +  self.y = 2;
>>>>> +  self.z = 2; // expected-error {{assigning to property with
>>>>> 'readonly'
>>>>> attribute not allowed}}
>>>>> +}
>>>>> + at end
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> cfe-commits mailing list
>>>>> cfe-commits at cs.uiuc.edu
>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>>>
>>>
>>>
>
>



More information about the cfe-commits mailing list