<commit_before>/*
 * Project:     libFIRM
 * File name:   ir/tr/entity_t.h
 * Purpose:     Representation of all program known entities -- private header.
 * Author:      <NAME>, <NAME>
 * Modified by: <NAME>
 * Created:
 * CVS-ID:      $Id$
 * Copyright:   (c) 1998-2003 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */

/**
 * @file entity_t.h
 *
 * entity.h:  entities represent all program known objects.
 *
 * @author <NAME>, <NAME>, <NAME>
 *
 *  An entity is the representation of program known objects in Firm.
 *  The primary concept of entities is to represent members of complex
 *  types, i.e., fields and methods of classes.  As not all programming
 *  language model all variables and methods as members of some class,
 *  the concept of entities is extended to cover also local and global
 *  variables, and arbitrary procedures.
 *
 *  An entity always specifies the type of the object it represents and
 *  the type of the object it is a part of, the owner of the entity.
 *  Originally this is the type of the class of which the entity is a
 *  member.
 *  The owner of local variables is the procedure they are defined in.
 *  The owner of global variables and procedures visible in the whole
 *  program is a universally defined class type "GlobalType".  The owner
 *  of procedures defined in the scope of an other procedure is the
 *  enclosing procedure.
 */

#ifndef _FIRM_TR_ENTITY_T_H_
#define _FIRM_TR_ENTITY_T_H_

#include "firm_common_t.h"
#include "firm_config.h"

#include "type_t.h"
#include "entity.h"
#include "typegmod.h"
#include "mangle.h"
#include "pseudo_irg.h"

/** A path in a compound graph. */
struct compound_graph_path {
  firm_kind kind;       /**< dynamic type tag for compound graph path. */
  ir_type *tp;          /**< The type this path belongs to. */
  int len;              /**< length of the path */
  struct tuple {
    int    index;       /**< Array index.  To compute position of array elements */
    entity *node;       /**< entity */
  } list[1];            /**< List of entity/index tuple of length len to express the
                             access path. */
};

/** attributes for atomic entities */
typedef struct atomic_ent_attr {
  ir_node *value;            /**< value if entity is not of variability uninitialized.
                               Only for atomic entities. */
} atomic_ent_attr;

/** attributes for compound entities */
typedef struct compound_ent_attr {
  ir_node **values;     /**< constant values of compound entities. Only available if
                             variability not uninitialized.  Must be set for variability constant. */
  compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if
                                        variability not uninitialized.  Must be set for variability constant. */
} compound_ent_attr;

/** a reserved value for "not yet set" */
#define VTABLE_NUM_NOT_SET ((unsigned)(-1))

/** attributes for methods */
typedef struct method_ent_attr {
  ir_graph *irg;        /**< The corresponding irg if known.
                             The ir_graph constructor automatically sets this field. */
  unsigned irg_add_properties;   /**< Additional graph properties can be
                                      stored in a entity if no irg is available. */

  unsigned vtable_number;        /**< For a dynamically called method, the number assigned
                                      in the virtual function table. */

  ptr_access_kind *param_access; /**< the parameter access */
  float *param_weight; /**< The weight of method's parameters. Parameters
                          with a high weight are good for procedure cloning. */
} method_ent_attr;


/** the type of an entity */
struct entity {
  firm_kind kind;       /**< The dynamic type tag for entity. */
  ident *name;          /**< The name of this entity. */
  ident *ld_name;       /**< Unique name of this entity, i.e., the mangled
                             name.  If the field is read before written a default
                             mangling is applies.  The name of the owner is prepended
                             to the name of the entity, separated by a underscore.
                             E.g.,  for a class `A' with field `a' this
                             is the ident for `A_a'. */
  ir_type *type;        /**< The type of this entity, e.g., a method type, a
                             basic type of the language or a class itself. */
  ir_type *owner;              /**< The compound type (e.g. class type) this entity belongs to. */
  ent_allocation allocation;   /**< Distinguishes static and dynamically allocated
                                    entities and some further cases. */
  visibility visibility;       /**< Specifies visibility to external program
                                    fragments. */
  ent_variability variability; /**< Specifies variability of entities content. */
  ent_volatility volatility;   /**< Specifies volatility of entities content. */
  ent_stickyness stickyness;   /**< Specifies whether this entity is sticky.  */
  int  offset;                 /**< Offset in bits for this entity.  Fixed when layout
                                    of owner is determined. */
  peculiarity peculiarity;     /**< The peculiarity of this entity. */
  unsigned long visit;         /**< visited counter for walks of the type information. */
  struct dbg_info *dbi;        /**< A pointer to information for debug support. */
  void *link;                  /**< To store some intermediate information. */

  /* ------------- fields for entities owned by a class type ---------------*/

  entity **overwrites;     /**< A list of entities this entity overwrites. */
  entity **overwrittenby;  /**< A list of entities that overwrite this entity.  */

  /* ------------- fields for atomic entities  --------------- */
  ir_node *value;          /**< value if entity is not of variability uninitialized.
                                Only for atomic entities. */
  union {
    /* ------------- fields for compound entities -------------- */
    compound_ent_attr cmpd_attr;
    /* ------------- fields for method entities ---------------- */
    method_ent_attr   mtd_attr;
  } attr; /**< type specific attributes */

  /* ------------- fields for analyses ---------------*/

#ifdef DEBUG_libfirm
  long nr;             /**< A unique node number for each node to make output
                            readable. */
# endif /* DEBUG_libfirm */
};

/** Initialize entity module. */
void firm_init_entity(void);


/* ----------------------- inline functions ------------------------ */
static INLINE int
_is_entity(const void *thing) {
  return get_kind(thing) == k_entity;
}

static INLINE const char *
_get_entity_name(const entity *ent) {
  assert(ent && ent->kind == k_entity);
  return get_id_str(get_entity_ident(ent));
}

static INLINE ident *
_get_entity_ident(const entity *ent) {
  assert(ent && ent->kind == k_entity);
  return ent->name;
}

static INLINE ident *<commit_msg>Fixed return type of _set_entity_ident()<commit_after>/*
 * Project:     libFIRM
 * File name:   ir/tr/entity_t.h
 * Purpose:     Representation of all program known entities -- private header.
 * Author:      <NAME>, <NAME>
 * Modified by: <NAME>
 * Created:
 * CVS-ID:      $Id$
 * Copyright:   (c) 1998-2003 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */

/**
 * @file entity_t.h
 *
 * entity.h:  entities represent all program known objects.
 *
 * @author <NAME>, <NAME>, <NAME>
 *
 *  An entity is the representation of program known objects in Firm.
 *  The primary concept of entities is to represent members of complex
 *  types, i.e., fields and methods of classes.  As not all programming
 *  language model all variables and methods as members of some class,
 *  the concept of entities is extended to cover also local and global
 *  variables, and arbitrary procedures.
 *
 *  An entity always specifies the type of the object it represents and
 *  the type of the object it is a part of, the owner of the entity.
 *  Originally this is the type of the class of which the entity is a
 *  member.
 *  The owner of local variables is the procedure they are defined in.
 *  The owner of global variables and procedures visible in the whole
 *  program is a universally defined class type "GlobalType".  The owner
 *  of procedures defined in the scope of an other procedure is the
 *  enclosing procedure.
 */

#ifndef _FIRM_TR_ENTITY_T_H_
#define _FIRM_TR_ENTITY_T_H_

#include "firm_common_t.h"
#include "firm_config.h"

#include "type_t.h"
#include "entity.h"
#include "typegmod.h"
#include "mangle.h"
#include "pseudo_irg.h"

/** A path in a compound graph. */
struct compound_graph_path {
  firm_kind kind;       /**< dynamic type tag for compound graph path. */
  ir_type *tp;          /**< The type this path belongs to. */
  int len;              /**< length of the path */
  struct tuple {
    int    index;       /**< Array index.  To compute position of array elements */
    entity *node;       /**< entity */
  } list[1];            /**< List of entity/index tuple of length len to express the
                             access path. */
};

/** attributes for atomic entities */
typedef struct atomic_ent_attr {
  ir_node *value;            /**< value if entity is not of variability uninitialized.
                               Only for atomic entities. */
} atomic_ent_attr;

