glsl_ast.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef GLSL_AST_H
  2. #define GLSL_AST_H
  3. #include "glsl_parser.h"
  4. struct glsl_ast_walk_data;
  5. //
  6. // glsl_is_list_node()
  7. //
  8. // Returns true if the children of this node form
  9. // a list
  10. //
  11. bool glsl_ast_is_list_node(struct glsl_node *n);
  12. //
  13. // glsl_ast_print()
  14. //
  15. // Print the AST tree as text for debugging purposes.
  16. // The 'depth' parameter represents amount to indent the
  17. // the printed text.
  18. //
  19. void glsl_ast_print(struct glsl_node *n, int depth);
  20. //
  21. // glsl_ast_generate_glsl()
  22. //
  23. // Translate AST into GLSL
  24. //
  25. // Returns a string containing the GLSL corresponding to
  26. // the AST or NULL on error. The returned string must be
  27. // deallocataed with free()
  28. //
  29. char *glsl_ast_generate_glsl(struct glsl_node *n);
  30. //
  31. // glsl_ast_walk_init()
  32. //
  33. // Initialize a glsl_ast_walk_data structure for
  34. // subsequent use
  35. //
  36. void glsl_ast_walk_init(struct glsl_ast_walk_data *data);
  37. //
  38. // glsl_ast_walk_push_node()
  39. //
  40. // Queue node for traversal in glsl_ast_walk(). In a typical
  41. // use case you would call this once outside of glsl_ast_walk()
  42. // and inside of any nodes of interest in the glsl_ast_walk()'s
  43. // enter_node() callback.
  44. //
  45. void glsl_ast_walk_push_node(struct glsl_ast_walk_data *data, struct glsl_node *n);
  46. //
  47. // glsl_ast_walk()
  48. //
  49. // Traverse tree nodes previously pushed with glsl_ast_walk_push_node(). When a node is processed
  50. // enter_node() will be called. This callback should call glsl_ast_walk_push_node() if any of
  51. // it's children also need processing. When all of a node's children are processed exit_node()
  52. // will be called.
  53. //
  54. void glsl_ast_walk(struct glsl_ast_walk_data *data, intptr_t userdata,
  55. void (*enter_node)(struct glsl_ast_walk_data *data, struct glsl_node *n, intptr_t userdata),
  56. void (*exit_node)(struct glsl_ast_walk_data *data, struct glsl_node *n, intptr_t userdata));
  57. struct glsl_ast_walk_data {
  58. struct glsl_node *node_stack[1024];
  59. int node_stack_level;
  60. struct glsl_node *parent_stack[1024];
  61. int parent_stack_idx[1024];
  62. int parent_stack_level;
  63. };
  64. #endif