UNPKG

@alu0101051420/constant-folding

Version:
1,239 lines (319 loc) 12.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Global</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Global</h1> <section> <header> <h2></h2> </header> <article> <div class="container-overview"> <dl class="details"> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="arrayConstantFolding"><span class="type-signature"></span>arrayConstantFolding<span class="signature">(code, args)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Does constant folding on Array operations. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>code</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">an AST node containing the expression statement</td> </tr> <tr> <td class="name"><code>args</code></td> <td class="type"> <span class="param-type">Array</span> </td> <td class="description last">arguments used on the function call. I.E. for [1].concat('d', 'e'), args = ['d', 'e']</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="constant-folding.js.html">constant-folding.js</a>, <a href="constant-folding.js.html#line72">line 72</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> the resulting js code to be used by escodegen </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="binaryConstantFolding"><span class="type-signature"></span>binaryConstantFolding<span class="signature">(n)</span><span class="type-signature"></span></h4> <div class="description"> Does ConstantFolding on binaryExpression nodes. I.E. turns 2+3 into 5. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>n</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">an AST node representing a binaryExpression.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="constant-folding.js.html">constant-folding.js</a>, <a href="constant-folding.js.html#line56">line 56</a> </li></ul></dd> </dl> <h4 class="name" id="constantFolding"><span class="type-signature"></span>constantFolding<span class="signature">(code)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> A function that does constant folding onto the code it receives </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>code</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">A string containing the code to do the constant folding on</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="constant-folding.js.html">constant-folding.js</a>, <a href="constant-folding.js.html#line15">line 15</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Returns the resulting code </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="getValue"><span class="type-signature"></span>getValue<span class="signature">(node)</span><span class="type-signature"> &rarr; {*}</span></h4> <div class="description"> Extracts the "value" of an AST node, it being its id, raw value, or array of elements </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>node</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line42">line 42</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> the value contained in the node </div> <dl> <dt> Type </dt> <dd> <span class="param-type">*</span> </dd> </dl> <h4 class="name" id="isConstant"><span class="type-signature"></span>isConstant<span class="signature">(code)</span><span class="type-signature"> &rarr; {bool}</span></h4> <div class="description"> Checks if an AST node's info is of constant nature </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>code</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">to be checked</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line29">line 29</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">bool</span> </dd> </dl> <h4 class="name" id="newArrayNode"><span class="type-signature"></span>newArrayNode<span class="signature">(array)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> Translates a js Array into an AST node containing its information </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>array</code></td> <td class="type"> <span class="param-type">Array</span> </td> <td class="description last">to be translated</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line17">line 17</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> the resulting AST node </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="newNode"><span class="type-signature"></span>newNode<span class="signature">(literal)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> Creates a new AST node containing the info received </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>literal</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">to be assigned as value of the node</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line8">line 8</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> the resulting AST node </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#arrayConstantFolding">arrayConstantFolding</a></li><li><a href="global.html#binaryConstantFolding">binaryConstantFolding</a></li><li><a href="global.html#constantFolding">constantFolding</a></li><li><a href="global.html#getValue">getValue</a></li><li><a href="global.html#isConstant">isConstant</a></li><li><a href="global.html#newArrayNode">newArrayNode</a></li><li><a href="global.html#newNode">newNode</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Thu Mar 10 2022 14:45:42 GMT+0000 (Western European Standard Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>