<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 10 Jul 2020, 08:39 David Rector via cfe-dev, <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">You definitely want to represent the original declaration in the AST — never just expand it right away into the underlying semantics.</div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">+1</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div>Others know the AST much better than I do, but: I think you could *also* implement the easy way as well, by adding implicit UsingShadowDecls for each enumerator, each linked to the original UsingEnumDecl.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">This is the approach that I would attempt -- model UsingEnumDecl similarly to UsingDecl.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div> Or better yet, somehow add a single shadow decl that is a transparent lookup context, somehow.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">It's tempting to try to build a representation whose size is independent of the number of enumerators, but this is likely to present problems -- name lookup for an injected enumerator name would find a declaration with a different name, which is going to confuse some parts of clang. Also, all name lookups would presumably need to additionally look for the shadow decl, much as we do for "using namespace". We need to pay an O(n) cost to check that the enumerators don't conflict with other declarations in their scope anyway, so building an O(n) representation seems likely to be OK.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div>I believe UsingShadowDecls are introduced by UsingDecls to handle whenever multiple individual declarations need to be introduced into a context — someone correct me if I’m wrong.  There is definitely precedent for introducing implicit declarations simply for lookup purposes, e.g. VarTemplateDecl instantiations get added to a DeclContext.  It’s annoying to deal with but since it’s already being done, I see no reason not to introducing UsingShadowDecls to handle the implementation in this way.</div><div><br></div><div>- Dave</div><div><div><br><blockquote type="cite"><div>On Jul 10, 2020, at 7:01 AM, Shachaf Co via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr">Hi all,<div><br></div><div>I'm new to Clang, and decided that I want to implement a small C++20 feature - the "using enum" proposal (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r5.html" target="_blank" rel="noreferrer">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r5.html</a>).</div><div><br></div><div>The first part of the proposal, supporting syntax such as "using Color::RED" is easy enough to implement, and basically requires removing an if-statement and adding some diagnostics.</div><div><br></div><div>However, I struggle finding the correct way to implement the "using enum Color" syntax. There are two approaches that I see when trying to implement it.</div><div><br></div><div>The first approach is "expanding" it to a list of using-declarations (i.e "using enum Color" would be equivalent to "using Color::RED, Color::BLUE, ...). This approach is easier to implement, however the resulting AST won't be as accurate.</div><div><br></div><div>The second approach is creating a new AST node representing a "UsingEnumDecl". This will generate a more "correct" AST, however it is much more complicated to implement - it is more similar to using directives ("using namespace ns"), whose implementation is complicated and heavily affects the name lookup.</div><div><br></div><div>What do you think is the correct way to implement the feature? Is reducing the complexity worth degrading the accuracy of the AST?</div><div><br></div><div>Thanks,</div><div>Shachaf</div></div>
_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank" rel="noreferrer">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br></div></blockquote></div><br></div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div></div>