Skip to content
Draft
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
23 changes: 19 additions & 4 deletions _xtool/llcppsymg/internal/symg/symg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,21 @@ func TestGen(t *testing.T) {
name: "inireader",
path: "./testdata/inireader",
dylibSymbols: []string{
"ZN9INIReaderC1EPKc",
"ZN9INIReaderC1EPKcl",
"ZN9INIReaderD1Ev",
"ZN9INIReaderC1EPKcm",
"ZN9INIReaderC1ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
"ZN9INIReaderC2EPKcm",
"ZN9INIReaderC2ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
"ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b",
"ZNK9INIReader10GetIntegerERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_l",
"ZNK9INIReader10HasSectionERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
"ZNK9INIReader10ParseErrorEv",
"ZNK9INIReader3GetEPKcS1_S1_",
"ZNK9INIReader11GetUnsignedERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_m",
"ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x",
"ZNK9INIReader13GetUnsigned64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_y",
"ZNK9INIReader3GetERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
"ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d",
"ZNK9INIReader8HasValueERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_",
"ZNK9INIReader9GetStringERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
},
},
{
Expand Down Expand Up @@ -487,12 +497,17 @@ func TestGen(t *testing.T) {
defer os.Remove(tempFile.Name())
clangtool.ComposeIncludes(cfg.Include, tempFile.Name())

symg.SetDebug(symg.DbgFlagAll)
pkgHfileInfo := header.PkgHfileInfo(cfg.Include, strings.Fields(cfg.CFlags), false)
headerSymbolMap, err := symg.ParseHeaderFile(tempFile.Name(), pkgHfileInfo.CurPkgFiles(), cfg.TrimPrefixes, strings.Fields(cfg.CFlags), cfg.SymMap, cfg.Cplusplus)
if err != nil {
t.Fatal(err)
}

for mangle, info := range headerSymbolMap {
fmt.Println(mangle, info.GoName, info.ProtoName)
}

// trim to nm symbols
var dylibsymbs []*nm.Symbol
for _, symb := range tc.dylibSymbols {
Expand Down
114 changes: 103 additions & 11 deletions _xtool/llcppsymg/internal/symg/testdata/inireader/INIReader.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,106 @@
// Read an INI file into easy-to-access name/value pairs.

// SPDX-License-Identifier: BSD-3-Clause

// Copyright (C) 2009-2020, Ben Hoyt

// inih and INIReader are released under the New BSD license (see LICENSE.txt).
// Go to the project home page for more info:
//
// https://github.com/benhoyt/inih

#ifndef INIREADER_H
#define INIREADER_H

#include <cstdint>
#include <map>
#include <string>

// Visibility symbols, required for Windows DLLs
#ifndef INI_API
#if defined _WIN32 || defined __CYGWIN__
#ifdef INI_SHARED_LIB
#ifdef INI_SHARED_LIB_BUILDING
#define INI_API __declspec(dllexport)
#else
#define INI_API __declspec(dllimport)
#endif
#else
#define INI_API
#endif
#else
#if defined(__GNUC__) && __GNUC__ >= 4
#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();
#else
#define INI_API
#endif
#endif
#endif

// Read an INI file into easy-to-access name/value pairs. (Note that I've gone
// for simplicity here rather than speed, but it should be pretty decent.)
class INIReader {
public:
// Construct INIReader and parse given filename. See ini.h for more info
// about the parsing.
__attribute__((visibility("default"))) explicit INIReader(const std::string &filename);

// Construct INIReader and parse given buffer. See ini.h for more info
// about the parsing.
INI_API explicit INIReader(const char *buffer, size_t buffer_size);

// Return the result of ini_parse(), i.e., 0 on success, line number of
// first error on parse error, or -1 on file open error.
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);
};
// Get a string value from INI file, returning default_value if not found.
INI_API std::string Get(const std::string &section, const std::string &name,
const std::string &default_value) const;

// Get a string value from INI file, returning default_value if not found,
// empty, or contains only whitespace.
INI_API std::string GetString(const std::string &section, const std::string &name,
const std::string &default_value) const;

// Get an integer (long) value from INI file, returning default_value if
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
INI_API long GetInteger(const std::string &section, const std::string &name, long default_value) const;

// Get a 64-bit integer (int64_t) value from INI file, returning default_value if
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
INI_API int64_t GetInteger64(const std::string &section, const std::string &name, int64_t default_value) const;

// Get an unsigned integer (unsigned long) value from INI file, returning default_value if
// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
INI_API unsigned long GetUnsigned(const std::string &section, const std::string &name,
unsigned long default_value) const;

// Get an unsigned 64-bit integer (uint64_t) value from INI file, returning default_value if
// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
INI_API uint64_t GetUnsigned64(const std::string &section, const std::string &name, uint64_t default_value) const;

// Get a real (floating point double) value from INI file, returning
// default_value if not found or not a valid floating point value
// according to strtod().
INI_API double GetReal(const std::string &section, const std::string &name, double default_value) const;

// Get a boolean value from INI file, returning default_value if not found or if
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
// and valid false values are "false", "no", "off", "0" (not case sensitive).
INI_API bool GetBoolean(const std::string &section, const std::string &name, bool default_value) const;

// Return true if the given section exists (section must contain at least
// one name=value pair).
INI_API bool HasSection(const std::string &section) const;

// Return true if a value exists with the given section and field names.
INI_API bool HasValue(const std::string &section, const std::string &name) const;

private:
int _error;
std::map<std::string, std::string> _values;
static std::string MakeKey(const std::string &section, const std::string &name);
static int ValueHandler(void *user, const char *section, const char *name, const char *value);
};

#endif // INIREADER_H
62 changes: 51 additions & 11 deletions _xtool/llcppsymg/internal/symg/testdata/inireader/expect.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,67 @@
[
{
"mangle": "_ZN9INIReaderC1EPKc",
"c++": "INIReader::INIReader(const char *)",
"mangle": "_ZN9INIReaderC1EPKcm",
"c++": "INIReader::INIReader(const char *, size_t)",
"go": "(*Reader).Init__1"
},
{
"mangle": "_ZN9INIReaderC1ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
"c++": "INIReader::INIReader(const std::string \u0026)",
"go": "(*Reader).Init"
},
{
"mangle": "_ZN9INIReaderC1EPKcl",
"c++": "INIReader::INIReader(const char *, long)",
"go": "(*Reader).Init__1"
"mangle": "_ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b",
"c++": "INIReader::GetBoolean(const std::string \u0026, const std::string \u0026, bool)",
"go": "(*Reader).GetBoolean"
},
{
"mangle": "_ZN9INIReaderD1Ev",
"c++": "INIReader::~INIReader()",
"go": "(*Reader).Dispose"
"mangle": "_ZNK9INIReader10GetIntegerERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_l",
"c++": "INIReader::GetInteger(const std::string \u0026, const std::string \u0026, long)",
"go": "(*Reader).GetInteger"
},
{
"mangle": "_ZNK9INIReader10HasSectionERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
"c++": "INIReader::HasSection(const std::string \u0026)",
"go": "(*Reader).HasSection"
},
{
"mangle": "_ZNK9INIReader10ParseErrorEv",
"c++": "INIReader::ParseError()",
"go": "(*Reader).ModifyedParseError"
},
{
"mangle": "_ZNK9INIReader3GetEPKcS1_S1_",
"c++": "INIReader::Get(const char *, const char *, const char *)",
"mangle": "_ZNK9INIReader11GetUnsignedERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_m",
"c++": "INIReader::GetUnsigned(const std::string \u0026, const std::string \u0026, unsigned long)",
"go": "(*Reader).GetUnsigned"
},
{
"mangle": "_ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x",
"c++": "INIReader::GetInteger64(const std::string \u0026, const std::string \u0026, int64_t)",
"go": "(*Reader).GetInteger64"
},
{
"mangle": "_ZNK9INIReader13GetUnsigned64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_y",
"c++": "INIReader::GetUnsigned64(const std::string \u0026, const std::string \u0026, uint64_t)",
"go": "(*Reader).GetUnsigned64"
},
{
"mangle": "_ZNK9INIReader3GetERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
"c++": "INIReader::Get(const std::string \u0026, const std::string \u0026, const std::string \u0026)",
"go": "(*Reader).Get"
},
{
"mangle": "_ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d",
"c++": "INIReader::GetReal(const std::string \u0026, const std::string \u0026, double)",
"go": "(*Reader).GetReal"
},
{
"mangle": "_ZNK9INIReader8HasValueERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_",
"c++": "INIReader::HasValue(const std::string \u0026, const std::string \u0026)",
"go": "(*Reader).HasValue"
},
{
"mangle": "_ZNK9INIReader9GetStringERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
"c++": "INIReader::GetString(const std::string \u0026, const std::string \u0026, const std::string \u0026)",
"go": "(*Reader).GetString"
}
]
]
5 changes: 2 additions & 3 deletions _xtool/llcppsymg/internal/symg/testdata/inireader/llcppg.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
"trimPrefixes": ["INI"],
"cplusplus": true,
"symMap": {
"_ZN9INIReaderC1EPKc":".Init",
"_ZN9INIReaderC1EPKcl":".Init__1",
"_ZN9INIReaderD1Ev":".Dispose",
"_ZN9INIReaderC1ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE":".Init",
"_ZN9INIReaderC1EPKcm":".Init__1",
"_ZNK9INIReader10ParseErrorEv":".ModifyedParseError"
}
}
Loading