Objective-C Protocol patch

David T. McWherter dtm@waterw.com
Sun Jan 4 04:46:00 GMT 1998


I noted that gcc-2.7.2.1 fails to recognize protocol qualifiers
in class definitions in its objective-c compiler:
	@interface Foo
	-(oneway void)myMethod; /* oneway not accepted here */
	@end
	@implementation Foo
	-(oneway void) myMethod /* oneway accepted here */
	{
	}

And I traced the problem back to some code in objc-parse.y that 
is causing the parser to forget about the oneway (and friends) 
keywords, resulting in compiler errors in seemingly legitimate
code.  

Anwyays, I not that the egcs-971225 compiler operates identically to gcc
on this one, and so I've made a patch for objc-parse.y to fix this
problem, so that oneway and friends are accepted in both prototypes
and definitions of methods.  The patch is pretty trivial, so I'd
presume I don't need to fill out that copyright release form for
folks to use it, but let me know if I'm mistaken.  

Here's the patch:

------------------------------------------------------------
*** objc-parse.y.bak    Sun Jan  4 07:42:15 1998
--- objc-parse.y        Sun Jan  4 07:43:22 1998
***************
*** 2647,2666 ****
--- 2647,2674 ----
  methodproto:
          '+'
                {
+               /* DTM: We should remember protocol qualifiers in prototypes */
+                 remember_protocol_qualifiers ();
                  objc_inherit_code = CLASS_METHOD_DECL;
                }
          methoddecl
                {
+               /* DTM: We should forget protocol qualifiers here */
+                 forget_protocol_qualifiers ();
                  add_class_method (objc_interface_context, $3);
                }
          semi_or_error
  
        | '-'
                {
+               /* DTM: We should remember protocol qualifiers in prototypes */
+                 remember_protocol_qualifiers ();
                  objc_inherit_code = INSTANCE_METHOD_DECL;
                }
          methoddecl
                {
+               /* DTM: We should forget protocol qualifiers here */
+                 forget_protocol_qualifiers ();
                  add_instance_method (objc_interface_context, $3);
                }
          semi_or_error



More information about the Gcc mailing list