llcppsymg:symbol generate test

llcppsymg:symbo test

llcppsymg:exist symb file test

llcppsymg:GenSymbolTabledata

llcppsymg:GenSymbolTableData test

llcppsymg:full symg operation test
This commit is contained in:
luoliwoshang
2024-09-25 14:59:02 +08:00
parent 174fdd40da
commit 944133de6e
13 changed files with 499 additions and 139 deletions

View File

@@ -0,0 +1,51 @@
package main
import (
"fmt"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/dylib"
)
func TestGenDylibPaths() {
fmt.Println("=== Test GenDylibPaths ===")
testCases := []struct {
name string
input string
}{
{
name: "Lua library",
input: "-L/opt/homebrew/lib -llua -lm",
},
{
name: "SQLite library",
input: "-L/opt/homebrew/opt/sqlite/lib -lsqlite3",
},
{
name: "INIReader library",
input: "-L/opt/homebrew/Cellar/inih/58/lib -lINIReader",
},
{
name: "No valid library",
input: "-L/opt/homebrew/lib",
},
}
for _, tc := range testCases {
fmt.Printf("Test case: %s\n", tc.name)
fmt.Printf("Input: %s\n", tc.input)
result, err := dylib.GenDylibPaths(tc.input)
if err != nil {
fmt.Printf("Error: %v\n", err)
} else {
fmt.Printf("Output: %v\n", result)
}
fmt.Println()
}
}
func main() {
TestGenDylibPaths()
}

View File

@@ -0,0 +1,22 @@
#stdout
=== Test GenDylibPaths ===
Test case: Lua library
Input: -L/opt/homebrew/lib -llua -lm
Output: [/opt/homebrew/lib/liblua.dylib /opt/homebrew/lib/libm.dylib]
Test case: SQLite library
Input: -L/opt/homebrew/opt/sqlite/lib -lsqlite3
Output: [/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib]
Test case: INIReader library
Input: -L/opt/homebrew/Cellar/inih/58/lib -lINIReader
Output: [/opt/homebrew/Cellar/inih/58/lib/libINIReader.dylib]
Test case: No valid library
Input: -L/opt/homebrew/lib
Error: failed to parse pkg-config output: -L/opt/homebrew/lib
#stderr
#exit 0

View File

@@ -0,0 +1,71 @@
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/header"
)
func TestGenHeaderFilePath() {
fmt.Println("=== Test GenHeaderFilePath ===")
tempDir := os.TempDir()
tempFile1 := filepath.Join(tempDir, "test1.h")
tempFile2 := filepath.Join(tempDir, "test2.h")
os.Create(tempFile1)
os.Create(tempFile2)
defer os.Remove(tempFile1)
defer os.Remove(tempFile2)
testCases := []struct {
name string
cflags string
files []string
}{
{
name: "Valid files",
cflags: "-I" + tempDir,
files: []string{"test1.h", "test2.h"},
},
{
name: "Mixed existing and non-existing files",
cflags: "-I" + tempDir,
files: []string{"test1.h", "nonexistent.h"},
},
{
name: "No existing files",
cflags: "-I" + tempDir,
files: []string{"nonexistent1.h", "nonexistent2.h"},
},
{
name: "Empty file list",
cflags: "-I/usr/include",
files: []string{},
},
}
for _, tc := range testCases {
fmt.Printf("Test case: %s\n", tc.name)
fmt.Printf("Input files: %v\n", tc.files)
result, err := header.GenHeaderFilePath(tc.cflags, tc.files)
if err != nil {
fmt.Printf("Error: %v\n", err)
}
if result != nil {
relativeResult := make([]string, len(result))
for i, path := range result {
relativeResult[i] = filepath.Base(path)
}
fmt.Printf("Output: %v\n", relativeResult)
}
fmt.Println()
}
}
func main() {
TestGenHeaderFilePath()
}

View File

