<commit_before>/*global define, console */
/*
    PumaScript main source code
 */
define([
    'escodegen',
    'esprima',
    '../src/global',
    '../src/state',
    '../src/symbols/symbol',
    '../src/symbols/function-symbol',
    '../src/symbols/property-wrapper',
    '../src/prune-pass'
], function (escodegen, esprima, Global, State, Symbol, FunctionSymbol, PropertyWrapper, PrunePass) {

    'use strict';

    /**
     * @constructor
     */
    function Result(success, value) {
        this.success = success;
        this.value = value;
    }

    Result.prototype.failed = function () {
        return this.success !== true;
    };

    Result.prototype.makeValue = function () {
        if (this.value instanceof Symbol) {
            this.value = this.value.value;
        }
    };

    Result.prototype.isReturnResult = function () {
        return this._isReturnResult === true;
    };

    Result.prototype.setIsReturnResult = function (value) {
        this._isReturnResult = value;
    };

    /**
     * @constructor
     */
    function FirstPass(programAst) {
        this._metaComments = [];
        this._lastStatementLoc = {
            "line": 0,
            "column": 0
        };
        this._programAst = programAst;
    }

    var defaultResult = new Result(false, null);
    var emptyResult = new Result(true, null);

    FirstPass.prototype.acceptArray = function (arrayNodes, state) {
        var result = defaultResult,
            i;
        for (i = 0; i < arrayNodes.length; i++) {
            result = this.accept(arrayNodes[i], state);
            if (result.isReturnResult()) break;
        }
        return result;
    };

    FirstPass.prototype.run = function (state) {
        return this.accept(this._programAst, state);
    };

    FirstPass.prototype.accept = function (ast, state) {
        if (ast === undefined || ast === null) throw "invalid call to accept with null ast.";

        var nodeType = ast.type;
        var result = defaultResult;

        // TODO order alphabetically
        switch (nodeType) {
        case "Program":
            result = this.visitProgram(ast, state);
            break;
        case "ExpressionStatement":
            result = this.accept(ast.expression, state);
            break;
        case "BinaryExpression":
            result = this.visitBinaryExpression(ast, state);
            break;
        case "AssignmentExpression":
            result = this.visitAssignmentExpression(ast, state);
            break;
        case "VariableDeclaration":
            result = this.visitVariableDeclaration(ast, state);
            break;
        case "VariableDeclarator":
            result = this.visitVariableDeclarator(ast, state);
            break;
        case "CallExpression":
            result = this.visitCallExpression(ast, state);
            break;
        case "MemberExpression":
            result = this.visitMemberExpression(ast, state);
            break;
        case "FunctionExpression":
            result = this.visitFunctionExpression(ast, state);
            break;
        case "FunctionDeclaration":
            result = this.visitFunctionDeclaration(ast, state);
            break;
        case "BlockStatement":
            result = this.visitBlockStatement(ast, state);
            break;
        case "Identifier":
            result = this.visitIdentifier(ast, state);
            break;
        case "Literal":
            result = this.visitLiteral(ast, state);
            break;
        case "UnaryExpression":
            result = this.visitUnaryExpression(ast, state);
            break;
        case "IfStatement":
            result = this.visitIfStatement(ast, state);
            break;
        case "ForStatement":
            result = this.visitForStatement(ast, state);
            break;
        case "ReturnStatement":
            result = this.visitReturnStatement(ast, state);
            break;
        case "Block":
            result = this.visitComment(ast, state);
            break;
        case "UpdateExpression":
            result = this.visitUpdateExpression(ast, state);
            break;
        case "WhileStatement":
            result = this.visitWhileStatement(ast, state);
            break;
        case "ObjectExpression":
            result = this.visitObjectExpression(ast, state);
            break;
        case "ArrayExpression":
            result = this.visitArrayExpression(ast, state);
            break;
        case "LogicalExpression":
            result = this.visitLogicalExpression(ast, state);
            break;
        case "ThisExpression":
            result = this.visitThisExpression(ast, state);
            break;
        case "NewExpression":
            result = this.visitNewExpression(ast, state);
            break;
        }

        this._lastStatementLoc = ast.loc.end;
        return result;
    };

    FirstPass.prototype.visitObjectExpression = function (ast, state) {
        var propertiesCount = ast.properties.length;
        var propertiesAst = ast.properties;
        var resultValue = {};
        for (var i = 0; i < propertiesCount; i++) {
            var propertyAst = propertiesAst[i];
            var propertyName;
            if (propertyAst.key.type === "Literal") {
                propertyName = propertyAst.key.value;
            } else if (propertyAst.key.type === "Identifier") {
                propertyName = propertyAst.key.name;
            } else {
                console.warn(loc(propertyAst) + "Error executing object expression. Property name not found!");
            }<commit_msg>Ordered the visitor list in accept() and added a list of missing visitors<commit_after>/*global define, console */
/*
    PumaScript main source code
 */
define([
    'escodegen',
    'esprima',
    '../src/global',
    '../src/state',
    '../src/symbols/symbol',
    '../src/symbols/function-symbol',
    '../src/symbols/property-wrapper',
    '../src/prune-pass'
], function (escodegen, esprima, Global, State, Symbol, FunctionSymbol, PropertyWrapper, PrunePass) {

    'use strict';

    /**
     * @constructor
     */
    function Result(success, value) {
        this.success = success;
        this.value = value;
    }

    Result.prototype.failed = function () {
        return this.success !== true;
    };

    Result.prototype.makeValue = function () {
        if (this.value instanceof Symbol) {
            this.value = this.value.value;
        }
    };

    Result.prototype.isReturnResult = function () {
        return this._isReturnResult === true;
    };

    Result.prototype.setIsReturnResult = function (value) {
        this._isReturnResult = value;
    };

    /**
     * @constructor
     */
    function FirstPass(programAst) {
        this._metaComments = [];
        this._lastStatementLoc = {
            "line": 0,
            "column": 0
        };
        this._programAst = programAst;
    }

    var defaultResult = new Result(false, null);
    var emptyResult = new Result(true, null);

    FirstPass.prototype.acceptArray = function (arrayNodes, state) {
        var result = defaultResult,
            i;
        for (i = 0; i < arrayNodes.length; i++) {
            result = this.accept(arrayNodes[i], state);
            if (result.isReturnResult()) break;
        }
        return result;
    };

    FirstPass.prototype.run = function (state) {
        return this.accept(this._programAst, state);
    };

    FirstPass.prototype.accept = function (ast, state) {
        if (ast === undefined || ast === null) throw "invalid call to accept with null ast.";

        var nodeType = ast.type;
        var result = defaultResult;

        switch (nodeType) {
        case "ArrayExpression":
            result = this.visitArrayExpression(ast, state);
            break;
        case "AssignmentExpression":
            result = this.visitAssignmentExpression(ast, state);
            break;
        case "BinaryExpression":
            result = this.visitBinaryExpression(ast, state);
            break;
        case "Block":
            result = this.visitComment(ast, state);
            break;
        case "BlockStatement":
            result = this.visitBlockStatement(ast, state);
            break;
        case "CallExpression":
            result = this.visitCallExpression(ast, state);
            break;
        case "ExpressionStatement":
            result = this.accept(ast.expression, state);
            break;
        case "ForStatement":
            result = this.visitForStatement(ast, state);
            break;
        case "FunctionDeclaration":
            result = this.visitFunctionDeclaration(ast, state);
            break;
        case "FunctionExpression":
            result = this.visitFunctionExpression(ast, state);
            break;    
        case "Identifier":
            result = this.visitIdentifier(ast, state);
            break;
        case "IfStatement":
            result = this.visitIfStatement(ast, state);
            break;
        case "Literal":
            result = this.visitLiteral(ast, state);
            break;
        case "LogicalExpression":
            result = this.visitLogicalExpression(ast, state);
            break;
        case "MemberExpression":
            result = this.visitMemberExpression(ast, state);
            break;
        case "NewExpression":
            result = this.visitNewExpression(ast, state);
            break;
        case "ObjectExpression":
            result = this.visitObjectExpression(ast, state);
            break; 
        case "Program":
            result = this.visitProgram(ast, state);
            break;
        case "ReturnStatement":
            result = this.visitReturnStatement(ast, state);
            break;
        case "ThisExpression":
            result = this.visitThisExpression(ast, state);
            break;
        case "UnaryExpression":
            result = this.visitUnaryExpression(ast, state);
            break;
        case "UpdateExpression":
            result = this.visitUpdateExpression(ast, state);
            break;
        case "VariableDeclaration":
            result = this.visitVariableDeclaration(ast, state);
            break;
        case "VariableDeclarator":
            result = this.visitVariableDeclarator(ast, state);
            break;
        case "WhileStatement":
            result = this.visitWhileStatement(ast, state);
            break;
        case Default:
            console.log("nos supported type by Puma visitor")
            break;
        /*20
        case "EmptyStatement":
            result = this.visitEmptyStatement(ast, state);
            break;
        case "LabeledStatement":
            result = this.visitLabeledStatement(ast, state);
            break;
        case "BreakStatement":
            result = this.visitBreakStatement(ast, state);
            break;
        case "ContinueStatement":
            result = this.visitContinueStatement(ast, state);
            break;
        case "WithStatement":
            result = this.visitWithStatement(ast, state);
            break;
        case "SwitchStatement":
            result = this.visitSwitchStatement(ast, state);
            break;
        case "SwitchCase":
            result = this.visitSwitchCase(ast, state);
            break;
        case "ThrowStatement":
            result = this.visitThrowStatement(ast, state);
            break;
        case "TryStatement":
            result = this.visitTryStatement(ast, state);
            break;
        case "CatchClause":
            result = this.visitCatchClause(ast, state);
            break;
        case "ForInStatement":
            result = this.visitForInStatement(ast, state);
            break;
        case "Property":
            result = this.visitProperty(ast, state);
            break;
        case "UnaryOperator":
            result = this.visitUnaryOperator(ast, state);
            break;
        case "UpdateExpression":
            result = this.visitUpdateExpression(ast, state);
            break;
        case "UpdateOperator":
            result = this.visitUpdateOperator(ast, state);
            break;
        case "BinaryOperator":
            result = this.visitBinaryOperator(ast, state);
            break;
        case "AssignmentOperator":
            result = this.visitAssignmentOperator(ast, state);
            break;
        case "LogicalOperator":
            result = this.visitLogicalOperator(ast, state);
            break;
        case "ConditionalExpression":
            result = this.visitConditionalExpression(ast, state);
            break;
        case "SequenceExpression":
            result = this.visitSequenceExpression(ast, state);
            break;
        case "LetStatement":
            result = this.visitLetStatement(ast, state);
            break;
        case "DebuggerStatement":
            result = this.visitDebuggerStatement(ast, state);
            break;
        case "ArrowExpression":
            result = this.visitArrowExpression(ast, state);
            break;
        case "SequenceExpression":
            result = this.visitSequenceExpression(ast, state);
            break;
        case "YieldExpression":
            result = this.visitYieldExpression(ast, state);
            break;
        case "ComprehensionExpression":
            result = this.visitComprehensionExpression(ast, state);
            break;
        case "GeneratorExpression":
            result = this.visitGeneratorExpression(ast, state);
            break;
        case "GraphExpression":
            result = this.visitGraphExpression(ast, state);
            break;
        case "GraphIndexExpression":
            result = this.visitGraphIndexExpression(ast, state);
            break;
            
        Some operators are missing but most of them aren't needed
        */
        }

        this._lastStatementLoc = ast.loc.end;
        return result;
    };

    FirstPass.prototype.visitObjectExpression = function (ast, state) {
        var propertiesCount = ast.properties.length;
        var propertiesAst = ast.properties;
        var resultValue = {};
        for (var i = 0; i < propertiesCount; i++) {
            var propertyAst = propertiesAst[i];
            var propertyName;
            if (propertyAst.key.type === "Literal") {
                propertyName = propertyAst.key.value;
            } else if (propertyAst.key.type === "Identifier") {
                propertyName = propertyAst.key.name;
            } else {
                console.warn(loc(propertyAst) + "Error executing object expression. Property name not found!");
            }
{'fraction_non_alphanumeric': 0.10427315477407482, 'fraction_numerical': 0.0006815238874122538, 'mean_word_length': 1.8454527826255576, 'pattern_counts': {'":': 83, '<': 7, '<?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': '5954214', 'n_tokens_mistral': 3659, 'n_tokens_neox': 3610, 'n_words': 871}