[cfe-dev] Reflection TS (Nick Meyer via cfe-dev)

David Rector via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 23 15:57:18 PST 2020


You might consult Andrew Sutton et al. work at https://gitlab.com/lock3/clang.

If you seek to do something different from what they’re doing, you’ll want to define two different kinds of AST Expr nodes: the first covers your entry-point reflections , i.e. the result of reflexpr(x) for various kinds of x’s (e.g. CXXReflectExpr - they define it to work with typename, template name, etc. operands); the second are queries on an existing reflection to produce another reflection or a primitive (e.g. CXXReflectionReadQueryExpr).  
I recommend you do keyword searches on their code to trace how they get from the parsing of the reflexpr keyword to the final evaluation in lib/AST/ExprConstant.cpp. 
 
The basic lifetime/processing of an AST Expression node:

ParseXYZ() -> 
Sema::ActOnXYZ(…) ->
[TransformXYZ(…) -> ActOnXYZ(…) while still dependent ->]
ExprEvaluator::EvaluateXYZ(…)

First, though, perhaps consider your goals, as I’m not 100% sure the Reflection TS is the last word on the subject of reflection — though others certainly disagree with me.  Are you simply anxious to get reflection support for use in your own code?  Perhaps instead look into writing your own clang tools to perform ersatz "metaprogramming" tasks (generating new source files, etc.) using "reflected" info from the AST.  It’s not an ideal approach, but until all the debates are resolved surrounding reflection, it’s the most dependable and powerful approach, and there’s already plenty of support.

Best of luck,

Dave

> 
> 
> Message: 2
> Date: Wed, 22 Jan 2020 21:13:35 -0500
> From: Nick Meyer via cfe-dev <cfe-dev at lists.llvm.org>
> To: cfe-dev at lists.llvm.org
> Subject: Re: [cfe-dev] Reflection TS
> Message-ID:
> 	<CA+kWLqvjFbOP0nhu1dv8oJF4UWE_jLEbzMUngGDJQ2Xy8EQB5A at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> It would probably be useful to link the TS in this thread too.  Here is the
> latest version: http://cplusplus.github.io/reflection-ts/draft.pdf
> 
> On Wed, Jan 22, 2020 at 8:55 PM Nick Meyer <nick.j.meyer at gmail.com> wrote:
> 
>> Hi all,
>> 
>> I want to start a thread about implementing the Reflection TS in Clang.
>> 
>> I've been chatting a bit with Matus Chochlik about this, but I also want
>> to get input from others on the best way to structure the code.  Currently,
>> I'm close to having the parsing for type reflection working.  Right now the
>> reflexpr keyword returns a specialized trait.  My plan was to then define
>> all the reflection traits as type traits that dispatch to an intrinsic.
>> For value reflection, I was thinking we could follow a similar pattern
>> except we might have to generate a type (instead of simply specializing a
>> template) to represent the value.
>> 
>> I want to get input from others about this direction to see if it is
>> reasonable or not before I go to far.  This is my first time working on
>> Clang, so not sure how these discussions typically start.  Let me know if I
>> should provide more detail on my comments above.
>> 
>> All best,
>> Nick
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200123/6ce1552d/attachment.html>


More information about the cfe-dev mailing list