<commit_before># frozen_string_literal: true

module Orbacle
  class GlobalTree
    class ArgumentsTree < Struct.new(:args, :kwargs, :blockarg)
      Regular = Struct.new(:name)
      Optional = Struct.new(:name)
      Splat = Struct.new(:name)
      Nested = Struct.new(:args)
    end

    class Method
      def initialize(id:, place_of_definition_id:, name:, location:, visibility:, args:)
        raise ArgumentError.new(visibility) if ![:public, :private, :protected].include?(visibility)

        @id = id
        @place_of_definition_id = place_of_definition_id
        @name = name
        @location = location
        @visibility = visibility
        @args = args
      end

      attr_reader :id, :name, :location, :args, :place_of_definition_id
      attr_accessor :visibility
    end

    class Lambda
      def initialize(id, args)
        @id = id
        @args = args
      end

      attr_reader :id, :args
    end

    class Klass
      def initialize(id:, parent_ref:, eigenclass_id: nil)
        @id = id
        @parent_ref = parent_ref
        @eigenclass_id = eigenclass_id
      end

      attr_reader :id, :parent_ref, :eigenclass_id
      attr_writer :eigenclass_id

      def ==(other)
        @id == other.id &&
          @parent_ref == other.parent_ref &&
          @eigenclass_id == other.eigenclass_id
      end
    end

    class Mod
      def initialize(id, eigenclass_id = nil)
        @id = id
        @eigenclass_id = eigenclass_id
      end

      attr_reader :id, :eigenclass_id
      attr_writer :eigenclass_id

      def ==(other)
        @id == other.id &&
          @eigenclass_id == other.eigenclass_id
      end
    end

    class Constant
      def initialize(name, scope, location, definition_id = nil)
        @name = name
        @scope = scope
        @location = location
        @definition_id = definition_id
      end

      attr_reader :name, :scope, :location, :definition_id

      def ==(other)
        @name == other.name &&
          @scope == other.scope &&
          @location == other.location &&
          @definition_id == other.definition_id
      end

      def full_name
        [*scope.elems, @name].join("::")
      end
    end

    def initialize(id_generator)
      @id_generator = id_generator
      @constants = ConstantsTree.new
      @classes_by_id = {}
      @modules_by_id = {}
      @metods = Hash.new {|h,k| h[k] = Hash.new {|h2, k2| h2[k2] = [] } }
      @metods_by_id = {}
      @lambdas_by_id = {}
    end

    attr_reader :metods

    def add_method(metod)
      @metods[metod.place_of_definition_id][metod.name] << metod
      @metods_by_id[metod.id] = metod
      return metod
    end

    def add_klass(parent_ref)
      klass = Klass.new(id: id_generator.call, parent_ref: parent_ref)
      @classes_by_id[klass.id] = klass
      return klass
    end

    def add_mod
      mod = Mod.new(id_generator.call)
      @modules_by_id[mod.id] = mod
      return mod
    end

    def add_constant(constant)
      @constants.add_element(constant.scope, constant.name, constant)
      return constant
    end

    def add_lambda(args)
      lamba = Lambda.new(id_generator.call, args)
      @lambdas_by_id[lamba.id] = lamba
      return lamba
    end

    def get_class(class_id)
      @classes_by_id[class_id]
    end

    def get_module(module_id)
      @modules_by_id[module_id]<commit_msg>No more keyword arguments in Klass<commit_after># frozen_string_literal: true

module Orbacle
  class GlobalTree
    class ArgumentsTree < Struct.new(:args, :kwargs, :blockarg)
      Regular = Struct.new(:name)
      Optional = Struct.new(:name)
      Splat = Struct.new(:name)
      Nested = Struct.new(:args)
    end

    class Method
      def initialize(id:, place_of_definition_id:, name:, location:, visibility:, args:)
        raise ArgumentError.new(visibility) if ![:public, :private, :protected].include?(visibility)

        @id = id
        @place_of_definition_id = place_of_definition_id
        @name = name
        @location = location
        @visibility = visibility
        @args = args
      end

      attr_reader :id, :name, :location, :args, :place_of_definition_id
      attr_accessor :visibility
    end

    class Lambda
      def initialize(id, args)
        @id = id
        @args = args
      end

      attr_reader :id, :args
    end

    class Klass
      def initialize(id, parent_ref, eigenclass_id = nil)
        @id = id
        @parent_ref = parent_ref
        @eigenclass_id = eigenclass_id
      end

      attr_reader :id, :parent_ref, :eigenclass_id
      attr_writer :eigenclass_id

      def ==(other)
        @id == other.id &&
          @parent_ref == other.parent_ref &&
          @eigenclass_id == other.eigenclass_id
      end
    end

    class Mod
      def initialize(id, eigenclass_id = nil)
        @id = id
        @eigenclass_id = eigenclass_id
      end

      attr_reader :id, :eigenclass_id
      attr_writer :eigenclass_id

      def ==(other)
        @id == other.id &&
          @eigenclass_id == other.eigenclass_id
      end
    end

    class Constant
      def initialize(name, scope, location, definition_id = nil)
        @name = name
        @scope = scope
        @location = location
        @definition_id = definition_id
      end

      attr_reader :name, :scope, :location, :definition_id

      def ==(other)
        @name == other.name &&
          @scope == other.scope &&
          @location == other.location &&
          @definition_id == other.definition_id
      end

      def full_name
        [*scope.elems, @name].join("::")
      end
    end

    def initialize(id_generator)
      @id_generator = id_generator
      @constants = ConstantsTree.new
      @classes_by_id = {}
      @modules_by_id = {}
      @metods = Hash.new {|h,k| h[k] = Hash.new {|h2, k2| h2[k2] = [] } }
      @metods_by_id = {}
      @lambdas_by_id = {}
    end

    attr_reader :metods

    def add_method(metod)
      @metods[metod.place_of_definition_id][metod.name] << metod
      @metods_by_id[metod.id] = metod
      return metod
    end

    def add_klass(parent_ref)
      klass = Klass.new(id_generator.call, parent_ref)
      @classes_by_id[klass.id] = klass
      return klass
    end

    def add_mod
      mod = Mod.new(id_generator.call)
      @modules_by_id[mod.id] = mod
      return mod
    end

    def add_constant(constant)
      @constants.add_element(constant.scope, constant.name, constant)
      return constant
    end

    def add_lambda(args)
      lamba = Lambda.new(id_generator.call, args)
      @lambdas_by_id[lamba.id] = lamba
      return lamba
    end

    def get_class(class_id)
      @classes_by_id[class_id]
    end

    def get_module(module_id)
      @modules_by_id[module_id]
{'fraction_non_alphanumeric': 0.09997033521210323, 'fraction_numerical': 0.0011865915158706616, 'mean_word_length': 2.2590623489608506, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 3, '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': '210449', 'n_tokens_mistral': 2250, 'n_tokens_neox': 2193, 'n_words': 484}