Skip to content

Commit 471b06a

Browse files
committed
Filter private defines
1 parent 2db8071 commit 471b06a

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

bindgen/ir/IR.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ void IR::filterDeclarations(const std::string &excludePrefix) {
166166

167167
filterTypeDefs(excludePrefix);
168168

169-
filterFunctions(excludePrefix);
169+
filter(functions, excludePrefix);
170+
171+
filter(literalDefines, excludePrefix);
170172
}
171173

172174
void IR::filterTypeDefs(const std::string &excludePrefix) {
@@ -192,17 +194,6 @@ void IR::replaceTypeInTypeDefs(const std::string &oldType,
192194
}
193195
}
194196

195-
void IR::filterFunctions(const std::string &excludePrefix) {
196-
for (auto it = functions.begin(); it != functions.end();) {
197-
Function &function = *it;
198-
if (startsWith(function.getName(), excludePrefix)) {
199-
it = functions.erase(it);
200-
} else {
201-
it++;
202-
}
203-
}
204-
}
205-
206197
template <typename T>
207198
bool IR::isTypeUsed(const std::vector<T> &declarations,
208199
const std::string &type) {
@@ -253,3 +244,16 @@ void IR::removeDefine(const std::string &name) {
253244
}
254245
}
255246
}
247+
248+
template <typename T>
249+
void IR::filter(std::vector<T> &declarations,
250+
const std::string &excludePrefix) {
251+
for (auto it = declarations.begin(); it != declarations.end();) {
252+
auto &declaration = *it;
253+
if (startsWith(declaration.getName(), excludePrefix)) {
254+
it = declarations.erase(it);
255+
} else {
256+
it++;
257+
}
258+
}
259+
}

bindgen/ir/IR.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ class IR {
8989
void replaceTypeInTypeDefs(const std::string &oldType,
9090
const std::string &newType);
9191

92-
/**
93-
* Remove functions with names that start with excludePrefix.
94-
*/
95-
void filterFunctions(const std::string &excludePrefix);
96-
9792
/**
9893
* @return true if given type is used only in typedefs.
9994
*/
@@ -110,6 +105,9 @@ class IR {
110105

111106
bool existsFunctionWithName(std::string functionName);
112107

108+
template <typename T>
109+
void filter(std::vector<T> &declarations, const std::string &excludePrefix);
110+
113111
std::string libName; // name of the library
114112
std::string linkName; // name of the library to link with
115113
std::string objectName; // name of Scala object

tests/samples/LiteralDefine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
extern int a;
2323
#define MY_A a // unsupported
2424

25+
#define __PRIVATE 1
26+
2527
#define wait_for_it(cond) \
2628
do { \
2729
sleep(1000); \

0 commit comments

Comments
 (0)