Douglas Gregor | a48412a | 2010-05-11 22:09:20 +0000 | [diff] [blame] | 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> |
| 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> |
| 25 | bool VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 26 | std::cout << D->getNameAsString() |
| 27 | << '\n'; |
| 28 | return false; |
| 29 | } |
| 30 | </pre> |
| 31 | |
| 32 | <p>Walk and print base classes of a class:</p> |
| 33 | <pre> |
| 34 | for(CXXRecordDecl::base_class_iterator |
| 35 | B = D->bases_begin(), BEnd = D->bases_end(); |
| 36 | B != BEnd; ++B) { |
| 37 | QualType BaseType = B->getType(); |
| 38 | std::cout << " " << BaseType.getAsString() |
| 39 | << '\n'; |
| 40 | } |
| 41 | </pre> |
| 42 | |
| 43 | <p>Retrieve the C++ class declaration from a base type:</p> |
| 44 | <pre> |
| 45 | if (const RecordType *RTy |
| 46 | = BaseType->getAs<RecordType>()) { |
| 47 | RecordDecl *Base = RTy->getDecl(); |
| 48 | if (CXXRecordDecl *BaseCXX |
| 49 | = dyn_cast<CXXRecordDecl>(Base)) { |
| 50 | |
| 51 | } |
| 52 | } |
| 53 | </pre> |
| 54 | </div> |
| 55 | </body> |
| 56 | </html> |