From: Götz Lindenmaier Date: Wed, 23 Feb 2005 17:01:03 +0000 (+0000) Subject: cast access routines X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=612d040e0d231331a4a01a74a6742baf4b46c85c;p=libfirm cast access routines [r5218] --- diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index 114245fe1..98fbcea75 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -1357,6 +1357,52 @@ set_Cast_type (ir_node *node, type *to_tp) { node->attr.cast.totype = to_tp; } + +/* Checks for upcast. + * + * Returns true if the Cast node casts a class type to a super type. + */ +int is_Cast_upcast(ir_node *node) { + type *totype = get_Cast_type(node); + type *fromtype = get_irn_typeinfo_type(get_Cast_op(node)); + ir_graph *myirg = get_irn_irg(node); + + assert(get_irg_typeinfo_state(myirg) == ir_typeinfo_consistent); + assert(fromtype); + + while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) { + totype = get_pointer_points_to_type(totype); + fromtype = get_pointer_points_to_type(fromtype); + } + + assert(fromtype); + + if (!is_Class_type(totype)) return false; + return is_subclass_of(fromtype, totype); +} + +/* Checks for downcast. + * + * Returns true if the Cast node casts a class type to a sub type. + */ +int is_Cast_downcast(ir_node *node) { + type *totype = get_Cast_type(node); + type *fromtype = get_irn_typeinfo_type(get_Cast_op(node)); + + assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent); + assert(fromtype); + + while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) { + totype = get_pointer_points_to_type(totype); + fromtype = get_pointer_points_to_type(fromtype); + } + + assert(fromtype); + + if (!is_Class_type(totype)) return false; + return is_subclass_of(totype, fromtype); +} + int (is_unop)(const ir_node *node) { return _is_unop(node); diff --git a/ir/ir/irnode.h b/ir/ir/irnode.h index 282c1f877..e7fcdf6aa 100644 --- a/ir/ir/irnode.h +++ b/ir/ir/irnode.h @@ -246,6 +246,9 @@ ir_node *get_Block_cfgpred (ir_node *node, int pos); void set_Block_cfgpred (ir_node *node, int pos, ir_node *pred); bool get_Block_matured (ir_node *node); void set_Block_matured (ir_node *node, bool matured); + +/** A visited flag only for block nodes. + * @see also: get_irn_visited() inc_irg_visited() inc_irg_block_visited()*/ unsigned long get_Block_block_visited (ir_node *node); void set_Block_block_visited (ir_node *node, unsigned long visit); ir_node *set_Block_dead(ir_node *block); @@ -701,6 +704,21 @@ void set_Cast_op (ir_node *node, ir_node *op); type *get_Cast_type (ir_node *node); void set_Cast_type (ir_node *node, type *to_tp); +/** Checks for upcast. + * + * Returns true if the Cast node casts a class type to a super type. + * Works also for pointers to classes (recursively). + */ +int is_Cast_upcast(ir_node *node); + +/** Checks for downcast. + * + * Returns true if the Cast node casts a class type to a sub type. + * Works also for pointers to classes (recursively). + */ +int is_Cast_downcast(ir_node *node); + + /** Returns true if n is Phi or Filter in interprocedural_view. Returns false if irg in phase building and the Phi has zero predecessors: it's a Phi0. */