<commit_before>/**
 * __          __   _ _   _                  _
 * \ \        / /  (_) | | |                | |
 *  \ \  /\  / / __ _| |_| |__    _ __   ___| |_
 *   \ \/  \/ / '__| | __| '_ \  | '_ \ / _ \ __|
 *    \  /\  /| |  | | |_| | | |_| | | |  __/ |_
 *     \/  \/ |_|  |_|\__|_| |_(_)_| |_|\___|\__|
 *
 * @created     2012-02-08
 * @edited      2012-09-26
 * @package     Libraries
 * @see         https://github.com/writh/classical
 *
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

global                                  = global || {};

/**
 * Defines a new Class.
 *
 * @global
 * @constructor
 */
global.Class = function() {};

/**
 * Creates a public member of a Class.
 *
 * @global
 * @param   member
 * @return  {Object}
 * @constructor
 */
global.Public = function Public(member) { return setVisibility(member); };

/**
 * Creates a private member of a Class.
 *
 * @global
 * @param   member
 * @return  {Object}
 * @constructor
 */
global.Private = function Private(member) { return setVisibility(member); };

/**
 * Creates a protected member of a Class.
 *
 * @global
 * @param   member
 * @return  {Object}
 * @constructor
 */
global.Protected = function Protected(member) { return setVisibility(member); };

/**
 * Creates a static member of a Class.
 *
 * @global
 * @param   member
 * @return  {Object}
 * @constructor
 */
global.Static = function Static(member) { return setStatic(member); };


/***************************************
 * INTERNALS
 *
 * The following code is not a part of the public API for Classical, and
 * should not be altered or exposed to external scripts.
 ***************************************/
var BaseClass                           = function BaseClass() {};

/**
 * Implements Classical inheritance by wrapping prototypal inheritance.
 *
 * @param   {Function}      fn
 * @param   {Object}        _super
 * @return  {ClassFactory}
 * @constructor
 * @global
 */
global.Class = function(fn, _super) {
    var member;
    _super                              = _super || {};

    // Create a copy of the SuperClass to set the prototype.
    initializing                        = true;
    var InheritedPrototype              = typeof this == 'function' ? this : BaseClass;
    var prototype                       = new InheritedPrototype;
    initializing                        = false;

    // Get a _preInstance.
    var _preInstance                    = new fn;
    var base                            = function() {};
    base.prototype                      = prototype;

    // Extend the _preInstance with the parent's members.
    for (member in _super) {
        if (member != 'constructor' && _super.hasOwnProperty(member)) {
            if (_super[member]._visibility == 'Public' || _super[member]._visibility == 'Protected' && typeof _preInstance[member] == 'undefined') {
                _preInstance[member]    = _super[member];
            }
        }
    }

    // Add the _super to the _preInstance, for construction and this._super purposes.
    _preInstance._super                 = _super;

    // Set up the ClassFactory.  This is what actually gets instantiated.
    var ClassFactory = function() {
        var _instance                   = new base;
        var _public                     = new base;

        if (!initializing) {
            assemble(_instance, _public, _preInstance);
            construct(_instance, _instance, arguments);
        }

        return _public;
    };

    // Bind the ClassFactory to the prototype (for the inheritance chain).
    ClassFactory.prototype              = prototype;

    // Set up static methods.
    for (member in _preInstance) {
        if (_preInstance.hasOwnProperty(member)) {
            if (_preInstance[member]._static === true && _preInstance[member]._visibility == 'Public') {
                ClassFactory[member]    = copyValue(_preInstance[member]._value, ClassFactory);
            }
        }
    }

    // Setup a method to extend the base class.
    var extend                          = arguments.callee;
    ClassFactory.extend                 = function(newfn) {
        return extend.call(ClassFactory, newfn, _preInstance);
    };

    // Assembles the instance and its public accessors.
    var assemble = function(_instance, _public, _preInstance) {
        var member;

        if (typeof _preInstance._super != 'undefined') {
            _instance._super            = new base;
            assemble(_instance._super, {}, _preInstance._super);
        }

        for (member in _preInstance) {
            if (member != '_super' && _preInstance.hasOwnProperty(member)) {
                _instance[member]       = copyValue(_preInstance[member]._value, _instance);

                if (_preInstance[member]._visibility == 'Public') {
                    _public[member]     = _instance[member];
                }
            }
        }
    };

    // Recursively calls the constructors for the class, starting with the ancestor
    // and working towards the instance.
    var construct = function(context, target, arguments) {
       // Call the SuperClass constructors first.
       if(target._super instanceof BaseClass && target._super._super instanceof BaseClass) {
           construct(context, target._super, arguments);<commit_msg>Fixed a bug with super-class methods being bound to the wrong instance.<commit_after>/**
 * __          __   _ _   _                  _
 * \ \        / /  (_) | | |                | |
 *  \ \  /\  / / __ _| |_| |__    _ __   ___| |_
 *   \ \/  \/ / '__| | __| '_ \  | '_ \ / _ \ __|
 *    \  /\  /| |  | | |_| | | |_| | | |  __/ |_
 *     \/  \/ |_|  |_|\__|_| |_(_)_| |_|\___|\__|
 *
 * @created     2012-02-08
 * @edited      2012-09-26
 * @package     Libraries
 * @see         https://github.com/writh/classical
 *
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

global                                  = global || {};

/**
 * Defines a new Class.
 *
 * @global
 * @constructor
 */
global.Class = function() {};

/**
 * Creates a public member of a Class.
 *
 * @global
 * @param   member
 * @return  {Object}
 * @constructor
 */
global.Public = function Public(member) { return setVisibility(member); };

/**
 * Creates a private member of a Class.
 *
 * @global
 * @param   member
 * @return  {Object}
 * @constructor
 */
global.Private = function Private(member) { return setVisibility(member); };

/**
 * Creates a protected member of a Class.
 *
 * @global
 * @param   member
 * @return  {Object}
 * @constructor
 */
global.Protected = function Protected(member) { return setVisibility(member); };

/**
 * Creates a static member of a Class.
 *
 * @global
 * @param   member
 * @return  {Object}
 * @constructor
 */
global.Static = function Static(member) { return setStatic(member); };


/***************************************
 * INTERNALS
 *
 * The following code is not a part of the public API for Classical, and
 * should not be altered or exposed to external scripts.
 ***************************************/
var BaseClass                           = function BaseClass() {};

/**
 * Implements Classical inheritance by wrapping prototypal inheritance.
 *
 * @param   {Function}      fn
 * @param   {Object}        _super
 * @return  {ClassFactory}
 * @constructor
 * @global
 */
global.Class = function(fn, _super) {
    var member;
    _super                              = _super || {};

    // Create a copy of the SuperClass to set the prototype.
    initializing                        = true;
    var InheritedPrototype              = typeof this == 'function' ? this : BaseClass;
    var prototype                       = new InheritedPrototype;
    initializing                        = false;

    // Get a _preInstance.
    var _preInstance                    = new fn;
    var base                            = function() {};
    base.prototype                      = prototype;

    // Extend the _preInstance with the parent's members.
    for (member in _super) {
        if (member != 'constructor' && _super.hasOwnProperty(member)) {
            if ((_super[member]._visibility == 'Public' || _super[member]._visibility == 'Protected') && typeof _preInstance[member] == 'undefined') {
                _preInstance[member]    = _super[member];
            }
        }
    }

    // Add the _super to the _preInstance, for construction and this._super purposes.
    _preInstance._super                 = _super;

    // Set up the ClassFactory.  This is what actually gets instantiated.
    var ClassFactory = function() {
        var _instance                   = new base;
        var _public                     = new base;

        if (!initializing) {
            assemble(_instance, _instance, _public, _preInstance);
            construct(_instance, _instance, arguments);
        }

        return _public;
    };

    // Bind the ClassFactory to the prototype (for the inheritance chain).
    ClassFactory.prototype              = prototype;

    // Set up static methods.
    for (member in _preInstance) {
        if (_preInstance.hasOwnProperty(member)) {
            if (_preInstance[member]._static === true && _preInstance[member]._visibility == 'Public') {
                ClassFactory[member]    = copyValue(_preInstance[member]._value, ClassFactory);
            }
        }
    }

    // Setup a method to extend the base class.
    var extend                          = arguments.callee;
    ClassFactory.extend                 = function(newfn) {
        return extend.call(ClassFactory, newfn, _preInstance);
    };

    // Assembles the instance and its public accessors.
    var assemble = function(_context, _instance, _public, _preInstance) {
        var member;

        if (typeof _preInstance._super != 'undefined') {
            _instance._super            = new base;
            assemble(_context, _instance._super, {}, _preInstance._super);
        }

        for (member in _preInstance) {
            if (member != '_super' && _preInstance.hasOwnProperty(member)) {
                _instance[member]       = copyValue(_preInstance[member]._value, _context);

                if (_preInstance[member]._visibility == 'Public') {
                    _public[member]     = _instance[member];
                }
            }
        }
    };

    // Recursively calls the constructors for the class, starting with the ancestor
    // and working towards the instance.
    var construct = function(context, target, arguments) {
       // Call the SuperClass constructors first.
       if(target._super instanceof BaseClass && target._super._super instanceof BaseClass) {
           construct(context, target._super, arguments);
{'fraction_non_alphanumeric': 0.11605611847233048, 'fraction_numerical': 0.003117692907248636, 'mean_word_length': 2.144082332761578, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4348529', 'n_tokens_mistral': 3472, 'n_tokens_neox': 3299, 'n_words': 1087}