Skip to content

Instantly share code, notes, and snippets.

@freakboy3742
Created January 20, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freakboy3742/5826ef09789dfba9042e to your computer and use it in GitHub Desktop.
Save freakboy3742/5826ef09789dfba9042e to your computer and use it in GitHub Desktop.
Example Python API for clang
=== sample.cpp
CursorKind.TRANSLATION_UNIT (type:TypeKind.INVALID | result type:TypeKind.INVALID) sample.cpp
CursorKind.CLASS_DECL (type:TypeKind.RECORD | result type:TypeKind.INVALID) Foo
CursorKind.CXX_ACCESS_SPEC_DECL (type:TypeKind.INVALID | result type:TypeKind.INVALID)
CursorKind.CONSTRUCTOR (type:TypeKind.FUNCTIONPROTO | result type:TypeKind.VOID) Foo
CursorKind.PARM_DECL (type:TypeKind.INT | result type:TypeKind.INVALID) x
CursorKind.COMPOUND_STMT (type:TypeKind.INVALID | result type:TypeKind.INVALID)
CursorKind.FUNCTION_DECL (type:TypeKind.FUNCTIONPROTO | result type:TypeKind.RECORD) factory
CursorKind.TYPE_REF (type:TypeKind.RECORD | result type:TypeKind.INVALID) class Foo
CursorKind.PARM_DECL (type:TypeKind.INT | result type:TypeKind.INVALID) x
CursorKind.COMPOUND_STMT (type:TypeKind.INVALID | result type:TypeKind.INVALID)
CursorKind.RETURN_STMT (type:TypeKind.INVALID | result type:TypeKind.INVALID)
CursorKind.CALL_EXPR (type:TypeKind.RECORD | result type:TypeKind.INVALID)
CursorKind.UNEXPOSED_EXPR (type:TypeKind.RECORD | result type:TypeKind.INVALID)
CursorKind.UNEXPOSED_EXPR (type:TypeKind.RECORD | result type:TypeKind.INVALID)
CursorKind.CXX_FUNCTIONAL_CAST_EXPR (type:TypeKind.RECORD | result type:TypeKind.INVALID)
CursorKind.TYPE_REF (type:TypeKind.RECORD | result type:TypeKind.INVALID) class Foo
CursorKind.CALL_EXPR (type:TypeKind.RECORD | result type:TypeKind.INVALID) Foo
CursorKind.UNEXPOSED_EXPR (type:TypeKind.INT | result type:TypeKind.INVALID) x
CursorKind.DECL_REF_EXPR (type:TypeKind.INT | result type:TypeKind.INVALID) x
TranslationUnitDecl 0x103030cc0 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x103031200 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
|-TypedefDecl 0x103031260 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
|-TypedefDecl 0x103031660 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list '__va_list_tag [1]'
|-CXXRecordDecl 0x1030316b0 <sample.cpp:1:1, line:5:1> line:1:7 referenced class Foo definition
| |-CXXRecordDecl 0x1030317c0 <col:1, col:7> col:7 implicit referenced class Foo
| |-AccessSpecDecl 0x103031850 <line:2:3, col:9> col:3 public
| |-CXXConstructorDecl 0x104000000 <line:3:5, line:4:5> line:3:5 used Foo 'void (int)'
| | |-ParmVarDecl 0x103031890 <col:9, col:13> col:13 x 'int'
| | `-CompoundStmt 0x1040000f8 <col:16, line:4:5>
| |-CXXConstructorDecl 0x104000300 <line:1:7> col:7 implicit used Foo 'void (const class Foo &) throw()' inline
| | |-ParmVarDecl 0x104000440 <col:7> col:7 'const class Foo &'
| | `-CompoundStmt 0x1040006e0 <col:7>
| `-CXXDestructorDecl 0x104000520 <col:7> col:7 implicit used ~Foo 'void (void) throw()' inline
| `-CompoundStmt 0x104000670 <col:7>
`-FunctionDecl 0x1040001e0 <line:7:1, line:9:1> line:7:5 factory 'class Foo (int)'
|-ParmVarDecl 0x104000120 <col:13, col:17> col:17 used x 'int'
`-CompoundStmt 0x104000790 <col:20, line:9:1>
`-ReturnStmt 0x104000770 <line:8:5, col:17>
`-CXXConstructExpr 0x104000738 <col:12, col:17> 'class Foo' 'void (const class Foo &) throw()' elidable
`-MaterializeTemporaryExpr 0x1040006c8 <col:12, col:17> 'const class Foo' lvalue
`-ImplicitCastExpr 0x1040006b0 <col:12, col:17> 'const class Foo' <NoOp>
`-CXXFunctionalCastExpr 0x104000688 <col:12, col:17> 'class Foo' functional cast to class Foo <ConstructorConversion>
`-CXXConstructExpr 0x1040004c0 <col:12, col:17> 'class Foo' 'void (int)'
`-ImplicitCastExpr 0x1040004a8 <col:16> 'int' <LValueToRValue>
`-DeclRefExpr 0x1040002a0 <col:16> 'int' lvalue ParmVar 0x104000120 'x' 'int'
class Foo {
public:
Foo(int x) {
}
};
Foo factory(int x) {
return Foo(x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment