mirror of
https://github.com/google/blockly.git
synced 2026-01-06 16:40:07 +01:00
Add procedures to name DB in init
This enables the generator for any block to see all variable names and procedure names in the whole program, including those that haven’t generated yet.
This commit is contained in:
@@ -513,8 +513,8 @@ Blockly.Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) {
|
|||||||
Blockly.Generator.prototype.finish = function(code) {
|
Blockly.Generator.prototype.finish = function(code) {
|
||||||
// Optionally override
|
// Optionally override
|
||||||
// Clean up temporary data.
|
// Clean up temporary data.
|
||||||
delete Blockly.JavaScript.definitions_;
|
delete this.definitions_;
|
||||||
delete Blockly.JavaScript.functionNames_;
|
delete this.functionNames_;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Blockly.utils.Metrics
|
||||||
|
* @namespace
|
||||||
|
*/
|
||||||
goog.provide('Blockly.utils.Metrics');
|
goog.provide('Blockly.utils.Metrics');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,14 @@ Blockly.Dart.init = function(workspace) {
|
|||||||
Blockly.VARIABLE_CATEGORY_NAME));
|
Blockly.VARIABLE_CATEGORY_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add user procedures.
|
||||||
|
var procedures = Blockly.Procedures.allProcedures(workspace);
|
||||||
|
// Flatten the return vs no-return procedure lists.
|
||||||
|
procedures = procedures[0].concat(procedures[1]);
|
||||||
|
for (var i = 0; i < procedures.length; i++) {
|
||||||
|
this.nameDB_.getName(procedures[i][0], Blockly.PROCEDURE_CATEGORY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
// Declare all of the variables.
|
// Declare all of the variables.
|
||||||
if (defvars.length) {
|
if (defvars.length) {
|
||||||
this.definitions_['variables'] =
|
this.definitions_['variables'] =
|
||||||
|
|||||||
@@ -152,6 +152,14 @@ Blockly.JavaScript.init = function(workspace) {
|
|||||||
Blockly.VARIABLE_CATEGORY_NAME));
|
Blockly.VARIABLE_CATEGORY_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add user procedures.
|
||||||
|
var procedures = Blockly.Procedures.allProcedures(workspace);
|
||||||
|
// Flatten the return vs no-return procedure lists.
|
||||||
|
procedures = procedures[0].concat(procedures[1]);
|
||||||
|
for (var i = 0; i < procedures.length; i++) {
|
||||||
|
this.nameDB_.getName(procedures[i][0], Blockly.PROCEDURE_CATEGORY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
// Declare all of the variables.
|
// Declare all of the variables.
|
||||||
if (defvars.length) {
|
if (defvars.length) {
|
||||||
this.definitions_['variables'] = 'var ' + defvars.join(', ') + ';';
|
this.definitions_['variables'] = 'var ' + defvars.join(', ') + ';';
|
||||||
|
|||||||
@@ -101,6 +101,15 @@ Blockly.Lua.init = function(workspace) {
|
|||||||
this.nameDB_.reset();
|
this.nameDB_.reset();
|
||||||
}
|
}
|
||||||
this.nameDB_.setVariableMap(workspace.getVariableMap());
|
this.nameDB_.setVariableMap(workspace.getVariableMap());
|
||||||
|
|
||||||
|
// Add user procedures.
|
||||||
|
var procedures = Blockly.Procedures.allProcedures(workspace);
|
||||||
|
// Flatten the return vs no-return procedure lists.
|
||||||
|
procedures = procedures[0].concat(procedures[1]);
|
||||||
|
for (var i = 0; i < procedures.length; i++) {
|
||||||
|
this.nameDB_.getName(procedures[i][0], Blockly.PROCEDURE_CATEGORY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -156,6 +156,14 @@ Blockly.PHP.init = function(workspace) {
|
|||||||
Blockly.VARIABLE_CATEGORY_NAME) + ';');
|
Blockly.VARIABLE_CATEGORY_NAME) + ';');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add user procedures.
|
||||||
|
var procedures = Blockly.Procedures.allProcedures(workspace);
|
||||||
|
// Flatten the return vs no-return procedure lists.
|
||||||
|
procedures = procedures[0].concat(procedures[1]);
|
||||||
|
for (var i = 0; i < procedures.length; i++) {
|
||||||
|
this.nameDB_.getName(procedures[i][0], Blockly.PROCEDURE_CATEGORY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
// Declare all of the variables.
|
// Declare all of the variables.
|
||||||
this.definitions_['variables'] = defvars.join('\n');
|
this.definitions_['variables'] = defvars.join('\n');
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
|
|||||||
@@ -169,6 +169,14 @@ Blockly.Python.init = function(workspace) {
|
|||||||
Blockly.VARIABLE_CATEGORY_NAME) + ' = None');
|
Blockly.VARIABLE_CATEGORY_NAME) + ' = None');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add user procedures.
|
||||||
|
var procedures = Blockly.Procedures.allProcedures(workspace);
|
||||||
|
// Flatten the return vs no-return procedure lists.
|
||||||
|
procedures = procedures[0].concat(procedures[1]);
|
||||||
|
for (var i = 0; i < procedures.length; i++) {
|
||||||
|
this.nameDB_.getName(procedures[i][0], Blockly.PROCEDURE_CATEGORY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
this.definitions_['variables'] = defvars.join('\n');
|
this.definitions_['variables'] = defvars.join('\n');
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user