<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I’m afraid the best thing to do is look at the code - the AST documentation is often not quite clear, and sometimes is entirely absent for important stuff, but on the other hand the code is usually very clear, and you really do learn a lot by looking at precisely how something was implemented.<div class=""><br class=""></div><div class="">You should not need to worry about scopes and lookup, just create UsingShadowDecls for each of the EnumeratorDecls of the enum; other than that, as Richard suggested, just follow exactly how UsingDecl does it.  That is the best way to learn, too.</div><div class=""><div><br class=""></div><div>Note you’ll also need an UnresolvedUsingEnumDecl for e.g. "using enum T::someenum" when T is dependent; in TreeTransfomr::… you may transform that to your UsingEnumDecl when T becomes non-dependent; follow the example of e.g. UnresolvedUsingTypenameDecl I believe it is.</div><div><br class=""></div><div>Good luck,</div><div><br class=""></div><div>Dave</div><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 10, 2020, at 1:33 PM, Shachaf Co <<a href="mailto:shsh999@gmail.com" class="">shsh999@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thank you very much!<div class=""><br class=""></div><div class="">I'll start looking into the UsingShadowDecls. </div><div class="">Are there some resources for learning about it, except for clang's documentation and the code itself?</div><div class="">I find the documentation quite lacking, and there are many internal concepts to understand such as Contexts, Scopes, the whole name lookup process etc.</div><div class=""><br class=""></div><div class="">Shachaf</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 10, 2020 at 7:48 PM Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto" class=""><div class=""><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" target="_blank" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class="">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" class=""><br class=""></div><div dir="auto" class="">+1</div><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class=""><div class="">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" class=""><br class=""></div><div dir="auto" class="">This is the approach that I would attempt -- model UsingEnumDecl similarly to UsingDecl.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class=""><div class=""> Or better yet, somehow add a single shadow decl that is a transparent lookup context, somehow.</div></div></blockquote></div></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">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" class=""><br class=""></div><div dir="auto" class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class=""><div class="">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 class=""><br class=""></div><div class="">- Dave</div><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jul 10, 2020, at 7:01 AM, Shachaf Co via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer" target="_blank" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Hi all,<div class=""><br class=""></div><div class="">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" rel="noreferrer" target="_blank" class="">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r5.html</a>).</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Thanks,</div><div class="">Shachaf</div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer" target="_blank" class="">cfe-dev@lists.llvm.org</a><br class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">
cfe-dev mailing list<br class="">
<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer" target="_blank" class="">cfe-dev@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="">
</blockquote></div></div></div>
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>