changed __functions into more comfrom _functions
[libfirm] / ir / tr / tr_inheritance.h
1 /**
2  *
3  * @file tp_inheritance.h
4  *
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>
9  * Modified by:                                                           <br>
10  * Created:                                                               <br>
11  * Copyright:   (c) 2001-2005 Universität Karlsruhe                       <br>
12  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE. <br>
13  * CVS-ID:      $Id$
14  *
15  * This file supplies a set of utility routines for the inheritance
16  * representation.
17  *
18  * Inheritance is represented in Firm by two relations: sub/supertype
19  * between class types, overwrites/ovwerwrittenby between entities.
20  *
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.
25  *
26  *  @see  type.h entity.h
27  */
28
29 #ifndef _TR_INHERITANCE_H_
30 #define _TR_INHERITANCE_H_
31
32 #include "type.h"
33 /* #include "entity.h" */
34 #include "ident.h"
35
36 /* ----------------------------------------------------------------------- */
37 /* Classify pairs of types/entities in the inheritance relations.          */
38 /* ----------------------------------------------------------------------- */
39
40 /** Returns true if low is subclass of high.
41  *
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);
47
48 /** Returns true if high is (transitive) overwritten by low.
49  *
50  *  Returns false if high == low. */
51 int is_overwritten_by(entity *high, entity *low);
52
53 /** Resolve polymorphy in the inheritance relation.
54  *
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);
59
60 /* ----------------------------------------------------------------------- */
61 /* Resolve implicit inheritance.                                           */
62 /* ----------------------------------------------------------------------- */
63
64 /** Default name mangling for inherited entities.
65  *
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);
69
70 /** Type of argument functions for inheritance resolver.
71  *
72  * @param super   The entity in the super type that will be overwritten
73  *                by the newly generated entity, for which this name is
74  *                used.
75  * @param clss    The class type in which the new entity will be placed.
76  */
77 typedef ident *mangle_inherited_name_func(entity *super, type *clss);
78
79 /** Resolve implicit inheritance.
80  *
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.
88  *
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
91  *  used.
92  *
93  *  This function was moved here from firmlower 3/2005.
94  */
95 void resolve_inheritance(mangle_inherited_name_func *mfunc);
96
97
98 /* ----------------------------------------------------------------------- */
99 /* The transitive closure of the subclass/superclass and                   */
100 /* overwrites/overwrittenby relation.                                      */
101 /*                                                                         */
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.                                         */
106 /*                                                                         */
107 /* The transitive edges are held in a set, not in an array as the          */
108 /* underlying relation.                                                    */
109 /* ----------------------------------------------------------------------- */
110
111 /** The state of the transitive closure.
112  *
113  *  @TODO: we could manage the state for each relation separately.  Invalidating
114  *  the entity relations does not mean invalidating the class relation. */
115 typedef enum {
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;
121
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);
125
126
127 /** Compute transitive closure of the subclass/superclass and
128 * overwrites/overwrittenby relation.
129 *
130 * This function walks over the ir (O(#types+#entities)) to compute the
131 * transitive closure.    */
132 void compute_inh_transitive_closure(void);
133
134 /** Free memory occupied by the transitive closure information. */
135 void free_inh_transitive_closure(void);
136
137
138 /* - subtype ------------------------------------------------------------- */
139
140 /** Iterate over all transitive subtypes. */
141 type *get_class_trans_subtype_first(type *tp);
142 type *get_class_trans_subtype_next (type *tp);
143
144 /* - supertype ----------------------------------------------------------- */
145
146 /** Iterate over all transitive supertypes. */
147 type *get_class_trans_supertype_first(type *tp);
148 type *get_class_trans_supertype_next (type *tp);
149
150 /* - overwrittenby ------------------------------------------------------- */
151
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);
155
156 /* - overwrites ---------------------------------------------------------- */
157
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);
161
162 #endif  /* _TR_INHERITANCE_H_ */