<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 11, 2019 at 8:43 AM 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div>Please enjoy this clang 7.0.0 fork:</div><div><br></div><a href="https://github.com/drec357/clang-meta" target="_blank">https://github.com/drec357/clang-meta</a><div><br></div><div>This reflection implementation reflects just about the entire clang AST, and lets you use clang syntax/names in *regular, non-clang* C++ code:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>namespace ns { class MyClass { float f; }; }</div><div>constexpr {</div><div><span style="white-space:pre-wrap"> </span>ce_assert(reflexpr(ns)->isInline());</div><div><span style="white-space:pre-wrap"> </span>ce_assert(!reflexpr(ns)->isAnonymousNamespace())</div><div><span style="white-space:pre-wrap"> </span>FOR ( (Decl *D) : reflexpr(ns::MyClass)->decls()) {</div><div><span style="white-space:pre-wrap"> </span>if (auto_ FD = dyn_cast<FieldDecl>(D))</div><div><span style="white-space:pre-wrap"> </span>FD->dump();</div><div><span style="white-space:pre-wrap"> </span>}</div><div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>//As for meta-parsing:</div><div><span style="white-space:pre-wrap"> </span>__queue_metaparse("static const int i = ");</div><div><span style="white-space:pre-wrap"> </span>constexpr int ival = __metaparse_expr(__concatenate("3", 2+2), int);</div><div><span style="white-space:pre-wrap"> </span>__queue_metaparse(jval);</div><div><span style="white-space:pre-wrap"> </span>__queue_metaparse(";")</div><div><br></div><div>} // queued metatparses performed here…</div><div><br></div><div>static_assert(i = 34);</div></blockquote><div><br></div><div>Plus you can define clang-style diagnostics and FixItHints, using reflected SourceLocations, in your regular, non-clang code.</div><div><br></div><div>Please adapt to any uses you see fit! I would love to see this way in the C++ standards, much more general and low-maintenance than the proposals I’ve seen, </div></div></blockquote><div><br>One quick caveat: If it's general and lower maintenance by exposing Clang's AST directly, that is probably a significant deterrent to this being standardized - Clang's AST changes and it's not the same as other compilers ASTs, so generalizing this across compilers and across time might be quite difficult.<br> </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;"><div>but I sense that will be an uphill battle. Please let me know if you would support this way of doing reflection/metaprogramming, or have suggestions on how to proceed.</div><div><br></div><div>David Rector</div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>