Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
CapsAdmin committed Aug 19, 2024
1 parent e05e124 commit 2420c29
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion nattlua/analyzer/control_flow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ return function(META)
self:IsRuntime() and
call_node and
not not_recursive_call and
not obj:IsRefFunction()
not obj:HasReferenceTypes()
then
for _, v in ipairs(self.call_stack) do
-- if the callnode is the same, we're doing some infinite recursion
Expand Down
6 changes: 3 additions & 3 deletions nattlua/analyzer/operators/call.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ do

-- TODO: callbacks with ref arguments should not be called
-- mixed ref args make no sense, maybe ref should be a keyword for the function instead?
if not b:IsRefFunction() and func then
if not b:HasReferenceTypes() and func then
self:Assert(self:Call(b, func:GetInputSignature():Copy(nil, true)))
end
end
Expand All @@ -166,7 +166,7 @@ do
if
analyzer:IsRuntime() and
self:IsCalled() and
not self:IsRefFunction()
not self:HasReferenceTypes()
and
self:GetFunctionBodyNode() and
self:GetFunctionBodyNode().environment == "runtime" and
Expand All @@ -185,7 +185,7 @@ do
not analyzer.config.should_crawl_untyped_functions and
analyzer:IsRuntime() and
self:IsCalled() and
not self:IsRefFunction()
not self:HasReferenceTypes()
and
self:GetFunctionBodyNode() and
self:GetFunctionBodyNode().environment == "runtime" and
Expand Down
16 changes: 8 additions & 8 deletions nattlua/analyzer/operators/function_call_body.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ local function check_input(self, obj, input)

