@@ -18,7 +18,7 @@ local vm = require 'vm.vm'
18
18
19
19
local searchFieldSwitch = util .switch ()
20
20
: case ' table'
21
- : call (function (suri , source , key , pushResult )
21
+ : call (function (suri , source , key , ref , pushResult )
22
22
local hasFiled = false
23
23
for _ , field in ipairs (source ) do
24
24
if field .type == ' tablefield'
@@ -52,16 +52,16 @@ local searchFieldSwitch = util.switch()
52
52
end
53
53
end )
54
54
: case ' string'
55
- : call (function (suri , source , key , pushResult )
55
+ : call (function (suri , source , key , ref , pushResult )
56
56
-- change to `string: stringlib` ?
57
57
local stringlib = globalMgr .getGlobal (' type' , ' stringlib' )
58
58
if stringlib then
59
- vm .getClassFields (suri , stringlib , key , pushResult )
59
+ vm .getClassFields (suri , stringlib , key , ref , pushResult )
60
60
end
61
61
end )
62
62
: case ' local'
63
63
: case ' self'
64
- : call (function (suri , node , key , pushResult )
64
+ : call (function (suri , node , key , ref , pushResult )
65
65
local fields
66
66
if key then
67
67
fields = localID .getSources (node , key )
@@ -70,12 +70,14 @@ local searchFieldSwitch = util.switch()
70
70
end
71
71
if fields then
72
72
for _ , src in ipairs (fields ) do
73
- pushResult (src )
73
+ if ref or guide .isSet (src ) then
74
+ pushResult (src )
75
+ end
74
76
end
75
77
end
76
78
end )
77
79
: case ' doc.type.array'
78
- : call (function (suri , source , key , pushResult )
80
+ : call (function (suri , source , key , ref , pushResult )
79
81
if type (key ) == ' number' then
80
82
if key < 1
81
83
or not math.tointeger (key ) then
@@ -85,7 +87,7 @@ local searchFieldSwitch = util.switch()
85
87
pushResult (source .node )
86
88
end )
87
89
: case ' doc.type.table'
88
- : call (function (suri , source , key , pushResult )
90
+ : call (function (suri , source , key , ref , pushResult )
89
91
for _ , field in ipairs (source .fields ) do
90
92
local fieldKey = field .name
91
93
if fieldKey .type == ' doc.type' then
@@ -111,7 +113,7 @@ local searchFieldSwitch = util.switch()
111
113
end
112
114
end )
113
115
: case ' global'
114
- : call (function (suri , node , key , pushResult )
116
+ : call (function (suri , node , key , ref , pushResult )
115
117
if node .cate == ' variable' then
116
118
if key then
117
119
if type (key ) ~= ' string' then
@@ -122,8 +124,10 @@ local searchFieldSwitch = util.switch()
122
124
for _ , set in ipairs (global :getSets (suri )) do
123
125
pushResult (set )
124
126
end
125
- for _ , get in ipairs (global :getGets (suri )) do
126
- pushResult (get )
127
+ if ref then
128
+ for _ , get in ipairs (global :getGets (suri )) do
129
+ pushResult (get )
130
+ end
127
131
end
128
132
end
129
133
else
@@ -132,17 +136,19 @@ local searchFieldSwitch = util.switch()
132
136
for _ , set in ipairs (global :getSets (suri )) do
133
137
pushResult (set )
134
138
end
135
- for _ , get in ipairs (global :getGets (suri )) do
136
- pushResult (get )
139
+ if ref then
140
+ for _ , get in ipairs (global :getGets (suri )) do
141
+ pushResult (get )
142
+ end
137
143
end
138
144
end
139
145
end
140
146
end
141
147
if node .cate == ' type' then
142
- vm .getClassFields (suri , node , key , pushResult )
148
+ vm .getClassFields (suri , node , key , ref , pushResult )
143
149
end
144
150
end )
145
- : default (function (suri , source , key , pushResult )
151
+ : default (function (suri , source , key , ref , pushResult )
146
152
local node = source ._globalNode
147
153
if not node then
148
154
return
@@ -174,12 +180,12 @@ local searchFieldSwitch = util.switch()
174
180
end
175
181
end
176
182
if node .cate == ' type' then
177
- vm .getClassFields (suri , node , key , pushResult )
183
+ vm .getClassFields (suri , node , key , ref , pushResult )
178
184
end
179
185
end )
180
186
181
187
182
- function vm .getClassFields (suri , node , key , pushResult )
188
+ function vm .getClassFields (suri , node , key , ref , pushResult )
183
189
local mark = {}
184
190
185
191
local function searchClass (class , searchedFields )
@@ -206,7 +212,7 @@ function vm.getClassFields(suri, node, key, pushResult)
206
212
-- check local field and global field
207
213
if set .bindSources then
208
214
for _ , src in ipairs (set .bindSources ) do
209
- searchFieldSwitch (src .type , suri , src , key , function (field )
215
+ searchFieldSwitch (src .type , suri , src , key , ref , function (field )
210
216
local fieldKey = guide .getKeyName (field )
211
217
if not searchedFields [fieldKey ]
212
218
and guide .isSet (field ) then
@@ -215,7 +221,7 @@ function vm.getClassFields(suri, node, key, pushResult)
215
221
end
216
222
end )
217
223
if src .value and src .value .type == ' table' then
218
- searchFieldSwitch (' table' , suri , src .value , key , function (field )
224
+ searchFieldSwitch (' table' , suri , src .value , key , ref , function (field )
219
225
local fieldKey = guide .getKeyName (field )
220
226
if not searchedFields [fieldKey ]
221
227
and guide .isSet (field ) then
@@ -361,7 +367,7 @@ local function getReturnOfSetMetaTable(args)
361
367
node :merge (vm .compileNode (tbl ))
362
368
end
363
369
if mt then
364
- vm .compileByParentNode (mt , ' __index' , function (src )
370
+ vm .compileByParentNode (mt , ' __index' , false , function (src )
365
371
for n in vm .compileNode (src ):eachObject () do
366
372
if n .type == ' global'
367
373
or n .type == ' local'
@@ -529,11 +535,11 @@ end
529
535
--- @param source vm.node
530
536
--- @param key ? any
531
537
--- @param pushResult fun ( source : parser.object )
532
- function vm .compileByParentNode (source , key , pushResult )
538
+ function vm .compileByParentNode (source , key , ref , pushResult )
533
539
local parentNode = vm .compileNode (source )
534
540
local suri = guide .getUri (source )
535
541
for node in parentNode :eachObject () do
536
- searchFieldSwitch (node .type , suri , node , key , pushResult )
542
+ searchFieldSwitch (node .type , suri , node , key , ref , pushResult )
537
543
end
538
544
end
539
545
@@ -903,7 +909,7 @@ local compilerSwitch = util.switch()
903
909
if key == nil then
904
910
return
905
911
end
906
- vm .compileByParentNode (source .node , key , function (src )
912
+ vm .compileByParentNode (source .node , key , false , function (src )
907
913
if src .type == ' doc.type.field'
908
914
or src .type == ' doc.field' then
909
915
vm .setNode (source , vm .compileNode (src ))
@@ -929,7 +935,7 @@ local compilerSwitch = util.switch()
929
935
vm .setNode (source , value )
930
936
end
931
937
else
932
- vm .compileByParentNode (source .node , key , function (src )
938
+ vm .compileByParentNode (source .node , key , false , function (src )
933
939
vm .setNode (source , vm .compileNode (src ))
934
940
end )
935
941
end
@@ -940,7 +946,7 @@ local compilerSwitch = util.switch()
940
946
return
941
947
end
942
948
local key = guide .getKeyName (source )
943
- vm .compileByParentNode (source .node , key , function (src )
949
+ vm .compileByParentNode (source .node , key , false , function (src )
944
950
if src .type == ' doc.type.field'
945
951
or src .type == ' doc.field' then
946
952
vm .setNode (source , vm .compileNode (src ))
@@ -953,7 +959,7 @@ local compilerSwitch = util.switch()
953
959
return
954
960
end
955
961
local key = guide .getKeyName (source )
956
- vm .compileByParentNode (source .node , key , function (src )
962
+ vm .compileByParentNode (source .node , key , false , function (src )
957
963
vm .setNode (source , vm .compileNode (src ))
958
964
end )
959
965
end )
@@ -976,7 +982,7 @@ local compilerSwitch = util.switch()
976
982
end
977
983
978
984
if not hasMarkDoc then
979
- vm .compileByParentNode (source .parent , guide .getKeyName (source ), function (src )
985
+ vm .compileByParentNode (source .parent , guide .getKeyName (source ), false , function (src )
980
986
vm .setNode (source , vm .compileNode (src ))
981
987
end )
982
988
end
0 commit comments