ObjC++ and MyObjCClass.class syntax

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

ObjC++ and MyObjCClass.class syntax

Jean-Daniel Dupas-2
Hello,

I would like to know if it is acceptable to add a special case in the parser to support the Foo.class syntax in ObjC++ (where Foo is an ObjC class).
This syntax already works in classic ObjC, and is supported by GCC in both ObjC and ObjC++. But actually, clang does not support it.

Thanks




-- Jean-Daniel





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Class.class.patch (553 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ObjC++ and MyObjCClass.class syntax

jahanian
Can you provide a test case. I see that in this case 'class' is  
supported as property name in objective-c mode (but not objective-c++).
g++ ObjC++  does not support it either.

@interface I
{
   int class;
}
@property int class;
@end

@implementation  I
- (int) Meth { I* Foo; return Foo.class; }
@end


% gcc -ObjC++ t.m
t.m:3: error: expected identifier before ';' token
t.m:5: error: expected identifier before ';' token
t.m: In function 'int -[I Meth](I*, objc_selector*)':
t.m:9: error: expected unqualified-id before 'class'
t.m:9: error: expected ';' before 'class'
- Fariborz


On Aug 11, 2010, at 9:40 AM, Jean-Daniel Dupas wrote:

> Hello,
>
> I would like to know if it is acceptable to add a special case in  
> the parser to support the Foo.class syntax in ObjC++ (where Foo is  
> an ObjC class).
> This syntax already works in classic ObjC, and is supported by GCC  
> in both ObjC and ObjC++. But actually, clang does not support it.
>
> Thanks
> <Class.class.patch>
>
>
> -- Jean-Daniel
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ObjC++ and MyObjCClass.class syntax

Jean-Daniel Dupas-2
You can't use class as a property name or as an ivar name in objc++

This extension is just to be able to write for example:

[obj isKindOfClass:NSString.class]

instead of

[obj isKindOfClass:[NSString class]]


As the +(Class)class method is defined on NSObject, this syntax may virtually be used by any ObjC class.

I know this syntax is "abusing" the new property syntax as it uses it to call a standard accessor method (not defined as a property), but this kind of "abuse" is supported for all other accessors name and g++ support it for 'class', so it may be worth supporting it too.

Here is a test case accepted by g++ but rejected by clang:
---------------------------------
@interface I {
 int cls;
}

+ (int)class;

@end

@implementation  I
- (int) Meth { return I.class; }
@end
---------------------------------

Le 11 août 2010 à 19:57, Fariborz Jahanian a écrit :

> Can you provide a test case. I see that in this case 'class' is supported as property name in objective-c mode (but not objective-c++).
> g++ ObjC++  does not support it either.
>
> @interface I
> {
>  int class;
> }
> @property int class;
> @end
>
> @implementation  I
> - (int) Meth { I* Foo; return Foo.class; }
> @end
>
>
> % gcc -ObjC++ t.m
> t.m:3: error: expected identifier before ';' token
> t.m:5: error: expected identifier before ';' token
> t.m: In function 'int -[I Meth](I*, objc_selector*)':
> t.m:9: error: expected unqualified-id before 'class'
> t.m:9: error: expected ';' before 'class'
> - Fariborz
>
>
> On Aug 11, 2010, at 9:40 AM, Jean-Daniel Dupas wrote:
>
>> Hello,
>>
>> I would like to know if it is acceptable to add a special case in the parser to support the Foo.class syntax in ObjC++ (where Foo is an ObjC class).
>> This syntax already works in classic ObjC, and is supported by GCC in both ObjC and ObjC++. But actually, clang does not support it.
>>
>> Thanks
>> <Class.class.patch>
>>
>>
>> -- Jean-Daniel
>>
>>
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>

-- Jean-Daniel





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ObjC++ and MyObjCClass.class syntax

jahanian

On Aug 11, 2010, at 11:11 AM, Jean-Daniel Dupas wrote:

> You can't use class as a property name or as an ivar name in objc++
>
> This extension is just to be able to write for example:
>
> [obj isKindOfClass:NSString.class]
>
> instead of
>
> [obj isKindOfClass:[NSString class]]
>
>
> As the +(Class)class method is defined on NSObject, this syntax may  
> virtually be used by any ObjC class.
>
> I know this syntax is "abusing" the new property syntax as it uses  
> it to call a standard accessor method (not defined as a property),  
> but this kind of "abuse" is supported for all other accessors name  
> and g++ support it for 'class', so it may be worth supporting it too.
>
> Here is a test case accepted by g++ but rejected by clang:
> ---------------------------------
> @interface I {
> int cls;
> }
>
> + (int)class;
>
> @end
>
> @implementation  I
> - (int) Meth { return I.class; }
> @end

I see. Yet g++ rejects a similar case when 'class' is instance method,  
or any other use of 'class' in an objective-c context.
  g++'s behavior is probably an accident of implementation. I am not  
sure if we need to follow this particular g++ behavior.

- Fariborz

>
> ---------------------------------
>
> Le 11 août 2010 à 19:57, Fariborz Jahanian a écrit :
>
>> Can you provide a test case. I see that in this case 'class' is  
>> supported as property name in objective-c mode (but not objective-c+
>> +).
>> g++ ObjC++  does not support it either.
>>
>> @interface I
>> {
>> int class;
>> }
>> @property int class;
>> @end
>>
>> @implementation  I
>> - (int) Meth { I* Foo; return Foo.class; }
>> @end
>>
>>
>> % gcc -ObjC++ t.m
>> t.m:3: error: expected identifier before ';' token
>> t.m:5: error: expected identifier before ';' token
>> t.m: In function 'int -[I Meth](I*, objc_selector*)':
>> t.m:9: error: expected unqualified-id before 'class'
>> t.m:9: error: expected ';' before 'class'
>> - Fariborz
>>
>>
>> On Aug 11, 2010, at 9:40 AM, Jean-Daniel Dupas wrote:
>>
>>> Hello,
>>>
>>> I would like to know if it is acceptable to add a special case in  
>>> the parser to support the Foo.class syntax in ObjC++ (where Foo is  
>>> an ObjC class).
>>> This syntax already works in classic ObjC, and is supported by GCC  
>>> in both ObjC and ObjC++. But actually, clang does not support it.
>>>
>>> Thanks
>>> <Class.class.patch>
>>>
>>>
>>> -- Jean-Daniel
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> [hidden email]
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>
> -- Jean-Daniel
>
>
>
>


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ObjC++ and MyObjCClass.class syntax

Blaine Garst
Since 'class' is a defined instance method, and [o class] is supported, o.class should be supported.  Dot syntax should work for all non-void returning no-argument methods.

Blaine

On Aug 11, 2010, at 11:26 AM, Fariborz Jahanian wrote:

>
> On Aug 11, 2010, at 11:11 AM, Jean-Daniel Dupas wrote:
>
>> You can't use class as a property name or as an ivar name in objc++
>>
>> This extension is just to be able to write for example:
>>
>> [obj isKindOfClass:NSString.class]
>>
>> instead of
>>
>> [obj isKindOfClass:[NSString class]]
>>
>>
>> As the +(Class)class method is defined on NSObject, this syntax may  
>> virtually be used by any ObjC class.
>>
>> I know this syntax is "abusing" the new property syntax as it uses  
>> it to call a standard accessor method (not defined as a property),  
>> but this kind of "abuse" is supported for all other accessors name  
>> and g++ support it for 'class', so it may be worth supporting it too.
>>
>> Here is a test case accepted by g++ but rejected by clang:
>> ---------------------------------
>> @interface I {
>> int cls;
>> }
>>
>> + (int)class;
>>
>> @end
>>
>> @implementation  I
>> - (int) Meth { return I.class; }
>> @end
>
> I see. Yet g++ rejects a similar case when 'class' is instance method,  
> or any other use of 'class' in an objective-c context.
>  g++'s behavior is probably an accident of implementation. I am not  
> sure if we need to follow this particular g++ behavior.
>
> - Fariborz
>
>>
>> ---------------------------------
>>
>> Le 11 août 2010 à 19:57, Fariborz Jahanian a écrit :
>>
>>> Can you provide a test case. I see that in this case 'class' is  
>>> supported as property name in objective-c mode (but not objective-c+
>>> +).
>>> g++ ObjC++  does not support it either.
>>>
>>> @interface I
>>> {
>>> int class;
>>> }
>>> @property int class;
>>> @end
>>>
>>> @implementation  I
>>> - (int) Meth { I* Foo; return Foo.class; }
>>> @end
>>>
>>>
>>> % gcc -ObjC++ t.m
>>> t.m:3: error: expected identifier before ';' token
>>> t.m:5: error: expected identifier before ';' token
>>> t.m: In function 'int -[I Meth](I*, objc_selector*)':
>>> t.m:9: error: expected unqualified-id before 'class'
>>> t.m:9: error: expected ';' before 'class'
>>> - Fariborz
>>>
>>>
>>> On Aug 11, 2010, at 9:40 AM, Jean-Daniel Dupas wrote:
>>>
>>>> Hello,
>>>>
>>>> I would like to know if it is acceptable to add a special case in  
>>>> the parser to support the Foo.class syntax in ObjC++ (where Foo is  
>>>> an ObjC class).
>>>> This syntax already works in classic ObjC, and is supported by GCC  
>>>> in both ObjC and ObjC++. But actually, clang does not support it.
>>>>
>>>> Thanks
>>>> <Class.class.patch>
>>>>
>>>>
>>>> -- Jean-Daniel
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> [hidden email]
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>
>> -- Jean-Daniel
>>
>>
>>
>>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ObjC++ and MyObjCClass.class syntax

Douglas Gregor
In reply to this post by Jean-Daniel Dupas-2

On Aug 11, 2010, at 11:11 AM, Jean-Daniel Dupas wrote:

> You can't use class as a property name or as an ivar name in objc++
>
> This extension is just to be able to write for example:
>
> [obj isKindOfClass:NSString.class]
>
> instead of
>
> [obj isKindOfClass:[NSString class]]
>
>
> As the +(Class)class method is defined on NSObject, this syntax may virtually be used by any ObjC class.
>
> I know this syntax is "abusing" the new property syntax as it uses it to call a standard accessor method (not defined as a property), but this kind of "abuse" is supported for all other accessors name and g++ support it for 'class', so it may be worth supporting it too.
>
> Here is a test case accepted by g++ but rejected by clang:
> ---------------------------------
> @interface I {
> int cls;
> }
>
> + (int)class;
>
> @end
>
> @implementation  I
> - (int) Meth { return I.class; }
> @end
> ---------------------------------


We decided not to support this idiom in Clang++. It's too horrible for words, and [NSString class] is a suitable formulation that will work.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ObjC++ and MyObjCClass.class syntax

Jean-Daniel Dupas-2

Le 11 août 2010 à 20:38, Douglas Gregor a écrit :

>
> On Aug 11, 2010, at 11:11 AM, Jean-Daniel Dupas wrote:
>
>> You can't use class as a property name or as an ivar name in objc++
>>
>> This extension is just to be able to write for example:
>>
>> [obj isKindOfClass:NSString.class]
>>
>> instead of
>>
>> [obj isKindOfClass:[NSString class]]
>>
>>
>> As the +(Class)class method is defined on NSObject, this syntax may virtually be used by any ObjC class.
>>
>> I know this syntax is "abusing" the new property syntax as it uses it to call a standard accessor method (not defined as a property), but this kind of "abuse" is supported for all other accessors name and g++ support it for 'class', so it may be worth supporting it too.
>>
>> Here is a test case accepted by g++ but rejected by clang:
>> ---------------------------------
>> @interface I {
>> int cls;
>> }
>>
>> + (int)class;
>>
>> @end
>>
>> @implementation  I
>> - (int) Meth { return I.class; }
>> @end
>> ---------------------------------
>
>
> We decided not to support this idiom in Clang++. It's too horrible for words, and [NSString class] is a suitable formulation that will work.

Thanks for the definite answer.


-- Jean-Daniel





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev