diff options
-rw-r--r-- | script-beta/parser/guide.lua | 29 | ||||
-rw-r--r-- | script-beta/vm/eachDef.lua | 11 |
2 files changed, 24 insertions, 16 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 5eff3e1d..a345beb3 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -315,6 +315,7 @@ end --- 遍历所有包含offset的source function m.eachSourceContain(ast, offset, callback) local list = { ast } + local mark = {} while true do local len = #list if len == 0 then @@ -322,14 +323,17 @@ function m.eachSourceContain(ast, offset, callback) end local obj = list[len] list[len] = nil - if m.isInRange(obj, offset) then - if m.isContain(obj, offset) then - local res = callback(obj) - if res ~= nil then - return res + if not mark[obj] then + mark[obj] = true + if m.isInRange(obj, offset) then + if m.isContain(obj, offset) then + local res = callback(obj) + if res ~= nil then + return res + end end + m.addChilds(list, obj, m.childMap) end - m.addChilds(list, obj, m.childMap) end end end @@ -338,14 +342,9 @@ end function m.eachSourceType(ast, type, callback) local cache = ast.typeCache if not cache then - local mark = {} cache = {} ast.typeCache = cache m.eachSource(ast, function (source) - if mark[source] then - return - end - mark[source] = true local tp = source.type if not tp then return @@ -370,6 +369,7 @@ end --- 遍历所有的source function m.eachSource(ast, callback) local list = { ast } + local mark = {} local index = 1 while true do local obj = list[index] @@ -378,8 +378,11 @@ function m.eachSource(ast, callback) end list[index] = false index = index + 1 - callback(obj) - m.addChilds(list, obj, m.childMap) + if not mark[obj] then + mark[obj] = true + callback(obj) + m.addChilds(list, obj, m.childMap) + end end end diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index 92982660..65878ebf 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -79,10 +79,15 @@ function m.eachDef(source, results) return results end -function vm.eachDef(source, callback) +function vm.getDefs(source) local cache = vm.cache.eachDef[source] or m.eachDef(source) vm.cache.eachDef[source] = cache - for i = 1, #cache do - callback(cache[i]) + return cache +end + +function vm.eachDef(source, callback) + local results = vm.getDefs(source) + for i = 1, #results do + callback(results[i]) end end |