[cfe-dev] Reflection/metaparsing implem

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 11 09:49:52 PST 2019


On Mon, Nov 11, 2019 at 8:43 AM David Rector via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Please enjoy this clang 7.0.0 fork:
>
> https://github.com/drec357/clang-meta
>
> This reflection implementation reflects just about the entire clang AST,
> and lets you use clang syntax/names in *regular, non-clang* C++ code:
>
> namespace ns { class MyClass { float f; }; }
> constexpr {
> ce_assert(reflexpr(ns)->isInline());
> ce_assert(!reflexpr(ns)->isAnonymousNamespace())
> FOR ( (Decl *D) : reflexpr(ns::MyClass)->decls()) {
> if (auto_ FD = dyn_cast<FieldDecl>(D))
> FD->dump();
> }
> //As for meta-parsing:
> __queue_metaparse("static const int i = ");
> constexpr int ival = __metaparse_expr(__concatenate("3", 2+2), int);
> __queue_metaparse(jval);
> __queue_metaparse(";")
>
> } // queued metatparses performed here…
>
> static_assert(i = 34);
>
>
> Plus you can define clang-style diagnostics and FixItHints, using
> reflected SourceLocations, in your regular, non-clang code.
>
> 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,
>

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.


> 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.
>
> David Rector
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191111/c1274ea8/attachment.html>


More information about the cfe-dev mailing list