Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions script/plugins/ffi/c-parser/cpp.lua
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@

local cpp = {}

local typed = require("plugins.ffi.c-parser.typed")
local c99 = require("plugins.ffi.c-parser.c99")

local SEP = package.config:sub(1,1)

local shl, shr
if jit then
shl = function(a, b)
return bit.lshift(a, b)
end
shr = function(a, b)
return bit.rshift(a, b)
end
else
shl, shr = load([[
local function shl(a, b)
return a << b
end
local function shr(a, b)
return a >> b
end
return shl, shr
]])()
local function shl(a, b)
return a << b
end
local function shr(a, b)
return a >> b
end

local function debug() end
local function debug(...) end
--[[
local inspect = require("inspect")
local function debug(...)
Expand Down Expand Up @@ -623,6 +609,7 @@ cpp.parse_file = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(filenam
ctx = {
incdirs = cpp_include_paths(),
defines = gcc_default_defines(),
---@type any[]
ifmode = { true },
output = {},
current_dir = {}
Expand Down Expand Up @@ -785,7 +772,7 @@ cpp.parse_context = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(cont
for cur, lineitem in ipairs(linelist) do
local line = lineitem.line
local tk = lineitem.tk
debug(filename, cur, ifmode[#ifmode], #ifmode, line)
debug(cur, ifmode[#ifmode], #ifmode, line)

if #ifmode == 1 and (tk.directive == "elif" or tk.directive == "else" or tk.directive == "endif") then
return nil, "unexpected directive " .. tk.directive
Expand All @@ -812,6 +799,7 @@ cpp.parse_context = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(cont
elseif tk.directive == "if" then
table.insert(ifmode, run_expression(ctx, tk.exp))
elseif tk.directive == "elif" then
---@diagnostic disable-next-line: assign-type-mismatch
ifmode[#ifmode] = "skip"
elseif tk.directive == "else" then
ifmode[#ifmode] = not ifmode[#ifmode]
Expand Down
1 change: 1 addition & 0 deletions script/plugins/ffi/c-parser/ctypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ local convert_value = typed("TypeList, table -> CType?, string?", function (lst,
src.ids = util.expandSingle(src.ids)
-- FIXME multiple ids, e.g.: int *x, y, *z;
local ok
---@diagnostic disable-next-line: cast-local-type
ok, name, ret_pointer, idxs = get_name(src.id or src.ids)
if not ok then
return nil, name
Expand Down
3 changes: 3 additions & 0 deletions script/plugins/ffi/searchCode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ local vm = require 'vm'
local function getLiterals(arg)
local literals = vm.getLiterals(arg)
local res = {}
if not literals then
return res
end
for k, v in pairs(literals) do
if type(k) == 'string' then
res[#res+1] = k
Expand Down