mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
feat: add getVariableName and getProcedureName to CodeGenerator (#7445)
* feat: add getVariableName and getProcedureName to CodeGenerator * feat: make nameDB_ public * feat: update block code generators to use new APIs * chore: fix build * chore: remove unused imports
This commit is contained in:
committed by
GitHub
parent
b0a7c004a9
commit
68261e5dd9
@@ -22,10 +22,11 @@ export function procedures_defreturn(block, generator) {
|
||||
const globals = [];
|
||||
const workspace = block.workspace;
|
||||
const usedVariables = Variables.allUsedVarModels(workspace) || [];
|
||||
for (let i = 0, variable; (variable = usedVariables[i]); i++) {
|
||||
for (const variable of usedVariables) {
|
||||
const varName = variable.name;
|
||||
// getVars returns parameter names, not ids, for procedure blocks
|
||||
if (block.getVars().indexOf(varName) === -1) {
|
||||
globals.push(generator.nameDB_.getName(varName, NameType.VARIABLE));
|
||||
globals.push(generator.getVariableName(varName));
|
||||
}
|
||||
}
|
||||
// Add developer variables.
|
||||
@@ -40,8 +41,7 @@ export function procedures_defreturn(block, generator) {
|
||||
generator.INDENT + 'global ' + globals.join(', ') + '\n' :
|
||||
'';
|
||||
const funcName =
|
||||
generator.nameDB_.getName(
|
||||
block.getFieldValue('NAME'), NameType.PROCEDURE);
|
||||
generator.getProcedureName(block.getFieldValue('NAME'));
|
||||
let xfix1 = '';
|
||||
if (generator.STATEMENT_PREFIX) {
|
||||
xfix1 += generator.injectId(generator.STATEMENT_PREFIX, block);
|
||||
@@ -74,7 +74,7 @@ export function procedures_defreturn(block, generator) {
|
||||
const args = [];
|
||||
const variables = block.getVars();
|
||||
for (let i = 0; i < variables.length; i++) {
|
||||
args[i] = generator.nameDB_.getName(variables[i], NameType.VARIABLE);
|
||||
args[i] = generator.getVariableName(variables[i]);
|
||||
}
|
||||
let code = 'def ' + funcName + '(' + args.join(', ') + '):\n' + globalString +
|
||||
xfix1 + loopTrap + branch + xfix2 + returnValue;
|
||||
@@ -91,8 +91,7 @@ export const procedures_defnoreturn = procedures_defreturn;
|
||||
export function procedures_callreturn(block, generator) {
|
||||
// Call a procedure with a return value.
|
||||
const funcName =
|
||||
generator.nameDB_.getName(
|
||||
block.getFieldValue('NAME'), NameType.PROCEDURE);
|
||||
generator.getProcedureName(block.getFieldValue('NAME'));
|
||||
const args = [];
|
||||
const variables = block.getVars();
|
||||
for (let i = 0; i < variables.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user