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

@@ -305,6 +305,12 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
elseifCount_: 0,
elseCount_: 0,
/**
* Don't automatically add STATEMENT_PREFIX and STATEMENT_SUFFIX to generated
* code. These will be handled manually in this block's generators.
*/
suppressPrefixSuffix: true,
/**
* Create XML to represent the number of else-if and else inputs.
* @return {Element} XML storage element.

View File

@@ -302,8 +302,19 @@ Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {
* To add a new loop type add this to your code:
* Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.LOOP_TYPES.push('custom_loop');
*/
LOOP_TYPES: ['controls_repeat', 'controls_repeat_ext', 'controls_forEach',
'controls_for', 'controls_whileUntil'],
LOOP_TYPES: [
'controls_repeat',
'controls_repeat_ext',
'controls_forEach',
'controls_for',
'controls_whileUntil'
],
/**
* Don't automatically add STATEMENT_PREFIX and STATEMENT_SUFFIX to generated
* code. These will be handled manually in this block's generators.
*/
suppressPrefixSuffix: true,
/**
* Is the given block enclosed (at any level) by a loop?

View File

@@ -642,6 +642,12 @@ Blockly.Blocks['procedures_callnoreturn'] = {
this.previousEnabledState_ = true;
},
/**
* Don't automatically add STATEMENT_PREFIX and STATEMENT_SUFFIX to generated
* code. These will be handled manually in this block's generators.
*/
suppressPrefixSuffix: true,
/**
* Returns the name of the procedure this block calls.
* @return {string} Procedure name.