<commit_before>/* -------------------------------------------------------------------
 * $Id$
 * -------------------------------------------------------------------
 * Intraprozedurale Analyse zur Abschtzung der Aufrulrelation. Es
 * wird eine Menge von freien Methoden und anschlieend die an den
 * Call-Operationen aufrufbaren Methoden bestimmt.
 *
 * Erstellt: <NAME>, 09.06.2002
 * ---------------------------------------------------------------- */

#include "stdlib.h"
#include "cgana.h"


#include "eset.h"
#include "pmap.h"
#include "array.h"
#include "irprog.h"
#include "irgwalk.h"
#include "ircons.h"
#include "irgmod.h"
#include "irnode.h"
#include "irflag.h"

#include "dbginfo_t.h"

/* Eindeutige Adresse zur Markierung von besuchten Knoten und zur
 * Darstellung der unbekannten Methode. */
static void * MARK = &MARK;



/* --- sel methods ---------------------------------------------------------- */


static eset * entities = NULL;


/* Bestimmt die eindeutige Methode, die die Methode fr den
 * bergebenene (dynamischen) Typ berschreibt. */
static entity * get_implementation(type * class, entity * method) {
  int i;
  if (get_entity_peculiarity(method) != description &&
      get_entity_owner(method) == class) {
    return method;
  }
  for (i = get_entity_n_overwrittenby(method) - 1; i >= 0; --i) {
    entity * e = get_entity_overwrittenby(method, i);
    if (get_entity_peculiarity(e) != description && get_entity_owner(e) == class) {
      return e;
    }
  }
  for (i = get_class_n_supertypes(class) - 1; i >= 0; --i) {
    entity * e = get_implementation(get_class_supertype(class, i), method);
    if (e) {
      return e;
    }
  }
  assert(0 && "implemenation not found");
  return NULL;
}

/* Returns the entity that contains the implementation of the inherited
   entity if available, else returns the entity passed. */
entity *get_inherited_methods_implementation(entity *inh_meth) {
  entity *impl_meth = NULL;
  ir_node *addr = get_atomic_ent_value(inh_meth);
  assert(addr && "constant entity without value");

  if (get_irn_op(addr) == op_Const) {
    impl_meth = tarval_to_entity(get_Const_tarval(addr));
  }

  assert(!impl_meth || get_entity_peculiarity(impl_meth) == existent);
  return impl_meth? impl_meth : inh_meth;
}


/* Collect the entity representing the implementation of this
   entity (not the same if inherited) and all entities for overwriting
   implementations in "set".
   If the implementation of the method is not included in the
   compilation unit "open" is set to true.
   A recursive descend in the overwritten relation.
   Cycle-free, therefore must terminate. */
void collect_impls(entity *method, eset *set, int *size, bool *open) {<commit_msg>more verbose assertion<commit_after>/* -------------------------------------------------------------------
 * $Id$
 * -------------------------------------------------------------------
 * Intraprozedurale Analyse zur Abschtzung der Aufrulrelation. Es
 * wird eine Menge von freien Methoden und anschlieend die an den
 * Call-Operationen aufrufbaren Methoden bestimmt.
 *
 * Erstellt: <NAME>, 09.06.2002
 * ---------------------------------------------------------------- */

#include "stdlib.h"
#include "cgana.h"


#include "eset.h"
#include "pmap.h"
#include "array.h"
#include "irprog.h"
#include "irgwalk.h"
#include "ircons.h"
#include "irgmod.h"
#include "irnode.h"
#include "irflag.h"

#include "dbginfo_t.h"

/* Eindeutige Adresse zur Markierung von besuchten Knoten und zur
 * Darstellung der unbekannten Methode. */
static void * MARK = &MARK;



/* --- sel methods ---------------------------------------------------------- */


static eset * entities = NULL;


/* Bestimmt die eindeutige Methode, die die Methode fr den
 * bergebenene (dynamischen) Typ berschreibt. */
static entity * get_implementation(type * class, entity * method) {
  int i;
  if (get_entity_peculiarity(method) != description &&
      get_entity_owner(method) == class) {
    return method;
  }
  for (i = get_entity_n_overwrittenby(method) - 1; i >= 0; --i) {
    entity * e = get_entity_overwrittenby(method, i);
    if (get_entity_peculiarity(e) != description && get_entity_owner(e) == class) {
      return e;
    }
  }
  for (i = get_class_n_supertypes(class) - 1; i >= 0; --i) {
    entity * e = get_implementation(get_class_supertype(class, i), method);
    if (e) {
      return e;
    }
  }
  assert(0 && "implemenation not found");
  return NULL;
}

/* Returns the entity that contains the implementation of the inherited
   entity if available, else returns the entity passed. */
entity *get_inherited_methods_implementation(entity *inh_meth) {
  entity *impl_meth = NULL;
  ir_node *addr = get_atomic_ent_value(inh_meth);
  assert(addr && "constant entity without value");

  if (get_irn_op(addr) == op_Const) {
    impl_meth = tarval_to_entity(get_Const_tarval(addr));
  } else {
    assert(0 && "Complex constant values not supported -- adress of method should be straight constant!");
  }
  if (impl_meth && (get_entity_peculiarity(impl_meth) != existent)) {
    printf("this_meth: "); DDMEO(inh_meth);
    printf("impl meth: "); DDMEO(impl_meth);
    assert(!impl_meth || get_entity_peculiarity(impl_meth) == existent);
  }
  return impl_meth? impl_meth : inh_meth;
}


/* Collect the entity representing the implementation of this
   entity (not the same if inherited) and all entities for overwriting
   implementations in "set".
   If the implementation of the method is not included in the
   compilation unit "open" is set to true.
   A recursive descend in the overwritten relation.
   Cycle-free, therefore must terminate. */
void collect_impls(entity *method, eset *set, int *size, bool *open) {
{'fraction_non_alphanumeric': 0.19408987585242174, 'fraction_numerical': 0.004721105088302151, 'mean_word_length': 2.664317745035234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2075679', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1767, 'n_words': 517}