From: Michael Beck Date: Thu, 2 Feb 2006 16:48:45 +0000 (+0000) Subject: added type info and final flag to class types X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=134ecab995321db5c61c0fbf71c9b6916f911a9b;p=libfirm added type info and final flag to class types [r7310] --- diff --git a/ir/tr/type.c b/ir/tr/type.c index 95a57023e..26ddf7cf3 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -765,6 +765,8 @@ ir_type *new_d_type_class (ident *name, dbg_info *db) { res->attr.ca.subtypes = NEW_ARR_F (ir_type *, 0); res->attr.ca.supertypes = NEW_ARR_F (ir_type *, 0); res->attr.ca.peculiarity = peculiarity_existent; + res->attr.ca.type_info = NULL; + res->attr.ca.final = 0; res->attr.ca.dfn = 0; hook_new_type(res); return res; @@ -774,11 +776,13 @@ ir_type *new_type_class (ident *name) { return new_d_type_class (name, NULL); } +/* free all entities of a class */ void free_class_entities(ir_type *clss) { int i; assert(clss && (clss->type_op == type_class)); for (i = get_class_n_members(clss) - 1; i >= 0; --i) free_entity(get_class_member(clss, i)); + /* do NOT free the type info here. It belongs to another class */ } void free_class_attrs(ir_type *clss) { @@ -939,6 +943,12 @@ void remove_class_supertype(ir_type *clss, ir_type *supertype) { break; } } +entity *get_class_type_info(const ir_type *clss) { + return clss->attr.ca.type_info; +} +void set_class_type_info(ir_type *clss, entity *ent) { + clss->attr.ca.type_info = ent; +} const char *get_peculiarity_string(peculiarity p) { #define X(a) case a: return #a @@ -962,13 +972,19 @@ void set_class_peculiarity (ir_type *clss, peculiarity pec) { clss->attr.ca.peculiarity = pec; } -void set_class_dfn (ir_type *clss, int dfn) -{ - clss->attr.ca.dfn = dfn; +int (is_class_final)(const ir_type *clss) { + return _is_class_final(clss); } -int get_class_dfn (const ir_type *clss) -{ +void (set_class_final)(ir_type *clss, int final) { + _set_class_final(clss, final); +} + +void set_class_dfn (ir_type *clss, int dfn) { + clss->attr.ca.dfn = dfn; +} + +int get_class_dfn (const ir_type *clss) { return (clss->attr.ca.dfn); } diff --git a/ir/tr/type.h b/ir/tr/type.h index 7abf38cf5..0fbab2c96 100644 --- a/ir/tr/type.h +++ b/ir/tr/type.h @@ -419,9 +419,9 @@ int smaller_type (ir_type *st, ir_type *lt); * The following two are dynamic lists that can be grown with an "add_" function, * but not shrinked: * - * - subtypes: A list of direct subclasses. + * - subtypes: A list of direct subclasses. * - * - supertypes: A list of direct superclasses. + * - supertypes: A list of direct superclasses. * * - peculiarity: The peculiarity of this class. If the class is of peculiarity * "description" it only is a description of requirements to a class, @@ -432,6 +432,17 @@ int smaller_type (ir_type *st, ir_type *lt); * no value for irg. * Values: description, existent, inherited. Default: existent. * + * - type_info: An entity representing the type information of this class. + * This entity can be of arbitrari type, Firm did not use it yet. + * It allows to express the coupling of a type with an entity + * representing this type. This information is useful for lowering + * of InstOf and TypeChk nodes. Default: NULL + * + * - final: A final class is always a leaf in the class hierarchy. Final + * classes cannot be super classes of other ones. As this information + * can only be computed in whole world compilations, we allow to + * set this flag. It is used in optimizations if get_opt_closed_world() + * is false. Default: false */ /** Creates a new class type. */ @@ -577,6 +588,18 @@ peculiarity get_class_peculiarity (const ir_type *clss); /** Sets the peculiarity of the class. */ void set_class_peculiarity (ir_type *clss, peculiarity pec); +/** Returns the type info entity of a class. */ +entity *get_class_type_info(const ir_type *clss); + +/** Set a type info entity for the class. */ +void set_class_type_info(ir_type *clss, entity *ent); + +/** Returns non-zero if a class is final. */ +int is_class_final(const ir_type *clss); + +/** Sets if a class is final. */ +void set_class_final(ir_type *clss, int final); + /* Set and get a class' dfn -- @todo This is an undocumented field, subject to change! */ void set_class_dfn (ir_type *clss, int dfn); diff --git a/ir/tr/type_t.h b/ir/tr/type_t.h index e8e9255ce..71358b620 100644 --- a/ir/tr/type_t.h +++ b/ir/tr/type_t.h @@ -3,7 +3,7 @@ * File name: ir/tr/type_t.h * Purpose: Representation of types -- private header. * Author: Goetz Lindenmaier - * Modified by: + * Modified by: Michael Beck * Created: * CVS-ID: $Id$ * Copyright: (c) 2001-2003 Universität Karlsruhe @@ -33,7 +33,9 @@ typedef struct { entity **members; /**< fields and methods of this class */ ir_type **subtypes; /**< direct subtypes */ ir_type **supertypes;/**< direct supertypes */ - peculiarity peculiarity; + peculiarity peculiarity; /**< peculiarity of this class */ + entity *type_info; /**< a entity representing this class, used for type info */ + unsigned final; /**< non-zero if this is a final class */ int dfn; /**< number used for 'instanceof' operator */ } cls_attr; @@ -335,6 +337,18 @@ _get_class_member (const ir_type *clss, int pos) { return clss->attr.ca.members[pos]; } +static INLINE int +_is_class_final (const ir_type *clss) { + assert(clss && (clss->type_op == type_class)); + return clss->attr.ca.final; +} + +static INLINE void +_set_class_final (ir_type *clss, int final) { + assert(clss && (clss->type_op == type_class)); + clss->attr.ca.final = final; +} + static INLINE int _is_struct_type(const ir_type *strct) { assert(strct); @@ -456,6 +470,8 @@ _set_method_calling_convention(ir_type *method, unsigned cc_mask) { #define is_Class_type(clss) _is_class_type(clss) #define get_class_n_members(clss) _get_class_n_members(clss) #define get_class_member(clss, pos) _get_class_member(clss, pos) +#define is_class_final(clss) _is_class_final(clss) +#define set_class_final(clss, final) _set_class_final(clss, final) #define is_Struct_type(strct) _is_struct_type(strct) #define is_Method_type(method) _is_method_type(method) #define is_Union_type(uni) _is_union_type(uni)