[cfe-dev] Preprocessor Macros Parser

Norman Rink via cfe-dev cfe-dev at lists.llvm.org
Thu May 19 01:18:47 PDT 2016


Hi Timur,

Are you tied to the preprocessor (pp) and pp macros? What is your use case?

I recently did some work on what you might call ³syntax macros² [1]. The
definition of a syntax macro captures an AST subtree. Later, when the
macro is called, the subtree is instantiated (i.e. pasted into the AST at
the place of the macro call). This is orthogonal to preprocessor macros:
since pp macros perform textual replacement, they may be more flexible
than syntax macros. On the other hand, syntax macros let you do type
checking at two levels: the ³standard² type checking or semantic analysis
of the language (i.e. C/C++), and checking of whether pasting a syntax
macro in a certain place in the AST is legal (i.e. type checking on the
AST node type). Since a syntax macro captures a subtree of the AST, you
can also perform tree transformations on the macro.

I implemented syntax macros as a language extension, which required quite
a bit of concentrated work. When I had to stop working on this, my
prototype was (and is) far from being complete, certainly not at the level
of the system described in [1].

I hope this helps more than it confuses.

Best regards,

Norman Rink


[1] 
https://www.cs.rice.edu/~taha/teaching/05S/511/papers/weise93programmable.p
df




>Date: Wed, 18 May 2016 12:50:43 +0300
>From: Timur Iskhakov via cfe-dev <cfe-dev at lists.llvm.org>
>To: cfe-dev at lists.llvm.org
>Subject: [cfe-dev] Preprocessor Macros Parser
>Message-ID:
>	<CAMDUZojd10uj3sqQix70cua=+bJKYk=u5Ey0o2bV67t46tc2uA at mail.gmail.com>
>Content-Type: text/plain; charset="utf-8"
>
>Hi All,
>
>I am attempting to implement a supercompilation method in optimizing the
>preprocessor.
>
>So, I need to parse the preprocessor directives (best case scenario: build
>an AST of the macroses) before compilation.
>Can anyone suggest a better way to do it? If it is quite hard to parse the
>macroses, it is ok to just get get all of them and then without clang
>usage.
>
>(It would be nice but not necessary if it is possible to implement as an
>extension. But I still cannot find a way to do it.)
>
>Thakns!
>
>Timur
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: 
><http://lists.llvm.org/pipermail/cfe-dev/attachments/20160518/382bda5a/att
>achment-0001.html>
>
>------------------------------





More information about the cfe-dev mailing list