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

Completely rethink code generation #25

Open
asutton opened this issue May 9, 2017 · 0 comments
Open

Completely rethink code generation #25

asutton opened this issue May 9, 2017 · 0 comments

Comments

@asutton
Copy link
Owner

asutton commented May 9, 2017

Token-based code injection does not solve metaprogramming problems. Consider a small class that wants to auto-generate accessors for its members:

struct S2 {
  int a, b, c;

  constexpr {
    for... (auto m : $S2.member_variables())
      -> { int declname("get_" m.name())() const { return m.name(); } }
  }
};

This results in an error claiming m is not found, which is not what we should expect.

As we expand the loop, we should expect to replace (by substitution) the m in the injection with each value of loop variable m in the expansion. This doesn't happen because we haven't done semantic analysis on the declaration in the injection statement. An we really don't want to try to make the substitution lexically because that can dramatically change the meaning of a fragment.

In short, we need to parse injected fragments and actually analyze them.

This is essentially the same as #22, except that it applies to any (potentially) bound identifier within the injection. That is, m in the injection statement should be bound, but isn't.

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

1 participant