1 /* Handle parameterized types (templates) for GNU C++.
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
3 Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Known bugs or deficiencies include:
22 * templates for class static data don't work (methods only)
23 * duplicated method templates can crash the compiler
24 * interface/impl data is taken from file defining the template
25 * all methods must be provided in header files; can't use a source
26 file that contains only the method templates and "just win"
27 * method templates must be seen before the expansion of the
28 class template is done
41 extern struct obstack permanent_obstack
;
42 extern tree
grokdeclarator ();
45 extern char *input_filename
;
46 struct pending_inline
*pending_template_expansions
;
48 int processing_template_decl
;
49 int processing_template_defn
;
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
55 static void add_pending_template ();
57 void overload_template_name (), pop_template_decls ();
59 /* We've got a template header coming up; set obstacks up to save the
60 nodes created permanently. (There might be cases with nested templates
61 where we don't have to do this, but they aren't implemented, and it
62 probably wouldn't be worth the effort.) */
64 begin_template_parm_list ()
67 push_obstacks (&permanent_obstack
, &permanent_obstack
);
71 /* Process information from new template parameter NEXT and append it to the
72 LIST being built. The rules for use of a template parameter type name
73 by later parameters are not well-defined for us just yet. However, the
74 only way to avoid having to parse expressions of unknown complexity (and
75 with tokens of unknown types) is to disallow it completely. So for now,
76 that is what is assumed. */
78 process_template_parm (list
, next
)
85 my_friendly_assert (TREE_CODE (parm
) == TREE_LIST
, 259);
86 is_type
= TREE_CODE (TREE_PURPOSE (parm
)) == IDENTIFIER_NODE
;
90 parm
= TREE_PURPOSE (parm
);
91 my_friendly_assert (TREE_CODE (parm
) == TREE_LIST
, 260);
92 parm
= TREE_VALUE (parm
);
93 /* is a const-param */
94 parm
= grokdeclarator (TREE_VALUE (next
), TREE_PURPOSE (next
),
96 /* A template parameter is not modifiable. */
97 TREE_READONLY (parm
) = 1;
98 if (TREE_CODE (TREE_TYPE (parm
)) == RECORD_TYPE
99 || TREE_CODE (TREE_TYPE (parm
)) == UNION_TYPE
)
101 sorry ("aggregate template parameter types");
102 TREE_TYPE (parm
) = void_type_node
;
104 tinfo
= make_node (TEMPLATE_CONST_PARM
);
105 my_friendly_assert (TREE_PERMANENT (tinfo
), 260.5);
106 if (TREE_PERMANENT (parm
) == 0)
108 parm
= copy_node (parm
);
109 TREE_PERMANENT (parm
) = 1;
111 TREE_TYPE (tinfo
) = TREE_TYPE (parm
);
112 decl
= build_decl (CONST_DECL
, DECL_NAME (parm
), TREE_TYPE (parm
));
113 DECL_INITIAL (decl
) = tinfo
;
114 DECL_INITIAL (parm
) = tinfo
;
118 tree t
= make_node (TEMPLATE_TYPE_PARM
);
119 decl
= build_lang_decl (TYPE_DECL
, TREE_PURPOSE (parm
), t
);
120 TYPE_NAME (t
) = decl
;
121 TREE_VALUE (parm
) = t
;
124 return chainon (list
, parm
);
127 /* The end of a template parameter list has been reached. Process the
128 tree list into a parameter vector, converting each parameter into a more
129 useful form. Type parameters are saved as IDENTIFIER_NODEs, and others
133 end_template_parm_list (parms
)
139 for (parm
= parms
; parm
; parm
= TREE_CHAIN (parm
))
141 saved_parmlist
= make_tree_vec (nparms
);
143 for (parm
= parms
, nparms
= 0; parm
; parm
= TREE_CHAIN (parm
), nparms
++)
146 if (TREE_CODE (p
) == TREE_LIST
)
148 tree t
= TREE_VALUE (p
);
149 TREE_VALUE (p
) = NULL_TREE
;
150 p
= TREE_PURPOSE (p
);
151 my_friendly_assert (TREE_CODE (p
) == IDENTIFIER_NODE
, 261);
152 TEMPLATE_TYPE_SET_INFO (t
, saved_parmlist
, nparms
);
156 tree tinfo
= DECL_INITIAL (p
);
157 DECL_INITIAL (p
) = NULL_TREE
;
158 TEMPLATE_CONST_SET_INFO (tinfo
, saved_parmlist
, nparms
);
160 TREE_VEC_ELT (saved_parmlist
, nparms
) = p
;
162 set_current_level_tags_transparency (1);
163 processing_template_decl
++;
164 return saved_parmlist
;
167 /* end_template_decl is called after a template declaration is seen.
168 D1 is template header; D2 is class_head_sans_basetype or a
169 TEMPLATE_DECL with its DECL_RESULT field set. */
171 end_template_decl (d1
, d2
, is_class
, defn
)
172 tree d1
, d2
, is_class
;
176 struct template_info
*tmpl
;
178 tmpl
= (struct template_info
*) obstack_alloc (&permanent_obstack
,
179 sizeof (struct template_info
));
182 tmpl
->aggr
= is_class
;
184 /* cloned from reinit_parse_for_template */
185 tmpl
->filename
= input_filename
;
186 tmpl
->lineno
= lineno
;
187 tmpl
->parm_vec
= d1
; /* [eichin:19911015.2306EST] */
189 if (d2
== NULL_TREE
|| d2
== error_mark_node
)
197 decl
= build_lang_decl (TEMPLATE_DECL
, d2
, NULL_TREE
);
201 if (TREE_CODE (d2
) == TEMPLATE_DECL
)
205 /* Class destructor templates and operator templates are
206 slipping past as non-template nodes. Process them here, since
207 I haven't figured out where to catch them earlier. I could
208 go do that, but it's a choice between getting that done and
209 staying only N months behind schedule. Sorry.... */
211 my_friendly_assert (TREE_CODE (d2
) == CALL_EXPR
, 263);
212 code
= TREE_CODE (TREE_OPERAND (d2
, 0));
213 my_friendly_assert (code
== BIT_NOT_EXPR
214 || code
== OP_IDENTIFIER
215 || code
== SCOPE_REF
, 264);
216 d2
= grokdeclarator (d2
, NULL_TREE
, MEMFUNCDEF
, 0, NULL_TREE
);
217 decl
= build_lang_decl (TEMPLATE_DECL
, DECL_NAME (d2
),
219 DECL_TEMPLATE_RESULT (decl
) = d2
;
220 DECL_CONTEXT (decl
) = DECL_CONTEXT (d2
);
221 DECL_CLASS_CONTEXT (decl
) = DECL_CLASS_CONTEXT (d2
);
222 DECL_NAME (decl
) = DECL_NAME (d2
);
223 TREE_TYPE (decl
) = TREE_TYPE (d2
);
224 if (interface_unknown
&& flag_external_templates
&& ! DECL_IN_SYSTEM_HEADER (decl
))
225 warn_if_unknown_interface ();
226 TREE_PUBLIC (decl
) = TREE_PUBLIC (d2
) = flag_external_templates
&& !interface_unknown
;
227 DECL_EXTERNAL (decl
) = (DECL_EXTERNAL (d2
)
228 && !(DECL_CLASS_CONTEXT (d2
)
229 && !DECL_THIS_EXTERN (d2
)));
232 /* All routines creating TEMPLATE_DECL nodes should now be using
233 build_lang_decl, which will have set this up already. */
234 my_friendly_assert (DECL_LANG_SPECIFIC (decl
) != 0, 265);
236 /* @@ Somewhere, permanent allocation isn't being used. */
237 if (! DECL_TEMPLATE_IS_CLASS (decl
)
238 && TREE_CODE (DECL_TEMPLATE_RESULT (decl
)) == FUNCTION_DECL
)
240 tree result
= DECL_TEMPLATE_RESULT (decl
);
241 /* Will do nothing if allocation was already permanent. */
242 DECL_ARGUMENTS (result
) = copy_to_permanent (DECL_ARGUMENTS (result
));
245 /* If this is for a method, there's an extra binding level here. */
246 if (! DECL_TEMPLATE_IS_CLASS (decl
)
247 && DECL_CONTEXT (DECL_TEMPLATE_RESULT (decl
)) != NULL_TREE
)
249 /* @@ Find out where this should be getting set! */
250 tree r
= DECL_TEMPLATE_RESULT (decl
);
251 if (DECL_CLASS_CONTEXT (r
) == NULL_TREE
)
252 DECL_CLASS_CONTEXT (r
) = DECL_CONTEXT (r
);
255 DECL_TEMPLATE_INFO (decl
) = tmpl
;
256 DECL_TEMPLATE_PARMS (decl
) = d1
;
258 /* So that duplicate_decls can do the right thing. */
260 DECL_INITIAL (decl
) = error_mark_node
;
262 /* If context of decl is non-null (i.e., method template), add it
263 to the appropriate class template, and pop the binding levels. */
264 if (! DECL_TEMPLATE_IS_CLASS (decl
)
265 && DECL_CONTEXT (DECL_TEMPLATE_RESULT (decl
)) != NULL_TREE
)
267 tree ctx
= DECL_CONTEXT (DECL_TEMPLATE_RESULT (decl
));
269 my_friendly_assert (TREE_CODE (ctx
) == UNINSTANTIATED_P_TYPE
, 266);
270 tmpl
= UPT_TEMPLATE (ctx
);
271 for (t
= DECL_TEMPLATE_MEMBERS (tmpl
); t
; t
= TREE_CHAIN (t
))
272 if (TREE_PURPOSE (t
) == DECL_NAME (decl
)
273 && duplicate_decls (decl
, TREE_VALUE (t
)))
275 DECL_TEMPLATE_MEMBERS (tmpl
) =
276 perm_tree_cons (DECL_NAME (decl
), decl
, DECL_TEMPLATE_MEMBERS (tmpl
));
281 /* Otherwise, go back to top level first, and push the template decl
290 #if 0 /* It happens sometimes, with syntactic or semantic errors.
293 template <class A, int X, int Y> class Foo { ... };
294 template <class A, int X, int y> Foo<X,Y>::method (Foo& x) { ... }
295 Note the missing "A" in the class containing "method". */
296 my_friendly_assert (global_bindings_p (), 267);
298 while (! global_bindings_p ())
302 processing_template_decl
--;
303 (void) get_pending_sizes ();
306 /* If TYPE contains a template parm type, then substitute that type
307 with its actual type that is found in TVEC. */
309 grok_template_type (tvec
, type
)
313 switch (TREE_CODE (*type
))
315 case TEMPLATE_TYPE_PARM
:
316 if (*type
!= TYPE_MAIN_VARIANT (*type
))
318 /* we are here for cases like const T* etc. */
319 grok_template_type (tvec
, &TYPE_MAIN_VARIANT (*type
));
320 *type
= build_type_variant (TYPE_MAIN_VARIANT (*type
),
321 TYPE_READONLY (*type
),
322 TYPE_VOLATILE (*type
));
325 *type
= TREE_VEC_ELT (tvec
, TEMPLATE_TYPE_IDX (*type
));
329 grok_template_type (tvec
, &TREE_TYPE (*type
));
335 /* take care of function's return type first */
336 grok_template_type (tvec
, &TREE_TYPE (*type
));
338 /* take care of function's arguments */
339 for (p
= TYPE_ARG_TYPES (*type
); p
; p
= TREE_CHAIN (p
))
340 grok_template_type (tvec
, &TREE_VALUE (p
));
349 /* Convert all template arguments to their appropriate types, and return
350 a vector containing the resulting values. If any error occurs, return
353 coerce_template_parms (parms
, arglist
, in_decl
)
357 int nparms
, i
, lost
= 0;
360 if (TREE_CODE (arglist
) == TREE_VEC
)
361 nparms
= TREE_VEC_LENGTH (arglist
);
363 nparms
= list_length (arglist
);
364 if (nparms
!= TREE_VEC_LENGTH (parms
))
366 error ("incorrect number of parameters (%d, should be %d)",
367 nparms
, TREE_VEC_LENGTH (parms
));
369 cp_error_at ("in template expansion for decl `%D'", in_decl
);
370 return error_mark_node
;
373 if (TREE_CODE (arglist
) == TREE_VEC
)
374 vec
= copy_node (arglist
);
377 vec
= make_tree_vec (nparms
);
378 for (i
= 0; i
< nparms
; i
++)
381 arglist
= TREE_CHAIN (arglist
);
382 if (arg
== error_mark_node
)
385 arg
= TREE_VALUE (arg
);
386 TREE_VEC_ELT (vec
, i
) = arg
;
389 for (i
= 0; i
< nparms
; i
++)
391 tree arg
= TREE_VEC_ELT (vec
, i
);
392 tree parm
= TREE_VEC_ELT (parms
, i
);
394 int is_type
, requires_type
;
396 is_type
= TREE_CODE_CLASS (TREE_CODE (arg
)) == 't';
397 requires_type
= TREE_CODE (parm
) == IDENTIFIER_NODE
;
398 if (is_type
!= requires_type
)
401 cp_error_at ("type/value mismatch in template parameter list for `%D'", in_decl
);
403 TREE_VEC_ELT (vec
, i
) = error_mark_node
;
407 val
= groktypename (arg
);
408 else if (TREE_CODE (arg
) == STRING_CST
)
410 cp_error ("string literal %E is not a valid template argument", arg
);
411 error ("because it is the address of an object with static linkage");
412 val
= error_mark_node
;
416 grok_template_type (vec
, &TREE_TYPE (parm
));
417 val
= digest_init (TREE_TYPE (parm
), arg
, (tree
*) 0);
419 if (val
== error_mark_node
)
422 /* 14.2: Other template-arguments must be constant-expressions,
423 addresses of objects or functions with external linkage, or of
424 static class members. */
425 else if (!TREE_CONSTANT (val
))
427 cp_error ("non-const `%E' cannot be used as template argument",
429 val
= error_mark_node
;
431 else if (TREE_CODE (val
) == ADDR_EXPR
)
433 tree a
= TREE_OPERAND (val
, 0);
434 if ((TREE_CODE (a
) == VAR_DECL
435 || TREE_CODE (a
) == FUNCTION_DECL
)
438 cp_error ("address of non-extern `%E' cannot be used as template argument", a
);
439 val
= error_mark_node
;
444 if (val
== error_mark_node
)
447 TREE_VEC_ELT (vec
, i
) = val
;
450 return error_mark_node
;
454 /* Given class template name and parameter list, produce a user-friendly name
455 for the instantiation. */
457 mangle_class_name_for_template (name
, parms
, arglist
)
461 static struct obstack scratch_obstack
;
462 static char *scratch_firstobj
;
465 if (!scratch_firstobj
)
467 gcc_obstack_init (&scratch_obstack
);
468 scratch_firstobj
= obstack_alloc (&scratch_obstack
, 1);
471 obstack_free (&scratch_obstack
, scratch_firstobj
);
474 #define buflen sizeof(buf)
475 #define check if (bufp >= buf+buflen-1) goto too_long
476 #define ccat(c) *bufp++=(c); check
477 #define advance bufp+=strlen(bufp); check
478 #define cat(s) strncpy(bufp, s, buf+buflen-bufp-1); advance
481 #define ccat(c) obstack_1grow (&scratch_obstack, (c));
483 #define cat(s) obstack_grow (&scratch_obstack, (s), strlen (s))
488 nparms
= TREE_VEC_LENGTH (parms
);
489 my_friendly_assert (nparms
== TREE_VEC_LENGTH (arglist
), 268);
490 for (i
= 0; i
< nparms
; i
++)
492 tree parm
= TREE_VEC_ELT (parms
, i
), arg
= TREE_VEC_ELT (arglist
, i
);
497 if (TREE_CODE (parm
) == IDENTIFIER_NODE
)
499 cat (type_as_string (arg
, 0));
503 my_friendly_assert (TREE_CODE (parm
) == PARM_DECL
, 269);
505 if (TREE_CODE (arg
) == TREE_LIST
)
507 /* New list cell was built because old chain link was in
509 my_friendly_assert (TREE_PURPOSE (arg
) == NULL_TREE
, 270);
510 arg
= TREE_VALUE (arg
);
512 /* No need to check arglist against parmlist here; we did that
513 in coerce_template_parms, called from lookup_template_class. */
514 cat (expr_as_string (arg
, 0));
517 char *bufp
= obstack_next_free (&scratch_obstack
);
519 while (bufp
[offset
- 1] == ' ')
521 obstack_blank_fast (&scratch_obstack
, offset
);
523 /* B<C<char> >, not B<C<char>> */
524 if (bufp
[offset
- 1] == '>')
529 return (char *) obstack_base (&scratch_obstack
);
534 fatal ("out of (preallocated) string space creating template instantiation name");
539 /* Given an IDENTIFIER_NODE (type TEMPLATE_DECL) and a chain of
540 parameters, find the desired type.
542 D1 is the PTYPENAME terminal, and ARGLIST is the list of arguments.
543 Since ARGLIST is build on the decl_obstack, we must copy it here
544 to keep it from being reclaimed when the decl storage is reclaimed.
546 IN_DECL, if non-NULL, is the template declaration we are trying to
549 lookup_template_class (d1
, arglist
, in_decl
)
553 tree
template, parmlist
;
557 my_friendly_assert (TREE_CODE (d1
) == IDENTIFIER_NODE
, 272);
558 template = IDENTIFIER_GLOBAL_VALUE (d1
); /* XXX */
560 template = IDENTIFIER_CLASS_VALUE (d1
);
561 /* With something like `template <class T> class X class X { ... };'
562 we could end up with D1 having nothing but an IDENTIFIER_LOCAL_VALUE.
563 We don't want to do that, but we have to deal with the situation, so
564 let's give them some syntax errors to chew on instead of a crash. */
566 return error_mark_node
;
567 if (TREE_CODE (template) != TEMPLATE_DECL
)
569 cp_error ("non-template type `%T' used as a template", d1
);
571 cp_error_at ("for template declaration `%D'", in_decl
);
572 return error_mark_node
;
574 parmlist
= DECL_TEMPLATE_PARMS (template);
576 arglist
= coerce_template_parms (parmlist
, arglist
, in_decl
);
577 if (arglist
== error_mark_node
)
578 return error_mark_node
;
579 if (uses_template_parms (arglist
))
581 tree t
= make_lang_type (UNINSTANTIATED_P_TYPE
);
583 id
= make_anon_name ();
584 d
= build_lang_decl (TYPE_DECL
, id
, t
);
586 TYPE_VALUES (t
) = build_tree_list (template, arglist
);
587 pushdecl_top_level (d
);
591 mangled_name
= mangle_class_name_for_template (IDENTIFIER_POINTER (d1
),
593 id
= get_identifier (mangled_name
);
595 if (!IDENTIFIER_TEMPLATE (id
))
597 arglist
= copy_to_permanent (arglist
);
598 IDENTIFIER_TEMPLATE (id
) = perm_tree_cons (template, arglist
, NULL_TREE
);
604 push_template_decls (parmlist
, arglist
, class_level
)
605 tree parmlist
, arglist
;
610 /* Don't want to push values into global context. */
614 declare_pseudo_global_level ();
617 nparms
= TREE_VEC_LENGTH (parmlist
);
619 for (i
= 0; i
< nparms
; i
++)
621 int requires_type
, is_type
;
622 tree parm
= TREE_VEC_ELT (parmlist
, i
);
623 tree arg
= TREE_VEC_ELT (arglist
, i
);
626 requires_type
= TREE_CODE (parm
) == IDENTIFIER_NODE
;
627 is_type
= TREE_CODE_CLASS (TREE_CODE (arg
)) == 't';
630 /* add typename to namespace */
633 error ("template use error: type provided where value needed");
637 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't', 273);
638 decl
= build_lang_decl (TYPE_DECL
, parm
, decl
);
642 /* add const decl to namespace */
646 error ("template use error: value provided where type needed");
649 val
= digest_init (TREE_TYPE (parm
), arg
, (tree
*) 0);
650 if (val
!= error_mark_node
)
652 decl
= build_decl (VAR_DECL
, DECL_NAME (parm
), TREE_TYPE (parm
));
653 DECL_INITIAL (decl
) = val
;
654 TREE_READONLY (decl
) = 1;
659 layout_decl (decl
, 0);
661 pushdecl_class_level (decl
);
669 pop_template_decls (parmlist
, arglist
, class_level
)
670 tree parmlist
, arglist
;
677 /* Should be defined in parse.h. */
681 uses_template_parms (t
)
686 switch (TREE_CODE (t
))
690 /* We assume that the object must be instantiated in order to build
691 the COMPONENT_REF, so we test only whether the type of the
692 COMPONENT_REF uses template parms. */
693 return uses_template_parms (TREE_TYPE (t
));
695 case IDENTIFIER_NODE
:
696 if (!IDENTIFIER_TEMPLATE (t
))
698 return uses_template_parms (TREE_VALUE (IDENTIFIER_TEMPLATE (t
)));
700 /* aggregates of tree nodes */
703 int i
= TREE_VEC_LENGTH (t
);
705 if (uses_template_parms (TREE_VEC_ELT (t
, i
)))
710 if (uses_template_parms (TREE_PURPOSE (t
))
711 || uses_template_parms (TREE_VALUE (t
)))
713 return uses_template_parms (TREE_CHAIN (t
));
715 /* constructed type nodes */
718 return uses_template_parms (TREE_TYPE (t
));
723 if (!TYPE_IDENTIFIER (t
))
725 return uses_template_parms (TYPE_IDENTIFIER (t
));
727 if (uses_template_parms (TYPE_ARG_TYPES (t
)))
729 return uses_template_parms (TREE_TYPE (t
));
731 if (uses_template_parms (TYPE_DOMAIN (t
)))
733 return uses_template_parms (TREE_TYPE (t
));
735 if (uses_template_parms (TYPE_OFFSET_BASETYPE (t
)))
737 return uses_template_parms (TREE_TYPE (t
));
739 if (uses_template_parms (TYPE_OFFSET_BASETYPE (t
)))
741 if (uses_template_parms (TYPE_ARG_TYPES (t
)))
743 return uses_template_parms (TREE_TYPE (t
));
747 return uses_template_parms (DECL_NAME (t
));
749 if (uses_template_parms (TREE_TYPE (t
)))
754 /* ??? What about FIELD_DECLs? */
755 /* The type of a decl can't use template parms if the name of the
756 variable doesn't, because it's impossible to resolve them. So
757 ignore the type field for now. */
758 if (DECL_CONTEXT (t
) && uses_template_parms (DECL_CONTEXT (t
)))
760 if (uses_template_parms (TREE_TYPE (t
)))
762 error ("template parms used where they can't be resolved");
767 return uses_template_parms (TREE_TYPE (t
));
769 return uses_template_parms (TREE_OPERAND (t
, 0));
771 /* template parm nodes */
772 case TEMPLATE_TYPE_PARM
:
773 case TEMPLATE_CONST_PARM
:
776 /* simple type nodes */
778 if (uses_template_parms (TYPE_MIN_VALUE (t
)))
780 return uses_template_parms (TYPE_MAX_VALUE (t
));
795 /* Non-error_mark_node ERROR_MARKs are bad things. */
796 my_friendly_assert (t
== error_mark_node
, 274);
800 case UNINSTANTIATED_P_TYPE
:
804 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
812 for (i
= tree_code_length
[(int) TREE_CODE (t
)]; --i
>= 0;)
813 if (uses_template_parms (TREE_OPERAND (t
, i
)))
820 sorry ("testing %s for template parms",
821 tree_code_name
[(int) TREE_CODE (t
)]);
822 my_friendly_abort (82);
829 instantiate_member_templates (classname
)
834 tree members
= DECL_TEMPLATE_MEMBERS (TREE_PURPOSE (IDENTIFIER_TEMPLATE (id
)));
836 for (t
= members
; t
; t
= TREE_CHAIN (t
))
838 tree parmvec
, type
, classparms
, tdecl
, t2
;
839 int nparms
, xxx
= 0, i
;
841 my_friendly_assert (TREE_VALUE (t
) != NULL_TREE
, 275);
842 my_friendly_assert (TREE_CODE (TREE_VALUE (t
)) == TEMPLATE_DECL
, 276);
843 /* @@ Should verify that class parm list is a list of
844 distinct template parameters, and covers all the template
846 tdecl
= TREE_VALUE (t
);
847 type
= DECL_CONTEXT (DECL_TEMPLATE_RESULT (tdecl
));
848 classparms
= UPT_PARMS (type
);
849 nparms
= TREE_VEC_LENGTH (classparms
);
850 parmvec
= make_tree_vec (nparms
);
851 for (i
= 0; i
< nparms
; i
++)
852 TREE_VEC_ELT (parmvec
, i
) = NULL_TREE
;
853 switch (unify (DECL_TEMPLATE_PARMS (tdecl
),
854 &TREE_VEC_ELT (parmvec
, 0), nparms
,
855 type
, IDENTIFIER_TYPE_VALUE (classname
),
859 /* Success -- well, no inconsistency, at least. */
860 for (i
= 0; i
< nparms
; i
++)
861 if (TREE_VEC_ELT (parmvec
, i
) == NULL_TREE
)
863 t2
= instantiate_template (tdecl
,
864 &TREE_VEC_ELT (parmvec
, 0));
865 type
= IDENTIFIER_TYPE_VALUE (id
);
866 my_friendly_assert (type
!= 0, 277);
867 if (CLASSTYPE_INTERFACE_UNKNOWN (type
))
869 DECL_EXTERNAL (t2
) = 0;
870 TREE_PUBLIC (t2
) = 0;
874 DECL_EXTERNAL (t2
) = CLASSTYPE_INTERFACE_ONLY (type
);
875 TREE_PUBLIC (t2
) = 1;
881 cp_error ("type unification error instantiating %T::%D",
883 cp_error_at ("for template declaration `%D'", tdecl
);
885 continue /* loop of members */;
888 my_friendly_abort (83);
893 struct tinst_level
*current_tinst_level
= 0;
894 struct tinst_level
*free_tinst_level
= 0;
897 push_tinst_level (name
)
900 struct tinst_level
*new;
901 tree global
= IDENTIFIER_GLOBAL_VALUE (name
);
903 if (free_tinst_level
)
905 new = free_tinst_level
;
906 free_tinst_level
= new->next
;
909 new = (struct tinst_level
*) xmalloc (sizeof (struct tinst_level
));
911 new->classname
= name
;
914 new->line
= DECL_SOURCE_LINE (global
);
915 new->file
= DECL_SOURCE_FILE (global
);
920 new->file
= input_filename
;
922 new->next
= current_tinst_level
;
923 current_tinst_level
= new;
929 struct tinst_level
*old
= current_tinst_level
;
931 current_tinst_level
= old
->next
;
932 old
->next
= free_tinst_level
;
933 free_tinst_level
= old
;
939 struct tinst_level
*p
= current_tinst_level
;
942 for (; p
->next
; p
= p
->next
)
948 instantiate_class_template (classname
, setup_parse
)
952 struct template_info
*template_info
;
955 if (classname
== error_mark_node
)
956 return error_mark_node
;
958 my_friendly_assert (TREE_CODE (classname
) == IDENTIFIER_NODE
, 278);
959 template = IDENTIFIER_TEMPLATE (classname
);
961 if (IDENTIFIER_HAS_TYPE_VALUE (classname
))
963 tree type
= IDENTIFIER_TYPE_VALUE (classname
);
964 if (TREE_CODE (type
) == UNINSTANTIATED_P_TYPE
)
966 if (TYPE_BEING_DEFINED (type
)
968 || CLASSTYPE_USE_TEMPLATE (type
) != 0)
972 /* If IDENTIFIER_LOCAL_VALUE is already set on this template classname
973 (it's something like `foo<int>'), that means we're already working on
974 the instantiation for it. Normally, a classname comes in with nothing
975 but its IDENTIFIER_TEMPLATE slot set. If we were to try to instantiate
976 this again, we'd get a redeclaration error. Since we're already working
977 on it, we'll pass back this classname's TYPE_DECL (it's the value of
978 the classname's IDENTIFIER_LOCAL_VALUE). Only do this if we're setting
979 things up for the parser, though---if we're just trying to instantiate
980 it (e.g., via tsubst) we can trip up cuz it may not have an
981 IDENTIFIER_TYPE_VALUE when it will need one. */
982 if (setup_parse
&& IDENTIFIER_LOCAL_VALUE (classname
))
983 return IDENTIFIER_LOCAL_VALUE (classname
);
985 if (uses_template_parms (classname
))
987 if (!TREE_TYPE (classname
))
989 tree t
= make_lang_type (RECORD_TYPE
);
990 tree d
= build_lang_decl (TYPE_DECL
, classname
, t
);
991 DECL_NAME (d
) = classname
;
998 t1
= TREE_PURPOSE (template);
999 my_friendly_assert (TREE_CODE (t1
) == TEMPLATE_DECL
, 279);
1001 /* If a template is declared but not defined, accept it; don't crash.
1002 Later uses requiring the definition will be flagged as errors by
1003 other code. Thanks to niklas@appli.se for this bug fix. */
1004 if (DECL_TEMPLATE_INFO (t1
)->text
== 0)
1007 push_to_top_level ();
1008 template_info
= DECL_TEMPLATE_INFO (t1
);
1011 push_tinst_level (classname
);
1012 push_template_decls (DECL_TEMPLATE_PARMS (TREE_PURPOSE (template)),
1013 TREE_VALUE (template), 0);
1014 set_current_level_tags_transparency (1);
1015 feed_input (template_info
->text
, template_info
->length
, (struct obstack
*)0);
1016 lineno
= template_info
->lineno
;
1017 input_filename
= template_info
->filename
;
1018 /* Get interface/implementation back in sync. */
1019 extract_interface_info ();
1020 overload_template_name (classname
, 0);
1021 /* Kludge so that we don't get screwed by our own base classes. */
1022 TYPE_BEING_DEFINED (TREE_TYPE (classname
)) = 1;
1023 yychar
= PRE_PARSED_CLASS_DECL
;
1024 yylval
.ttype
= classname
;
1025 processing_template_defn
++;
1026 if (!flag_external_templates
)
1027 interface_unknown
++;
1031 tree t
, decl
, id
, tmpl
;
1034 tmpl
= TREE_PURPOSE (IDENTIFIER_TEMPLATE (id
));
1035 t
= xref_tag (DECL_TEMPLATE_INFO (tmpl
)->aggr
, id
, NULL_TREE
, 0);
1036 my_friendly_assert (TREE_CODE (t
) == RECORD_TYPE
1037 || TREE_CODE (t
) == UNION_TYPE
, 280);
1039 /* Now, put a copy of the decl in global scope, to avoid
1040 * recursive expansion. */
1041 decl
= IDENTIFIER_LOCAL_VALUE (id
);
1043 decl
= IDENTIFIER_CLASS_VALUE (id
);
1046 my_friendly_assert (TREE_CODE (decl
) == TYPE_DECL
, 281);
1047 /* We'd better make sure we're on the permanent obstack or else
1048 * we'll get a "friendly" abort 124 in pushdecl. Perhaps a
1049 * copy_to_permanent would be sufficient here, but then a
1050 * sharing problem might occur. I don't know -- niklas@appli.se */
1051 push_obstacks (&permanent_obstack
, &permanent_obstack
);
1052 pushdecl_top_level (copy_node (decl
));
1055 pop_from_top_level ();
1065 if (t1
== NULL_TREE
)
1066 return t2
== NULL_TREE
;
1067 if (t2
== NULL_TREE
)
1069 /* Don't care if one declares its arg const and the other doesn't -- the
1070 main variant of the arg type is all that matters. */
1071 if (TYPE_MAIN_VARIANT (TREE_VALUE (t1
))
1072 != TYPE_MAIN_VARIANT (TREE_VALUE (t2
)))
1074 return list_eq (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
1078 lookup_nested_type_by_name (ctype
, name
)
1083 t
= TREE_VALUE(CLASSTYPE_TAGS(ctype
));
1086 if (strcmp(IDENTIFIER_POINTER(name
), IDENTIFIER_POINTER(TYPE_IDENTIFIER(t
)))
1096 search_nested_type_in_tmpl (tmpl
, type
)
1101 if (tmpl
== NULL
|| TYPE_CONTEXT(type
) == NULL
)
1103 t
= search_nested_type_in_tmpl (tmpl
, TYPE_CONTEXT(type
));
1104 if (t
== NULL
) return t
;
1105 t
= lookup_nested_type_by_name(t
, DECL_NAME(TYPE_NAME(type
)));
1110 tsubst (t
, args
, nargs
, in_decl
)
1117 if (t
== NULL_TREE
|| t
== error_mark_node
)
1120 type
= TREE_TYPE (t
);
1122 /* Minor optimization.
1123 ?? Are these really the most frequent cases? Is the savings
1125 && type
!= integer_type_node
1126 && type
!= void_type_node
1127 && type
!= char_type_node
)
1128 type
= build_type_variant (tsubst (type
, args
, nargs
, in_decl
),
1129 TYPE_READONLY (type
),
1130 TYPE_VOLATILE (type
));
1131 switch (TREE_CODE (t
))
1134 if (TYPE_PTRMEMFUNC_P (t
))
1135 return build_ptrmemfunc_type
1136 (tsubst (TYPE_PTRMEMFUNC_FN_TYPE (t
), args
, nargs
, in_decl
));
1138 /* else fall through */
1141 case IDENTIFIER_NODE
:
1154 if (t
== integer_type_node
)
1157 if (TREE_CODE (TYPE_MIN_VALUE (t
)) == INTEGER_CST
1158 && TREE_CODE (TYPE_MAX_VALUE (t
)) == INTEGER_CST
)
1160 return build_index_2_type
1161 (tsubst (TYPE_MIN_VALUE (t
), args
, nargs
, in_decl
),
1162 tsubst (TYPE_MAX_VALUE (t
), args
, nargs
, in_decl
));
1164 case TEMPLATE_TYPE_PARM
:
1165 return build_type_variant (args
[TEMPLATE_TYPE_IDX (t
)],
1169 case TEMPLATE_CONST_PARM
:
1170 return args
[TEMPLATE_CONST_IDX (t
)];
1175 tree fnargs
, result
;
1177 if (type
== TREE_TYPE (t
)
1178 && (DECL_CONTEXT (t
) == NULL_TREE
1179 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) != 't'))
1181 fnargs
= tsubst (DECL_ARGUMENTS (t
), args
, nargs
, t
);
1182 result
= tsubst (DECL_RESULT (t
), args
, nargs
, t
);
1183 if (DECL_CONTEXT (t
) != NULL_TREE
1184 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) == 't')
1186 /* Look it up in that class, and return the decl node there,
1187 instead of creating a new one. */
1188 tree ctx
, methods
, name
, method
;
1192 name
= DECL_NAME (t
);
1193 ctx
= tsubst (DECL_CONTEXT (t
), args
, nargs
, t
);
1194 methods
= CLASSTYPE_METHOD_VEC (ctx
);
1195 if (methods
== NULL_TREE
)
1196 /* No methods at all -- no way this one can match. */
1198 n_methods
= TREE_VEC_LENGTH (methods
);
1202 if (!strncmp (OPERATOR_TYPENAME_FORMAT
,
1203 IDENTIFIER_POINTER (name
),
1204 sizeof (OPERATOR_TYPENAME_FORMAT
) - 1))
1206 /* Type-conversion operator. Reconstruct the name, in
1207 case it's the name of one of the template's parameters. */
1208 name
= build_typename_overload (TREE_TYPE (type
));
1211 if (DECL_CONTEXT (t
) != NULL_TREE
1212 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) == 't'
1213 && constructor_name (DECL_CONTEXT (t
)) == DECL_NAME (t
))
1214 name
= constructor_name (ctx
);
1216 fprintf (stderr
, "\nfor function %s in class %s:\n",
1217 IDENTIFIER_POINTER (name
),
1218 IDENTIFIER_POINTER (TYPE_IDENTIFIER (ctx
)));
1220 for (i
= 0; i
< n_methods
; i
++)
1224 method
= TREE_VEC_ELT (methods
, i
);
1225 if (method
== NULL_TREE
|| DECL_NAME (method
) != name
)
1230 for (; method
; method
= DECL_CHAIN (method
))
1232 my_friendly_assert (TREE_CODE (method
) == FUNCTION_DECL
,
1234 if (! comptypes (type
, TREE_TYPE (method
), 1))
1236 tree mtype
= TREE_TYPE (method
);
1239 /* Keep looking for a method that matches
1240 perfectly. This takes care of the problem
1241 where destructors (which have implicit int args)
1242 look like constructors which have an int arg. */
1246 t1
= TYPE_ARG_TYPES (mtype
);
1247 t2
= TYPE_ARG_TYPES (type
);
1248 if (TREE_CODE (mtype
) == FUNCTION_TYPE
)
1249 t2
= TREE_CHAIN (t2
);
1251 if (list_eq (t1
, t2
))
1253 if (TREE_CODE (mtype
) == FUNCTION_TYPE
)
1256 newtype
= build_function_type (TREE_TYPE (type
),
1257 TYPE_ARG_TYPES (type
));
1258 newtype
= build_type_variant (newtype
,
1259 TYPE_READONLY (type
),
1260 TYPE_VOLATILE (type
));
1262 if (TREE_TYPE (type
) != TREE_TYPE (mtype
))
1263 goto maybe_bad_return_type
;
1265 else if (TYPE_METHOD_BASETYPE (mtype
)
1266 == TYPE_METHOD_BASETYPE (type
))
1268 /* Types didn't match, but arg types and
1269 `this' do match, so the return type is
1270 all that should be messing it up. */
1271 maybe_bad_return_type
:
1272 if (TREE_TYPE (type
) != TREE_TYPE (mtype
))
1273 error ("inconsistent return types for method `%s' in class `%s'",
1274 IDENTIFIER_POINTER (name
),
1275 IDENTIFIER_POINTER (TYPE_IDENTIFIER (ctx
)));
1284 fprintf (stderr
, "\tfound %s\n\n",
1285 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (method
)));
1288 if (DECL_ARGUMENTS (method
)
1289 && ! TREE_PERMANENT (DECL_ARGUMENTS (method
)))
1290 /* @@ Is this early enough? Might we want to do
1291 this instead while processing the expansion? */
1292 DECL_ARGUMENTS (method
)
1293 = tsubst (DECL_ARGUMENTS (t
), args
, nargs
, t
);
1297 if (r
== NULL_TREE
&& pass
== 0)
1300 method
= TREE_VEC_ELT (methods
, i
);
1309 ? "template for method `%D' doesn't match any in class `%T'"
1310 : "method `%D' not found in class `%T'", name
, ctx
);
1312 cp_error_at ("in attempt to instantiate `%D' declared at this point in file", in_decl
);
1313 return error_mark_node
;
1323 decls
= lookup_name (r
, 0);
1324 if (decls
== NULL_TREE
)
1326 else if (TREE_CODE (decls
) == TREE_LIST
)
1327 for (decls
= TREE_VALUE (decls
); decls
;
1328 decls
= DECL_CHAIN (decls
))
1330 if (TREE_CODE (decls
) == FUNCTION_DECL
1331 && TREE_TYPE (decls
) == type
)
1342 if (TREE_CODE (val
) == FUNCTION_DECL
1343 && TREE_TYPE (val
) == type
)
1352 r
= build_decl_overload (r
, TYPE_VALUES (type
),
1353 DECL_CONTEXT (t
) != NULL_TREE
);
1354 r
= build_lang_decl (FUNCTION_DECL
, r
, type
);
1356 else if (DECL_INLINE (r
) && DECL_SAVED_INSNS (r
))
1358 /* This overrides the template version, use it. */
1363 TREE_PUBLIC (r
) = TREE_PUBLIC (t
);
1364 DECL_EXTERNAL (r
) = DECL_EXTERNAL (t
);
1365 TREE_STATIC (r
) = TREE_STATIC (t
);
1366 DECL_INLINE (r
) = DECL_INLINE (t
);
1368 #if 0 /* Maybe later. -jason */
1369 struct tinst_level
*til
= tinst_for_decl();
1371 /* should always be true under new approach */
1374 DECL_SOURCE_FILE (r
) = til
->file
;
1375 DECL_SOURCE_LINE (r
) = til
->line
;
1380 DECL_SOURCE_FILE (r
) = DECL_SOURCE_FILE (t
);
1381 DECL_SOURCE_LINE (r
) = DECL_SOURCE_LINE (t
);
1384 DECL_CLASS_CONTEXT (r
) = tsubst (DECL_CLASS_CONTEXT (t
), args
, nargs
, t
);
1385 make_decl_rtl (r
, NULL_PTR
, 1);
1386 DECL_ARGUMENTS (r
) = fnargs
;
1387 DECL_RESULT (r
) = result
;
1388 if (DECL_CONTEXT (t
) == NULL_TREE
1389 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) != 't')
1390 push_overloaded_decl_top_level (r
, 0);
1397 r
= build_decl (PARM_DECL
, DECL_NAME (t
), type
);
1398 DECL_INITIAL (r
) = TREE_TYPE (r
);
1400 TREE_CHAIN (r
) = tsubst (TREE_CHAIN (t
), args
, nargs
, TREE_CHAIN (t
));
1406 tree purpose
, value
, chain
, result
;
1407 int via_public
, via_virtual
, via_protected
;
1409 if (t
== void_list_node
)
1412 via_public
= TREE_VIA_PUBLIC (t
);
1413 via_protected
= TREE_VIA_PROTECTED (t
);
1414 via_virtual
= TREE_VIA_VIRTUAL (t
);
1416 purpose
= TREE_PURPOSE (t
);
1418 purpose
= tsubst (purpose
, args
, nargs
, in_decl
);
1419 value
= TREE_VALUE (t
);
1421 value
= tsubst (value
, args
, nargs
, in_decl
);
1422 chain
= TREE_CHAIN (t
);
1423 if (chain
&& chain
!= void_type_node
)
1424 chain
= tsubst (chain
, args
, nargs
, in_decl
);
1425 if (purpose
== TREE_PURPOSE (t
)
1426 && value
== TREE_VALUE (t
)
1427 && chain
== TREE_CHAIN (t
))
1429 result
= hash_tree_cons (via_public
, via_virtual
, via_protected
,
1430 purpose
, value
, chain
);
1431 TREE_PARMLIST (result
) = TREE_PARMLIST (t
);
1436 int len
= TREE_VEC_LENGTH (t
), need_new
= 0, i
;
1437 tree
*elts
= (tree
*) alloca (len
* sizeof (tree
));
1438 bzero (elts
, len
* sizeof (tree
));
1440 for (i
= 0; i
< len
; i
++)
1442 elts
[i
] = tsubst (TREE_VEC_ELT (t
, i
), args
, nargs
, in_decl
);
1443 if (elts
[i
] != TREE_VEC_ELT (t
, i
))
1450 t
= make_tree_vec (len
);
1451 for (i
= 0; i
< len
; i
++)
1452 TREE_VEC_ELT (t
, i
) = elts
[i
];
1456 case REFERENCE_TYPE
:
1459 enum tree_code code
;
1460 if (type
== TREE_TYPE (t
))
1463 code
= TREE_CODE (t
);
1464 if (code
== POINTER_TYPE
)
1465 r
= build_pointer_type (type
);
1467 r
= build_reference_type (type
);
1468 r
= build_type_variant (r
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1469 /* Will this ever be needed for TYPE_..._TO values? */
1474 return build_offset_type
1475 (tsubst (TYPE_OFFSET_BASETYPE (t
), args
, nargs
, in_decl
), type
);
1479 tree values
= TYPE_VALUES (t
); /* same as TYPE_ARG_TYPES */
1480 tree context
= TYPE_CONTEXT (t
);
1483 /* Don't bother recursing if we know it won't change anything. */
1484 if (values
!= void_list_node
)
1485 values
= tsubst (values
, args
, nargs
, in_decl
);
1487 context
= tsubst (context
, args
, nargs
, in_decl
);
1488 /* Could also optimize cases where return value and
1489 values have common elements (e.g., T min(const &T, const T&). */
1491 /* If the above parameters haven't changed, just return the type. */
1492 if (type
== TREE_TYPE (t
)
1493 && values
== TYPE_VALUES (t
)
1494 && context
== TYPE_CONTEXT (t
))
1497 /* Construct a new type node and return it. */
1498 if (TREE_CODE (t
) == FUNCTION_TYPE
1499 && context
== NULL_TREE
)
1501 new_value
= build_function_type (type
, values
);
1503 else if (context
== NULL_TREE
)
1505 tree base
= tsubst (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))),
1506 args
, nargs
, in_decl
);
1507 new_value
= build_cplus_method_type (base
, type
,
1508 TREE_CHAIN (values
));
1512 new_value
= make_node (TREE_CODE (t
));
1513 TREE_TYPE (new_value
) = type
;
1514 TYPE_CONTEXT (new_value
) = context
;
1515 TYPE_VALUES (new_value
) = values
;
1516 TYPE_SIZE (new_value
) = TYPE_SIZE (t
);
1517 TYPE_ALIGN (new_value
) = TYPE_ALIGN (t
);
1518 TYPE_MODE (new_value
) = TYPE_MODE (t
);
1519 if (TYPE_METHOD_BASETYPE (t
))
1520 TYPE_METHOD_BASETYPE (new_value
) = tsubst (TYPE_METHOD_BASETYPE (t
),
1521 args
, nargs
, in_decl
);
1522 /* Need to generate hash value. */
1523 my_friendly_abort (84);
1525 new_value
= build_type_variant (new_value
,
1532 tree domain
= tsubst (TYPE_DOMAIN (t
), args
, nargs
, in_decl
);
1534 if (type
== TREE_TYPE (t
) && domain
== TYPE_DOMAIN (t
))
1536 r
= build_cplus_array_type (type
, domain
);
1540 case UNINSTANTIATED_P_TYPE
:
1542 int nparms
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (UPT_TEMPLATE (t
)));
1543 tree argvec
= make_tree_vec (nparms
);
1544 tree parmvec
= UPT_PARMS (t
);
1547 for (i
= 0; i
< nparms
; i
++)
1548 TREE_VEC_ELT (argvec
, i
) = tsubst (TREE_VEC_ELT (parmvec
, i
),
1549 args
, nargs
, in_decl
);
1550 id
= lookup_template_class (DECL_NAME (UPT_TEMPLATE (t
)), argvec
, NULL_TREE
);
1551 if (! IDENTIFIER_HAS_TYPE_VALUE (id
)) {
1552 instantiate_class_template(id
, 0);
1553 /* set up pending_classes */
1554 add_pending_template (id
);
1556 TYPE_MAIN_VARIANT (IDENTIFIER_TYPE_VALUE (id
)) =
1557 IDENTIFIER_TYPE_VALUE (id
);
1559 rt
= IDENTIFIER_TYPE_VALUE (id
);
1561 /* kung: this part handles nested type in template definition */
1563 if ( !ANON_AGGRNAME_P (DECL_NAME(TYPE_NAME(t
))))
1565 rt
= search_nested_type_in_tmpl (rt
, t
);
1568 return build_type_variant (rt
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1573 return fold (build (TREE_CODE (t
), TREE_TYPE (t
),
1574 tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
),
1575 tsubst (TREE_OPERAND (t
, 1), args
, nargs
, in_decl
)));
1579 return fold (build1 (TREE_CODE (t
), TREE_TYPE (t
),
1580 tsubst (TREE_OPERAND (t
, 0), args
, nargs
, in_decl
)));
1583 sorry ("use of `%s' in function template",
1584 tree_code_name
[(int) TREE_CODE (t
)]);
1585 return error_mark_node
;
1590 instantiate_template (tmpl
, targ_ptr
)
1591 tree tmpl
, *targ_ptr
;
1595 struct pending_inline
*p
;
1596 struct template_info
*t
;
1597 struct obstack
*old_fmp_obstack
;
1598 extern struct obstack
*function_maybepermanent_obstack
;
1600 push_obstacks (&permanent_obstack
, &permanent_obstack
);
1601 old_fmp_obstack
= function_maybepermanent_obstack
;
1602 function_maybepermanent_obstack
= &permanent_obstack
;
1604 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 283);
1605 len
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (tmpl
));
1607 for (fndecl
= DECL_TEMPLATE_INSTANTIATIONS (tmpl
);
1608 fndecl
; fndecl
= TREE_CHAIN (fndecl
))
1610 tree
*t1
= &TREE_VEC_ELT (TREE_PURPOSE (fndecl
), 0);
1611 for (i
= len
- 1; i
>= 0; i
--)
1612 if (t1
[i
] != targ_ptr
[i
])
1615 /* Here, we have a match. */
1616 fndecl
= TREE_VALUE (fndecl
);
1617 function_maybepermanent_obstack
= old_fmp_obstack
;
1625 targs
= make_tree_vec (len
);
1628 TREE_VEC_ELT (targs
, i
) = targ_ptr
[i
];
1630 /* substitute template parameters */
1631 fndecl
= tsubst (DECL_RESULT (tmpl
), targ_ptr
,
1632 TREE_VEC_LENGTH (targs
), tmpl
);
1634 /* If it's a static member fn in the template, we need to change it
1635 into a FUNCTION_TYPE and chop off its this pointer. */
1636 if (TREE_CODE (TREE_TYPE (DECL_RESULT (tmpl
))) == METHOD_TYPE
1637 && fndecl
!= error_mark_node
1638 && DECL_STATIC_FUNCTION_P (fndecl
))
1640 tree olddecl
= DECL_RESULT (tmpl
);
1641 revert_static_member_fn (&DECL_RESULT (tmpl
), NULL
, NULL
);
1642 /* Chop off the this pointer that grokclassfn so kindly added
1643 for us (it didn't know yet if the fn was static or not). */
1644 DECL_ARGUMENTS (olddecl
) = TREE_CHAIN (DECL_ARGUMENTS (olddecl
));
1645 DECL_ARGUMENTS (fndecl
) = TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
1648 /* If we have a preexisting version of this function, don't expand
1649 the template version, use the other instead. */
1650 t
= DECL_TEMPLATE_INFO (tmpl
);
1651 if (t
->text
&& !(DECL_INLINE (fndecl
) && DECL_SAVED_INSNS (fndecl
)))
1653 p
= (struct pending_inline
*) permalloc (sizeof (struct pending_inline
));
1654 p
->parm_vec
= t
->parm_vec
;
1655 p
->bindings
= targs
;
1663 char * f
= input_filename
;
1665 lineno
= p
->lineno
= t
->lineno
;
1666 input_filename
= p
->filename
= t
->filename
;
1668 extract_interface_info ();
1670 if (interface_unknown
&& flag_external_templates
&& ! DECL_IN_SYSTEM_HEADER (tmpl
))
1671 warn_if_unknown_interface ();
1672 if (interface_unknown
|| !flag_external_templates
)
1673 p
->interface
= 1; /* unknown */
1675 p
->interface
= interface_only
? 0 : 2;
1680 extract_interface_info ();
1684 p
= (struct pending_inline
*)0;
1686 DECL_TEMPLATE_INSTANTIATIONS (tmpl
) =
1687 tree_cons (targs
, fndecl
, DECL_TEMPLATE_INSTANTIATIONS (tmpl
));
1689 function_maybepermanent_obstack
= old_fmp_obstack
;
1692 if (fndecl
== error_mark_node
|| p
== (struct pending_inline
*)0)
1696 else if (DECL_INLINE (fndecl
))
1698 DECL_PENDING_INLINE_INFO (fndecl
) = p
;
1699 p
->next
= pending_inlines
;
1700 pending_inlines
= p
;
1704 p
->next
= pending_template_expansions
;
1705 pending_template_expansions
= p
;
1710 /* classlevel should now never be true. jason 4/12/94 */
1712 undo_template_name_overload (id
, classlevel
)
1718 template = IDENTIFIER_TEMPLATE (id
);
1722 #if 0 /* not yet, should get fixed properly later */
1726 /* This was a botch... See `overload_template_name' just below. */
1732 /* classlevel should now never be true. jason 4/12/94 */
1734 overload_template_name (id
, classlevel
)
1738 tree
template, t
, decl
;
1739 struct template_info
*tinfo
;
1741 my_friendly_assert (TREE_CODE (id
) == IDENTIFIER_NODE
, 284);
1742 template = IDENTIFIER_TEMPLATE (id
);
1746 template = TREE_PURPOSE (template);
1747 tinfo
= DECL_TEMPLATE_INFO (template);
1748 template = DECL_NAME (template);
1749 my_friendly_assert (template != NULL_TREE
, 285);
1752 /* This was a botch... names of templates do not get their own private
1753 scopes. Rather, they should go into the binding level already created
1754 by push_template_decls. Except that there isn't one of those for
1759 declare_pseudo_global_level ();
1763 t
= xref_tag (tinfo
->aggr
, id
, NULL_TREE
, 0);
1764 my_friendly_assert (TREE_CODE (t
) == RECORD_TYPE
1765 || TREE_CODE (t
) == UNION_TYPE
1766 || TREE_CODE (t
) == UNINSTANTIATED_P_TYPE
, 286);
1768 decl
= build_decl (TYPE_DECL
, template, t
);
1770 #if 0 /* fix this later */
1771 /* We don't want to call here if the work has already been done. */
1773 ? IDENTIFIER_CLASS_VALUE (template)
1774 : IDENTIFIER_LOCAL_VALUE (template));
1776 && TREE_CODE (t
) == TYPE_DECL
1777 && TREE_TYPE (t
) == t
)
1778 my_friendly_abort (85);
1782 pushdecl_class_level (decl
);
1786 #if 0 /* This seems bogus to me; if it isn't, explain why. (jason) */
1787 /* Fake this for now, just to make dwarfout.c happy. It will have to
1788 be done in a proper way later on. */
1789 DECL_CONTEXT (decl
) = t
;
1793 /* NAME is the IDENTIFIER value of a PRE_PARSED_CLASS_DECL. */
1795 end_template_instantiation (name
)
1798 extern struct pending_input
*to_be_restored
;
1801 processing_template_defn
--;
1802 if (!flag_external_templates
)
1803 interface_unknown
--;
1805 /* Restore the old parser input state. */
1806 if (yychar
== YYEMPTY
)
1808 if (yychar
!= END_OF_SAVED_INPUT
)
1809 error ("parse error at end of class template");
1812 restore_pending_input (to_be_restored
);
1816 /* Our declarations didn't get stored in the global slot, since
1817 there was a (supposedly tags-transparent) scope in between. */
1818 t
= IDENTIFIER_TYPE_VALUE (name
);
1819 my_friendly_assert (t
!= NULL_TREE
1820 && TREE_CODE_CLASS (TREE_CODE (t
)) == 't',
1822 CLASSTYPE_USE_TEMPLATE (t
) = 2;
1823 /* Make methods of template classes static, unless
1824 -fexternal-templates is given. */
1825 if (!flag_external_templates
)
1826 SET_CLASSTYPE_INTERFACE_UNKNOWN (t
);
1827 decl
= IDENTIFIER_GLOBAL_VALUE (name
);
1828 my_friendly_assert (TREE_CODE (decl
) == TYPE_DECL
, 288);
1830 undo_template_name_overload (name
, 0);
1831 t
= IDENTIFIER_TEMPLATE (name
);
1832 pop_template_decls (DECL_TEMPLATE_PARMS (TREE_PURPOSE (t
)), TREE_VALUE (t
),
1834 /* This will fix up the type-value field. */
1836 pop_from_top_level ();
1838 #ifdef DWARF_DEBUGGING_INFO
1839 if (write_symbols
== DWARF_DEBUG
&& TREE_CODE (decl
) == TYPE_DECL
)
1841 /* We just completed the definition of a new file-scope type,
1842 so we can go ahead and output debug-info for it now. */
1843 TYPE_STUB_DECL (TREE_TYPE (decl
)) = decl
;
1844 rest_of_type_compilation (TREE_TYPE (decl
), 1);
1846 #endif /* DWARF_DEBUGGING_INFO */
1848 /* Restore interface/implementation settings. */
1849 extract_interface_info ();
1852 /* Store away the text of an template. */
1855 reinit_parse_for_template (yychar
, d1
, d2
)
1859 struct template_info
*template_info
;
1860 extern struct obstack inline_text_obstack
; /* see comment in lex.c */
1862 if (d2
== NULL_TREE
|| d2
== error_mark_node
)
1865 /* @@ Should use temp obstack, and discard results. */
1866 reinit_parse_for_block (yychar
, &inline_text_obstack
, 1);
1870 if (TREE_CODE (d2
) == IDENTIFIER_NODE
)
1871 d2
= IDENTIFIER_GLOBAL_VALUE (d2
);
1874 template_info
= DECL_TEMPLATE_INFO (d2
);
1877 template_info
= (struct template_info
*) permalloc (sizeof (struct template_info
));
1878 bzero (template_info
, sizeof (struct template_info
));
1879 DECL_TEMPLATE_INFO (d2
) = template_info
;
1881 template_info
->filename
= input_filename
;
1882 template_info
->lineno
= lineno
;
1883 reinit_parse_for_block (yychar
, &inline_text_obstack
, 1);
1884 template_info
->text
= obstack_base (&inline_text_obstack
);
1885 template_info
->length
= obstack_object_size (&inline_text_obstack
);
1886 obstack_finish (&inline_text_obstack
);
1887 template_info
->parm_vec
= d1
;
1890 /* Type unification.
1892 We have a function template signature with one or more references to
1893 template parameters, and a parameter list we wish to fit to this
1894 template. If possible, produce a list of parameters for the template
1895 which will cause it to fit the supplied parameter list.
1897 Return zero for success, 2 for an incomplete match that doesn't resolve
1898 all the types, and 1 for complete failure. An error message will be
1899 printed only for an incomplete match.
1901 TPARMS[NTPARMS] is an array of template parameter types;
1902 TARGS[NTPARMS] is the array of template parameter values. PARMS is
1903 the function template's signature (using TEMPLATE_PARM_IDX nodes),
1904 and ARGS is the argument list we're trying to match against it.
1906 If SUBR is 1, we're being called recursively (to unify the arguments of
1907 a function or method parameter of a function template), so don't zero
1908 out targs and don't fail on an incomplete match. */
1911 type_unification (tparms
, targs
, parms
, args
, nsubsts
, subr
)
1912 tree tparms
, *targs
, parms
, args
;
1917 int ntparms
= TREE_VEC_LENGTH (tparms
);
1919 my_friendly_assert (TREE_CODE (tparms
) == TREE_VEC
, 289);
1920 my_friendly_assert (TREE_CODE (parms
) == TREE_LIST
, 290);
1921 /* ARGS could be NULL (via a call from parse.y to
1922 build_x_function_call). */
1924 my_friendly_assert (TREE_CODE (args
) == TREE_LIST
, 291);
1925 my_friendly_assert (ntparms
> 0, 292);
1928 bzero (targs
, sizeof (tree
) * ntparms
);
1931 && parms
!= void_list_node
1933 && args
!= void_list_node
)
1935 parm
= TREE_VALUE (parms
);
1936 parms
= TREE_CHAIN (parms
);
1937 arg
= TREE_VALUE (args
);
1938 args
= TREE_CHAIN (args
);
1940 if (arg
== error_mark_node
)
1942 if (arg
== unknown_type_node
)
1945 if (TREE_CODE (arg
) == VAR_DECL
)
1946 arg
= TREE_TYPE (arg
);
1947 else if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'e')
1948 arg
= TREE_TYPE (arg
);
1950 if (TREE_CODE_CLASS (TREE_CODE (arg
)) != 't')
1952 my_friendly_assert (TREE_TYPE (arg
) != NULL_TREE
, 293);
1953 arg
= TREE_TYPE (arg
);
1956 if (TREE_CODE (arg
) == FUNCTION_TYPE
1957 || TREE_CODE (arg
) == METHOD_TYPE
)
1958 arg
= build_pointer_type (arg
);
1960 switch (unify (tparms
, targs
, ntparms
, parm
, arg
, nsubsts
))
1968 /* Fail if we've reached the end of the parm list, and more args
1969 are present, and the parm list isn't variadic. */
1970 if (args
&& args
!= void_list_node
&& parms
== void_list_node
)
1972 /* Fail if parms are left and they don't have default values. */
1974 && parms
!= void_list_node
1975 && TREE_PURPOSE (parms
) == NULL_TREE
)
1978 for (i
= 0; i
< ntparms
; i
++)
1981 error ("incomplete type unification");
1987 /* Tail recursion is your friend. */
1989 unify (tparms
, targs
, ntparms
, parm
, arg
, nsubsts
)
1990 tree tparms
, *targs
, parm
, arg
;
1991 int *nsubsts
, ntparms
;
1995 /* I don't think this will do the right thing with respect to types.
1996 But the only case I've seen it in so far has been array bounds, where
1997 signedness is the only information lost, and I think that will be
1999 while (TREE_CODE (parm
) == NOP_EXPR
)
2000 parm
= TREE_OPERAND (parm
, 0);
2002 if (arg
== error_mark_node
)
2004 if (arg
== unknown_type_node
)
2009 if (TREE_CODE (arg
) == REFERENCE_TYPE
)
2010 arg
= TREE_TYPE (arg
);
2012 switch (TREE_CODE (parm
))
2014 case TEMPLATE_TYPE_PARM
:
2016 if (TEMPLATE_TYPE_TPARMLIST (parm
) != tparms
)
2018 error ("mixed template headers?!");
2019 my_friendly_abort (86);
2022 idx
= TEMPLATE_TYPE_IDX (parm
);
2023 /* Simple cases: Value already set, does match or doesn't. */
2024 if (targs
[idx
] == arg
)
2026 else if (targs
[idx
])
2028 if (TYPE_MAIN_VARIANT (targs
[idx
]) == TYPE_MAIN_VARIANT (arg
))
2029 /* allow different parms to have different cv-qualifiers */;
2033 /* Check for mixed types and values. */
2034 if (TREE_CODE (TREE_VEC_ELT (tparms
, idx
)) != IDENTIFIER_NODE
)
2036 /* Allow trivial conversions. */
2037 if (TYPE_READONLY (parm
) < TYPE_READONLY (arg
)
2038 || TYPE_VOLATILE (parm
) < TYPE_VOLATILE (arg
))
2042 case TEMPLATE_CONST_PARM
:
2044 idx
= TEMPLATE_CONST_IDX (parm
);
2045 if (targs
[idx
] == arg
)
2047 else if (targs
[idx
])
2049 tree t
= targs
[idx
];
2050 if (TREE_CODE (t
) == TREE_CODE (arg
))
2051 switch (TREE_CODE (arg
))
2054 if (tree_int_cst_equal (t
, arg
))
2058 if (REAL_VALUES_EQUAL (TREE_REAL_CST (t
), TREE_REAL_CST (arg
)))
2061 /* STRING_CST values are not valid template const parms. */
2065 my_friendly_abort (87);
2068 /* else if (typeof arg != tparms[idx])
2071 targs
[idx
] = copy_to_permanent (arg
);
2075 if (TREE_CODE (arg
) != POINTER_TYPE
)
2077 return unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
), TREE_TYPE (arg
),
2080 case REFERENCE_TYPE
:
2081 return unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
), arg
, nsubsts
);
2084 if (TREE_CODE (arg
) != ARRAY_TYPE
)
2086 if (unify (tparms
, targs
, ntparms
, TYPE_DOMAIN (parm
), TYPE_DOMAIN (arg
),
2089 return unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
), TREE_TYPE (arg
),
2094 if (TREE_CODE (parm
) == INTEGER_TYPE
&& TREE_CODE (arg
) == INTEGER_TYPE
)
2096 if (TYPE_MIN_VALUE (parm
) && TYPE_MIN_VALUE (arg
)
2097 && unify (tparms
, targs
, ntparms
,
2098 TYPE_MIN_VALUE (parm
), TYPE_MIN_VALUE (arg
), nsubsts
))
2100 if (TYPE_MAX_VALUE (parm
) && TYPE_MAX_VALUE (arg
)
2101 && unify (tparms
, targs
, ntparms
,
2102 TYPE_MAX_VALUE (parm
), TYPE_MAX_VALUE (arg
), nsubsts
))
2105 /* As far as unification is concerned, this wins. Later checks
2106 will invalidate it if necessary. */
2109 /* Types INTEGER_CST and MINUS_EXPR can come from array bounds. */
2111 if (TREE_CODE (arg
) != INTEGER_CST
)
2113 return !tree_int_cst_equal (parm
, arg
);
2118 t1
= TREE_OPERAND (parm
, 0);
2119 t2
= TREE_OPERAND (parm
, 1);
2120 if (TREE_CODE (t1
) != TEMPLATE_CONST_PARM
)
2122 return unify (tparms
, targs
, ntparms
, t1
,
2123 fold (build (PLUS_EXPR
, integer_type_node
, arg
, t2
)),
2130 if (TREE_CODE (arg
) != TREE_VEC
)
2132 if (TREE_VEC_LENGTH (parm
) != TREE_VEC_LENGTH (arg
))
2134 for (i
= TREE_VEC_LENGTH (parm
) - 1; i
>= 0; i
--)
2135 if (unify (tparms
, targs
, ntparms
,
2136 TREE_VEC_ELT (parm
, i
), TREE_VEC_ELT (arg
, i
),
2142 case UNINSTANTIATED_P_TYPE
:
2145 /* Unification of something that is not a template fails. (mrs) */
2146 if (TYPE_NAME (arg
) == 0)
2148 a
= IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (arg
));
2149 /* Unification of something that is not a template fails. (mrs) */
2152 if (UPT_TEMPLATE (parm
) != TREE_PURPOSE (a
))
2153 /* different templates */
2155 return unify (tparms
, targs
, ntparms
, UPT_PARMS (parm
), TREE_VALUE (a
),
2160 if (TYPE_PTRMEMFUNC_P (parm
))
2161 return unify (tparms
, targs
, ntparms
, TYPE_PTRMEMFUNC_FN_TYPE (parm
),
2164 /* Allow trivial conversions. */
2165 if (TYPE_MAIN_VARIANT (parm
) != TYPE_MAIN_VARIANT (arg
)
2166 || TYPE_READONLY (parm
) < TYPE_READONLY (arg
)
2167 || TYPE_VOLATILE (parm
) < TYPE_VOLATILE (arg
))
2172 if (TREE_CODE (arg
) != METHOD_TYPE
)
2177 if (TREE_CODE (arg
) != FUNCTION_TYPE
)
2180 return type_unification (tparms
, targs
, TYPE_ARG_TYPES (parm
),
2181 TYPE_ARG_TYPES (arg
), nsubsts
, 1);
2184 if (TREE_CODE (arg
) != OFFSET_TYPE
)
2186 if (unify (tparms
, targs
, ntparms
, TYPE_OFFSET_BASETYPE (parm
),
2187 TYPE_OFFSET_BASETYPE (arg
), nsubsts
))
2189 return unify (tparms
, targs
, ntparms
, TREE_TYPE (parm
),
2190 TREE_TYPE (arg
), nsubsts
);
2193 sorry ("use of `%s' in template type unification",
2194 tree_code_name
[(int) TREE_CODE (parm
)]);
2203 do_pending_expansions ()
2205 struct pending_inline
*i
, *new_list
= 0;
2207 if (!pending_template_expansions
)
2211 fprintf (stderr
, "\n\n\t\t IN DO_PENDING_EXPANSIONS\n\n");
2214 i
= pending_template_expansions
;
2219 struct pending_inline
*next
= i
->next
;
2223 #define DECIDE(N) do {decision=(N); goto decided;} while(0)
2225 my_friendly_assert (TREE_CODE (t
) == FUNCTION_DECL
2226 || TREE_CODE (t
) == VAR_DECL
, 294);
2227 if (TREE_ASM_WRITTEN (t
))
2230 if (DECL_EXPLICITLY_INSTANTIATED (t
))
2233 /* If it's a method, let the class type decide it.
2234 @@ What if the method template is in a separate file?
2235 Maybe both file contexts should be taken into account?
2236 Maybe only do this if i->interface == 1 (unknown)? */
2237 context
= DECL_CONTEXT (t
);
2238 if (context
!= NULL_TREE
2239 && TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
2241 /* I'm interested in the context of this version of the function,
2242 not the original virtual declaration. */
2243 context
= DECL_CLASS_CONTEXT (t
);
2245 /* If `unknown', we might want a static copy.
2246 If `implementation', we want a global one.
2247 If `interface', ext ref. */
2248 if (CLASSTYPE_INTERFACE_KNOWN (context
))
2249 DECIDE (!CLASSTYPE_INTERFACE_ONLY (context
));
2250 #if 0 /* This doesn't get us stuff needed only by the file initializer. */
2251 DECIDE (TREE_USED (t
));
2252 #else /* This compiles too much stuff, but that's probably better in
2253 most cases than never compiling the stuff we need. */
2258 if (i
->interface
== 1)
2259 DECIDE (TREE_USED (t
));
2261 DECIDE (i
->interface
);
2265 print_node_brief (stderr
, decision
? "yes: " : "no: ", t
, 0);
2266 fprintf (stderr
, "\t%s\n",
2267 (DECL_ASSEMBLER_NAME (t
)
2268 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t
))
2273 i
->next
= pending_inlines
;
2274 pending_inlines
= i
;
2283 pending_template_expansions
= new_list
;
2284 if (!pending_inlines
)
2286 do_pending_inlines ();
2291 struct pending_template
{
2292 struct pending_template
*next
;
2296 static struct pending_template
* pending_templates
;
2299 do_pending_templates ()
2301 struct pending_template
* t
;
2303 for ( t
= pending_templates
; t
; t
= t
->next
)
2305 instantiate_class_template (t
->id
, 1);
2308 for ( t
= pending_templates
; t
; t
= pending_templates
)
2310 pending_templates
= t
->next
;
2316 add_pending_template (pt
)
2319 struct pending_template
*p
;
2321 p
= (struct pending_template
*) malloc (sizeof (struct pending_template
));
2322 p
->next
= pending_templates
;
2323 pending_templates
= p
;
2327 /* called from the parser. */
2329 do_function_instantiation (declspecs
, declarator
)
2330 tree declspecs
, declarator
;
2332 tree decl
= grokdeclarator (declarator
, declspecs
, NORMAL
, 0, 0);
2333 tree name
= DECL_NAME (decl
);
2334 tree fn
= IDENTIFIER_GLOBAL_VALUE (name
);
2335 tree result
= NULL_TREE
;
2338 for (fn
= get_first_fn (fn
); fn
; fn
= DECL_CHAIN (fn
))
2339 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2341 int ntparms
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (fn
));
2342 tree
*targs
= (tree
*) malloc (sizeof (tree
) * ntparms
);
2344 i
= type_unification (DECL_TEMPLATE_PARMS (fn
), targs
,
2345 TYPE_ARG_TYPES (TREE_TYPE (fn
)),
2346 TYPE_ARG_TYPES (TREE_TYPE (decl
)),
2351 cp_error ("ambiguous template instantiation for `%D' requested", decl
);
2353 result
= instantiate_template (fn
, targs
);
2358 cp_error ("no matching template for `%D' found", decl
);
2360 DECL_EXPLICITLY_INSTANTIATED (result
) = 1;
2364 do_type_instantiation (name
)
2367 tree t
= TREE_TYPE (name
);
2369 CLASSTYPE_EXPLICITLY_INSTANTIATED (t
) = 1;
2370 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
2372 /* this should really be done by instantiate_member_templates */
2374 tree method
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t
), 0);
2375 for (; method
; method
= TREE_CHAIN (method
))
2376 DECL_EXPLICITLY_INSTANTIATED (method
) = 1;
2379 /* and data member templates, too */
2383 create_nested_upt (scope
, name
)
2386 tree t
= make_lang_type (UNINSTANTIATED_P_TYPE
);
2387 tree d
= build_lang_decl (TYPE_DECL
, name
, t
);
2390 TYPE_VALUES (t
) = TYPE_VALUES (scope
);
2391 TYPE_CONTEXT (t
) = scope
;