src/js/instrument/astUtil.js
function computeTopLevelExpressions(ast) {
        var exprDepth = 0;
        var exprDepthStack = [];
        var topLevelExprs = [];
        var visitorIdentifyTopLevelExprPre = {
            "CallExpression":function (node) {
                if (node.callee.type === 'MemberExpression' &&
                    node.callee.object.type === 'Identifier' &&
                    node.callee.object.name === JALANGI_VAR) {
                    var funName = node.callee.property.name;
                    if ((exprDepth === 0 &&
                        (funName === 'A' ||
                            funName === 'P' ||
                            funName === 'G' ||
                            funName === 'R' ||
                            funName === 'W' ||
                            funName === 'H' ||
                            funName === 'T' ||
                            funName === 'Rt' ||
                            funName === 'B' ||
                            funName === 'U' ||
                            funName === 'C' ||
                            funName === 'C1' ||
                            funName === 'C2'
                            )) ||
                        (exprDepth === 1 &&
                            (funName === 'F' ||
                                funName === 'M'))) {
                        topLevelExprs.push(node.arguments[0].value);
                    }
                    exprDepth++;
                } else if (node.callee.type === 'CallExpression' &&
                    node.callee.callee.type === 'MemberExpression' &&
                    node.callee.callee.object.type === 'Identifier' &&
                    node.callee.callee.object.name === JALANGI_VAR &&
                    (node.callee.callee.property.name === 'F' ||
                        node.callee.callee.property.name === 'M')) {
                    exprDepth++;
                }
            },
            "FunctionExpression":function (node, context) {
                exprDepthStack.push(exprDepth);
                exprDepth = 0;
            },
            "FunctionDeclaration":function (node) {
                exprDepthStack.push(exprDepth);
                exprDepth = 0;
            }

        };

        var visitorIdentifyTopLevelExprPost = {
            "CallExpression":function (node) {
                if (node.callee.type === 'MemberExpression' &&
                    node.callee.object.type === 'Identifier' &&
                    node.callee.object.name === JALANGI_VAR) {
                    exprDepth--;
                } else if (node.callee.type === 'CallExpression' &&
                    node.callee.callee.type === 'MemberExpression' &&
                    node.callee.callee.object.type === 'Identifier' &&
                    node.callee.callee.object.name === JALANGI_VAR &&
                    (node.callee.callee.property.name === 'F' ||
                        node.callee.callee.property.name === 'M')) {
                    exprDepth--;
                }
                return node;
            },
            "FunctionExpression":function (node, context) {
                exprDepth = exprDepthStack.pop();
                return node;
            },
            "FunctionDeclaration":function (node) {
                exprDepth = exprDepthStack.pop();
                return node;
            }
        };
        transformAst(ast, visitorIdentifyTopLevelExprPost, visitorIdentifyTopLevelExprPre, CONTEXT.RHS);
        return topLevelExprs;
    }
