ast.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* AST nodes for Jtalk */
  2. smalltalk.node = function(spec) {
  3. var that = {};
  4. that.nodes = spec.nodes || [];
  5. that.accept = function(visitor){visitor.visitNode(that)};
  6. return that;
  7. }
  8. smalltalk.methodNode = function(spec) {
  9. var that = smalltalk.node(spec);
  10. that.accept = function(visitor) {
  11. visitor.visitMethodNode(that);
  12. };
  13. that.selector = spec.selector || [];
  14. that.arguments = spec.arguments || [];
  15. return that;
  16. }
  17. smalltalk.sendNode = function(spec) {
  18. var that = smalltalk.node(spec);
  19. that.accept = function(visitor) {
  20. visitor.visitSendNode(that);
  21. };
  22. that.selector = spec.selector;
  23. that.receiver = spec.receiver;
  24. that.arguments = spec.arguments || [];
  25. return that;
  26. }
  27. smalltalk.cascadeNode = function(spec) {
  28. var that = smalltalk.node(spec);
  29. that.accept = function(visitor) {
  30. return visitor.visitCascadeNode(that);
  31. };
  32. that.receiver = spec.receiver;
  33. return that;
  34. }
  35. smalltalk.sequenceNode = function(spec) {
  36. var that = smalltalk.node(spec);
  37. that.accept = function(visitor) {
  38. visitor.visitSequenceNode(that);
  39. };
  40. that.asBlockSequenceNode = function() {
  41. return smalltalk.blockSequenceNode(that);
  42. };
  43. that.temps = spec.temps || [];
  44. return that;
  45. }
  46. smalltalk.blockSequenceNode = function(spec) {
  47. var that = smalltalk.sequenceNode(spec);
  48. that.accept = function(visitor) {
  49. visitor.compileBlockSequenceNode(that);
  50. }
  51. return that;
  52. }
  53. smalltalk.blockNode = function(spec) {
  54. var that = smalltalk.node(spec);
  55. that.accept = function(visitor) {
  56. visitor.visitBlockNode(that);
  57. };
  58. that.params = spec.params || [];
  59. that.inlined = false;
  60. return that;
  61. }
  62. smalltalk.returnNode = function(spec) {
  63. var that = smalltalk.node(spec);
  64. that.accept = function(visitor) {
  65. visitor.visitReturnNode(that);
  66. };
  67. that.isReturnNode = true;
  68. return that;
  69. }
  70. smalltalk.assignmentNode = function(spec) {
  71. var that = smalltalk.node(spec);
  72. var accept = function(visitor) {
  73. return visitor.visitAssignmentNode(that);
  74. };
  75. that.left = spec.left;
  76. that.right = spec.right;
  77. return that;
  78. }
  79. smalltalk.valueNode = function(spec) {
  80. var that = smalltalk.node(spec);
  81. that.accept = function(visitor) {
  82. visitor.compileValueNode(that);
  83. }
  84. that.value = spec.value;
  85. that.isValueNode = true;
  86. return that;
  87. }
  88. smalltalk.variableNode = function(spec) {
  89. var that = smalltalk.valueNode(spec);
  90. that.accept = function(visitor) {
  91. visitor.visitVariableNode(that);
  92. };
  93. that.isVariableNode = true;
  94. return that;
  95. }
  96. smalltalk.classReferenceNode = function(spec) {
  97. var that = smalltalk.variableNode(spec);
  98. that.accept = function(visitor) {
  99. return visitor.visitClassReferenceNode(that);
  100. };
  101. return that;
  102. }
  103. smalltalk.jsStatementNode = function(spec) {
  104. var that = smalltalk.node(spec);
  105. that.accept = function(visitor) {
  106. visitor.visitJsStatement(that);
  107. };
  108. that.source = spec.source || "";
  109. return that;
  110. }
  111. /* Utility function used by the parser */
  112. smalltalk.setReceiver = function(t, m) {
  113. if(!t.receiver) {
  114. t.receiver = m;
  115. } else {
  116. smalltalk.setReceiver(t.receiver, m);
  117. }
  118. }