Commit 1899c3a4 by Kriang Lerdsuwanakij Committed by Jason Merrill

parse.y (template_arg): Convert TEMPLATE_DECL that is a template template paramter to...

        * parse.y (template_arg): Convert TEMPLATE_DECL
        that is a template template paramter to
        TEMPLATE_TEMPLATE_PARM here.

        * cp-tree.def (TEMPLATE_TEMPLATE_PARM): Adjust comment.
        * cp-tree.h (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL): New macro.
        (copy_template_template_parm): Adjust prototype.
        * decl.c (grokdeclarator): Remove dead code.
        * pt.c (process_template_parm): Tidy.
        (lookup_template_class): Construct nodes in
        copy_template_template_parm.
        (tsubst): Pass TEMPLATE_DECL rather than IDENTIFIER_NODE to
        lookup_template_class.  Use TYPE_TI_TEMPLATE.
        * tree.c (copy_template_template_parm): Add NEWARGS
        parameter.
        (mapcar): Adjust call to copy_template_template_parm.
        * typeck.c (comptypes): Use TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL.
        * method.c (build_template_template_parm_names): Change error
        code to avoid compilation warning.

        * gxxint.texi: Document template template parameter
        name mangling.

From-SVN: r34659
parent 69112571
2000-06-23 Kriang Lerdsuwanakij <lerdsuwa@scf.usc.edu>
* parse.y (template_arg): Convert TEMPLATE_DECL
that is a template template paramter to
TEMPLATE_TEMPLATE_PARM here.
* cp-tree.def (TEMPLATE_TEMPLATE_PARM): Adjust comment.
* cp-tree.h (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL): New macro.
(copy_template_template_parm): Adjust prototype.
* decl.c (grokdeclarator): Remove dead code.
* pt.c (process_template_parm): Tidy.
(lookup_template_class): Construct nodes in
copy_template_template_parm.
(tsubst): Pass TEMPLATE_DECL rather than IDENTIFIER_NODE to
lookup_template_class. Use TYPE_TI_TEMPLATE.
* tree.c (copy_template_template_parm): Add NEWARGS
parameter.
(mapcar): Adjust call to copy_template_template_parm.
* typeck.c (comptypes): Use TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL.
* method.c (build_template_template_parm_names): Change error
code to avoid compilation warning.
* gxxint.texi: Document template template parameter
name mangling.
2000-06-21 Alex Samuel <samuel@codesourcery.com>
* Make-lang.in (CXX_LIB2FUNCS): Add cp-demangle.o and dyn-string.o.
......
......@@ -140,10 +140,17 @@ DEFTREECODE (TEMPLATE_PARM_INDEX, "template_parm_index", 'x',
The TYPE_FIELDS value will be a TEMPLATE_PARM_INDEX. */
DEFTREECODE (TEMPLATE_TYPE_PARM, "template_type_parm", 't', 0)
/* Index into a template parameter list. This parameter must be a type.
If it is used in signature of a template, TEMPLATE_INFO is NULL_TREE.
Otherwise it is used to declare a type like TT<int>.
The TYPE_FIELDS value will be a TEMPLATE_PARM_INDEX. */
/* Index into a template parameter list for template template parameters.
This parameter must be a type. The TYPE_FIELDS value will be a
TEMPLATE_PARM_INDEX.
If it is used without template arguments like TT in C<TT>,
TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO is NULL_TREE
and TYPE_NAME is a TEMPLATE_DECL.
Otherwise it is used with bound template arguments like TT<int>. In this case,
TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO contains the template name
and its bound arguments. TYPE_NAME is a TYPE_DECL. */
DEFTREECODE (TEMPLATE_TEMPLATE_PARM, "template_template_parm", 't', 0)
/* A type designated by `typename T::t'. TYPE_CONTEXT is `T',
......
......@@ -3802,6 +3802,13 @@ enum tree_string_flags
TS_NEXT_BIT = 13 /* next available bit */
};
/* Returns the TEMPLATE_DECL associated to a TEMPLATE_TEMPLATE_PARM
node. */
#define TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL(NODE) \
(TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (NODE) \
? TYPE_TI_TEMPLATE (NODE) \
: TYPE_NAME (NODE))
/* in lex.c */
/* Indexed by TREE_CODE, these tables give C-looking names to
operators represented by TREE_CODES. For example,
......@@ -4574,7 +4581,7 @@ extern int promotes_to_aggr_type PARAMS ((tree, enum tree_code));
extern int is_aggr_type_2 PARAMS ((tree, tree));
extern const char *lang_printable_name PARAMS ((tree, int));
extern tree build_exception_variant PARAMS ((tree, tree));
extern tree copy_template_template_parm PARAMS ((tree));
extern tree copy_template_template_parm PARAMS ((tree, tree));
extern void print_lang_statistics PARAMS ((void));
extern tree array_type_nelts_total PARAMS ((tree));
extern tree array_type_nelts_top PARAMS ((tree));
......
......@@ -10111,7 +10111,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
}
}
/* C++ aggregate types. */
else if (TREE_CODE (id) == TYPE_DECL || TREE_CODE (id) == TEMPLATE_DECL)
else if (TREE_CODE (id) == TYPE_DECL)
{
if (type)
cp_error ("multiple declarations `%T' and `%T'", type,
......
......@@ -1655,7 +1655,9 @@ A class template instantiation is encoded as the letter @samp{t},
followed by the encoding of the template name, followed
the number of template parameters, followed by encoding of the template
parameters. If a template parameter is a type, it is written
as a @samp{Z} followed by the encoding of the type.
as a @samp{Z} followed by the encoding of the type. If it is a
template, it is encoded as @samp{z} followed by the parameter
of the template template parameter and the template name.
A function template specialization (either an instantiation or an
explicit specialization) is encoded by an @samp{H} followed by the
......@@ -1664,8 +1666,9 @@ encoding of the template parameters, as described above, followed by an
(not the specialization), another @samp{_}, and the return type. (Like
the argument types, the return type is the return type of the function
template, not the specialization.) Template parameters in the argument
and return types are encoded by an @samp{X} for type parameters, or a
@samp{Y} for constant parameters, an index indicating their position
and return types are encoded by an @samp{X} for type parameters,
@samp{zX} for template parameters,
or a @samp{Y} for constant parameters, an index indicating their position
in the template parameter list declaration, and their template depth.
@subsection Arrays
......@@ -1831,6 +1834,9 @@ Encodes a template type parameter, when part of a function type.
@item Y
Encodes a template constant parameter, when part of a function type.
@item z
Used for template template parameters.
@item Z
Used for template type parameters.
......
......@@ -919,7 +919,7 @@ build_template_template_parm_names (parmlist)
{
int i, nparms;
my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5);
my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 990228);
nparms = TREE_VEC_LENGTH (parmlist);
icat (nparms);
for (i = 0; i < nparms; i++)
......
......@@ -1060,7 +1060,11 @@ template_arg:
type_id
{ $$ = groktypename ($1.t); }
| PTYPENAME
{ $$ = lastiddecl; }
{
$$ = lastiddecl;
if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
$$ = TREE_TYPE ($$);
}
| expr_no_commas %prec ARITHCOMPARE
;
......
......@@ -1797,10 +1797,8 @@ process_template_parm (list, next)
{
tree p = TREE_VALUE (tree_last (list));
if (TREE_CODE (p) == TYPE_DECL)
if (TREE_CODE (p) == TYPE_DECL || TREE_CODE (p) == TEMPLATE_DECL)
idx = TEMPLATE_TYPE_IDX (TREE_TYPE (p));
else if (TREE_CODE (p) == TEMPLATE_DECL)
idx = TEMPLATE_TYPE_IDX (TREE_TYPE (DECL_TEMPLATE_RESULT (p)));
else
idx = TEMPLATE_PARM_IDX (DECL_INITIAL (p));
++idx;
......@@ -3803,8 +3801,7 @@ lookup_template_class (d1, arglist, in_decl, context, entering_scope)
/* Create a new TEMPLATE_DECL and TEMPLATE_TEMPLATE_PARM node to store
template arguments */
tree parm = copy_template_template_parm (TREE_TYPE (template));
tree template2 = TYPE_STUB_DECL (parm);
tree parm;
tree arglist2;
parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
......@@ -3813,8 +3810,7 @@ lookup_template_class (d1, arglist, in_decl, context, entering_scope)
if (arglist2 == error_mark_node)
return error_mark_node;
TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parm)
= tree_cons (template2, arglist2, NULL_TREE);
parm = copy_template_template_parm (TREE_TYPE (template), arglist2);
TYPE_SIZE (parm) = 0;
return parm;
}
......@@ -6333,7 +6329,7 @@ tsubst (t, args, complain, in_decl)
if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
arg = TYPE_NAME (arg);
r = lookup_template_class (DECL_NAME (arg),
r = lookup_template_class (arg,
argvec, in_decl,
DECL_CONTEXT (arg),
/*entering_scope=*/0);
......@@ -6383,7 +6379,7 @@ tsubst (t, args, complain, in_decl)
return error_mark_node;
TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (r)
= tree_cons (TYPE_NAME (t), argvec, NULL_TREE);
= tree_cons (TYPE_TI_TEMPLATE (t), argvec, NULL_TREE);
}
break;
......
......@@ -1173,26 +1173,45 @@ build_exception_variant (type, raises)
}
/* Given a TEMPLATE_TEMPLATE_PARM node T, create a new one together with its
lang_specific field and its corresponding TEMPLATE_DECL node */
lang_specific field and its corresponding *_DECL node.
If NEWARGS is not NULL_TREE, this parameter is bound with new set of
arguments. */
tree
copy_template_template_parm (t)
copy_template_template_parm (t, newargs)
tree t;
tree newargs;
{
tree template = TYPE_NAME (t);
tree decl = TYPE_NAME (t);
tree t2;
t2 = make_aggr_type (TEMPLATE_TEMPLATE_PARM);
template = copy_decl (template);
if (newargs == NULL_TREE)
{
decl = copy_decl (decl);
/* No need to copy these. */
TEMPLATE_TYPE_PARM_INDEX (t2) = TEMPLATE_TYPE_PARM_INDEX (t);
TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
= TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t);
}
else
{
decl = build_decl (TYPE_DECL, DECL_NAME (decl), NULL_TREE);
/* These nodes have to be created to reflect new TYPE_DECL and template
arguments. */
TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
= tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t),
newargs, NULL_TREE);
}
TREE_TYPE (template) = t2;
TYPE_NAME (t2) = template;
TYPE_STUB_DECL (t2) = template;
TREE_TYPE (decl) = t2;
TYPE_NAME (t2) = decl;
TYPE_STUB_DECL (t2) = decl;
/* No need to copy these */
TYPE_FIELDS (t2) = TYPE_FIELDS (t);
TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
= TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t);
return t2;
}
......@@ -1496,7 +1515,7 @@ copy_tree_r (tp, walk_subtrees, data)
}
else if (code == TEMPLATE_TEMPLATE_PARM)
/* These must be copied specially. */
*tp = copy_template_template_parm (*tp);
*tp = copy_template_template_parm (*tp, NULL_TREE);
else if (TREE_CODE_CLASS (code) == 't')
/* There's no need to copy types, or anything beneath them. */
*walk_subtrees = 0;
......
......@@ -994,8 +994,9 @@ comptypes (t1, t2, strict)
if (TEMPLATE_TYPE_IDX (t1) != TEMPLATE_TYPE_IDX (t2)
|| TEMPLATE_TYPE_LEVEL (t1) != TEMPLATE_TYPE_LEVEL (t2))
return 0;
if (! comp_template_parms (DECL_TEMPLATE_PARMS (TYPE_NAME (t1)),
DECL_TEMPLATE_PARMS (TYPE_NAME (t2))))
if (! comp_template_parms
(DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
return 0;
if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t1)
&& ! TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2))
......
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