@@ -0,0 +1,23 @@
#stdout
=== Test GenHeaderFilePath ===
Test case: Valid files
Input files: [test1.h test2.h]
Output: [test1.h test2.h]
Test case: Mixed existing and non-existing files
Input files: [test1.h nonexistent.h]
Error: some files not found or inaccessible: [file not found: nonexistent.h]
Output: [test1.h]
Test case: No existing files
Input files: [nonexistent1.h nonexistent2.h]
Error: some files not found or inaccessible: [file not found: nonexistent1.h file not found: nonexistent2.h]
Test case: Empty file list
Input files: []
Error: no valid header files
#stderr
#exit 0

View File

@@ -0,0 +1,44 @@
#stdout
=== Test NewSymbolProcessor ===
Before: No prefixes After: Prefixes: [lua_ luaL_]
=== Test RemovePrefix ===
Before: lua_closethread After: closethread
Before: luaL_checknumber After: checknumber
=== Test ToGoName ===
Before: lua_closethread After: Closethread
Before: luaL_checknumber After: Checknumber
Before: sqlite3_close_v2 After: CloseV2
Before: sqlite3_callback After: Callback
Before: GetReal After: GetReal
Before: GetBoolean After: GetBoolean
Before: INIReader After: Reader
=== Test GenMethodName ===
Before: Class: INIReader, Name: INIReader After: (*INIReader).Init
Before: Class: INIReader, Name: INIReader After: (*INIReader).Dispose
Before: Class: INIReader, Name: HasValue After: (*INIReader).HasValue
=== Test AddSuffix ===
Before: Class: INIReader, Method: INIReader After: (*Reader).Init
Before: Class: INIReader, Method: INIReader After: (*Reader).Init__1
Before: Class: INIReader, Method: ParseError After: (*Reader).ParseError
Before: Class: INIReader, Method: HasValue After: (*Reader).HasValue
=== Test Case: C++ Class with Methods ===
Parsed Symbols:
Symbol Map GoName: (*Reader).Init__1, ProtoName In HeaderFile: INIReader::INIReader(const char *, int), MangledName: _ZN9INIReaderC1EPKci
Symbol Map GoName: (*Reader).Init, ProtoName In HeaderFile: INIReader::INIReader(const int &), MangledName: _ZN9INIReaderC1ERKi
Symbol Map GoName: (*Reader).Dispose, ProtoName In HeaderFile: INIReader::~INIReader(), MangledName: _ZN9INIReaderD1Ev
Symbol Map GoName: (*Reader).ParseError, ProtoName In HeaderFile: INIReader::ParseError(), MangledName: _ZNK9INIReader10ParseErrorEv
=== Test Case: C Functions ===
Parsed Symbols:
Symbol Map GoName: Compare, ProtoName In HeaderFile: lua_compare(lua_State *, int, int, int), MangledName: lua_compare
Symbol Map GoName: Rawequal, ProtoName In HeaderFile: lua_rawequal(lua_State *, int, int), MangledName: lua_rawequal
#stderr
#exit 0

View File

