summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/core/boolean.lua32
-rw-r--r--server-beta/src/core/engineer.lua13
-rw-r--r--server-beta/src/core/field.lua18
-rw-r--r--server-beta/src/core/getglobal.lua32
-rw-r--r--server-beta/src/core/local.lua32
-rw-r--r--server-beta/src/core/method.lua18
-rw-r--r--server-beta/src/core/number.lua32
-rw-r--r--server-beta/src/core/string.lua32
-rw-r--r--server-beta/src/core/table.lua13
9 files changed, 158 insertions, 64 deletions
diff --git a/server-beta/src/core/boolean.lua b/server-beta/src/core/boolean.lua
index c27f6579..15aef9e5 100644
--- a/server-beta/src/core/boolean.lua
+++ b/server-beta/src/core/boolean.lua
@@ -1,11 +1,39 @@
+local guide = require 'parser.guide'
+
local m = {}
function m:def(source, callback)
- self:asIndex(source, 'def', callback)
+ local parent = source.parent
+ if not parent then
+ return
+ end
+ if parent.type ~= 'setindex' and parent.type ~= 'getindex' then
+ return
+ end
+ local node = parent.node
+ local key = guide.getKeyName(source)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' then
+ callback(src, mode)
+ end
+ end)
end
function m:ref(source, callback)
- self:asIndex(source, 'ref', callback)
+ local parent = source.parent
+ if not parent then
+ return
+ end
+ if parent.type ~= 'setindex' and parent.type ~= 'getindex' then
+ return
+ end
+ local node = parent.node
+ local key = guide.getKeyName(source)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' or mode == 'get' then
+ callback(src, mode)
+ end
+ end)
end
return m
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua
index efc88828..05976c76 100644
--- a/server-beta/src/core/engineer.lua
+++ b/server-beta/src/core/engineer.lua
@@ -53,19 +53,6 @@ mt['table'] = require 'core.table'
-- end
--end
-function mt:asIndex(source, mode, callback)
- local parent = source.parent
- if not parent then
- return
- end
- if parent.type ~= 'setindex' and parent.type ~= 'getindex' then
- return
- end
- local node = parent.node
- local key = guide.getKeyName(source)
- self:eachField(node, key, mode, callback)
-end
-
function mt:getSpecial(source)
local node = source.node
if node.tag ~= '_ENV' then
diff --git a/server-beta/src/core/field.lua b/server-beta/src/core/field.lua
index 1304eeab..cd50d713 100644
--- a/server-beta/src/core/field.lua
+++ b/server-beta/src/core/field.lua
@@ -5,19 +5,21 @@ local m = {}
function m:def(source, callback)
local node = source.parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, 'def', callback)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' then
+ callback(src, mode)
+ end
+ end)
end
function m:ref(source, callback)
local node = source.parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, 'ref', callback)
-end
-
-function m:field(source, callback)
- local node = source.parent.node
- local key = guide.getKeyName(source)
- self:eachField(node, key, 'field', callback)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' or mode == 'get' then
+ callback(src, mode)
+ end
+ end)
end
return m
diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua
index 6c14cc70..74c05e29 100644
--- a/server-beta/src/core/getglobal.lua
+++ b/server-beta/src/core/getglobal.lua
@@ -22,17 +22,27 @@ function m:ref(source, callback)
end)
end
-function m:field(source, callback)
- self:search(source, 'getglobal', 'ref', function (src)
- local parent = src.parent
- local tp = parent.type
- if tp == 'setfield'
- or tp == 'getfield'
- or tp == 'setmethod'
- or tp == 'getmethod'
- or tp == 'setindex'
- or tp == 'getindex' then
- callback(parent)
+function m:field(source, key, callback)
+ local global = guide.getKeyName(source)
+ self:eachField(source.node, global, function (src, mode)
+ if mode == 'get' then
+ local parent = src.parent
+ if key == guide.getKeyName(parent) then
+ local tp = parent.type
+ if tp == 'getfield' then
+ callback(parent.field, 'get')
+ elseif tp == 'getmethod' then
+ callback(parent.method, 'get')
+ elseif tp == 'getindex' then
+ callback(parent.index, 'get')
+ elseif tp == 'setfield' then
+ callback(parent.field, 'set')
+ elseif tp == 'setmethod' then
+ callback(parent.method, 'set')
+ elseif tp == 'setindex' then
+ callback(parent.index, 'set')
+ end
+ end
end
end)
end
diff --git a/server-beta/src/core/local.lua b/server-beta/src/core/local.lua
index 113637a9..1916ba88 100644
--- a/server-beta/src/core/local.lua
+++ b/server-beta/src/core/local.lua
@@ -16,7 +16,7 @@ function m:def(source, callback)
if source.tag == 'self' then
local method = source.method
local node = method.node
- self:eachRef(node, 'def', callback)
+ self:eachDef(node, callback)
end
end
@@ -36,7 +36,7 @@ function m:ref(source, callback)
if source.tag == 'self' then
local method = source.method
local node = method.node
- self:eachRef(node, 'ref', callback)
+ self:eachRef(node, callback)
end
end
@@ -47,18 +47,22 @@ function m:field(source, key, callback)
local parent = ref.parent
if key == guide.getKeyName(parent) then
local tp = parent.type
- if tp == 'setfield'
- or tp == 'setmethod'
- or tp == 'setindex' then
- callback(parent, 'set')
- elseif tp == 'getfield'
- or tp == 'getmethod'
- or tp == 'getindex' then
- callback(parent, 'get')
+ if tp == 'setfield' then
+ callback(parent.field, 'set')
+ elseif tp == 'setmethod' then
+ callback(parent.method, 'set')
+ elseif tp == 'setindex' then
+ callback(parent.index, 'set')
+ elseif tp == 'getfield' then
+ callback(parent.field, 'get')
+ elseif tp == 'getmethod' then
+ callback(parent.method, 'get')
+ elseif tp == 'getindex' then
+ callback(parent.index, 'get')
end
end
elseif ref.type == 'setlocal' then
- self:eachRef(ref.value, 'field', callback)
+ self:eachField(ref.value, key, callback)
elseif ref.type == 'getglobal' then
-- _ENV.XXX
if key == guide.getKeyName(ref) then
@@ -77,9 +81,9 @@ function m:field(source, key, callback)
-- local node = method.node
-- self:eachRef(node, 'field', callback)
--end
- --if source.value then
- -- self:eachField(source.value, nil, 'ref', callback)
- --end
+ if source.value then
+ self:eachField(source.value, key, callback)
+ end
end
return m
diff --git a/server-beta/src/core/method.lua b/server-beta/src/core/method.lua
index 9217c4a3..78f74e7a 100644
--- a/server-beta/src/core/method.lua
+++ b/server-beta/src/core/method.lua
@@ -5,19 +5,21 @@ local m = {}
function m:def(source, callback)
local node = source.parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, 'def', callback)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' then
+ callback(src, mode)
+ end
+ end)
end
function m:ref(source, callback)
local node = source.parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, 'ref', callback)
-end
-
-function m:field(source, callback)
- local node = source.parent.node
- local key = guide.getKeyName(source)
- self:eachField(node, key, 'field', callback)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' or mode == 'get' then
+ callback(src, mode)
+ end
+ end)
end
return m
diff --git a/server-beta/src/core/number.lua b/server-beta/src/core/number.lua
index c27f6579..15aef9e5 100644
--- a/server-beta/src/core/number.lua
+++ b/server-beta/src/core/number.lua
@@ -1,11 +1,39 @@
+local guide = require 'parser.guide'
+
local m = {}
function m:def(source, callback)
- self:asIndex(source, 'def', callback)
+ local parent = source.parent
+ if not parent then
+ return
+ end
+ if parent.type ~= 'setindex' and parent.type ~= 'getindex' then
+ return
+ end
+ local node = parent.node
+ local key = guide.getKeyName(source)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' then
+ callback(src, mode)
+ end
+ end)
end
function m:ref(source, callback)
- self:asIndex(source, 'ref', callback)
+ local parent = source.parent
+ if not parent then
+ return
+ end
+ if parent.type ~= 'setindex' and parent.type ~= 'getindex' then
+ return
+ end
+ local node = parent.node
+ local key = guide.getKeyName(source)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' or mode == 'get' then
+ callback(src, mode)
+ end
+ end)
end
return m
diff --git a/server-beta/src/core/string.lua b/server-beta/src/core/string.lua
index c27f6579..15aef9e5 100644
--- a/server-beta/src/core/string.lua
+++ b/server-beta/src/core/string.lua
@@ -1,11 +1,39 @@
+local guide = require 'parser.guide'
+
local m = {}
function m:def(source, callback)
- self:asIndex(source, 'def', callback)
+ local parent = source.parent
+ if not parent then
+ return
+ end
+ if parent.type ~= 'setindex' and parent.type ~= 'getindex' then
+ return
+ end
+ local node = parent.node
+ local key = guide.getKeyName(source)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' then
+ callback(src, mode)
+ end
+ end)
end
function m:ref(source, callback)
- self:asIndex(source, 'ref', callback)
+ local parent = source.parent
+ if not parent then
+ return
+ end
+ if parent.type ~= 'setindex' and parent.type ~= 'getindex' then
+ return
+ end
+ local node = parent.node
+ local key = guide.getKeyName(source)
+ self:eachField(node, key, function (src, mode)
+ if mode == 'set' or mode == 'get' then
+ callback(src, mode)
+ end
+ end)
end
return m
diff --git a/server-beta/src/core/table.lua b/server-beta/src/core/table.lua
index 1f6c45c4..36f4f887 100644
--- a/server-beta/src/core/table.lua
+++ b/server-beta/src/core/table.lua
@@ -1,11 +1,16 @@
+local guide = require 'parser.guide'
+
local m = {}
-function m:field(source, callback)
+function m:field(source, key, callback)
for i = 1, #source do
local src = source[i]
- if src.type == 'tablefield'
- or src.type == 'tableindex' then
- callback(src)
+ if key == guide.getKeyName(src) then
+ if src.type == 'tablefield' then
+ callback(src.field, 'set')
+ elseif src.type == 'tableindex' then
+ callback(src.index, 'set')
+ end
end
end
end