utility.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @license
  3. * Visual Blocks Language
  4. *
  5. * Copyright 2012 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Generating Pseudo for utility blocks.
  22. * @author acbart@vt.edu (Austin Cory Bart)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Pseudo.utility');
  26. goog.require('Blockly.Pseudo');
  27. Blockly.Pseudo['raw_block'] = function(block) {
  28. var code = block.getFieldValue('TEXT')+"\n";
  29. return code;
  30. };
  31. Blockly.Pseudo['raw_expression'] = function(block) {
  32. var code = block.getFieldValue('TEXT');
  33. return [code, Blockly.Pseudo.ORDER_ATOMIC];
  34. };
  35. Blockly.Pseudo['raw_empty'] = function(block) {
  36. var code = Blockly.Pseudo.valueToCode(block, 'VALUE',
  37. Blockly.Pseudo.ORDER_MEMBER) || '';
  38. return code+"\n";
  39. };
  40. Blockly.Pseudo['raw_table'] = function(block) {
  41. //var code = block.getFieldValue('TEXT')+"\n";
  42. return '';//code;
  43. };
  44. Blockly.Pseudo['type_check'] = function(block) {
  45. var value = Blockly.Pseudo.valueToCode(block, 'VALUE',
  46. Blockly.Pseudo.ORDER_MEMBER) || '___';
  47. var code = 'type('+value + ')';
  48. return [code, Blockly.Pseudo.ORDER_ATOMIC];
  49. };
  50. Blockly.Pseudo['function_call'] = function(block) {
  51. var name = block.getFieldValue('NAME');
  52. var hasReturn = block.hasReturn_;
  53. var args = new Array(block.itemCount_);
  54. for (var n = 0; n < block.itemCount_; n++) {
  55. args[n] = Blockly.Pseudo.valueToCode(block, 'ARGUMENT' + n,
  56. Blockly.Pseudo.ORDER_NONE) || '___';
  57. }
  58. var code = name+ '(' + args.join(', ') + ')';
  59. if (hasReturn) {
  60. return [code, Blockly.Pseudo.ORDER_ATOMIC];
  61. } else {
  62. return code+'\n';
  63. }
  64. };