@@ -0,0 +1,165 @@
package main
import (
"fmt"
"sort"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/parse"
)
func main() {
TestNewSymbolProcessor()
TestRemovePrefix()
TestToGoName()
TestGenMethodName()
TestAddSuffix()
TestParseHeaderFile()
}
func TestNewSymbolProcessor() {
fmt.Println("=== Test NewSymbolProcessor ===")
process := parse.NewSymbolProcessor([]string{"lua_", "luaL_"})
fmt.Printf("Before: No prefixes After: Prefixes: %v\n", process.Prefixes)
fmt.Println()
}
func TestRemovePrefix() {
fmt.Println("=== Test RemovePrefix ===")
process := parse.NewSymbolProcessor([]string{"lua_", "luaL_"})
testCases := []string{"lua_closethread", "luaL_checknumber"}
for _, input := range testCases {
result := process.TrimPrefixes(input)
fmt.Printf("Before: %s After: %s\n", input, result)
}
fmt.Println()
}
func TestToGoName() {
fmt.Println("=== Test ToGoName ===")
process1 := parse.NewSymbolProcessor([]string{"lua_", "luaL_"})
process2 := parse.NewSymbolProcessor([]string{"sqlite3_", "sqlite3_"})
process3 := parse.NewSymbolProcessor([]string{"INI"})
testCases := []struct {
processor *parse.SymbolProcessor
input string
}{
{process1, "lua_closethread"},
{process1, "luaL_checknumber"},
{process2, "sqlite3_close_v2"},
{process2, "sqlite3_callback"},
{process3, "GetReal"},
{process3, "GetBoolean"},
{process3, "INIReader"},
}
for _, tc := range testCases {
result := tc.processor.ToGoName(tc.input)
fmt.Printf("Before: %s After: %s\n", tc.input, result)
}
fmt.Println()
}
func TestGenMethodName() {
fmt.Println("=== Test GenMethodName ===")
process := &parse.SymbolProcessor{}
testCases := []struct {
class string
name string
isDestructor bool
}{
{"INIReader", "INIReader", false},
{"INIReader", "INIReader", true},
{"INIReader", "HasValue", false},
}
for _, tc := range testCases {
input := fmt.Sprintf("Class: %s, Name: %s", tc.class, tc.name)
result := process.GenMethodName(tc.class, tc.name, tc.isDestructor)
fmt.Printf("Before: %s After: %s\n", input, result)
}
fmt.Println()
}
func TestAddSuffix() {
fmt.Println("=== Test AddSuffix ===")
process := parse.NewSymbolProcessor([]string{"INI"})
methods := []string{
"INIReader",
"INIReader",
"ParseError",
"HasValue",
}
for _, method := range methods {
goName := process.ToGoName(method)
className := process.ToGoName("INIReader")
methodName := process.GenMethodName(className, goName, false)
finalName := process.AddSuffix(methodName)
input := fmt.Sprintf("Class: INIReader, Method: %s", method)
fmt.Printf("Before: %s After: %s\n", input, finalName)
}
fmt.Println()
}
func TestParseHeaderFile() {
testCases := []struct {
name string
content string
isCpp bool
prefixes []string
}{
{
name: "C++ Class with Methods",
content: `
class INIReader {
public:
INIReader(const std::string &filename);
INIReader(const char *buffer, size_t buffer_size);
~INIReader();
int ParseError() const;
private:
static std::string MakeKey(const std::string &section, const std::string &name);
};
`,
isCpp: true,
prefixes: []string{"INI"},
},
{
name: "C Functions",
content: `
typedef struct lua_State lua_State;
int(lua_rawequal)(lua_State *L, int idx1, int idx2);
int(lua_compare)(lua_State *L, int idx1, int idx2, int op);
`,
isCpp: false,
prefixes: []string{"lua_"},
},
}
for _, tc := range testCases {
fmt.Printf("=== Test Case: %s ===\n", tc.name)
symbolMap, err := parse.ParseHeaderFile([]string{tc.content}, tc.prefixes, tc.isCpp, true)
if err != nil {
fmt.Printf("Error: %v\n", err)
continue
}
fmt.Println("Parsed Symbols:")
var keys []string
for key := range symbolMap {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
info := symbolMap[key]
fmt.Printf("Symbol Map GoName: %s, ProtoName In HeaderFile: %s, MangledName: %s\n", info.GoName, info.ProtoName, key)
}
fmt.Println()
}
}

View File

@@ -0,0 +1,46 @@
#stdout
=== Test GetCommonSymbols ===
Test Case: Lua symbols
Common Symbols (4):
Mangle: lua_absindex, CPP: lua_absindex(lua_State *, int), Go: Absindex
Mangle: lua_arith, CPP: lua_arith(lua_State *, int), Go: Arith
Mangle: lua_atpanic, CPP: lua_atpanic(lua_State *, lua_CFunction), Go: Atpanic
Mangle: lua_callk, CPP: lua_callk(lua_State *, int, int, lua_KContext, lua_KFunction), Go: Callk
Test Case: INIReader and Std library symbols
Common Symbols (3):
Mangle: ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x, CPP: INIReader::GetInteger64(const std::string &, const std::string &, int64_t), Go: (*Reader).GetInteger64
Mangle: ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d, CPP: INIReader::GetReal(const std::string &, const std::string &, double), Go: (*Reader).GetReal
Mangle: ZNK9INIReader10ParseErrorEv, CPP: INIReader::ParseError(), Go: (*Reader).ParseError
=== Test ReadExistingSymbolTable ===
Symbols read from the file:
Symbol Map GoName: (*Reader).Init__1, ProtoName In HeaderFile: INIReader::INIReader(const char *, size_t), MangledName: _ZN9INIReaderC1EPKcm
Symbol Map GoName: (*Reader).GetBoolean, ProtoName In HeaderFile: INIReader::GetBoolean(const std::string &, const std::string &, bool), MangledName: _ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b
Symbol Map GoName: (*Reader).ParseError, ProtoName In HeaderFile: INIReader::ParseError(), MangledName: _ZNK9INIReader10ParseErrorEv
Havent existed symb file
=== Test GenSymbolTableData ===
[{
"mangle": "lua_absindex",
"c++": "lua_absindex(lua_State *, int)",
"go": "Absindex"
}, {
"mangle": "lua_arith",
"c++": "lua_arith(lua_State *, int)",
"go": "Arith"
}, {
"mangle": "lua_atpanic",
"c++": "lua_atpanic(lua_State *, lua_CFunction)",
"go": "Atpanic"
}, {
"mangle": "lua_callk",
"c++": "lua_callk(lua_State *, int, int, lua_KContext, lua_KFunction)",
"go": "ModifiedCallk"
}]
#stderr
#exit 0

