Thanks for response!<div>No, I don't really need to mutate the AST. </div><div>I just had a wrong impression that AST printer is supposed to emit valid code, since it was doing it nicely in most cases. I can certainly grab everything I need to modify from original code.</div><div><br></div><div>-Roman<br><div><br></div><div><br><br>понедельник, 2 октября 2017 г. пользователь Richard Smith  написал:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 29 September 2017 at 13:01, Roman Popov via cfe-dev <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','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"><div dir="ltr"><div>Hello,</div><div><br></div><div>Is it possible to emit a valid C++ from AST?</div><div><br></div><div>I've tried ASTPrinter in Clang-5.0, but it seems to emit some internal Clang representations. For example for template specialization I got:</div><div><br></div><div><div>template <typename T> struct test<T, int> : sc_core::sc_module {</div><div>    typedef test<type-parameter-0-0, int> this_t; </div></div><div>...</div><div><br></div><div><br></div><div>This "type-parameter-0-0"  seem to be some Clang specifics.</div></div></blockquote><div><br></div><div>We generally try to preserve type sugar, and printing "type-parameter-0-0" here is undesirable. If you could figure out how we're losing the type sugar and fix it, we would probably take the fix. However, while we make a best-effort attempt to produce valid code from the AST printer, there is in general no guarantee that the output is valid C++; it is intended for consumption primarily by humans, not by a compiler.</div><div><br></div><div>Usually, people asking about the AST printer are trying to perform some kind of refactoring by mutating the AST and pretty-printing the output. We do not recommend this approach. Instead, we recommend that you treat the AST as an immutable representation of the original code, decide on what transformations you want to perform, and then produce a set of edits to the original source code that have the desired effect. Clang's Tooling library provides support utilities for doing this.</div></div></div></div>
</blockquote></div></div>