Fix the clang-wpa example.
[clang.git] / www / clang-tutorial.html
blob0e17046996e9f0f118d859b49cafb67c0b505fb0
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
6 <title>Clang - Quick Tutorial</title>
7 <link type="text/css" rel="stylesheet" href="menu.css" />
8 <link type="text/css" rel="stylesheet" href="content.css" />
9 </head>
10 <body>
12 <!--#include virtual="menu.html.incl"-->
14 <div id="content">
16 <h1>Tutorial</h1>
18 <p>Invoking the BoostCon tool:</p>
19 <pre>
20 $ clang -cc1 -boostcon t.cpp
21 </pre>
23 <p>Teach the BoostCon action to identify and print C++ classes:</p>
24 <pre>
25 bool VisitCXXRecordDecl(CXXRecordDecl *D) {
26 std::cout &lt;&lt; D-&gt;getNameAsString()
27 &lt;&lt; '\n';
28 return false;
30 </pre>
32 <p>Walk and print base classes of a class:</p>
33 <pre>
34 for(CXXRecordDecl::base_class_iterator
35 B = D-&gt;bases_begin(), BEnd = D-&gt;bases_end();
36 B != BEnd; ++B) {
37 QualType BaseType = B-&gt;getType();
38 std::cout &lt;&lt; " " &lt;&lt; BaseType.getAsString()
39 &lt;&lt; '\n';
41 </pre>
43 <p>Retrieve the C++ class declaration from a base type:</p>
44 <pre>
45 if (const RecordType *RTy
46 = BaseType-&gt;getAs&lt;RecordType&gt;()) {
47 RecordDecl *Base = RTy-&gt;getDecl();
48 if (CXXRecordDecl *BaseCXX
49 = dyn_cast&lt;CXXRecordDecl&gt;(Base)) {
53 </pre>
54 </div>
55 </body>
56 </html>