Add method to suppress prefix/suffix from blocks.

This allows generators to have more control over the placement of suffix.  Needed for ‘if’ blocks and function calls which require their suffix code to be somewhere other than the end.
Also, add loop’s prefix to ‘break’ blocks, since the loop’s suffix will be the next statement hit.
Also, reuse procedures_callreturn generator for procedures_callnoreturn.
This commit is contained in:
Neil Fraser
2019-05-14 13:59:19 -07:00
committed by Neil Fraser
parent 25adb40e66
commit c0e14c3a7c
19 changed files with 210 additions and 73 deletions

View File

@@ -87,14 +87,21 @@ Blockly.JavaScript['procedures_callreturn'] = function(block) {
Blockly.JavaScript['procedures_callnoreturn'] = function(block) {
// Call a procedure with no return value.
var funcName = Blockly.JavaScript.variableDB_.getName(
block.getFieldValue('NAME'), Blockly.Procedures.NAME_TYPE);
var args = [];
for (var i = 0; i < block.arguments_.length; i++) {
args[i] = Blockly.JavaScript.valueToCode(block, 'ARG' + i,
Blockly.JavaScript.ORDER_COMMA) || 'null';
var code = '';
if (Blockly.JavaScript.STATEMENT_PREFIX) {
// Automatic prefix insertion is switched off for this block. Add manually.
code += Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_PREFIX,
block);
}
var code = funcName + '(' + args.join(', ') + ');\n';
if (Blockly.JavaScript.STATEMENT_SUFFIX) {
// Suffix needs to be added before the function call.
code += Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_SUFFIX,
block);
}
// Generated code is for a function call as a statement is the same as a
// function call as a value, with the addition of line ending.
var tuple = Blockly.JavaScript['procedures_callreturn'](block);
code += tuple[0] + ';\n';
return code;
};