Skip to content

Commit

Permalink
Static Typing: Remove "basic types", all Blockly.Types define a uniqu…
Browse files Browse the repository at this point in the history
…e type.

Now all Blockly.Types can be used indiscriminately.
The original basicTypes were introduced to maintain some level of compatibility with the original Blockly blocks type assignment for block outputs and checks. Since all the blocks have to be modified anyway, it does not make sense to keep this old rule.
  • Loading branch information
carlosperate committed Mar 29, 2016
1 parent 82ec3c0 commit 8c04540
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 182 deletions.
12 changes: 6 additions & 6 deletions blockly/blocks/arduino/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Blockly.Blocks['io_digitalwrite'] = {
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.digitalPins), 'PIN')
.appendField(Blockly.Msg.ARD_WRITE_TO)
.setCheck(Blockly.Types.BOOLEAN.compatibles());
.setCheck(Blockly.Types.BOOLEAN.check);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
Expand Down Expand Up @@ -61,7 +61,7 @@ Blockly.Blocks['io_digitalread'] = {
.appendField(Blockly.Msg.ARD_DIGITALREAD)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.digitalPins), 'PIN');
this.setOutput(true, Blockly.Types.BOOLEAN.basicType);
this.setOutput(true, Blockly.Types.BOOLEAN.output);
this.setTooltip(Blockly.Msg.ARD_DIGITALREAD_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
Expand Down Expand Up @@ -91,7 +91,7 @@ Blockly.Blocks['io_builtin_led'] = {
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.builtinLed), 'BUILT_IN_LED')
.appendField('to')
.setCheck(Blockly.Types.BOOLEAN.compatibles());
.setCheck(Blockly.Types.BOOLEAN.check);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
Expand Down Expand Up @@ -124,7 +124,7 @@ Blockly.Blocks['io_analogwrite'] = {
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.pwmPins), 'PIN')
.appendField(Blockly.Msg.ARD_WRITE_TO)
.setCheck(Blockly.Types.NUMBER.basicType);
.setCheck(Blockly.Types.NUMBER.output);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
Expand Down Expand Up @@ -155,7 +155,7 @@ Blockly.Blocks['io_analogread'] = {
.appendField(Blockly.Msg.ARD_ANALOGREAD)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.analogPins), 'PIN');
this.setOutput(true, Blockly.Types.NUMBER.basicType);
this.setOutput(true, Blockly.Types.NUMBER.output);
this.setTooltip(Blockly.Msg.ARD_ANALOGREAD_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
Expand Down Expand Up @@ -183,7 +183,7 @@ Blockly.Blocks['io_highlow'] = {
.appendField(
new Blockly.FieldDropdown([[Blockly.Msg.ARD_HIGH, 'HIGH'], [Blockly.Msg.ARD_LOW, 'LOW']]),
'STATE');
this.setOutput(true, Blockly.Types.BOOLEAN.basicType);
this.setOutput(true, Blockly.Types.BOOLEAN.output);
this.setTooltip(Blockly.Msg.ARD_HIGHLOW_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
Expand Down
4 changes: 2 additions & 2 deletions blockly/blocks/arduino/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ Blockly.Blocks['base_map'] = {
this.setColour(Blockly.Blocks.map.HUE);
this.appendValueInput('NUM')
.appendField(Blockly.Msg.ARD_MAP)
.setCheck(Blockly.Types.NUMBER.compatibles());
.setCheck(Blockly.Types.NUMBER.checkList);
this.appendValueInput('DMAX')
.appendField(Blockly.Msg.ARD_MAP_VAL)
.setCheck(Blockly.Types.NUMBER.compatibles());
.setCheck(Blockly.Types.NUMBER.checkList);
this.appendDummyInput()
.appendField(']');
this.setInputsInline(true);
Expand Down
2 changes: 1 addition & 1 deletion blockly/blocks/arduino/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Blockly.Blocks['serial_print'] = {
Blockly.Arduino.Boards.selected.serial), 'SERIAL_ID')
.appendField(Blockly.Msg.ARD_SERIAL_PRINT);
this.appendValueInput('CONTENT')
.setCheck(Blockly.Types.TEXT.compatibles());
.setCheck(Blockly.Types.TEXT.checkList);
this.appendDummyInput()
.appendField(new Blockly.FieldCheckbox('TRUE'), 'NEW_LINE')
.appendField(Blockly.Msg.ARD_SERIAL_PRINT_NEWLINE);
Expand Down
4 changes: 2 additions & 2 deletions blockly/blocks/arduino/servo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Blockly.Blocks['servo_write'] = {
Blockly.Arduino.Boards.selected.pwmPins), 'SERVO_PIN');
this.setInputsInline(false);
this.appendValueInput('SERVO_ANGLE')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.appendField(Blockly.Msg.ARD_SERVO_WRITE_TO);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_SERVO_WRITE_DEG_180);
Expand Down Expand Up @@ -66,7 +66,7 @@ Blockly.Blocks['servo_read'] = {
.appendField(Blockly.Msg.ARD_SERVO_READ)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.pwmPins), 'SERVO_PIN');
this.setOutput(true, Blockly.Types.NUMBER.basicType);
this.setOutput(true, Blockly.Types.NUMBER.output);
this.setTooltip(Blockly.Msg.ARD_SERVO_READ_TIP);
},
/** @return {string} The type of return value for the block, an integer. */
Expand Down
2 changes: 1 addition & 1 deletion blockly/blocks/arduino/spi.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Blockly.Blocks['spi_transfer'] = {
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.spi), 'SPI_ID');
this.appendValueInput('SPI_DATA')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.appendField(Blockly.Msg.ARD_SPI_TRANS_VAL);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_SPI_TRANS_SLAVE)
Expand Down
6 changes: 3 additions & 3 deletions blockly/blocks/arduino/stepper.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ Blockly.Blocks['stepper_config'] = {
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.digitalPins), 'STEPPER_PIN2');
this.appendValueInput('STEPPER_STEPS')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.ARD_STEPPER_REVOLVS);
this.appendValueInput('STEPPER_SPEED')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.ARD_STEPPER_SPEED);
this.setTooltip(Blockly.Msg.ARD_STEPPER_SETUP_TIP);
Expand Down Expand Up @@ -156,7 +156,7 @@ Blockly.Blocks['stepper_step'] = {
.appendField(new Blockly.Blocks.stepper.FieldStepperInstance(),
'STEPPER_NAME');
this.appendValueInput('STEPPER_STEPS')
.setCheck(Blockly.Types.NUMBER.compatibles());
.setCheck(Blockly.Types.NUMBER.checkList);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_STEPPER_STEPS);
this.setPreviousStatement(true);
Expand Down
8 changes: 4 additions & 4 deletions blockly/blocks/arduino/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Blockly.Blocks['time_delay'] = {
this.setHelpUrl('http://arduino.cc/en/Reference/Delay');
this.setColour(Blockly.Blocks.time.HUE);
this.appendValueInput('DELAY_TIME_MILI')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.appendField(Blockly.Msg.ARD_TIME_DELAY);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_TIME_MS);
Expand All @@ -48,7 +48,7 @@ Blockly.Blocks['time_delaymicros'] = {
this.setHelpUrl('http://arduino.cc/en/Reference/DelayMicroseconds');
this.setColour(Blockly.Blocks.time.HUE);
this.appendValueInput('DELAY_TIME_MICRO')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.appendField(Blockly.Msg.ARD_TIME_DELAY);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_TIME_DELAY_MICROS);
Expand All @@ -69,7 +69,7 @@ Blockly.Blocks['time_millis'] = {
this.setColour(Blockly.Blocks.time.HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_TIME_MILLIS);
this.setOutput(true, Blockly.Types.NUMBER.basicType);
this.setOutput(true, Blockly.Types.NUMBER.output);
this.setTooltip(Blockly.Msg.ARD_TIME_MILLIS_TIP);
},
/** @return {string} The type of return value for the block, an integer. */
Expand All @@ -88,7 +88,7 @@ Blockly.Blocks['time_micros'] = {
this.setColour(Blockly.Blocks.time.HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_TIME_MICROS);
this.setOutput(true, Blockly.Types.NUMBER.basicType);
this.setOutput(true, Blockly.Types.NUMBER.output);
this.setTooltip(Blockly.Msg.ARD_TIME_MICROS_TIP);
},
/**
Expand Down
8 changes: 4 additions & 4 deletions blockly/blocks/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ Blockly.Blocks['colour_rgb'] = {
this.setHelpUrl(Blockly.Msg.COLOUR_RGB_HELPURL);
this.setColour(Blockly.Blocks.colour.HUE);
this.appendValueInput('RED')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.COLOUR_RGB_TITLE)
.appendField(Blockly.Msg.COLOUR_RGB_RED);
this.appendValueInput('GREEN')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.COLOUR_RGB_GREEN);
this.appendValueInput('BLUE')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.COLOUR_RGB_BLUE);
this.setOutput(true, 'Colour');
Expand All @@ -124,7 +124,7 @@ Blockly.Blocks['colour_blend'] = {
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.COLOUR_BLEND_COLOUR2);
this.appendValueInput('RATIO')
.setCheck(Blockly.Types.NUMBER.compatibles())
.setCheck(Blockly.Types.NUMBER.checkList)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.COLOUR_BLEND_RATIO);
this.setOutput(true, 'Colour');
Expand Down
31 changes: 13 additions & 18 deletions blockly/blocks/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Blockly.Blocks['lists_repeat'] = {
{
"type": "input_value",
"name": "NUM",
"check": Blockly.Types.NUMBER.compatibles()
"check": Blockly.Types.NUMBER.checkList
}
],
"output": "Array",
Expand All @@ -246,11 +246,10 @@ Blockly.Blocks['lists_length'] = {
{
"type": "input_value",
"name": "VALUE",
"check": Blockly.Types.TEXT
.compatibles().concat('Array')
"check": Blockly.Types.TEXT.checkList.concat('Array')
}
],
"output": Blockly.Types.NUMBER.basicType,
"output": Blockly.Types.NUMBER.output,
"colour": Blockly.Blocks.lists.HUE,
"tooltip": Blockly.Msg.LISTS_LENGTH_TOOLTIP,
"helpUrl": Blockly.Msg.LISTS_LENGTH_HELPURL
Expand All @@ -270,11 +269,10 @@ Blockly.Blocks['lists_isEmpty'] = {
{
"type": "input_value",
"name": "VALUE",
"check": Blockly.Types.TEXT
.compatibles().concat('Array')
"check": Blockly.Types.TEXT.checkList.concat('Array')
}
],
"output": Blockly.Types.BOOLEAN.basicType,
"output": Blockly.Types.BOOLEAN.output,
"colour": Blockly.Blocks.lists.HUE,
"tooltip": Blockly.Msg.LISTS_ISEMPTY_TOOLTIP,
"helpUrl": Blockly.Msg.LISTS_ISEMPTY_HELPURL
Expand All @@ -293,7 +291,7 @@ Blockly.Blocks['lists_indexOf'] = {
[Blockly.Msg.LISTS_INDEX_OF_LAST, 'LAST']];
this.setHelpUrl(Blockly.Msg.LISTS_INDEX_OF_HELPURL);
this.setColour(Blockly.Blocks.lists.HUE);
this.setOutput(true, Blockly.Types.NUMBER.basicType);
this.setOutput(true, Blockly.Types.NUMBER.output);
this.appendValueInput('VALUE')
.setCheck('Array')
.appendField(Blockly.Msg.LISTS_INDEX_OF_INPUT_IN_LIST);
Expand Down Expand Up @@ -409,7 +407,7 @@ Blockly.Blocks['lists_getIndex'] = {
this.removeInput('ORDINAL', true);
// Create either a value 'AT' input or a dummy input.
if (isAt) {
this.appendValueInput('AT').setCheck(Blockly.Types.NUMBER.compatibles());
this.appendValueInput('AT').setCheck(Blockly.Types.NUMBER.checkList);
if (Blockly.Msg.ORDINAL_NUMBER_SUFFIX) {
this.appendDummyInput('ORDINAL')
.appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX);
Expand Down Expand Up @@ -509,7 +507,7 @@ Blockly.Blocks['lists_setIndex'] = {
this.removeInput('ORDINAL', true);
// Create either a value 'AT' input or a dummy input.
if (isAt) {
this.appendValueInput('AT').setCheck(Blockly.Types.NUMBER.compatibles());
this.appendValueInput('AT').setCheck(Blockly.Types.NUMBER.checkList);
if (Blockly.Msg.ORDINAL_NUMBER_SUFFIX) {
this.appendDummyInput('ORDINAL')
.appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX);
Expand Down Expand Up @@ -608,8 +606,7 @@ Blockly.Blocks['lists_getSublist'] = {
this.removeInput('ORDINAL' + n, true);
// Create either a value 'AT' input or a dummy input.
if (isAt) {
this.appendValueInput('AT' + n).setCheck(
Blockly.Types.NUMBER.compatibles());
this.appendValueInput('AT' + n).setCheck(Blockly.Types.NUMBER.checkList);
if (Blockly.Msg.ORDINAL_NUMBER_SUFFIX) {
this.appendDummyInput('ORDINAL' + n)
.appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX);
Expand Down Expand Up @@ -661,10 +658,10 @@ Blockly.Blocks['lists_split'] = {
this.setHelpUrl(Blockly.Msg.LISTS_SPLIT_HELPURL);
this.setColour(Blockly.Blocks.lists.HUE);
this.appendValueInput('INPUT')
.setCheck(Blockly.Types.TEXT.compatibles())
.setCheck(Blockly.Types.TEXT.checkList)
.appendField(dropdown, 'MODE');
this.appendValueInput('DELIM')
.setCheck(Blockly.Types.TEXT.compatibles())
.setCheck(Blockly.Types.TEXT.checkList)
.appendField(Blockly.Msg.LISTS_SPLIT_WITH_DELIMITER);
this.setInputsInline(true);
this.setOutput(true, 'Array');
Expand All @@ -687,11 +684,9 @@ Blockly.Blocks['lists_split'] = {
updateType_: function(newMode) {
if (newMode == 'SPLIT') {
this.outputConnection.setCheck('Array');
this.getInput('INPUT').setCheck(
Blockly.Types.TEXT.compatibles());
this.getInput('INPUT').setCheck(Blockly.Types.TEXT.checkList);
} else {
this.outputConnection.setCheck(
Blockly.Types.TEXT.compatibles());
this.outputConnection.setCheck(Blockly.Types.TEXT.checkList);
this.getInput('INPUT').setCheck('Array');
}
},
Expand Down
24 changes: 12 additions & 12 deletions blockly/blocks/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Blockly.Blocks['controls_if'] = {
this.setHelpUrl(Blockly.Msg.CONTROLS_IF_HELPURL);
this.setColour(Blockly.Blocks.logic.HUE);
this.appendValueInput('IF0')
.setCheck(Blockly.Types.BOOLEAN.compatibles())
.setCheck(Blockly.Types.BOOLEAN.checkList)
.appendField(Blockly.Msg.CONTROLS_IF_MSG_IF);
this.appendStatementInput('DO0')
.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
Expand Down Expand Up @@ -97,7 +97,7 @@ Blockly.Blocks['controls_if'] = {
this.elseCount_ = parseInt(xmlElement.getAttribute('else'), 10) || 0;
for (var i = 1; i <= this.elseifCount_; i++) {
this.appendValueInput('IF' + i)
.setCheck(Blockly.Types.BOOLEAN.compatibles())
.setCheck(Blockly.Types.BOOLEAN.checkList)
.appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF);
this.appendStatementInput('DO' + i)
.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
Expand Down Expand Up @@ -154,7 +154,7 @@ Blockly.Blocks['controls_if'] = {
case 'controls_if_elseif':
this.elseifCount_++;
var ifInput = this.appendValueInput('IF' + this.elseifCount_)
.setCheck(Blockly.Types.BOOLEAN.compatibles())
.setCheck(Blockly.Types.BOOLEAN.checkList)
.appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF);
var doInput = this.appendStatementInput('DO' + this.elseifCount_);
doInput.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
Expand Down Expand Up @@ -284,7 +284,7 @@ Blockly.Blocks['logic_compare'] = {
];
this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL);
this.setColour(Blockly.Blocks.logic.HUE);
this.setOutput(true, Blockly.Types.BOOLEAN.basicType);
this.setOutput(true, Blockly.Types.BOOLEAN.output);
this.appendValueInput('A');
this.appendValueInput('B')
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
Expand Down Expand Up @@ -345,11 +345,11 @@ Blockly.Blocks['logic_operation'] = {
[Blockly.Msg.LOGIC_OPERATION_OR, 'OR']];
this.setHelpUrl(Blockly.Msg.LOGIC_OPERATION_HELPURL);
this.setColour(Blockly.Blocks.logic.HUE);
this.setOutput(true, Blockly.Types.BOOLEAN.basicType);
this.setOutput(true, Blockly.Types.BOOLEAN.output);
this.appendValueInput('A')
.setCheck(Blockly.Types.BOOLEAN.compatibles());
.setCheck(Blockly.Types.BOOLEAN.checkList);
this.appendValueInput('B')
.setCheck(Blockly.Types.BOOLEAN.compatibles())
.setCheck(Blockly.Types.BOOLEAN.checkList)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.setInputsInline(true);
// Assign 'this' to a variable for use in the tooltip closure below.
Expand Down Expand Up @@ -381,10 +381,10 @@ Blockly.Blocks['logic_negate'] = {
{
"type": "input_value",
"name": "BOOL",
"check": Blockly.Types.BOOLEAN.compatibles()
"check": Blockly.Types.BOOLEAN.checkList
}
],
"output": Blockly.Types.BOOLEAN.basicType,
"output": Blockly.Types.BOOLEAN.output,
"colour": Blockly.Blocks.logic.HUE,
"tooltip": Blockly.Msg.LOGIC_NEGATE_TOOLTIP,
"helpUrl": Blockly.Msg.LOGIC_NEGATE_HELPURL
Expand Down Expand Up @@ -414,7 +414,7 @@ Blockly.Blocks['logic_boolean'] = {
]
}
],
"output": Blockly.Types.BOOLEAN.basicType,
"output": Blockly.Types.BOOLEAN.output,
"colour": Blockly.Blocks.logic.HUE,
"tooltip": Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP,
"helpUrl": Blockly.Msg.LOGIC_BOOLEAN_HELPURL
Expand All @@ -434,7 +434,7 @@ Blockly.Blocks['logic_null'] = {
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOGIC_NULL,
"output": Blockly.Types.NULL.basicType,
"output": Blockly.Types.NULL.output,
"colour": Blockly.Blocks.logic.HUE,
"tooltip": Blockly.Msg.LOGIC_NULL_TOOLTIP,
"helpUrl": Blockly.Msg.LOGIC_NULL_HELPURL
Expand All @@ -455,7 +455,7 @@ Blockly.Blocks['logic_ternary'] = {
this.setHelpUrl(Blockly.Msg.LOGIC_TERNARY_HELPURL);
this.setColour(Blockly.Blocks.logic.HUE);
this.appendValueInput('IF')
.setCheck(Blockly.Types.BOOLEAN.compatibles())
.setCheck(Blockly.Types.BOOLEAN.checkList)
.appendField(Blockly.Msg.LOGIC_TERNARY_CONDITION);
this.appendValueInput('THEN')
.appendField(Blockly.Msg.LOGIC_TERNARY_IF_TRUE);
Expand Down
Loading

0 comments on commit 8c04540

Please sign in to comment.