<commit_before>/**
 * ClassServer.cc
 *
 *
 * Copyright(c) 2001 <NAME>, <NAME>
 * All rights reserved.
 */

#include "ClassServer.h"

std::vector<std::vector<bool> >& ClassServer::getMap() {
   static std::vector<std::vector<bool> > map = ClassServer::init_map();
   return map;
}
ClassTypeHashMap* ClassServer::getClassType() {
   static ClassTypeHashMap *class_type = ClassServer::init_type();
   return class_type;
}
ClassNameHashMap* ClassServer::getClassName() {
   static ClassNameHashMap *class_name = ClassServer::init_name();
   return class_name;
}


/*
 * A function to automatically initialize the map with
 * all classes and super-classes. 
 *
*/
void ClassServer::init_inheritance(std::vector<std::vector<bool> >& map, int parentClassNum, int classNum) {
  map[parentClassNum][classNum] = true;
  //printf("ClassServer inheritance %d : %d \n",classNum,parentClassNum);
  for(int i = 0; i < NUMBER_OF_CLASSES; i++) {
    if (map[i][parentClassNum] && i!=parentClassNum && !map[i][classNum]) 
      init_inheritance(map,i,classNum);
  }
}


/*
 * Mike says: I changed this function to make it easier to debug.
 * I noticed that a few of the original mappings were not completely
 * transitive (that is, A->B and B->C but not A->C).  I assume this was
 * a mistake.
 * Now you only have to indicate the direct parent class of a class.
 * But you now MUST insert every parent class before each of its descendents.
 * This could be made even simpler at the expense of efficiency.
 * 
*/
std::vector<std::vector<bool> > ClassServer::init_map() {
   std::vector<std::vector<bool> > map(NUMBER_OF_CLASSES);
   // map will first receive false for all positions, except when the
   // first index is equal to the second since a type is always
   // assignable from itself
   for (int i = 0; i < NUMBER_OF_CLASSES; i++) {
     map[i].resize(NUMBER_OF_CLASSES);
     for (int j = 0; j < NUMBER_OF_CLASSES; j++) {
     map[i][j] = (i == j);
     }
   }
   
//=================================================================
// ATOMS
//
// NOTE: The order of the commands below is important. You MUST 
// declare every parent class before its descendents. Otherwise
// some superclasses will be missing in the inheritance set of 
// some classes.
//=================================================================

#include "type_inheritance.h"


   return map;
}



ClassTypeHashMap *ClassServer::init_type() {
   static ClassTypeHashMap class_to_int;
   // getClassName/init_name is called to avoid duplicate strings
   getClassName();

   class_to_int.clear();
#include "type_classint.h"
   return &class_to_int;
}

ClassNameHashMap *ClassServer::init_name() {
   static ClassNameHashMap int_to_class;

   int_to_class.clear();
#include "type_intclass.h"
   return &int_to_class;
}

Type* ClassServer::getChildren(Type type, int &n) {
    int count = 0;
    // counts the number of subclasses of a given type
    for (int i = 0; i < NUMBER_OF_CLASSES; i++) {
       if ((getMap()[type][i]) && (i != type)) count++;
    }
    Type* answer = new Type[count*sizeof(Type)];

    n = count;
    for (int i = 0, j = 0; i < NUMBER_OF_CLASSES; i++) {
        if ((getMap()[type][i]) && (i != type)) {
            answer[j++] = i;
        }
    }
    return answer;
}

int ClassServer::getNumberOfClasses() {
    return NUMBER_OF_CLASSES;
}

bool ClassServer::isAssignableFrom(Type super, Type sub) {
    return getMap()[super][sub];
}

bool ClassServer::isDefined(const char *typeName) {
    return (getType(typeName) < NUMBER_OF_CLASSES);
}

Type ClassServer::getType(const char *typeName) {
    ClassTypeHashMap::iterator it = getClassType()->find(typeName);

    if (it == getClassType()->end()){
        return(NOTYPE);
    }
    return it->second;
}