View File

@@ -0,0 +1,152 @@
package main
import (
"fmt"
"os"
"sort"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/parse"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/symbol"
"github.com/goplus/llgo/chore/llcppg/types"
"github.com/goplus/llgo/xtool/nm"
)
func main() {
TestGetCommonSymbols()
TestReadExistingSymbolTable()
TestGenSymbolTableData()
}
func TestGetCommonSymbols() {
fmt.Println("=== Test GetCommonSymbols ===")
testCases := []struct {
name string
dylibSymbols []*nm.Symbol
headerSymbols map[string]*parse.SymbolInfo
}{
{
name: "Lua symbols",
dylibSymbols: []*nm.Symbol{
{Name: "_lua_absindex"},
{Name: "_lua_arith"},
{Name: "_lua_atpanic"},
{Name: "_lua_callk"},
{Name: "_lua_lib_nonexistent"},
},
headerSymbols: map[string]*parse.SymbolInfo{
"lua_absindex": {ProtoName: "lua_absindex(lua_State *, int)", GoName: "Absindex"},
"lua_arith": {ProtoName: "lua_arith(lua_State *, int)", GoName: "Arith"},
"lua_atpanic": {ProtoName: "lua_atpanic(lua_State *, lua_CFunction)", GoName: "Atpanic"},
"lua_callk": {ProtoName: "lua_callk(lua_State *, int, int, lua_KContext, lua_KFunction)", GoName: "Callk"},
"lua_header_nonexistent": {ProtoName: "lua_header_nonexistent()", GoName: "HeaderNonexistent"},
},
},
{
name: "INIReader and Std library symbols",
dylibSymbols: []*nm.Symbol{
{Name: "_ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x"},
{Name: "_ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d"},
{Name: "_ZNK9INIReader10ParseErrorEv"},
},
headerSymbols: map[string]*parse.SymbolInfo{
"ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x": {GoName: "(*Reader).GetInteger64", ProtoName: "INIReader::GetInteger64(const std::string &, const std::string &, int64_t)"},
"ZNK9INIReader13GetUnsigned64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_y": {GoName: "(*Reader).GetUnsigned64", ProtoName: "INIReader::GetUnsigned64(const std::string &, const std::string &, uint64_t)"},
"ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d": {GoName: "(*Reader).GetReal", ProtoName: "INIReader::GetReal(const std::string &, const std::string &, double)"},
"ZNK9INIReader10ParseErrorEv": {GoName: "(*Reader).ParseError", ProtoName: "INIReader::ParseError()"},
"ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b": {GoName: "(*Reader).GetBoolean", ProtoName: "INIReader::GetBoolean(const std::string &, const std::string &, bool)"},
},
},
}
for _, tc := range testCases {
fmt.Printf("\nTest Case: %s\n", tc.name)
commonSymbols := symbol.GetCommonSymbols(tc.dylibSymbols, tc.headerSymbols)
fmt.Printf("Common Symbols (%d):\n", len(commonSymbols))
for _, sym := range commonSymbols {
fmt.Printf("Mangle: %s, CPP: %s, Go: %s\n", sym.Mangle, sym.CPP, sym.Go)
}
}
fmt.Println()
}
func TestReadExistingSymbolTable() {
fmt.Println("=== Test ReadExistingSymbolTable ===")
tmpFile, err := os.CreateTemp("", "llcppg.symb.json")
if err != nil {
fmt.Printf("Failed to create temp file: %v\n", err)
return
}
defer os.Remove(tmpFile.Name())
testData := `[
{
"mangle": "_ZN9INIReaderC1EPKcm",
"c++": "INIReader::INIReader(const char *, size_t)",
"go": "(*Reader).Init__1"
},
{
"mangle": "_ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b",
"c++": "INIReader::GetBoolean(const std::string &, const std::string &, bool)",
"go": "(*Reader).GetBoolean"
},
{
"mangle": "_ZNK9INIReader10ParseErrorEv",
"c++": "INIReader::ParseError()",
"go": "(*Reader).ParseError"
}
]`
if _, err := tmpFile.Write([]byte(testData)); err != nil {
fmt.Printf("Failed to write test data: %v\n", err)
return
}
tmpFile.Close()
symbols, exist := symbol.ReadExistingSymbolTable(tmpFile.Name())
if !exist {
fmt.Printf("ReadExistingSymbolTable failed")
return
}
fmt.Println("Symbols read from the file:")
var keys []string
for key := range symbols {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
info := symbols[key]
fmt.Printf("Symbol Map GoName: %s, ProtoName In HeaderFile: %s, MangledName: %s\n",
info.Go, info.CPP, key)
}
_, exist = symbol.ReadExistingSymbolTable("other.json")
if !exist {
fmt.Println("Havent existed symb file")
}
fmt.Println()
}
func TestGenSymbolTableData() {
fmt.Println("=== Test GenSymbolTableData ===")
commonSymbols := []*types.SymbolInfo{
{Mangle: "lua_absindex", CPP: "lua_absindex(lua_State *, int)", Go: "Absindex"},
{Mangle: "lua_arith", CPP: "lua_arith(lua_State *, int)", Go: "Arith"},
{Mangle: "lua_atpanic", CPP: "lua_atpanic(lua_State *, lua_CFunction)", Go: "Atpanic"},
{Mangle: "lua_callk", CPP: "lua_callk(lua_State *, int, int, lua_KContext, lua_KFunction)", Go: "Callk"},
}
existingSymbols := map[string]types.SymbolInfo{
"lua_absindex": {Mangle: "lua_absindex", CPP: "lua_absindex(lua_State *, int)", Go: "Absindex"},
"lua_arith": {Mangle: "lua_arith", CPP: "lua_arith(lua_State *, int)", Go: "Arith"},
"lua_callk": {Mangle: "lua_callk", CPP: "lua_callk(lua_State *, int, int, lua_KContext, lua_KFunction)", Go: "ModifiedCallk"},
}
data, err := symbol.GenSymbolTableData(commonSymbols, existingSymbols)
if err != nil {
fmt.Printf("Error generating symbol table data: %v\n", err)
return
}
fmt.Println(string(data))
fmt.Println()
}

