2011-01-22 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / fortran / class.c
blob2227f9e72f3d09648f16d91d6936fe4a8fb6a219
1 /* Implementation of Fortran 2003 Polymorphism.
2 Copyright (C) 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Paul Richard Thomas <pault@gcc.gnu.org>
5 and Janus Weil <janus@gcc.gnu.org>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
24 /* class.c -- This file contains the front end functions needed to service
25 the implementation of Fortran 2003 polymorphism and other
26 object-oriented features. */
29 /* Outline of the internal representation:
31 Each CLASS variable is encapsulated by a class container, which is a
32 structure with two fields:
33 * _data: A pointer to the actual data of the variable. This field has the
34 declared type of the class variable and its attributes
35 (pointer/allocatable/dimension/...).
36 * _vptr: A pointer to the vtable entry (see below) of the dynamic type.
38 For each derived type we set up a "vtable" entry, i.e. a structure with the
39 following fields:
40 * _hash: A hash value serving as a unique identifier for this type.
41 * _size: The size in bytes of the derived type.
42 * _extends: A pointer to the vtable entry of the parent derived type.
43 * _def_init: A pointer to a default initialized variable of this type.
44 * _copy: A procedure pointer to a copying procedure.
45 After these follow procedure pointer components for the specific
46 type-bound procedures. */
49 #include "config.h"
50 #include "system.h"
51 #include "gfortran.h"
52 #include "constructor.h"
55 /* Insert a reference to the component of the given name.
56 Only to be used with CLASS containers and vtables. */
58 void
59 gfc_add_component_ref (gfc_expr *e, const char *name)
61 gfc_ref **tail = &(e->ref);
62 gfc_ref *next = NULL;
63 gfc_symbol *derived = e->symtree->n.sym->ts.u.derived;
64 while (*tail != NULL)
66 if ((*tail)->type == REF_COMPONENT)
67 derived = (*tail)->u.c.component->ts.u.derived;
68 if ((*tail)->type == REF_ARRAY && (*tail)->next == NULL)
69 break;
70 tail = &((*tail)->next);
72 if (*tail != NULL && strcmp (name, "_data") == 0)
73 next = *tail;
74 (*tail) = gfc_get_ref();
75 (*tail)->next = next;
76 (*tail)->type = REF_COMPONENT;
77 (*tail)->u.c.sym = derived;
78 (*tail)->u.c.component = gfc_find_component (derived, name, true, true);
79 gcc_assert((*tail)->u.c.component);
80 if (!next)
81 e->ts = (*tail)->u.c.component->ts;
85 /* Build a NULL initializer for CLASS pointers,
86 initializing the _data component to NULL and
87 the _vptr component to the declared type. */
89 gfc_expr *
90 gfc_class_null_initializer (gfc_typespec *ts)
92 gfc_expr *init;
93 gfc_component *comp;
95 init = gfc_get_structure_constructor_expr (ts->type, ts->kind,
96 &ts->u.derived->declared_at);
97 init->ts = *ts;
99 for (comp = ts->u.derived->components; comp; comp = comp->next)
101 gfc_constructor *ctor = gfc_constructor_get();
102 if (strcmp (comp->name, "_vptr") == 0)
103 ctor->expr = gfc_lval_expr_from_sym (gfc_find_derived_vtab (ts->u.derived));
104 else
105 ctor->expr = gfc_get_null_expr (NULL);
106 gfc_constructor_append (&init->value.constructor, ctor);
109 return init;
113 /* Create a unique string identifier for a derived type, composed of its name
114 and module name. This is used to construct unique names for the class
115 containers and vtab symbols. */
117 static void
118 get_unique_type_string (char *string, gfc_symbol *derived)
120 char dt_name[GFC_MAX_SYMBOL_LEN+1];
121 sprintf (dt_name, "%s", derived->name);
122 dt_name[0] = TOUPPER (dt_name[0]);
123 if (derived->module)
124 sprintf (string, "%s_%s", derived->module, dt_name);
125 else if (derived->ns->proc_name)
126 sprintf (string, "%s_%s", derived->ns->proc_name->name, dt_name);
127 else
128 sprintf (string, "_%s", dt_name);
132 /* A relative of 'get_unique_type_string' which makes sure the generated
133 string will not be too long (replacing it by a hash string if needed). */
135 static void
136 get_unique_hashed_string (char *string, gfc_symbol *derived)
138 char tmp[2*GFC_MAX_SYMBOL_LEN+2];
139 get_unique_type_string (&tmp[0], derived);
140 /* If string is too long, use hash value in hex representation
141 (allow for extra decoration, cf. gfc_build_class_symbol)*/
142 if (strlen (tmp) > GFC_MAX_SYMBOL_LEN - 10)
144 int h = gfc_hash_value (derived);
145 sprintf (string, "%X", h);
147 else
148 strcpy (string, tmp);
152 /* Assign a hash value for a derived type. The algorithm is that of SDBM. */
154 unsigned int
155 gfc_hash_value (gfc_symbol *sym)
157 unsigned int hash = 0;
158 char c[2*(GFC_MAX_SYMBOL_LEN+1)];
159 int i, len;
161 get_unique_type_string (&c[0], sym);
162 len = strlen (c);
164 for (i = 0; i < len; i++)
165 hash = (hash << 6) + (hash << 16) - hash + c[i];
167 /* Return the hash but take the modulus for the sake of module read,
168 even though this slightly increases the chance of collision. */
169 return (hash % 100000000);
173 /* Build a polymorphic CLASS entity, using the symbol that comes from
174 build_sym. A CLASS entity is represented by an encapsulating type,
175 which contains the declared type as '_data' component, plus a pointer
176 component '_vptr' which determines the dynamic type. */
178 gfc_try
179 gfc_build_class_symbol (gfc_typespec *ts, symbol_attribute *attr,
180 gfc_array_spec **as, bool delayed_vtab)
182 char name[GFC_MAX_SYMBOL_LEN+1], tname[GFC_MAX_SYMBOL_LEN+1];
183 gfc_symbol *fclass;
184 gfc_symbol *vtab;
185 gfc_component *c;
187 /* Determine the name of the encapsulating type. */
188 get_unique_hashed_string (tname, ts->u.derived);
189 if ((*as) && (*as)->rank && attr->allocatable)
190 sprintf (name, "__class_%s_%d_a", tname, (*as)->rank);
191 else if ((*as) && (*as)->rank)
192 sprintf (name, "__class_%s_%d", tname, (*as)->rank);
193 else if (attr->pointer)
194 sprintf (name, "__class_%s_p", tname);
195 else if (attr->allocatable)
196 sprintf (name, "__class_%s_a", tname);
197 else
198 sprintf (name, "__class_%s", tname);
200 gfc_find_symbol (name, ts->u.derived->ns, 0, &fclass);
201 if (fclass == NULL)
203 gfc_symtree *st;
204 /* If not there, create a new symbol. */
205 fclass = gfc_new_symbol (name, ts->u.derived->ns);
206 st = gfc_new_symtree (&ts->u.derived->ns->sym_root, name);
207 st->n.sym = fclass;
208 gfc_set_sym_referenced (fclass);
209 fclass->refs++;
210 fclass->ts.type = BT_UNKNOWN;
211 fclass->attr.abstract = ts->u.derived->attr.abstract;
212 if (ts->u.derived->f2k_derived)
213 fclass->f2k_derived = gfc_get_namespace (NULL, 0);
214 if (gfc_add_flavor (&fclass->attr, FL_DERIVED,
215 NULL, &gfc_current_locus) == FAILURE)
216 return FAILURE;
218 /* Add component '_data'. */
219 if (gfc_add_component (fclass, "_data", &c) == FAILURE)
220 return FAILURE;
221 c->ts = *ts;
222 c->ts.type = BT_DERIVED;
223 c->attr.access = ACCESS_PRIVATE;
224 c->ts.u.derived = ts->u.derived;
225 c->attr.class_pointer = attr->pointer;
226 c->attr.pointer = attr->pointer || attr->dummy;
227 c->attr.allocatable = attr->allocatable;
228 c->attr.dimension = attr->dimension;
229 c->attr.codimension = attr->codimension;
230 c->attr.abstract = ts->u.derived->attr.abstract;
231 c->as = (*as);
232 c->initializer = NULL;
234 /* Add component '_vptr'. */
235 if (gfc_add_component (fclass, "_vptr", &c) == FAILURE)
236 return FAILURE;
237 c->ts.type = BT_DERIVED;
238 if (delayed_vtab)
239 c->ts.u.derived = NULL;
240 else
242 vtab = gfc_find_derived_vtab (ts->u.derived);
243 gcc_assert (vtab);
244 c->ts.u.derived = vtab->ts.u.derived;
246 c->attr.access = ACCESS_PRIVATE;
247 c->attr.pointer = 1;
250 /* Since the extension field is 8 bit wide, we can only have
251 up to 255 extension levels. */
252 if (ts->u.derived->attr.extension == 255)
254 gfc_error ("Maximum extension level reached with type '%s' at %L",
255 ts->u.derived->name, &ts->u.derived->declared_at);
256 return FAILURE;
259 fclass->attr.extension = ts->u.derived->attr.extension + 1;
260 fclass->attr.is_class = 1;
261 ts->u.derived = fclass;
262 attr->allocatable = attr->pointer = attr->dimension = 0;
263 (*as) = NULL; /* XXX */
264 return SUCCESS;
268 /* Add a procedure pointer component to the vtype
269 to represent a specific type-bound procedure. */
271 static void
272 add_proc_comp (gfc_symbol *vtype, const char *name, gfc_typebound_proc *tb)
274 gfc_component *c;
275 c = gfc_find_component (vtype, name, true, true);
277 if (c == NULL)
279 /* Add procedure component. */
280 if (gfc_add_component (vtype, name, &c) == FAILURE)
281 return;
283 if (!c->tb)
284 c->tb = XCNEW (gfc_typebound_proc);
285 *c->tb = *tb;
286 c->tb->ppc = 1;
287 c->attr.procedure = 1;
288 c->attr.proc_pointer = 1;
289 c->attr.flavor = FL_PROCEDURE;
290 c->attr.access = ACCESS_PRIVATE;
291 c->attr.external = 1;
292 c->attr.untyped = 1;
293 c->attr.if_source = IFSRC_IFBODY;
295 else if (c->attr.proc_pointer && c->tb)
297 *c->tb = *tb;
298 c->tb->ppc = 1;
301 if (tb->u.specific)
303 c->ts.interface = tb->u.specific->n.sym;
304 if (!tb->deferred)
305 c->initializer = gfc_get_variable_expr (tb->u.specific);
310 /* Add all specific type-bound procedures in the symtree 'st' to a vtype. */
312 static void
313 add_procs_to_declared_vtab1 (gfc_symtree *st, gfc_symbol *vtype)
315 if (!st)
316 return;
318 if (st->left)
319 add_procs_to_declared_vtab1 (st->left, vtype);
321 if (st->right)
322 add_procs_to_declared_vtab1 (st->right, vtype);
324 if (st->n.tb && !st->n.tb->error
325 && !st->n.tb->is_generic && st->n.tb->u.specific)
326 add_proc_comp (vtype, st->name, st->n.tb);
330 /* Copy procedure pointers components from the parent type. */
332 static void
333 copy_vtab_proc_comps (gfc_symbol *declared, gfc_symbol *vtype)
335 gfc_component *cmp;
336 gfc_symbol *vtab;
338 vtab = gfc_find_derived_vtab (declared);
340 for (cmp = vtab->ts.u.derived->components; cmp; cmp = cmp->next)
342 if (gfc_find_component (vtype, cmp->name, true, true))
343 continue;
345 add_proc_comp (vtype, cmp->name, cmp->tb);
350 /* Add procedure pointers for all type-bound procedures to a vtab. */
352 static void
353 add_procs_to_declared_vtab (gfc_symbol *derived, gfc_symbol *vtype)
355 gfc_symbol* super_type;
357 super_type = gfc_get_derived_super_type (derived);
359 if (super_type && (super_type != derived))
361 /* Make sure that the PPCs appear in the same order as in the parent. */
362 copy_vtab_proc_comps (super_type, vtype);
363 /* Only needed to get the PPC initializers right. */
364 add_procs_to_declared_vtab (super_type, vtype);
367 if (derived->f2k_derived && derived->f2k_derived->tb_sym_root)
368 add_procs_to_declared_vtab1 (derived->f2k_derived->tb_sym_root, vtype);
370 if (derived->f2k_derived && derived->f2k_derived->tb_uop_root)
371 add_procs_to_declared_vtab1 (derived->f2k_derived->tb_uop_root, vtype);
375 /* Find (or generate) the symbol for a derived type's vtab. */
377 gfc_symbol *
378 gfc_find_derived_vtab (gfc_symbol *derived)
380 gfc_namespace *ns;
381 gfc_symbol *vtab = NULL, *vtype = NULL, *found_sym = NULL, *def_init = NULL;
382 gfc_symbol *copy = NULL, *src = NULL, *dst = NULL;
384 /* Find the top-level namespace (MODULE or PROGRAM). */
385 for (ns = gfc_current_ns; ns; ns = ns->parent)
386 if (!ns->parent)
387 break;
389 /* If the type is a class container, use the underlying derived type. */
390 if (derived->attr.is_class)
391 derived = gfc_get_derived_super_type (derived);
393 if (ns)
395 char name[GFC_MAX_SYMBOL_LEN+1], tname[GFC_MAX_SYMBOL_LEN+1];
397 get_unique_hashed_string (tname, derived);
398 sprintf (name, "__vtab_%s", tname);
400 /* Look for the vtab symbol in various namespaces. */
401 gfc_find_symbol (name, gfc_current_ns, 0, &vtab);
402 if (vtab == NULL)
403 gfc_find_symbol (name, ns, 0, &vtab);
404 if (vtab == NULL)
405 gfc_find_symbol (name, derived->ns, 0, &vtab);
407 if (vtab == NULL)
409 gfc_get_symbol (name, ns, &vtab);
410 vtab->ts.type = BT_DERIVED;
411 if (gfc_add_flavor (&vtab->attr, FL_VARIABLE, NULL,
412 &gfc_current_locus) == FAILURE)
413 goto cleanup;
414 vtab->attr.target = 1;
415 vtab->attr.save = SAVE_EXPLICIT;
416 vtab->attr.vtab = 1;
417 vtab->attr.access = ACCESS_PUBLIC;
418 gfc_set_sym_referenced (vtab);
419 sprintf (name, "__vtype_%s", tname);
421 gfc_find_symbol (name, ns, 0, &vtype);
422 if (vtype == NULL)
424 gfc_component *c;
425 gfc_symbol *parent = NULL, *parent_vtab = NULL;
427 gfc_get_symbol (name, ns, &vtype);
428 if (gfc_add_flavor (&vtype->attr, FL_DERIVED,
429 NULL, &gfc_current_locus) == FAILURE)
430 goto cleanup;
431 vtype->attr.access = ACCESS_PUBLIC;
432 vtype->attr.vtype = 1;
433 gfc_set_sym_referenced (vtype);
435 /* Add component '_hash'. */
436 if (gfc_add_component (vtype, "_hash", &c) == FAILURE)
437 goto cleanup;
438 c->ts.type = BT_INTEGER;
439 c->ts.kind = 4;
440 c->attr.access = ACCESS_PRIVATE;
441 c->initializer = gfc_get_int_expr (gfc_default_integer_kind,
442 NULL, derived->hash_value);
444 /* Add component '_size'. */
445 if (gfc_add_component (vtype, "_size", &c) == FAILURE)
446 goto cleanup;
447 c->ts.type = BT_INTEGER;
448 c->ts.kind = 4;
449 c->attr.access = ACCESS_PRIVATE;
450 /* Remember the derived type in ts.u.derived,
451 so that the correct initializer can be set later on
452 (in gfc_conv_structure). */
453 c->ts.u.derived = derived;
454 c->initializer = gfc_get_int_expr (gfc_default_integer_kind,
455 NULL, 0);
457 /* Add component _extends. */
458 if (gfc_add_component (vtype, "_extends", &c) == FAILURE)
459 goto cleanup;
460 c->attr.pointer = 1;
461 c->attr.access = ACCESS_PRIVATE;
462 parent = gfc_get_derived_super_type (derived);
463 if (parent)
465 parent_vtab = gfc_find_derived_vtab (parent);
466 c->ts.type = BT_DERIVED;
467 c->ts.u.derived = parent_vtab->ts.u.derived;
468 c->initializer = gfc_get_expr ();
469 c->initializer->expr_type = EXPR_VARIABLE;
470 gfc_find_sym_tree (parent_vtab->name, parent_vtab->ns,
471 0, &c->initializer->symtree);
473 else
475 c->ts.type = BT_DERIVED;
476 c->ts.u.derived = vtype;
477 c->initializer = gfc_get_null_expr (NULL);
480 if (derived->components == NULL && !derived->attr.zero_comp)
482 /* At this point an error must have occurred.
483 Prevent further errors on the vtype components. */
484 found_sym = vtab;
485 goto have_vtype;
488 /* Add component _def_init. */
489 if (gfc_add_component (vtype, "_def_init", &c) == FAILURE)
490 goto cleanup;
491 c->attr.pointer = 1;
492 c->attr.access = ACCESS_PRIVATE;
493 c->ts.type = BT_DERIVED;
494 c->ts.u.derived = derived;
495 if (derived->attr.abstract)
496 c->initializer = gfc_get_null_expr (NULL);
497 else
499 /* Construct default initialization variable. */
500 sprintf (name, "__def_init_%s", tname);
501 gfc_get_symbol (name, ns, &def_init);
502 def_init->attr.target = 1;
503 def_init->attr.save = SAVE_EXPLICIT;
504 def_init->attr.access = ACCESS_PUBLIC;
505 def_init->attr.flavor = FL_VARIABLE;
506 gfc_set_sym_referenced (def_init);
507 def_init->ts.type = BT_DERIVED;
508 def_init->ts.u.derived = derived;
509 def_init->value = gfc_default_initializer (&def_init->ts);
511 c->initializer = gfc_lval_expr_from_sym (def_init);
514 /* Add component _copy. */
515 if (gfc_add_component (vtype, "_copy", &c) == FAILURE)
516 goto cleanup;
517 c->attr.proc_pointer = 1;
518 c->attr.access = ACCESS_PRIVATE;
519 c->tb = XCNEW (gfc_typebound_proc);
520 c->tb->ppc = 1;
521 if (derived->attr.abstract)
522 c->initializer = gfc_get_null_expr (NULL);
523 else
525 /* Set up namespace. */
526 gfc_namespace *sub_ns = gfc_get_namespace (ns, 0);
527 sub_ns->sibling = ns->contained;
528 ns->contained = sub_ns;
529 sub_ns->resolved = 1;
530 /* Set up procedure symbol. */
531 sprintf (name, "__copy_%s", tname);
532 gfc_get_symbol (name, sub_ns, &copy);
533 sub_ns->proc_name = copy;
534 copy->attr.flavor = FL_PROCEDURE;
535 copy->attr.if_source = IFSRC_DECL;
536 if (ns->proc_name->attr.flavor == FL_MODULE)
537 copy->module = ns->proc_name->name;
538 gfc_set_sym_referenced (copy);
539 /* Set up formal arguments. */
540 gfc_get_symbol ("src", sub_ns, &src);
541 src->ts.type = BT_DERIVED;
542 src->ts.u.derived = derived;
543 src->attr.flavor = FL_VARIABLE;
544 src->attr.dummy = 1;
545 gfc_set_sym_referenced (src);
546 copy->formal = gfc_get_formal_arglist ();
547 copy->formal->sym = src;
548 gfc_get_symbol ("dst", sub_ns, &dst);
549 dst->ts.type = BT_DERIVED;
550 dst->ts.u.derived = derived;
551 dst->attr.flavor = FL_VARIABLE;
552 dst->attr.dummy = 1;
553 gfc_set_sym_referenced (dst);
554 copy->formal->next = gfc_get_formal_arglist ();
555 copy->formal->next->sym = dst;
556 /* Set up code. */
557 sub_ns->code = gfc_get_code ();
558 sub_ns->code->op = EXEC_INIT_ASSIGN;
559 sub_ns->code->expr1 = gfc_lval_expr_from_sym (dst);
560 sub_ns->code->expr2 = gfc_lval_expr_from_sym (src);
561 /* Set initializer. */
562 c->initializer = gfc_lval_expr_from_sym (copy);
563 c->ts.interface = copy;
566 /* Add procedure pointers for type-bound procedures. */
567 add_procs_to_declared_vtab (derived, vtype);
570 have_vtype:
571 vtab->ts.u.derived = vtype;
572 vtab->value = gfc_default_initializer (&vtab->ts);
576 found_sym = vtab;
578 cleanup:
579 /* It is unexpected to have some symbols added at resolution or code
580 generation time. We commit the changes in order to keep a clean state. */
581 if (found_sym)
583 gfc_commit_symbol (vtab);
584 if (vtype)
585 gfc_commit_symbol (vtype);
586 if (def_init)
587 gfc_commit_symbol (def_init);
588 if (copy)
589 gfc_commit_symbol (copy);
590 if (src)
591 gfc_commit_symbol (src);
592 if (dst)
593 gfc_commit_symbol (dst);
595 else
596 gfc_undo_symbols ();
598 return found_sym;
602 /* General worker function to find either a type-bound procedure or a
603 type-bound user operator. */
605 static gfc_symtree*
606 find_typebound_proc_uop (gfc_symbol* derived, gfc_try* t,
607 const char* name, bool noaccess, bool uop,
608 locus* where)
610 gfc_symtree* res;
611 gfc_symtree* root;
613 /* Set correct symbol-root. */
614 gcc_assert (derived->f2k_derived);
615 root = (uop ? derived->f2k_derived->tb_uop_root
616 : derived->f2k_derived->tb_sym_root);
618 /* Set default to failure. */
619 if (t)
620 *t = FAILURE;
622 /* Try to find it in the current type's namespace. */
623 res = gfc_find_symtree (root, name);
624 if (res && res->n.tb && !res->n.tb->error)
626 /* We found one. */
627 if (t)
628 *t = SUCCESS;
630 if (!noaccess && derived->attr.use_assoc
631 && res->n.tb->access == ACCESS_PRIVATE)
633 if (where)
634 gfc_error ("'%s' of '%s' is PRIVATE at %L",
635 name, derived->name, where);
636 if (t)
637 *t = FAILURE;
640 return res;
643 /* Otherwise, recurse on parent type if derived is an extension. */
644 if (derived->attr.extension)
646 gfc_symbol* super_type;
647 super_type = gfc_get_derived_super_type (derived);
648 gcc_assert (super_type);
650 return find_typebound_proc_uop (super_type, t, name,
651 noaccess, uop, where);
654 /* Nothing found. */
655 return NULL;
659 /* Find a type-bound procedure or user operator by name for a derived-type
660 (looking recursively through the super-types). */
662 gfc_symtree*
663 gfc_find_typebound_proc (gfc_symbol* derived, gfc_try* t,
664 const char* name, bool noaccess, locus* where)
666 return find_typebound_proc_uop (derived, t, name, noaccess, false, where);
669 gfc_symtree*
670 gfc_find_typebound_user_op (gfc_symbol* derived, gfc_try* t,
671 const char* name, bool noaccess, locus* where)
673 return find_typebound_proc_uop (derived, t, name, noaccess, true, where);
677 /* Find a type-bound intrinsic operator looking recursively through the
678 super-type hierarchy. */
680 gfc_typebound_proc*
681 gfc_find_typebound_intrinsic_op (gfc_symbol* derived, gfc_try* t,
682 gfc_intrinsic_op op, bool noaccess,
683 locus* where)
685 gfc_typebound_proc* res;
687 /* Set default to failure. */
688 if (t)
689 *t = FAILURE;
691 /* Try to find it in the current type's namespace. */
692 if (derived->f2k_derived)
693 res = derived->f2k_derived->tb_op[op];
694 else
695 res = NULL;
697 /* Check access. */
698 if (res && !res->error)
700 /* We found one. */
701 if (t)
702 *t = SUCCESS;
704 if (!noaccess && derived->attr.use_assoc
705 && res->access == ACCESS_PRIVATE)
707 if (where)
708 gfc_error ("'%s' of '%s' is PRIVATE at %L",
709 gfc_op2string (op), derived->name, where);
710 if (t)
711 *t = FAILURE;
714 return res;
717 /* Otherwise, recurse on parent type if derived is an extension. */
718 if (derived->attr.extension)
720 gfc_symbol* super_type;
721 super_type = gfc_get_derived_super_type (derived);
722 gcc_assert (super_type);
724 return gfc_find_typebound_intrinsic_op (super_type, t, op,
725 noaccess, where);
728 /* Nothing found. */
729 return NULL;
733 /* Get a typebound-procedure symtree or create and insert it if not yet
734 present. This is like a very simplified version of gfc_get_sym_tree for
735 tbp-symtrees rather than regular ones. */
737 gfc_symtree*
738 gfc_get_tbp_symtree (gfc_symtree **root, const char *name)
740 gfc_symtree *result;
742 result = gfc_find_symtree (*root, name);
743 if (!result)
745 result = gfc_new_symtree (root, name);
746 gcc_assert (result);
747 result->n.tb = NULL;
750 return result;