@@ -3,92 +3,92 @@ local guide = require 'parser.guide'
33--- @class vm
44local vm = require ' vm.vm'
55
6- --- @class vm.local
6+ --- @class vm.variable
77--- @field sets parser.object[]
88--- @field gets parser.object[]
99--- @field node ? vm.node
1010
1111--- @class parser.object
12- --- @field package _localID string| false
13- --- @field package _localIDs table<string, vm.local >
12+ --- @field package _variableID string| false
13+ --- @field package _variableIDs table<string, vm.variable >
1414
15- local compileLocalID , getLocal
15+ local compileVariableID , getVariable
1616
1717local compileSwitch = util .switch ()
1818 : case ' local'
1919 : case ' self'
2020 : call (function (source )
21- source ._localID = (' %d' ):format (source .start )
21+ source ._variableID = (' l| %d' ):format (source .start )
2222 if not source .ref then
2323 return
2424 end
2525 for _ , ref in ipairs (source .ref ) do
26- compileLocalID (ref )
26+ compileVariableID (ref )
2727 end
2828 end )
2929 : case ' setlocal'
3030 : case ' getlocal'
3131 : call (function (source )
32- source ._localID = (' %d' ):format (source .node .start )
33- compileLocalID (source .next )
32+ source ._variableID = (' l| %d' ):format (source .node .start )
33+ compileVariableID (source .next )
3434 end )
3535 : case ' getfield'
3636 : case ' setfield'
3737 : call (function (source )
38- local parentID = source .node ._localID
38+ local parentID = source .node ._variableID
3939 if not parentID then
4040 return
4141 end
4242 local key = guide .getKeyName (source )
4343 if type (key ) ~= ' string' then
4444 return
4545 end
46- source ._localID = parentID .. vm .ID_SPLITE .. key
47- source .field ._localID = source ._localID
46+ source ._variableID = parentID .. vm .ID_SPLITE .. key
47+ source .field ._variableID = source ._variableID
4848 if source .type == ' getfield' then
49- compileLocalID (source .next )
49+ compileVariableID (source .next )
5050 end
5151 end )
5252 : case ' getmethod'
5353 : case ' setmethod'
5454 : call (function (source )
55- local parentID = source .node ._localID
55+ local parentID = source .node ._variableID
5656 if not parentID then
5757 return
5858 end
5959 local key = guide .getKeyName (source )
6060 if type (key ) ~= ' string' then
6161 return
6262 end
63- source ._localID = parentID .. vm .ID_SPLITE .. key
64- source .method ._localID = source ._localID
63+ source ._variableID = parentID .. vm .ID_SPLITE .. key
64+ source .method ._variableID = source ._variableID
6565 if source .type == ' getmethod' then
66- compileLocalID (source .next )
66+ compileVariableID (source .next )
6767 end
6868 end )
6969 : case ' getindex'
7070 : case ' setindex'
7171 : call (function (source )
72- local parentID = source .node ._localID
72+ local parentID = source .node ._variableID
7373 if not parentID then
7474 return
7575 end
7676 local key = guide .getKeyName (source )
7777 if type (key ) ~= ' string' then
7878 return
7979 end
80- source ._localID = parentID .. vm .ID_SPLITE .. key
81- source .index ._localID = source ._localID
80+ source ._variableID = parentID .. vm .ID_SPLITE .. key
81+ source .index ._variableID = source ._variableID
8282 if source .type == ' setindex' then
83- compileLocalID (source .next )
83+ compileVariableID (source .next )
8484 end
8585 end )
8686
8787local leftSwitch = util .switch ()
8888 : case ' field'
8989 : case ' method'
9090 : call (function (source )
91- return getLocal (source .parent )
91+ return getVariable (source .parent )
9292 end )
9393 : case ' getfield'
9494 : case ' setfield'
@@ -97,7 +97,7 @@ local leftSwitch = util.switch()
9797 : case ' getindex'
9898 : case ' setindex'
9999 : call (function (source )
100- return getLocal (source .node )
100+ return getVariable (source .node )
101101 end )
102102 : case ' getlocal'
103103 : call (function (source )
@@ -111,71 +111,71 @@ local leftSwitch = util.switch()
111111
112112--- @param source parser.object
113113--- @return parser.object ?
114- function getLocal (source )
114+ function getVariable (source )
115115 return leftSwitch (source .type , source )
116116end
117117
118118--- @param id string
119119--- @param source parser.object
120- function vm .insertLocalID (id , source )
120+ function vm .insertVariableID (id , source )
121121 local root = guide .getRoot (source )
122- if not root ._localIDs then
123- root ._localIDs = util .multiTable (2 , function ()
122+ if not root ._variableIDs then
123+ root ._variableIDs = util .multiTable (2 , function ()
124124 return {
125125 sets = {},
126126 gets = {},
127127 }
128128 end )
129129 end
130- local sources = root ._localIDs [id ]
130+ local sources = root ._variableIDs [id ]
131131 if guide .isSet (source ) then
132132 sources .sets [# sources .sets + 1 ] = source
133133 else
134134 sources .gets [# sources .gets + 1 ] = source
135135 end
136136end
137137
138- function compileLocalID (source )
138+ function compileVariableID (source )
139139 if not source then
140140 return
141141 end
142- source ._localID = false
142+ source ._variableID = false
143143 if not compileSwitch :has (source .type ) then
144144 return
145145 end
146146 compileSwitch (source .type , source )
147- local id = source ._localID
147+ local id = source ._variableID
148148 if not id then
149149 return
150150 end
151- vm .insertLocalID (id , source )
151+ vm .insertVariableID (id , source )
152152end
153153
154154--- @param source parser.object
155155--- @return string | false
156- function vm .getLocalID (source )
157- if source ._localID ~= nil then
158- return source ._localID
156+ function vm .getVariableID (source )
157+ if source ._variableID ~= nil then
158+ return source ._variableID
159159 end
160- source ._localID = false
161- local loc = getLocal (source )
160+ source ._variableID = false
161+ local loc = getVariable (source )
162162 if not loc then
163- return source ._localID
163+ return source ._variableID
164164 end
165- compileLocalID (loc )
166- return source ._localID
165+ compileVariableID (loc )
166+ return source ._variableID
167167end
168168
169169--- @param source parser.object
170170--- @param key ? string
171- --- @return vm.local ?
172- function vm .getLocalInfo (source , key )
173- local id = vm .getLocalID (source )
171+ --- @return vm.variable ?
172+ function vm .getVariableInfo (source , key )
173+ local id = vm .getVariableID (source )
174174 if not id then
175175 return nil
176176 end
177177 local root = guide .getRoot (source )
178- if not root ._localIDs then
178+ if not root ._variableIDs then
179179 return nil
180180 end
181181 if key then
@@ -184,14 +184,14 @@ function vm.getLocalInfo(source, key)
184184 end
185185 id = id .. vm .ID_SPLITE .. key
186186 end
187- return root ._localIDs [id ]
187+ return root ._variableIDs [id ]
188188end
189189
190190--- @param source parser.object
191191--- @param key ? string
192192--- @return parser.object[] ?
193- function vm .getLocalSets (source , key )
194- local localInfo = vm .getLocalInfo (source , key )
193+ function vm .getVariableSets (source , key )
194+ local localInfo = vm .getVariableInfo (source , key )
195195 if not localInfo then
196196 return nil
197197 end
201201--- @param source parser.object
202202--- @param key ? string
203203--- @return parser.object[] ?
204- function vm .getLocalGets (source , key )
205- local localInfo = vm .getLocalInfo (source , key )
204+ function vm .getVariableGets (source , key )
205+ local localInfo = vm .getVariableInfo (source , key )
206206 if not localInfo then
207207 return nil
208208 end
@@ -212,19 +212,19 @@ end
212212--- @param source parser.object
213213--- @param includeGets boolean
214214--- @return parser.object[] ?
215- function vm .getLocalFields (source , includeGets )
216- local id = vm .getLocalID (source )
215+ function vm .getVariableFields (source , includeGets )
216+ local id = vm .getVariableID (source )
217217 if not id then
218218 return nil
219219 end
220220 local root = guide .getRoot (source )
221- if not root ._localIDs then
221+ if not root ._variableIDs then
222222 return nil
223223 end
224224 -- TODO:optimize
225225 local clock = os.clock ()
226226 local fields = {}
227- for lid , sources in pairs (root ._localIDs ) do
227+ for lid , sources in pairs (root ._variableIDs ) do
228228 if lid ~= id
229229 and util .stringStartWith (lid , id )
230230 and lid :sub (# id + 1 , # id + 1 ) == vm .ID_SPLITE
@@ -242,7 +242,7 @@ function vm.getLocalFields(source, includeGets)
242242 end
243243 local cost = os.clock () - clock
244244 if cost > 1.0 then
245- log .warn (' local -id getFields takes %.3f seconds' , cost )
245+ log .warn (' variable -id getFields takes %.3f seconds' , cost )
246246 end
247247 return fields
248248end
0 commit comments