View File

@@ -0,0 +1,45 @@
#stdout
=== Test Case: inireader ===
[{
"mangle": "_ZN9INIReaderC1EPKc",
"c++": "INIReader::INIReader(const char *)",
"go": "(*Reader).Init"
}, {
"mangle": "_ZN9INIReaderC1EPKcl",
"c++": "INIReader::INIReader(const char *, long)",
"go": "(*Reader).Init__1"
}, {
"mangle": "_ZN9INIReaderD1Ev",
"c++": "INIReader::~INIReader()",
"go": "(*Reader).Dispose"
}, {
"mangle": "_ZNK9INIReader10ParseErrorEv",
"c++": "INIReader::ParseError()",
"go": "(*Reader).ModifyedParseError"
}, {
"mangle": "_ZNK9INIReader3GetEPKcS1_S1_",
"c++": "INIReader::Get(const char *, const char *, const char *)",
"go": "(*Reader).Get"
}]
=== Test Case: lua ===
[{
"mangle": "lua_error",
"c++": "lua_error(lua_State *)",
"go": "Error"
}, {
"mangle": "lua_next",
"c++": "lua_next(lua_State *, int)",
"go": "Next"
}, {
"mangle": "lua_concat",
"c++": "lua_concat(lua_State *, int)",
"go": "Concat"
}, {
"mangle": "lua_stringtonumber",
"c++": "lua_stringtonumber(lua_State *, const char *)",
"go": "Stringtonumber"
}]
#stderr
#exit 0

View File

@@ -0,0 +1,117 @@
package main
import (
"fmt"
"os"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/parse"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/symbol"
"github.com/goplus/llgo/xtool/nm"
)
func main() {
TestParseHeaderFile()
}
func TestParseHeaderFile() {
testCases := []struct {
name string
content string
isCpp bool
prefixes []string
dylibSymbols []*nm.Symbol
symbFileContent string
}{
{
name: "inireader",
content: `
#define INI_API __attribute__((visibility("default")))
class INIReader {
public:
__attribute__((visibility("default"))) explicit INIReader(const char *filename);
INI_API explicit INIReader(const char *buffer, long buffer_size);
~INIReader();
INI_API int ParseError() const;
INI_API const char * Get(const char *section, const char *name,
const char *default_value) const;
private:
static const char * MakeKey(const char *section, const char *name);
};
`,
isCpp: true,
prefixes: []string{"INI"},
dylibSymbols: []*nm.Symbol{
{Name: "__ZN9INIReaderC1EPKc"},
{Name: "__ZN9INIReaderC1EPKcl"},
{Name: "__ZN9INIReaderD1Ev"},
{Name: "__ZNK9INIReader10ParseErrorEv"},
{Name: "__ZNK9INIReader3GetEPKcS1_S1_"},
},
symbFileContent: `
[{
"mangle": "_ZN9INIReaderC1EPKc",
"c++": "INIReader::INIReader(const char *)",
"go": "(*Reader).Init"
}, {
"mangle": "_ZN9INIReaderC1EPKcl",
"c++": "INIReader::INIReader(const char *, long)",
"go": "(*Reader).Init__1"
}, {
"mangle": "_ZN9INIReaderD1Ev",
"c++": "INIReader::~INIReader()",
"go": "(*Reader).Dispose"
}, {
"mangle": "_ZNK9INIReader10ParseErrorEv",
"c++": "INIReader::ParseError()",
"go": "(*Reader).ModifyedParseError"
}]`,
},
{
name: "lua",
content: `
typedef struct lua_State lua_State;
LUA_API int(lua_error)(lua_State *L);
LUA_API int(lua_next)(lua_State *L, int idx);
LUA_API void(lua_concat)(lua_State *L, int n);
LUA_API void(lua_len)(lua_State *L, int idx);
LUA_API long unsigned int(lua_stringtonumber)(lua_State *L, const char *s);
LUA_API void(lua_setallocf)(lua_State *L, lua_Alloc f, void *ud);
LUA_API void(lua_toclose)(lua_State *L, int idx);
LUA_API void(lua_closeslot)(lua_State *L, int idx);
`,
isCpp: false,
prefixes: []string{"lua_"},
dylibSymbols: []*nm.Symbol{
{Name: "_lua_error"},
{Name: "_lua_next"},
{Name: "_lua_concat"},
{Name: "_lua_stringtonumber"},
},
},
}
for _, tc := range testCases {
fmt.Printf("=== Test Case: %s ===\n", tc.name)
headerSymbolMap, err := parse.ParseHeaderFile([]string{tc.content}, tc.prefixes, tc.isCpp, true)
if err != nil {
fmt.Println("Error:", err)
}
tmpFile, err := os.CreateTemp("", "llcppg.symb.json")
if err != nil {
fmt.Printf("Failed to create temp file: %v\n", err)
return
}
tmpFile.Write([]byte(tc.symbFileContent))
symbolData, err := symbol.GenerateAndUpdateSymbolTable(tc.dylibSymbols, headerSymbolMap, tmpFile.Name())
if err != nil {
fmt.Println("Error:", err)
}
fmt.Println(string(symbolData))
os.Remove(tmpFile.Name())
}
}