const char* ClassServer::getTypeName(Type type) {
   int t = (int) type;
   if ((t < 0) || (t >=  NUMBER_OF_CLASSES)) {
        return NULL;
   }
   return (*getClassName())[type];
}
Handle ClassServer::typeDesignatorHandle(Type T) {<commit_msg>check for null pointer dereference<commit_after>/**
 * ClassServer.cc
 *
 *
 * Copyright(c) 2001 <NAME>, <NAME>
 * All rights reserved.
 */

#include "ClassServer.h"

std::vector<std::vector<bool> >& ClassServer::getMap() {
   static std::vector<std::vector<bool> > map = ClassServer::init_map();
   return map;
}
ClassTypeHashMap* ClassServer::getClassType() {
   static ClassTypeHashMap *class_type = ClassServer::init_type();
   return class_type;
}
ClassNameHashMap* ClassServer::getClassName() {
   static ClassNameHashMap *class_name = ClassServer::init_name();
   return class_name;
}


/*
 * A function to automatically initialize the map with
 * all classes and super-classes. 
 *
*/
void ClassServer::init_inheritance(std::vector<std::vector<bool> >& map, int parentClassNum, int classNum) {
  map[parentClassNum][classNum] = true;
  //printf("ClassServer inheritance %d : %d \n",classNum,parentClassNum);
  for(int i = 0; i < NUMBER_OF_CLASSES; i++) {
    if (map[i][parentClassNum] && i!=parentClassNum && !map[i][classNum]) 
      init_inheritance(map,i,classNum);
  }
}


/*
 * Mike says: I changed this function to make it easier to debug.
 * I noticed that a few of the original mappings were not completely
 * transitive (that is, A->B and B->C but not A->C).  I assume this was
 * a mistake.
 * Now you only have to indicate the direct parent class of a class.
 * But you now MUST insert every parent class before each of its descendents.
 * This could be made even simpler at the expense of efficiency.
 * 
*/
std::vector<std::vector<bool> > ClassServer::init_map() {
   std::vector<std::vector<bool> > map(NUMBER_OF_CLASSES);
   // map will first receive false for all positions, except when the
   // first index is equal to the second since a type is always
   // assignable from itself
   for (int i = 0; i < NUMBER_OF_CLASSES; i++) {
     map[i].resize(NUMBER_OF_CLASSES);
     for (int j = 0; j < NUMBER_OF_CLASSES; j++) {
     map[i][j] = (i == j);
     }
   }
   
//=================================================================
// ATOMS
//
// NOTE: The order of the commands below is important. You MUST 
// declare every parent class before its descendents. Otherwise
// some superclasses will be missing in the inheritance set of 
// some classes.
//=================================================================

#include "type_inheritance.h"


   return map;
}



ClassTypeHashMap *ClassServer::init_type() {
   static ClassTypeHashMap class_to_int;
   // getClassName/init_name is called to avoid duplicate strings
   getClassName();

   class_to_int.clear();
#include "type_classint.h"
   return &class_to_int;
}

ClassNameHashMap *ClassServer::init_name() {
   static ClassNameHashMap int_to_class;

   int_to_class.clear();
#include "type_intclass.h"
   return &int_to_class;
}

Type* ClassServer::getChildren(Type type, int &n) {
    int count = 0;
    // counts the number of subclasses of a given type
    for (int i = 0; i < NUMBER_OF_CLASSES; i++) {
       if ((getMap()[type][i]) && (i != type)) count++;
    }
    Type* answer = new Type[count*sizeof(Type)];

    n = count;
    for (int i = 0, j = 0; i < NUMBER_OF_CLASSES; i++) {
        if ((getMap()[type][i]) && (i != type)) {
            answer[j++] = i;
        }
    }
    return answer;
}

int ClassServer::getNumberOfClasses() {
    return NUMBER_OF_CLASSES;
}

bool ClassServer::isAssignableFrom(Type super, Type sub) {
    return getMap()[super][sub];
}

bool ClassServer::isDefined(const char *typeName) {
    return (getType(typeName) < NUMBER_OF_CLASSES);
}

Type ClassServer::getType(const char *typeName)
{
    if (!typeName) return NOTYPE;

    ClassTypeHashMap::iterator it = getClassType()->find(typeName);

    if (it == getClassType()->end()){
        return NOTYPE;
    }
    return it->second;
}

const char* ClassServer::getTypeName(Type type) {
   int t = (int) type;
   if ((t < 0) || (t >=  NUMBER_OF_CLASSES)) {
        return NULL;
   }
   return (*getClassName())[type];
}
Handle ClassServer::typeDesignatorHandle(Type T) {
{'fraction_non_alphanumeric': 0.16221587380449634, 'fraction_numerical': 0.0029809961495466403, 'mean_word_length': 3.871143375680581, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '1334970', 'n_tokens_mistral': 2634, 'n_tokens_neox': 2528, 'n_words': 735}