if
contract and
contract:IsReferenceArgument() and
contract:IsReferenceType() and
(
contract.Type ~= "function" or
arg.Type ~= "function" or
Expand All @@ -183,7 +183,7 @@ local function check_input(self, obj, input)
then
self:CreateLocalValue(identifier, arg)
signature_override[i] = arg
signature_override[i]:SetReferenceArgument(true)
signature_override[i]:SetReferenceType(true)
local ok, err = signature_override[i]:IsSubsetOf(contract)

if not ok then
Expand Down Expand Up @@ -216,7 +216,7 @@ local function check_input(self, obj, input)
if
signature_override[i] and
signature_override[i].Type == "union" and
not signature_override[i]:IsReferenceArgument()
not signature_override[i]:IsReferenceType()
then
local merged = shrink_union_to_function_signature(signature_override[i])

Expand Down Expand Up @@ -296,10 +296,10 @@ local function check_input(self, obj, input)
arg.Type == "table" and
contract.Type == "table" and
arg:GetUpvalue() and
not contract:IsReferenceArgument()
not contract:IsReferenceType()
then
mutate_type(self, i, arg, contract, input)
elseif not contract:IsReferenceArgument() then
elseif not contract:IsReferenceType() then
local doit = true

if contract.Type == "union" then
Expand Down Expand Up @@ -465,8 +465,8 @@ return function(self, obj, input)
val = Nil()
local arg = obj:GetInputSignature():Get(argi)

if arg and arg:IsReferenceArgument() then
val:SetReferenceArgument(true)
if arg and arg:IsReferenceType() then
val:SetReferenceType(true)
end
end

Expand Down Expand Up @@ -572,7 +572,7 @@ return function(self, obj, input)
-- if a return type is marked with ref, it will pass the ref value back to the caller
-- a bit like generics
for i, v in ipairs(output_signature:GetData()) do
if v:IsReferenceArgument() then contract:Set(i, output:Get(i)) end
if v:IsReferenceType() then contract:Set(i, output:Get(i)) end
end

return contract
Expand Down
2 changes: 1 addition & 1 deletion nattlua/analyzer/operators/index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ local function index_table(analyzer, self, key)

if not val then return val, err end

if not self.argument_index or contract:IsReferenceArgument() then
if not self.argument_index or contract:IsReferenceType() then
local val = self:GetMutatedValue(key, analyzer:GetScope())

if val then
Expand Down
2 changes: 1 addition & 1 deletion nattlua/analyzer/operators/prefix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ local function Prefix(analyzer, node, r)
end

if op == "ref" then
r:SetReferenceArgument(true)
r:SetReferenceType(true)
return r
end

Expand Down
2 changes: 1 addition & 1 deletion nattlua/analyzer/statements/if.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local type_errors = require("nattlua.types.error_messages")

local function contains_ref_argument(upvalues)
for _, v in ipairs(upvalues) do
if v.upvalue:GetValue():IsReferenceArgument() or v.upvalue:GetValue().from_for_loop then
if v.upvalue:GetValue():IsReferenceType() or v.upvalue:GetValue().from_for_loop then
return true
end
end
Expand Down
8 changes: 4 additions & 4 deletions nattlua/types/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ do
self:SetMetaTable(obj:GetMetaTable())
self:SetAnalyzerEnvironment(obj:GetAnalyzerEnvironment())
self:SetTypeOverride(obj:GetTypeOverride())
self:SetReferenceArgument(obj:IsReferenceArgument())
self:SetReferenceType(obj:IsReferenceType())
self.truthy_union = obj.truthy_union
self.falsy_union = obj.falsy_union
end
Expand Down Expand Up @@ -165,16 +165,16 @@ do
end

do
META:IsSet("ReferenceArgument", false--[[# as boolean]])
META:IsSet("ReferenceType", false--[[# as boolean]])
end

do
META:IsSet("Literal", false--[[# as boolean]])

function META:CopyLiteralness(obj--[[#: TBaseType]])
if obj:IsReferenceArgument() then
if obj:IsReferenceType() then
self:SetLiteral(true)
self:SetReferenceArgument(true)
self:SetReferenceType(true)
else
self:SetLiteral(obj:IsLiteral())
end
Expand Down
8 changes: 4 additions & 4 deletions nattlua/types/function.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ do
end
end

function META:IsRefFunction()
function META:HasReferenceTypes()
for i, v in ipairs(self:GetInputSignature():GetData()) do
if v:IsReferenceArgument() then return true end
if v:IsReferenceType() then return true end
end

for i, v in ipairs(self:GetOutputSignature():GetData()) do
if v:IsReferenceArgument() then return true end
if v:IsReferenceType() then return true end
end

return false
Expand All @@ -201,7 +201,7 @@ function META.New(input--[[#: TTuple]], output--[[#: TTuple]])
Falsy = false,
Truthy = true,
Literal = false,
ReferenceArgument = false,
ReferenceType = false,
Called = false,
ExplicitInputSignature = false,
ExplicitOutputSignature = false,
Expand Down
10 changes: 5 additions & 5 deletions nattlua/types/number.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ end
function META:CopyLiteralness(num--[[#: TNumber]])
if num.Type == "number" and num:GetMax() then
if self:IsSubsetOf(num) then
if num:IsReferenceArgument() then
if num:IsReferenceType() then
self:SetLiteral(true)
self:SetReferenceArgument(true)
self:SetReferenceType(true)
end

self:SetData(num:GetData())
self:SetMax(num:GetMax())
end
else
if num:IsReferenceArgument() then
if num:IsReferenceType() then
self:SetLiteral(true)
self:SetReferenceArgument(true)
self:SetReferenceType(true)
else
self:SetLiteral(num:IsLiteral())
end
Expand Down Expand Up @@ -546,7 +546,7 @@ function META.New()
Falsy = false,
Truthy = true,
Literal = false,
ReferenceArgument = false,
ReferenceType = false,
},
META
)
Expand Down
4 changes: 2 additions & 2 deletions nattlua/types/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function META.New(data--[[#: string | nil]])
Falsy = false,
Truthy = true,
Literal = false,
ReferenceArgument = false,
ReferenceType = false,
},
META
)
Expand Down Expand Up @@ -186,7 +186,7 @@ return {
Falsy = false,
Truthy = true,
Literal = false,
ReferenceArgument = false,
ReferenceType = false,
},
META
):SetLiteral(true)
Expand Down
2 changes: 1 addition & 1 deletion nattlua/types/symbol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function META.New(data--[[#: any]])
Falsy = false,
Truthy = false,
Literal = false,
ReferenceArgument = false,
ReferenceType = false,
},
META
)
Expand Down
2 changes: 1 addition & 1 deletion nattlua/types/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ function META.New()
Falsy = false,
Truthy = false,
Literal = false,
ReferenceArgument = false,
ReferenceType = false,
suppress = false,
},
META
Expand Down
2 changes: 1 addition & 1 deletion nattlua/types/tuple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ function META.New(data--[[#: nil | List<|TBaseType|>]])
Falsy = false,
Truthy = false,
Literal = false,
ReferenceArgument = false,
ReferenceType = false,
Unpackable = false,
suppress = false,
},
Expand Down
2 changes: 1 addition & 1 deletion nattlua/types/union.lua
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ function META.New(data--[[#: nil | List<|TBaseType|>]])
Falsy = false,
Truthy = false,
Literal = false,
ReferenceArgument = false,
ReferenceType = false,
suppress = false,
},
META
Expand Down
2 changes: 1 addition & 1 deletion test/nattlua/analyzer/metatable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ analyze[[
local constructor = analyzer:Assert(meta:Get(types.ConstString("constructor")))
local self_arg = types.Any()
self_arg:SetReferenceArgument(true)
self_arg:SetReferenceType(true)
constructor:GetInputSignature():Set(1, self_arg)
tbl:SetMetaTable(meta)
Expand Down

0 comments on commit 2420c29

Please sign in to comment.