/** attributes for compound entities */
typedef struct compound_ent_attr {
  ir_node **values;     /**< constant values of compound entities. Only available if
                             variability not uninitialized.  Must be set for variability constant. */
  compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if
                                        variability not uninitialized.  Must be set for variability constant. */
} compound_ent_attr;

/** a reserved value for "not yet set" */
#define VTABLE_NUM_NOT_SET ((unsigned)(-1))

/** attributes for methods */
typedef struct method_ent_attr {
  ir_graph *irg;        /**< The corresponding irg if known.
                             The ir_graph constructor automatically sets this field. */
  unsigned irg_add_properties;   /**< Additional graph properties can be
                                      stored in a entity if no irg is available. */

  unsigned vtable_number;        /**< For a dynamically called method, the number assigned
                                      in the virtual function table. */

  ptr_access_kind *param_access; /**< the parameter access */
  float *param_weight; /**< The weight of method's parameters. Parameters
                          with a high weight are good for procedure cloning. */
} method_ent_attr;


/** the type of an entity */
struct entity {
  firm_kind kind;       /**< The dynamic type tag for entity. */
  ident *name;          /**< The name of this entity. */
  ident *ld_name;       /**< Unique name of this entity, i.e., the mangled
                             name.  If the field is read before written a default
                             mangling is applies.  The name of the owner is prepended
                             to the name of the entity, separated by a underscore.
                             E.g.,  for a class `A' with field `a' this
                             is the ident for `A_a'. */
  ir_type *type;        /**< The type of this entity, e.g., a method type, a
                             basic type of the language or a class itself. */
  ir_type *owner;              /**< The compound type (e.g. class type) this entity belongs to. */
  ent_allocation allocation;   /**< Distinguishes static and dynamically allocated
                                    entities and some further cases. */
  visibility visibility;       /**< Specifies visibility to external program
                                    fragments. */
  ent_variability variability; /**< Specifies variability of entities content. */
  ent_volatility volatility;   /**< Specifies volatility of entities content. */
  ent_stickyness stickyness;   /**< Specifies whether this entity is sticky.  */
  int  offset;                 /**< Offset in bits for this entity.  Fixed when layout
                                    of owner is determined. */
  peculiarity peculiarity;     /**< The peculiarity of this entity. */
  unsigned long visit;         /**< visited counter for walks of the type information. */
  struct dbg_info *dbi;        /**< A pointer to information for debug support. */
  void *link;                  /**< To store some intermediate information. */

  /* ------------- fields for entities owned by a class type ---------------*/

  entity **overwrites;     /**< A list of entities this entity overwrites. */
  entity **overwrittenby;  /**< A list of entities that overwrite this entity.  */

  /* ------------- fields for atomic entities  --------------- */
  ir_node *value;          /**< value if entity is not of variability uninitialized.
                                Only for atomic entities. */
  union {
    /* ------------- fields for compound entities -------------- */
    compound_ent_attr cmpd_attr;
    /* ------------- fields for method entities ---------------- */
    method_ent_attr   mtd_attr;
  } attr; /**< type specific attributes */

  /* ------------- fields for analyses ---------------*/

#ifdef DEBUG_libfirm
  long nr;             /**< A unique node number for each node to make output
                            readable. */
# endif /* DEBUG_libfirm */
};

/** Initialize entity module. */
void firm_init_entity(void);


/* ----------------------- inline functions ------------------------ */
static INLINE int
_is_entity(const void *thing) {
  return get_kind(thing) == k_entity;
}

static INLINE const char *
_get_entity_name(const entity *ent) {
  assert(ent && ent->kind == k_entity);
  return get_id_str(get_entity_ident(ent));
}

static INLINE ident *
_get_entity_ident(const entity *ent) {
  assert(ent && ent->kind == k_entity);
  return ent->name;
}

static INLINE void
{'fraction_non_alphanumeric': 0.11225634553358575, 'fraction_numerical': 0.0014023278642546627, 'mean_word_length': 2.0450469684030743, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7439071', 'n_tokens_mistral': 3734, 'n_tokens_neox': 3613, 'n_words': 1514}