3 * @file tp_inheritance.h
5 * Project: libFIRM <br>
6 * File name: ir/tr/tp_inheritance.h <br>
7 * Purpose: Utility routines for inheritance representation <br>
8 * Author: Goetz Lindenmaier <br>
11 * Copyright: (c) 2001-2005 Universität Karlsruhe <br>
12 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. <br>
15 * This file supplies a set of utility routines for the inheritance
18 * Inheritance is represented in Firm by two relations: sub/supertype
19 * between class types, overwrites/ovwerwrittenby between entities.
21 * - Classify pairs of types/entities in the inheritance relations.
22 * - Resolve implicit inheritance.
23 * - Compute the transitive closure of the subclass/superclass and
24 * overwrites/overwrittenby relation.
26 * @see type.h entity.h
29 #ifndef _TR_INHERITANCE_H_
30 #define _TR_INHERITANCE_H_
33 /* #include "entity.h" */
36 /* ----------------------------------------------------------------------- */
37 /* Classify pairs of types/entities in the inheritance relations. */
38 /* ----------------------------------------------------------------------- */
40 /** Returns true if low is subclass of high.
42 * Low is a subclass of high if low == high or if low is a subclass of
43 * a subclass of high. I.e, we search in all subtypes of high for low.
44 * @@@ this can be implemented more efficient if we know the set of all
45 * subclasses of high. */
46 int is_subclass_of(type *low, type *high);
48 /** Returns true if high is (transitive) overwritten by low.
50 * Returns false if high == low. */
51 int is_overwritten_by(entity *high, entity *low);
53 /** Resolve polymorphy in the inheritance relation.
55 * Returns the dynamically referenced entity if the static entity and the
56 * dynamic type are given.
57 * Searches downwards in overwritten tree. */
58 entity *resolve_ent_polymorphy(type *dynamic_class, entity* static_ent);
60 /* ----------------------------------------------------------------------- */
61 /* Resolve implicit inheritance. */
62 /* ----------------------------------------------------------------------- */
64 /** Default name mangling for inherited entities.
66 * Returns an ident that consists of the name of type followed by an
67 * underscore and the name (not ld_name) of the entity. */
68 ident *default_mangle_inherited_name(entity *super, type *clss);
70 /** Type of argument functions for inheritance resolver.
72 * @param super The entity in the super type that will be overwritten
73 * by the newly generated entity, for which this name is
75 * @param clss The class type in which the new entity will be placed.
77 typedef ident *mangle_inherited_name_func(entity *super, type *clss);
79 /** Resolve implicit inheritance.
81 * Resolves the implicit inheritance supplied by firm. Firm defines,
82 * that each entity that is not overwritten in a subclass is
83 * inherited to this subclass without change implicitly. This
84 * function generates entities that explicitly represent this
85 * inheritance. It generates for each entity overwriting entities in
86 * all subclasses of the owner of the entity, if the entity is not
87 * overwritten in that subclass.
89 * The name of the new entity is generated with the function passed.
90 * If the function is NULL, the default_mangle_inherited_name() is
93 * This function was moved here from firmlower 3/2005.
95 void resolve_inheritance(mangle_inherited_name_func *mfunc);
98 /* ----------------------------------------------------------------------- */
99 /* The transitive closure of the subclass/superclass and */
100 /* overwrites/overwrittenby relation. */
102 /* A walk over the ir (O(#types+#entities)) computes the transitive */
103 /* closure. Adding a new type/entity or changing the basic relations in */
104 /* some other way invalidates the transitive closure, i.e., it is not */
105 /* updated by the basic functions. */
107 /* The transitive edges are held in a set, not in an array as the */
108 /* underlying relation. */
109 /* ----------------------------------------------------------------------- */
111 /** The state of the transitive closure.
113 * @TODO: we could manage the state for each relation separately. Invalidating
114 * the entity relations does not mean invalidating the class relation. */
116 inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */
117 inh_transitive_closure_valid, /**< Closure computed and valid. */
118 inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */
119 inh_transitive_closure_max /**< Invalid value. */
120 } inh_transitive_closure_state;
122 void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s);
123 void invalidate_irp_inh_transitive_closure_state(void);
124 inh_transitive_closure_state get_irp_inh_transitive_closure_state(void);
127 /** Compute transitive closure of the subclass/superclass and
128 * overwrites/overwrittenby relation.
130 * This function walks over the ir (O(#types+#entities)) to compute the
131 * transitive closure. */
132 void compute_inh_transitive_closure(void);
134 /** Free memory occupied by the transitive closure information. */
135 void free_inh_transitive_closure(void);
138 /* - subtype ------------------------------------------------------------- */
140 /** Iterate over all transitive subtypes. */
141 type *get_class_trans_subtype_first(type *tp);
142 type *get_class_trans_subtype_next (type *tp);
144 /* - supertype ----------------------------------------------------------- */
146 /** Iterate over all transitive supertypes. */
147 type *get_class_trans_supertype_first(type *tp);
148 type *get_class_trans_supertype_next (type *tp);
150 /* - overwrittenby ------------------------------------------------------- */
152 /** Iterate over all entities that transitive overwrite this entities. */
153 entity *get_entity_trans_overwrittenby_first(entity *ent);
154 entity *get_entity_trans_overwrittenby_next (entity *ent);
156 /* - overwrites ---------------------------------------------------------- */
158 /** Iterate over all transitive overwritten entities. */
159 entity *get_entity_trans_overwrites_first(entity *ent);
160 entity *get_entity_trans_overwrites_next (entity *ent);
162 #endif /* _TR_INHERITANCE_H_ */