<commit_before>package som.compiler;

import som.vm.NotYetImplementedException;
import som.vmobjects.SClass;
import som.vmobjects.SInvokable.SMethod;
import som.vmobjects.SSymbol;

/**
 * Produced by the Parser, contains all static information on a class that is
 * in the source. Is used to instantiate complete class objects at runtime,
 * which then also have the super class resolved.
 * @author <NAME>
 */
public final class ClassDefinition {
  private final SSymbol name;
  private final SMethod   assembleClassObjectMethod;
  private final SMethod[] instanceMethods;
  private final SMethod[] factoryMethods;

  public ClassDefinition(final SSymbol name,
      final SMethod classObjectInstantiation, final SMethod[] instanceMethods,
      final SMethod[] factoryMethods) {
    this.name = name;
    this.assembleClassObjectMethod = classObjectInstantiation;
    this.instanceMethods = instanceMethods;
    this.factoryMethods  = factoryMethods;
  }

  public SSymbol getName() {
    return name;
  }

  public SClass createSClass(final SClass superClass) {
    // build class class name
    String ccName = name.getString() + " class";

//  // Allocate the class of the resulting class
//  SClass resultClass = Universe.newClass(Classes.metaclassClass);
    //
    //
//        // Initialize the class of the resulting class
//        resultClass.setInstanceInvokables(
//            SArray.create(factoryMethods.toArray(new Object[0])));
//        resultClass.setName(Symbols.symbolFor(ccname));
    //
//        SClass superMClass = superClass.getSOMClass();
//        resultClass.setSuperClass(superMClass);
    //
//        // Allocate the resulting class
//        SClass result = Universe.newClass(resultClass);
    //
//        // Initialize the resulting class
//        result.setName(name);
//        result.setSuperClass(superClass);
//        result.setInstanceFields(
//            SArray.create(slots.toArray(new Object[0])));
//        result.setInstanceInvokables(
//            SArray.create(methods.toArray(new Object[0])));
    //
//        return result;
    throw new NotYetImplementedException();
  }

  public static final class SlotDefinition {
    private final SSymbol name;
    private final AccessModifier modifier;
    private final boolean immutable;

    public SlotDefinition(final SSymbol name,
        final AccessModifier acccessModifier, final boolean immutable) {
      this.name      = name;
      this.modifier  = acccessModifier;
      this.immutable = immutable;
    }

    public SSymbol getName() {
      return name;
    }

    public AccessModifier getModifier() {
      return modifier;
    }

    public boolean isImmutable() {
      return immutable;
    }

    @Override
    public String toString() {
      String imm = immutable ? ", immut" : "";
      return "SlotDef(" + name.getString()
          + " :" + modifier.toString().toLowerCase() + imm + ")";
    }
  }
}<commit_msg>Add some missing elements to class definition and initialize class objects<commit_after>package som.compiler;

import java.util.LinkedHashMap;

import som.vm.Symbols;
import som.vm.constants.Classes;
import som.vmobjects.SAbstractObject;
import som.vmobjects.SArray;
import som.vmobjects.SClass;
import som.vmobjects.SInvokable;
import som.vmobjects.SInvokable.SMethod;
import som.vmobjects.SSymbol;

import com.sun.istack.internal.Nullable;

/**
 * Produced by the Parser, contains all static information on a class that is
 * in the source. Is used to instantiate complete class objects at runtime,
 * which then also have the super class resolved.
 * @author <NAME>
 */
public final class ClassDefinition {
  private final SSymbol      name;
  private final SMethod      assembleClassObjectMethod;
  private final SInvokable[] instanceMethods;
  private final SMethod[]    factoryMethods;

  @Nullable
  private final LinkedHashMap<SSymbol, ClassDefinition> nestedClassDefinitions;

  @Nullable
  private final LinkedHashMap<SSymbol, SlotDefinition>  slotDefinitions;

  public ClassDefinition(final SSymbol name,
      final SMethod classObjectInstantiation, final SInvokable[] instanceMethods,
      final SMethod[] factoryMethods,
      final LinkedHashMap<SSymbol, ClassDefinition> nestedClassDefinitions,
      final LinkedHashMap<SSymbol, SlotDefinition> slotDefinitions) {
    this.name = name;
    this.assembleClassObjectMethod = classObjectInstantiation;
    this.instanceMethods = instanceMethods;
    this.factoryMethods  = factoryMethods;
    this.nestedClassDefinitions = nestedClassDefinitions;
    this.slotDefinitions = slotDefinitions;
  }

  public SSymbol getName() {
    return name;
  }

  public void initializeClass(final SAbstractObject outer, final SClass result,
      final SClass superClass) {
    result.setSuperClass(superClass);

    // build class class name
    String ccName = name.getString() + " class";

    if (result.getSOMClass() != null) {
      // Initialize the class of the resulting class
      result.getSOMClass().setInstanceInvokables(SArray.create(factoryMethods));
      result.getSOMClass().setName(Symbols.symbolFor(ccName));
    }

    // Initialize the resulting class
    result.setName(name);
    result.setInstanceFields(SArray.create(
        slotDefinitions.values().toArray(new Object[slotDefinitions.size()])));
    result.setInstanceInvokables(SArray.create(instanceMethods));
  }

  public SClass instantiateClass(final SAbstractObject outer, final SClass superClass) {
    SClass resultClass = new SClass(Classes.metaclassClass);
    SClass result = new SClass(resultClass);
    initializeClass(outer, result, superClass);
    return result;
  }

  public static final class SlotDefinition {
    private final SSymbol name;
    private final AccessModifier modifier;
    private final boolean immutable;

    public SlotDefinition(final SSymbol name,
        final AccessModifier acccessModifier, final boolean immutable) {
      this.name      = name;
      this.modifier  = acccessModifier;
      this.immutable = immutable;
    }

    public SSymbol getName() {
      return name;
    }

    public AccessModifier getModifier() {
      return modifier;
    }

    public boolean isImmutable() {
      return immutable;
    }

    @Override
    public String toString() {
      String imm = immutable ? ", immut" : "";
      return "SlotDef(" + name.getString()
          + " :" + modifier.toString().toLowerCase() + imm + ")";
    }
  }

  public ClassDefinition getEmbeddedClassDefinition(final String string) {
    if (nestedClassDefinitions == null) {
      return null;
    }
    return nestedClassDefinitions.get(Symbols.symbolFor(string));
  }

  public int getNumberOfSlots() {
    if (slotDefinitions == null) {
      return 0;
    }
    return slotDefinitions.size();
  }
}
{'fraction_non_alphanumeric': 0.09056103666617582, 'fraction_numerical': 0.0005890148726255338, 'mean_word_length': 3.334396936821953, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5379968', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1846, 'n_words': 496}