Commit f2e6e530 by Ziemowit Laski Committed by Stan Shebs

c-parse.in (OBJC_NEED_RAW_IDENTIFIER): Define macro and flag for contextualizing…

c-parse.in (OBJC_NEED_RAW_IDENTIFIER): Define macro and flag for contextualizing Objective-C class name lookup by the...

2001-08-01  Ziemowit Laski  <zlaski@apple.com>

        * c-parse.in (OBJC_NEED_RAW_IDENTIFIER): Define macro and flag for
	contextualizing Objective-C class name lookup by the lexer.
	(typespec_reserved_nonattr): Disable ObjC class name lookup after
	seeing a TYPESPEC.
	(protocoldef): Add support for forward @protocol declarations.
	(yylexname): Suppress ObjC class name lookup in certain contexts;
	re-enable after lookup is complete.
	(_yylex): Re-enable ObjC class name lookup when certain
	punctuation marks are seen.

	* objc/objc-act.c (check_protocol_recursively): New function used
	for finding circular dependencies in protocols.
	(objc_declare_protocols): New function for handling forward
	@protocol declarations.
	(receiver_is_class_object): Detect the case when 'self' is used
	inside of a class method.
	(build_message_expr): Issue a warning if class method is desired
	but instance method is found instead.
	(conforms_to_protocol): Streamline.
	(objc_comptypes): Detect the fact that 'Bar<Foo> foo' conforms to
	protocol Foo, even if 'Bar foo' does not.
	(check_protocols): Streamline.
	(start_protocol): Add checks for circular and duplicate protocol
	definitions.
	(encode_aggregate_within): For typedefs of structs, encode the
	underlying struct.
	* objc/objc-act.h (PROTOCOL_DEFINED): New tree accessor.
	(objc_declare_protocols): New prototype.

From-SVN: r44536
parent 80858e66
2001-08-01 Ziemowit Laski <zlaski@apple.com>
* c-parse.in (OBJC_NEED_RAW_IDENTIFIER): Define macro and flag for
contextualizing Objective-C class name lookup by the lexer.
(typespec_reserved_nonattr): Disable ObjC class name lookup after
seeing a TYPESPEC.
(protocoldef): Add support for forward @protocol declarations.
(yylexname): Suppress ObjC class name lookup in certain contexts;
re-enable after lookup is complete.
(_yylex): Re-enable ObjC class name lookup when certain
punctuation marks are seen.
* objc/objc-act.c (check_protocol_recursively): New function used
for finding circular dependencies in protocols.
(objc_declare_protocols): New function for handling forward
@protocol declarations.
(receiver_is_class_object): Detect the case when 'self' is used
inside of a class method.
(build_message_expr): Issue a warning if class method is desired
but instance method is found instead.
(conforms_to_protocol): Streamline.
(objc_comptypes): Detect the fact that 'Bar<Foo> foo' conforms to
protocol Foo, even if 'Bar foo' does not.
(check_protocols): Streamline.
(start_protocol): Add checks for circular and duplicate protocol
definitions.
(encode_aggregate_within): For typedefs of structs, encode the
underlying struct.
* objc/objc-act.h (PROTOCOL_DEFINED): New tree accessor.
(objc_declare_protocols): New prototype.
2001-08-01 Neil Booth <neil@cat.daikokuya.demon.co.uk>
* cpphash.h (struct cpp_reader): New members line, pseudo_newlines.
......
......@@ -29,10 +29,10 @@ Boston, MA 02111-1307, USA. */
written by AT&T, but I have never seen it. */
ifobjc
%expect 31
%expect 31 /* shift/reduce conflicts, and 1 reduce/reduce conflict. */
end ifobjc
ifc
%expect 10
%expect 10 /* shift/reduce conflicts, and no reduce/reduce conflicts. */
end ifc
%{
......@@ -295,8 +295,18 @@ int objc_receiver_context;
int objc_public_flag;
int objc_pq_context;
/* The following flag is needed to contextualize ObjC lexical analysis.
In some cases (e.g., 'int NSObject;'), it is undesirable to bind
an identifier to an ObjC class, even if a class with that name
exists. */
int objc_need_raw_identifier;
#define OBJC_NEED_RAW_IDENTIFIER(VAL) objc_need_raw_identifier = VAL
end ifobjc
ifc
#define OBJC_NEED_RAW_IDENTIFIER(VAL) /* nothing */
end ifc
/* Tell yyparse how to print a token's value, if yydebug is set. */
#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
......@@ -444,7 +454,7 @@ identifier:
| TYPENAME
ifobjc
| OBJECTNAME
| CLASSNAME
| CLASSNAME
end ifobjc
;
......@@ -1384,6 +1394,7 @@ typespec_attr:
typespec_reserved_nonattr:
TYPESPEC
{ OBJC_NEED_RAW_IDENTIFIER (1); }
| structsp_nonattr
;
......@@ -1694,6 +1705,9 @@ parm_declarator_starttypename:
| parm_declarator_starttypename array_declarator %prec '.'
{ $$ = set_array_declarator_type ($2, $1, 0); }
| TYPENAME
ifobjc
| OBJECTNAME
end ifobjc
;
parm_declarator_nostarttypename:
......@@ -2836,6 +2850,13 @@ protocoldef:
finish_protocol(objc_interface_context);
objc_interface_context = NULL_TREE;
}
/* The @protocol forward-declaration production introduces a
reduce/reduce conflict on ';', which should be resolved in
favor of the production 'identifier_list -> identifier'. */
| PROTOCOL identifier_list ';'
{
objc_declare_protocols ($2);
}
;
protocolrefs:
......@@ -3119,8 +3140,9 @@ keywordselector:
selector:
IDENTIFIER
| TYPENAME
| OBJECTNAME
| TYPENAME
| CLASSNAME
| OBJECTNAME
| reservedwords
;
......@@ -3615,12 +3637,26 @@ static int
yylexname ()
{
tree decl;
ifobjc
int objc_force_identifier = objc_need_raw_identifier;
OBJC_NEED_RAW_IDENTIFIER (0);
end ifobjc
if (C_IS_RESERVED_WORD (yylval.ttype))
{
enum rid rid_code = C_RID_CODE (yylval.ttype);
ifobjc
/* Turn non-typedefed refs to "id" into plain identifiers; this
allows constructs like "void foo(id id);" to work. */
if (rid_code == RID_ID)
{
decl = lookup_name (yylval.ttype);
if (decl == NULL_TREE || TREE_CODE (decl) != TYPE_DECL)
return IDENTIFIER;
}
if (!OBJC_IS_AT_KEYWORD (rid_code)
&& (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
end ifobjc
......@@ -3653,8 +3689,11 @@ ifobjc
else
{
tree objc_interface_decl = is_class_name (yylval.ttype);
if (objc_interface_decl)
/* ObjC class names are in the same namespace as variables and
typedefs, and hence are shadowed by local declarations. */
if (objc_interface_decl
&& (global_bindings_p ()
|| (!objc_force_identifier && !decl)))
{
yylval.ttype = objc_interface_decl;
return CLASSNAME;
......@@ -3692,10 +3731,7 @@ _yylex ()
case CPP_AND_AND: return ANDAND;
case CPP_OR_OR: return OROR;
case CPP_QUERY: return '?';
case CPP_COLON: return ':';
case CPP_COMMA: return ',';
case CPP_OPEN_PAREN: return '(';
case CPP_CLOSE_PAREN: return ')';
case CPP_EQ_EQ: yylval.code = EQ_EXPR; return EQCOMPARE;
case CPP_NOT_EQ: yylval.code = NE_EXPR; return EQCOMPARE;
case CPP_GREATER_EQ:yylval.code = GE_EXPR; return ARITHCOMPARE;
......@@ -3716,7 +3752,6 @@ _yylex ()
case CPP_CLOSE_SQUARE: return ']';
case CPP_OPEN_BRACE: return '{';
case CPP_CLOSE_BRACE: return '}';
case CPP_SEMICOLON: return ';';
case CPP_ELLIPSIS: return ELLIPSIS;
case CPP_PLUS_PLUS: return PLUSPLUS;
......@@ -3724,6 +3759,13 @@ _yylex ()
case CPP_DEREF: return POINTSAT;
case CPP_DOT: return '.';
/* The following tokens may affect the interpretation of any
identifiers following, if doing Objective-C. */
case CPP_COLON: OBJC_NEED_RAW_IDENTIFIER (0); return ':';
case CPP_COMMA: OBJC_NEED_RAW_IDENTIFIER (0); return ',';
case CPP_CLOSE_PAREN: OBJC_NEED_RAW_IDENTIFIER (0); return ')';
case CPP_SEMICOLON: OBJC_NEED_RAW_IDENTIFIER (0); return ';';
case CPP_EOF:
if (cpp_pop_buffer (parse_in) == 0)
return 0;
......@@ -3741,8 +3783,8 @@ _yylex ()
case CPP_WSTRING:
return STRING;
/* This token is Objective-C specific. It gives the next
token special significance. */
/* This token is Objective-C specific. It gives the next token
special significance. */
case CPP_ATSIGN:
ifobjc
{
......
/* Declarations for objc-act.c.
Copyright (C) 1990, 2000 Free Software Foundation, Inc.
Copyright (C) 1990, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU CC.
......@@ -59,6 +59,7 @@ extern tree objc_ellipsis_node;
void objc_declare_alias PARAMS ((tree, tree));
void objc_declare_class PARAMS ((tree));
void objc_declare_protocols PARAMS ((tree));
extern int objc_receiver_context;
......@@ -101,6 +102,7 @@ tree build_encode_expr PARAMS ((tree));
#define PROTOCOL_NST_METHODS(CLASS) ((CLASS)->type.minval)
#define PROTOCOL_CLS_METHODS(CLASS) ((CLASS)->type.maxval)
#define PROTOCOL_FORWARD_DECL(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 1)
#define PROTOCOL_DEFINED(CLASS) TREE_USED (CLASS)
#define TYPE_PROTOCOL_LIST(TYPE) ((TYPE)->type.context)
/* Define the Objective-C or Objective-C++ language-specific tree codes. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment