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

Method astBinaryExpression

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

* @desc Parses the abstract syntax tree for *binary* expression * @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

252 * @returns {Array} the append retArr
253 */
254 astBinaryExpression(ast, retArr) {
255 if (this.checkAndUpconvertOperator(ast, retArr)) {
256 return retArr;
257 }
258
259 if (this.fixIntegerDivisionAccuracy && ast.operator === '/') {
260 retArr.push('divWithIntCheck(');
261 this.pushState('building-float');
262 switch (this.getType(ast.left)) {
263 case 'Integer':
264 this.castValueToFloat(ast.left, retArr);
265 break;
266 case 'LiteralInteger':
267 this.castLiteralToFloat(ast.left, retArr);
268 break;
269 default:
270 this.astGeneric(ast.left, retArr);
271 }
272 retArr.push(', ');
273 switch (this.getType(ast.right)) {
274 case 'Integer':
275 this.castValueToFloat(ast.right, retArr);
276 break;
277 case 'LiteralInteger':
278 this.castLiteralToFloat(ast.right, retArr);
279 break;
280 default:
281 this.astGeneric(ast.right, retArr);
282 }
283 this.popState('building-float');
284 retArr.push(')');
285 return retArr;
286 }
287
288 retArr.push('(');
289 const leftType = this.getType(ast.left) || 'Number';
290 const rightType = this.getType(ast.right) || 'Number';
291 if (!leftType || !rightType) {
292 throw this.astErrorOutput(`Unhandled binary expression`, ast);
293 }
294 const key = leftType + ' & ' + rightType;
295 switch (key) {
296 case 'Integer & Integer':
297 this.pushState('building-integer');
298 this.astGeneric(ast.left, retArr);
299 retArr.push(operatorMap[ast.operator] || ast.operator);
300 this.astGeneric(ast.right, retArr);
301 this.popState('building-integer');
302 break;
303 case 'Number & Float':
304 case 'Float & Number':
305 case 'Float & Float':
306 case 'Number & Number':
307 this.pushState('building-float');
308 this.astGeneric(ast.left, retArr);
309 retArr.push(operatorMap[ast.operator] || ast.operator);
310 this.astGeneric(ast.right, retArr);
311 this.popState('building-float');

Callers

nothing calls this directly

Calls 11

castValueToFloatMethod · 0.95
castLiteralToFloatMethod · 0.95
castLiteralToIntegerMethod · 0.95
castValueToIntegerMethod · 0.95
getTypeMethod · 0.80
astGenericMethod · 0.80
astErrorOutputMethod · 0.80
pushStateMethod · 0.45
popStateMethod · 0.45
isStateMethod · 0.45

Tested by

no test coverage detected