-
Notifications
You must be signed in to change notification settings - Fork 7
Filter functions, extern vars, defines and unused types from included headers #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f9f9bf
Ignore functions, defines and variables from included headers
kornilova203 919c4be
Remove unused external types
kornilova203 a0a616b
Remove HeaderManager and locations
kornilova203 331dabe
Remove unused code
kornilova203 bce760d
Add location to Struct, Union and Enum
kornilova203 902fa75
Remove subclasses of Location. Don't remove not printed declarations
kornilova203 5447079
Add tests. Search for type usages recursively
kornilova203 7e45389
Check number of headers before running bindgen
kornilova203 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ DefineFinder::DefineFinder(IR &ir, const clang::CompilerInstance &compiler, | |
void DefineFinder::MacroDefined(const clang::Token ¯oNameTok, | ||
const clang::MacroDirective *md) { | ||
clang::SourceManager &sm = compiler.getSourceManager(); | ||
if (!sm.isInMainFile(md->getLocation())) { | ||
/* include defines only from the original header */ | ||
return; | ||
} | ||
if (sm.isWrittenInMainFile(macroNameTok.getLocation()) && md->isDefined() && | ||
!md->getMacroInfo()->isFunctionLike()) { | ||
/* save defines only from the given header. | ||
|
@@ -100,6 +104,9 @@ void DefineFinder::MacroUndefined(const clang::Token ¯oNameTok, | |
const clang::MacroDefinition &md, | ||
const clang::MacroDirective *undef) { | ||
clang::SourceManager &sm = compiler.getSourceManager(); | ||
if (!sm.isInMainFile(undef->getLocation())) { | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a test for this would be very valuable. |
||
if (sm.isWrittenInMainFile(macroNameTok.getLocation()) && | ||
md.getMacroInfo() && !md.getMacroInfo()->isFunctionLike()) { | ||
std::string macroName = macroNameTok.getIdentifierInfo()->getName(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually passing a location here would allow us to provide a better diagnostic if an opaque type is used in a problematic way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good idea but we should not use
location
field for this.Maybe create an optional field
typeDeclarationLocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started doing it but it required passing
Location
instance to methods ofTypeTranslator
and it does not look good to me, so I decided to leave it for now.I hope that after fixing #106 we will not see the error message often (except the case when one wants to generated bindings for broken header).