Remove unneeded check in Arduino generator as per...

Remove unneeded check in Arduino generator as per carlospamg/ardublockly@c400ca83-b69d-9dd7-9705-49c6b8615e23
parent c1fedcff
...@@ -110,46 +110,45 @@ Blockly.Arduino.init = function() { ...@@ -110,46 +110,45 @@ Blockly.Arduino.init = function() {
Blockly.Arduino.setups_ = Object.create(null); Blockly.Arduino.setups_ = Object.create(null);
// Create a dictionary of pins to check if their use conflict // Create a dictionary of pins to check if their use conflict
Blockly.Arduino.pins_ = Object.create(null); Blockly.Arduino.pins_ = Object.create(null);
if (!Blockly.Arduino.variableDB_) {
Blockly.Arduino.variableDB_ = new Blockly.Names(Blockly.Arduino.RESERVED_WORDS_);
} else {
Blockly.Arduino.variableDB_.reset();
}
if (Blockly.Variables) { // Iterate through the blocks to capture variables with first value
if (!Blockly.Arduino.variableDB_) { var variableWithType = Object.create(null);
Blockly.Arduino.variableDB_ = new Blockly.Names(Blockly.Arduino.RESERVED_WORDS_); var blocks = Blockly.mainWorkspace.getAllBlocks();
} else { for (var x = 0; x < blocks.length; x++) {
Blockly.Arduino.variableDB_.reset(); var func = blocks[x].getVars;
} if (func) {
var blockVariables = func.call(blocks[x]);
// Iterate through the blocks to capture variables with first value for (var y = 0; y < blockVariables.length; y++) {
var variableWithType = Object.create(null); // Check if it's the first instance of the new variable name
var blocks = Blockly.mainWorkspace.getAllBlocks(); var unique = true;
for (var x = 0; x < blocks.length; x++) { for (var name in variableWithType) {
var func = blocks[x].getVars; if (name == blockVariables[y]) {
if (func) { unique = false;
var blockVariables = func.call(blocks[x]); break;
for (var y = 0; y < blockVariables.length; y++) {
// Check if it's the first instance of the new variable name
var unique = true;
for (var name in variableWithType) {
if (name == blockVariables[y]) {
unique = false;
break;
}
}
// If it is the first instance log the variable type
if (unique == true) {
variableWithType[blockVariables[y]] = Blockly.Arduino.evaluateType(
Blockly.Arduino.valueToCode(blocks[x], 'VALUE', Blockly.Arduino.ORDER_ASSIGNMENT));
} }
} }
// If it is the first instance log the variable type
if (unique == true) {
variableWithType[blockVariables[y]] = Blockly.Arduino.evaluateType(
Blockly.Arduino.valueToCode(blocks[x], 'VALUE', Blockly.Arduino.ORDER_ASSIGNMENT));
}
} }
} }
}
// Set variable declarations // Set variable declarations
var variableDeclarations = []; var variableDeclarations = [];
for (var name in variableWithType) { for (var name in variableWithType) {
variableDeclarations.push(variableWithType[name] + ' ' + name + ';'); variableDeclarations.push(variableWithType[name] + ' ' + name + ';');
}
Blockly.Arduino.definitions_['variables'] = variableDeclarations.join('\n') + '\n';
} }
Blockly.Arduino.definitions_['variables'] = variableDeclarations.join('\n') + '\n';
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment