>"C++ Insights is a clang-based tool which does a source to source transformation. Its goal is to make things visible, which normally and intentionally happen behind the scenes. It's about the magic the compiler does for us to make things work. Or looking through the classes of a compiler.

Some time ago, I started looking into some new things we got with C++11, C++14, C++17 and C++20. Amazing things like lambdas, range-based for-loops, and structured bindings. I put it together in a talk. You can find the slides and a video online.

However, all that research and some of my training and teaching got me to start thinking about

how it would be if we could see with the eyes of the compiler

. Sure, there is an AST-dump, at least for clang. With tools like Compiler Explorer, we can see what code the compiler generates from a C++ source snippet. However, what we see is assembler.

Neither the AST nor the Compiler Explorer output is in the language I write code

, and therefore I'm most familiar with. Plus, when teaching students C++ showing an AST and explaining that it is all there was not quite satisfying for me.

I started to write a clang-based tool able to transform a range-based for-loop into the compiler-internal version. Then, I did the same for structured bindings and lambdas. In the end, I ended up doing a lot more as initially planned. It shows where operators are invoked, places in which the compiler does some casting. C++ Insights is able to deduce the type behind auto or decltype. The goal is to produce compilable code. However, this is not possible in all places.

Still, there is work to do.

I do not claim to get all the things right. This is just the initial version of C++ Insights I consider good enough to hand it to the public. Also, keep in mind that it is solely based on clang and my understanding of C++ and the AST.

You can see, for example, the transformation of a lambda, range-based for-loop, or auto. Of course, you can transform any other C++ snippet.

For those who like videos, there is a C++ Insights series on Youtube. If you have topics you like me to speak about, please reach out to me.

The version information of the C++ Insights version running on this website can be found here: https://cppinsights.io/version.

You can find the source of the web front-end and the tool C++ Insights on Github.

If you like to support the project, consider submitting a patch. Another alternative is to become a Patreon supporter.

Contact: andy at cppinsights.io"

PDS: Andy, I think your work is brilliant and highly laudable, because you've partially solved, and are on the road to solving a really big problem, which can be summarized as "What does all of this complex code -- really boil down to, codewise, without transforming it into assembler".

In other words, let's suppose that there is a language, a Turing complete subset of C (I'm sure there is probably something like this somewhere on the web) that preserves such things as symbol names, if statements, loops, pointer reference/dereferences, etc.

OK, so now I've used C++ and I've created an object-oriented program that uses templating and the preprocessor, all of the advanced features of C++...

So now, what does that all boil down to, in C, or my limited subset of C?

See, that's the problem!

In other words, what does it all boil down to, without losing symbol names or high-level code constructs, like loops inside of loops, or block structures after if statments?

And of course, there could be many possible views of this. For example, one view might be to reduce a program down to its lowest level that still preserves objects, where another view might be to reduce a program below that level (to C or C subset) -- while still presevering symbol names... (or heck, you could move higher level constructs that were reduced into comments, etc.).

Anyway, you're on a very laudable path! I hope you get some publicity/traction and the HN community helps you out!