私は libtooling の初心者です。簡単な C++ コードで学習しようとしています。以下の行のような typedef 式を解析/出力しようとしています:
namespace DEBUG {
typedef void(*function_pointer_t)(int&);
typedef int myInt;
}
clang++ -Xclang -ast-dump -fsyntax-only
出力:
`-NamespaceDecl 0x3e4fe331a8 <test.h:3:1, line:7:1> line:3:11 TESTS
|-TypedefDecl 0x3e4fe333b8 <line:4:2, col:42> col:18 function_pointer_t 'double (*)(int &)'
| `-PointerType 0x3e4fe33350 'double (*)(int &)'
| `-ParenType 0x3e4fe332f0 'double (int &)' sugar
| `-FunctionProtoType 0x3e4fe332b0 'double (int &)' cdecl
| |-BuiltinType 0x3e4fe32b60 'double'
| `-LValueReferenceType 0x3e4fe33210 'int &'
| `-BuiltinType 0x3e4fe32a40 'int'
`-TypedefDecl 0x3e4fe33420 <line:5:2, col:14> col:14 myInt 'int'
`-BuiltinType 0x3e4fe32a40 'int'
それを解析するために、継承しMatchFinder::MatchCallback
てオーバーロードするクラスを作成しMatchFinder::MatchCallback::run
ます。
class TypdefDeclFinder : public MatchFinder::MatchCallback {
public:
virtual void run(const MatchFinder::MatchResult& result)
{
auto Item = result.Nodes.getNodeAs<clang::TypedefDecl>("typedefDeclMatch");
if (!Item) return;
if (!IsDeclFromInputFiles(Item, result.SourceManager)) return;
if (!Item->getIdentifier()) return;
if (IsInsideTemplateContext(Item)) return;
print(Item);
}
};
しかし、Item
ポインターはヌルに等しいです。関数、変数、クラス、構造体テンプレート、メソッド テンプレート、列挙型などを解析/出力できますMacthFinder::MatchCallback
が、この方法は typedef では実行されません。このコードの何が問題になっていますか?