From e642a77f5d877bdf6ab562be5833ebb6c5769e60 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 15 May 2019 13:43:57 -0700 Subject: [PATCH] Use conventional prefix/suffix for function calls. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously a function call with no return value generated: prefix(); suffix(); function(); The intent was so the prefix and suffix calls in the function body wouldn’t overlap with the prefix and suffix calls of the function call. However, this is doomed to be inconsistent with a function call with a return value: prefix(); print(function()); suffix(); Thus since overlaping must exist, both types of function calls should have consistent suffix locations. --- blocks/procedures.js | 6 ------ generators/dart/procedures.js | 12 +----------- generators/javascript/procedures.js | 14 +------------- generators/lua/procedures.js | 12 +----------- generators/php/procedures.js | 12 +----------- generators/python/procedures.js | 12 +----------- 6 files changed, 5 insertions(+), 63 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index a95babe47..5188ac8b9 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -642,12 +642,6 @@ 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. diff --git a/generators/dart/procedures.js b/generators/dart/procedures.js index e6402a77b..451be16d8 100644 --- a/generators/dart/procedures.js +++ b/generators/dart/procedures.js @@ -93,20 +93,10 @@ Blockly.Dart['procedures_callreturn'] = function(block) { Blockly.Dart['procedures_callnoreturn'] = function(block) { // Call a procedure with no return value. - var code = ''; - if (Blockly.Dart.STATEMENT_PREFIX) { - // Automatic prefix insertion is switched off for this block. Add manually. - code += Blockly.Dart.injectId(Blockly.Dart.STATEMENT_PREFIX, block); - } - if (Blockly.Dart.STATEMENT_SUFFIX) { - // Suffix needs to be added before the function call. - code += Blockly.Dart.injectId(Blockly.Dart.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.Dart['procedures_callreturn'](block); - code += tuple[0] + ';\n'; - return code; + return tuple[0] + ';\n'; }; Blockly.Dart['procedures_ifreturn'] = function(block) { diff --git a/generators/javascript/procedures.js b/generators/javascript/procedures.js index 86ee28b21..9c2ac09ac 100644 --- a/generators/javascript/procedures.js +++ b/generators/javascript/procedures.js @@ -95,22 +95,10 @@ Blockly.JavaScript['procedures_callreturn'] = function(block) { Blockly.JavaScript['procedures_callnoreturn'] = function(block) { // Call a procedure with no return value. - 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); - } - 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; + return tuple[0] + ';\n'; }; Blockly.JavaScript['procedures_ifreturn'] = function(block) { diff --git a/generators/lua/procedures.js b/generators/lua/procedures.js index 1a5b605dc..917ee2493 100644 --- a/generators/lua/procedures.js +++ b/generators/lua/procedures.js @@ -95,20 +95,10 @@ Blockly.Lua['procedures_callreturn'] = function(block) { Blockly.Lua['procedures_callnoreturn'] = function(block) { // Call a procedure with no return value. - var code = ''; - if (Blockly.Lua.STATEMENT_PREFIX) { - // Automatic prefix insertion is switched off for this block. Add manually. - code += Blockly.Lua.injectId(Blockly.Lua.STATEMENT_PREFIX, block); - } - if (Blockly.Lua.STATEMENT_SUFFIX) { - // Suffix needs to be added before the function call. - code += Blockly.Lua.injectId(Blockly.Lua.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.Lua['procedures_callreturn'](block); - code += tuple[0] + '\n'; - return code; + return tuple[0] + '\n'; }; Blockly.Lua['procedures_ifreturn'] = function(block) { diff --git a/generators/php/procedures.js b/generators/php/procedures.js index f66703d10..0f9dd91ac 100644 --- a/generators/php/procedures.js +++ b/generators/php/procedures.js @@ -114,20 +114,10 @@ Blockly.PHP['procedures_callreturn'] = function(block) { Blockly.PHP['procedures_callnoreturn'] = function(block) { // Call a procedure with no return value. - var code = ''; - if (Blockly.PHP.STATEMENT_PREFIX) { - // Automatic prefix insertion is switched off for this block. Add manually. - code += Blockly.PHP.injectId(Blockly.PHP.STATEMENT_PREFIX, block); - } - if (Blockly.PHP.STATEMENT_SUFFIX) { - // Suffix needs to be added before the function call. - code += Blockly.PHP.injectId(Blockly.PHP.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.PHP['procedures_callreturn'](block); - code += tuple[0] + ';\n'; - return code; + return tuple[0] + ';\n'; }; Blockly.PHP['procedures_ifreturn'] = function(block) { diff --git a/generators/python/procedures.js b/generators/python/procedures.js index daec89855..3b81edca4 100644 --- a/generators/python/procedures.js +++ b/generators/python/procedures.js @@ -117,20 +117,10 @@ Blockly.Python['procedures_callreturn'] = function(block) { Blockly.Python['procedures_callnoreturn'] = function(block) { // Call a procedure with no return value. - var code = ''; - if (Blockly.Python.STATEMENT_PREFIX) { - // Automatic prefix insertion is switched off for this block. Add manually. - code += Blockly.Python.injectId(Blockly.Python.STATEMENT_PREFIX, block); - } - if (Blockly.Python.STATEMENT_SUFFIX) { - // Suffix needs to be added before the function call. - code += Blockly.Python.injectId(Blockly.Python.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.Python['procedures_callreturn'](block); - code += tuple[0] + '\n'; - return code; + return tuple[0] + '\n'; }; Blockly.Python['procedures_ifreturn'] = function(block) {