(block, context, expressions, outputScans)
| 394 | //----------------------------------------------------------- |
| 395 | |
| 396 | function buildExpressions(block, context, expressions, outputScans) { |
| 397 | for(let expression of expressions) { |
| 398 | if(expression.type === "expression") { |
| 399 | let results = []; |
| 400 | if(expression.variable) { |
| 401 | let result = context.getValue(expression.variable); |
| 402 | results.push(result); |
| 403 | context.provide(result); |
| 404 | } |
| 405 | let args = []; |
| 406 | for(let arg of expression.args) { |
| 407 | args.push(context.getValue(arg)); |
| 408 | } |
| 409 | let impl = providers.get(expression.op); |
| 410 | if(impl) { |
| 411 | outputScans.push(new impl(`${expression.id}|build`, args, results)); |
| 412 | } else { |
| 413 | context.errors.push(errors.unimplementedExpression(block, expression)); |
| 414 | } |
| 415 | } else if(expression.type === "functionRecord") { |
| 416 | let results; |
| 417 | if(expression.returns !== undefined) { |
| 418 | results = expression.returns.slice(); |
| 419 | } else { |
| 420 | results = [expression.variable]; |
| 421 | let resolved = context.getValue(expression.variable); |
| 422 | context.provide(resolved); |
| 423 | } |
| 424 | let args = []; |
| 425 | let impl = providers.get(expression.op); |
| 426 | if(!impl) { |
| 427 | context.errors.push(errors.unimplementedExpression(block, expression)); |
| 428 | return; |
| 429 | } |
| 430 | for(let attribute of expression.record.attributes) { |
| 431 | let ix; |
| 432 | if(impl.AttributeMapping && (ix = impl.AttributeMapping[attribute.attribute]) !== undefined) { |
| 433 | args[ix] = context.getValue(attribute.value); |
| 434 | } else if(impl.ReturnMapping && (ix = impl.ReturnMapping[attribute.attribute]) !== undefined) { |
| 435 | results[ix] = attribute.value; |
| 436 | } else { |
| 437 | context.errors.push(errors.unrecognisedFunctionAttribute(block , expression,attribute)); |
| 438 | } |
| 439 | |
| 440 | } |
| 441 | let resultIx = 0; |
| 442 | for(let result of results) { |
| 443 | // if one of the returns is fixed, we need to add an equality check |
| 444 | // to make sure that the return is actually that constant. The constraint |
| 445 | // provider may be smart enough to do that themselves, but this removes |
| 446 | // the burden from them. |
| 447 | let resolved = context.getValue(result); |
| 448 | context.provide(resolved); |
| 449 | results[resultIx] = resolved; |
| 450 | if(!join.isVariable(resolved)) { |
| 451 | // @TODO: mark this variable as generated? |
| 452 | let variable = context.createVariable(); |
| 453 | let klass = providers.get("="); |
no test coverage detected