+#include "firm_types.h"
+#include "dbginfo.h"
+
+#include "tr_inheritance.h"
+
+/*-----------------------------------------------------------------*/
+/* ENTITY */
+/*-----------------------------------------------------------------*/
+
+/**
+ *
+ * An abstract data type to represent program entities.
+ *
+ * @param owner A compound type this entity is a part of.
+ * @param type The type of this entity.
+ * @param name The string that represents this entity in the source program.
+ * @param allocation A flag saying whether the entity is dynamically or statically
+ * allocated (values: dynamic_allocated, static_allocated,
+ * automatic_allocated).
+ * @param visibility A flag indicating the visibility of this entity (values: local,
+ * external_visible, external_allocated)
+ * @param variability A flag indicating the variability of this entity (values:
+ * uninitialized, initialized, part_constant, constant)
+ * @param volatility @@@
+ * @param offset The offset of the entity within the compound object in bits. Only set
+ * if the owner in the state "layout_fixed".
+ * @param overwrites A list of entities overwritten by this entity. This list is only
+ * existent if the owner of this entity is a class. The members in
+ * this list must be entities of super classes.
+ * @param overwrittenby A list of entities that overwrite this entity. This list is only
+ * existent if the owner of this entity is a class. The members in
+ * this list must be entities of sub classes.
+ * @param link A void* to associate some additional information with the entity.
+ * @param irg If the entity is a method this is the ir graph that represents the
+ * code of the method.
+ * @param peculiarity The peculiarity of the entity. If the entity is a method this
+ * indicates whether the entity represents
+ * a real method or whether it only exists to describe an interface.
+ * In that case there nowhere exists code for this entity and this entity
+ * is never dynamically used in the code.
+ * Values: description, existent. Default: existent.
+ * @param visited visited flag. Master flag is type_visited.
+ *
+ * @param These fields can only be accessed via access functions.
+ *
+ * @see type
+ */
+
+/* to resolve recursion between entity.h and type.h */
+/** the type of an entity */
+#ifndef _ENTITY_TYPEDEF_
+#define _ENTITY_TYPEDEF_
+typedef struct entity entity;
+#endif
+
+/**
+ * Creates a new entity.
+ *
+ * Automatically inserts the entity as a member of owner.
+ * Entity is automatic_allocated and uninitialized except if the type
+ * is type_method, then it is static_allocated and constant. The constant
+ * value is a pointer to the method.
+ * Visibility is local, offset -1, and it is not volatile.
+ */
+entity *new_entity (ir_type *owner, ident *name, ir_type *tp);
+
+/**
+ * Creates a new entity.
+ *
+ * Automatically inserts the entity as a member of owner.
+ * The entity is automatic allocated and uninitialized except if the type
+ * is type_method, then it is static allocated and constant. The constant
+ * value is a pointer to the method.
+ * Visibility is local, offset -1, and it is not volatile.
+ */
+entity *new_d_entity (ir_type *owner, ident *name, ir_type *tp, dbg_info *db);
+
+/**
+ * Copies the entity if the new_owner is different from the
+ * owner of the old entity, else returns the old entity.
+ *
+ * Automatically inserts the new entity as a member of owner.
+ * Resets the overwrites/overwritten_by fields.
+ * Keeps the old atomic value.
+ * @@@ Maybe we should change this. If peculiarity of a method
+ * is existent, we should add a new SymConst that points to
+ * itself and not to the origin. Right now we have to change
+ * the peculiarity and then set a new atomic value by hand.
+ */
+entity *copy_entity_own (entity *old, ir_type *new_owner);
+
+/**
+ * Copies the entity if the new_name is different from the
+ * name of the old entity, else returns the old entity.
+ *
+ * Automatically inserts the new entity as a member of owner.
+ * The mangled name ld_name is set to NULL.
+ * Overwrites relation is copied from old.
+ */
+entity *copy_entity_name (entity *old, ident *new_name);
+
+/**
+ * Frees the entity.
+ *
+ * The owner will still contain the pointer to this
+ * entity, as well as all other references!
+ */
+void free_entity (entity *ent);
+
+/** Returns the name of an entity. */
+const char *get_entity_name (const entity *ent);
+
+/** Returns the ident of an entity. */
+ident *get_entity_ident (const entity *ent);
+
+/** Returns the mangled name of the entity.
+ *
+ * If the mangled name is set it returns the existing name.
+ * Else it generates a name with mangle_entity()
+ * and remembers this new name internally.
+ */
+ident *get_entity_ld_ident (entity *ent);
+
+/** Sets the mangled name of the entity. */
+void set_entity_ld_ident (entity *ent, ident *ld_ident);
+
+/** Returns the mangled name of the entity as a string. */
+const char *get_entity_ld_name (entity *ent);
+
+/** Returns the owner of the entity. */
+ir_type *get_entity_owner (entity *ent);
+
+/** Sets the owner field in entity to owner. Don't forget to add
+ ent to owner!! */
+void set_entity_owner (entity *ent, ir_type *owner);
+
+/** Asserts if the type owner is either a compound type or an array */
+void assert_legal_owner_of_ent(ir_type *owner);
+
+/** Returns the type of an entity. */
+ir_type *get_entity_type (entity *ent);
+
+/** Sets the type of an entity. */
+void set_entity_type (entity *ent, ir_type *tp);
+
+/** The allocation type. */
+typedef enum {
+ allocation_automatic, /**< The entity is allocated during runtime, implicitly
+ as component of a compound type. This is the default. */
+ allocation_parameter, /**< The entity is a parameter. It is also automatic allocated.
+ We distinguish the allocation of parameters from the allocation
+ of local variables as their placement depends on the calling
+ conventions. */
+ allocation_dynamic, /**< The entity is allocated during runtime, explicitly
+ by an Alloc node. */
+ allocation_static /**< The entity is allocated statically. We can use a
+ Const as address of the entity. */
+} ent_allocation;
+
+/** Returns the allocation type of an entity. */
+ent_allocation get_entity_allocation (const entity *ent);
+
+/** Sets the allocation type of an entity. */
+void set_entity_allocation (entity *ent, ent_allocation al);
+
+/** Return the name of the allocation type. */
+const char *get_allocation_name(ent_allocation vis);
+
+/** Returns the visibility of an entity. */
+visibility get_entity_visibility (const entity *ent);
+
+/** Sets the visibility of an entity. */
+void set_entity_visibility (entity *ent, visibility vis);
+
+/** Return the name of the visibility */
+const char *get_visibility_name(visibility vis);
+
+/** This enumeration flags the variability of entities. */
+typedef enum {
+ variability_uninitialized, /**< The content of the entity is completely unknown. Default. */
+ variability_initialized, /**< After allocation the entity is initialized with the
+ value given somewhere in the entity. */
+ variability_part_constant, /**< For entities of compound types.
+ The members of the entity are mixed constant,
+ initialized or uninitialized. */
+ variability_constant /**< The entity is constant. */
+} ent_variability;
+
+/** Returns the variability of an entity. */
+ent_variability get_entity_variability (const entity *ent);
+
+/** Sets the variability of an entity. */
+void set_entity_variability (entity *ent, ent_variability var);
+
+/** Return the name of the variability. */
+const char *get_variability_name(ent_variability var);
+
+/** This enumeration flags the volatility of entities. */
+typedef enum {
+ volatility_non_volatile, /**< The entity is not volatile. Default. */
+ volatility_is_volatile /**< The entity is volatile */
+} ent_volatility;
+
+/** Returns the volatility of an entity. */
+ent_volatility get_entity_volatility (const entity *ent);
+
+/** Sets the volatility of an entity. */
+void set_entity_volatility (entity *ent, ent_volatility vol);
+
+/** Return the name of the volatility. */
+const char *get_volatility_name(ent_volatility var);
+
+/** This enumeration flags the stickyness of an entity. */
+typedef enum {
+ stickyness_unsticky, /**< The entity can be removed from
+ the program, unless contraindicated
+ by other attributes. Default. */
+ stickyness_sticky /**< The entity must remain in the
+ program in any case. */
+} ent_stickyness;
+
+/** Get the entity's stickyness */
+ent_stickyness get_entity_stickyness(const entity *ent);
+
+/** Set the entity's stickyness */
+void set_entity_stickyness(entity *ent, ent_stickyness stickyness);
+
+/** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */
+int get_entity_offset_bytes(const entity *ent);
+
+/** Returns the offset of an entity (in a compound) in bits. Only set if layout = fixed. */
+int get_entity_offset_bits(const entity *ent);
+
+/** Sets the offset of an entity (in a compound) in bytes. */
+void set_entity_offset_bytes(entity *ent, int offset);