X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Ftr_inheritance.h;h=ad127d56f72f49581a1a0dea64270dc3a64b09f2;hb=5af2b48e41c335416a1cf4dce49086868c3f6dec;hp=c4e47110c00bbbc25bbc947dbead65ce37692452;hpb=e18eba3e4511208f4eaccc1501ead35ba8c555b8;p=libfirm diff --git a/ir/tr/tr_inheritance.h b/ir/tr/tr_inheritance.h index c4e47110c..ad127d56f 100644 --- a/ir/tr/tr_inheritance.h +++ b/ir/tr/tr_inheritance.h @@ -1,6 +1,5 @@ /** - * - * @file tp_inheritance.h + * @file tr_inheritance.h * * Project: libFIRM
* File name: ir/tr/tp_inheritance.h
@@ -29,8 +28,8 @@ #ifndef _TR_INHERITANCE_H_ #define _TR_INHERITANCE_H_ +#include "firm_types.h" #include "type.h" -/* #include "entity.h" */ #include "ident.h" /* ----------------------------------------------------------------------- */ @@ -43,19 +42,43 @@ * a subclass of high. I.e, we search in all subtypes of high for low. * @@@ this can be implemented more efficient if we know the set of all * subclasses of high. */ -int is_subclass_of(type *low, type *high); +int is_SubClass_of(ir_type *low, ir_type *high); + +/** Subclass check for pointers to classes. + * + * Dereferences at both types the same amount of pointer types (as + * many as possible). If the remaining types are both class types + * and subclasses, returns true, else false. Can also be called with + * two class types. */ +int is_SubClass_ptr_of(ir_type *low, ir_type *high); -/** Returns true if high is (transitiv) overwritten by low. +/** Returns true if high is superclass of low. + * + * Low is a subclass of high if low == high or if low is a subclass of + * a subclass of high. I.e, we search in all subtypes of high for low. + * @@@ this can be implemented more efficient if we know the set of all + * subclasses of high. */ +#define is_SuperClass_of(high, low) is_SubClass_of(low, high) + +/** Superclass check for pointers to classes. + * + * Dereferences at both types the same amount of pointer types (as + * many as possible). If the remaining types are both class types + * and superclasses, returns true, else false. Can also be called with + * two class types. */ +#define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low) + +/** Returns true if high is (transitive) overwritten by low. * * Returns false if high == low. */ int is_overwritten_by(entity *high, entity *low); -/** Resolve polymorphy in the inheritance relation. +/** Resolve polymorphism in the inheritance relation. * - * Returns the dynamically referenced entity if the static entity and the - * dynamic type are given. - * Searches downwards in overwritten tree. */ -entity *resolve_ent_polymorphy(type *dynamic_class, entity* static_ent); + * Returns the dynamically referenced entity if the static entity and the + * dynamic type are given. + * Searches downwards in overwritten tree. */ +entity *resolve_ent_polymorphy(ir_type *dynamic_class, entity* static_ent); /* ----------------------------------------------------------------------- */ /* Resolve implicit inheritance. */ @@ -65,7 +88,7 @@ entity *resolve_ent_polymorphy(type *dynamic_class, entity* static_ent); * * Returns an ident that consists of the name of type followed by an * underscore and the name (not ld_name) of the entity. */ -ident *default_mangle_inherited_name(entity *super, type *clss); +ident *default_mangle_inherited_name(entity *super, ir_type *clss); /** Type of argument functions for inheritance resolver. * @@ -74,7 +97,7 @@ ident *default_mangle_inherited_name(entity *super, type *clss); * used. * @param clss The class type in which the new entity will be placed. */ -typedef ident *mangle_inherited_name_func(entity *super, type *clss); +typedef ident *mangle_inherited_name_func(entity *super, ir_type *clss); /** Resolve implicit inheritance. * @@ -84,7 +107,7 @@ typedef ident *mangle_inherited_name_func(entity *super, type *clss); * function generates entities that explicitly represent this * inheritance. It generates for each entity overwriting entities in * all subclasses of the owner of the entity, if the entity is not - * overwritten in that sublclass. + * overwritten in that subclass. * * The name of the new entity is generated with the function passed. * If the function is NULL, the default_mangle_inherited_name() is @@ -106,11 +129,13 @@ void resolve_inheritance(mangle_inherited_name_func *mfunc); /* */ /* The transitive edges are held in a set, not in an array as the */ /* underlying relation. */ +/* */ +/* Do the sets contain the node itself? I assume NOT! */ /* ----------------------------------------------------------------------- */ /** The state of the transitive closure. * - * @TODO: we could manage the state for each relation separately. Invalidating + * @todo: we could manage the state for each relation separately. Invalidating * the entity relations does not mean invalidating the class relation. */ typedef enum { inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */ @@ -119,8 +144,8 @@ typedef enum { inh_transitive_closure_max /**< Invalid value. */ } inh_transitive_closure_state; -void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s); -void invalidate_irp_inh_transitive_closure_state(void); +void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s); +void invalidate_irp_inh_transitive_closure_state(void); inh_transitive_closure_state get_irp_inh_transitive_closure_state(void); @@ -138,14 +163,15 @@ void free_inh_transitive_closure(void); /* - subtype ------------------------------------------------------------- */ /** Iterate over all transitive subtypes. */ -type *get_class_trans_subtype_first(type *tp); -type *get_class_trans_subtype_next (type *tp); +ir_type *get_class_trans_subtype_first(ir_type *tp); +ir_type *get_class_trans_subtype_next (ir_type *tp); +int is_class_trans_subtype (ir_type *tp, ir_type *subtp); /* - supertype ----------------------------------------------------------- */ /** Iterate over all transitive supertypes. */ -type *get_class_trans_supertype_first(type *tp); -type *get_class_trans_supertype_next (type *tp); +ir_type *get_class_trans_supertype_first(ir_type *tp); +ir_type *get_class_trans_supertype_next (ir_type *tp); /* - overwrittenby ------------------------------------------------------- */ @@ -159,4 +185,54 @@ entity *get_entity_trans_overwrittenby_next (entity *ent); entity *get_entity_trans_overwrites_first(entity *ent); entity *get_entity_trans_overwrites_next (entity *ent); + +/* ----------------------------------------------------------------------- */ +/** The state of Cast operations that cast class types or pointers to class + * types. + * + * The state expresses, how far Cast operations conform with the class + * hierarchy. + * + * class A {} + * class B1 extends A {} + * class B2 extends A {} + * class C extends B1 {} + * normalized: Cast operations conform with the inheritance relation. + * I.e., the type of the operand of a Cast is either a super= or a sub- + * type of the type casted to. Example: (A)((B2) (new C())). + * transitive: Cast operations conform with the transitive inheritance + * relation. Example: (A)(new C()). + * any: Cast operations do not conform with the transitive inheritance + * relation. Example: (B2)(new B1()) + * + * @see: tropt.h + */ +/* ----------------------------------------------------------------------- */ + +/** Flags for class cast state. + * + * The state in irp is always smaller or equal to the state of any + * irg. + * + * We rely on the ordering of the enum. */ +typedef enum { + ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with + the class hierarchy. @@@ So far this does not happen in Firm. */ + ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */ + ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */ + ir_class_casts_state_max +} ir_class_cast_state; +char *get_class_cast_state_string(ir_class_cast_state s); + +void set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s); +ir_class_cast_state get_irg_class_cast_state(ir_graph *irg); +void set_irp_class_cast_state(ir_class_cast_state s); +ir_class_cast_state get_irp_class_cast_state(void); + +/** Verify the class cast state of an irg. + * + * Asserts if state is to high, outputs warning if state is to low + * and firm verbosity is set. + */ +void verify_irg_class_cast_state(ir_graph *irg); #endif /* _TR_INHERITANCE_H_ */