970907 version & member templates
Mark Mitchell
mmitchell@usa.net
Mon Sep 8 11:30:00 GMT 1997
Todd --
>>>>> "Todd" == Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> writes:
Todd> Hi Mark, I've been trying to get member templates working on
Todd> the 970907 snapshot. I don't seem to have a set of patches
Todd> to add member templates to 970907, and the 970904 patches
Todd> don't seem to work.
Todd> Are member templates included in 970907? If not, would it
Todd> be possible to get a full set of patches against 970907?
Todd> Cheers + thanks, Todd
Member templates are included in the 970907 snapshot. I think that
there are two problems, however:
o The cp/parse.c file was not regenerated. If you blow it away, and
rebuild it, everything should work OK.
o libstdc++ was not updated to include the following change to
stl_config.h, which enables member templates in the STL. I've put
that patch below.
Per your request, I've also enclosed patches against 970907 which
include my latest fixes. These are already in the tree, thanks to
Jason, and will appear in the next snapshot.
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu
Index: stl/stl_config.h
===================================================================
RCS file: /home/mitchell/Repository/egcs/libstdc++/stl/stl_config.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -c -p -r1.1.1.1 -r1.2
*** stl_config.h 1997/08/26 06:24:12 1.1.1.1
--- stl_config.h 1997/09/02 06:38:49 1.2
***************
*** 88,93 ****
--- 88,94 ----
# define __STL_NEED_EXPLICIT
# else
# define __STL_CLASS_PARTIAL_SPECIALIZATION
+ # define __STL_MEMBER_TEMPLATES
# endif
# ifdef __EXCEPTIONS
# define __STL_USE_EXCEPTIONS
Index: call.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/call.c,v
retrieving revision 1.1.1.5
retrieving revision 1.5
diff -c -p -r1.1.1.5 -r1.5
*** call.c 1997/09/08 05:23:53 1.1.1.5
--- call.c 1997/09/08 09:22:40 1.5
*************** static struct z_candidate * splice_viabl
*** 78,83 ****
--- 78,85 ----
static int any_viable PROTO((struct z_candidate *));
static struct z_candidate * add_template_candidate
PROTO((struct z_candidate *, tree, tree, tree, int));
+ static struct z_candidate * add_template_conv_candidate
+ PROTO((struct z_candidate *, tree, tree, tree, tree));
static struct z_candidate * add_builtin_candidates
PROTO((struct z_candidate *, enum tree_code, enum tree_code,
tree, tree *, int));
*************** add_template_candidate (candidates, tmpl
*** 4170,4175 ****
--- 4172,4204 ----
return cand;
}
+
+ static struct z_candidate *
+ add_template_conv_candidate (candidates, tmpl, obj, arglist,
return_type)
+ struct z_candidate *candidates;
+ tree tmpl, obj, arglist, return_type;
+ {
+ int ntparms = DECL_NTPARMS (tmpl);
+ tree targs = make_tree_vec (ntparms);
+ struct z_candidate *cand;
+ int i;
+ tree fn;
+
+ i = fn_type_unification (tmpl, targs, arglist, return_type, 0);
+
+ if (i != 0)
+ return candidates;
+
+ fn = instantiate_template (tmpl, targs);
+ if (fn == error_mark_node)
+ return candidates;
+
+ cand = add_conv_candidate (candidates, fn, obj, arglist);
+ cand->template = DECL_TEMPLATE_INFO (fn);
+ return cand;
+ }
+
+
static int
any_viable (cands)
struct z_candidate *cands;
*************** build_object_call (obj, args)
*** 4508,4513 ****
--- 4537,4543 ----
struct z_candidate *candidates = 0, *cand;
tree fns, convs, mem_args;
tree type = TREE_TYPE (obj);
+ tree templates = NULL_TREE;
fns = lookup_fnfields (TYPE_BINFO (type), ansi_opname [CALL_EXPR],
0);
*************** build_object_call (obj, args)
*** 4523,4531 ****
for (; fn; fn = DECL_CHAIN (fn))
{
! candidates = add_function_candidate
! (candidates, fn, mem_args, LOOKUP_NORMAL);
! candidates->basetype_path = TREE_PURPOSE (fns);
}
}
--- 4553,4571 ----
for (; fn; fn = DECL_CHAIN (fn))
{
! if (TREE_CODE (fn) == TEMPLATE_DECL)
! {
! templates = decl_tree_cons (NULL_TREE, fn, templates);
! candidates = add_template_candidate (candidates, fn,
! mem_args,
NULL_TREE,
! LOOKUP_NORMAL);
! }
! else
! candidates = add_function_candidate
! (candidates, fn, mem_args, LOOKUP_NORMAL);
!
! if (candidates)
! candidates->basetype_path = TREE_PURPOSE (fns);
}
}
*************** build_object_call (obj, args)
*** 4540,4547 ****
&& TREE_CODE (TREE_TYPE (totype)) == FUNCTION_TYPE)
for (; fn; fn = DECL_CHAIN (fn))
{
! candidates = add_conv_candidate (candidates, fn, obj,
args);
! candidates->basetype_path = TREE_PURPOSE (convs);
}
}
--- 4580,4599 ----
&& TREE_CODE (TREE_TYPE (totype)) == FUNCTION_TYPE)
for (; fn; fn = DECL_CHAIN (fn))
{
! if (TREE_CODE (fn) == TEMPLATE_DECL)
! {
! templates = decl_tree_cons (NULL_TREE, fn, templates);
! candidates = add_template_conv_candidate (candidates,
! fn,
! obj,
! args,
! totype);
! }
! else
! candidates = add_conv_candidate (candidates, fn, obj,
args);
!
! if (candidates)
! candidates->basetype_path = TREE_PURPOSE (convs);
}
}
Index: class.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/class.c,v
retrieving revision 1.1.1.3
retrieving revision 1.5
diff -c -p -r1.1.1.3 -r1.5
Index: cp-tree.h
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.1.1.2
retrieving revision 1.4
diff -c -p -r1.1.1.2 -r1.4
Index: decl.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/decl.c,v
retrieving revision 1.1.1.5
retrieving revision 1.6
diff -c -p -r1.1.1.5 -r1.6
Index: decl2.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/decl2.c,v
retrieving revision 1.1.1.4
retrieving revision 1.4
diff -c -p -r1.1.1.4 -r1.4
Index: error.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/error.c,v
retrieving revision 1.1.1.3
retrieving revision 1.7
diff -c -p -r1.1.1.3 -r1.7
*** error.c 1997/09/08 05:23:57 1.1.1.3
--- error.c 1997/09/08 16:52:43 1.7
*************** dump_decl (t, v)
*** 782,791 ****
case CONST_DECL:
if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) ==
ENUMERAL_TYPE)
! || TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_CONST_PARM)
goto general;
! else
dump_expr (DECL_INITIAL (t), 0);
break;
case USING_DECL:
--- 782,794 ----
case CONST_DECL:
if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) ==
ENUMERAL_TYPE)
! || (DECL_INITIAL (t) &&
! TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_CONST_PARM))
goto general;
! else if (DECL_INITIAL (t))
dump_expr (DECL_INITIAL (t), 0);
+ else
+ OB_PUTS ("constant");
break;
case USING_DECL:
*************** dump_expr (t, nop)
*** 1366,1378 ****
if (current_template_parms)
{
int i;
! tree parms;
tree r;
! for (parms = current_template_parms;
! TREE_CHAIN (parms);
! parms = TREE_CHAIN (parms))
! ;
r = TREE_VEC_ELT (TREE_VALUE (parms),
TEMPLATE_CONST_IDX (t));
--- 1369,1383 ----
if (current_template_parms)
{
int i;
! int l = list_length (current_template_parms);
! tree parms = current_template_parms;
tree r;
! for (i = 0; i < l - TEMPLATE_CONST_LEVEL (t); ++i)
! {
! parms = TREE_CHAIN (parms);
! my_friendly_assert (parms != NULL_TREE, 0);
! }
r = TREE_VEC_ELT (TREE_VALUE (parms),
TEMPLATE_CONST_IDX (t));
Index: lex.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/lex.c,v
retrieving revision 1.1.1.3
retrieving revision 1.4
diff -c -p -r1.1.1.3 -r1.4
*** lex.c 1997/09/08 05:23:57 1.1.1.3
--- lex.c 1997/09/08 09:22:42 1.4
*************** do_pending_inlines ()
*** 1191,1197 ****
if (context)
push_cp_function_context (context);
if (is_member_template (t->fndecl))
! begin_member_template_processing (DECL_TI_ARGS (t->fndecl));
if (t->len > 0)
{
feed_input (t->buf, t->len);
--- 1191,1197 ----
if (context)
push_cp_function_context (context);
if (is_member_template (t->fndecl))
! begin_member_template_processing (t->fndecl);
if (t->len > 0)
{
feed_input (t->buf, t->len);
*************** process_next_inline (t)
*** 1254,1260 ****
if (context)
push_cp_function_context (context);
if (is_member_template (i->fndecl))
! begin_member_template_processing (DECL_TI_ARGS (i->fndecl));
feed_input (i->buf, i->len);
lineno = i->lineno;
input_filename = i->filename;
--- 1254,1260 ----
if (context)
push_cp_function_context (context);
if (is_member_template (i->fndecl))
! begin_member_template_processing (i->fndecl);
feed_input (i->buf, i->len);
lineno = i->lineno;
input_filename = i->filename;
*************** do_pending_defargs ()
*** 1874,1880 ****
push_nested_class (TREE_PURPOSE (defarg_fns), 1);
pushlevel (0);
if (is_member_template (defarg_fn))
! begin_member_template_processing (DECL_TI_ARGS
(defarg_fn));
if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
{
--- 1874,1880 ----
push_nested_class (TREE_PURPOSE (defarg_fns), 1);
pushlevel (0);
if (is_member_template (defarg_fn))
! begin_member_template_processing (defarg_fn);
if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
{
Index: method.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/method.c,v
retrieving revision 1.1.1.3
retrieving revision 1.4
diff -c -p -r1.1.1.3 -r1.4
Index: parse.y
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/parse.y,v
retrieving revision 1.1.1.3
retrieving revision 1.3
diff -c -p -r1.1.1.3 -r1.3
Index: pt.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/pt.c,v
retrieving revision 1.1.1.4
retrieving revision 1.9
diff -c -p -r1.1.1.4 -r1.9
*** pt.c 1997/09/08 16:24:02 1.1.1.4
--- pt.c 1997/09/08 16:41:27 1.9
*************** static tree add_to_template_args PROTO((
*** 82,110 ****
/* Restore the template parameter context. */
void
! begin_member_template_processing (parms)
! tree parms;
{
int i;
++processing_template_decl;
current_template_parms
= tree_cons (build_int_2 (0, processing_template_decl),
parms, current_template_parms);
for (i = 0; i < TREE_VEC_LENGTH (parms); ++i)
{
! tree parm = TREE_VEC_ELT (parms, i);
!
switch (TREE_CODE (parm))
{
! case TEMPLATE_TYPE_PARM:
! pushdecl (TYPE_NAME (parm));
! break;
!
! case TEMPLATE_CONST_PARM:
pushdecl (parm);
break;
!
default:
my_friendly_abort (0);
}
--- 82,121 ----
/* Restore the template parameter context. */
void
! begin_member_template_processing (decl)
! tree decl;
{
+ tree parms;
int i;
+ parms = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (decl));
+
++processing_template_decl;
current_template_parms
= tree_cons (build_int_2 (0, processing_template_decl),
parms, current_template_parms);
+ pushlevel (0);
for (i = 0; i < TREE_VEC_LENGTH (parms); ++i)
{
! tree parm = TREE_VALUE (TREE_VEC_ELT (parms, i));
! my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (parm)) == 'd',
0);
!
switch (TREE_CODE (parm))
{
! case TYPE_DECL:
pushdecl (parm);
break;
!
! case PARM_DECL:
! {
! /* Make a CONST_DECL as is done in
process_template_parm. */
! tree decl = build_decl (CONST_DECL, DECL_NAME (parm),
! TREE_TYPE (parm));
! DECL_INITIAL (decl) = DECL_INITIAL (parm);
! pushdecl (decl);
! }
! break;
!
default:
my_friendly_abort (0);
}
*************** end_member_template_processing ()
*** 121,126 ****
--- 132,138 ----
--processing_template_decl;
current_template_parms = TREE_CHAIN (current_template_parms);
+ poplevel (0, 0, 0);
}
/* Returns non-zero iff T is a member template function. Works if T
*************** push_template_decl (decl)
*** 449,455 ****
DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
DECL_CONTEXT (tmpl) = DECL_CONTEXT (decl);
if (DECL_LANG_SPECIFIC (decl))
! DECL_CLASS_CONTEXT (tmpl) = DECL_CLASS_CONTEXT (decl);
}
else
{
--- 461,471 ----
DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
DECL_CONTEXT (tmpl) = DECL_CONTEXT (decl);
if (DECL_LANG_SPECIFIC (decl))
! {
! DECL_CLASS_CONTEXT (tmpl) = DECL_CLASS_CONTEXT (decl);
! DECL_STATIC_FUNCTION_P (tmpl) =
! DECL_STATIC_FUNCTION_P (decl);
! }
}
else
{
More information about the Gcc
mailing list