Rename variableDB_ to nameDB_

There is significant confusion in names and comments with regards to variables and procedures.  `Blockly.Generator.prototype.variableDB_` is a Blockly.Names database, not a variable map.  This rename introduces a getter and setter so deprecated references still work.  This commit also fixes some comments which are either outright wrong or misleading regarding variable and procedure names.
This commit is contained in:
Neil Fraser
2021-05-19 13:06:24 -07:00
committed by Neil Fraser
parent 5344ad6c21
commit 2f2252f588
45 changed files with 167 additions and 150 deletions

View File

@@ -402,24 +402,42 @@ Blockly.Generator.prototype.definitions_;
Blockly.Generator.prototype.functionNames_;
/**
* A database of variable names.
* A database of variable and procedure names.
* @type {Blockly.Names}
* @protected
*/
Blockly.Generator.prototype.variableDB_;
Blockly.Generator.prototype.nameDB_;
/**
* Define a function to be included in the generated code.
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
*/
Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', {
get: function() {
console.warn('Deprecated use of "variableDB_"; change to "nameDB_"');
return this.nameDB_;
},
set: function(x) {
console.warn('Deprecated use of "variableDB_"; change to "nameDB_"');
this.nameDB_ = x;
}
});
/**
* Define a developer-defined function (not a user-defined procedure) to be
* included in the generated code. Used for creating private helper functions.
* The first time this is called with a given desiredName, the code is
* saved and an actual name is generated. Subsequent calls with the
* same desiredName have no effect but have the same return value.
*
* It is up to the caller to make sure the same desiredName is not
* used for different code values.
* used for different helper functions (e.g. use "colourRandom" and
* "listRandom", not "random"). There is no danger of colliding with reserved
* words, or user-defined variable or procedure names.
*
* The code gets output when Blockly.Generator.finish() is called.
*
* @param {string} desiredName The desired name of the function (e.g., isPrime).
* @param {string} desiredName The desired name of the function
* (e.g. mathIsPrime).
* @param {!Array.<string>} code A list of statements. Use ' ' for indents.
* @return {string} The actual name of the new function. This may differ
* from desiredName if the former has already been taken by the user.
@@ -427,7 +445,7 @@ Blockly.Generator.prototype.variableDB_;
*/
Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) {
if (!this.definitions_[desiredName]) {
var functionName = this.variableDB_.getDistinctName(desiredName,
var functionName = this.nameDB_.getDistinctName(desiredName,
Blockly.PROCEDURE_CATEGORY_NAME);
this.functionNames_[desiredName] = functionName;
var codeText = code.join('\n').replace(

View File

@@ -5,7 +5,7 @@
*/
/**
* @fileoverview Utility functions for handling variables and procedure names.
* @fileoverview Utility functions for handling variable and procedure names.
* @author fraser@google.com (Neil Fraser)
*/
'use strict';
@@ -20,11 +20,11 @@ goog.requireType('Blockly.VariableMap');
/**
* Class for a database of entity names (variables, functions, etc).
* Class for a database of entity names (variables, procedures, etc).
* @param {string} reservedWords A comma-separated string of words that are
* illegal for use as names in a language (e.g. 'new,if,this,...').
* @param {string=} opt_variablePrefix Some languages need a '$' or a namespace
* before all variable names.
* before all variable names (but not procedure names).
* @constructor
*/
Blockly.Names = function(reservedWords, opt_variablePrefix) {
@@ -85,10 +85,10 @@ Blockly.Names.prototype.setVariableMap = function(map) {
*/
Blockly.Names.prototype.getNameForUserVariable_ = function(id) {
if (!this.variableMap_) {
console.log('Deprecated call to Blockly.Names.prototype.getName without ' +
console.warn('Deprecated call to Blockly.Names.prototype.getName without ' +
'defining a variable map. To fix, add the following code in your ' +
'generator\'s init() function:\n' +
'Blockly.YourGeneratorName.variableDB_.setVariableMap(' +
'Blockly.YourGeneratorName.nameDB_.setVariableMap(' +
'workspace.getVariableMap());');
return null;
}
@@ -157,7 +157,7 @@ Blockly.Names.prototype.getDistinctName = function(name, realm) {
/**
* Given a proposed entity name, generate a name that conforms to the
* [_A-Za-z][_A-Za-z0-9]* format that most languages consider legal for
* variables.
* variable and function names.
* @param {string} name Potentially illegal entity name.
* @return {string} Safe entity name.
* @private

View File

@@ -24,8 +24,8 @@ goog.requireType('Blockly.Workspace');
* Class for a variable model.
* Holds information for the variable including name, ID, and type.
* @param {!Blockly.Workspace} workspace The variable's workspace.
* @param {string} name The name of the variable. This must be unique across
* variables and procedures.
* @param {string} name The name of the variable. This is the user-visible name
* (e.g. 'my var' or '私の変数'), not the generated name.
* @param {string=} opt_type The type of the variable like 'int' or 'string'.
* Does not need to be unique. Field_variable can filter variables based on
* their type. This will default to '' which is a specific type.
@@ -42,8 +42,7 @@ Blockly.VariableModel = function(workspace, name, opt_type, opt_id) {
this.workspace = workspace;
/**
* The name of the variable, typically defined by the user. It must be
* unique across all names used for procedures and variables. It may be
* The name of the variable, typically defined by the user. It may be
* changed by the user.
* @type {string}
*/

View File

@@ -97,7 +97,7 @@ FactoryUtils.getGeneratorStub = function(block, generatorLanguage) {
// Subclass of Blockly.FieldDropdown, must test first.
code.push(makeVar('variable', name) +
" = Blockly." + language +
".variableDB_.getName(block.getFieldValue('" + name +
".nameDB_.getName(block.getFieldValue('" + name +
"'), Blockly.Variables.NAME_TYPE);");
} else if (field instanceof Blockly.FieldAngle) {
// Subclass of Blockly.FieldTextInput, must test first.

View File

@@ -558,7 +558,7 @@ function updateGenerator(block) {
// Subclass of Blockly.FieldDropdown, must test first.
code.push(makeVar('variable', name) +
" = Blockly." + language +
".variableDB_.getName(block.getFieldValue('" + name +
".nameDB_.getName(block.getFieldValue('" + name +
"'), Blockly.Variables.NAME_TYPE);");
} else if (field instanceof Blockly.FieldAngle) {
// Subclass of Blockly.FieldTextInput, must test first.

View File

@@ -89,27 +89,27 @@ Blockly.Dart.init = function(workspace) {
// to actual function names (to avoid collisions with user functions).
Blockly.Dart.functionNames_ = Object.create(null);
if (!Blockly.Dart.variableDB_) {
Blockly.Dart.variableDB_ =
if (!Blockly.Dart.nameDB_) {
Blockly.Dart.nameDB_ =
new Blockly.Names(Blockly.Dart.RESERVED_WORDS_);
} else {
Blockly.Dart.variableDB_.reset();
Blockly.Dart.nameDB_.reset();
}
Blockly.Dart.variableDB_.setVariableMap(workspace.getVariableMap());
Blockly.Dart.nameDB_.setVariableMap(workspace.getVariableMap());
var defvars = [];
// 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.Dart.variableDB_.getName(devVarList[i],
defvars.push(Blockly.Dart.nameDB_.getName(devVarList[i],
Blockly.Names.DEVELOPER_VARIABLE_TYPE));
}
// Add user variables, but only ones that are being used.
var variables = Blockly.Variables.allUsedVarModels(workspace);
for (var i = 0; i < variables.length; i++) {
defvars.push(Blockly.Dart.variableDB_.getName(variables[i].getId(),
defvars.push(Blockly.Dart.nameDB_.getName(variables[i].getId(),
Blockly.VARIABLE_CATEGORY_NAME));
}
@@ -147,7 +147,7 @@ Blockly.Dart.finish = function(code) {
// Clean up temporary data.
delete Blockly.Dart.definitions_;
delete Blockly.Dart.functionNames_;
Blockly.Dart.variableDB_.reset();
Blockly.Dart.nameDB_.reset();
var allDefs = imports.join('\n') + '\n\n' + definitions.join('\n\n');
return allDefs.replace(/\n\n+/g, '\n\n').replace(/\n*$/, '\n\n\n') + code;
};

View File

@@ -83,7 +83,7 @@ Blockly.Dart['lists_getIndex'] = function(block) {
// Cache non-trivial values to variables to prevent repeated look-ups.
// Closure, which accesses and modifies 'list'.
function cacheList() {
var listVar = Blockly.Dart.variableDB_.getDistinctName(
var listVar = Blockly.Dart.nameDB_.getDistinctName(
'tmp_list', Blockly.VARIABLE_CATEGORY_NAME);
var code = 'List ' + listVar + ' = ' + list + ';\n';
list = listVar;
@@ -100,7 +100,7 @@ Blockly.Dart['lists_getIndex'] = function(block) {
'import \'dart:math\' as Math;';
// We can use multiple statements.
var code = cacheList();
var xVar = Blockly.Dart.variableDB_.getDistinctName(
var xVar = Blockly.Dart.nameDB_.getDistinctName(
'tmp_x', Blockly.VARIABLE_CATEGORY_NAME);
code += 'int ' + xVar + ' = new Math.Random().nextInt(' + list +
'.length);\n';
@@ -199,7 +199,7 @@ Blockly.Dart['lists_getIndex'] = function(block) {
'import \'dart:math\' as Math;';
if (mode == 'REMOVE') {
// We can use multiple statements.
var xVar = Blockly.Dart.variableDB_.getDistinctName(
var xVar = Blockly.Dart.nameDB_.getDistinctName(
'tmp_x', Blockly.VARIABLE_CATEGORY_NAME);
var code = 'int ' + xVar + ' = new Math.Random().nextInt(' + list +
'.length);\n';
@@ -247,7 +247,7 @@ Blockly.Dart['lists_setIndex'] = function(block) {
if (list.match(/^\w+$/)) {
return '';
}
var listVar = Blockly.Dart.variableDB_.getDistinctName(
var listVar = Blockly.Dart.nameDB_.getDistinctName(
'tmp_list', Blockly.VARIABLE_CATEGORY_NAME);
var code = 'List ' + listVar + ' = ' + list + ';\n';
list = listVar;
@@ -296,7 +296,7 @@ Blockly.Dart['lists_setIndex'] = function(block) {
Blockly.Dart.definitions_['import_dart_math'] =
'import \'dart:math\' as Math;';
var code = cacheList();
var xVar = Blockly.Dart.variableDB_.getDistinctName(
var xVar = Blockly.Dart.nameDB_.getDistinctName(
'tmp_x', Blockly.VARIABLE_CATEGORY_NAME);
code += 'int ' + xVar +
' = new Math.Random().nextInt(' + list + '.length);\n';

View File

@@ -28,11 +28,11 @@ Blockly.Dart['controls_repeat_ext'] = function(block) {
var branch = Blockly.Dart.statementToCode(block, 'DO');
branch = Blockly.Dart.addLoopTrap(branch, block);
var code = '';
var loopVar = Blockly.Dart.variableDB_.getDistinctName(
var loopVar = Blockly.Dart.nameDB_.getDistinctName(
'count', Blockly.VARIABLE_CATEGORY_NAME);
var endVar = repeats;
if (!repeats.match(/^\w+$/) && !Blockly.isNumber(repeats)) {
endVar = Blockly.Dart.variableDB_.getDistinctName(
endVar = Blockly.Dart.nameDB_.getDistinctName(
'repeat_end', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + endVar + ' = ' + repeats + ';\n';
}
@@ -61,7 +61,7 @@ Blockly.Dart['controls_whileUntil'] = function(block) {
Blockly.Dart['controls_for'] = function(block) {
// For loop.
var variable0 = Blockly.Dart.variableDB_.getName(
var variable0 = Blockly.Dart.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.Dart.valueToCode(block, 'FROM',
Blockly.Dart.ORDER_ASSIGNMENT) || '0';
@@ -91,19 +91,19 @@ Blockly.Dart['controls_for'] = function(block) {
// Cache non-trivial values to variables to prevent repeated look-ups.
var startVar = argument0;
if (!argument0.match(/^\w+$/) && !Blockly.isNumber(argument0)) {
startVar = Blockly.Dart.variableDB_.getDistinctName(
startVar = Blockly.Dart.nameDB_.getDistinctName(
variable0 + '_start', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + startVar + ' = ' + argument0 + ';\n';
}
var endVar = argument1;
if (!argument1.match(/^\w+$/) && !Blockly.isNumber(argument1)) {
endVar = Blockly.Dart.variableDB_.getDistinctName(
endVar = Blockly.Dart.nameDB_.getDistinctName(
variable0 + '_end', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + endVar + ' = ' + argument1 + ';\n';
}
// Determine loop direction at start, in case one of the bounds
// changes during loop execution.
var incVar = Blockly.Dart.variableDB_.getDistinctName(
var incVar = Blockly.Dart.nameDB_.getDistinctName(
variable0 + '_inc', Blockly.VARIABLE_CATEGORY_NAME);
code += 'num ' + incVar + ' = ';
if (Blockly.isNumber(increment)) {
@@ -126,7 +126,7 @@ Blockly.Dart['controls_for'] = function(block) {
Blockly.Dart['controls_forEach'] = function(block) {
// For each loop.
var variable0 = Blockly.Dart.variableDB_.getName(
var variable0 = Blockly.Dart.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.Dart.valueToCode(block, 'LIST',
Blockly.Dart.ORDER_ASSIGNMENT) || '[]';

View File

@@ -240,7 +240,7 @@ Blockly.Dart['math_change'] = function(block) {
// Add to a variable in place.
var argument0 = Blockly.Dart.valueToCode(block, 'DELTA',
Blockly.Dart.ORDER_ADDITIVE) || '0';
var varName = Blockly.Dart.variableDB_.getName(block.getFieldValue('VAR'),
var varName = Blockly.Dart.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = (' + varName + ' is num ? ' + varName + ' : 0) + ' +
argument0 + ';\n';

View File

@@ -17,7 +17,7 @@ goog.require('Blockly.Dart');
Blockly.Dart['procedures_defreturn'] = function(block) {
// Define a procedure with a return value.
var funcName = Blockly.Dart.variableDB_.getName(block.getFieldValue('NAME'),
var funcName = Blockly.Dart.nameDB_.getName(block.getFieldValue('NAME'),
Blockly.PROCEDURE_CATEGORY_NAME);
var xfix1 = '';
if (Blockly.Dart.STATEMENT_PREFIX) {
@@ -50,7 +50,7 @@ Blockly.Dart['procedures_defreturn'] = function(block) {
var args = [];
var variables = block.getVars();
for (var i = 0; i < variables.length; i++) {
args[i] = Blockly.Dart.variableDB_.getName(variables[i],
args[i] = Blockly.Dart.nameDB_.getName(variables[i],
Blockly.VARIABLE_CATEGORY_NAME);
}
var code = returnType + ' ' + funcName + '(' + args.join(', ') + ') {\n' +
@@ -67,7 +67,7 @@ Blockly.Dart['procedures_defnoreturn'] = Blockly.Dart['procedures_defreturn'];
Blockly.Dart['procedures_callreturn'] = function(block) {
// Call a procedure with a return value.
var funcName = Blockly.Dart.variableDB_.getName(block.getFieldValue('NAME'),
var funcName = Blockly.Dart.nameDB_.getName(block.getFieldValue('NAME'),
Blockly.PROCEDURE_CATEGORY_NAME);
var args = [];
var variables = block.getVars();

View File

@@ -54,7 +54,7 @@ Blockly.Dart['text_join'] = function(block) {
Blockly.Dart['text_append'] = function(block) {
// Append to a variable in place.
var varName = Blockly.Dart.variableDB_.getName(block.getFieldValue('VAR'),
var varName = Blockly.Dart.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
var value = Blockly.Dart.valueToCode(block, 'TEXT',
Blockly.Dart.ORDER_NONE) || '\'\'';

View File

@@ -17,7 +17,7 @@ goog.require('Blockly.Dart');
Blockly.Dart['variables_get'] = function(block) {
// Variable getter.
var code = Blockly.Dart.variableDB_.getName(block.getFieldValue('VAR'),
var code = Blockly.Dart.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return [code, Blockly.Dart.ORDER_ATOMIC];
};
@@ -26,7 +26,7 @@ Blockly.Dart['variables_set'] = function(block) {
// Variable setter.
var argument0 = Blockly.Dart.valueToCode(block, 'VALUE',
Blockly.Dart.ORDER_ASSIGNMENT) || '0';
var varName = Blockly.Dart.variableDB_.getName(block.getFieldValue('VAR'),
var varName = Blockly.Dart.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = ' + argument0 + ';\n';
};

View File

@@ -131,27 +131,27 @@ Blockly.JavaScript.init = function(workspace) {
// to actual function names (to avoid collisions with user functions).
Blockly.JavaScript.functionNames_ = Object.create(null);
if (!Blockly.JavaScript.variableDB_) {
Blockly.JavaScript.variableDB_ =
if (!Blockly.JavaScript.nameDB_) {
Blockly.JavaScript.nameDB_ =
new Blockly.Names(Blockly.JavaScript.RESERVED_WORDS_);
} else {
Blockly.JavaScript.variableDB_.reset();
Blockly.JavaScript.nameDB_.reset();
}
Blockly.JavaScript.variableDB_.setVariableMap(workspace.getVariableMap());
Blockly.JavaScript.nameDB_.setVariableMap(workspace.getVariableMap());
var defvars = [];
// 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.JavaScript.variableDB_.getName(devVarList[i],
defvars.push(Blockly.JavaScript.nameDB_.getName(devVarList[i],
Blockly.Names.DEVELOPER_VARIABLE_TYPE));
}
// Add user variables, but only ones that are being used.
var variables = Blockly.Variables.allUsedVarModels(workspace);
for (var i = 0; i < variables.length; i++) {
defvars.push(Blockly.JavaScript.variableDB_.getName(variables[i].getId(),
defvars.push(Blockly.JavaScript.nameDB_.getName(variables[i].getId(),
Blockly.VARIABLE_CATEGORY_NAME));
}
@@ -177,7 +177,7 @@ Blockly.JavaScript.finish = function(code) {
// Clean up temporary data.
delete Blockly.JavaScript.definitions_;
delete Blockly.JavaScript.functionNames_;
Blockly.JavaScript.variableDB_.reset();
Blockly.JavaScript.nameDB_.reset();
return definitions.join('\n\n') + '\n\n\n' + code;
};

View File

@@ -174,7 +174,7 @@ Blockly.JavaScript['lists_setIndex'] = function(block) {
if (list.match(/^\w+$/)) {
return '';
}
var listVar = Blockly.JavaScript.variableDB_.getDistinctName(
var listVar = Blockly.JavaScript.nameDB_.getDistinctName(
'tmpList', Blockly.VARIABLE_CATEGORY_NAME);
var code = 'var ' + listVar + ' = ' + list + ';\n';
list = listVar;
@@ -220,7 +220,7 @@ Blockly.JavaScript['lists_setIndex'] = function(block) {
break;
case ('RANDOM'):
var code = cacheList();
var xVar = Blockly.JavaScript.variableDB_.getDistinctName(
var xVar = Blockly.JavaScript.nameDB_.getDistinctName(
'tmpX', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + xVar + ' = Math.floor(Math.random() * ' + list +
'.length);\n';

View File

@@ -28,11 +28,11 @@ Blockly.JavaScript['controls_repeat_ext'] = function(block) {
var branch = Blockly.JavaScript.statementToCode(block, 'DO');
branch = Blockly.JavaScript.addLoopTrap(branch, block);
var code = '';
var loopVar = Blockly.JavaScript.variableDB_.getDistinctName(
var loopVar = Blockly.JavaScript.nameDB_.getDistinctName(
'count', Blockly.VARIABLE_CATEGORY_NAME);
var endVar = repeats;
if (!repeats.match(/^\w+$/) && !Blockly.isNumber(repeats)) {
endVar = Blockly.JavaScript.variableDB_.getDistinctName(
endVar = Blockly.JavaScript.nameDB_.getDistinctName(
'repeat_end', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + endVar + ' = ' + repeats + ';\n';
}
@@ -62,7 +62,7 @@ Blockly.JavaScript['controls_whileUntil'] = function(block) {
Blockly.JavaScript['controls_for'] = function(block) {
// For loop.
var variable0 = Blockly.JavaScript.variableDB_.getName(
var variable0 = Blockly.JavaScript.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.JavaScript.valueToCode(block, 'FROM',
Blockly.JavaScript.ORDER_ASSIGNMENT) || '0';
@@ -92,19 +92,19 @@ Blockly.JavaScript['controls_for'] = function(block) {
// Cache non-trivial values to variables to prevent repeated look-ups.
var startVar = argument0;
if (!argument0.match(/^\w+$/) && !Blockly.isNumber(argument0)) {
startVar = Blockly.JavaScript.variableDB_.getDistinctName(
startVar = Blockly.JavaScript.nameDB_.getDistinctName(
variable0 + '_start', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + startVar + ' = ' + argument0 + ';\n';
}
var endVar = argument1;
if (!argument1.match(/^\w+$/) && !Blockly.isNumber(argument1)) {
endVar = Blockly.JavaScript.variableDB_.getDistinctName(
endVar = Blockly.JavaScript.nameDB_.getDistinctName(
variable0 + '_end', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + endVar + ' = ' + argument1 + ';\n';
}
// Determine loop direction at start, in case one of the bounds
// changes during loop execution.
var incVar = Blockly.JavaScript.variableDB_.getDistinctName(
var incVar = Blockly.JavaScript.nameDB_.getDistinctName(
variable0 + '_inc', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + incVar + ' = ';
if (Blockly.isNumber(increment)) {
@@ -127,7 +127,7 @@ Blockly.JavaScript['controls_for'] = function(block) {
Blockly.JavaScript['controls_forEach'] = function(block) {
// For each loop.
var variable0 = Blockly.JavaScript.variableDB_.getName(
var variable0 = Blockly.JavaScript.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.JavaScript.valueToCode(block, 'LIST',
Blockly.JavaScript.ORDER_ASSIGNMENT) || '[]';
@@ -137,11 +137,11 @@ Blockly.JavaScript['controls_forEach'] = function(block) {
// Cache non-trivial values to variables to prevent repeated look-ups.
var listVar = argument0;
if (!argument0.match(/^\w+$/)) {
listVar = Blockly.JavaScript.variableDB_.getDistinctName(
listVar = Blockly.JavaScript.nameDB_.getDistinctName(
variable0 + '_list', Blockly.VARIABLE_CATEGORY_NAME);
code += 'var ' + listVar + ' = ' + argument0 + ';\n';
}
var indexVar = Blockly.JavaScript.variableDB_.getDistinctName(
var indexVar = Blockly.JavaScript.nameDB_.getDistinctName(
variable0 + '_index', Blockly.VARIABLE_CATEGORY_NAME);
branch = Blockly.JavaScript.INDENT + variable0 + ' = ' +
listVar + '[' + indexVar + '];\n' + branch;

View File

@@ -207,7 +207,7 @@ Blockly.JavaScript['math_change'] = function(block) {
// Add to a variable in place.
var argument0 = Blockly.JavaScript.valueToCode(block, 'DELTA',
Blockly.JavaScript.ORDER_ADDITION) || '0';
var varName = Blockly.JavaScript.variableDB_.getName(
var varName = Blockly.JavaScript.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = (typeof ' + varName + ' == \'number\' ? ' + varName +
' : 0) + ' + argument0 + ';\n';

View File

@@ -17,7 +17,7 @@ goog.require('Blockly.JavaScript');
Blockly.JavaScript['procedures_defreturn'] = function(block) {
// Define a procedure with a return value.
var funcName = Blockly.JavaScript.variableDB_.getName(
var funcName = Blockly.JavaScript.nameDB_.getName(
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
var xfix1 = '';
if (Blockly.JavaScript.STATEMENT_PREFIX) {
@@ -51,7 +51,7 @@ Blockly.JavaScript['procedures_defreturn'] = function(block) {
var args = [];
var variables = block.getVars();
for (var i = 0; i < variables.length; i++) {
args[i] = Blockly.JavaScript.variableDB_.getName(variables[i],
args[i] = Blockly.JavaScript.nameDB_.getName(variables[i],
Blockly.VARIABLE_CATEGORY_NAME);
}
var code = 'function ' + funcName + '(' + args.join(', ') + ') {\n' +
@@ -69,7 +69,7 @@ Blockly.JavaScript['procedures_defnoreturn'] =
Blockly.JavaScript['procedures_callreturn'] = function(block) {
// Call a procedure with a return value.
var funcName = Blockly.JavaScript.variableDB_.getName(
var funcName = Blockly.JavaScript.nameDB_.getName(
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
var args = [];
var variables = block.getVars();

View File

@@ -80,7 +80,7 @@ Blockly.JavaScript['text_join'] = function(block) {
Blockly.JavaScript['text_append'] = function(block) {
// Append to a variable in place.
var varName = Blockly.JavaScript.variableDB_.getName(
var varName = Blockly.JavaScript.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var value = Blockly.JavaScript.valueToCode(block, 'TEXT',
Blockly.JavaScript.ORDER_NONE) || '\'\'';

View File

@@ -17,7 +17,7 @@ goog.require('Blockly.JavaScript');
Blockly.JavaScript['variables_get'] = function(block) {
// Variable getter.
var code = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('VAR'),
var code = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
@@ -26,7 +26,7 @@ Blockly.JavaScript['variables_set'] = function(block) {
// Variable setter.
var argument0 = Blockly.JavaScript.valueToCode(block, 'VALUE',
Blockly.JavaScript.ORDER_ASSIGNMENT) || '0';
var varName = Blockly.JavaScript.variableDB_.getName(
var varName = Blockly.JavaScript.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = ' + argument0 + ';\n';
};

View File

@@ -97,13 +97,13 @@ Blockly.Lua.init = function(workspace) {
// to actual function names (to avoid collisions with user functions).
Blockly.Lua.functionNames_ = Object.create(null);
if (!Blockly.Lua.variableDB_) {
Blockly.Lua.variableDB_ =
if (!Blockly.Lua.nameDB_) {
Blockly.Lua.nameDB_ =
new Blockly.Names(Blockly.Lua.RESERVED_WORDS_);
} else {
Blockly.Lua.variableDB_.reset();
Blockly.Lua.nameDB_.reset();
}
Blockly.Lua.variableDB_.setVariableMap(workspace.getVariableMap());
Blockly.Lua.nameDB_.setVariableMap(workspace.getVariableMap());
this.isInitialized = true;
};
@@ -121,7 +121,7 @@ Blockly.Lua.finish = function(code) {
// Clean up temporary data.
delete Blockly.Lua.definitions_;
delete Blockly.Lua.functionNames_;
Blockly.Lua.variableDB_.reset();
Blockly.Lua.nameDB_.reset();
return definitions.join('\n\n') + '\n\n\n' + code;
};

View File

@@ -139,7 +139,7 @@ Blockly.Lua['lists_getIndex'] = function(block) {
var atOrder = (where == 'FROM_END') ? Blockly.Lua.ORDER_ADDITIVE :
Blockly.Lua.ORDER_NONE;
var at = Blockly.Lua.valueToCode(block, 'AT', atOrder) || '1';
var listVar = Blockly.Lua.variableDB_.getDistinctName(
var listVar = Blockly.Lua.nameDB_.getDistinctName(
'tmp_list', Blockly.VARIABLE_CATEGORY_NAME);
at = getIndex_(listVar, where, at);
var code = listVar + ' = ' + list + '\n' +
@@ -218,7 +218,7 @@ Blockly.Lua['lists_setIndex'] = function(block) {
!list.match(/^\w+$/)) {
// `list` is an expression, so we may not evaluate it more than once.
// We can use multiple statements.
var listVar = Blockly.Lua.variableDB_.getDistinctName(
var listVar = Blockly.Lua.nameDB_.getDistinctName(
'tmp_list', Blockly.VARIABLE_CATEGORY_NAME);
code = listVar + ' = ' + list + '\n';
list = listVar;

View File

@@ -60,7 +60,7 @@ Blockly.Lua['controls_repeat_ext'] = function(block) {
var branch = Blockly.Lua.statementToCode(block, 'DO');
branch = Blockly.Lua.addLoopTrap(branch, block);
branch = Blockly.Lua.addContinueLabel_(branch);
var loopVar = Blockly.Lua.variableDB_.getDistinctName(
var loopVar = Blockly.Lua.nameDB_.getDistinctName(
'count', Blockly.VARIABLE_CATEGORY_NAME);
var code = 'for ' + loopVar + ' = 1, ' + repeats + ' do\n' +
branch + 'end\n';
@@ -86,7 +86,7 @@ Blockly.Lua['controls_whileUntil'] = function(block) {
Blockly.Lua['controls_for'] = function(block) {
// For loop.
var variable0 = Blockly.Lua.variableDB_.getName(
var variable0 = Blockly.Lua.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var startVar = Blockly.Lua.valueToCode(block, 'FROM',
Blockly.Lua.ORDER_NONE) || '0';
@@ -109,7 +109,7 @@ Blockly.Lua['controls_for'] = function(block) {
code = '';
// Determine loop direction at start, in case one of the bounds
// changes during loop execution.
incValue = Blockly.Lua.variableDB_.getDistinctName(
incValue = Blockly.Lua.nameDB_.getDistinctName(
variable0 + '_inc', Blockly.VARIABLE_CATEGORY_NAME);
code += incValue + ' = ';
if (Blockly.isNumber(increment)) {
@@ -129,7 +129,7 @@ Blockly.Lua['controls_for'] = function(block) {
Blockly.Lua['controls_forEach'] = function(block) {
// For each loop.
var variable0 = Blockly.Lua.variableDB_.getName(
var variable0 = Blockly.Lua.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.Lua.valueToCode(block, 'LIST',
Blockly.Lua.ORDER_NONE) || '{}';

View File

@@ -196,7 +196,7 @@ Blockly.Lua['math_change'] = function(block) {
// Add to a variable in place.
var argument0 = Blockly.Lua.valueToCode(block, 'DELTA',
Blockly.Lua.ORDER_ADDITIVE) || '0';
var varName = Blockly.Lua.variableDB_.getName(
var varName = Blockly.Lua.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = ' + varName + ' + ' + argument0 + '\n';
};

View File

@@ -17,7 +17,7 @@ goog.require('Blockly.Lua');
Blockly.Lua['procedures_defreturn'] = function(block) {
// Define a procedure with a return value.
var funcName = Blockly.Lua.variableDB_.getName(
var funcName = Blockly.Lua.nameDB_.getName(
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
var xfix1 = '';
if (Blockly.Lua.STATEMENT_PREFIX) {
@@ -51,7 +51,7 @@ Blockly.Lua['procedures_defreturn'] = function(block) {
var args = [];
var variables = block.getVars();
for (var i = 0; i < variables.length; i++) {
args[i] = Blockly.Lua.variableDB_.getName(variables[i],
args[i] = Blockly.Lua.nameDB_.getName(variables[i],
Blockly.VARIABLE_CATEGORY_NAME);
}
var code = 'function ' + funcName + '(' + args.join(', ') + ')\n' +
@@ -69,7 +69,7 @@ Blockly.Lua['procedures_defnoreturn'] =
Blockly.Lua['procedures_callreturn'] = function(block) {
// Call a procedure with a return value.
var funcName = Blockly.Lua.variableDB_.getName(
var funcName = Blockly.Lua.nameDB_.getName(
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
var args = [];
var variables = block.getVars();

View File

@@ -58,7 +58,7 @@ Blockly.Lua['text_join'] = function(block) {
Blockly.Lua['text_append'] = function(block) {
// Append to a variable in place.
var varName = Blockly.Lua.variableDB_.getName(
var varName = Blockly.Lua.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var value = Blockly.Lua.valueToCode(block, 'TEXT',
Blockly.Lua.ORDER_CONCATENATION) || '\'\'';

View File

@@ -17,7 +17,7 @@ goog.require('Blockly.Lua');
Blockly.Lua['variables_get'] = function(block) {
// Variable getter.
var code = Blockly.Lua.variableDB_.getName(block.getFieldValue('VAR'),
var code = Blockly.Lua.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return [code, Blockly.Lua.ORDER_ATOMIC];
};
@@ -26,7 +26,7 @@ Blockly.Lua['variables_set'] = function(block) {
// Variable setter.
var argument0 = Blockly.Lua.valueToCode(block, 'VALUE',
Blockly.Lua.ORDER_NONE) || '0';
var varName = Blockly.Lua.variableDB_.getName(
var varName = Blockly.Lua.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = ' + argument0 + '\n';
};

View File

@@ -135,27 +135,27 @@ Blockly.PHP.init = function(workspace) {
// to actual function names (to avoid collisions with user functions).
Blockly.PHP.functionNames_ = Object.create(null);
if (!Blockly.PHP.variableDB_) {
Blockly.PHP.variableDB_ =
if (!Blockly.PHP.nameDB_) {
Blockly.PHP.nameDB_ =
new Blockly.Names(Blockly.PHP.RESERVED_WORDS_, '$');
} else {
Blockly.PHP.variableDB_.reset();
Blockly.PHP.nameDB_.reset();
}
Blockly.PHP.variableDB_.setVariableMap(workspace.getVariableMap());
Blockly.PHP.nameDB_.setVariableMap(workspace.getVariableMap());
var defvars = [];
// 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],
defvars.push(Blockly.PHP.nameDB_.getName(devVarList[i],
Blockly.Names.DEVELOPER_VARIABLE_TYPE) + ';');
}
// Add user variables, but only ones that are being used.
var variables = Blockly.Variables.allUsedVarModels(workspace);
for (var i = 0, variable; variable = variables[i]; i++) {
defvars.push(Blockly.PHP.variableDB_.getName(variable.getId(),
defvars.push(Blockly.PHP.nameDB_.getName(variable.getId(),
Blockly.VARIABLE_CATEGORY_NAME) + ';');
}
@@ -178,7 +178,7 @@ Blockly.PHP.finish = function(code) {
// Clean up temporary data.
delete Blockly.PHP.definitions_;
delete Blockly.PHP.functionNames_;
Blockly.PHP.variableDB_.reset();
Blockly.PHP.nameDB_.reset();
return definitions.join('\n\n') + '\n\n\n' + code;
};

View File

@@ -257,7 +257,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
if (list.match(/^\$\w+$/)) {
return '';
}
var listVar = Blockly.PHP.variableDB_.getDistinctName(
var listVar = Blockly.PHP.nameDB_.getDistinctName(
'tmp_list', Blockly.VARIABLE_CATEGORY_NAME);
var code = listVar + ' = &' + list + ';\n';
list = listVar;
@@ -328,7 +328,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
var list = Blockly.PHP.valueToCode(block, 'LIST',
Blockly.PHP.ORDER_REFERENCE) || 'array()';
var code = cacheList();
var xVar = Blockly.PHP.variableDB_.getDistinctName(
var xVar = Blockly.PHP.nameDB_.getDistinctName(
'tmp_x', Blockly.VARIABLE_CATEGORY_NAME);
code += xVar + ' = rand(0, count(' + list + ')-1);\n';
if (mode == 'SET') {

View File

@@ -28,11 +28,11 @@ Blockly.PHP['controls_repeat_ext'] = function(block) {
var branch = Blockly.PHP.statementToCode(block, 'DO');
branch = Blockly.PHP.addLoopTrap(branch, block);
var code = '';
var loopVar = Blockly.PHP.variableDB_.getDistinctName(
var loopVar = Blockly.PHP.nameDB_.getDistinctName(
'count', Blockly.VARIABLE_CATEGORY_NAME);
var endVar = repeats;
if (!repeats.match(/^\w+$/) && !Blockly.isNumber(repeats)) {
endVar = Blockly.PHP.variableDB_.getDistinctName(
endVar = Blockly.PHP.nameDB_.getDistinctName(
'repeat_end', Blockly.VARIABLE_CATEGORY_NAME);
code += endVar + ' = ' + repeats + ';\n';
}
@@ -61,7 +61,7 @@ Blockly.PHP['controls_whileUntil'] = function(block) {
Blockly.PHP['controls_for'] = function(block) {
// For loop.
var variable0 = Blockly.PHP.variableDB_.getName(
var variable0 = Blockly.PHP.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.PHP.valueToCode(block, 'FROM',
Blockly.PHP.ORDER_ASSIGNMENT) || '0';
@@ -91,19 +91,19 @@ Blockly.PHP['controls_for'] = function(block) {
// Cache non-trivial values to variables to prevent repeated look-ups.
var startVar = argument0;
if (!argument0.match(/^\w+$/) && !Blockly.isNumber(argument0)) {
startVar = Blockly.PHP.variableDB_.getDistinctName(
startVar = Blockly.PHP.nameDB_.getDistinctName(
variable0 + '_start', Blockly.VARIABLE_CATEGORY_NAME);
code += startVar + ' = ' + argument0 + ';\n';
}
var endVar = argument1;
if (!argument1.match(/^\w+$/) && !Blockly.isNumber(argument1)) {
endVar = Blockly.PHP.variableDB_.getDistinctName(
endVar = Blockly.PHP.nameDB_.getDistinctName(
variable0 + '_end', Blockly.VARIABLE_CATEGORY_NAME);
code += endVar + ' = ' + argument1 + ';\n';
}
// Determine loop direction at start, in case one of the bounds
// changes during loop execution.
var incVar = Blockly.PHP.variableDB_.getDistinctName(
var incVar = Blockly.PHP.nameDB_.getDistinctName(
variable0 + '_inc', Blockly.VARIABLE_CATEGORY_NAME);
code += incVar + ' = ';
if (Blockly.isNumber(increment)) {
@@ -126,7 +126,7 @@ Blockly.PHP['controls_for'] = function(block) {
Blockly.PHP['controls_forEach'] = function(block) {
// For each loop.
var variable0 = Blockly.PHP.variableDB_.getName(
var variable0 = Blockly.PHP.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.PHP.valueToCode(block, 'LIST',
Blockly.PHP.ORDER_ASSIGNMENT) || '[]';

View File

@@ -205,7 +205,7 @@ Blockly.PHP['math_change'] = function(block) {
// Add to a variable in place.
var argument0 = Blockly.PHP.valueToCode(block, 'DELTA',
Blockly.PHP.ORDER_ADDITION) || '0';
var varName = Blockly.PHP.variableDB_.getName(
var varName = Blockly.PHP.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' += ' + argument0 + ';\n';
};

View File

@@ -25,20 +25,20 @@ Blockly.PHP['procedures_defreturn'] = function(block) {
for (var i = 0, variable; variable = variables[i]; i++) {
varName = variable.name;
if (block.getVars().indexOf(varName) == -1) {
globals.push(Blockly.PHP.variableDB_.getName(varName,
globals.push(Blockly.PHP.nameDB_.getName(varName,
Blockly.VARIABLE_CATEGORY_NAME));
}
}
// Add developer variables.
var devVarList = Blockly.Variables.allDeveloperVariables(workspace);
for (var i = 0; i < devVarList.length; i++) {
globals.push(Blockly.PHP.variableDB_.getName(devVarList[i],
globals.push(Blockly.PHP.nameDB_.getName(devVarList[i],
Blockly.Names.DEVELOPER_VARIABLE_TYPE));
}
globals = globals.length ?
Blockly.PHP.INDENT + 'global ' + globals.join(', ') + ';\n' : '';
var funcName = Blockly.PHP.variableDB_.getName(
var funcName = Blockly.PHP.nameDB_.getName(
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
var xfix1 = '';
if (Blockly.PHP.STATEMENT_PREFIX) {
@@ -70,7 +70,7 @@ Blockly.PHP['procedures_defreturn'] = function(block) {
var args = [];
var variables = block.getVars();
for (var i = 0; i < variables.length; i++) {
args[i] = Blockly.PHP.variableDB_.getName(variables[i],
args[i] = Blockly.PHP.nameDB_.getName(variables[i],
Blockly.VARIABLE_CATEGORY_NAME);
}
var code = 'function ' + funcName + '(' + args.join(', ') + ') {\n' +
@@ -88,7 +88,7 @@ Blockly.PHP['procedures_defnoreturn'] =
Blockly.PHP['procedures_callreturn'] = function(block) {
// Call a procedure with a return value.
var funcName = Blockly.PHP.variableDB_.getName(
var funcName = Blockly.PHP.nameDB_.getName(
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
var args = [];
var variables = block.getVars();

View File

@@ -58,7 +58,7 @@ Blockly.PHP['text_join'] = function(block) {
Blockly.PHP['text_append'] = function(block) {
// Append to a variable in place.
var varName = Blockly.PHP.variableDB_.getName(
var varName = Blockly.PHP.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var value = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_ASSIGNMENT) || '\'\'';

View File

@@ -17,7 +17,7 @@ goog.require('Blockly.PHP');
Blockly.PHP['variables_get'] = function(block) {
// Variable getter.
var code = Blockly.PHP.variableDB_.getName(block.getFieldValue('VAR'),
var code = Blockly.PHP.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return [code, Blockly.PHP.ORDER_ATOMIC];
};
@@ -26,7 +26,7 @@ Blockly.PHP['variables_set'] = function(block) {
// Variable setter.
var argument0 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_ASSIGNMENT) || '0';
var varName = Blockly.PHP.variableDB_.getName(
var varName = Blockly.PHP.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = ' + argument0 + ';\n';
};

View File

@@ -148,27 +148,27 @@ Blockly.Python.init = function(workspace) {
// to actual function names (to avoid collisions with user functions).
Blockly.Python.functionNames_ = Object.create(null);
if (!Blockly.Python.variableDB_) {
Blockly.Python.variableDB_ =
if (!Blockly.Python.nameDB_) {
Blockly.Python.nameDB_ =
new Blockly.Names(Blockly.Python.RESERVED_WORDS_);
} else {
Blockly.Python.variableDB_.reset();
Blockly.Python.nameDB_.reset();
}
Blockly.Python.variableDB_.setVariableMap(workspace.getVariableMap());
Blockly.Python.nameDB_.setVariableMap(workspace.getVariableMap());
var defvars = [];
// 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],
defvars.push(Blockly.Python.nameDB_.getName(devVarList[i],
Blockly.Names.DEVELOPER_VARIABLE_TYPE) + ' = None');
}
// Add user variables, but only ones that are being used.
var variables = Blockly.Variables.allUsedVarModels(workspace);
for (var i = 0; i < variables.length; i++) {
defvars.push(Blockly.Python.variableDB_.getName(variables[i].getId(),
defvars.push(Blockly.Python.nameDB_.getName(variables[i].getId(),
Blockly.VARIABLE_CATEGORY_NAME) + ' = None');
}
@@ -196,7 +196,7 @@ Blockly.Python.finish = function(code) {
// Clean up temporary data.
delete Blockly.Python.definitions_;
delete Blockly.Python.functionNames_;
Blockly.Python.variableDB_.reset();
Blockly.Python.nameDB_.reset();
var allDefs = imports.join('\n') + '\n\n' + definitions.join('\n\n');
return allDefs.replace(/\n\n+/g, '\n\n').replace(/\n*$/, '\n\n\n') + code;
};

View File

@@ -187,7 +187,7 @@ Blockly.Python['lists_setIndex'] = function(block) {
if (list.match(/^\w+$/)) {
return '';
}
var listVar = Blockly.Python.variableDB_.getDistinctName(
var listVar = Blockly.Python.nameDB_.getDistinctName(
'tmp_list', Blockly.VARIABLE_CATEGORY_NAME);
var code = listVar + ' = ' + list + '\n';
list = listVar;
@@ -228,7 +228,7 @@ Blockly.Python['lists_setIndex'] = function(block) {
case 'RANDOM':
Blockly.Python.definitions_['import_random'] = 'import random';
var code = cacheList();
var xVar = Blockly.Python.variableDB_.getDistinctName(
var xVar = Blockly.Python.nameDB_.getDistinctName(
'tmp_x', Blockly.VARIABLE_CATEGORY_NAME);
code += xVar + ' = int(random.random() * len(' + list + '))\n';
if (mode == 'SET') {

View File

@@ -32,7 +32,7 @@ Blockly.Python['controls_repeat_ext'] = function(block) {
}
var branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block) || Blockly.Python.PASS;
var loopVar = Blockly.Python.variableDB_.getDistinctName(
var loopVar = Blockly.Python.nameDB_.getDistinctName(
'count', Blockly.VARIABLE_CATEGORY_NAME);
var code = 'for ' + loopVar + ' in range(' + repeats + '):\n' + branch;
return code;
@@ -56,7 +56,7 @@ Blockly.Python['controls_whileUntil'] = function(block) {
Blockly.Python['controls_for'] = function(block) {
// For loop.
var variable0 = Blockly.Python.variableDB_.getName(
var variable0 = Blockly.Python.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.Python.valueToCode(block, 'FROM',
Blockly.Python.ORDER_NONE) || '0';
@@ -143,7 +143,7 @@ Blockly.Python['controls_for'] = function(block) {
arg = 'float(' + arg + ')';
} else {
// It's complicated.
var varName = Blockly.Python.variableDB_.getDistinctName(
var varName = Blockly.Python.nameDB_.getDistinctName(
variable0 + suffix, Blockly.VARIABLE_CATEGORY_NAME);
code += varName + ' = float(' + arg + ')\n';
arg = varName;
@@ -172,7 +172,7 @@ Blockly.Python['controls_for'] = function(block) {
Blockly.Python['controls_forEach'] = function(block) {
// For each loop.
var variable0 = Blockly.Python.variableDB_.getName(
var variable0 = Blockly.Python.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
var argument0 = Blockly.Python.valueToCode(block, 'LIST',
Blockly.Python.ORDER_RELATIONAL) || '[]';

View File

@@ -226,7 +226,7 @@ Blockly.Python['math_change'] = function(block) {
'from numbers import Number';
var argument0 = Blockly.Python.valueToCode(block, 'DELTA',
Blockly.Python.ORDER_ADDITIVE) || '0';
var varName = Blockly.Python.variableDB_.getName(block.getFieldValue('VAR'),
var varName = Blockly.Python.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = (' + varName + ' if isinstance(' + varName +
', Number) else 0) + ' + argument0 + '\n';

View File

@@ -26,20 +26,20 @@ Blockly.Python['procedures_defreturn'] = function(block) {
for (var i = 0, variable; variable = variables[i]; i++) {
varName = variable.name;
if (block.getVars().indexOf(varName) == -1) {
globals.push(Blockly.Python.variableDB_.getName(varName,
globals.push(Blockly.Python.nameDB_.getName(varName,
Blockly.VARIABLE_CATEGORY_NAME));
}
}
// Add developer variables.
var devVarList = Blockly.Variables.allDeveloperVariables(workspace);
for (var i = 0; i < devVarList.length; i++) {
globals.push(Blockly.Python.variableDB_.getName(devVarList[i],
globals.push(Blockly.Python.nameDB_.getName(devVarList[i],
Blockly.Names.DEVELOPER_VARIABLE_TYPE));
}
globals = globals.length ?
Blockly.Python.INDENT + 'global ' + globals.join(', ') + '\n' : '';
var funcName = Blockly.Python.variableDB_.getName(
var funcName = Blockly.Python.nameDB_.getName(
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
var xfix1 = '';
if (Blockly.Python.STATEMENT_PREFIX) {
@@ -73,7 +73,7 @@ Blockly.Python['procedures_defreturn'] = function(block) {
var args = [];
var variables = block.getVars();
for (var i = 0; i < variables.length; i++) {
args[i] = Blockly.Python.variableDB_.getName(variables[i],
args[i] = Blockly.Python.nameDB_.getName(variables[i],
Blockly.VARIABLE_CATEGORY_NAME);
}
var code = 'def ' + funcName + '(' + args.join(', ') + '):\n' +
@@ -91,7 +91,7 @@ Blockly.Python['procedures_defnoreturn'] =
Blockly.Python['procedures_callreturn'] = function(block) {
// Call a procedure with a return value.
var funcName = Blockly.Python.variableDB_.getName(block.getFieldValue('NAME'),
var funcName = Blockly.Python.nameDB_.getName(block.getFieldValue('NAME'),
Blockly.PROCEDURE_CATEGORY_NAME);
var args = [];
var variables = block.getVars();

View File

@@ -77,7 +77,7 @@ Blockly.Python['text_join'] = function(block) {
elements[i] = Blockly.Python.valueToCode(block, 'ADD' + i,
Blockly.Python.ORDER_NONE) || '\'\'';
}
var tempVar = Blockly.Python.variableDB_.getDistinctName('x',
var tempVar = Blockly.Python.nameDB_.getDistinctName('x',
Blockly.VARIABLE_CATEGORY_NAME);
var code = '\'\'.join([str(' + tempVar + ') for ' + tempVar + ' in [' +
elements.join(', ') + ']])';
@@ -87,7 +87,7 @@ Blockly.Python['text_join'] = function(block) {
Blockly.Python['text_append'] = function(block) {
// Append to a variable in place.
var varName = Blockly.Python.variableDB_.getName(block.getFieldValue('VAR'),
var varName = Blockly.Python.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
var value = Blockly.Python.valueToCode(block, 'TEXT',
Blockly.Python.ORDER_NONE) || '\'\'';

View File

@@ -17,7 +17,7 @@ goog.require('Blockly.Python');
Blockly.Python['variables_get'] = function(block) {
// Variable getter.
var code = Blockly.Python.variableDB_.getName(block.getFieldValue('VAR'),
var code = Blockly.Python.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return [code, Blockly.Python.ORDER_ATOMIC];
};
@@ -26,7 +26,7 @@ Blockly.Python['variables_set'] = function(block) {
// Variable setter.
var argument0 = Blockly.Python.valueToCode(block, 'VALUE',
Blockly.Python.ORDER_NONE) || '0';
var varName = Blockly.Python.variableDB_.getName(block.getFieldValue('VAR'),
var varName = Blockly.Python.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = ' + argument0 + '\n';
};

View File

@@ -12,7 +12,7 @@
Blockly.Dart['unittest_main'] = function(block) {
// Container for unit tests.
var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.Dart.provideFunction_(
'unittest_report',
@@ -61,7 +61,7 @@ Blockly.Dart['unittest_main'] = function(block) {
};
Blockly.Dart['unittest_main'].defineAssert_ = function() {
var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.Dart.provideFunction_(
'unittest_assertequals',
@@ -129,7 +129,7 @@ Blockly.Dart['unittest_assertvalue'] = function(block) {
Blockly.Dart['unittest_fail'] = function(block) {
// Always assert an error.
var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var message = Blockly.Dart.quote_(block.getFieldValue('MESSAGE'));
var functionName = Blockly.Dart.provideFunction_(

View File

@@ -12,7 +12,7 @@
Blockly.JavaScript['unittest_main'] = function(block) {
// Container for unit tests.
var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults',
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.JavaScript.provideFunction_(
'unittest_report',
@@ -62,7 +62,7 @@ Blockly.JavaScript['unittest_main'] = function(block) {
};
Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) {
var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults',
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.JavaScript.provideFunction_(
'assertEquals',
@@ -133,7 +133,7 @@ Blockly.JavaScript['unittest_assertvalue'] = function(block) {
Blockly.JavaScript['unittest_fail'] = function(block) {
// Always assert an error.
var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults',
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var message = Blockly.JavaScript.quote_(block.getFieldValue('MESSAGE'));
var functionName = Blockly.JavaScript.provideFunction_(

View File

@@ -12,7 +12,7 @@
Blockly.Lua['unittest_main'] = function(block) {
// Container for unit tests.
var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.Lua.provideFunction_(
'unittest_report',
@@ -60,7 +60,7 @@ Blockly.Lua['unittest_main'] = function(block) {
};
Blockly.Lua['unittest_main'].defineAssert_ = function(block) {
var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.Lua.provideFunction_(
'assertEquals',
@@ -139,7 +139,7 @@ Blockly.Lua['unittest_assertvalue'] = function(block) {
Blockly.Lua['unittest_fail'] = function(block) {
// Always assert an error.
var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var message = Blockly.Lua.quote_(block.getFieldValue('MESSAGE'));
var functionName = Blockly.Lua.provideFunction_(

View File

@@ -12,7 +12,7 @@
Blockly.PHP['unittest_main'] = function(block) {
// Container for unit tests.
var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults',
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.PHP.provideFunction_(
'unittest_report',
@@ -62,7 +62,7 @@ Blockly.PHP['unittest_main'] = function(block) {
};
Blockly.PHP['unittest_main'].defineAssert_ = function(block) {
var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults',
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.PHP.provideFunction_(
'assertEquals',
@@ -119,7 +119,7 @@ Blockly.PHP['unittest_assertvalue'] = function(block) {
Blockly.PHP['unittest_fail'] = function(block) {
// Always assert an error.
var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults',
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var message = Blockly.PHP.quote_(block.getFieldValue('MESSAGE'));
var functionName = Blockly.PHP.provideFunction_(

View File

@@ -12,7 +12,7 @@
Blockly.Python['unittest_main'] = function(block) {
// Container for unit tests.
var resultsVar = Blockly.Python.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.Python.provideFunction_(
'unittest_report',
@@ -58,7 +58,7 @@ Blockly.Python['unittest_main'] = function(block) {
};
Blockly.Python['unittest_main'].defineAssert_ = function() {
var resultsVar = Blockly.Python.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var functionName = Blockly.Python.provideFunction_(
'assertEquals',
@@ -107,7 +107,7 @@ Blockly.Python['unittest_assertvalue'] = function(block) {
Blockly.Python['unittest_fail'] = function(block) {
// Always assert an error.
var resultsVar = Blockly.Python.variableDB_.getName('unittestResults',
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
var message = Blockly.Python.quote_(block.getFieldValue('MESSAGE'));
var functionName = Blockly.Python.provideFunction_(