MCPcopy Index your code
hub / github.com/gpujs/gpu.js / astLiteral

Method astLiteral

src/backend/web-gl/function-node.js:217–246  ·  view source on GitHub ↗

* @desc Parses the abstract syntax tree for *literal value* * * @param {Object} ast - the AST object to parse * @param {Array} retArr - return array string * * @returns {Array} the append retArr

(ast, retArr)

Source from the content-addressed store, hash-verified

215 * @returns {Array} the append retArr
216 */
217 astLiteral(ast, retArr) {
218 // Reject non numeric literals
219 if (isNaN(ast.value)) {
220 throw this.astErrorOutput(
221 'Non-numeric literal not supported : ' + ast.value,
222 ast
223 );
224 }
225
226 const key = this.astKey(ast);
227 if (Number.isInteger(ast.value)) {
228 if (this.isState('casting-to-integer') || this.isState('building-integer')) {
229 this.literalTypes[key] = 'Integer';
230 retArr.push(`${ast.value}`);
231 } else if (this.isState('casting-to-float') || this.isState('building-float')) {
232 this.literalTypes[key] = 'Number';
233 retArr.push(`${ast.value}.0`);
234 } else {
235 this.literalTypes[key] = 'Number';
236 retArr.push(`${ast.value}.0`);
237 }
238 } else if (this.isState('casting-to-integer') || this.isState('building-integer')) {
239 this.literalTypes[key] = 'Integer';
240 retArr.push(Math.round(ast.value));
241 } else {
242 this.literalTypes[key] = 'Number';
243 retArr.push(`${ast.value}`);
244 }
245 return retArr;
246 }
247
248 /**
249 * @desc Parses the abstract syntax tree for *binary* expression

Callers

nothing calls this directly

Calls 3

astErrorOutputMethod · 0.80
astKeyMethod · 0.80
isStateMethod · 0.45

Tested by

no test coverage detected