Skip to content

Commit 5f76154

Browse files
committed
Updated functionNode documentation
1 parent de3ee5e commit 5f76154

3 files changed

Lines changed: 83 additions & 48 deletions

File tree

src/backend/functionBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///
2-
/// Class: functionBuilder
2+
/// @class functionBuilder
33
///
44
/// Provides a functionBuilder class, that helps "build" the various voodoo code, from JS code.
55
/// This handles a collection of functionNodes.

src/backend/functionNode.js

Lines changed: 81 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
///
2-
/// @class functionNode
2+
/// Class: functionNode
33
///
4-
/// Represents a single function, inside JS, webGL, or openGL.
5-
/// This handles the raw state, converted state, etc.
4+
/// [INTERNAL] Represents a single function, inside JS, webGL, or openGL.
5+
///
6+
/// This handles all the raw state, converted state, etc. Of a single function.
67
///
7-
/// # JS Related properties
8-
///
9-
/// @property {JS Function} jsFunction The JS Function the node represents
10-
/// @property {String} jsFunctionString jsFunction.toString()
11-
/// @property {[String,...]} paramNames Parameter names of the function
12-
/// @property {[String,...]} paramType Shader land parameter type assumption
13-
/// @property {Boolean} isRootKernal Special indicator, for kernal function
14-
///
15-
/// # Webgl related properties
16-
///
17-
/// @property {String} webglFunctionString webgl converted function string
18-
///
19-
/// # Code analysis properties (after converting to webgl)
20-
///
21-
/// @property {[String,...]} calledFunctions List of all the functions called
22-
/// @property {[String,...]} initVariables List of variables initialized in the function
23-
/// @property {[String,...]} readVariables List of variables read operations occur
24-
/// @property {[String,...]} writeVariables List of variables write operations occur
8+
/// Properties:
9+
/// jsFunction - {JS Function} The JS Function the node represents
10+
/// jsFunctionString - {String} jsFunction.toString()
11+
/// paramNames - {[String,...]} Parameter names of the function
12+
/// paramType - {[String,...]} Shader land parameter type assumption
13+
/// isRootKernal - {Boolean} Special indicator, for kernal function
14+
/// webglFunctionString - {String} webgl converted function string
15+
/// openglFunctionString - {String} opengl converted function string
16+
/// calledFunctions - {[String,...]} List of all the functions called
17+
/// initVariables - {[String,...]} List of variables initialized in the function
18+
/// readVariables - {[String,...]} List of variables read operations occur
19+
/// writeVariables - {[String,...]} List of variables write operations occur
2520
///
2621
var functionNode = (function() {
2722

@@ -30,15 +25,15 @@ var functionNode = (function() {
3025
//----------------------------------------------------------------------------------------------------
3126

3227
///
33-
/// @function functionNode
28+
/// Function: functionNode
3429
///
35-
/// [Constructor] Builds the function with the given JS function, and argument type array.
36-
/// If argument types are not provided, they are assumed to be "float*"
30+
/// [Constructor] Builds the function with the given JS function, and argument type array.
3731
///
38-
/// @param {String} Function name to assume, if its null, it attempts to extract from the function
39-
/// @param {JS Function} JS Function to do conversion
40-
/// @param {[String,...]} Parameter type array, assumes "float" if not given
41-
/// @param {String} The return type, assumes float
32+
/// Parameters:
33+
/// functionName - {String} -Function name to assume, if its null, it attempts to extract from the function
34+
/// jsFunction - {JS Function} JS Function to do conversion
35+
/// paramTypeArray - {[String,...]} Parameter type array, assumes all parameters are "float" if not given
36+
/// returnType - {String} The return type, assumes "float" if not given
4237
///
4338
function functionNode( functionName, jsFunction, paramTypeArray, returnType ) {
4439

@@ -101,22 +96,34 @@ var functionNode = (function() {
10196
//----------------------------------------------------------------------------------------------------
10297

10398
///
104-
/// @function isFunction
99+
/// Function: isFunction
100+
///
101+
/// [static] Return TRUE, on a JS function
105102
///
106-
/// @param {JS Function} Object to validate if its a function
103+
/// This is 'static' function, not a class function (functionNode.prototype)
107104
///
108-
/// @return {Boolean} TRUE if the object is a JS function
105+
/// Parameters:
106+
/// funcObj - {JS Function} Object to validate if its a function
107+
///
108+
/// Returns:
109+
/// {Boolean} TRUE if the object is a JS function
109110
///
110111
function isFunction( funcObj ) {
111112
return typeof(funcObj) === 'function';
112113
}
113114

114115
///
115-
/// @function validateStringIsFunction
116+
/// Function: validateStringIsFunction
117+
///
118+
/// [static] Return TRUE, on a valid JS function string
119+
///
120+
/// This is 'static' function, not a class function (functionNode.prototype)
116121
///
117-
/// @param {String} String of JS function to validate
122+
/// Parameters:
123+
/// funcStr - {String} String of JS function to validate
118124
///
119-
/// @return {Boolean} TRUE if the string passes basic validation
125+
/// Returns:
126+
/// {Boolean} TRUE if the string passes basic validation
120127
///
121128
function validateStringIsFunction( funcStr ) {
122129
if( funcStr !== null ) {
@@ -129,11 +136,17 @@ var functionNode = (function() {
129136
var ARGUMENT_NAMES = /([^\s,]+)/g;
130137

131138
///
132-
/// @function getParamNames
139+
/// Function: getParamNames
133140
///
134-
/// @param {String} String of JS function to extract parameter names
135-
///
136-
/// @return {[String, ...]} Array representing all the parameter names
141+
/// [static] Return list of parameter names extracted from the JS function string
142+
///
143+
/// This is 'static' function, not a class function (functionNode.prototype)
144+
///
145+
/// Parameters:
146+
/// funcStr - {String} String of JS function to validate
147+
///
148+
/// Returns:
149+
/// {[String, ...]} Array representing all the parameter names
137150
///
138151
function getParamNames(func) {
139152
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
@@ -145,20 +158,26 @@ var functionNode = (function() {
145158

146159
// Passing it to the class object, in case it is needed elsewhere
147160
// Note, support for this is not guranteed across versions.
148-
functionNode._isFunction = isFunction;
149-
functionNode._validateStringIsFunction = validateStringIsFunction;
150-
functionNode._getParamNames = getParamNames;
161+
functionNode.isFunction = isFunction;
162+
functionNode.validateStringIsFunction = validateStringIsFunction;
163+
functionNode.getParamNames = getParamNames;
151164

152165
//
153166
// Core function
154167
//----------------------------------------------------------------------------------------------------
155168

156169
///
157-
/// @function functionNode.getJS_AST
170+
/// Function: getJS_AST
171+
///
172+
/// Parses the class function JS, and returns its Abstract Syntax Tree object.
173+
///
174+
/// This is used internally to convert to shader code
158175
///
159-
/// @param {JISON Parser} Parser to use, assumes in scope "parser" if null
176+
/// Parameters:
177+
/// inParser - {JISON Parser} Parser to use, assumes in scope "parser" if null
160178
///
161-
/// @return {AST Object} The function AST Object, note that result is cached under this.jsFunctionAST;
179+
/// Returns:
180+
/// {AST Object} The function AST Object, note that result is cached under this.jsFunctionAST;
162181
///
163182
functionNode.prototype.getJS_AST = function getJS_AST( inParser ) {
164183
if( this.jsFunctionAST ) {
@@ -183,9 +202,12 @@ var functionNode = (function() {
183202
}
184203

185204
///
186-
/// @function functionNode.getWebglString
205+
/// Function: getWebglString
187206
///
188-
/// @return {String} webgl function string, result is cached under this.webglFunctionString
207+
/// Returns the converted webgl shader function equivalent of the JS function
208+
///
209+
/// Returns:
210+
/// {String} webgl function string, result is cached under this.webglFunctionString
189211
///
190212
functionNode.prototype.getWebglFunctionString = function getWebglFunctionString() {
191213
if( this.webglFunctionString ) {
@@ -195,5 +217,18 @@ var functionNode = (function() {
195217
return this.webglFunctionString = functionNode_webgl(this);
196218
}
197219

220+
///
221+
/// Function: setWebglString
222+
///
223+
/// Set the webglFunctionString value, overwriting it
224+
///
225+
/// Parameters:
226+
/// shaderCode - {String} Shader code string, representing the function
227+
///
228+
functionNode.prototype.getWebglFunctionString = function getWebglFunctionString(shaderCode) {
229+
this.webglFunctionString = shaderCode;
230+
}
231+
232+
198233
return functionNode;
199234
})();

test/src/internal/functionNode_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ QUnit.test( "Math.round implementation: A function with arguments", function( as
7373

7474
/// Test creation of function, that calls another function, with ARGS
7575
QUnit.test( "Two arguments test", function( assert ) {
76-
// Math.round node
76+
7777
var node = new functionNode(
7878
"add_together",
7979
function(a,b) {

0 commit comments

Comments
 (0)