Skip to content
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

Regex on symbol names doesn't seem to quite work #233

Open
ThosRTanner opened this issue Nov 7, 2015 · 6 comments
Open

Regex on symbol names doesn't seem to quite work #233

ThosRTanner opened this issue Nov 7, 2015 · 6 comments

Comments

@ThosRTanner
Copy link
Contributor

Given this:

QDir

#include "qdir.h"

qdir.h

class QDir { public: class Filters { }; };

test.cc

#include <QDir>

void test() { QDir::Filters f; }

And this mapping file:

[
    { symbol: [ "QDir", "private", "<QDir>", "public" ]},
    { symbol: [ "@QDir::.*", "private", "<QDir>", "public" ]},
]

I get told I should add #include "qdir.h" for QDir::Filters. I've tried pretty much everything, and the only way I can get it to behave is to specify the full name rather than using a regex in the second mapping entry. (I was hoping to have one entry, @qdir(::.*)?

@kimgr
Copy link
Contributor

kimgr commented Nov 7, 2015

Regexes aren't supposed to work for symbols. I guess it could be made to work, but that would mean you'd have to keep a map from regex -> target symbol, and evaluate every symbol against every key in that map, which seems pretty costly.

There's some specialized handling of regexes for include mappings, but I don't know the details there. It looks like they're expanded to all matching headers before IWYU analysis begins.

@ThosRTanner
Copy link
Contributor Author

the documentation says:

Like include, symbol directives support the @-prefixed regex syntax in the first entry. 

(from https://code.google.com/p/include-what-you-use/wiki/IWYUMappings)

And it'd be nice if it did work, because following header files for QT is a nightmare (QList::toSet ends you up in qset.h, which may be sensible, but it's not what the documentation says!) So you end up with an awful lot of symbol mappings anyway.

@ThosRTanner
Copy link
Contributor Author

Thinking about that it strikes me as likely that subclasses of classes would be in the same header. That is to say that for any class Class, class Class::SubClass will actually be defined in the same header. It more or less has to be. So you wouldn't really need a regexp.

@kevinoid
Copy link

kevinoid commented Jun 9, 2017

I just encountered this issue as well. Regex symbol matching would be nice, but unless that is coming soon it would be very helpful to fix the incorrect documentation in docs/IWYUMappings.md.

@purpleKarrot
Copy link

I agree with @ThosRTanner that proper handling of nested types makes all our use cases of regex symbol mappings disappear. I created #451. I think this issue can be closed.

Note that it is possible to forward declare nested types:

struct Foo
{
  struct Bar;
};

And then defining the type in a different header:

struct Foo::Bar
{
};

So, the symbols Foo::Bar and Foo are not guaranteed to be defined in the same header.

But: if there is a mapping for Foo and no mapping for Foo::Bar, it is safe to assume that Foo::Bar should follow the mapping for Foo.

@kimgr
Copy link
Contributor

kimgr commented Jun 29, 2017

@ThosRTanner, if you agree, can you close this issue? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants