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