[cfe-dev] Reflection/metaparsing implem
David Rector via cfe-dev
cfe-dev at lists.llvm.org
Sun Nov 10 08:32:34 PST 2019
Please enjoy this clang 7.0.0 fork:
https://github.com/drec357/clang-meta <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, 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191110/9d53fb3d/attachment.html>
More information about the cfe-dev
mailing list