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

Improve support for generic constraints #3

Open
yeputons opened this issue Jun 2, 2020 · 5 comments
Open

Improve support for generic constraints #3

yeputons opened this issue Jun 2, 2020 · 5 comments

Comments

@yeputons
Copy link
Collaborator

yeputons commented Jun 2, 2020

E.g. HTMLCollectionOf<> returned by getElementsByClassName

@stheophil
Copy link
Contributor

stheophil commented Oct 5, 2021

  • Generate templates for generic classes
  • Generate non-type templates for generics with enum/double non-type parameters
  • Generate basic type constraints in C++ such as std::is_base_of<Node, T> for interface A<T extends Node>

@stheophil
Copy link
Contributor

  • Update tree of parsed classes, functions, variables so they store back pointers to their parents.
  • Lookup TypeParameters in type parameter collections of each parent to resolve type parameter to their type. See MangleVariableTypeParameterAsType

@stheophil
Copy link
Contributor

For IndexedAccessTypes, something like this with boost::Hana could be nice:


#include <functional>
#include <boost/hana/assert.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/type.hpp>
#include <boost/hana/string.hpp>
#include <boost/hana/hash.hpp>
#include <boost/hana/at_key.hpp>

#include <string>
using namespace std::literals;
namespace hana = boost::hana;

struct SChangeEvent {};
struct SMouseEvent {};

static constexpr auto m = hana::make_map(
    hana::make_pair(BOOST_HANA_STRING("change"), hana::type_c<SChangeEvent>),
    hana::make_pair(BOOST_HANA_STRING("mousemove"), hana::type_c<SMouseEvent>)
);
template<typename T> 
void addEventListener(T t, std::function<void(typename decltype(+m[t])::type)>);

int main() {
    std::function<void (SChangeEvent)> fn;
    addEventListener(BOOST_HANA_STRING("change"), fn);
}

@stheophil
Copy link
Contributor

Slightly better error message with

template<typename T, typename Arg, 
    std::enable_if_t<
        // hana::contains(hana::keys(m), T{}) &&
        std::is_same_v<Arg, typename decltype(hana::find(m, T{}))::type>
    >* = nullptr 
> 
void addEventListener(T t, std::function<void(Arg)>);

@stheophil
Copy link
Contributor

IndexesAccessTypes supported in commit 9eb2f9b

@stheophil stheophil changed the title Generic classes are unsupported Improve support for generic constraints Apr 4, 2022
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

2 participants