function computeTopLevelExpressions(ast) {
        var exprDepth = 0;
        var exprDepthStack = [];
        var topLevelExprs = [];
        var visitorIdentifyTopLevelExprPre = {
            "CallExpression":function (node) {
                if (node.callee.type === 'MemberExpression' &&
                    node.callee.object.type === 'Identifier' &&
                    node.callee.object.name === JALANGI_VAR) {
                    var funName = node.callee.property.name;
                    if ((exprDepth === 0 &&
                        (funName === 'A' ||
                            funName === 'P' ||
                            funName === 'G' ||
                            funName === 'R' ||
                            funName === 'W' ||
                            funName === 'H' ||
                            funName === 'T' ||
                            funName === 'Rt' ||
                            funName === 'B' ||
                            funName === 'U' ||
                            funName === 'C' ||
                            funName === 'C1' ||
                            funName === 'C2'
                            )) ||
                        (exprDepth === 1 &&
                            (funName === 'F' ||
                                funName === 'M'))) {
                        topLevelExprs.push(node.arguments[0].value);
                    }
                    exprDepth++;
                } else if (node.callee.type === 'CallExpression' &&
                    node.callee.callee.type === 'MemberExpression' &&
                    node.callee.callee.object.type === 'Identifier' &&
                    node.callee.callee.object.name === JALANGI_VAR &&
                    (node.callee.callee.property.name === 'F' ||
                        node.callee.callee.property.name === 'M')) {
                    exprDepth++;
                }
            },
            "FunctionExpression":function (node, context) {
                exprDepthStack.push(exprDepth);
                exprDepth = 0;
            },
            "FunctionDeclaration":function (node) {
                exprDepthStack.push(exprDepth);
                exprDepth = 0;
            }

        };

        var visitorIdentifyTopLevelExprPost = {
            "CallExpression":function (node) {
                if (node.callee.type === 'MemberExpression' &&
                    node.callee.object.type === 'Identifier' &&
                    node.callee.object.name === JALANGI_VAR) {
                    exprDepth--;
                } else if (node.callee.type === 'CallExpression' &&
                    node.callee.callee.type === 'MemberExpression' &&
                    node.callee.callee.object.type === 'Identifier' &&
                    node.callee.callee.object.name === JALANGI_VAR &&
                    (node.callee.callee.property.name === 'F' ||
                        node.callee.callee.property.name === 'M')) {
                    exprDepth--;
                }
                return node;
            },
            "FunctionExpression":function (node, context) {
                exprDepth = exprDepthStack.pop();
                return node;
            },
            "FunctionDeclaration":function (node) {
                exprDepth = exprDepthStack.pop();
                return node;
            }
        };
        transformAst(ast, visitorIdentifyTopLevelExprPost, visitorIdentifyTopLevelExprPre, CONTEXT.RHS);
        return topLevelExprs;
    }
function computeTopLevelExpressions ( ast ) { var exprDepth = 0 ; var exprDepthStack = [ ] ; var topLevelExprs = [ ] ; var visitorIdentifyTopLevelExprPre = { "CallExpression" : function ( node ) { if ( node . callee . type === 'MemberExpression' && node . callee . object . type === 'Identifier' && node . callee . object . name === JALANGI_VAR ) { var funName = node . callee . property . name ; if ( ( exprDepth === 0 && ( funName === 'A' || funName === 'P' || funName === 'G' || funName === 'R' || funName === 'W' || funName === 'H' || funName === 'T' || funName === 'Rt' || funName === 'B' || funName === 'U' || funName === 'C' || funName === 'C1' || funName === 'C2' ) ) || ( exprDepth === 1 && ( funName === 'F' || funName === 'M' ) ) ) { topLevelExprs . push ( node . arguments [ 0 ] . value ) ; } exprDepth ++ ; } else if ( node . callee . type === 'CallExpression' && node . callee . callee . type === 'MemberExpression' && node . callee . callee . object . type === 'Identifier' && node . callee . callee . object . name === JALANGI_VAR && ( node . callee . callee . property . name === 'F' || node . callee . callee . property . name === 'M' ) ) { exprDepth ++ ; } } , "FunctionExpression" : function ( node , context ) { exprDepthStack . push ( exprDepth ) ; exprDepth = 0 ; } , "FunctionDeclaration" : function ( node ) { exprDepthStack . push ( exprDepth ) ; exprDepth = 0 ; } } ; var visitorIdentifyTopLevelExprPost = { "CallExpression" : function ( node ) { if ( node . callee . type === 'MemberExpression' && node . callee . object . type === 'Identifier' && node . callee . object . name === JALANGI_VAR ) { exprDepth -- ; } else if ( node . callee . type === 'CallExpression' && node . callee . callee . type === 'MemberExpression' && node . callee . callee . object . type === 'Identifier' && node . callee . callee . object . name === JALANGI_VAR && ( node . callee . callee . property . name === 'F' || node . callee . callee . property . name === 'M' ) ) { exprDepth -- ; } return node ; } , "FunctionExpression" : function ( node , context ) { exprDepth = exprDepthStack . pop ( ) ; return node ; } , "FunctionDeclaration" : function ( node ) { exprDepth = exprDepthStack . pop ( ) ; return node ; } } ; transformAst ( ast , visitorIdentifyTopLevelExprPost , visitorIdentifyTopLevelExprPre , CONTEXT . RHS ) ; return topLevelExprs ; }
given an instrumented AST, returns an array of IIDs corresponding to "top-level expressions,"
i.e., expressions that are not nested within another
@param ast
given an instrumented AST returns an array of IIDs corresponding to top - level expressions i . e . expressions that are not nested within another