Skip to content

Commit 83dbfcd

Browse files
committed
llcppsymg:c++ case with inih/58
1 parent f4cab00 commit 83dbfcd

File tree

3 files changed

+160
-25
lines changed

3 files changed

+160
-25
lines changed
Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,106 @@
1+
// Read an INI file into easy-to-access name/value pairs.
2+
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
// Copyright (C) 2009-2020, Ben Hoyt
6+
7+
// inih and INIReader are released under the New BSD license (see LICENSE.txt).
8+
// Go to the project home page for more info:
9+
//
10+
// https://github.com/benhoyt/inih
11+
12+
#ifndef INIREADER_H
13+
#define INIREADER_H
14+
15+
#include <cstdint>
16+
#include <map>
17+
#include <string>
18+
19+
// Visibility symbols, required for Windows DLLs
20+
#ifndef INI_API
21+
#if defined _WIN32 || defined __CYGWIN__
22+
#ifdef INI_SHARED_LIB
23+
#ifdef INI_SHARED_LIB_BUILDING
24+
#define INI_API __declspec(dllexport)
25+
#else
26+
#define INI_API __declspec(dllimport)
27+
#endif
28+
#else
29+
#define INI_API
30+
#endif
31+
#else
32+
#if defined(__GNUC__) && __GNUC__ >= 4
133
#define INI_API __attribute__((visibility("default")))
2-
class INIReader
3-
{
4-
public:
5-
__attribute__((visibility("default"))) explicit INIReader(const char *filename);
6-
INI_API explicit INIReader(const char *buffer, long buffer_size);
7-
~INIReader();
34+
#else
35+
#define INI_API
36+
#endif
37+
#endif
38+
#endif
39+
40+
// Read an INI file into easy-to-access name/value pairs. (Note that I've gone
41+
// for simplicity here rather than speed, but it should be pretty decent.)
42+
class INIReader {
43+
public:
44+
// Construct INIReader and parse given filename. See ini.h for more info
45+
// about the parsing.
46+
__attribute__((visibility("default"))) explicit INIReader(const std::string &filename);
47+
48+
// Construct INIReader and parse given buffer. See ini.h for more info
49+
// about the parsing.
50+
INI_API explicit INIReader(const char *buffer, size_t buffer_size);
51+
52+
// Return the result of ini_parse(), i.e., 0 on success, line number of
53+
// first error on parse error, or -1 on file open error.
854
INI_API int ParseError() const;
9-
INI_API const char *Get(const char *section, const char *name,
10-
const char *default_value) const;
1155

12-
private:
13-
static const char *MakeKey(const char *section, const char *name);
14-
};
56+
// Get a string value from INI file, returning default_value if not found.
57+
INI_API std::string Get(const std::string &section, const std::string &name,
58+
const std::string &default_value) const;
59+
60+
// Get a string value from INI file, returning default_value if not found,
61+
// empty, or contains only whitespace.
62+
INI_API std::string GetString(const std::string &section, const std::string &name,
63+
const std::string &default_value) const;
64+
65+
// Get an integer (long) value from INI file, returning default_value if
66+
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
67+
INI_API long GetInteger(const std::string &section, const std::string &name, long default_value) const;
68+
69+
// Get a 64-bit integer (int64_t) value from INI file, returning default_value if
70+
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
71+
INI_API int64_t GetInteger64(const std::string &section, const std::string &name, int64_t default_value) const;
72+
73+
// Get an unsigned integer (unsigned long) value from INI file, returning default_value if
74+
// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
75+
INI_API unsigned long GetUnsigned(const std::string &section, const std::string &name,
76+
unsigned long default_value) const;
77+
78+
// Get an unsigned 64-bit integer (uint64_t) value from INI file, returning default_value if
79+
// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
80+
INI_API uint64_t GetUnsigned64(const std::string &section, const std::string &name, uint64_t default_value) const;
81+
82+
// Get a real (floating point double) value from INI file, returning
83+
// default_value if not found or not a valid floating point value
84+
// according to strtod().
85+
INI_API double GetReal(const std::string &section, const std::string &name, double default_value) const;
86+
87+
// Get a boolean value from INI file, returning default_value if not found or if
88+
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
89+
// and valid false values are "false", "no", "off", "0" (not case sensitive).
90+
INI_API bool GetBoolean(const std::string &section, const std::string &name, bool default_value) const;
91+
92+
// Return true if the given section exists (section must contain at least
93+
// one name=value pair).
94+
INI_API bool HasSection(const std::string &section) const;
95+
96+
// Return true if a value exists with the given section and field names.
97+
INI_API bool HasValue(const std::string &section, const std::string &name) const;
98+
99+
private:
100+
int _error;
101+
std::map<std::string, std::string> _values;
102+
static std::string MakeKey(const std::string &section, const std::string &name);
103+
static int ValueHandler(void *user, const char *section, const char *name, const char *value);
104+
};
105+
106+
#endif // INIREADER_H

_xtool/llcppsymg/_cmptest/symg_test/llgo.expect

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,57 @@ Symbol Map GoName: X__mpzSetUiSafe, ProtoName In HeaderFile: __mpz_set_ui_safe(m
133133
}]
134134
=== Test Case: inireader ===
135135
[{
136-
"mangle": "_ZN9INIReaderC1EPKc",
137-
"c++": "INIReader::INIReader(const char *)",
136+
"mangle": "_ZN9INIReaderC1EPKcm",
137+
"c++": "INIReader::INIReader(const char *, size_t)",
138+
"go": "(*Reader).Init__1"
139+
}, {
140+
"mangle": "_ZN9INIReaderC1ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
141+
"c++": "INIReader::INIReader(const std::string &)",
138142
"go": "(*Reader).Init"
139143
}, {
140-
"mangle": "_ZN9INIReaderC1EPKcl",
141-
"c++": "INIReader::INIReader(const char *, long)",
142-
"go": "(*Reader).Init__1"
144+
"mangle": "_ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b",
145+
"c++": "INIReader::GetBoolean(const std::string &, const std::string &, bool)",
146+
"go": "(*Reader).GetBoolean"
143147
}, {
144-
"mangle": "_ZN9INIReaderD1Ev",
145-
"c++": "INIReader::~INIReader()",
146-
"go": "(*Reader).Dispose"
148+
"mangle": "_ZNK9INIReader10GetIntegerERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_l",
149+
"c++": "INIReader::GetInteger(const std::string &, const std::string &, long)",
150+
"go": "(*Reader).GetInteger"
151+
}, {
152+
"mangle": "_ZNK9INIReader10HasSectionERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
153+
"c++": "INIReader::HasSection(const std::string &)",
154+
"go": "(*Reader).HasSection"
147155
}, {
148156
"mangle": "_ZNK9INIReader10ParseErrorEv",
149157
"c++": "INIReader::ParseError()",
150158
"go": "(*Reader).ModifyedParseError"
151159
}, {
152-
"mangle": "_ZNK9INIReader3GetEPKcS1_S1_",
153-
"c++": "INIReader::Get(const char *, const char *, const char *)",
160+
"mangle": "_ZNK9INIReader11GetUnsignedERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_m",
161+
"c++": "INIReader::GetUnsigned(const std::string &, const std::string &, unsigned long)",
162+
"go": "(*Reader).GetUnsigned"
163+
}, {
164+
"mangle": "_ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x",
165+
"c++": "INIReader::GetInteger64(const std::string &, const std::string &, int64_t)",
166+
"go": "(*Reader).GetInteger64"
167+
}, {
168+
"mangle": "_ZNK9INIReader13GetUnsigned64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_y",
169+
"c++": "INIReader::GetUnsigned64(const std::string &, const std::string &, uint64_t)",
170+
"go": "(*Reader).GetUnsigned64"
171+
}, {
172+
"mangle": "_ZNK9INIReader3GetERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
173+
"c++": "INIReader::Get(const std::string &, const std::string &, const std::string &)",
154174
"go": "(*Reader).Get"
175+
}, {
176+
"mangle": "_ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d",
177+
"c++": "INIReader::GetReal(const std::string &, const std::string &, double)",
178+
"go": "(*Reader).GetReal"
179+
}, {
180+
"mangle": "_ZNK9INIReader8HasValueERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_",
181+
"c++": "INIReader::HasValue(const std::string &, const std::string &)",
182+
"go": "(*Reader).HasValue"
183+
}, {
184+
"mangle": "_ZNK9INIReader9GetStringERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
185+
"c++": "INIReader::GetString(const std::string &, const std::string &, const std::string &)",
186+
"go": "(*Reader).GetString"
155187
}]
156188
=== Test Case: lua ===
157189
[{

_xtool/llcppsymg/_cmptest/symg_test/symg.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,25 @@ func TestGen() {
312312
},
313313
},
314314
{
315+
// inih/58
315316
name: "inireader",
316317
path: "./inireader",
317318
dylibSymbols: []string{
318-
"ZN9INIReaderC1EPKc",
319-
"ZN9INIReaderC1EPKcl",
320-
"ZN9INIReaderD1Ev",
319+
"ZN9INIReaderC1EPKcm",
320+
"ZN9INIReaderC1ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
321+
"ZN9INIReaderC2EPKcm",
322+
"ZN9INIReaderC2ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
323+
"ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b",
324+
"ZNK9INIReader10GetIntegerERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_l",
325+
"ZNK9INIReader10HasSectionERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
321326
"ZNK9INIReader10ParseErrorEv",
322-
"ZNK9INIReader3GetEPKcS1_S1_",
327+
"ZNK9INIReader11GetUnsignedERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_m",
328+
"ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x",
329+
"ZNK9INIReader13GetUnsigned64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_y",
330+
"ZNK9INIReader3GetERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
331+
"ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d",
332+
"ZNK9INIReader8HasValueERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_",
333+
"ZNK9INIReader9GetStringERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
323334
},
324335
},
325336
{

0 commit comments

Comments
 (0)