-
Notifications
You must be signed in to change notification settings - Fork 1
/
code.analyze.red
78 lines (63 loc) · 1.81 KB
/
code.analyze.red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Red [
Title: "code.analyze.red"
]
.list-funcs: function[red-file][
src: read red-file
src-block: load src
list: .func.name.list src-block
]
list-funcs: :.list-funcs
.get-func-body: function[.func-name red-file][
;.func-name: 'emit-nav
src: read red-file
src-block: load src
Ctx: Context src-block
if ((body-of Ctx) = []) [
new-code: .code.analyze code
Ctx: Context new-code
func-src: get in Ctx .func-name
]
]
get-func-body: :.get-func-body
get-func-spec: :.get-func-body
.func.name.list: function[src-block /local .func-name-list][
.func-name-list: copy []
foreach element src-block [
if ((type? element) = set-word!) [
element-src: select src-block element
if element-src = 'function [
append .func-name-list to-word element
]
]
]
return .func-name-list
]
collect-funcs: copy []
.code.analyze: function[code][
code-copy: copy code
forall code [
i: index? code
element: code/1
; type: type? element
; if (type = set-word!) [
if set-word? element [
j: i + 1
next-element: code-copy/:j
if (next-element = 'func) or (next-element = 'function) [
func-collect: copy []
append func-collect compose/deep [(element) (next-element)]
j: i + 2
append/only func-collect code-copy/:j
j: i + 3
append/only func-collect code-copy/:j
append collect-funcs func-collect
]
]
if block? element [
.code.analyze element
]
]
return collect-funcs
]
.analyze-code: :.code.analyze
analyze-code: :.analyze-code