exlib.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #pragma once
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /*
  15. * Glenn Fowler
  16. * AT&T Research
  17. *
  18. * expression library private definitions
  19. */
  20. #include <ast/ast.h>
  21. #include <sfio/sfio.h>
  22. #include <stdio.h>
  23. #include <util/agxbuf.h>
  24. typedef struct Exinput_s /* input stack */
  25. {
  26. struct Exinput_s*next; /* next in stack */
  27. int close; /* close fp on pop */
  28. char* file; /* previous file */
  29. FILE* fp; /* expression file pointer */
  30. int line; /* previous line */
  31. int nesting; /* expression nesting level */
  32. int peek; /* 1 char peek */
  33. int unit; /* first frame in parse unit */
  34. char* pushback; /* pushback buffer */
  35. char* pp; /* pushback pointer */
  36. } Exinput_t;
  37. typedef struct Print_s /* compiled printf arg node */
  38. {
  39. struct Print_s* next; /* next arg */
  40. char* format; /* printf format for arg */
  41. struct Exnode_s*param[3]; /* 0:width 1:precision 2:base */
  42. struct Exnode_s*arg; /* arg to format */
  43. } Print_t;
  44. #define _EX_DATA_PRIVATE_ \
  45. Exnode_t* next; /* free list link */ \
  46. Extype_t value; /* dynamic variable value */ \
  47. struct \
  48. { \
  49. Exid_t* procedure; /* called procedure */ \
  50. Exnode_t* args; /* actual argument list */ \
  51. } call; /* procedure call */ \
  52. struct \
  53. { \
  54. Exnode_t* array; /* array name */ \
  55. Exid_t* index; /* array index */ \
  56. Exnode_t* statement; /* statement to apply */ \
  57. } generate; /* associative array generator */ \
  58. struct \
  59. { \
  60. Exid_t* array; /* array */ \
  61. Exnode_t* string; /* string */ \
  62. Exnode_t* seps; /* optional separators */ \
  63. } split; /* string split */ \
  64. struct \
  65. { \
  66. Exnode_t* descriptor; /* Expr_t.file index */ \
  67. Print_t* args; /* compiler printf args */ \
  68. } print; /* printf */ \
  69. struct \
  70. { \
  71. Exnode_t* base; /* base string */ \
  72. Exnode_t* pat; /* pattern or start index */ \
  73. Exnode_t* repl; /* optional replacement or end index */ \
  74. } string; /* string builtins */ \
  75. struct \
  76. { \
  77. Exnode_t* args; /* formal arg list */ \
  78. Exnode_t* body; /* body */ \
  79. Dt_t* frame; /* local symbol frame */ \
  80. int arity; /* # formal args */ \
  81. } procedure; /* procedure args and body */ \
  82. struct \
  83. { \
  84. Exnode_t* descriptor; /* Expr_t.file index */ \
  85. Exnode_t* format; /* format arg */ \
  86. Exnode_t* args; /* actual args */ \
  87. } scan; /* printf */
  88. #define _EX_NODE_PRIVATE_ \
  89. int subop; /* operator qualifier */
  90. #define _EX_PROG_PRIVATE_ \
  91. Vmalloc_t* ve; /* eval tmp region */ \
  92. Dt_t* frame; /* frame symbol table */ \
  93. Dtdisc_t symdisc; /* Expr_t.symbols discipline */ \
  94. Exdisc_t* disc; /* user discipline */ \
  95. Exinput_t* input; /* input stack */ \
  96. Expr_t* program; /* previous program on stack */ \
  97. agxbuf tmp; /* tmp string buffer */ \
  98. Extype_t loopret; /* return value */ \
  99. Exid_t main; /* main procedure */ \
  100. char line[512]; /* last few input tokens */ \
  101. char* linep; /* line[] pointer */ \
  102. int eof; /* lex hit eof */ \
  103. int errors; /* fatal error count */ \
  104. int linewrap; /* linep wrapped around line[] */ \
  105. long long loopcount; /* break|continue|return count */ \
  106. long loopop; /* break|continue|return op */ \
  107. int nesting; /* exstatement() nesting */
  108. #include <expr/expr.h>
  109. #include <ctype.h>
  110. #include <ast/error.h>
  111. #define id_string (&exbuiltin[0])
  112. #define exunlex(p,c) ((p)->linep--,(p)->input->peek=(c))
  113. #define putcontext(p,c) (((p)->linep>=&(p)->line[sizeof((p)->line)]?(p)->linep=(p)->line,(p)->linewrap=1:0),*(p)->linep++=(c))
  114. #define setcontext(p) ((p)->linep=(p)->line,(p)->linewrap=0)
  115. typedef struct Switch_s /* switch parse state */
  116. {
  117. struct Switch_s*prev; /* previous switch state */
  118. Exnode_t* firstcase; /* first case block */
  119. Exnode_t* lastcase; /* last case block */
  120. Exnode_t* defcase; /* default case block */
  121. Extype_t** base; /* label base pointer */
  122. Extype_t** cur; /* current label pointer */
  123. Extype_t** last; /* last label pointer */
  124. int def; /* default label hit */
  125. long type; ///< switch test type
  126. } Switch_t;
  127. typedef struct Exassoc_s /* associative array bucket */
  128. {
  129. Dtlink_t link; /* table link */
  130. Extype_t key; /* key */
  131. Extype_t value; /* value */
  132. char name[1]; /* index name */
  133. } Exassoc_t;
  134. typedef struct Exstate_s /* ex global state */
  135. {
  136. Exid_t* id; /* current declaration id */
  137. long declare; ///< current declaration type
  138. int nolabel; /* <id>':' not a label */
  139. Exinput_t null; /* null input */
  140. Expr_t* program; /* current program */
  141. Exnode_t* procedure; /* current procedure */
  142. Exref_t* refs; /* . reference list */
  143. int assigned; /* declaration assignment */
  144. Switch_t* swstate; /* switch parse state */
  145. char nullstring[1]; /* "" */
  146. } Exstate_t;
  147. extern Exid_t exbuiltin[];
  148. extern const char* exversion;
  149. extern Exstate_t expr;
  150. extern int ex_parse(void); /* yacc should do this */
  151. #ifdef __cplusplus
  152. }
  153. #endif