/// /// Class: functionNode /// /// [INTERNAL] Represents a single function, inside JS, webGL, or openGL. /// /// This handles all the raw state, converted state, etc. Of a single function. /// /// Properties: /// functionName - {String} Name of the function /// jsFunction - {JS Function} The JS Function the node represents /// jsFunctionString - {String} jsFunction.toString() /// paramNames - {[String,...]} Parameter names of the function /// paramType - {[String,...]} Shader land parameter type assumption /// isRootKernal - {Boolean} Special indicator, for kernal function /// webglFunctionString - {String} webgl converted function string /// openglFunctionString - {String} opengl converted function string /// calledFunctions - {[String,...]} List of all the functions called /// initVariables - {[String,...]} List of variables initialized in the function /// readVariables - {[String,...]} List of variables read operations occur /// writeVariables - {[String,...]} 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. /// /// Parameters: /// functionName - {String} Function name to assume, if its null, it attempts to extract from the function /// jsFunction - {JS Function} JS Function to do conversion /// paramTypeArray - {[String,...]} Parameter type array, assumes all parameters are "float" if null /// returnType - {String} The return type, assumes "float" if null /// 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