<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using dotless.Functions;
using dotless.Tree;

namespace dotless.Infrastructure
{
  public class Env
  {
    private Dictionary<string, Type> _functionTypes;

    public Stack<Ruleset> Frames { get; set; }

    public Env()
    {
      Frames = new Stack<Ruleset>();
    }

    public Function GetFunction(string name)
    {
      if (_functionTypes == null)
      {
        var functionType = typeof (Function);

        _functionTypes = Assembly.GetExecutingAssembly()
          .GetTypes()
          .Where(t => functionType.IsAssignableFrom(t) && t != functionType)
          .ToDictionary(t => GetFunctionName(t));
      }

      name = name.ToLowerInvariant();

      if (_functionTypes.ContainsKey(name))
        return (Function) Activator.CreateInstance(_functionTypes[name]);

      return null;
    }

    private static string GetFunctionName(Type t)
    {
      var name = t.Name.ToLowerInvariant();
      return name.EndsWith("function") ? name.Substring(0, name.Length - 8) : name;
    }
  }
}<commit_msg>Made Env.GetFunction virutal<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using dotless.Functions;
using dotless.Tree;

namespace dotless.Infrastructure
{
  public class Env
  {
    private Dictionary<string, Type> _functionTypes;

    public Stack<Ruleset> Frames { get; set; }

    public Env()
    {
      Frames = new Stack<Ruleset>();
    }

    public virtual Function GetFunction(string name)
    {
      if (_functionTypes == null)
      {
        var functionType = typeof (Function);

        _functionTypes = Assembly.GetExecutingAssembly()
          .GetTypes()
          .Where(t => functionType.IsAssignableFrom(t) && t != functionType)
          .ToDictionary(t => GetFunctionName(t));
      }

      name = name.ToLowerInvariant();

      if (_functionTypes.ContainsKey(name))
        return (Function) Activator.CreateInstance(_functionTypes[name]);

      return null;
    }

    private static string GetFunctionName(Type t)
    {
      var name = t.Name.ToLowerInvariant();
      return name.EndsWith("function") ? name.Substring(0, name.Length - 8) : name;
    }
  }
}
{'fraction_non_alphanumeric': 0.11023276240667546, 'fraction_numerical': 0.001756697408871322, 'mean_word_length': 2.9208261617900173, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3299962', 'n_tokens_mistral': 670, 'n_tokens_neox': 651, 'n_words': 151}