diff --git a/.gitignore b/.gitignore index 3eac990..1e5ed94 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ libclang.node *.swp node_modules +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 387d426..f395c46 100644 --- a/README.md +++ b/README.md @@ -7,22 +7,37 @@ AST Traversal ```javascript var libclang = require('libclang'); -var index = new libclang.index(); -var tu = new libclang.translationunit(); - -tu.fromSource(idx, 'myLibrary.h', ['-I/path/to/my/project']); - -tu.cursor().visitChildren(function (parent) { - switch (this.kind) { - case libclang.KINDS.CXCursor_FunctionDecl: - console.log(this.spelling); - break; - } - return libclang.CXChildVisit_Continue; +var + Cursor = libclang.Cursor, + Index = libclang.Index, + TranslationUnit = libclang.TranslationUnit; + +var dclang = require('./node_modules/libclang/lib/dynamic_clang'); +var consts = dclang.CONSTANTS; + +var index = new Index(true, true); +var tu = new TranslationUnit.fromSource(index, '/path/to/my/sourcefile/myLibrary.h', [ + '-xc++', +]); + +tu.cursor.visitChildren(function (parent) { + if(this.spelling == "__llvm__") { + return; + } else { + console.log("Name = " + this.spelling); + console.log("Kind = " + consts.CXCursorKind[this.kind]); + console.log("Type = " + consts.CXTypeKind[this.type.kind]); + console.log("Line Number = " + this.location.presumedLocation.line); + console.log("Column Number = " + this.location.presumedLocation.column); + console.log("------------"); + return Cursor.Recurse; + } + }); index.dispose(); -tu.dispose(); +tu.dispose; + ```` Generate FFI Bindings diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/lib/.DS_Store differ diff --git a/lib/cursor.js b/lib/cursor.js index dfca6b3..5e4042d 100644 --- a/lib/cursor.js +++ b/lib/cursor.js @@ -69,6 +69,12 @@ var Cursor = function (instance) { } }); + Object.defineProperty(this, 'pointeeType', { + get: function () { + return new Type(lib.clang_getPointeeType(lib.clang_getCursorType(self._instance))); + } + }); + Object.defineProperty(this, 'enumType', { get: function () { return new Type(lib.clang_getEnumDeclIntegerType(self._instance));