|
11 | 11 | source-code-analysis?)] |
12 | 12 | [source-code-analysis? (-> any/c boolean?)] |
13 | 13 | [source-code-analysis-code (-> source-code-analysis? source?)] |
| 14 | + [source-code-analysis-enriched-syntax (-> source-code-analysis? syntax?)] |
| 15 | + [source-code-analysis-visited-paths (-> source-code-analysis? (listof syntax-path?))] |
14 | 16 | [source-code-analysis-visited-forms (-> source-code-analysis? (listof syntax?))] |
15 | 17 | [source-code-analysis-expansion-time-output (-> source-code-analysis? immutable-string?)] |
16 | 18 | [source-code-analysis-namespace (-> source-code-analysis? namespace?)] |
|
55 | 57 |
|
56 | 58 |
|
57 | 59 | (define-record-type source-code-analysis |
58 | | - (code visited-forms expansion-time-output namespace added-syntax-properties)) |
| 60 | + (code enriched-syntax visited-paths expansion-time-output namespace added-syntax-properties)) |
| 61 | + |
| 62 | + |
| 63 | +;; Backward-compatible accessor that computes visited forms from paths |
| 64 | +(define (source-code-analysis-visited-forms analysis) |
| 65 | + (define stx (source-code-analysis-enriched-syntax analysis)) |
| 66 | + (define paths (source-code-analysis-visited-paths analysis)) |
| 67 | + (for/list ([path (in-list paths)]) |
| 68 | + (syntax-ref stx path))) |
59 | 69 |
|
60 | 70 |
|
61 | 71 | (define (source-analyze code |
|
198 | 208 | #:parent-srcloc-modifier values |
199 | 209 | #:parent-props-modifier values)) |
200 | 210 |
|
201 | | - (define visited |
| 211 | + (define visited-paths |
202 | 212 | (transduce (build-vector original-visits) |
203 | 213 | (peeking |
204 | 214 | (λ (visit) |
205 | 215 | (unless (syntax-original-path visit) |
206 | 216 | (raise-arguments-error |
207 | | - 'source-analyze "pre-enriched visit is missing original path" |
| 217 | + 'source-analyze "visit is missing original path" |
208 | 218 | "visited syntax" visit)))) |
209 | | - (deduplicating #:key syntax-original-path) |
210 | | - (mapping |
211 | | - (λ (visit) |
212 | | - (define path (syntax-original-path visit)) |
213 | | - (define visit-props |
214 | | - (syntax-property-bundle-get-all-properties |
215 | | - expansion-analyzer-props-adjusted-for-visits path)) |
216 | | - (syntax-add-all-properties visit visit-props))) |
217 | | - (mapping enrich) |
218 | | - (peeking |
219 | | - (λ (visit) |
220 | | - (unless (syntax-original-path visit) |
221 | | - (raise-arguments-error |
222 | | - 'source-analyze "post-enriched visit is missing original path" |
223 | | - "visited syntax" visit)))) |
224 | | - (sorting syntax-path<=> #:key syntax-original-path) |
| 219 | + (mapping syntax-original-path) |
| 220 | + (deduplicating) |
| 221 | + (sorting syntax-path<=>) |
225 | 222 | #:into into-list)) |
| 223 | + |
| 224 | + ;; Extract expander-added properties from visits |
| 225 | + ;; Known expander properties that need to be preserved |
| 226 | + (define expander-property-keys '(class-body)) |
| 227 | + (define expander-property-entries |
| 228 | + (for*/list ([(path visit) (in-hash most-recent-visits-by-original-path)] |
| 229 | + [key (in-list expander-property-keys)] |
| 230 | + [val (in-value (syntax-property visit key))] |
| 231 | + #:when val) |
| 232 | + (syntax-property-entry path key val))) |
| 233 | + |
| 234 | + ;; Combine expander and analyzer properties |
| 235 | + (define all-property-entries |
| 236 | + (append (sequence->list (syntax-property-bundle-entries expansion-analyzer-props-adjusted-for-visits)) |
| 237 | + expander-property-entries)) |
| 238 | + (define all-properties (sequence->syntax-property-bundle all-property-entries)) |
| 239 | + |
| 240 | + ;; Label the original program syntax with paths, then add all properties and enrich |
| 241 | + (define program-stx-with-paths (syntax-label-original-paths program-stx)) |
| 242 | + (define program-stx-with-props |
| 243 | + (syntax-add-all-properties program-stx-with-paths all-properties)) |
| 244 | + (define enriched-program-stx (enrich program-stx-with-props)) |
226 | 245 |
|
227 | | - (log-resyntax-debug "visited ~a forms" (length visited)) |
| 246 | + (log-resyntax-debug "visited ~a forms" (length visited-paths)) |
228 | 247 | (source-code-analysis #:code code |
229 | | - #:visited-forms visited |
| 248 | + #:enriched-syntax enriched-program-stx |
| 249 | + #:visited-paths visited-paths |
230 | 250 | #:expansion-time-output output |
231 | 251 | #:namespace ns |
232 | 252 | #:added-syntax-properties expansion-analyzer-props-adjusted-for-visits))) |
|
0 commit comments