<commit_before>package som.compiler;

import java.util.HashMap;
import java.util.LinkedHashMap;

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

import com.oracle.truffle.api.source.SourceSection;
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 HashMap<SSymbol, SInvokable> instanceMethods;
  private final HashMap<SSymbol, SInvokable> factoryMethods;
  private final SourceSection sourceSection;

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

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

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

  public SSymbol getName() {
    return name;
  }

  public void initializeClass(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(factoryMethods);
      result.getSOMClass().setName(Symbols.symbolFor(ccName));
    }

    // Initialize the resulting class
    result.setName(name);
    result.setInstanceSlots(slotDefinitions);
    result.setInstanceInvokables(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 int index;
    private final AccessModifier modifier;
    private final boolean immutable;
    private final SourceSection source;
<commit_msg>Set outer object<commit_after>package som.compiler;

import java.util.HashMap;
import java.util.LinkedHashMap;

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

import com.oracle.truffle.api.source.SourceSection;
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 HashMap<SSymbol, SInvokable> instanceMethods;
  private final HashMap<SSymbol, SInvokable> factoryMethods;
  private final SourceSection sourceSection;

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

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

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

  public SSymbol getName() {
    return name;
  }

  public void initializeClass(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(factoryMethods);
      result.getSOMClass().setName(Symbols.symbolFor(ccName));
    }

    // Initialize the resulting class
    result.setName(name);
    result.setInstanceSlots(slotDefinitions);
    result.setInstanceInvokables(instanceMethods);
  }

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

  public static final class SlotDefinition {
    private final SSymbol name;
    private final int index;
    private final AccessModifier modifier;
    private final boolean immutable;
    private final SourceSection source;

{'fraction_non_alphanumeric': 0.07302807486631016, 'fraction_numerical': 0.0, 'mean_word_length': 4.480769230769231, 'pattern_counts': {'":': 0, '<': 21, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3383502', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1604, 'n_words': 451}