Skip to content

Conversation

@HertzDevil
Copy link
Contributor

Extends Bindgen's type parser to handle C++ templates, and adds methods that replace names in a given type with other types. This PR lays the groundwork for at least 2 scenarios:

  • Alias resolution, including in template arguments, e.g. from const QVector<QRgb> & to const QVector<unsigned int> &, provided QRgb is an alias for unsigned int. This can be used for the first issue mentioned in Generic pseudo-instantiation macro for container wrapper types #102; before this PR, the most Bindgen could do was resolving one level of aliases in each template argument.
  • Template type substitution, e.g. QVector<const T *> to QVector<const QVector<int> *>, provided T is instantiated with const QVector<int> & (notice the combination of const-ness and references and pointers). This allows for example the possibility of defining container interfaces in the config files.

The parser and the substitution both fully handle arbitrarily nested templates; the returned Parser::Types respect the template structure at all levels, and should match what would be produced by the Clang parser.

type.pointer.should eq(1)
type.base_name.should eq("int")
type.full_name.should eq("int*")
type.full_name.should eq("int *")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the extra space coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointers/references coming from the Clang parser have the extra space, so Parser::Type.parse now canonicalizes the typename given to it with Cpp::Typename, instead of using the typename verbatim. (This probably fixed a bug somewhere that considered T* and T * to be unequal types.)

@Papierkorb Papierkorb merged commit db8c7e7 into Papierkorb:master Nov 2, 2020
@Papierkorb
Copy link
Owner

Thanks 👍

@HertzDevil HertzDevil deleted the type-substitution branch November 2, 2020 09:28
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

Successfully merging this pull request may close these issues.

2 participants