This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[ObjC PATCH] Clean-up TREE_OVERFLOW abuse in objc
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 18 Apr 2005 14:13:42 -0600 (MDT)
- Subject: [ObjC PATCH] Clean-up TREE_OVERFLOW abuse in objc
The following patch removes an abuse of the TREE_OVERFLOW macro
by the objective C front-end. Throughout most (but not all) of
the compiler, the macro TREE_OVERFLOW is only used and defined
for constant class tree nodes, such as INTEGER_CST, REAL_CST,
etc.. Unfortunately, the misuse of this macro elsewhere currently
prevents us from using a enable-checking test to it to confirm
that it's only being used where appropriate.
It turns out that the objective C front-end has hijacked the
use of TREE_OVERFLOW for recording on TREE_LIST nodes whether an
argument list was terminated by ellipsis (i.e. "...") or not.
The patch below cleans this up, by storing this Boolean flag
not on the tree_list itself, but the METHOD_DECL node that
wraps it. Then instead of using TREE_OVERFLOW, a new macro
METHOD_ADD_ARGS_ELLIPSIS_P is defined to access this datum
which is now stored in the decl's lang_flag_0. The METHOD_DECL
tree codes are local to the objective C front-end, hence there's
no possible conflict with using a language specific bit on a
front-end specific tree-code (i.e. this shouldn't interfere
with Objective C++).
The following patch has been tested on i686-pc-linux-gnu with a
full "make bootstrap", all default languages, and regression tested
with a top-level "make -k check" with no new failures. This patch
is part of an effort to unify TREE_OVERFLOW and TREE_CONSTANT_OVERFLOW,
which in turn is in an effort to eliminate TREE_CONSTANT_OVERFLOW,
which is part of a clean-up of the C front-end's diagnostics, which
is required by an otherwise simple fold-const.c clean-up.
Ok for mainline? These changes touch both the C and ObjC front-ends,
so global approval is probably required once the objc folks are happy.
2005-04-18 Roger Sayle <roger@eyesopen.com>
* c-common.h (objc_build_method_signature): Update prototype.
* stub-objc.c (objc_build_method_signature): Update the stub
implementation to accept and ignore additional parameter.
* c-parser.c (c_parser_objc_method_decl): Reorgnize to pass
the value of ellipsis to objc_build_method_signature instead
of setting TREE_OVERFLOW on the parms TREE_LIST node.
* objc-act.h (METHOD_ADD_ARGS_ELLIPSIS_P): New macro for accessing
this field of an objc method decl.
* objc-act.c (build_method_decl): Take an additional "ellipsis"
argument, and set METHOD_ADD_ARGS_ELLIPSIS_P as appropriate.
(objc_build_method_signature): Accept additional "ellipsis"
argument and pass it to build_method_decl.
(get_arg_type_list, start_method_def, gen_method_decl): Use
the new METHOD_ADD_ARGS_ELLIPSIS_P instead of examining the
TREE_OVERFLOW field of a TREE_LIST node.
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.284
diff -c -3 -p -r1.284 c-common.h
*** c-common.h 14 Apr 2005 23:37:33 -0000 1.284
--- c-common.h 18 Apr 2005 03:22:47 -0000
*************** extern void objc_continue_implementation
*** 920,926 ****
extern void objc_finish_implementation (void);
extern void objc_set_visibility (int);
extern void objc_set_method_type (enum tree_code);
! extern tree objc_build_method_signature (tree, tree, tree);
extern void objc_add_method_declaration (tree);
extern void objc_start_method_definition (tree);
extern void objc_finish_method_definition (tree);
--- 920,926 ----
extern void objc_finish_implementation (void);
extern void objc_set_visibility (int);
extern void objc_set_method_type (enum tree_code);
! extern tree objc_build_method_signature (tree, tree, tree, bool);
extern void objc_add_method_declaration (tree);
extern void objc_start_method_definition (tree);
extern void objc_finish_method_definition (tree);
Index: stub-objc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stub-objc.c,v
retrieving revision 2.9
diff -c -3 -p -r2.9 stub-objc.c
*** stub-objc.c 25 Feb 2005 23:20:40 -0000 2.9
--- stub-objc.c 18 Apr 2005 03:22:47 -0000
*************** objc_build_keyword_decl (tree ARG_UNUSED
*** 189,195 ****
tree
objc_build_method_signature (tree ARG_UNUSED (rettype),
tree ARG_UNUSED (selectors),
! tree ARG_UNUSED (optparms))
{
return 0;
}
--- 189,196 ----
tree
objc_build_method_signature (tree ARG_UNUSED (rettype),
tree ARG_UNUSED (selectors),
! tree ARG_UNUSED (optparms),
! bool ARG_UNUSED (ellipsis))
{
return 0;
}
Index: c-parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parser.c,v
retrieving revision 2.9
diff -c -3 -p -r2.9 c-parser.c
*** c-parser.c 29 Mar 2005 18:54:32 -0000 2.9
--- c-parser.c 18 Apr 2005 03:22:48 -0000
*************** c_parser_objc_method_decl (c_parser *par
*** 5793,5798 ****
--- 5793,5800 ----
tree type = NULL_TREE;
tree sel;
tree parms = NULL_TREE;
+ bool ellipsis = false;
+
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
{
c_parser_consume_token (parser);
*************** c_parser_objc_method_decl (c_parser *par
*** 5807,5813 ****
{
tree tsel = sel;
tree list = NULL_TREE;
- bool ellipsis;
while (true)
{
tree atype = NULL_TREE, id, keyworddecl;
--- 5809,5814 ----
*************** c_parser_objc_method_decl (c_parser *par
*** 5837,5843 ****
method parameters follow the C syntax, and may include '...'
to denote a variable number of arguments. */
parms = make_node (TREE_LIST);
- ellipsis = false;
while (c_parser_next_token_is (parser, CPP_COMMA))
{
struct c_parm *parm;
--- 5838,5843 ----
*************** c_parser_objc_method_decl (c_parser *par
*** 5854,5863 ****
parms = chainon (parms,
build_tree_list (NULL_TREE, grokparm (parm)));
}
- TREE_OVERFLOW (parms) = ellipsis;
sel = list;
}
! return objc_build_method_signature (type, sel, parms);
}
/* Parse an objc-type-name.
--- 5854,5862 ----
parms = chainon (parms,
build_tree_list (NULL_TREE, grokparm (parm)));
}
sel = list;
}
! return objc_build_method_signature (type, sel, parms, ellipsis);
}
/* Parse an objc-type-name.
Index: objc/objc-act.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.h,v
retrieving revision 1.36
diff -c -3 -p -r1.36 objc-act.h
*** objc/objc-act.h 13 Apr 2005 19:28:31 -0000 1.36
--- objc/objc-act.h 18 Apr 2005 03:22:48 -0000
*************** enum gimplify_status objc_gimplify_expr
*** 52,57 ****
--- 52,58 ----
#define METHOD_SEL_NAME(DECL) ((DECL)->decl.name)
#define METHOD_SEL_ARGS(DECL) ((DECL)->decl.arguments)
#define METHOD_ADD_ARGS(DECL) ((DECL)->decl.result)
+ #define METHOD_ADD_ARGS_ELLIPSIS_P(DECL) ((DECL)->decl.lang_flag_0)
#define METHOD_DEFINITION(DECL) ((DECL)->decl.initial)
#define METHOD_ENCODING(DECL) ((DECL)->decl.context)
Index: objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.269
diff -c -3 -p -r1.269 objc-act.c
*** objc/objc-act.c 13 Apr 2005 19:28:26 -0000 1.269
--- objc/objc-act.c 18 Apr 2005 03:22:50 -0000
*************** static void objc_start_function (tree, t
*** 164,170 ****
static void objc_start_function (tree, tree, tree, struct c_arg_info *);
#endif
static tree start_protocol (enum tree_code, tree, tree);
! static tree build_method_decl (enum tree_code, tree, tree, tree);
static tree objc_add_method (tree, tree, int);
static tree add_instance_variable (tree, int, tree);
static tree build_ivar_reference (tree);
--- 164,170 ----
static void objc_start_function (tree, tree, tree, struct c_arg_info *);
#endif
static tree start_protocol (enum tree_code, tree, tree);
! static tree build_method_decl (enum tree_code, tree, tree, tree, bool);
static tree objc_add_method (tree, tree, int);
static tree add_instance_variable (tree, int, tree);
static tree build_ivar_reference (tree);
*************** objc_set_method_type (enum tree_code typ
*** 771,779 ****
}
tree
! objc_build_method_signature (tree rettype, tree selector, tree optparms)
{
! return build_method_decl (objc_inherit_code, rettype, selector, optparms);
}
void
--- 771,781 ----
}
tree
! objc_build_method_signature (tree rettype, tree selector,
! tree optparms, bool ellipsis)
{
! return build_method_decl (objc_inherit_code, rettype, selector,
! optparms, ellipsis);
}
void
*************** build_keyword_selector (tree selector)
*** 5263,5269 ****
static tree
build_method_decl (enum tree_code code, tree ret_type, tree selector,
! tree add_args)
{
tree method_decl;
--- 5265,5271 ----
static tree
build_method_decl (enum tree_code code, tree ret_type, tree selector,
! tree add_args, bool ellipsis)
{
tree method_decl;
*************** build_method_decl (enum tree_code code,
*** 5280,5285 ****
--- 5282,5288 ----
METHOD_SEL_NAME (method_decl) = build_keyword_selector (selector);
METHOD_SEL_ARGS (method_decl) = selector;
METHOD_ADD_ARGS (method_decl) = add_args;
+ METHOD_ADD_ARGS_ELLIPSIS_P (method_decl) = ellipsis;
}
else
{
*************** get_arg_type_list (tree meth, int contex
*** 5347,5353 ****
chainon (arglist, build_tree_list (NULL_TREE, arg_type));
}
! if (!TREE_OVERFLOW (METHOD_ADD_ARGS (meth)))
goto lack_of_ellipsis;
}
else
--- 5350,5356 ----
chainon (arglist, build_tree_list (NULL_TREE, arg_type));
}
! if (!METHOD_ADD_ARGS_ELLIPSIS_P (meth))
goto lack_of_ellipsis;
}
else
*************** start_method_def (tree method)
*** 7536,7542 ****
objc_push_parm (TREE_VALUE (akey));
}
! if (TREE_OVERFLOW (METHOD_ADD_ARGS (method)))
have_ellipsis = 1;
}
--- 7539,7545 ----
objc_push_parm (TREE_VALUE (akey));
}
! if (METHOD_ADD_ARGS_ELLIPSIS_P (method))
have_ellipsis = 1;
}
*************** gen_method_decl (tree method)
*** 8109,8115 ****
chain = TREE_CHAIN (chain);
}
! if (TREE_OVERFLOW (METHOD_ADD_ARGS (method)))
strcat (errbuf, ", ...");
}
}
--- 8112,8118 ----
chain = TREE_CHAIN (chain);
}
! if (METHOD_ADD_ARGS_ELLIPSIS_P (method))
strcat (errbuf, ", ...");
}
}
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833