Skip to content

Commit 2f9f9bf

Browse files
committed
Ignore functions, defines and variables from included headers
1 parent 87b7d3c commit 2f9f9bf

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

bindgen/defines/DefineFinder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ DefineFinder::DefineFinder(IR &ir, const clang::CompilerInstance &compiler,
1111
void DefineFinder::MacroDefined(const clang::Token &macroNameTok,
1212
const clang::MacroDirective *md) {
1313
clang::SourceManager &sm = compiler.getSourceManager();
14+
if (!sm.isInMainFile(md->getLocation())) {
15+
/* include defines only from the original header */
16+
return;
17+
}
1418
if (sm.isWrittenInMainFile(macroNameTok.getLocation()) && md->isDefined() &&
1519
!md->getMacroInfo()->isFunctionLike()) {
1620
/* save defines only from the given header.
@@ -100,6 +104,9 @@ void DefineFinder::MacroUndefined(const clang::Token &macroNameTok,
100104
const clang::MacroDefinition &md,
101105
const clang::MacroDirective *undef) {
102106
clang::SourceManager &sm = compiler.getSourceManager();
107+
if (!sm.isInMainFile(undef->getLocation())) {
108+
return;
109+
}
103110
if (sm.isWrittenInMainFile(macroNameTok.getLocation()) &&
104111
md.getMacroInfo() && !md.getMacroInfo()->isFunctionLike()) {
105112
std::string macroName = macroNameTok.getIdentifierInfo()->getName();

bindgen/visitor/TreeVisitor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ HeaderManager headerMan;
55
std::set<std::string> locations;
66

77
bool TreeVisitor::VisitFunctionDecl(clang::FunctionDecl *func) {
8+
if (!astContext->getSourceManager().isInMainFile(func->getLocation())) {
9+
/* include functions only from the original header */
10+
return true;
11+
}
812
std::string funcName = func->getNameInfo().getName().getAsString();
913
std::shared_ptr<Type> retType =
1014
typeTranslator.translate(func->getReturnType());
@@ -157,6 +161,10 @@ void TreeVisitor::handleStruct(clang::RecordDecl *record, std::string name) {
157161
}
158162

159163
bool TreeVisitor::VisitVarDecl(clang::VarDecl *varDecl) {
164+
if (!astContext->getSourceManager().isInMainFile(varDecl->getLocation())) {
165+
/* include variables only from the original header */
166+
return true;
167+
}
160168
if (!varDecl->isThisDeclarationADefinition()) {
161169
std::string variableName = varDecl->getName().str();
162170
std::shared_ptr<Type> type =

0 commit comments

Comments
 (0)