diff --git a/core/names.js b/core/names.js index 016c01538..77577ccba 100644 --- a/core/names.js +++ b/core/names.js @@ -76,6 +76,11 @@ Blockly.Names.prototype.setVariableMap = function(map) { Blockly.Names.prototype.getNameForVariable = function(id) { if (!this.variableMap_) { + console.log('Deprecated call to Blockly.Names.prototype.getName without ' + + 'defining a variable map. To fix, add the folowing code in your ' + + 'generator\'s init() function:\n' + + 'Blockly.YourGeneratorName.variableDB_.setVariableMap(' + + 'workspace.getVariableMap());'); return null; } var variable = this.variableMap_.getVariableById(id); diff --git a/generators/php.js b/generators/php.js index 2c65a6809..dfe966843 100644 --- a/generators/php.js +++ b/generators/php.js @@ -149,14 +149,27 @@ Blockly.PHP.init = function(workspace) { Blockly.PHP.variableDB_.reset(); } + Blockly.PHP.variableDB_.setVariableMap(workspace.getVariableMap()); + var defvars = []; var varName; + // TODO (fenichel): Why does this use Variables.allVariables when the rest use + // workspace.getAllVariables()? var variables = Blockly.Variables.allVariables(workspace); for (var i = 0, variable; variable = variables[i]; i++) { varName = variable.name; defvars[i] = Blockly.PHP.variableDB_.getName(varName, Blockly.Variables.NAME_TYPE) + ';'; } + + // Add developer variables (not created or named by the user). + var devVarList = Blockly.Variables.allDeveloperVariables(workspace); + for (var i = 0; i < devVarList.length; i++) { + defvars.push(Blockly.PHP.variableDB_.getName(devVarList[i], + Blockly.Names.DEVELOPER_VARIABLE_TYPE) + ';'); + } + + // Declare all of the variables. Blockly.PHP.definitions_['variables'] = defvars.join('\n'); }; diff --git a/generators/python.js b/generators/python.js index e81a04234..ab927d13b 100644 --- a/generators/python.js +++ b/generators/python.js @@ -160,12 +160,21 @@ Blockly.Python.init = function(workspace) { Blockly.Python.variableDB_.reset(); } + Blockly.Python.variableDB_.setVariableMap(workspace.getVariableMap()); + var defvars = []; var variables = workspace.getAllVariables(); for (var i = 0; i < variables.length; i++) { defvars[i] = Blockly.Python.variableDB_.getName(variables[i].name, Blockly.Variables.NAME_TYPE) + ' = None'; } + + // Add developer variables (not created or named by the user). + var devVarList = Blockly.Variables.allDeveloperVariables(workspace); + for (var i = 0; i < devVarList.length; i++) { + defvars.push(Blockly.Python.variableDB_.getName(devVarList[i], + Blockly.Names.DEVELOPER_VARIABLE_TYPE) + ' = None'); + } Blockly.Python.definitions_['variables'] = defvars.join('\n'); }; diff --git a/tests/generators/unittest_php.js b/tests/generators/unittest_php.js index 528e5971d..54d7e4e97 100644 --- a/tests/generators/unittest_php.js +++ b/tests/generators/unittest_php.js @@ -27,7 +27,7 @@ Blockly.PHP['unittest_main'] = function(block) { // Container for unit tests. var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults', - Blockly.Variables.NAME_TYPE); + Blockly.Names.DEVELOPER_VARIABLE_TYPE); var functionName = Blockly.PHP.provideFunction_( 'unittest_report', [ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + '() {', @@ -72,7 +72,7 @@ Blockly.PHP['unittest_main'] = function(block) { Blockly.PHP['unittest_main'].defineAssert_ = function(block) { var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults', - Blockly.Variables.NAME_TYPE); + Blockly.Names.DEVELOPER_VARIABLE_TYPE); var functionName = Blockly.PHP.provideFunction_( 'assertEquals', ['function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + @@ -129,7 +129,7 @@ Blockly.PHP['unittest_assertvalue'] = function(block) { Blockly.PHP['unittest_fail'] = function(block) { // Always assert an error. var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults', - Blockly.Variables.NAME_TYPE); + Blockly.Names.DEVELOPER_VARIABLE_TYPE); var message = Blockly.PHP.quote_(block.getFieldValue('MESSAGE')); var functionName = Blockly.PHP.provideFunction_( 'unittest_fail', diff --git a/tests/generators/unittest_python.js b/tests/generators/unittest_python.js index 5e00e26be..91fabd179 100644 --- a/tests/generators/unittest_python.js +++ b/tests/generators/unittest_python.js @@ -27,7 +27,7 @@ Blockly.Python['unittest_main'] = function(block) { // Container for unit tests. var resultsVar = Blockly.Python.variableDB_.getName('unittestResults', - Blockly.Variables.NAME_TYPE); + Blockly.Names.DEVELOPER_VARIABLE_TYPE); var functionName = Blockly.Python.provideFunction_( 'unittest_report', ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '():', @@ -68,7 +68,7 @@ Blockly.Python['unittest_main'] = function(block) { Blockly.Python['unittest_main'].defineAssert_ = function() { var resultsVar = Blockly.Python.variableDB_.getName('unittestResults', - Blockly.Variables.NAME_TYPE); + Blockly.Names.DEVELOPER_VARIABLE_TYPE); var functionName = Blockly.Python.provideFunction_( 'assertEquals', ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + @@ -117,7 +117,7 @@ Blockly.Python['unittest_assertvalue'] = function(block) { Blockly.Python['unittest_fail'] = function(block) { // Always assert an error. var resultsVar = Blockly.Python.variableDB_.getName('unittestResults', - Blockly.Variables.NAME_TYPE); + Blockly.Names.DEVELOPER_VARIABLE_TYPE); var message = Blockly.Python.quote_(block.getFieldValue('MESSAGE')); var functionName = Blockly.Python.provideFunction_( 'fail',