[cfe-dev] Is there a tool that restores a previously saved AST?

Ronan Keryell Ronan.Keryell at silkan.com
Mon Jul 8 15:34:50 PDT 2013


>>>>> On Mon, 8 Jul 2013 21:46:28 +0200, Daniel Albuschat <d.albuschat at gmail.com> said:

    Daniel> The reason I am interested in restoring and/or building an
    Daniel> AST is because I am thinking about using Clang as the
    Daniel> backend for a programming language.  It will obviously be a
    Daniel> subset of C++. It would be awesome to use libraries written
    Daniel> in C++ in it. This means, at a minimum, instantiating
    Daniel> "simple" classes and calling functions. Think of "C++ light"
    Daniel> with less baggage from C and more straightforward Syntax. I
    Daniel> am going to evaluate whether building my own, simpler AST
    Daniel> and translating it into the Clang AST might work.

    Daniel> Do you think that this is feasible, or is it doomed to fail
    Daniel> for some obvious reasons?

This seems overly more complex to me than just generating C++11 directly
from your own parser instead. Instead of spending A LOT OF TIME porting
your tool to the Clang AST moving target, just generate something quite
standard. :-) By using more or less macroprocessing and metaprogramming,
you may even tune the complexity of your generator (for example like
https://github.com/MetaScale/nt2 ). And the generated C++11 programs can
pretty well "use libraries in C++ in it" as you expect! :-) After all,
C++11 can be seen as a serialized version of the Clang AST with some
restrictions. :-)

As an example, I was thinking about implementing a Fortran 2008
front-end for Clang this way, by reusing the existing run-time and
relying on the fact that the Fortran norm describes now an API for
interfacing with C and externalizes its array triplet notation through
another API (so for example you could use boost::multi_array to
implement them at the C++ level).
-- 
  Ronan KERYELL                            |\/  Phone:  +1 650 386 6482
  SILKAN Wild Systems                      |/)
  4962 El Camino Real #201                 K    Ronan.Keryell at silkan.com
  Los Altos, CA 94022                      |\   skype:keryell
  USA                                      | \  http://silkan.com



More information about the cfe-dev mailing list