Thank you! A truly great intro into the clang AST. I'm trying to fix a clang bug I discovered and contribute and this has really helped to inject a lot of base knowledge very quickly.
My tutorial on Clang's AST from the LLVM Euro 2013 conference. If you're new to Clang, this gives you the very basics to get you started. Make sure to watch in HD to be able to read the code in the terminal session. Featuring YCM code completion and clang-format in action :)
It already was 720p - that options was readily available when I made the G+ post. Over night youtube seems to have decided that I cannot get 720p. I'm investigating why that might be ...
I'm using ycm (see link [4]) which uses libclang for code completion and has pluggable build system support for compilation databases (we're using a different compilation database integration for our internal server based build system).
Awesome work Manuel, we need more efforts like yours to push C++ into the future. So it can become not only more powerful and performant but also more accessible and easy to use!
On AST matchers and triggering on expressions, isn’t the main thing that you want to do with expressions is to have a control flow tree starting from main? Yeah, expressions in a separate source file might be needed. But, I’d say the most useful thing is to traverse main.
Thanks for your response, ycm is awesome :) And thanks for your video. I'm planning to develop some specific code quality checking tools for our team, and this video is good entry point to AST.
Hi, I am working on coding conventions using clang compiler. I can check variable declaration by using class varDecl. What I do clang::Vardecl *a StringRef s=a->getName(); Now I can put the condition on s. Like this Suppose I want to check #ifndef and other things as Cout what are the classes I have to use and how to fetch the function?
Nico159: kk, working on it duminicad: what would you want examples about? If you're into tooling, I think the best place to start is the step-by-step tutorials: clang.llvm.org/docs/LibTooling.html And then dive into the ast matchers: clang.llvm.org/docs/LibASTMatchers.html If you want to dive into the compiler, the best way is to visit the IRC channel and ask for good tasks to pick up, or put a mail to cfe-dev (for clang) or llvmdev (for llvm).
@@ManuelKlimek Since I wrote last comment I managed to clone template params, then i drop it because approach was wrong. Then I cloned whole class definition because it was better haha. So clang is huge, but now i hope I understand something :-) Anyways thanks! I'll wait for your publications!
I don't really mind, as long as I can use your classes. I would also like to use it, not as a standalone tool from the command line, following the Libtooling setup methods, but inside an application, adding files and getting their translation units as I go. That is, I would like to manually call all the methods to get the AST. Is that possible or too complicated?
I really would like to learn how to write a basic programming language, but I think the problem is that too many focus on the concepts, theories, etc and not taking the same approach as to bringing a person that doesn't know how to program into the loop of writing programs. I've read many books about making compilers and interpreters, but it felt more like they were teaching me the fundamentals of how an airplane operates, then throwing me in the cockpit to fly it alone. Above all, great video. :D
I think the problem is that writing a programming language in the end is more like building an airplane while flying a different one. Thus, you need to know how an airplane operates, otherwise the one you build will never leave ground...
TrollMonger For an easier intro try MPS from Jetbrains. Its free and it already provides an already made 'basic programming language' that you can tweak. In you analogy of planes I think it would be to sit in a cockpit with a pilot and so you can then go to the aerospace institute ;)
Can someone point me to an actual tutorial, as in: teach me how to set up AST traversal? Start with somethin simple? This is way too much about the internals of the Clang AST stuff.
Plain C is and will probably always be one of the most important languages out there, but I cannot wait for C++ to die. C++ is a horrific language. Horrific syntax, horrific illegibility, horrific everything. Other, better, more readable, concise, friendly system languages are on the rise and will continue to do so. "C++ is too complicated. At the moment, it's impossible for me to write portable code that I believe would work on lots of different systems, unless I avoid all exotic features. Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said "OK, we'll do them both". So the language is too baroque for my taste." -- Donald Knuth "(Edsger W. Dijkstra's) great strength is that he is uncompromising. It would make him physically ill to think of programming in C++." -- Donald Knuth
Long duration of video and not much important information. - What did I know after watched this video? - It is possible to dump useless AST for C++ sources. - Why do I need this? - It is a rhetorical question...
Thank you whoever subtitled 45 minutes of video!
Thank you! A truly great intro into the clang AST. I'm trying to fix a clang bug I discovered and contribute and this has really helped to inject a lot of base knowledge very quickly.
My tutorial on Clang's AST from the LLVM Euro 2013 conference. If you're new to Clang, this gives you the very basics to get you started.
Make sure to watch in HD to be able to read the code in the terminal session. Featuring YCM code completion and clang-format in action :)
Is youtube still processing the video so it will be > 480p?
It already was 720p - that options was readily available when I made the G+ post. Over night youtube seems to have decided that I cannot get 720p. I'm investigating why that might be ...
This is a good workaround until youtube fixes: llvm.org/devmtg/2013-04/videos/klimek-vhres.mov :)
And HD mode is back! :)
Now with captions!
Hey Manuel, great talk! Really enjoyed it. Always interesting to see how C++ compilers look like on the inside.
I'm using ycm (see link [4]) which uses libclang for code completion and has pluggable build system support for compilation databases (we're using a different compilation database integration for our internal server based build system).
Great presentation, thanks. Saved to see later, so I can rewatch it as learning the AST Lang.
Awesome work Manuel, we need more efforts like yours to push C++ into the future. So it can become not only more powerful and performant but also more accessible and easy to use!
On AST matchers and triggering on expressions, isn’t the main thing that you want to do with expressions is to have a control flow tree starting from main? Yeah, expressions in a separate source file might be needed. But, I’d say the most useful thing is to traverse main.
Thanks for your response, ycm is awesome :)
And thanks for your video. I'm planning to develop some specific code quality checking tools for our team, and this video is good entry point to AST.
It seems at 13:40 there is a possible error. I think that getCaller() method returns the Var. getCallee() returns the function().
Also getLocStart() is now deprecated in favor of getBeginLoc().
Nico159: captions added - let me know if something doesn't work :)
Also, would be nice to see an example for a full multi-file program. Not just 1 source file.
Hi, I am working on coding conventions using clang compiler. I can check variable declaration by using class varDecl.
What I do clang::Vardecl *a
StringRef s=a->getName();
Now I can put the condition on s.
Like this Suppose I want to check #ifndef and other things as Cout what are the classes I have to use and how to fetch the function?
Are you using clang_complete for auto-completion?
Nico159: kk, working on it
duminicad: what would you want examples about? If you're into tooling, I think the best place to start is the step-by-step tutorials: clang.llvm.org/docs/LibTooling.html
And then dive into the ast matchers: clang.llvm.org/docs/LibASTMatchers.html
If you want to dive into the compiler, the best way is to visit the IRC channel and ask for good tasks to pick up, or put a mail to cfe-dev (for clang) or llvmdev (for llvm).
Hi Manuel! Are there any tutorials on how to add synthetic AST nodes? Thanks!
There's work going on to introduce the concept of a "mutable AST" for refactorings; this is all very early work, so stay tuned.
@@ManuelKlimek Since I wrote last comment I managed to clone template params, then i drop it because approach was wrong. Then I cloned whole class definition because it was better haha. So clang is huge, but now i hope I understand something :-) Anyways thanks! I'll wait for your publications!
Is there a place that explains how to setup the tools to start developing with the Clang AST?
You'll want to build clang from source. Or were you looking for something different?
I don't really mind, as long as I can use your classes. I would also like to use it, not as a standalone tool from the command line, following the Libtooling setup methods, but inside an application, adding files and getting their translation units as I go. That is, I would like to manually call all the methods to get the AST. Is that possible or too complicated?
That's possible - clang.llvm.org/docs/LibTooling.html should be a good starting point.
(note: while the default is all set up as standalone tools, you should be able to extract what you need for an in-program run from there)
Watch from 25:00
May I have the lecture slides as PDF or powerpoint?
Found them:
llvm.org/devmtg/2013-04/klimek-slides.pdf
@@konstantinrebrov675 Thanks for following up before I could! :)
In case you want this captioned, please let me know in the comments.
Getting everything up and running on VS is not straight forward for everyone even reading the documentation
True. The problem is that most devs in the community work on linux or macos.
We'd really welcome patches, especially to the documentation :)
I really would like to learn how to write a basic programming language, but I think the problem is that too many focus on the concepts, theories, etc and not taking the same approach as to bringing a person that doesn't know how to program into the loop of writing programs. I've read many books about making compilers and interpreters, but it felt more like they were teaching me the fundamentals of how an airplane operates, then throwing me in the cockpit to fly it alone. Above all, great video. :D
I think the problem is that writing a programming language in the end is more like building an airplane while flying a different one. Thus, you need to know how an airplane operates, otherwise the one you build will never leave ground...
TrollMonger For an easier intro try MPS from Jetbrains. Its free and it already provides an already made 'basic programming language' that you can tweak. In you analogy of planes I think it would be to sit in a cockpit with a pilot and so you can then go to the aerospace institute ;)
helpful
Can someone point me to an actual tutorial, as in: teach me how to set up AST traversal? Start with somethin simple? This is way too much about the internals of the Clang AST stuff.
Victor Eijkhout jonasdevlieghere.com/understanding-the-clang-ast/ ?
lol subtitler does not know any C++
GRIFFITHHHH!!!!!!!!!!
Plain C is and will probably always be one of the most important languages out there, but I cannot wait for C++ to die. C++ is a horrific language. Horrific syntax, horrific illegibility, horrific everything. Other, better, more readable, concise, friendly system languages are on the rise and will continue to do so.
"C++ is too complicated. At the moment, it's impossible for me to write portable code that I believe would work on lots of different systems, unless I avoid all exotic features. Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said "OK, we'll do them both". So the language is too baroque for my taste." -- Donald Knuth
"(Edsger W. Dijkstra's) great strength is that he is uncompromising. It would make him physically ill to think of programming in C++." -- Donald Knuth
I just hope the world realizes this soon. Rust is the best replacement for c++.
Long duration of video and not much important information.
- What did I know after watched this video?
- It is possible to dump useless AST for C++ sources.
- Why do I need this?
- It is a rhetorical question...
Thanks for your feedback, sorry you didn't get what you wanted out of it :( What were you looking for?