MCPcopy Create free account
hub / github.com/ShaderFrog/glsl-parser / evaluteExpression

Function evaluteExpression

src/preprocessor/preprocessor.ts:311–412  ·  view source on GitHub ↗
(node: PreprocessorAstNode, macros: Macros)

Source from the content-addressed store, hash-verified

309
310// TODO: Are all of these operators equivalent between javascript and GLSL?
311const evaluteExpression = (node: PreprocessorAstNode, macros: Macros) =>
312 evaluate(node, {
313 // TODO: Handle non-base-10 numbers. Should these be parsed in the peg grammar?
314 int_constant: (node) => parseInt(node.token, 10),
315 unary_defined: (node) => node.identifier.identifier in macros,
316 identifier: (node) => node.identifier,
317 group: (node, visit) => visit(node.expression),
318 binary: ({ left, right, operator: { literal } }, visit) => {
319 switch (literal) {
320 // multiplicative
321 case '*': {
322 return visit(left) * visit(right);
323 }
324 // division
325 case '/': {
326 return visit(left) / visit(right);
327 }
328 // modulo
329 case '%': {
330 return visit(left) % visit(right);
331 }
332 // addition
333 case '+': {
334 return visit(left) + visit(right);
335 }
336 // subtraction
337 case '-': {
338 return visit(left) - visit(right);
339 }
340 // bit-wise shift
341 case '<<': {
342 return visit(left) << visit(right);
343 }
344 // bit-wise shift
345 case '>>': {
346 return visit(left) >> visit(right);
347 }
348 case '<': {
349 return visit(left) < visit(right);
350 }
351 case '>': {
352 return visit(left) > visit(right);
353 }
354 case '<=': {
355 return visit(left) <= visit(right);
356 }
357 case '>=': {
358 return visit(left) >= visit(right);
359 }
360 case '==': {
361 return visit(left) == visit(right);
362 }
363 case '!=': {
364 return visit(left) != visit(right);
365 }
366 // bit-wise and
367 case '&': {
368 return visit(left) & visit(right);

Callers 2

evaluateIfPartFunction · 0.85
preprocessAstFunction · 0.85

Calls 2

evaluateFunction · 0.85
visitFunction · 0.70

Tested by

no test coverage detected