1 /* Handle parameterized types (templates) for GNU C++.
2 Copyright (C) 1992, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
4 Rewritten by Jason Merrill (jason@cygnus.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Known bugs or deficiencies include:
25 templates for class static data don't work (methods only),
26 duplicated method templates can crash the compiler,
27 interface/impl data is taken from file defining the template,
28 all methods must be provided in header files; can't use a source
29 file that contains only the method templates and "just win". */
44 extern struct obstack permanent_obstack
;
47 extern char *input_filename
;
48 struct pending_inline
*pending_template_expansions
;
50 tree current_template_parms
;
51 HOST_WIDE_INT processing_template_decl
;
53 tree pending_templates
;
54 static tree
*template_tail
= &pending_templates
;
56 int minimal_parse_mode
;
58 #define obstack_chunk_alloc xmalloc
59 #define obstack_chunk_free free
63 void pop_template_decls ();
65 tree
classtype_mangled_name ();
66 static char * mangle_class_name_for_template ();
67 tree
tsubst_expr_values ();
69 /* We've got a template header coming up; push to a new level for storing
73 begin_template_parm_list ()
76 declare_pseudo_global_level ();
79 /* Process information from new template parameter NEXT and append it to the
83 process_template_parm (list
, next
)
91 my_friendly_assert (TREE_CODE (parm
) == TREE_LIST
, 259);
92 defval
= TREE_PURPOSE (parm
);
93 parm
= TREE_VALUE (parm
);
94 is_type
= TREE_PURPOSE (parm
) == class_type_node
;
98 tree p
= TREE_VALUE (tree_last (list
));
100 if (TREE_CODE (p
) == TYPE_DECL
)
101 idx
= TEMPLATE_TYPE_IDX (TREE_TYPE (p
));
103 idx
= TEMPLATE_CONST_IDX (DECL_INITIAL (p
));
112 my_friendly_assert (TREE_CODE (TREE_PURPOSE (parm
)) == TREE_LIST
, 260);
113 /* is a const-param */
114 parm
= grokdeclarator (TREE_VALUE (parm
), TREE_PURPOSE (parm
),
115 PARM
, 0, NULL_TREE
, NULL_TREE
);
116 /* A template parameter is not modifiable. */
117 TREE_READONLY (parm
) = 1;
118 if (IS_AGGR_TYPE (TREE_TYPE (parm
))
119 && TREE_CODE (TREE_TYPE (parm
)) != TEMPLATE_TYPE_PARM
)
121 cp_error ("`%#T' is not a valid type for a template constant parameter",
123 if (DECL_NAME (parm
) == NULL_TREE
)
124 error (" a template type parameter must begin with `class' or `typename'");
125 TREE_TYPE (parm
) = void_type_node
;
127 tinfo
= make_node (TEMPLATE_CONST_PARM
);
128 my_friendly_assert (TREE_PERMANENT (tinfo
), 260.5);
129 if (TREE_PERMANENT (parm
) == 0)
131 parm
= copy_node (parm
);
132 TREE_PERMANENT (parm
) = 1;
134 TREE_TYPE (tinfo
) = TREE_TYPE (parm
);
135 decl
= build_decl (CONST_DECL
, DECL_NAME (parm
), TREE_TYPE (parm
));
136 DECL_INITIAL (decl
) = tinfo
;
137 DECL_INITIAL (parm
) = tinfo
;
138 TEMPLATE_CONST_SET_INFO (tinfo
, idx
, processing_template_decl
+ 1);
142 tree t
= make_lang_type (TEMPLATE_TYPE_PARM
);
143 CLASSTYPE_GOT_SEMICOLON (t
) = 1;
144 decl
= build_decl (TYPE_DECL
, TREE_VALUE (parm
), t
);
145 TYPE_MAIN_DECL (t
) = decl
;
147 TEMPLATE_TYPE_SET_INFO (t
, idx
, processing_template_decl
+ 1);
149 SET_DECL_ARTIFICIAL (decl
);
151 parm
= build_tree_list (defval
, parm
);
152 return chainon (list
, parm
);
155 /* The end of a template parameter list has been reached. Process the
156 tree list into a parameter vector, converting each parameter into a more
157 useful form. Type parameters are saved as IDENTIFIER_NODEs, and others
161 end_template_parm_list (parms
)
166 tree saved_parmlist
= make_tree_vec (list_length (parms
));
168 ++processing_template_decl
;
169 current_template_parms
170 = tree_cons (build_int_2 (0, processing_template_decl
),
171 saved_parmlist
, current_template_parms
);
173 for (parm
= parms
, nparms
= 0; parm
; parm
= TREE_CHAIN (parm
), nparms
++)
174 TREE_VEC_ELT (saved_parmlist
, nparms
) = parm
;
176 return saved_parmlist
;
179 /* end_template_decl is called after a template declaration is seen. */
184 /* This matches the pushlevel in begin_template_parm_list. */
187 --processing_template_decl
;
188 current_template_parms
= TREE_CHAIN (current_template_parms
);
189 (void) get_pending_sizes (); /* Why? */
193 push_template_decl (decl
)
196 tree header
= current_template_parms
;
198 tree args
= NULL_TREE
;
200 tree ctx
= DECL_CONTEXT (decl
) ? DECL_CONTEXT (decl
) : current_class_type
;
204 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_FRIEND_P (decl
)
205 && DECL_CLASS_CONTEXT (decl
))
207 /* Note that this template is a "primary template" */
208 else if (! ctx
|| ! CLASSTYPE_TEMPLATE_INFO (ctx
)
209 /* || (processing_template_decl > CLASSTYPE_TEMPLATE_LEVEL (ctx)) */)
214 tree a
= copy_node (TREE_VALUE (header
));
215 int i
= TREE_VEC_LENGTH (a
);
216 TREE_TYPE (a
) = NULL_TREE
;
219 tree t
= TREE_VALUE (TREE_VEC_ELT (a
, i
));
220 if (TREE_CODE (t
) == TYPE_DECL
)
223 t
= DECL_INITIAL (t
);
224 TREE_VEC_ELT (a
, i
) = t
;
226 args
= tree_cons (TREE_PURPOSE (header
), a
, args
);
227 header
= TREE_CHAIN (header
);
229 args
= nreverse (args
);
230 args
= TREE_VALUE (args
);
232 if (! ctx
|| TYPE_BEING_DEFINED (ctx
))
234 tmpl
= build_lang_decl (TEMPLATE_DECL
, DECL_NAME (decl
), NULL_TREE
);
235 DECL_TEMPLATE_PARMS (tmpl
) = TREE_VALUE (current_template_parms
);
236 DECL_CONTEXT (tmpl
) = DECL_CONTEXT (decl
);
240 if (TREE_CODE (decl
) == TYPE_DECL
)
241 tmpl
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (decl
));
242 else if (! DECL_TEMPLATE_INFO (decl
))
244 cp_error ("template definition of non-template `%#D'", decl
);
248 tmpl
= DECL_TI_TEMPLATE (decl
);
251 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
252 TREE_TYPE (tmpl
) = TREE_TYPE (decl
);
255 tmpl
= pushdecl_top_level (tmpl
);
258 TREE_TYPE (DECL_TEMPLATE_PARMS (tmpl
)) = tmpl
;
260 info
= perm_tree_cons (tmpl
, args
, NULL_TREE
);
262 if (TREE_CODE (decl
) == TYPE_DECL
)
264 CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (tmpl
)) = info
;
265 DECL_NAME (decl
) = classtype_mangled_name (TREE_TYPE (decl
));
267 else if (! DECL_LANG_SPECIFIC (decl
))
268 cp_error ("template declaration of `%#D'", decl
);
270 DECL_TEMPLATE_INFO (decl
) = info
;
273 tree tsubst
PROTO ((tree
, tree
*, int, tree
));
275 /* Convert all template arguments to their appropriate types, and return
276 a vector containing the resulting values. If any error occurs, return
280 coerce_template_parms (parms
, arglist
, in_decl
)
284 int nparms
, nargs
, i
, lost
= 0;
287 if (arglist
== NULL_TREE
)
289 else if (TREE_CODE (arglist
) == TREE_VEC
)
290 nargs
= TREE_VEC_LENGTH (arglist
);
292 nargs
= list_length (arglist
);
294 nparms
= TREE_VEC_LENGTH (parms
);
298 && TREE_PURPOSE (TREE_VEC_ELT (parms
, nargs
)) == NULL_TREE
))
300 error ("incorrect number of parameters (%d, should be %d)",
303 cp_error_at ("in template expansion for decl `%D'", in_decl
);
304 return error_mark_node
;
307 if (arglist
&& TREE_CODE (arglist
) == TREE_VEC
)
308 vec
= copy_node (arglist
);
311 vec
= make_tree_vec (nparms
);
312 for (i
= 0; i
< nparms
; i
++)
319 arglist
= TREE_CHAIN (arglist
);
321 if (arg
== error_mark_node
)
324 arg
= TREE_VALUE (arg
);
327 arg
= tsubst (TREE_PURPOSE (TREE_VEC_ELT (parms
, i
)),
328 &TREE_VEC_ELT (vec
, 0), i
, in_decl
);
330 TREE_VEC_ELT (vec
, i
) = arg
;
333 for (i
= 0; i
< nparms
; i
++)
335 tree arg
= TREE_VEC_ELT (vec
, i
);
336 tree parm
= TREE_VALUE (TREE_VEC_ELT (parms
, i
));
338 int is_type
, requires_type
;
340 is_type
= TREE_CODE_CLASS (TREE_CODE (arg
)) == 't';
341 requires_type
= TREE_CODE (parm
) == TYPE_DECL
;
343 if (requires_type
&& ! is_type
&& TREE_CODE (arg
) == SCOPE_REF
344 && TREE_CODE (TREE_OPERAND (arg
, 0)) == TEMPLATE_TYPE_PARM
)
346 cp_pedwarn ("to refer to a type member of a template parameter,");
347 cp_pedwarn (" use `typename %E'", arg
);
348 arg
= make_typename_type (TREE_OPERAND (arg
, 0),
349 TREE_OPERAND (arg
, 1));
352 if (is_type
!= requires_type
)
356 cp_error ("type/value mismatch at argument %d in template parameter list for `%D'",
359 cp_error (" expected a constant of type `%T', got `%T'",
360 TREE_TYPE (parm
), arg
);
362 cp_error (" expected a type, got `%E'", arg
);
365 TREE_VEC_ELT (vec
, i
) = error_mark_node
;
370 val
= groktypename (arg
);
371 if (! current_template_parms
)
373 tree t
= target_type (val
);
375 && decl_function_context (TYPE_MAIN_DECL (t
)))
377 cp_error ("type `%T' composed from a local class is not a valid template-argument", val
);
378 return error_mark_node
;
384 tree t
= tsubst (TREE_TYPE (parm
), &TREE_VEC_ELT (vec
, 0),
385 TREE_VEC_LENGTH (vec
), in_decl
);
386 if (current_template_parms
)
389 val
= digest_init (t
, arg
, (tree
*) 0);
391 if (val
== error_mark_node
|| current_template_parms
)
394 /* 14.2: Other template-arguments must be constant-expressions,
395 addresses of objects or functions with external linkage, or of
396 static class members. */
397 else if (!TREE_CONSTANT (val
))
399 cp_error ("non-const `%E' cannot be used as template argument",
401 val
= error_mark_node
;
403 else if (POINTER_TYPE_P (TREE_TYPE (val
))
404 && ! integer_zerop (val
)
405 && TREE_CODE (TREE_TYPE (TREE_TYPE (val
))) != OFFSET_TYPE
406 && TREE_CODE (TREE_TYPE (TREE_TYPE (val
))) != METHOD_TYPE
)
410 if (TREE_CODE (t
) == ADDR_EXPR
)
412 tree a
= TREE_OPERAND (t
, 0);
414 if (TREE_CODE (a
) == STRING_CST
)
416 cp_error ("string literal %E is not a valid template argument", a
);
417 error ("because it is the address of an object with static linkage");
418 val
= error_mark_node
;
420 else if (TREE_CODE (a
) != VAR_DECL
421 && TREE_CODE (a
) != FUNCTION_DECL
)
423 else if (! DECL_PUBLIC (a
))
425 cp_error ("address of non-extern `%E' cannot be used as template argument", a
);
426 val
= error_mark_node
;
432 cp_error ("`%E' is not a valid template argument", t
);
433 error ("it must be %s%s with external linkage",
434 TREE_CODE (TREE_TYPE (val
)) == POINTER_TYPE
435 ? "a pointer to " : "",
436 TREE_CODE (TREE_TYPE (TREE_TYPE (val
))) == FUNCTION_TYPE
437 ? "a function" : "an object");
438 val
= error_mark_node
;
443 if (val
== error_mark_node
)
446 TREE_VEC_ELT (vec
, i
) = val
;
449 return error_mark_node
;
454 comp_template_args (oldargs
, newargs
)
455 tree oldargs
, newargs
;
459 for (i
= 0; i
< TREE_VEC_LENGTH (oldargs
); ++i
)
461 tree nt
= TREE_VEC_ELT (newargs
, i
);
462 tree ot
= TREE_VEC_ELT (oldargs
, i
);
466 if (TREE_CODE (nt
) != TREE_CODE (ot
))
468 if (TREE_CODE_CLASS (TREE_CODE (ot
)) == 't')
470 if (comptypes (ot
, nt
, 1))
473 else if (cp_tree_equal (ot
, nt
) > 0)
480 /* Given class template name and parameter list, produce a user-friendly name
481 for the instantiation. */
484 mangle_class_name_for_template (name
, parms
, arglist
)
488 static struct obstack scratch_obstack
;
489 static char *scratch_firstobj
;
492 if (!scratch_firstobj
)
493 gcc_obstack_init (&scratch_obstack
);
495 obstack_free (&scratch_obstack
, scratch_firstobj
);
496 scratch_firstobj
= obstack_alloc (&scratch_obstack
, 1);
499 #define buflen sizeof(buf)
500 #define check if (bufp >= buf+buflen-1) goto too_long
501 #define ccat(c) *bufp++=(c); check
502 #define advance bufp+=strlen(bufp); check
503 #define cat(s) strncpy(bufp, s, buf+buflen-bufp-1); advance
506 #define ccat(c) obstack_1grow (&scratch_obstack, (c));
508 #define cat(s) obstack_grow (&scratch_obstack, (s), strlen (s))
513 nparms
= TREE_VEC_LENGTH (parms
);
514 my_friendly_assert (nparms
== TREE_VEC_LENGTH (arglist
), 268);
515 for (i
= 0; i
< nparms
; i
++)
517 tree parm
= TREE_VALUE (TREE_VEC_ELT (parms
, i
));
518 tree arg
= TREE_VEC_ELT (arglist
, i
);
523 if (TREE_CODE (parm
) == TYPE_DECL
)
525 cat (type_as_string (arg
, 0));
529 my_friendly_assert (TREE_CODE (parm
) == PARM_DECL
, 269);
531 if (TREE_CODE (arg
) == TREE_LIST
)
533 /* New list cell was built because old chain link was in
535 my_friendly_assert (TREE_PURPOSE (arg
) == NULL_TREE
, 270);
536 arg
= TREE_VALUE (arg
);
538 /* No need to check arglist against parmlist here; we did that
539 in coerce_template_parms, called from lookup_template_class. */
540 cat (expr_as_string (arg
, 0));
543 char *bufp
= obstack_next_free (&scratch_obstack
);
545 while (bufp
[offset
- 1] == ' ')
547 obstack_blank_fast (&scratch_obstack
, offset
);
549 /* B<C<char> >, not B<C<char>> */
550 if (bufp
[offset
- 1] == '>')
555 return (char *) obstack_base (&scratch_obstack
);
560 fatal ("out of (preallocated) string space creating template instantiation name");
566 classtype_mangled_name (t
)
569 if (CLASSTYPE_TEMPLATE_INFO (t
)
570 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)))
572 tree name
= DECL_NAME (CLASSTYPE_TI_TEMPLATE (t
));
573 char *mangled_name
= mangle_class_name_for_template
574 (IDENTIFIER_POINTER (name
),
575 DECL_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (t
)),
576 CLASSTYPE_TI_ARGS (t
));
577 tree id
= get_identifier (mangled_name
);
578 IDENTIFIER_TEMPLATE (id
) = name
;
582 return TYPE_IDENTIFIER (t
);
586 add_pending_template (d
)
591 if (TREE_CODE_CLASS (TREE_CODE (d
)) == 't')
592 ti
= CLASSTYPE_TEMPLATE_INFO (d
);
594 ti
= DECL_TEMPLATE_INFO (d
);
596 if (TREE_LANG_FLAG_0 (ti
))
599 *template_tail
= perm_tree_cons
600 (current_function_decl
, d
, NULL_TREE
);
601 template_tail
= &TREE_CHAIN (*template_tail
);
602 TREE_LANG_FLAG_0 (ti
) = 1;
605 /* Given an IDENTIFIER_NODE (type TEMPLATE_DECL) and a chain of
606 parameters, find the desired type.
608 D1 is the PTYPENAME terminal, and ARGLIST is the list of arguments.
609 Since ARGLIST is build on the decl_obstack, we must copy it here
610 to keep it from being reclaimed when the decl storage is reclaimed.
612 IN_DECL, if non-NULL, is the template declaration we are trying to
616 lookup_template_class (d1
, arglist
, in_decl
)
620 tree
template, parmlist
;
625 if (TREE_CODE (d1
) == IDENTIFIER_NODE
)
627 template = IDENTIFIER_GLOBAL_VALUE (d1
); /* XXX */
629 template = IDENTIFIER_CLASS_VALUE (d1
);
631 else if (TREE_CODE (d1
) == TYPE_DECL
&& IS_AGGR_TYPE (TREE_TYPE (d1
)))
633 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d1
));
634 d1
= DECL_NAME (template);
636 else if (TREE_CODE_CLASS (TREE_CODE (d1
)) == 't' && IS_AGGR_TYPE (d1
))
638 template = CLASSTYPE_TI_TEMPLATE (d1
);
639 d1
= DECL_NAME (template);
642 my_friendly_abort (272);
644 /* With something like `template <class T> class X class X { ... };'
645 we could end up with D1 having nothing but an IDENTIFIER_LOCAL_VALUE.
646 We don't want to do that, but we have to deal with the situation, so
647 let's give them some syntax errors to chew on instead of a crash. */
649 return error_mark_node
;
650 if (TREE_CODE (template) != TEMPLATE_DECL
)
652 cp_error ("non-template type `%T' used as a template", d1
);
654 cp_error_at ("for template declaration `%D'", in_decl
);
655 return error_mark_node
;
658 if (PRIMARY_TEMPLATE_P (template))
660 parmlist
= DECL_TEMPLATE_PARMS (template);
662 arglist
= coerce_template_parms (parmlist
, arglist
, template);
663 if (arglist
== error_mark_node
)
664 return error_mark_node
;
665 if (uses_template_parms (arglist
))
668 if (comp_template_args
669 (CLASSTYPE_TI_ARGS (TREE_TYPE (template)), arglist
))
670 found
= TREE_TYPE (template);
673 for (found
= DECL_TEMPLATE_INSTANTIATIONS (template);
674 found
; found
= TREE_CHAIN (found
))
676 if (TI_USES_TEMPLATE_PARMS (found
)
677 && comp_template_args (TREE_PURPOSE (found
), arglist
))
681 found
= TREE_VALUE (found
);
686 if (can_free (&permanent_obstack
, arglist
))
687 obstack_free (&permanent_obstack
, arglist
);
692 mangled_name
= mangle_class_name_for_template (IDENTIFIER_POINTER (d1
),
694 id
= get_identifier (mangled_name
);
695 IDENTIFIER_TEMPLATE (id
) = d1
;
697 maybe_push_to_top_level (uses_template_parms (arglist
));
698 t
= xref_tag_from_type (TREE_TYPE (template), id
, 1);
699 pop_from_top_level ();
703 tree ctx
= lookup_template_class (TYPE_CONTEXT (TREE_TYPE (template)),
706 arglist
= CLASSTYPE_TI_ARGS (ctx
);
708 if (TYPE_BEING_DEFINED (ctx
) && ctx
== current_class_type
)
710 tree save_parms
= current_template_parms
;
711 current_template_parms
= NULL_TREE
;
712 t
= xref_tag_from_type (TREE_TYPE (template), id
, 0);
713 current_template_parms
= save_parms
;
717 t
= lookup_nested_type_by_name (ctx
, id
);
718 my_friendly_assert (t
!= NULL_TREE
, 42);
722 /* Seems to be wanted. */
723 CLASSTYPE_GOT_SEMICOLON (t
) = 1;
725 if (! CLASSTYPE_TEMPLATE_INFO (t
))
727 arglist
= copy_to_permanent (arglist
);
728 CLASSTYPE_TEMPLATE_INFO (t
)
729 = perm_tree_cons (template, arglist
, NULL_TREE
);
730 DECL_TEMPLATE_INSTANTIATIONS (template) = perm_tree_cons
731 (arglist
, t
, DECL_TEMPLATE_INSTANTIATIONS (template));
732 TI_USES_TEMPLATE_PARMS (DECL_TEMPLATE_INSTANTIATIONS (template))
733 = uses_template_parms (arglist
);
735 SET_CLASSTYPE_IMPLICIT_INSTANTIATION (t
);
737 /* We need to set this again after CLASSTYPE_TEMPLATE_INFO is set up. */
738 DECL_ASSEMBLER_NAME (TYPE_MAIN_DECL (t
)) = id
;
739 if (! uses_template_parms (arglist
))
740 DECL_ASSEMBLER_NAME (TYPE_MAIN_DECL (t
))
741 = get_identifier (build_overload_name (t
, 1, 1));
743 if (flag_external_templates
&& ! uses_template_parms (arglist
)
744 && CLASSTYPE_INTERFACE_KNOWN (TREE_TYPE (template))
745 && ! CLASSTYPE_INTERFACE_ONLY (TREE_TYPE (template)))
746 add_pending_template (t
);
752 /* Should be defined in parse.h. */
756 uses_template_parms (t
)
761 switch (TREE_CODE (t
))
765 /* We assume that the object must be instantiated in order to build
766 the COMPONENT_REF, so we test only whether the type of the
767 COMPONENT_REF uses template parms. */
768 return uses_template_parms (TREE_TYPE (t
));
770 case IDENTIFIER_NODE
:
771 if (!IDENTIFIER_TEMPLATE (t
))
773 my_friendly_abort (42);
775 /* aggregates of tree nodes */
778 int i
= TREE_VEC_LENGTH (t
);
780 if (uses_template_parms (TREE_VEC_ELT (t
, i
)))
785 if (uses_template_parms (TREE_PURPOSE (t
))
786 || uses_template_parms (TREE_VALUE (t
)))
788 return uses_template_parms (TREE_CHAIN (t
));
790 /* constructed type nodes */
793 return uses_template_parms (TREE_TYPE (t
));
795 if (TYPE_PTRMEMFUNC_FLAG (t
))
796 return uses_template_parms (TYPE_PTRMEMFUNC_FN_TYPE (t
));
798 if (! CLASSTYPE_TEMPLATE_INFO (t
))
800 return uses_template_parms (TREE_VALUE (CLASSTYPE_TEMPLATE_INFO (t
)));
802 if (uses_template_parms (TYPE_ARG_TYPES (t
)))
804 return uses_template_parms (TREE_TYPE (t
));
806 if (uses_template_parms (TYPE_DOMAIN (t
)))
808 return uses_template_parms (TREE_TYPE (t
));
810 if (uses_template_parms (TYPE_OFFSET_BASETYPE (t
)))
812 return uses_template_parms (TREE_TYPE (t
));
814 if (uses_template_parms (TYPE_METHOD_BASETYPE (t
)))
816 if (uses_template_parms (TYPE_ARG_TYPES (t
)))
818 return uses_template_parms (TREE_TYPE (t
));
822 return uses_template_parms (TREE_TYPE (t
));
826 /* ??? What about FIELD_DECLs? */
827 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
)
828 && uses_template_parms (DECL_TI_ARGS (t
)))
833 if (uses_template_parms (TREE_TYPE (t
)))
835 if (DECL_CONTEXT (t
) && uses_template_parms (DECL_CONTEXT (t
)))
840 return uses_template_parms (TREE_TYPE (t
));
842 return uses_template_parms (TREE_OPERAND (t
, 0));
844 /* template parm nodes */
845 case TEMPLATE_TYPE_PARM
:
846 case TEMPLATE_CONST_PARM
:
849 /* simple type nodes */
851 if (uses_template_parms (TYPE_MIN_VALUE (t
)))
853 return uses_template_parms (TYPE_MAX_VALUE (t
));
868 /* Non-error_mark_node ERROR_MARKs are bad things. */
869 my_friendly_assert (t
== error_mark_node
, 274);
878 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
879 return uses_template_parms (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
880 /* else fall through */
883 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
891 for (i
= tree_code_length
[(int) TREE_CODE (t
)]; --i
>= 0;)
892 if (uses_template_parms (TREE_OPERAND (t
, i
)))
899 sorry ("testing %s for template parms",
900 tree_code_name
[(int) TREE_CODE (t
)]);
901 my_friendly_abort (82);
907 static struct tinst_level
*current_tinst_level
= 0;
908 static struct tinst_level
*free_tinst_level
= 0;
909 static int tinst_depth
= 0;
910 int max_tinst_depth
= 17;
911 #ifdef GATHER_STATISTICS
912 int depth_reached
= 0;
919 struct tinst_level
*new;
921 if (tinst_depth
>= max_tinst_depth
)
923 struct tinst_level
*p
= current_tinst_level
;
925 char *file
= input_filename
;
927 error ("template instantiation depth exceeds maximum of %d",
929 cp_error (" instantiating `%D'", d
);
931 for (; p
; p
= p
->next
)
933 cp_error (" instantiated from `%D'", p
->decl
);
935 input_filename
= p
->file
;
937 error (" instantiated from here");
940 input_filename
= file
;
945 if (free_tinst_level
)
947 new = free_tinst_level
;
948 free_tinst_level
= new->next
;
951 new = (struct tinst_level
*) xmalloc (sizeof (struct tinst_level
));
955 new->file
= input_filename
;
956 new->next
= current_tinst_level
;
957 current_tinst_level
= new;
960 #ifdef GATHER_STATISTICS
961 if (tinst_depth
> depth_reached
)
962 depth_reached
= tinst_depth
;
971 struct tinst_level
*old
= current_tinst_level
;
973 current_tinst_level
= old
->next
;
974 old
->next
= free_tinst_level
;
975 free_tinst_level
= old
;
982 struct tinst_level
*p
= current_tinst_level
;
985 for (; p
->next
; p
= p
->next
)
991 instantiate_class_template (type
)
994 tree
template, template_info
, args
, pattern
, t
, *field_chain
;
996 if (type
== error_mark_node
)
997 return error_mark_node
;
999 template_info
= CLASSTYPE_TEMPLATE_INFO (type
);
1001 if (TYPE_BEING_DEFINED (type
) || TYPE_SIZE (type
))
1004 template = TI_TEMPLATE (template_info
);
1005 my_friendly_assert (TREE_CODE (template) == TEMPLATE_DECL
, 279);
1006 args
= TI_ARGS (template_info
);
1007 pattern
= TREE_TYPE (template);
1009 if (TYPE_SIZE (pattern
) == NULL_TREE
)
1012 TYPE_BEING_DEFINED (type
) = 1;
1014 if (! push_tinst_level (type
))
1017 maybe_push_to_top_level (uses_template_parms (type
));
1018 pushclass (type
, 0);
1020 if (flag_external_templates
)
1022 if (flag_alt_external_templates
)
1024 CLASSTYPE_INTERFACE_ONLY (type
) = interface_only
;
1025 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (type
, interface_unknown
);
1026 CLASSTYPE_VTABLE_NEEDS_WRITING (type
)
1027 = ! CLASSTYPE_INTERFACE_ONLY (type
)
1028 && CLASSTYPE_INTERFACE_KNOWN (type
);
1032 CLASSTYPE_INTERFACE_ONLY (type
) = CLASSTYPE_INTERFACE_ONLY (pattern
);
1033 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1034 (type
, CLASSTYPE_INTERFACE_UNKNOWN (pattern
));
1035 CLASSTYPE_VTABLE_NEEDS_WRITING (type
)
1036 = ! CLASSTYPE_INTERFACE_ONLY (type
)
1037 && CLASSTYPE_INTERFACE_KNOWN (type
);
1042 SET_CLASSTYPE_INTERFACE_UNKNOWN (type
);
1043 CLASSTYPE_VTABLE_NEEDS_WRITING (type
) = 1;
1047 tree binfo
= TYPE_BINFO (type
);
1048 tree pbases
= TYPE_BINFO_BASETYPES (pattern
);
1054 int len
= TREE_VEC_LENGTH (pbases
);
1055 BINFO_BASETYPES (binfo
) = bases
= make_tree_vec (len
);
1056 for (i
= 0; i
< len
; ++i
)
1060 TREE_VEC_ELT (bases
, i
) = elt
1061 = tsubst (TREE_VEC_ELT (pbases
, i
), &TREE_VEC_ELT (args
, 0),
1062 TREE_VEC_LENGTH (args
), NULL_TREE
);
1063 BINFO_INHERITANCE_CHAIN (elt
) = binfo
;
1065 if (! uses_template_parms (type
) &&
1066 TYPE_SIZE (complete_type (TREE_TYPE (elt
))) == NULL_TREE
)
1067 cp_error ("base class `%T' of `%T' has incomplete type",
1068 TREE_TYPE (elt
), type
);
1073 CLASSTYPE_LOCAL_TYPEDECLS (type
) = CLASSTYPE_LOCAL_TYPEDECLS (pattern
);
1075 field_chain
= &TYPE_FIELDS (type
);
1077 for (t
= CLASSTYPE_TAGS (pattern
); t
; t
= TREE_CHAIN (t
))
1079 tree name
= TREE_PURPOSE (t
);
1080 tree tag
= TREE_VALUE (t
);
1083 /* These will add themselves to CLASSTYPE_TAGS for the new type. */
1084 if (TREE_CODE (tag
) == ENUMERAL_TYPE
)
1085 newtag
= start_enum (name
);
1087 newtag
= tsubst (tag
, &TREE_VEC_ELT (args
, 0),
1088 TREE_VEC_LENGTH (args
), NULL_TREE
);
1090 if (TREE_CODE (tag
) == ENUMERAL_TYPE
)
1092 tree e
, values
= NULL_TREE
, *last
= &values
;
1094 for (e
= TYPE_VALUES (tag
); e
; e
= TREE_CHAIN (e
))
1096 tree elt
= build_enumerator
1098 tsubst_expr (TREE_VALUE (e
), &TREE_VEC_ELT (args
, 0),
1099 TREE_VEC_LENGTH (args
), NULL_TREE
));
1100 DECL_FIELD_CONTEXT (TREE_VALUE (elt
)) = type
;
1102 last
= &TREE_CHAIN (elt
);
1105 finish_enum (newtag
, values
);
1107 *field_chain
= grok_enum_decls (newtag
, NULL_TREE
);
1108 while (*field_chain
)
1109 field_chain
= &TREE_CHAIN (*field_chain
);
1113 /* Don't replace enum constants here. */
1114 for (t
= TYPE_FIELDS (pattern
); t
; t
= TREE_CHAIN (t
))
1115 if (TREE_CODE (t
) != CONST_DECL
)
1117 tree r
= tsubst (t
, &TREE_VEC_ELT (args
, 0),
1118 TREE_VEC_LENGTH (args
), NULL_TREE
);
1119 if (TREE_CODE (r
) == VAR_DECL
)
1121 if (! uses_template_parms (r
))
1122 pending_statics
= perm_tree_cons (NULL_TREE
, r
, pending_statics
);
1123 /* Perhaps I should do more of grokfield here. */
1125 DECL_IN_AGGR_P (r
) = 1;
1126 DECL_EXTERNAL (r
) = 1;
1127 cp_finish_decl (r
, DECL_INITIAL (r
), NULL_TREE
, 0, 0);
1131 field_chain
= &TREE_CHAIN (r
);
1134 TYPE_METHODS (type
) = tsubst_chain (TYPE_METHODS (pattern
), args
);
1136 DECL_FRIENDLIST (TYPE_MAIN_DECL (type
))
1137 = tsubst (DECL_FRIENDLIST (TYPE_MAIN_DECL (pattern
)),
1138 &TREE_VEC_ELT (args
, 0), TREE_VEC_LENGTH (args
), NULL_TREE
);
1141 tree d
= CLASSTYPE_FRIEND_CLASSES (type
) =
1142 tsubst (CLASSTYPE_FRIEND_CLASSES (pattern
), &TREE_VEC_ELT (args
, 0),
1143 TREE_VEC_LENGTH (args
), NULL_TREE
);
1145 /* This does injection for friend classes. */
1146 for (; d
; d
= TREE_CHAIN (d
))
1147 TREE_VALUE (d
) = xref_tag_from_type (TREE_VALUE (d
), NULL_TREE
, 1);
1149 d
= tsubst (DECL_TEMPLATE_INJECT (template), &TREE_VEC_ELT (args
, 0),
1150 TREE_VEC_LENGTH (args
), NULL_TREE
);
1152 for (; d
; d
= TREE_CHAIN (d
))
1154 tree t
= TREE_VALUE (d
);
1156 if (TREE_CODE (t
) == TYPE_DECL
)
1157 /* Already injected. */;
1163 TYPE_HAS_CONSTRUCTOR (type
) = TYPE_HAS_CONSTRUCTOR (pattern
);
1164 TYPE_HAS_DESTRUCTOR (type
) = TYPE_HAS_DESTRUCTOR (pattern
);
1165 TYPE_HAS_ASSIGNMENT (type
) = TYPE_HAS_ASSIGNMENT (pattern
);
1166 TYPE_OVERLOADS_CALL_EXPR (type
) = TYPE_OVERLOADS_CALL_EXPR (pattern
);
1167 TYPE_OVERLOADS_ARRAY_REF (type
) = TYPE_OVERLOADS_ARRAY_REF (pattern
);
1168 TYPE_OVERLOADS_ARROW (type
) = TYPE_OVERLOADS_ARROW (pattern
);
1169 TYPE_GETS_NEW (type
) = TYPE_GETS_NEW (pattern
);
1170 TYPE_GETS_DELETE (type
) = TYPE_GETS_DELETE (pattern
);
1171 TYPE_VEC_DELETE_TAKES_SIZE (type
) = TYPE_VEC_DELETE_TAKES_SIZE (pattern
);
1172 TYPE_HAS_ASSIGN_REF (type
) = TYPE_HAS_ASSIGN_REF (pattern
);
1173 TYPE_HAS_CONST_ASSIGN_REF (type
) = TYPE_HAS_CONST_ASSIGN_REF (pattern
);
1174 TYPE_HAS_ABSTRACT_ASSIGN_REF (type
) = TYPE_HAS_ABSTRACT_ASSIGN_REF (pattern
);
1175 TYPE_HAS_INIT_REF (type
) = TYPE_HAS_INIT_REF (pattern
);
1176 TYPE_HAS_CONST_INIT_REF (type
) = TYPE_HAS_CONST_INIT_REF (pattern
);
1177 TYPE_GETS_INIT_AGGR (type
) = TYPE_GETS_INIT_AGGR (pattern
);
1178 TYPE_HAS_DEFAULT_CONSTRUCTOR (type
) = TYPE_HAS_DEFAULT_CONSTRUCTOR (pattern
);
1179 TYPE_HAS_CONVERSION (type
) = TYPE_HAS_CONVERSION (pattern
);
1180 TYPE_USES_COMPLEX_INHERITANCE (type
)
1181 = TYPE_USES_COMPLEX_INHERITANCE (pattern
);
1182 TYPE_USES_VIRTUAL_BASECLASSES (type
)
1183 = TYPE_USES_VIRTUAL_BASECLASSES (pattern
);
1184 TYPE_PACKED (type
) = TYPE_PACKED (pattern
);
1185 TYPE_ALIGN (type
) = TYPE_ALIGN (pattern
);
1187 if (! uses_template_parms (type
))
1190 for (tmp
= TYPE_FIELDS (type
); tmp
; tmp
= TREE_CHAIN (tmp
))
1191 if (TREE_CODE (tmp
) == FIELD_DECL
)
1193 TREE_TYPE (tmp
) = complete_type (TREE_TYPE (tmp
));
1194 require_complete_type (tmp
);
1197 type
= finish_struct_1 (type
, 0);
1198 CLASSTYPE_GOT_SEMICOLON (type
) = 1;
1199 if (at_eof
&& TYPE_BINFO_VTABLE (type
) != NULL_TREE
)
1200 finish_prevtable_vardecl (NULL
, TYPE_BINFO_VTABLE (type
));
1202 repo_template_used (type
);
1206 TYPE_SIZE (type
) = integer_zero_node
;
1207 CLASSTYPE_METHOD_VEC (type
)
1208 = finish_struct_methods (type
, TYPE_METHODS (type
), 1);
1211 TYPE_BEING_DEFINED (type
) = 0;
1214 pop_from_top_level ();
1224 if (t1
== NULL_TREE
)
1225 return t2
== NULL_TREE
;
1226 if (t2
== NULL_TREE
)
1228 /* Don't care if one declares its arg const and the other doesn't -- the
1229 main variant of the arg type is all that matters. */
1230 if (TYPE_MAIN_VARIANT (TREE_VALUE (t1
))
1231 != TYPE_MAIN_VARIANT (TREE_VALUE (t2
)))
1233 return list_eq (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
1237 lookup_nested_type_by_name (ctype
, name
)
1242 complete_type (ctype
);
1244 for (t
= CLASSTYPE_TAGS (ctype
); t
; t
= TREE_CHAIN (t
))
1246 if (name
== TREE_PURPOSE (t
))
1247 return TREE_VALUE (t
);
1253 tsubst (t
, args
, nargs
, in_decl
)
1260 if (t
== NULL_TREE
|| t
== error_mark_node
1261 || t
== integer_type_node
1262 || t
== void_type_node
1263 || t
== char_type_node
)
1266 type
= TREE_TYPE (t
);
1267 if (type
== unknown_type_node
)
1268 my_friendly_abort (42);
1269 if (type
&& TREE_CODE (t
) != FUNCTION_DECL
)
1270 type
= tsubst (type
, args
, nargs
, in_decl
);
1272 switch (TREE_CODE (t
))
1275 if (TYPE_PTRMEMFUNC_P (t
))
1277 tree r
= build_ptrmemfunc_type
1278 (tsubst (TYPE_PTRMEMFUNC_FN_TYPE (t
), args
, nargs
, in_decl
));
1279 return cp_build_type_variant (r
, TYPE_READONLY (t
),
1283 /* else fall through */
1285 if (uses_template_parms (t
))
1287 tree argvec
= tsubst (CLASSTYPE_TI_ARGS (t
), args
, nargs
, in_decl
);
1288 tree r
= lookup_template_class (t
, argvec
, in_decl
);
1289 return cp_build_type_variant (r
, TYPE_READONLY (t
),
1293 /* else fall through */
1295 case IDENTIFIER_NODE
:
1307 tree ctx
= tsubst (TYPE_CONTEXT (t
), args
, nargs
, in_decl
);
1308 if (ctx
== NULL_TREE
)
1311 return lookup_nested_type_by_name (ctx
, TYPE_IDENTIFIER (t
));
1315 if (t
== integer_type_node
)
1318 if (TREE_CODE (TYPE_MIN_VALUE (t
)) == INTEGER_CST
1319 && TREE_CODE (TYPE_MAX_VALUE (t
)) == INTEGER_CST
)
1323 tree max
= tsubst_expr (TYPE_MAX_VALUE (t
), args
, nargs
, in_decl
);
1324 if (current_template_parms
)
1326 tree itype
= make_node (INTEGER_TYPE
);
1327 TYPE_MIN_VALUE (itype
) = size_zero_node
;
1328 TYPE_MAX_VALUE (itype
) = max
;
1331 return build_index_2_type (size_zero_node
, max
);
1334 case TEMPLATE_TYPE_PARM
:
1336 tree arg
= args
[TEMPLATE_TYPE_IDX (t
)];
1337 return cp_build_type_variant
1338 (arg
, TYPE_READONLY (arg
) || TYPE_READONLY (t
),
1339 TYPE_VOLATILE (arg
) || TYPE_VOLATILE (t
));
1342 case TEMPLATE_CONST_PARM
:
1343 return args
[TEMPLATE_CONST_IDX (t
)];
1348 tree arg_types
, ctx
;
1352 if (DECL_CONTEXT (t
) != NULL_TREE
1353 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) == 't')
1355 if (DECL_NAME (t
) == constructor_name (DECL_CONTEXT (t
)))
1359 ctx
= tsubst (DECL_CLASS_CONTEXT (t
), args
, nargs
, t
);
1360 type
= tsubst (type
, args
, nargs
, in_decl
);
1366 type
= tsubst (type
, args
, nargs
, in_decl
);
1369 if (type
== TREE_TYPE (t
)
1370 && (! member
|| ctx
== DECL_CLASS_CONTEXT (t
)))
1373 /* Do we already have this instantiation? */
1374 if (DECL_TEMPLATE_INFO (t
) != NULL_TREE
)
1376 tree tmpl
= TREE_PURPOSE (DECL_TEMPLATE_INFO (t
));
1377 tree decls
= DECL_TEMPLATE_INSTANTIATIONS (tmpl
);
1379 for (; decls
; decls
= TREE_CHAIN (decls
))
1380 if (TREE_TYPE (TREE_VALUE (decls
)) == type
1381 && DECL_CLASS_CONTEXT (TREE_VALUE (decls
)) == ctx
)
1382 return TREE_VALUE (decls
);
1385 /* We do NOT check for matching decls pushed separately at this
1386 point, as they may not represent instantiations of this
1387 template, and in any case are considered separate under the
1392 TREE_TYPE (r
) = type
;
1395 = tsubst (DECL_CONTEXT (t
), args
, nargs
, t
);
1396 DECL_CLASS_CONTEXT (r
) = ctx
;
1398 if (member
&& !strncmp (OPERATOR_TYPENAME_FORMAT
,
1399 IDENTIFIER_POINTER (DECL_NAME (r
)),
1400 sizeof (OPERATOR_TYPENAME_FORMAT
) - 1))
1402 /* Type-conversion operator. Reconstruct the name, in
1403 case it's the name of one of the template's parameters. */
1404 DECL_NAME (r
) = build_typename_overload (TREE_TYPE (type
));
1407 arg_types
= TYPE_VALUES (type
);
1409 if (member
&& TREE_CODE (type
) == FUNCTION_TYPE
)
1410 arg_types
= hash_tree_chain
1411 (build_pointer_type (DECL_CONTEXT (r
)), arg_types
);
1413 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t
)))
1415 char *buf
, *dbuf
= build_overload_name (ctx
, 1, 1);
1416 int len
= sizeof (DESTRUCTOR_DECL_PREFIX
) - 1;
1417 buf
= (char *) alloca (strlen (dbuf
)
1418 + sizeof (DESTRUCTOR_DECL_PREFIX
));
1419 bcopy (DESTRUCTOR_DECL_PREFIX
, buf
, len
);
1422 DECL_ASSEMBLER_NAME (r
) = get_identifier (buf
);
1425 DECL_ASSEMBLER_NAME (r
)
1426 = build_decl_overload (DECL_NAME (r
), arg_types
, member
);
1428 make_decl_rtl (r
, NULL_PTR
, 1);
1430 DECL_ARGUMENTS (r
) = tsubst (DECL_ARGUMENTS (t
), args
, nargs
, t
);
1431 DECL_MAIN_VARIANT (r
) = r
;
1432 DECL_RESULT (r
) = NULL_TREE
;
1433 DECL_INITIAL (r
) = NULL_TREE
;
1435 TREE_STATIC (r
) = 0;
1436 TREE_PUBLIC (r
) = 1;
1437 DECL_EXTERNAL (r
) = 1;
1438 DECL_INTERFACE_KNOWN (r
) = 0;
1439 DECL_DEFER_OUTPUT (r
) = 0;
1440 TREE_CHAIN (r
) = NULL_TREE
;
1441 DECL_CHAIN (r
) = NULL_TREE
;
1443 if (IDENTIFIER_OPNAME_P (DECL_NAME (r
)))
1444 grok_op_properties (r
, DECL_VIRTUAL_P (r
), DECL_FRIEND_P (r
));
1446 /* Look for matching decls for the moment. */
1449 tree decls
= lookup_name_nonclass (DECL_NAME (t
));
1452 if (decls
== NULL_TREE
)
1454 else if (is_overloaded_fn (decls
))
1455 for (decls
= get_first_fn (decls
); decls
;
1456 decls
= DECL_CHAIN (decls
))
1458 if (TREE_CODE (decls
) == FUNCTION_DECL
1459 && TREE_TYPE (decls
) == type
)
1468 int dcl_only
= ! DECL_INITIAL (d
);
1470 DECL_INITIAL (r
) = error_mark_node
;
1471 duplicate_decls (r
, d
);
1474 DECL_INITIAL (r
) = 0;
1478 if (DECL_TEMPLATE_INFO (t
) != NULL_TREE
)
1480 tree tmpl
= DECL_TI_TEMPLATE (t
);
1481 tree
*declsp
= &DECL_TEMPLATE_INSTANTIATIONS (tmpl
);
1482 tree argvec
= tsubst (TREE_VALUE (DECL_TEMPLATE_INFO (t
)),
1483 args
, nargs
, in_decl
);
1485 DECL_TEMPLATE_INFO (r
) = perm_tree_cons (tmpl
, argvec
, NULL_TREE
);
1486 *declsp
= perm_tree_cons (argvec
, r
, *declsp
);
1488 /* If we have a preexisting version of this function, don't expand
1489 the template version, use the other instead. */
1490 if (TREE_STATIC (r
) || DECL_TEMPLATE_SPECIALIZATION (r
))
1491 SET_DECL_TEMPLATE_SPECIALIZATION (r
);
1493 SET_DECL_IMPLICIT_INSTANTIATION (r
);
1495 DECL_TEMPLATE_INSTANTIATIONS (tmpl
) =
1496 tree_cons (argvec
, r
, DECL_TEMPLATE_INSTANTIATIONS (tmpl
));
1499 /* Like grokfndecl. If we don't do this, pushdecl will mess up our
1500 TREE_CHAIN because it doesn't find a previous decl. Sigh. */
1502 && IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (r
)) == NULL_TREE
)
1503 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (r
)) = r
;
1510 tree r
= copy_node (t
);
1511 TREE_TYPE (r
) = type
;
1512 DECL_INITIAL (r
) = TREE_TYPE (r
);
1513 DECL_CONTEXT (r
) = NULL_TREE
;
1514 #ifdef PROMOTE_PROTOTYPES
1515 if ((TREE_CODE (type
) == INTEGER_TYPE
1516 || TREE_CODE (type
) == ENUMERAL_TYPE
)
1517 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
1518 DECL_ARG_TYPE (r
) = integer_type_node
;
1521 TREE_CHAIN (r
) = tsubst (TREE_CHAIN (t
), args
, nargs
, TREE_CHAIN (t
));
1527 tree r
= copy_node (t
);
1528 TREE_TYPE (r
) = type
;
1531 DECL_FIELD_CONTEXT (r
) = tsubst (DECL_FIELD_CONTEXT (t
), args
, nargs
, in_decl
);
1533 DECL_INITIAL (r
) = tsubst_expr (DECL_INITIAL (t
), args
, nargs
, in_decl
);
1534 TREE_CHAIN (r
) = NULL_TREE
;
1540 tree r
= copy_node (t
);
1542 = tsubst_copy (DECL_INITIAL (t
), args
, nargs
, in_decl
);
1543 TREE_CHAIN (r
) = NULL_TREE
;
1550 tree ctx
= tsubst_copy (DECL_CONTEXT (t
), args
, nargs
, in_decl
);
1552 /* Do we already have this instantiation? */
1553 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
))
1555 tree tmpl
= DECL_TI_TEMPLATE (t
);
1556 tree decls
= DECL_TEMPLATE_INSTANTIATIONS (tmpl
);
1558 for (; decls
; decls
= TREE_CHAIN (decls
))
1559 if (DECL_CONTEXT (TREE_VALUE (decls
)) == ctx
)
1560 return TREE_VALUE (decls
);
1564 TREE_TYPE (r
) = type
;
1565 DECL_CONTEXT (r
) = ctx
;
1566 if (TREE_STATIC (r
))
1567 DECL_ASSEMBLER_NAME (r
)
1568 = build_static_name (DECL_CONTEXT (r
), DECL_NAME (r
));
1569 DECL_INITIAL (r
) = tsubst_expr
1570 (DECL_INITIAL (t
), args
, nargs
, in_decl
);
1575 if (DECL_LANG_SPECIFIC (r
))
1578 DECL_CLASS_CONTEXT (r
) = DECL_CONTEXT (r
);
1581 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
))
1583 tree tmpl
= DECL_TI_TEMPLATE (t
);
1584 tree
*declsp
= &DECL_TEMPLATE_INSTANTIATIONS (tmpl
);
1585 tree argvec
= tsubst (TREE_VALUE (DECL_TEMPLATE_INFO (t
)),
1586 args
, nargs
, in_decl
);
1588 DECL_TEMPLATE_INFO (r
) = perm_tree_cons (tmpl
, argvec
, NULL_TREE
);
1589 *declsp
= perm_tree_cons (argvec
, r
, *declsp
);
1590 SET_DECL_IMPLICIT_INSTANTIATION (r
);
1592 TREE_CHAIN (r
) = NULL_TREE
;
1598 tree r
= copy_node (t
);
1599 TREE_TYPE (r
) = type
;
1600 DECL_CONTEXT (r
) = current_class_type
;
1601 TREE_CHAIN (r
) = NULL_TREE
;
1607 tree purpose
, value
, chain
, result
;
1608 int via_public
, via_virtual
, via_protected
;
1610 if (t
== void_list_node
)
1613 via_public
= TREE_VIA_PUBLIC (t
);
1614 via_protected
= TREE_VIA_PROTECTED (t
);
1615 via_virtual
= TREE_VIA_VIRTUAL (t
);
1617 purpose
= TREE_PURPOSE (t
);
1619 purpose
= tsubst (purpose
, args
, nargs
, in_decl
);
1620 value
= TREE_VALUE (t
);
1622 value
= tsubst (value
, args
, nargs
, in_decl
);
1623 chain
= TREE_CHAIN (t
);
1624 if (chain
&& chain
!= void_type_node
)
1625 chain
= tsubst (chain
, args
, nargs
, in_decl
);
1626 if (purpose
== TREE_PURPOSE (t
)
1627 && value
== TREE_VALUE (t
)
1628 && chain
== TREE_CHAIN (t
))
1630 result
= hash_tree_cons (via_public
, via_virtual
, via_protected
,
1631 purpose
, value
, chain
);
1632 TREE_PARMLIST (result
) = TREE_PARMLIST (t
);
1636 if (type
!= NULL_TREE
)
1640 if (type
== TREE_TYPE (t
))
1643 TREE_TYPE (t
) = complete_type (type
);
1644 BINFO_VTABLE (t
) = TYPE_BINFO_VTABLE (type
);
1645 BINFO_VIRTUALS (t
) = TYPE_BINFO_VIRTUALS (type
);
1646 if (TYPE_BINFO_BASETYPES (type
) != NULL_TREE
)
1647 BINFO_BASETYPES (t
) = copy_node (TYPE_BINFO_BASETYPES (type
));
1652 int len
= TREE_VEC_LENGTH (t
), need_new
= 0, i
;
1653 tree
*elts
= (tree
*) alloca (len
* sizeof (tree
));
1655 bzero ((char *) elts
, len
* sizeof (tree
));
1657 for (i
= 0; i
< len
; i
++)
1659 elts
[i
] = tsubst_expr (TREE_VEC_ELT (t
, i
), args
, nargs
, in_decl
);
1660 if (elts
[i
] != TREE_VEC_ELT (t
, i
))
1667 t
= make_tree_vec (len
);
1668 for (i
= 0; i
< len
; i
++)
1669 TREE_VEC_ELT (t
, i
) = elts
[i
];
1674 case REFERENCE_TYPE
:
1677 enum tree_code code
;
1678 if (type
== TREE_TYPE (t
))
1681 code
= TREE_CODE (t
);
1682 if (code
== POINTER_TYPE
)
1683 r
= build_pointer_type (type
);
1685 r
= build_reference_type (type
);
1686 r
= cp_build_type_variant (r
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1687 /* Will this ever be needed for TYPE_..._TO values? */
1692 return build_offset_type
1693 (tsubst (TYPE_OFFSET_BASETYPE (t
), args
, nargs
, in_decl
), type
);
1697 tree values
= TYPE_ARG_TYPES (t
);
1698 tree context
= TYPE_CONTEXT (t
);
1701 /* Don't bother recursing if we know it won't change anything. */
1702 if (values
!= void_list_node
)
1704 /* This should probably be rewritten to use hash_tree_cons for
1705 the memory savings. */
1706 tree first
= NULL_TREE
;
1709 for (; values
&& values
!= void_list_node
;
1710 values
= TREE_CHAIN (values
))
1713 = tsubst (TREE_VALUE (values
), args
, nargs
, in_decl
);
1714 tree purpose
= tsubst_expr (TREE_PURPOSE (values
),
1715 args
, nargs
, in_decl
);
1716 tree x
= build_tree_list (purpose
, value
);
1719 TREE_CHAIN (last
) = x
;
1725 if (values
== void_list_node
)
1726 TREE_CHAIN (last
) = void_list_node
;
1731 context
= tsubst (context
, args
, nargs
, in_decl
);
1732 /* Could also optimize cases where return value and
1733 values have common elements (e.g., T min(const &T, const T&). */
1735 /* If the above parameters haven't changed, just return the type. */
1736 if (type
== TREE_TYPE (t
)
1737 && values
== TYPE_VALUES (t
)
1738 && context
== TYPE_CONTEXT (t
))
1741 /* Construct a new type node and return it. */
1742 if (TREE_CODE (t
) == FUNCTION_TYPE
1743 && context
== NULL_TREE
)
1745 new_value
= build_function_type (type
, values
);
1747 else if (context
== NULL_TREE
)
1749 tree base
= tsubst (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))),
1750 args
, nargs
, in_decl
);
1751 new_value
= build_cplus_method_type (base
, type
,
1752 TREE_CHAIN (values
));
1756 new_value
= make_node (TREE_CODE (t
));
1757 TREE_TYPE (new_value
) = type
;
1758 TYPE_CONTEXT (new_value
) = context
;
1759 TYPE_VALUES (new_value
) = values
;
1760 TYPE_SIZE (new_value
) = TYPE_SIZE (t
);
1761 TYPE_ALIGN (new_value
) = TYPE_ALIGN (t
);
1762 TYPE_MODE (new_value
) = TYPE_MODE (t
);
1763 if (TYPE_METHOD_BASETYPE (t
))
1764 TYPE_METHOD_BASETYPE (new_value
) = tsubst (TYPE_METHOD_BASETYPE (t
),
1765 args
, nargs
, in_decl
);
1766 /* Need to generate hash value. */
1767 my_friendly_abort (84);
1769 new_value
= build_type_variant (new_value
,
1776 tree domain
= tsubst (TYPE_DOMAIN (t
), args
, nargs
, in_decl
);
1778 if (type
== TREE_TYPE (t
) && domain
== TYPE_DOMAIN (t
))
1780 r
= build_cplus_array_type (type
, domain
);
1786 return fold (build (TREE_CODE (t
), TREE_TYPE (t
),
1787 tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
1788 tsubst (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
)));
1792 return fold (build1 (TREE_CODE (t
), TREE_TYPE (t
),
1793 tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
)));
1797 tree ctx
= tsubst (TYPE_CONTEXT (t
), args
, nargs
, in_decl
);
1798 tree f
= make_typename_type (ctx
, TYPE_IDENTIFIER (t
));
1799 return cp_build_type_variant
1800 (f
, TYPE_READONLY (f
) || TYPE_READONLY (t
),
1801 TYPE_VOLATILE (f
) || TYPE_VOLATILE (t
));
1805 return make_pointer_declarator
1806 (type
, tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
));
1809 return make_reference_declarator
1810 (type
, tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
));
1813 return build_parse_node
1814 (ARRAY_REF
, tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
1815 tsubst_expr (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
));
1818 return build_parse_node
1819 (CALL_EXPR
, tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
1820 tsubst (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
), NULL_TREE
);
1823 return build_parse_node
1824 (TREE_CODE (t
), tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
1825 tsubst (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
));
1828 sorry ("use of `%s' in template",
1829 tree_code_name
[(int) TREE_CODE (t
)]);
1830 return error_mark_node
;
1837 emit_line_note (input_filename
, lineno
);
1841 expand_start_bindings (0);
1849 expand_end_bindings (getdecls (), kept_level_p (), 1);
1850 t
= poplevel (kept_level_p (), 1, 0);
1856 tsubst_copy (t
, args
, nargs
, in_decl
)
1861 enum tree_code code
;
1863 if (t
== NULL_TREE
|| t
== error_mark_node
)
1866 code
= TREE_CODE (t
);
1871 return do_identifier (DECL_NAME (t
), 0);
1875 if (DECL_CONTEXT (t
))
1877 tree ctx
= tsubst (DECL_CONTEXT (t
), args
, nargs
, in_decl
);
1878 if (ctx
!= DECL_CONTEXT (t
))
1879 return lookup_field (ctx
, DECL_NAME (t
), 0, 0);
1885 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
))
1886 t
= tsubst (t
, args
, nargs
, in_decl
);
1891 case IDENTIFIER_NODE
:
1892 return do_identifier (t
, 0);
1896 case REINTERPRET_CAST_EXPR
:
1897 case CONST_CAST_EXPR
:
1898 case STATIC_CAST_EXPR
:
1899 case DYNAMIC_CAST_EXPR
:
1901 (code
, tsubst (TREE_TYPE (t
), args
, nargs
, in_decl
),
1902 tsubst_copy (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
));
1905 case PREDECREMENT_EXPR
:
1906 case PREINCREMENT_EXPR
:
1907 case POSTDECREMENT_EXPR
:
1908 case POSTINCREMENT_EXPR
:
1910 case TRUTH_NOT_EXPR
:
1912 case CONVERT_EXPR
: /* Unary + */
1918 tsubst_copy (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
));
1923 case TRUNC_DIV_EXPR
:
1925 case FLOOR_DIV_EXPR
:
1926 case ROUND_DIV_EXPR
:
1927 case EXACT_DIV_EXPR
:
1929 case BIT_ANDTC_EXPR
:
1932 case TRUNC_MOD_EXPR
:
1933 case FLOOR_MOD_EXPR
:
1934 case TRUTH_ANDIF_EXPR
:
1935 case TRUTH_ORIF_EXPR
:
1936 case TRUTH_AND_EXPR
:
1957 (code
, tsubst_copy (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
1958 tsubst_copy (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
));
1962 tree fn
= TREE_OPERAND (t
, 0);
1963 if (really_overloaded_fn (fn
))
1964 fn
= tsubst_copy (TREE_VALUE (fn
), args
, nargs
, in_decl
);
1966 fn
= tsubst_copy (fn
, args
, nargs
, in_decl
);
1968 (code
, fn
, tsubst_copy (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
),
1972 case METHOD_CALL_EXPR
:
1974 tree name
= TREE_OPERAND (t
, 0);
1975 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1977 name
= tsubst_copy (TREE_OPERAND (name
, 0), args
, nargs
, in_decl
);
1978 name
= build1 (BIT_NOT_EXPR
, NULL_TREE
, TYPE_MAIN_VARIANT (name
));
1980 else if (TREE_CODE (name
) == SCOPE_REF
1981 && TREE_CODE (TREE_OPERAND (name
, 1)) == BIT_NOT_EXPR
)
1983 tree base
= tsubst_copy (TREE_OPERAND (name
, 0), args
, nargs
, in_decl
);
1984 name
= TREE_OPERAND (name
, 1);
1985 name
= tsubst_copy (TREE_OPERAND (name
, 0), args
, nargs
, in_decl
);
1986 name
= build1 (BIT_NOT_EXPR
, NULL_TREE
, TYPE_MAIN_VARIANT (name
));
1987 name
= build_nt (SCOPE_REF
, base
, name
);
1990 name
= tsubst_copy (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
);
1992 (code
, name
, tsubst_copy (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
),
1993 tsubst_copy (TREE_OPERAND (t
, 2), args
, nargs
, in_decl
),
2000 (code
, tsubst_copy (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
2001 tsubst_copy (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
),
2002 tsubst_copy (TREE_OPERAND (t
, 2), args
, nargs
, in_decl
));
2007 (code
, tsubst_copy (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
2008 tsubst_copy (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
),
2009 tsubst_copy (TREE_OPERAND (t
, 2), args
, nargs
, in_decl
));
2010 NEW_EXPR_USE_GLOBAL (r
) = NEW_EXPR_USE_GLOBAL (t
);
2017 (code
, tsubst_copy (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
2018 tsubst_copy (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
));
2019 DELETE_EXPR_USE_GLOBAL (r
) = DELETE_EXPR_USE_GLOBAL (t
);
2020 DELETE_EXPR_USE_VEC (r
) = DELETE_EXPR_USE_VEC (t
);
2026 tree purpose
, value
, chain
;
2028 if (t
== void_list_node
)
2031 purpose
= TREE_PURPOSE (t
);
2033 purpose
= tsubst_copy (purpose
, args
, nargs
, in_decl
);
2034 value
= TREE_VALUE (t
);
2036 value
= tsubst_copy (value
, args
, nargs
, in_decl
);
2037 chain
= TREE_CHAIN (t
);
2038 if (chain
&& chain
!= void_type_node
)
2039 chain
= tsubst_copy (chain
, args
, nargs
, in_decl
);
2040 if (purpose
== TREE_PURPOSE (t
)
2041 && value
== TREE_VALUE (t
)
2042 && chain
== TREE_CHAIN (t
))
2044 return tree_cons (purpose
, value
, chain
);
2051 case TEMPLATE_TYPE_PARM
:
2052 case TEMPLATE_CONST_PARM
:
2054 case REFERENCE_TYPE
:
2060 return tsubst (t
, args
, nargs
, in_decl
);
2062 case IDENTIFIER_NODE
:
2063 if (IDENTIFIER_TYPENAME_P (t
))
2064 return build_typename_overload
2065 (tsubst (TREE_TYPE (t
), args
, nargs
, in_decl
));
2075 tsubst_expr (t
, args
, nargs
, in_decl
)
2080 if (t
== NULL_TREE
|| t
== error_mark_node
)
2083 if (current_template_parms
)
2084 return tsubst_copy (t
, args
, nargs
, in_decl
);
2086 switch (TREE_CODE (t
))
2089 lineno
= TREE_COMPLEXITY (t
);
2090 emit_line_note (input_filename
, lineno
);
2092 (tsubst_expr (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
));
2097 lineno
= TREE_COMPLEXITY (t
);
2098 emit_line_note (input_filename
, lineno
);
2099 t
= tsubst_expr (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
);
2100 /* Do default conversion if safe and possibly important,
2101 in case within ({...}). */
2102 if ((TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
&& lvalue_p (t
))
2103 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
2104 t
= default_conversion (t
);
2105 cplus_expand_expr_stmt (t
);
2112 int i
= suspend_momentary ();
2115 lineno
= TREE_COMPLEXITY (t
);
2116 emit_line_note (input_filename
, lineno
);
2118 (tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
2119 tsubst (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
),
2120 TREE_OPERAND (t
, 3) != 0,
2121 tsubst (TREE_OPERAND (t
, 2), args
, nargs
, in_decl
));
2122 init
= tsubst_expr (TREE_OPERAND (t
, 3), args
, nargs
, in_decl
);
2124 (dcl
, init
, NULL_TREE
, 1, /*init ? LOOKUP_ONLYCONVERTING :*/ 0);
2125 resume_momentary (i
);
2132 int init_scope
= (flag_new_for_scope
> 0 && TREE_OPERAND (t
, 0)
2133 && TREE_CODE (TREE_OPERAND (t
, 0)) == DECL_STMT
);
2134 int cond_scope
= (TREE_OPERAND (t
, 1)
2135 && TREE_CODE (TREE_OPERAND (t
, 1)) == DECL_STMT
);
2137 lineno
= TREE_COMPLEXITY (t
);
2138 emit_line_note (input_filename
, lineno
);
2141 for (tmp
= TREE_OPERAND (t
, 0); tmp
; tmp
= TREE_CHAIN (tmp
))
2142 tsubst_expr (tmp
, args
, nargs
, in_decl
);
2144 emit_line_note (input_filename
, lineno
);
2145 expand_start_loop_continue_elsewhere (1);
2149 tmp
= tsubst_expr (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
);
2150 emit_line_note (input_filename
, lineno
);
2152 expand_exit_loop_if_false (0, condition_conversion (tmp
));
2156 tsubst_expr (TREE_OPERAND (t
, 3), args
, nargs
, in_decl
);
2159 emit_line_note (input_filename
, lineno
);
2160 expand_loop_continue_here ();
2161 tmp
= tsubst_expr (TREE_OPERAND (t
, 2), args
, nargs
, in_decl
);
2163 cplus_expand_expr_stmt (tmp
);
2176 lineno
= TREE_COMPLEXITY (t
);
2178 emit_line_note (input_filename
, lineno
);
2179 expand_start_loop (1);
2181 cond
= TREE_OPERAND (t
, 0);
2182 if (TREE_CODE (cond
) == DECL_STMT
)
2184 cond
= tsubst_expr (cond
, args
, nargs
, in_decl
);
2185 emit_line_note (input_filename
, lineno
);
2186 expand_exit_loop_if_false (0, condition_conversion (cond
));
2188 if (TREE_CODE (TREE_OPERAND (t
, 0)) != DECL_STMT
)
2190 tsubst_expr (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
);
2202 lineno
= TREE_COMPLEXITY (t
);
2204 emit_line_note (input_filename
, lineno
);
2205 expand_start_loop_continue_elsewhere (1);
2207 tsubst_expr (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
);
2208 expand_loop_continue_here ();
2210 cond
= tsubst_expr (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
);
2211 emit_line_note (input_filename
, lineno
);
2212 expand_exit_loop_if_false (0, condition_conversion (cond
));
2223 int cond_scope
= (TREE_CODE (TREE_OPERAND (t
, 0)) == DECL_STMT
);
2225 lineno
= TREE_COMPLEXITY (t
);
2228 tmp
= tsubst_expr (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
);
2229 emit_line_note (input_filename
, lineno
);
2230 expand_start_cond (condition_conversion (tmp
), 0);
2232 if (tmp
= TREE_OPERAND (t
, 1), tmp
)
2233 tsubst_expr (tmp
, args
, nargs
, in_decl
);
2235 if (tmp
= TREE_OPERAND (t
, 2), tmp
)
2237 expand_start_else ();
2238 tsubst_expr (tmp
, args
, nargs
, in_decl
);
2252 tree substmt
= TREE_OPERAND (t
, 0);
2254 lineno
= TREE_COMPLEXITY (t
);
2256 if (COMPOUND_STMT_NO_SCOPE (t
) == 0)
2259 for (; substmt
; substmt
= TREE_CHAIN (substmt
))
2260 tsubst_expr (substmt
, args
, nargs
, in_decl
);
2262 if (COMPOUND_STMT_NO_SCOPE (t
) == 0)
2268 lineno
= TREE_COMPLEXITY (t
);
2269 emit_line_note (input_filename
, lineno
);
2270 if (! expand_exit_something ())
2271 error ("break statement not within loop or switch");
2275 lineno
= TREE_COMPLEXITY (t
);
2276 emit_line_note (input_filename
, lineno
);
2277 if (! expand_continue_loop (0))
2278 error ("continue statement not within a loop");
2284 int cond_scope
= (TREE_CODE (TREE_OPERAND (t
, 0)) == DECL_STMT
);
2286 lineno
= TREE_COMPLEXITY (t
);
2289 val
= tsubst_expr (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
);
2290 emit_line_note (input_filename
, lineno
);
2291 c_expand_start_case (val
);
2294 if (tmp
= TREE_OPERAND (t
, 1), tmp
)
2295 tsubst_expr (tmp
, args
, nargs
, in_decl
);
2297 expand_end_case (val
);
2308 do_case (tsubst_expr (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
2309 tsubst_expr (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
));
2313 t
= define_label (DECL_SOURCE_FILE (t
), DECL_SOURCE_LINE (t
),
2320 lineno
= TREE_COMPLEXITY (t
);
2321 emit_line_note (input_filename
, lineno
);
2322 if (TREE_CODE (TREE_OPERAND (t
, 0)) == IDENTIFIER_NODE
)
2324 tree decl
= lookup_label (TREE_OPERAND (t
, 0));
2325 TREE_USED (decl
) = 1;
2329 expand_computed_goto
2330 (tsubst_expr (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
));
2334 return build_expr_from_tree (tsubst_copy (t
, args
, nargs
, in_decl
));
2340 instantiate_template (tmpl
, targ_ptr
)
2341 tree tmpl
, *targ_ptr
;
2345 struct obstack
*old_fmp_obstack
;
2346 extern struct obstack
*function_maybepermanent_obstack
;
2348 push_obstacks (&permanent_obstack
, &permanent_obstack
);
2349 old_fmp_obstack
= function_maybepermanent_obstack
;
2350 function_maybepermanent_obstack
= &permanent_obstack
;
2352 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 283);
2353 len
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (tmpl
));
2358 tree t
= targ_ptr
[i
];
2359 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
2361 tree nt
= target_type (t
);
2362 if (IS_AGGR_TYPE (nt
) && decl_function_context (TYPE_MAIN_DECL (nt
)))
2364 cp_error ("type `%T' composed from a local class is not a valid template-argument", t
);
2365 cp_error (" trying to instantiate `%D'", tmpl
);
2366 fndecl
= error_mark_node
;
2370 targ_ptr
[i
] = copy_to_permanent (t
);
2373 /* substitute template parameters */
2374 fndecl
= tsubst (DECL_RESULT (tmpl
), targ_ptr
, len
, tmpl
);
2377 function_maybepermanent_obstack
= old_fmp_obstack
;
2383 /* Push the name of the class template into the scope of the instantiation. */
2386 overload_template_name (type
)
2389 tree id
= DECL_NAME (CLASSTYPE_TI_TEMPLATE (type
));
2392 if (IDENTIFIER_CLASS_VALUE (id
)
2393 && TREE_TYPE (IDENTIFIER_CLASS_VALUE (id
)) == type
)
2396 decl
= build_decl (TYPE_DECL
, id
, type
);
2397 SET_DECL_ARTIFICIAL (decl
);
2398 pushdecl_class_level (decl
);
2401 /* Type unification.
2403 We have a function template signature with one or more references to
2404 template parameters, and a parameter list we wish to fit to this
2405 template. If possible, produce a list of parameters for the template
2406 which will cause it to fit the supplied parameter list.
2408 Return zero for success, 2 for an incomplete match that doesn't resolve
2409 all the types, and 1 for complete failure. An error message will be
2410 printed only for an incomplete match.
2412 TPARMS[NTPARMS] is an array of template parameter types;
2413 TARGS[NTPARMS] is the array of template parameter values. PARMS is
2414 the function template's signature (using TEMPLATE_PARM_IDX nodes),
2415 and ARGS is the argument list we're trying to match against it.
2417 If SUBR is 1, we're being called recursively (to unify the arguments of
2418 a function or method parameter of a function template), so don't zero
2419 out targs and don't fail on an incomplete match.
2421 If STRICT is 1, the match must be exact (for casts of overloaded
2422 addresses, explicit instantiation, and more_specialized). */
2425 type_unification (tparms
, targs
, parms
, args
, nsubsts
, subr
, strict
)
2426 tree tparms
, *targs
, parms
, args
;
2427 int *nsubsts
, subr
, strict
;
2431 int ntparms
= TREE_VEC_LENGTH (tparms
);
2433 my_friendly_assert (TREE_CODE (tparms
) == TREE_VEC
, 289);
2434 my_friendly_assert (TREE_CODE (parms
) == TREE_LIST
, 290);
2435 /* ARGS could be NULL (via a call from parse.y to
2436 build_x_function_call). */
2438 my_friendly_assert (TREE_CODE (args
) == TREE_LIST
, 291);
2439 my_friendly_assert (ntparms
> 0, 292);
2442 bzero ((char *) targs
, sizeof (tree
) * ntparms
);
2445 && parms
!= void_list_node
2447 && args
!= void_list_node
)
2449 parm
= TREE_VALUE (parms
);
2450 parms
= TREE_CHAIN (parms
);
2451 arg
= TREE_VALUE (args
);
2452 args
= TREE_CHAIN (args
);
2454 if (arg
== error_mark_node
)
2456 if (arg
== unknown_type_node
)
2459 if (! uses_template_parms (parm
)
2460 && TREE_CODE_CLASS (TREE_CODE (arg
)) != 't')
2462 if (can_convert_arg (parm
, TREE_TYPE (arg
), arg
))
2468 if (TREE_CODE (arg
) == VAR_DECL
)
2469 arg
= TREE_TYPE (arg
);
2470 else if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'e')
2471 arg
= TREE_TYPE (arg
);
2473 if (TREE_CODE_CLASS (TREE_CODE (arg
)) != 't')
2475 my_friendly_assert (TREE_TYPE (arg
) != NULL_TREE
, 293);
2476 if (TREE_CODE (arg
) == TREE_LIST
2477 && TREE_TYPE (arg
) == unknown_type_node
2478 && TREE_CODE (TREE_VALUE (arg
)) == TEMPLATE_DECL
)
2480 int nsubsts
, ntparms
;
2483 /* Have to back unify here */
2484 arg
= TREE_VALUE (arg
);
2486 ntparms
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (arg
));
2487 targs
= (tree
*) alloca (sizeof (tree
) * ntparms
);
2488 parm
= tree_cons (NULL_TREE
, parm
, NULL_TREE
);
2489 return type_unification (DECL_TEMPLATE_PARMS (arg
), targs
,
2490 TYPE_ARG_TYPES (TREE_TYPE (arg
)),
2491 parm
, &nsubsts
, 0, strict
);
2493 arg
= TREE_TYPE (arg
);
2496 if (TREE_CODE (arg
) == REFERENCE_TYPE
)
2497 arg
= TREE_TYPE (arg
);
2499 if (TREE_CODE (parm
) != REFERENCE_TYPE
)
2501 if (TREE_CODE (arg
) == FUNCTION_TYPE
2502 || TREE_CODE (arg
) == METHOD_TYPE
)
2503 arg
= build_pointer_type (arg
);
2504 else if (TREE_CODE (arg
) == ARRAY_TYPE
)
2505 arg
= build_pointer_type (TREE_TYPE (arg
));
2507 arg
= TYPE_MAIN_VARIANT (arg
);
2510 switch (unify (tparms
, targs
, ntparms
, parm
, arg
, nsubsts
, strict
))
2518 /* Fail if we've reached the end of the parm list, and more args
2519 are present, and the parm list isn't variadic. */
2520 if (args
&& args
!= void_list_node
&& parms
== void_list_node
)
2522 /* Fail if parms are left and they don't have default values. */
2524 && parms
!= void_list_node
2525 && TREE_PURPOSE (parms
) == NULL_TREE
)
2528 for (i
= 0; i
< ntparms
; i
++)
2531 error ("incomplete type unification");
2537 /* Tail recursion is your friend. */
2540 unify (tparms
, targs
, ntparms
, parm
, arg
, nsubsts
, strict
)
2541 tree tparms
, *targs
, parm
, arg
;
2542 int *nsubsts
, ntparms
, strict
;
2546 /* I don't think this will do the right thing with respect to types.
2547 But the only case I've seen it in so far has been array bounds, where
2548 signedness is the only information lost, and I think that will be
2550 while (TREE_CODE (parm
) == NOP_EXPR
)
2551 parm
= TREE_OPERAND (parm
, 0);
2553 if (arg
== error_mark_node
)
2555 if (arg
== unknown_type_node
)
2560 switch (TREE_CODE (parm
))
2562 case TEMPLATE_TYPE_PARM
:
2564 idx
= TEMPLATE_TYPE_IDX (parm
);
2565 if (strict
&& (TYPE_READONLY (arg
) < TYPE_READONLY (parm
)
2566 || TYPE_VOLATILE (arg
) < TYPE_VOLATILE (parm
)))
2569 /* Template type parameters cannot contain cv-quals; i.e.
2570 template <class T> void f (T& a, T& b) will not generate
2571 void f (const int& a, const int& b). */
2572 if (TYPE_READONLY (arg
) > TYPE_READONLY (parm
)
2573 || TYPE_VOLATILE (arg
) > TYPE_VOLATILE (parm
))
2575 arg
= TYPE_MAIN_VARIANT (arg
);
2578 int constp
= TYPE_READONLY (arg
) > TYPE_READONLY (parm
);
2579 int volatilep
= TYPE_VOLATILE (arg
) > TYPE_VOLATILE (parm
);
2580 arg
= cp_build_type_variant (arg
, constp
, volatilep
);
2583 /* Simple cases: Value already set, does match or doesn't. */
2584 if (targs
[idx
] == arg
)
2586 else if (targs
[idx
])
2588 /* Check for mixed types and values. */
2589 if (TREE_CODE (TREE_VALUE (TREE_VEC_ELT (tparms
, idx
))) != TYPE_DECL
)
2593 case TEMPLATE_CONST_PARM
:
2595 idx
= TEMPLATE_CONST_IDX (parm
);
2596 if (targs
[idx
] == arg
)
2598 else if (targs
[idx
])
2600 tree t
= targs
[idx
];
2601 if (TREE_CODE (t
) == TREE_CODE (arg
))
2602 switch (TREE_CODE (arg
))
2605 if (tree_int_cst_equal (t
, arg
))
2609 if (REAL_VALUES_EQUAL (TREE_REAL_CST (t
), TREE_REAL_CST (arg
)))
2612 /* STRING_CST values are not valid template const parms. */
2616 my_friendly_abort (87);
2619 /* else if (typeof arg != tparms[idx])
2622 targs
[idx
] = copy_to_permanent (arg
);
2626 if (TREE_CODE (arg
) == RECORD_TYPE
&& TYPE_PTRMEMFUNC_FLAG (arg
))
2627 return unify (tparms
, targs
, ntparms
, parm
,
2628 TYPE_PTRMEMFUNC_FN_TYPE (arg
), nsubsts
, strict
);
2630 if (TREE_CODE (arg
) != POINTER_TYPE
)
2632 return unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
), TREE_TYPE (arg
),
2635 case REFERENCE_TYPE
:
2636 if (TREE_CODE (arg
) == REFERENCE_TYPE
)
2637 arg
= TREE_TYPE (arg
);
2638 return unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
), arg
,
2642 if (TREE_CODE (arg
) != ARRAY_TYPE
)
2644 if (unify (tparms
, targs
, ntparms
, TYPE_DOMAIN (parm
), TYPE_DOMAIN (arg
),
2645 nsubsts
, strict
) != 0)
2647 return unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
), TREE_TYPE (arg
),
2652 if (TREE_CODE (arg
) != TREE_CODE (parm
))
2655 if (TREE_CODE (parm
) == INTEGER_TYPE
)
2657 if (TYPE_MIN_VALUE (parm
) && TYPE_MIN_VALUE (arg
)
2658 && unify (tparms
, targs
, ntparms
, TYPE_MIN_VALUE (parm
),
2659 TYPE_MIN_VALUE (arg
), nsubsts
, strict
))
2661 if (TYPE_MAX_VALUE (parm
) && TYPE_MAX_VALUE (arg
)
2662 && unify (tparms
, targs
, ntparms
, TYPE_MAX_VALUE (parm
),
2663 TYPE_MAX_VALUE (arg
), nsubsts
, strict
))
2666 /* As far as unification is concerned, this wins. Later checks
2667 will invalidate it if necessary. */
2670 /* Types INTEGER_CST and MINUS_EXPR can come from array bounds. */
2672 if (TREE_CODE (arg
) != INTEGER_CST
)
2674 return !tree_int_cst_equal (parm
, arg
);
2679 t1
= TREE_OPERAND (parm
, 0);
2680 t2
= TREE_OPERAND (parm
, 1);
2681 return unify (tparms
, targs
, ntparms
, t1
,
2682 fold (build (PLUS_EXPR
, integer_type_node
, arg
, t2
)),
2689 if (TREE_CODE (arg
) != TREE_VEC
)
2691 if (TREE_VEC_LENGTH (parm
) != TREE_VEC_LENGTH (arg
))
2693 for (i
= TREE_VEC_LENGTH (parm
) - 1; i
>= 0; i
--)
2694 if (unify (tparms
, targs
, ntparms
,
2695 TREE_VEC_ELT (parm
, i
), TREE_VEC_ELT (arg
, i
),
2702 if (TYPE_PTRMEMFUNC_FLAG (parm
))
2703 return unify (tparms
, targs
, ntparms
, TYPE_PTRMEMFUNC_FN_TYPE (parm
),
2704 arg
, nsubsts
, strict
);
2706 /* Allow trivial conversions. */
2707 if (TREE_CODE (arg
) != RECORD_TYPE
2708 || TYPE_READONLY (parm
) < TYPE_READONLY (arg
)
2709 || TYPE_VOLATILE (parm
) < TYPE_VOLATILE (arg
))
2712 if (CLASSTYPE_TEMPLATE_INFO (parm
) && uses_template_parms (parm
))
2715 if (flag_ansi_overloading
&& ! strict
)
2716 t
= get_template_base (CLASSTYPE_TI_TEMPLATE (parm
), arg
);
2718 (CLASSTYPE_TEMPLATE_INFO (arg
)
2719 && CLASSTYPE_TI_TEMPLATE (parm
) == CLASSTYPE_TI_TEMPLATE (arg
))
2721 if (! t
|| t
== error_mark_node
)
2724 return unify (tparms
, targs
, ntparms
, CLASSTYPE_TI_ARGS (parm
),
2725 CLASSTYPE_TI_ARGS (t
), nsubsts
, strict
);
2727 else if (TYPE_MAIN_VARIANT (parm
) != TYPE_MAIN_VARIANT (arg
))
2732 if (TREE_CODE (arg
) != METHOD_TYPE
)
2737 if (TREE_CODE (arg
) != FUNCTION_TYPE
)
2740 if (unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
),
2741 TREE_TYPE (arg
), nsubsts
, strict
))
2743 return type_unification (tparms
, targs
, TYPE_ARG_TYPES (parm
),
2744 TYPE_ARG_TYPES (arg
), nsubsts
, 1, strict
);
2747 if (TREE_CODE (arg
) != OFFSET_TYPE
)
2749 if (unify (tparms
, targs
, ntparms
, TYPE_OFFSET_BASETYPE (parm
),
2750 TYPE_OFFSET_BASETYPE (arg
), nsubsts
, strict
))
2752 return unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
),
2753 TREE_TYPE (arg
), nsubsts
, strict
);
2756 sorry ("use of `%s' in template type unification",
2757 tree_code_name
[(int) TREE_CODE (parm
)]);
2763 mark_decl_instantiated (result
, extern_p
)
2767 if (DECL_TEMPLATE_INSTANTIATION (result
))
2768 SET_DECL_EXPLICIT_INSTANTIATION (result
);
2769 TREE_PUBLIC (result
) = 1;
2773 DECL_INTERFACE_KNOWN (result
) = 1;
2774 DECL_NOT_REALLY_EXTERN (result
) = 1;
2778 /* Given two function templates PAT1 and PAT2, return:
2780 1 if PAT1 is more specialized than PAT2 as described in [temp.func.order].
2781 -1 if PAT2 is more specialized than PAT1.
2782 0 if neither is more specialized. */
2785 more_specialized (pat1
, pat2
)
2788 int ntparms
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (pat1
));
2789 tree
*targs
= (tree
*) malloc (sizeof (tree
) * ntparms
);
2790 int i
, dummy
= 0, winner
= 0;
2792 i
= type_unification (DECL_TEMPLATE_PARMS (pat1
), targs
,
2793 TYPE_ARG_TYPES (TREE_TYPE (pat1
)),
2794 TYPE_ARG_TYPES (TREE_TYPE (pat2
)),
2801 ntparms
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (pat2
));
2802 targs
= (tree
*) malloc (sizeof (tree
) * ntparms
);
2804 i
= type_unification (DECL_TEMPLATE_PARMS (pat2
), targs
,
2805 TYPE_ARG_TYPES (TREE_TYPE (pat2
)),
2806 TYPE_ARG_TYPES (TREE_TYPE (pat1
)),
2816 /* called from the parser. */
2819 do_function_instantiation (declspecs
, declarator
, storage
)
2820 tree declspecs
, declarator
, storage
;
2822 tree decl
= grokdeclarator (declarator
, declspecs
, NORMAL
, 0,
2823 NULL_TREE
, NULL_TREE
);
2826 tree result
= NULL_TREE
;
2829 if (! DECL_LANG_SPECIFIC (decl
))
2831 cp_error ("explicit instantiation of non-template `%#D'", decl
);
2835 /* If we've already seen this template instance, use it. */
2836 if (DECL_FUNCTION_MEMBER_P (decl
))
2838 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2840 else if (name
= DECL_ASSEMBLER_NAME (decl
),
2841 fn
= IDENTIFIER_GLOBAL_VALUE (name
),
2842 fn
&& DECL_TEMPLATE_INSTANTIATION (fn
))
2845 else if (name
= DECL_NAME (decl
), fn
= IDENTIFIER_GLOBAL_VALUE (name
), fn
)
2847 for (fn
= get_first_fn (fn
); fn
; fn
= DECL_CHAIN (fn
))
2848 if (decls_match (fn
, decl
)
2849 && DECL_DEFER_OUTPUT (fn
))
2854 else if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2856 int ntparms
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (fn
));
2857 tree
*targs
= (tree
*) malloc (sizeof (tree
) * ntparms
);
2859 i
= type_unification (DECL_TEMPLATE_PARMS (fn
), targs
,
2860 TYPE_ARG_TYPES (TREE_TYPE (fn
)),
2861 TYPE_ARG_TYPES (TREE_TYPE (decl
)),
2867 int win
= more_specialized (DECL_TI_TEMPLATE (result
), fn
);
2870 cp_error ("ambiguous template instantiation for `%D' requested", decl
);
2872 result
= instantiate_template (fn
, targs
);
2873 /* else keep current winner */
2876 result
= instantiate_template (fn
, targs
);
2883 cp_error ("no matching template for `%D' found", decl
);
2887 if (flag_external_templates
)
2890 if (storage
== NULL_TREE
)
2892 else if (storage
== ridpointers
[(int) RID_EXTERN
])
2895 cp_error ("storage class `%D' applied to template instantiation",
2898 mark_decl_instantiated (result
, extern_p
);
2899 repo_template_instantiated (result
, extern_p
);
2901 instantiate_decl (result
);
2905 mark_class_instantiated (t
, extern_p
)
2909 SET_CLASSTYPE_EXPLICIT_INSTANTIATION (t
);
2910 SET_CLASSTYPE_INTERFACE_KNOWN (t
);
2911 CLASSTYPE_INTERFACE_ONLY (t
) = extern_p
;
2912 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = ! extern_p
;
2913 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = extern_p
;
2916 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2917 rest_of_type_compilation (t
, 1);
2922 do_type_instantiation (name
, storage
)
2925 tree t
= TREE_TYPE (name
);
2932 /* With -fexternal-templates, explicit instantiations are treated the same
2933 as implicit ones. */
2934 if (flag_external_templates
)
2937 if (TYPE_SIZE (t
) == NULL_TREE
)
2939 cp_error ("explicit instantiation of `%#T' before definition of template",
2944 if (storage
== NULL_TREE
)
2946 else if (storage
== ridpointers
[(int) RID_INLINE
])
2948 else if (storage
== ridpointers
[(int) RID_EXTERN
])
2950 else if (storage
== ridpointers
[(int) RID_STATIC
])
2954 cp_error ("storage class `%D' applied to template instantiation",
2959 /* We've already instantiated this. */
2960 if (CLASSTYPE_EXPLICIT_INSTANTIATION (t
) && ! CLASSTYPE_INTERFACE_ONLY (t
)
2964 if (! CLASSTYPE_TEMPLATE_SPECIALIZATION (t
))
2966 mark_class_instantiated (t
, extern_p
);
2967 repo_template_instantiated (t
, extern_p
);
2977 for (tmp
= TYPE_METHODS (t
); tmp
; tmp
= TREE_CHAIN (tmp
))
2978 if (DECL_TEMPLATE_INSTANTIATION (tmp
))
2980 mark_decl_instantiated (tmp
, extern_p
);
2981 repo_template_instantiated (tmp
, extern_p
);
2983 instantiate_decl (tmp
);
2986 for (tmp
= TYPE_FIELDS (t
); tmp
; tmp
= TREE_CHAIN (tmp
))
2987 if (TREE_CODE (tmp
) == VAR_DECL
&& DECL_TEMPLATE_INSTANTIATION (tmp
))
2989 mark_decl_instantiated (tmp
, extern_p
);
2990 repo_template_instantiated (tmp
, extern_p
);
2992 instantiate_decl (tmp
);
2995 for (tmp
= CLASSTYPE_TAGS (t
); tmp
; tmp
= TREE_CHAIN (tmp
))
2996 if (IS_AGGR_TYPE (TREE_VALUE (tmp
)))
2997 do_type_instantiation (TYPE_MAIN_DECL (TREE_VALUE (tmp
)), storage
);
3002 instantiate_decl (d
)
3005 tree ti
= DECL_TEMPLATE_INFO (d
);
3006 tree tmpl
= TI_TEMPLATE (ti
);
3007 tree args
= TI_ARGS (ti
);
3009 tree pattern
= DECL_TEMPLATE_RESULT (tmpl
);
3011 int nested
= in_function_p ();
3013 int pattern_defined
;
3015 if (TREE_CODE (d
) == FUNCTION_DECL
)
3017 d_defined
= (DECL_INITIAL (d
) != NULL_TREE
);
3018 pattern_defined
= (DECL_INITIAL (pattern
) != NULL_TREE
);
3022 d_defined
= ! DECL_IN_AGGR_P (d
);
3023 pattern_defined
= ! DECL_IN_AGGR_P (pattern
);
3028 else if (pattern_defined
)
3030 repo_template_used (d
);
3032 if (flag_external_templates
&& ! DECL_INTERFACE_KNOWN (d
))
3034 if (flag_alt_external_templates
)
3036 if (interface_unknown
)
3037 warn_if_unknown_interface (d
);
3039 else if (DECL_INTERFACE_KNOWN (pattern
))
3041 DECL_INTERFACE_KNOWN (d
) = 1;
3042 DECL_NOT_REALLY_EXTERN (d
) = ! DECL_EXTERNAL (pattern
);
3045 warn_if_unknown_interface (pattern
);
3049 import_export_decl (d
);
3052 if (! pattern_defined
3053 || (TREE_CODE (d
) == FUNCTION_DECL
&& ! DECL_INLINE (d
)
3054 && (! DECL_INTERFACE_KNOWN (d
)
3055 || ! DECL_NOT_REALLY_EXTERN (d
)))
3056 /* Kludge: if we compile a constructor in the middle of processing a
3057 toplevel declaration, we blow away the declspecs in
3058 temp_decl_obstack when we call permanent_allocation in
3059 finish_function. So don't compile it yet. */
3060 || (TREE_CODE (d
) == FUNCTION_DECL
&& ! nested
&& ! at_eof
))
3062 add_pending_template (d
);
3066 if (! push_tinst_level (d
))
3069 push_to_top_level ();
3071 /* Trick tsubst into giving us a new decl in case the template changed. */
3072 save_ti
= DECL_TEMPLATE_INFO (pattern
);
3073 DECL_TEMPLATE_INFO (pattern
) = NULL_TREE
;
3074 td
= tsubst (pattern
, &TREE_VEC_ELT (args
, 0), TREE_VEC_LENGTH (args
), tmpl
);
3075 DECL_TEMPLATE_INFO (pattern
) = save_ti
;
3077 /* Convince duplicate_decls to use the DECL_ARGUMENTS from the new decl. */
3078 if (TREE_CODE (d
) == FUNCTION_DECL
)
3079 DECL_INITIAL (td
) = error_mark_node
;
3080 duplicate_decls (td
, d
);
3081 if (TREE_CODE (d
) == FUNCTION_DECL
)
3082 DECL_INITIAL (td
) = 0;
3084 if (TREE_CODE (d
) == VAR_DECL
)
3086 DECL_IN_AGGR_P (d
) = 0;
3087 if (DECL_INTERFACE_KNOWN (d
))
3088 DECL_EXTERNAL (d
) = ! DECL_NOT_REALLY_EXTERN (d
);
3091 DECL_EXTERNAL (d
) = 1;
3092 DECL_NOT_REALLY_EXTERN (d
) = 1;
3094 cp_finish_decl (d
, DECL_INITIAL (d
), NULL_TREE
, 0, 0);
3096 else if (TREE_CODE (d
) == FUNCTION_DECL
)
3098 tree t
= DECL_SAVED_TREE (pattern
);
3100 char *file
= input_filename
;
3102 lineno
= DECL_SOURCE_LINE (d
);
3103 input_filename
= DECL_SOURCE_FILE (d
);
3105 start_function (NULL_TREE
, d
, NULL_TREE
, NULL_TREE
, 1);
3106 store_parm_decls ();
3108 if (t
&& TREE_CODE (t
) == RETURN_INIT
)
3111 (TREE_OPERAND (t
, 0),
3112 tsubst_expr (TREE_OPERAND (t
, 1), &TREE_VEC_ELT (args
, 0),
3113 TREE_VEC_LENGTH (args
), tmpl
));
3117 if (t
&& TREE_CODE (t
) == CTOR_INITIALIZER
)
3119 current_member_init_list
3120 = tsubst_expr_values (TREE_OPERAND (t
, 0), args
);
3121 current_base_init_list
3122 = tsubst_expr_values (TREE_OPERAND (t
, 1), args
);
3127 /* Always keep the BLOCK node associated with the outermost
3128 pair of curley braces of a function. These are needed
3129 for correct operation of dwarfout.c. */
3132 my_friendly_assert (TREE_CODE (t
) == COMPOUND_STMT
, 42);
3133 tsubst_expr (t
, &TREE_VEC_ELT (args
, 0),
3134 TREE_VEC_LENGTH (args
), tmpl
);
3136 finish_function (lineno
, 0, nested
);
3139 input_filename
= file
;
3142 pop_from_top_level ();
3149 tsubst_chain (t
, argvec
)
3154 tree first
= tsubst (t
, &TREE_VEC_ELT (argvec
, 0),
3155 TREE_VEC_LENGTH (argvec
), NULL_TREE
);
3158 for (t
= TREE_CHAIN (t
); t
; t
= TREE_CHAIN (t
))
3160 tree x
= tsubst (t
, &TREE_VEC_ELT (argvec
, 0),
3161 TREE_VEC_LENGTH (argvec
), NULL_TREE
);
3162 TREE_CHAIN (last
) = x
;
3172 tsubst_expr_values (t
, argvec
)
3175 tree first
= NULL_TREE
;
3178 for (; t
; t
= TREE_CHAIN (t
))
3180 tree pur
= tsubst_copy (TREE_PURPOSE (t
), &TREE_VEC_ELT (argvec
, 0),
3181 TREE_VEC_LENGTH (argvec
), NULL_TREE
);
3182 tree val
= tsubst_expr (TREE_VALUE (t
), &TREE_VEC_ELT (argvec
, 0),
3183 TREE_VEC_LENGTH (argvec
), NULL_TREE
);
3184 *p
= build_tree_list (pur
, val
);
3185 p
= &TREE_CHAIN (*p
);
3196 last_tree
= TREE_CHAIN (last_tree
) = t
;