backburn 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/Makefile +50 -0
  4. data/README.md +520 -0
  5. data/docs/cli-and-outputs.md +226 -0
  6. data/docs/technical-spec.md +656 -0
  7. data/exe/backburn +8 -0
  8. data/ext/backburn/extconf.rb +31 -0
  9. data/ext/backburn/prism/COMMIT +1 -0
  10. data/ext/backburn/prism/LICENSE.md +7 -0
  11. data/ext/backburn/prism/Makefile +213 -0
  12. data/ext/backburn/prism/include/prism/arena.h +45 -0
  13. data/ext/backburn/prism/include/prism/arena.hpp +42 -0
  14. data/ext/backburn/prism/include/prism/ast.h +10395 -0
  15. data/ext/backburn/prism/include/prism/ast.hpp +641 -0
  16. data/ext/backburn/prism/include/prism/buffer.h +60 -0
  17. data/ext/backburn/prism/include/prism/buffer.hpp +55 -0
  18. data/ext/backburn/prism/include/prism/comments.h +72 -0
  19. data/ext/backburn/prism/include/prism/compiler/accel.h +26 -0
  20. data/ext/backburn/prism/include/prism/compiler/align.h +36 -0
  21. data/ext/backburn/prism/include/prism/compiler/assume.h +25 -0
  22. data/ext/backburn/prism/include/prism/compiler/branch.h +26 -0
  23. data/ext/backburn/prism/include/prism/compiler/bswap.h +46 -0
  24. data/ext/backburn/prism/include/prism/compiler/cplusplus.hpp +16 -0
  25. data/ext/backburn/prism/include/prism/compiler/endianness.h +34 -0
  26. data/ext/backburn/prism/include/prism/compiler/exceptions.hpp +17 -0
  27. data/ext/backburn/prism/include/prism/compiler/exported.h +24 -0
  28. data/ext/backburn/prism/include/prism/compiler/fallthrough.h +22 -0
  29. data/ext/backburn/prism/include/prism/compiler/filesystem.h +32 -0
  30. data/ext/backburn/prism/include/prism/compiler/flex_array.h +19 -0
  31. data/ext/backburn/prism/include/prism/compiler/force_inline.h +21 -0
  32. data/ext/backburn/prism/include/prism/compiler/format.h +27 -0
  33. data/ext/backburn/prism/include/prism/compiler/inline.h +17 -0
  34. data/ext/backburn/prism/include/prism/compiler/lifetimebound.hpp +25 -0
  35. data/ext/backburn/prism/include/prism/compiler/nodiscard.h +22 -0
  36. data/ext/backburn/prism/include/prism/compiler/nonnull.h +18 -0
  37. data/ext/backburn/prism/include/prism/compiler/noreturn.h +24 -0
  38. data/ext/backburn/prism/include/prism/compiler/stack.h +60 -0
  39. data/ext/backburn/prism/include/prism/compiler/unused.h +18 -0
  40. data/ext/backburn/prism/include/prism/constant_pool.h +112 -0
  41. data/ext/backburn/prism/include/prism/diagnostic.h +121 -0
  42. data/ext/backburn/prism/include/prism/errors_format.h +63 -0
  43. data/ext/backburn/prism/include/prism/excludes.h +29 -0
  44. data/ext/backburn/prism/include/prism/integer.h +79 -0
  45. data/ext/backburn/prism/include/prism/internal/allocator.h +68 -0
  46. data/ext/backburn/prism/include/prism/internal/allocator_debug.h +88 -0
  47. data/ext/backburn/prism/include/prism/internal/arena.h +223 -0
  48. data/ext/backburn/prism/include/prism/internal/assert.h +14 -0
  49. data/ext/backburn/prism/include/prism/internal/bignum.h +239 -0
  50. data/ext/backburn/prism/include/prism/internal/bit.h +66 -0
  51. data/ext/backburn/prism/include/prism/internal/buffer.h +104 -0
  52. data/ext/backburn/prism/include/prism/internal/char.h +145 -0
  53. data/ext/backburn/prism/include/prism/internal/comments.h +54 -0
  54. data/ext/backburn/prism/include/prism/internal/constant_pool.h +155 -0
  55. data/ext/backburn/prism/include/prism/internal/diagnostic.h +392 -0
  56. data/ext/backburn/prism/include/prism/internal/double.h +19 -0
  57. data/ext/backburn/prism/include/prism/internal/encoding.h +326 -0
  58. data/ext/backburn/prism/include/prism/internal/integer.h +66 -0
  59. data/ext/backburn/prism/include/prism/internal/isinf.h +16 -0
  60. data/ext/backburn/prism/include/prism/internal/line_offset_list.h +50 -0
  61. data/ext/backburn/prism/include/prism/internal/list.h +62 -0
  62. data/ext/backburn/prism/include/prism/internal/magic_comments.h +23 -0
  63. data/ext/backburn/prism/include/prism/internal/memchr.h +15 -0
  64. data/ext/backburn/prism/include/prism/internal/node.h +197 -0
  65. data/ext/backburn/prism/include/prism/internal/oom.h +16 -0
  66. data/ext/backburn/prism/include/prism/internal/options.h +248 -0
  67. data/ext/backburn/prism/include/prism/internal/parser.h +1170 -0
  68. data/ext/backburn/prism/include/prism/internal/regexp.h +70 -0
  69. data/ext/backburn/prism/include/prism/internal/serialize.h +39 -0
  70. data/ext/backburn/prism/include/prism/internal/source.h +72 -0
  71. data/ext/backburn/prism/include/prism/internal/static_literals.h +60 -0
  72. data/ext/backburn/prism/include/prism/internal/stringy.h +37 -0
  73. data/ext/backburn/prism/include/prism/internal/strncasecmp.h +18 -0
  74. data/ext/backburn/prism/include/prism/internal/strpbrk.h +61 -0
  75. data/ext/backburn/prism/include/prism/internal/tokens.h +11 -0
  76. data/ext/backburn/prism/include/prism/internal/xxh3.h +16 -0
  77. data/ext/backburn/prism/include/prism/json.h +40 -0
  78. data/ext/backburn/prism/include/prism/line_offset_list.h +69 -0
  79. data/ext/backburn/prism/include/prism/magic_comments.h +53 -0
  80. data/ext/backburn/prism/include/prism/node.h +139 -0
  81. data/ext/backburn/prism/include/prism/node.hpp +272 -0
  82. data/ext/backburn/prism/include/prism/node_type.hpp +38 -0
  83. data/ext/backburn/prism/include/prism/options.h +393 -0
  84. data/ext/backburn/prism/include/prism/options.hpp +43 -0
  85. data/ext/backburn/prism/include/prism/parser.h +433 -0
  86. data/ext/backburn/prism/include/prism/parser.hpp +274 -0
  87. data/ext/backburn/prism/include/prism/prettyprint.h +39 -0
  88. data/ext/backburn/prism/include/prism/serialize.h +123 -0
  89. data/ext/backburn/prism/include/prism/source.h +163 -0
  90. data/ext/backburn/prism/include/prism/stream.h +36 -0
  91. data/ext/backburn/prism/include/prism/string_query.h +97 -0
  92. data/ext/backburn/prism/include/prism/stringy.h +61 -0
  93. data/ext/backburn/prism/include/prism/stringy.hpp +31 -0
  94. data/ext/backburn/prism/include/prism/version.h +46 -0
  95. data/ext/backburn/prism/include/prism.h +123 -0
  96. data/ext/backburn/prism/include/prism.hpp +24 -0
  97. data/ext/backburn/prism/src/arena.c +200 -0
  98. data/ext/backburn/prism/src/bignum.c +399 -0
  99. data/ext/backburn/prism/src/buffer.c +405 -0
  100. data/ext/backburn/prism/src/char.c +289 -0
  101. data/ext/backburn/prism/src/comments.c +455 -0
  102. data/ext/backburn/prism/src/constant_pool.c +410 -0
  103. data/ext/backburn/prism/src/diagnostic.c +918 -0
  104. data/ext/backburn/prism/src/double.c +394 -0
  105. data/ext/backburn/prism/src/encoding.c +1701 -0
  106. data/ext/backburn/prism/src/errors_format.c +650 -0
  107. data/ext/backburn/prism/src/integer.c +675 -0
  108. data/ext/backburn/prism/src/json.c +5745 -0
  109. data/ext/backburn/prism/src/line_offset_list.c +99 -0
  110. data/ext/backburn/prism/src/list.c +24 -0
  111. data/ext/backburn/prism/src/memchr.c +37 -0
  112. data/ext/backburn/prism/src/node.c +4464 -0
  113. data/ext/backburn/prism/src/options.c +475 -0
  114. data/ext/backburn/prism/src/parser.c +371 -0
  115. data/ext/backburn/prism/src/prettyprint.c +9038 -0
  116. data/ext/backburn/prism/src/prism.c +23615 -0
  117. data/ext/backburn/prism/src/regexp.c +3833 -0
  118. data/ext/backburn/prism/src/serialize.c +2656 -0
  119. data/ext/backburn/prism/src/source.c +525 -0
  120. data/ext/backburn/prism/src/static_literals.c +562 -0
  121. data/ext/backburn/prism/src/string_query.c +195 -0
  122. data/ext/backburn/prism/src/stringy.c +77 -0
  123. data/ext/backburn/prism/src/strncasecmp.c +37 -0
  124. data/ext/backburn/prism/src/strpbrk.c +465 -0
  125. data/ext/backburn/prism/src/tokens.c +724 -0
  126. data/ext/backburn/prism/src/xxh3.c +292 -0
  127. data/lib/backburn/version.rb +7 -0
  128. data/presets/devise.roots +11 -0
  129. data/presets/fast-mcp.roots +5 -0
  130. data/presets/graphql.roots +6 -0
  131. data/presets/phlex.roots +7 -0
  132. data/presets/pundit.roots +3 -0
  133. data/presets/rails-framework.roots +10 -0
  134. data/presets/rails.roots +83 -0
  135. data/presets/sidekiq.roots +4 -0
  136. data/presets/thor.roots +3 -0
  137. data/rails.roots +99 -0
  138. data/scripts/embed-presets.sh +13 -0
  139. data/scripts/version-h.sh +7 -0
  140. data/src/analysis/analysis.c +95 -0
  141. data/src/analysis/analysis.h +24 -0
  142. data/src/analysis/batches.c +127 -0
  143. data/src/analysis/batches.h +17 -0
  144. data/src/analysis/graph.c +238 -0
  145. data/src/analysis/graph.h +34 -0
  146. data/src/analysis/mark.c +300 -0
  147. data/src/analysis/mark.h +21 -0
  148. data/src/analysis/roots.c +229 -0
  149. data/src/analysis/roots.h +29 -0
  150. data/src/cli/cli.c +237 -0
  151. data/src/cli/cli.h +9 -0
  152. data/src/cli/config.c +112 -0
  153. data/src/cli/config.h +14 -0
  154. data/src/cli/options.c +17 -0
  155. data/src/cli/options.h +35 -0
  156. data/src/commands/commands.h +11 -0
  157. data/src/commands/explain.c +255 -0
  158. data/src/commands/gemfile.c +126 -0
  159. data/src/commands/gemfile.h +27 -0
  160. data/src/commands/gems.c +408 -0
  161. data/src/commands/init.c +92 -0
  162. data/src/commands/roots.c +82 -0
  163. data/src/commands/scan.c +91 -0
  164. data/src/core/intern.c +94 -0
  165. data/src/core/intern.h +40 -0
  166. data/src/core/json.c +17 -0
  167. data/src/core/json.h +9 -0
  168. data/src/core/model.c +25 -0
  169. data/src/core/model.h +85 -0
  170. data/src/core/util.c +116 -0
  171. data/src/core/util.h +48 -0
  172. data/src/index/erb.c +40 -0
  173. data/src/index/erb.h +9 -0
  174. data/src/index/haml.c +334 -0
  175. data/src/index/haml.h +10 -0
  176. data/src/index/indexer.c +702 -0
  177. data/src/index/indexer.h +19 -0
  178. data/src/index/walk.c +144 -0
  179. data/src/index/walk.h +14 -0
  180. data/src/main.c +81 -0
  181. data/src/output/baseline.c +101 -0
  182. data/src/output/baseline.h +15 -0
  183. data/src/output/report.c +440 -0
  184. data/src/output/report.h +28 -0
  185. metadata +231 -0
