AST.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. export class Program {
  2. constructor() {
  3. this.body = [];
  4. this.isProgram = true;
  5. }
  6. }
  7. export class VariableDeclaration {
  8. constructor( type, name, value = null, next = null, immutable = false ) {
  9. this.type = type;
  10. this.name = name;
  11. this.value = value;
  12. this.next = next;
  13. this.immutable = immutable;
  14. this.isVariableDeclaration = true;
  15. }
  16. }
  17. export class Uniform {
  18. constructor( type, name ) {
  19. this.type = type;
  20. this.name = name;
  21. this.isUniform = true;
  22. }
  23. }
  24. export class Varying {
  25. constructor( type, name ) {
  26. this.type = type;
  27. this.name = name;
  28. this.isVarying = true;
  29. }
  30. }
  31. export class FunctionParameter {
  32. constructor( type, name, qualifier = null, immutable = true ) {
  33. this.type = type;
  34. this.name = name;
  35. this.qualifier = qualifier;
  36. this.immutable = immutable;
  37. this.isFunctionParameter = true;
  38. }
  39. }
  40. export class FunctionDeclaration {
  41. constructor( type, name, params = [] ) {
  42. this.type = type;
  43. this.name = name;
  44. this.params = params;
  45. this.body = [];
  46. this.isFunctionDeclaration = true;
  47. }
  48. }
  49. export class Expression {
  50. constructor( expression ) {
  51. this.expression = expression;
  52. this.isExpression = true;
  53. }
  54. }
  55. export class Ternary {
  56. constructor( cond, left, right ) {
  57. this.cond = cond;
  58. this.left = left;
  59. this.right = right;
  60. this.isTernary = true;
  61. }
  62. }
  63. export class Operator {
  64. constructor( type, left, right ) {
  65. this.type = type;
  66. this.left = left;
  67. this.right = right;
  68. this.isOperator = true;
  69. }
  70. }
  71. export class Unary {
  72. constructor( type, expression, after = false ) {
  73. this.type = type;
  74. this.expression = expression;
  75. this.after = after;
  76. this.isUnary = true;
  77. }
  78. }
  79. export class Number {
  80. constructor( value, type = 'float' ) {
  81. this.type = type;
  82. this.value = value;
  83. this.isNumber = true;
  84. }
  85. }
  86. export class String {
  87. constructor( value ) {
  88. this.value = value;
  89. this.isString = true;
  90. }
  91. }
  92. export class Conditional {
  93. constructor( cond = null ) {
  94. this.cond = cond;
  95. this.body = [];
  96. this.elseConditional = null;
  97. this.isConditional = true;
  98. }
  99. }
  100. export class FunctionCall {
  101. constructor( name, params = [] ) {
  102. this.name = name;
  103. this.params = params;
  104. this.isFunctionCall = true;
  105. }
  106. }
  107. export class Return {
  108. constructor( value ) {
  109. this.value = value;
  110. this.isReturn = true;
  111. }
  112. }
  113. export class Discard {
  114. constructor() {
  115. this.isDiscard = true;
  116. }
  117. }
  118. export class Accessor {
  119. constructor( property ) {
  120. this.property = property;
  121. this.isAccessor = true;
  122. }
  123. }
  124. export class StaticElement {
  125. constructor( value ) {
  126. this.value = value;
  127. this.isStaticElement = true;
  128. }
  129. }
  130. export class DynamicElement {
  131. constructor( value ) {
  132. this.value = value;
  133. this.isDynamicElement = true;
  134. }
  135. }
  136. export class AccessorElements {
  137. constructor( object, elements = [] ) {
  138. this.object = object;
  139. this.elements = elements;
  140. this.isAccessorElements = true;
  141. }
  142. }
  143. export class For {
  144. constructor( initialization, condition, afterthought ) {
  145. this.initialization = initialization;
  146. this.condition = condition;
  147. this.afterthought = afterthought;
  148. this.body = [];
  149. this.isFor = true;
  150. }
  151. }