blob: 0e17046996e9f0f118d859b49cafb67c0b505fb0 [file] [log] [blame]
Douglas Gregora48412a2010-05-11 22:09:20 +00001<!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>
11
12<!--#include virtual="menu.html.incl"-->
13
14<div id="content">
15
16<h1>Tutorial</h1>
17
18 <p>Invoking the BoostCon tool:</p>
19 <pre>
20$ clang -cc1 -boostcon t.cpp
21</pre>
22
23 <p>Teach the BoostCon action to identify and print C++ classes:</p>
24 <pre>
25bool VisitCXXRecordDecl(CXXRecordDecl *D) {
26 std::cout &lt;&lt; D-&gt;getNameAsString()
27 &lt;&lt; '\n';
28 return false;
29}
30</pre>
31
32 <p>Walk and print base classes of a class:</p>
33 <pre>
34for(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';
40}
41</pre>
42
43 <p>Retrieve the C++ class declaration from a base type:</p>
44 <pre>
45if (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)) {
50
51 }
52}
53</pre>
54</div>
55</body>
56</html>