<div dir="ltr">Hi,<div><br></div><div><font color="#500050"><span style="font-size:12.8px">In fact, I am confused in very basic things about clang: I have found no way to get the macro definition, make some magic with it and then make some magic on calling macroses.</span></font></div><div><font color="#500050"><span style="font-size:12.8px"><br></span></font></div><div><font color="#500050"><span style="font-size:12.8px">For instance, for code:</span></font></div><div>#define sum(a, b) (a) + (b)</div><div>int main() { sum(1, 2); }</div><div>I want to do something on macro sum initialization and on macro sum call processing (in fact, at this moment I will evaluate the macros by myself and then push "3" instead of "(1) + (2)").</div><div><br></div><div>So, generally speaking, I need to replace the clang preprocessor in the easiest way if possible (I still hope that it is possible to make it as an extension without changing anything in clang code).</div><div><br></div><div>I hone, someone can give me an advice how to implement it!</div><div><br></div><div>Timur </div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><br></div></div></div></div>
<br><div class="gmail_quote">On Thu, May 19, 2016 at 11:18 AM, Norman Rink via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Timur,<br>
<br>
Are you tied to the preprocessor (pp) and pp macros? What is your use case?<br>
<br>
I recently did some work on what you might call ³syntax macros² [1]. The<br>
definition of a syntax macro captures an AST subtree. Later, when the<br>
macro is called, the subtree is instantiated (i.e. pasted into the AST at<br>
the place of the macro call). This is orthogonal to preprocessor macros:<br>
since pp macros perform textual replacement, they may be more flexible<br>
than syntax macros. On the other hand, syntax macros let you do type<br>
checking at two levels: the ³standard² type checking or semantic analysis<br>
of the language (i.e. C/C++), and checking of whether pasting a syntax<br>
macro in a certain place in the AST is legal (i.e. type checking on the<br>
AST node type). Since a syntax macro captures a subtree of the AST, you<br>
can also perform tree transformations on the macro.<br>
<br>
I implemented syntax macros as a language extension, which required quite<br>
a bit of concentrated work. When I had to stop working on this, my<br>
prototype was (and is) far from being complete, certainly not at the level<br>
of the system described in [1].<br>
<br>
I hope this helps more than it confuses.<br>
<br>
Best regards,<br>
<br>
Norman Rink<br>
<br>
<br>
[1]<br>
<a href="https://www.cs.rice.edu/~taha/teaching/05S/511/papers/weise93programmable.p
df" rel="noreferrer" target="_blank">https://www.cs.rice.edu/~taha/teaching/05S/511/papers/weise93programmable.p<br>
df</a><br>
<br>
<br>
<br>
<br>
>Date: Wed, 18 May 2016 12:50:43 +0300<br>
>From: Timur Iskhakov via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
>To: <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
>Subject: [cfe-dev] Preprocessor Macros Parser<br>
>Message-ID:<br>
> <CAMDUZojd10uj3sqQix70cua=+bJKYk=<a href="mailto:u5Ey0o2bV67t46tc2uA@mail.gmail.com">u5Ey0o2bV67t46tc2uA@mail.gmail.com</a>><br>
>Content-Type: text/plain; charset="utf-8"<br>
<div><div class="h5">><br>
>Hi All,<br>
><br>
>I am attempting to implement a supercompilation method in optimizing the<br>
>preprocessor.<br>
><br>
>So, I need to parse the preprocessor directives (best case scenario: build<br>
>an AST of the macroses) before compilation.<br>
>Can anyone suggest a better way to do it? If it is quite hard to parse the<br>
>macroses, it is ok to just get get all of them and then without clang<br>
>usage.<br>
><br>
>(It would be nice but not necessary if it is possible to implement as an<br>
>extension. But I still cannot find a way to do it.)<br>
><br>
>Thakns!<br>
><br>
>Timur<br>
</div></div>>-------------- next part --------------<br>
>An HTML attachment was scrubbed...<br>
>URL:<br>
><<a href="http://lists.llvm.org/pipermail/cfe-dev/attachments/20160518/382bda5a/att" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/cfe-dev/attachments/20160518/382bda5a/att</a><br>
>achment-0001.html><br>
><br>
>------------------------------<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>