@@ -0,0 +1,702 @@
1
+ /* The Prism visitor: turns one parsed file into definitions and named references. */
2
+ #include <ctype.h>
3
+
4
+ #include "index/indexer.h"
5
+ #include "core/intern.h"
6
+ #include "core/model.h"
7
+ #include "cli/options.h"
8
+ #include "index/erb.h"
9
+ #include "index/haml.h"
10
+ #include "index/walk.h"
11
+
12
+ typedef struct {
13
+ pm_parser_t *p;
14
+ const uint8_t *src;
15
+ size_t srclen;
16
+ uint32_t file;
17
+ int is_test;
18
+ sbuf ns; /* current namespace, e.g. Admin::Reports */
19
+ int32_t nest; /* Module.nesting, innermost first, newline-separated; -1 at top level */
20
+ int singleton; /* inside class << self */
21
+ uint32_t cur; /* def that owns references; 0 = load time */
22
+ int32_t self_q; /* inside def Name.x: the class self is, else -1 (self is ns) */
23
+ int64_t cur_name; /* enclosing method name, for super */
24
+ int vis, next_def_vis;
25
+ int in_eval; /* depth of class_eval strings being read */
26
+ uint32_t eval_line;
27
+ } ctx_t;
28
+
29
+ pm_options_t *OPTS;
30
+
31
+ static pm_visit_result_t visit(const pm_node_t *node, void *data);
32
+
33
+ static uint32_t line_at(ctx_t *c, uint32_t off) {
34
+ if (c->in_eval) return c->eval_line;
35
+ return (uint32_t) pm_line_offset_list_line_column(pm_parser_line_offsets(c->p), off,
36
+ pm_parser_start_line(c->p)).line;
37
+ }
38
+
39
+ static uint32_t end_off(const pm_node_t *n) {
40
+ return n->location.length ? n->location.start + n->location.length - 1 : n->location.start;
41
+ }
42
+
43
+ /* Prism leaves id 0 on nodes it recovered from a syntax error. */
44
+ const pm_constant_t *safe_constant(pm_parser_t *p, pm_constant_id_t id) {
45
+ return id && id <= pm_parser_constants_size(p) ? pm_parser_constant(p, id) : NULL;
46
+ }
47
+
48
+ static uint32_t cid(ctx_t *c, pm_constant_id_t id) {
49
+ const pm_constant_t *k = safe_constant(c->p, id);
50
+ if (!k) return intern("", 0);
51
+ return intern((const char *) pm_constant_start(k), pm_constant_length(k));
52
+ }
53
+
54
+ const char *str_of(const pm_string_t *s, size_t *n) {
55
+ *n = pm_string_length(s);
56
+ return (const char *) pm_string_source(s);
57
+ }
58
+
59
+ static void slice(ctx_t *c, const pm_node_t *n, const char **s, size_t *len) {
60
+ *s = (const char *) c->src + n->location.start;
61
+ *len = n->location.length;
62
+ if (*len >= 2 && (*s)[0] == ':' && (*s)[1] == ':') *s += 2, *len -= 2;
63
+ }
64
+
65
+ static void add_ref(ctx_t *c, uint32_t name, int is_const, uint32_t off) {
66
+ if (c->is_test) {
67
+ PUSH(TR, (tref_t){name, c->file, (uint8_t) is_const});
68
+ } else {
69
+ uint32_t line = line_at(c, off);
70
+ PUSH(D.a[c->cur].refs, (ref_t){name, c->file, line, (uint8_t) is_const});
71
+ }
72
+ }
73
+
74
+ static void add_ref_str(ctx_t *c, const char *s, size_t n, int is_const, uint32_t off) {
75
+ if (n) add_ref(c, intern(s, n), is_const, off);
76
+ }
77
+
78
+ static int scan_nodoc(ctx_t *c, uint32_t off) {
79
+ if (c->in_eval) return 0;
80
+ const char *p = (const char *) c->src + off, *end = (const char *) c->src + c->srclen;
81
+ if (end - p > 400) end = p + 400;
82
+ for (const char *q = p; q + 7 <= end && *q != '\n'; q++)
83
+ if (*q == ':' && !memcmp(q, ":nodoc:", 7)) return 1;
84
+ return 0;
85
+ }
86
+
87
+ static uint32_t add_def(ctx_t *c, int kind, uint32_t name, const char *qual, size_t qn,
88
+ uint32_t off, uint32_t endoff, int vis) {
89
+ def_t d;
90
+ memset(&d, 0, sizeof d);
91
+ d.kind = (uint8_t) kind;
92
+ d.name = name;
93
+ d.qual = intern(qual, qn);
94
+ d.file = c->file;
95
+ d.line = line_at(c, off);
96
+ d.end_line = line_at(c, endoff);
97
+ d.vis = (uint8_t) vis;
98
+ d.super_ = d.outer = -1;
99
+ d.parent = -1;
100
+ d.root_rule = NOT_ROOT;
101
+ d.batch = -1;
102
+ d.nodoc = (uint8_t) scan_nodoc(c, off);
103
+ PUSH(D, d);
104
+ return (uint32_t) D.n - 1;
105
+ }
106
+
107
+ /* Constant-shaped: Foo or Foo::Bar, every segment starting A-Z. */
108
+ static int const_shaped(const char *s, size_t n) {
109
+ if (!n) return 0;
110
+ size_t i = 0;
111
+ while (i < n) {
112
+ if (!isupper((unsigned char) s[i])) return 0;
113
+ while (i < n && is_ident_char((unsigned char) s[i])) i++;
114
+ if (i == n) return 1;
115
+ if (i + 2 < n + 1 && s[i] == ':' && i + 1 < n && s[i + 1] == ':') i += 2;
116
+ else return 0;
117
+ }
118
+ return 0;
119
+ }
120
+
121
+ /* Method-shaped: 3-100 chars, [a-z_][a-z0-9_]* and an optional ? ! = */
122
+ static int meth_shaped(const char *s, size_t n) {
123
+ if (n < 3 || n > 100) return 0;
124
+ if (!(islower((unsigned char) s[0]) || s[0] == '_')) return 0;
125
+ size_t end = n;
126
+ if (s[n - 1] == '?' || s[n - 1] == '!' || s[n - 1] == '=') end--;
127
+ for (size_t i = 1; i < end; i++)
128
+ if (!(islower((unsigned char) s[i]) || isdigit((unsigned char) s[i]) || s[i] == '_')) return 0;
129
+ return 1;
130
+ }
131
+
132
+ static void last_segment(const char *s, size_t n, const char **o, size_t *on) {
133
+ size_t st = 0;
134
+ for (size_t i = 0; i + 1 < n; i++)
135
+ if (s[i] == ':' && s[i + 1] == ':') st = i + 2;
136
+ *o = s + st;
137
+ *on = n - st;
138
+ }
139
+
140
+ /* Interpolated strings and symbols become globs: literal parts as written
141
+ * (? escaped), interpolations as *. Returns 1 with *is_const set when the
142
+ * glob is a method pattern or a constant pattern (on its last segment). */
143
+ static int glob_of(const pm_node_list_t *parts, sbuf *out, int *is_const) {
144
+ sb_trunc(out, 0);
145
+ int lit = 0, meth_ok = 1, ident_ok = 1, upper = 0;
146
+ for (uint32_t i = 0; i < parts->size; i++) {
147
+ const pm_node_t *part = parts->nodes[i];
148
+ if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
149
+ size_t n;
150
+ const char *s = str_of(&((const pm_string_node_t *) part)->unescaped, &n);
151
+ for (size_t k = 0; k < n; k++) {
152
+ unsigned char ch = (unsigned char) s[k];
153
+ lit++;
154
+ if (!(islower(ch) || isdigit(ch) || ch == '_' || ch == '?' || ch == '!' || ch == '=')) meth_ok = 0;
155
+ if (!(isalnum(ch) || ch == '_' || ch == ':')) ident_ok = 0;
156
+ if (isupper(ch)) upper = 1;
157
+ if (ch == '?') sb_puts(out, "\\?");
158
+ else if (ch == '*' || ch == '[' || ch == '\\') sb_putc(out, '\\'), sb_putc(out, (char) ch);
159
+ else sb_putc(out, (char) ch);
160
+ }
161
+ } else if (!out->n || out->s[out->n - 1] != '*') {
162
+ sb_putc(out, '*');
163
+ }
164
+ }
165
+ if (lit < 3) return 0;
166
+ if (meth_ok) {
167
+ *is_const = 0;
168
+ return 1;
169
+ }
170
+ if (upper && ident_ok) {
171
+ const char *seg;
172
+ size_t sn;
173
+ last_segment(out->s, out->n, &seg, &sn);
174
+ int seglit = 0;
175
+ for (size_t k = 0; k < sn; k++)
176
+ if (seg[k] != '*') seglit++;
177
+ if (seglit < 3) return 0;
178
+ memmove(out->s, seg, sn);
179
+ sb_trunc(out, sn);
180
+ *is_const = 1;
181
+ return 1;
182
+ }
183
+ return 0;
184
+ }
185
+
186
+ static const pm_node_list_t *interp_parts(const pm_node_t *n) {
187
+ if (PM_NODE_TYPE_P(n, PM_INTERPOLATED_STRING_NODE)) return &((const pm_interpolated_string_node_t *) n)->parts;
188
+ if (PM_NODE_TYPE_P(n, PM_INTERPOLATED_SYMBOL_NODE)) return &((const pm_interpolated_symbol_node_t *) n)->parts;
189
+ return NULL;
190
+ }
191
+
192
+ static int yields_pattern(const pm_node_t *n, int want_const) {
193
+ const pm_node_list_t *parts = interp_parts(n);
194
+ if (!parts) return 0;
195
+ sbuf b = {0};
196
+ int k = 0, ok = glob_of(parts, &b, &k);
197
+ free(b.s);
198
+ return ok && k == want_const;
199
+ }
200
+
201
+ static void add_dyn(ctx_t *c, uint32_t name, uint32_t off, const pm_node_t *recv) {
202
+ if (c->is_test || c->in_eval) return;
203
+ dyn_t d = {c->file, line_at(c, off), S(name), -1, c->cur, 0, K_LOAD};
204
+ if (name >= W_SEND && name <= W_PUBLIC_METHOD && (c->self_q >= 0 || c->ns.n) &&
205
+ (!recv || PM_NODE_TYPE_P(recv, PM_SELF_NODE))) {
206
+ d.self_ns = c->self_q >= 0 ? c->self_q : (int32_t) intern(c->ns.s, c->ns.n);
207
+ d.public_only = name == W_PUBLIC_SEND || name == W_TRY || name == W_TRY_BANG || name == W_PUBLIC_METHOD;
208
+ d.self_kind = c->cur ? D.a[c->cur].kind : K_LOAD;
209
+ }
210
+ PUSH(DYN, d);
211
+ }
212
+
213
+ /* class_eval "…" and friends: rebuild the source, parse it, visit it with
214
+ * the same context. References count; definitions do not. */
215
+ static void eval_string(ctx_t *c, const pm_node_t *arg, uint32_t call_off) {
216
+ sbuf b = {0};
217
+ if (PM_NODE_TYPE_P(arg, PM_STRING_NODE)) {
218
+ size_t n;
219
+ const char *s = str_of(&((const pm_string_node_t *) arg)->unescaped, &n);
220
+ sb_put(&b, s, n);
221
+ } else {
222
+ const pm_node_list_t *parts = interp_parts(arg);
223
+ for (uint32_t i = 0; parts && i < parts->size; i++) {
224
+ if (PM_NODE_TYPE_P(parts->nodes[i], PM_STRING_NODE)) {
225
+ size_t n;
226
+ const char *s = str_of(&((const pm_string_node_t *) parts->nodes[i])->unescaped, &n);
227
+ sb_put(&b, s, n);
228
+ } else {
229
+ sb_puts(&b, "BackburnX"); /* valid as a constant, a method name, an ivar suffix */
230
+ }
231
+ }
232
+ }
233
+ if (!b.n) {
234
+ free(b.s);
235
+ return;
236
+ }
237
+ uint32_t line = line_at(c, call_off);
238
+ pm_arena_t *arena = pm_arena_new();
239
+ pm_parser_t *p = pm_parser_new(arena, (const uint8_t *) b.s, b.n, OPTS);
240
+ pm_node_t *root = pm_parse(p);
241
+ pm_parser_t *sp = c->p;
242
+ const uint8_t *ssrc = c->src;
243
+ size_t slen = c->srclen;
244
+ uint32_t sline = c->eval_line;
245
+ c->p = p;
246
+ c->src = (const uint8_t *) b.s;
247
+ c->srclen = b.n;
248
+ c->eval_line = line;
249
+ c->in_eval++;
250
+ pm_visit_node(root, visit, c);
251
+ c->in_eval--;
252
+ c->p = sp;
253
+ c->src = ssrc;
254
+ c->srclen = slen;
255
+ c->eval_line = sline;
256
+ pm_parser_free(p);
257
+ pm_arena_free(arena);
258
+ free(b.s);
259
+ }
260
+
261
+ /* class / module: record the def, then visit the body inside its namespace. */
262
+ static void enter_ns(ctx_t *c, const pm_node_t *node, const pm_node_t *cpath, const pm_node_t *body,
263
+ int kind, const pm_node_t *super) {
264
+ const char *t;
265
+ size_t tn;
266
+ slice(c, cpath, &t, &tn);
267
+ size_t saved = c->ns.n;
268
+ int32_t outer_nest = c->nest;
269
+ /* `class ::Name` names the top-level constant, whatever namespace it is written in */
270
+ sbuf outer_ns = {0};
271
+ int absolute = t != (const char *) c->src + cpath->location.start && c->ns.n;
272
+ if (absolute) sb_put(&outer_ns, c->ns.s, c->ns.n), sb_trunc(&c->ns, 0);
273
+ if (c->ns.n) sb_put(&c->ns, "::", 2);
274
+ sb_put(&c->ns, t, tn);
275
+ sbuf nb = {0};
276
+ sb_put(&nb, c->ns.s, c->ns.n);
277
+ if (outer_nest >= 0) sb_putc(&nb, '\n'), sb_put(&nb, S(outer_nest), SLEN(outer_nest));
278
+ c->nest = (int32_t) intern(nb.s, nb.n);
279
+ free(nb.s);
280
+ if (!c->is_test && !c->in_eval) {
281
+ const char *seg;
282
+ size_t sn;
283
+ last_segment(t, tn, &seg, &sn);
284
+ uint32_t i = add_def(c, kind, intern(seg, sn), c->ns.s, c->ns.n, cpath->location.start, end_off(node), V_PUBLIC);
285
+ if (kind == K_CLASS) {
286
+ D.a[i].outer = outer_nest;
287
+ const pm_node_t *s = super;
288
+ if (s && PM_NODE_TYPE_P(s, PM_CALL_NODE)) s = ((const pm_call_node_t *) s)->receiver;
289
+ if (s && (PM_NODE_TYPE_P(s, PM_CONSTANT_READ_NODE) || PM_NODE_TYPE_P(s, PM_CONSTANT_PATH_NODE))) {
290
+ const char *st;
291
+ size_t sl;
292
+ slice(c, s, &st, &sl);
293
+ D.a[i].super_ = (int32_t) intern(st, sl);
294
+ D.a[i].super_top = (uint8_t) (st != (const char *) c->src + s->location.start);
295
+ }
296
+ }
297
+ }
298
+ int sing = c->singleton, vis = c->vis, ndv = c->next_def_vis;
299
+ uint32_t cur = c->cur;
300
+ int64_t cur_name = c->cur_name;
301
+ c->singleton = 0;
302
+ c->vis = V_PUBLIC;
303
+ c->next_def_vis = -1;
304
+ if (!c->in_eval) c->cur = 0;
305
+ c->cur_name = -1;
306
+ if (body) pm_visit_node(body, visit, c);
307
+ c->singleton = sing;
308
+ c->vis = vis;
309
+ c->next_def_vis = ndv;
310
+ c->cur = cur;
311
+ c->cur_name = cur_name;
312
+ sb_trunc(&c->ns, absolute ? 0 : saved);
313
+ if (absolute) sb_put(&c->ns, outer_ns.s, outer_ns.n), free(outer_ns.s);
314
+ c->nest = outer_nest;
315
+ }
316
+
317
+ static void camel_refs(ctx_t *c, const char *s, size_t n, uint32_t off) {
318
+ for (size_t i = 0; i < n; i++)
319
+ if (!(islower((unsigned char) s[i]) || isdigit((unsigned char) s[i]) || s[i] == '_')) return;
320
+ sbuf b = {0};
321
+ int up = 1;
322
+ for (size_t i = 0; i < n; i++) {
323
+ if (s[i] == '_') {
324
+ up = 1;
325
+ continue;
326
+ }
327
+ sb_putc(&b, up ? (char) toupper((unsigned char) s[i]) : s[i]);
328
+ up = 0;
329
+ }
330
+ if (b.n && isupper((unsigned char) b.s[0])) {
331
+ add_ref_str(c, b.s, b.n, 1, off);
332
+ if (b.n > 3 && has_suffix(b.s, "ies")) {
333
+ sbuf y = {0};
334
+ sb_put(&y, b.s, b.n - 3);
335
+ sb_putc(&y, 'y');
336
+ add_ref_str(c, y.s, y.n, 1, off);
337
+ free(y.s);
338
+ } else if (b.n > 1 && b.s[b.n - 1] == 's' && b.s[b.n - 2] != 's') {
339
+ add_ref_str(c, b.s, b.n - 1, 1, off);
340
+ if (b.n > 2 && b.s[b.n - 2] == 'e') add_ref_str(c, b.s, b.n - 2, 1, off);
341
+ }
342
+ }
343
+ free(b.s);
344
+ }
345
+
346
+ /* RSpec predicate matchers: `be_active` calls active?, `have_key` calls has_key?. */
347
+ static void rspec_matcher_ref(ctx_t *c, uint32_t name, uint32_t off) {
348
+ const char *s = S(name);
349
+ size_t n = SLEN(name);
350
+ sbuf b = {0};
351
+ if (n > 3 && !strncmp(s, "be_", 3)) {
352
+ sb_put(&b, s + 3, n - 3);
353
+ sb_putc(&b, '?');
354
+ } else if (n > 5 && !strncmp(s, "have_", 5)) {
355
+ sb_puts(&b, "has_");
356
+ sb_put(&b, s + 5, n - 5);
357
+ sb_putc(&b, '?');
358
+ }
359
+ if (b.n) add_ref(c, intern(b.s, b.n), 0, off);
360
+ free(b.s);
361
+ }
362
+
363
+ static void visit_call(ctx_t *c, const pm_node_t *node) {
364
+ const pm_call_node_t *cn = (const pm_call_node_t *) node;
365
+ uint32_t name = cid(c, cn->name);
366
+ uint32_t off = cn->message_loc.length ? cn->message_loc.start : node->location.start;
367
+ add_ref(c, name, 0, off);
368
+ if (c->is_test) rspec_matcher_ref(c, name, off);
369
+ if (name >= W_N) {
370
+ /* def as argument: `register def self.handler(...)` */
371
+ if (cn->arguments) {
372
+ const pm_node_list_t *args = &cn->arguments->arguments;
373
+ for (uint32_t i = 0; i < args->size; i++)
374
+ if (PM_NODE_TYPE_P(args->nodes[i], PM_DEF_NODE))
375
+ add_ref(c, cid(c, ((const pm_def_node_t *) args->nodes[i])->name), 0, args->nodes[i]->location.start);
376
+ }
377
+ return;
378
+ }
379
+ const pm_node_list_t *args = cn->arguments ? &cn->arguments->arguments : NULL;
380
+ const pm_node_t *a0 = args && args->size ? args->nodes[0] : NULL;
381
+ int recvless = cn->receiver == NULL;
382
+
383
+ if (name <= W_PUBLIC) {
384
+ if (recvless && c->cur == 0) {
385
+ int v = name == W_PRIVATE ? V_PRIVATE : name == W_PROTECTED ? V_PROTECTED : V_PUBLIC;
386
+ if (!a0) c->vis = v;
387
+ else if (PM_NODE_TYPE_P(a0, PM_DEF_NODE)) c->next_def_vis = v;
388
+ }
389
+ } else if (name > W_MODULE_FUNCTION && args) {
390
+ for (uint32_t i = 0; i < args->size; i++)
391
+ if (PM_NODE_TYPE_P(args->nodes[i], PM_DEF_NODE))
392
+ add_ref(c, cid(c, ((const pm_def_node_t *) args->nodes[i])->name), 0, args->nodes[i]->location.start);
393
+ }
394
+
395
+ if ((name == W_INCLUDE || name == W_PREPEND || name == W_EXTEND) && recvless && c->ns.n && args &&
396
+ !c->is_test && !c->in_eval) {
397
+ uint32_t cls = intern(c->ns.s, c->ns.n);
398
+ for (uint32_t i = 0; i < args->size; i++) {
399
+ const pm_node_t *a = args->nodes[i];
400
+ if (PM_NODE_TYPE_P(a, PM_CONSTANT_READ_NODE) || PM_NODE_TYPE_P(a, PM_CONSTANT_PATH_NODE)) {
401
+ const char *t;
402
+ size_t tn;
403
+ slice(c, a, &t, &tn);
404
+ PUSH(INC, (incl_t){cls, intern(t, tn), c->nest, -1});
405
+ }
406
+ }
407
+ }
408
+
409
+ if (name >= W_SEND && name <= W_DEFINE_METHOD && a0) {
410
+ if (PM_NODE_TYPE_P(a0, PM_STRING_NODE)) {
411
+ size_t n;
412
+ const char *s = str_of(&((const pm_string_node_t *) a0)->unescaped, &n);
413
+ add_ref_str(c, s, n, 0, a0->location.start);
414
+ } else if (PM_NODE_TYPE_P(a0, PM_SYMBOL_NODE)) {
415
+ /* the SymbolNode visit already references it */
416
+ } else if (!yields_pattern(a0, 0)) {
417
+ add_dyn(c, name, off, cn->receiver);
418
+ }
419
+ }
420
+
421
+ if (name >= W_CONST_GET && name <= W_CONST_DEFINED) {
422
+ const pm_node_t *arg = (name == W_CONSTANTIZE || name == W_SAFE_CONSTANTIZE) ? cn->receiver : a0;
423
+ if (arg) {
424
+ const char *s = NULL;
425
+ size_t n = 0;
426
+ if (PM_NODE_TYPE_P(arg, PM_STRING_NODE)) s = str_of(&((const pm_string_node_t *) arg)->unescaped, &n);
427
+ else if (PM_NODE_TYPE_P(arg, PM_SYMBOL_NODE)) s = str_of(&((const pm_symbol_node_t *) arg)->unescaped, &n);
428
+ if (s) {
429
+ const char *seg;
430
+ size_t sn;
431
+ last_segment(s, n, &seg, &sn);
432
+ add_ref_str(c, seg, sn, 1, arg->location.start);
433
+ } else if (!yields_pattern(arg, 1)) {
434
+ add_dyn(c, name, off, cn->receiver);
435
+ }
436
+ }
437
+ }
438
+
439
+ /* class_eval "…" and friends; whenever's `runner "Report.send_all"` runs its string too */
440
+ if (((name >= W_CLASS_EVAL && name <= W_EVAL) || (name == W_RUNNER && recvless)) && a0 && c->in_eval < 3 &&
441
+ (PM_NODE_TYPE_P(a0, PM_STRING_NODE) || PM_NODE_TYPE_P(a0, PM_INTERPOLATED_STRING_NODE)))
442
+ eval_string(c, a0, node->location.start);
443
+
444
+ if (name == W_REQUIRE && recvless && a0 && PM_NODE_TYPE_P(a0, PM_STRING_NODE) && !c->in_eval) {
445
+ size_t n;
446
+ const char *s = str_of(&((const pm_string_node_t *) a0)->unescaped, &n);
447
+ PUSH(REQ, (req_t){c->file, xstrndup(s, n)});
448
+ }
449
+ }
450
+
451
+ static pm_visit_result_t visit(const pm_node_t *node, void *data) {
452
+ ctx_t *c = data;
453
+ switch (PM_NODE_TYPE(node)) {
454
+ case PM_CLASS_NODE: {
455
+ const pm_class_node_t *n = (const pm_class_node_t *) node;
456
+ if (n->superclass) pm_visit_node(n->superclass, visit, c);
457
+ enter_ns(c, node, n->constant_path, n->body, K_CLASS, n->superclass);
458
+ return PM_VISIT_SKIP;
459
+ }
460
+ case PM_MODULE_NODE: {
461
+ const pm_module_node_t *n = (const pm_module_node_t *) node;
462
+ enter_ns(c, node, n->constant_path, n->body, K_MODULE, NULL);
463
+ return PM_VISIT_SKIP;
464
+ }
465
+ case PM_SINGLETON_CLASS_NODE: {
466
+ const pm_singleton_class_node_t *n = (const pm_singleton_class_node_t *) node;
467
+ if (n->expression && !PM_NODE_TYPE_P(n->expression, PM_SELF_NODE)) pm_visit_node(n->expression, visit, c);
468
+ int sing = c->singleton, vis = c->vis, ndv = c->next_def_vis;
469
+ c->singleton = 1;
470
+ c->vis = V_PUBLIC;
471
+ c->next_def_vis = -1;
472
+ if (n->body) pm_visit_node(n->body, visit, c);
473
+ c->singleton = sing;
474
+ c->vis = vis;
475
+ c->next_def_vis = ndv;
476
+ return PM_VISIT_SKIP;
477
+ }
478
+ case PM_DEF_NODE: {
479
+ const pm_def_node_t *n = (const pm_def_node_t *) node;
480
+ uint32_t name = cid(c, n->name);
481
+ int sing = c->singleton || n->receiver != NULL;
482
+ /* a bare `private` doesn't reach `def self.x` */
483
+ int vis = c->next_def_vis >= 0 ? c->next_def_vis : (n->receiver && !c->singleton) ? V_PUBLIC : c->vis;
484
+ c->next_def_vis = -1;
485
+ uint32_t cur = c->cur;
486
+ int64_t cur_name = c->cur_name;
487
+ int32_t self_q = c->self_q;
488
+ c->self_q = -1;
489
+ if (!c->is_test && !c->in_eval) {
490
+ const pm_node_t *recv = n->receiver;
491
+ sbuf q = {0};
492
+ int32_t pending_recv = -1;
493
+ if (recv && (PM_NODE_TYPE_P(recv, PM_CONSTANT_READ_NODE) || PM_NODE_TYPE_P(recv, PM_CONSTANT_PATH_NODE))) {
494
+ /* `def Name.x` belongs to Name. At top level or written `::Name` that is Name
495
+ * itself; inside a namespace it is qualified as if nested until
496
+ * place_singleton_defs looks Name up. */
497
+ const char *rt;
498
+ size_t rn;
499
+ slice(c, recv, &rt, &rn);
500
+ if (c->ns.n && rt == (const char *) c->src + recv->location.start) {
501
+ sb_put(&q, c->ns.s, c->ns.n), sb_put(&q, "::", 2);
502
+ pending_recv = (int32_t) intern(rt, rn);
503
+ }
504
+ sb_put(&q, rt, rn);
505
+ c->self_q = (int32_t) intern(q.s, q.n);
506
+ } else if (c->ns.n) {
507
+ sb_put(&q, c->ns.s, c->ns.n);
508
+ } else {
509
+ sb_puts(&q, "Object");
510
+ }
511
+ sb_putc(&q, sing ? '.' : '#');
512
+ sb_put(&q, S(name), SLEN(name));
513
+ c->cur = add_def(c, sing ? K_SMETHOD : K_METHOD, name, q.s, q.n, n->name_loc.start, end_off(node), vis);
514
+ if (pending_recv >= 0) PUSH(SRECV, (srecv_t){c->cur, (uint32_t) pending_recv, c->nest});
515
+ free(q.s);
516
+ }
517
+ c->cur_name = name;
518
+ pm_visit_child_nodes(node, visit, c);
519
+ c->cur = cur;
520
+ c->cur_name = cur_name;
521
+ c->self_q = self_q;
522
+ return PM_VISIT_SKIP;
523
+ }
524
+ case PM_CALL_NODE:
525
+ visit_call(c, node);
526
+ return PM_VISIT_DESCEND;
527
+ case PM_SYMBOL_NODE: {
528
+ size_t n;
529
+ const char *s = str_of(&((const pm_symbol_node_t *) node)->unescaped, &n);
530
+ if (n) {
531
+ add_ref_str(c, s, n, 0, node->location.start);
532
+ if (is_ident_char((unsigned char) s[n - 1])) {
533
+ sbuf b = {0};
534
+ sb_put(&b, s, n);
535
+ sb_putc(&b, '=');
536
+ add_ref_str(c, b.s, b.n, 0, node->location.start);
537
+ free(b.s);
538
+ }
539
+ if (O.inflect) camel_refs(c, s, n, node->location.start);
540
+ }
541
+ return PM_VISIT_DESCEND;
542
+ }
543
+ case PM_STRING_NODE: {
544
+ size_t n;
545
+ const char *s = str_of(&((const pm_string_node_t *) node)->unescaped, &n);
546
+ if (const_shaped(s, n)) {
547
+ const char *seg;
548
+ size_t sn;
549
+ last_segment(s, n, &seg, &sn);
550
+ add_ref_str(c, seg, sn, 1, node->location.start);
551
+ } else if (meth_shaped(s, n)) {
552
+ add_ref_str(c, s, n, 0, node->location.start);
553
+ }
554
+ return PM_VISIT_DESCEND;
555
+ }
556
+ case PM_CONSTANT_READ_NODE:
557
+ add_ref(c, cid(c, ((const pm_constant_read_node_t *) node)->name), 1, node->location.start);
558
+ return PM_VISIT_DESCEND;
559
+ case PM_CONSTANT_PATH_NODE:
560
+ add_ref(c, cid(c, ((const pm_constant_path_node_t *) node)->name), 1, node->location.start);
561
+ return PM_VISIT_DESCEND;
562
+ case PM_CONSTANT_WRITE_NODE: {
563
+ const pm_constant_write_node_t *n = (const pm_constant_write_node_t *) node;
564
+ if (c->cur == 0 && !c->is_test && !c->in_eval) {
565
+ uint32_t name = cid(c, n->name);
566
+ sbuf q = {0};
567
+ if (c->ns.n) sb_put(&q, c->ns.s, c->ns.n), sb_put(&q, "::", 2);
568
+ sb_put(&q, S(name), SLEN(name));
569
+ add_def(c, K_CONST, name, q.s, q.n, n->name_loc.start, end_off(node), V_PUBLIC);
570
+ free(q.s);
571
+ }
572
+ return PM_VISIT_DESCEND;
573
+ }
574
+ case PM_SUPER_NODE:
575
+ case PM_FORWARDING_SUPER_NODE:
576
+ if (c->cur_name >= 0) add_ref(c, (uint32_t) c->cur_name, 0, node->location.start);
577
+ if (c->cur && !c->is_test && !c->in_eval) D.a[c->cur].overrides = 1;
578
+ return PM_VISIT_DESCEND;
579
+ case PM_INTERPOLATED_STRING_NODE:
580
+ case PM_INTERPOLATED_SYMBOL_NODE: {
581
+ sbuf g = {0};
582
+ int is_const = 0;
583
+ if (glob_of(interp_parts(node), &g, &is_const)) {
584
+ PUSH(PREF, (pref_t){c->is_test ? -1 : (int32_t) c->cur, intern(g.s, g.n), c->file,
585
+ line_at(c, node->location.start), (uint8_t) is_const});
586
+ }
587
+ free(g.s);
588
+ return PM_VISIT_DESCEND;
589
+ }
590
+ case PM_CALL_OPERATOR_WRITE_NODE: {
591
+ const pm_call_operator_write_node_t *n = (const pm_call_operator_write_node_t *) node;
592
+ add_ref(c, cid(c, n->read_name), 0, node->location.start);
593
+ add_ref(c, cid(c, n->write_name), 0, node->location.start);
594
+ return PM_VISIT_DESCEND;
595
+ }
596
+ case PM_CALL_OR_WRITE_NODE: {
597
+ const pm_call_or_write_node_t *n = (const pm_call_or_write_node_t *) node;
598
+ add_ref(c, cid(c, n->read_name), 0, node->location.start);
599
+ add_ref(c, cid(c, n->write_name), 0, node->location.start);
600
+ return PM_VISIT_DESCEND;
601
+ }
602
+ case PM_CALL_AND_WRITE_NODE: {
603
+ const pm_call_and_write_node_t *n = (const pm_call_and_write_node_t *) node;
604
+ add_ref(c, cid(c, n->read_name), 0, node->location.start);
605
+ add_ref(c, cid(c, n->write_name), 0, node->location.start);
606
+ return PM_VISIT_DESCEND;
607
+ }
608
+ default:
609
+ return PM_VISIT_DESCEND;
610
+ }
611
+ }
612
+
613
+ /* Sorbet's inline RBS signatures live in #: and #| comments. */
614
+ static void rbs_scan(ctx_t *c, const char *b, size_t n) {
615
+ uint32_t cur = c->cur;
616
+ c->cur = 0;
617
+ for (size_t i = 0; i + 1 < n; i++) {
618
+ if (b[i] != '#' || (b[i + 1] != ':' && b[i + 1] != '|')) continue;
619
+ size_t j = i + 2;
620
+ while (j < n && b[j] != '\n') {
621
+ if (isupper((unsigned char) b[j]) && !is_ident_char((unsigned char) b[j - 1])) {
622
+ size_t st = j;
623
+ while (j < n && (is_ident_char((unsigned char) b[j]) ||
624
+ (b[j] == ':' && j + 1 < n && b[j + 1] == ':')))
625
+ j += b[j] == ':' ? 2 : 1;
626
+ size_t seg = st;
627
+ for (size_t k = st; k <= j; k++) {
628
+ if (k == j || (b[k] == ':' && k + 1 < j && b[k + 1] == ':')) {
629
+ if (k > seg) add_ref_str(c, b + seg, k - seg, 1, (uint32_t) seg);
630
+ seg = k + 2;
631
+ k++;
632
+ }
633
+ }
634
+ } else {
635
+ j++;
636
+ }
637
+ }
638
+ i = j;
639
+ }
640
+ c->cur = cur;
641
+ }
642
+
643
+ void index_file(const char *abs, const char *rel, int kind) {
644
+ size_t n;
645
+ char *buf = read_file(abs, &n);
646
+ if (!buf) return;
647
+ uint32_t fi = (uint32_t) FILES.n;
648
+ PUSH(FILES, xstrdup(rel));
649
+ int is_test = any_glob(&O.tests, rel);
650
+ PUSH(FTEST, (uint8_t) is_test);
651
+ PUSH(FTEMPLATE, (uint8_t) (kind != FK_RUBY));
652
+ if (kind == FK_TEMPLATE) erb_to_ruby(buf, n);
653
+ if (kind == FK_HAML || kind == FK_SLIM) {
654
+ size_t rn;
655
+ char *ruby = haml_to_ruby(buf, n, kind == FK_SLIM, &rn);
656
+ free(buf);
657
+ buf = ruby;
658
+ n = rn;
659
+ kind = FK_TEMPLATE;
660
+ }
661
+
662
+ pm_arena_t *arena = pm_arena_new();
663
+ pm_parser_t *p = pm_parser_new(arena, (const uint8_t *) buf, n, OPTS);
664
+ pm_node_t *root = pm_parse(p);
665
+ if (kind == FK_RUBY && pm_parser_errors_size(p) && memmem(buf, n, "<%", 2)) {
666
+ /* old-style generator templates: ERB in a .rb file */
667
+ pm_parser_free(p);
668
+ pm_arena_free(arena);
669
+ kind = FK_TEMPLATE;
670
+ FTEMPLATE.a[fi] = 1;
671
+ is_test = FTEST.a[fi] = 0; /* a generator template, even when named *_spec.rb */
672
+ erb_to_ruby(buf, n);
673
+ arena = pm_arena_new();
674
+ p = pm_parser_new(arena, (const uint8_t *) buf, n, OPTS);
675
+ root = pm_parse(p);
676
+ }
677
+ ctx_t c;
678
+ memset(&c, 0, sizeof c);
679
+ c.p = p;
680
+ c.src = (const uint8_t *) buf;
681
+ c.srclen = n;
682
+ c.file = fi;
683
+ c.is_test = is_test;
684
+ c.cur_name = -1;
685
+ c.next_def_vis = -1;
686
+ c.nest = -1;
687
+ c.self_q = -1;
688
+ pm_visit_node(root, visit, &c);
689
+ rbs_scan(&c, buf, n);
690
+ if (pm_parser_errors_size(p)) {
691
+ if (kind == FK_TEMPLATE) {
692
+ TEMPLATE_ERRORS++;
693
+ } else {
694
+ const pm_diagnostic_t *e = pm_parser_errors_first(p);
695
+ PUSH(PERR, (perr_t){fi, line_at(&c, pm_diagnostic_location(e).start), xstrdup(pm_diagnostic_message(e))});
696
+ }
697
+ }
698
+ free(c.ns.s);
699
+ pm_parser_free(p);
700
+ pm_arena_free(arena);
701
+ free(buf);
702
+ }