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

Walking a template specialization #40

Open
rokups opened this issue Feb 20, 2018 · 7 comments
Open

Walking a template specialization #40

rokups opened this issue Feb 20, 2018 · 7 comments
Labels

Comments

@rokups
Copy link
Contributor

rokups commented Feb 20, 2018

Consider std::vector<std::string> used as return type somewhere. Is there a way to somehow use that return type and walk instantiation of class std::vector<std::string> so that methods of std::vector have std::string type inserted where appropriate? Or do i have to resolve these template types manually somehow?

P.S. I hope i am not getting annoying with spamming issue tracker with random questions. If there is a better place to ask these things please let me know.
P.P.S. Thank you for the help with other issues, i greatly appreciate swift response. Just never posted "thanks" messages to save you some spam in the mailbox :)

@foonathan
Copy link
Collaborator

foonathan commented Feb 21, 2018

No, there is no way to do that.

Why do you need it?

I hope i am not getting annoying with spamming issue tracker with random questions. If there is a better place to ask these things please let me know.

No, it's okay.

@rokups
Copy link
Contributor Author

rokups commented Feb 21, 2018

I am using cppast to generate .net bindings for one project. Unfortunately some template containers are a big part of API and i am looking for ways to wrap these containers. I was considering to wrap every instantiation of template class as separate type with separate name so for example std::vector<std::string> on c# side would end up being non-generic StringVector type.

@foonathan
Copy link
Collaborator

And you are looking for an automated way of generating such a StringVector?

@rokups
Copy link
Contributor Author

rokups commented Feb 21, 2018

Yes indeed i am. I already have wrapper generation automated for good chunk of API. these template classes are like a last piece of puzzle.

@foonathan
Copy link
Collaborator

Then I'm afraid there isn't an easy way to do it with the current API.

@Firefly35
Copy link
Contributor

Firefly35 commented Jan 2, 2020

But is there a "non-easy" way to do it ?

trying to walk through a template instantiation, it seems that inner template arguments are unexposed and available as a string (for instance for std::vector<std::shared_ptr<std::string>> unexposed_args contains std::shared_ptr<std::string> but arguments are empty), but not as an entity tree, am I wrong ?

I thought I could be able to retrieve arguments then get back to their types through the arguments array, but the template instantiation parsing code (in cppast::type_parser.cpp) seems to only provide unexposed_arguments ?

@Firefly35
Copy link
Contributor

I made a pull request (#99) that parses every template instantiation argument. There may be limitations, but up till now it worked for instantiations such as std::vector<std::shared_ptr,std::map<std::shared_ptrstd::string,std::vectorstd::string>> and provide the full AST.

The template instantiation full argument parsing is built when the option-DCPPAST_TEMPLATE_FULLARGUMENTSPARSING=ON is used upon invoking cmake.

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

No branches or pull requests

3 participants