/// /// @class functionNode /// /// Represents a single function, inside JS, webGL, or openGL. /// This handles the raw state, converted state, etc. /// /// # JS Related properties /// /// @property {JS Function} jsFunction The JS Function the node represents /// @property {String} jsFunctionString jsFunction.toString() /// @property {[String,...]} paramNames Parameter names of the function /// @property {[String,...]} paramType Shader land parameter type assumption /// @property {Boolean} isRootKernal Special indicator, for kernal function /// /// # Webgl related properties /// /// @property {String} webglFunctionString webgl converted function string /// /// # Code analysis properties (after converting to webgl) /// /// @property {[String,...]} calledFunctions List of all the functions called /// @property {[String,...]} initVariables List of variables initialized in the function /// @property {[String,...]} readVariables List of variables read operations occur /// @property {[String,...]} writeVariables List of variables write operations occur /// var functionNode = (function() { // // Constructor //---------------------------------------------------------------------------------------------------- /// /// @function functionNode /// /// [Constructor] Builds the function with the given JS function, and argument type array. /// If argument types are not provided, they are assumed to be "float*" /// /// @param {String} Function name to assume, if its null, it attempts to extract from the function /// @param {JS Function} JS Function to do conversion /// @param {[String,...]} Parameter type array, assumes "float" if not given /// @param {String} The return type, assumes float /// function functionNode( functionName, jsFunction, paramTypeArray, returnType ) { // // Internal vars setup // this.calledFunctions = []; this.initVariables = []; this.readVariables = []; this.writeVariables = []; // // Setup jsFunction and its string property + validate them // this.jsFunction = jsFunction; if( !isFunction(this.jsFunction) ) { throw "jsFunction, is not a valid JS Function"; } this.jsFunctionString = jsFunction.toString(); if( !validateStringIsFunction(this.jsFunctionString) ) { throw "jsFunction, to string conversion falied"; } // // Setup the function name property // this.functionName = functionName || jsFunction.name; if( !(this.functionName) ) { throw "jsFunction, missing name argument or value"; } // // Extract parameter name, and its argument types // this.paramNames = getParamNames(this.jsFunctionString); if( paramTypeArray != null ) { if( paramTypeArray.length != this.paramNames.length ) { throw "Invalid argument type array length, against function length -> ("+ paramTypeArray.length+","+ this.paramNames.length+ ")"; } this.paramType = paramTypeArray; } else { this.paramType = []; for(var a=0; a