removed a bug
[libfirm] / ir / tr / entity.h
1 /*
2 **  Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
3 **  All rights reserved.
4 **
5 **  Authors: Martin Trapp, Christian Schaefer,
6 **           Goetz Lindenmaier
7 **
8 **  entity.h:  entities represent all program known objects.
9 **
10 **  An entity is the representation of program known objects in Firm.
11 **  The primary concept of entities is to represent members of complex
12 **  types, i.e., fields and methods of classes.  As not all programming
13 **  language model all variables and methods as members of some class,
14 **  the concept of entities is extended to cover also local and global
15 **  variables, and arbitrary procedures.
16 **
17 **  An entity always specifies the type of the object it represents and
18 **  the type of the object it is a part of, the owner of the entity.
19 **  Originally this is the type of the class of which the entity is a
20 **  member.
21 **  The owner of local variables is the procedure they are defined in.
22 **  The owner of global variables and procedures visible in the whole
23 **  program is a universally defined class type "GlobalType".  The owner
24 **  of procedures defined in the scope of an other procedure is the
25 **  enclosing procedure.
26 **
27 **  In detail the datastructure entity has the following fields:
28 **
29 **  ident *name     Name of this entity as specified in the source code.
30 **                  Only unequivocal in conjuction with scope.
31 **  ident *ld_name  Unique name of this entity, i.e., the mangled
32 **                  name.  E.g., for a class `A' with field `a' this
33 **                  is the ident for `A_a'.
34 **  type *type      The type of this entity, e.g., a method type, a
35 **                  basic type of the language or a class itself.
36 **  type *owner;    The class this entity belongs to.  In case of local
37 **                  variables the method they are defined in.
38 **  int offset;     Offset in byte for this entity.  Fixed when layout
39 **                  of owner is determined.
40 **  ir_graph *irg;  If (type == method_type) this is the corresponding irg.
41 **                  The ir_graph constructor automatically sets this field.
42 **                  If (type !- method_type) access of this field will cause
43 **                  an assertion.
44 */
45
46 # ifndef _ENTITY_H_
47 # define _ENTITY_H_
48
49 # include "ident.h"
50 # include "type.h"
51
52 /*******************************************************************/
53 /** general                                                       **/
54 /*******************************************************************/
55
56 /* initalize entity module */
57 void init_entity (void);
58
59 /*******************************************************************/
60 /** ENTITY                                                        **/
61 /*******************************************************************/
62
63 #ifndef _IR_GRAPH_TYPEDEF_
64 #define _IR_GRAPH_TYPEDEF_
65 /* to resolve recursion between entity.h and irgraph.h */
66 typedef struct ir_graph ir_graph;
67 #endif
68
69 /****s* entity/entity
70  *
71  * NAME
72  *   entity - An abstract data type to represent program entites.
73  * NOTE
74  *
75  * ATTRIBUTES
76  *   owner      A compound type this entity is a part of.
77  *   type       The type of this entity.
78  *   name       The string that represents this entity in the source program.
79  *   allocation A flag saying whether the entity is dynamically or statically
80  *              allocated (values: dynamic_allocated,  static_allocated).
81  *              @@@ Does this make sense???
82  *   visibility A flag indicating the visibility of this entity (values: local,
83  *              external_visible,  external_allocated)
84  *   offset     The offset of the entity within the compound object.  Only set
85  *              if IR in the state "@@@"  Wie nennen wir den??
86  *   overwrites A list of entities overwritten by this entity.  This list is only
87  *              existent if the owner of this entity is a class.  The members in
88  *              this list must be entities of super classes.
89  *   irg        If the entity is a method this is the ir graph that represents the
90  *              code of the method.
91  *
92  *
93  *  These fields can only be accessed via access functions.
94  *
95  * SEE ALSO
96  *   type
97  * SOURCE
98  */
99
100 #ifndef _ENTITY_TYPEDEF_
101 #define _ENTITY_TYPEDEF_
102 /* to resolve recursion between entity.h and type.h */
103 typedef struct entity entity;
104 #endif
105
106 /* Creates a new entity.
107    Automatically inserts the entity as a member of owner. */
108 entity     *new_entity (type *owner, ident *name, type *type);
109 /* Copies the entity if the new_owner is different from the
110    owner of the old entity.  Else returns the old entity.
111    Automatically inserts the new entity as a member of owner. */
112 entity     *copy_entity_own (entity *old, type *new_owner);
113 /* Copies the entity if the new_name is different from the
114    name of the old entity.  Else returns the old entity.
115    Automatically inserts the new entity as a member of owner.
116    The mangled name ld_name is set to NULL. */
117 entity     *copy_entity_name (entity *old, ident *new_name);
118
119 /** manipulate fields of entity **/
120 const char *get_entity_name     (entity *ent);
121 ident      *get_entity_ident    (entity *ent);
122 /* returns the mangled name of the entity.  If the mangled name is
123    set it returns the existing name.  Else it generates a name
124    with mangle_entity() and remembers this new name internally. */
125 ident      *get_entity_ld_ident (entity *ent);
126 void        set_entity_ld_ident (entity *ent, ident *ld_ident);
127
128 /*
129 char       *get_entity_ld_name  (entity *ent);
130 void        set_entity_ld_name  (entity *ent, char *ld_name);
131 */
132
133 type       *get_entity_owner (entity *ent);
134 /* Sets the owner field in entity to owner. */
135 void        set_entity_owner (entity *ent, type *owner);
136 inline void assert_legal_owner_of_ent(type *owner);
137
138 type     *get_entity_type (entity *ent);
139 void      set_entity_type (entity *ent, type *type);
140
141 typedef enum {
142   dynamic_allocated,  /* The entity is allocated during runtime, either explicitly
143                          by an Alloc node or implicitly as component of a compound
144                          type.  This is the default. */
145   static_allocated    /* The entity is allocated statically.  We can use a
146                           SymConst as address of the entity. */
147 } ent_allocation;
148
149 ent_allocation get_entity_allocation (entity *ent);
150 void           set_entity_allocation (entity *ent, ent_allocation al);
151
152 /* This enumeration flags the visibility of entities.  This is necessary
153    for partial compilation. */
154 typedef enum {
155   local,              /* The entity is only visible locally.  This is the default. */
156   external_visible,   /* The entity is visible to other external program parts, but
157                          it is defined here.  It may not be optimized away.  The entity must
158                          be static_allocated. */
159   external_allocated  /* The entity is defined and allocated externaly.  This compilation
160                          must not allocate memory for this entity. The entity must
161                          be static_allocated. */
162 } ent_visibility;
163
164 ent_visibility get_entity_visibility (entity *ent);
165 void           set_entity_visibility (entity *ent, ent_visibility vis);
166
167 int       get_entity_offset (entity *ent);
168 void      set_entity_offset (entity *ent, int offset);
169
170 /* Overwrites is a field that specifies that an access to the overwritten
171    entity in the supertype must use this entity.  It's a list as with
172    multiple inheritance several enitites can be overwritten.  This field
173    is mostly useful for method entities.
174    If a Sel node selects an entity that is overwritten by other entities it
175    must return a pointer to the entity of the dynamic type of the pointer
176    that is passed to it.  Lowering of the Sel node must assure this. */
177 void    add_entity_overwrites   (entity *ent, entity *overwritten);
178 int     get_entity_n_overwrites (entity *ent);
179 entity *get_entity_overwrites   (entity *ent, int pos);
180 void    set_entity_overwrites   (entity *ent, int pos, entity *overwritten);
181 /* Do we need a second relation "overwritten"? */
182
183 /* The entity knows the corresponding irg if the entity is a method.
184    This allows to get from a Call to the called irg. */
185 ir_graph *get_entity_irg(entity *ent);
186 void      set_entity_irg(entity *ent, ir_graph *irg);
187
188
189
190 /*****/
191
192 # endif /* _ENTITY_H_ */