Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 45 lines (35 sloc) 1.33 KB
\ Pretty intense test of the boxing support
import "stdlib"
import "clang-c/Index"
@HeaderIndex {
+ parse: path withBlock: lambda `self new parse: path withBlock: lambda`
- init {
@idx = Clang_createIndex(0, 1)
^self
}
- dealloc `Clang_disposeIndex(@idx)`
- parse: path withBlock: lambda {
clangArgs = TQPointer to: #-ObjC withType: #*
clangOpts = CXTranslationUnit_DetailedPreprocessingRecord bitOr: CXTranslationUnit_SkipFunctionBodies
header = Clang_parseTranslationUnit(@idx, path, clangArgs, clangArgs count, nil, 0, clangOpts)
if header == nil {
"Unable to parse «path»" print
^nil
}
cursor = Clang_getTranslationUnitCursor(header)
Clang_visitChildrenWithBlock(cursor, lambda)
Clang_disposeTranslationUnit(header)
}
}
HeaderIndex parse: "/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h"
withBlock: { child, parent |
name_ = Clang_getCursorSpelling(child)
name = Clang_getCString(name_) toString
kind_ = Clang_getCursorKindSpelling(Clang_getCursorKind(child))
kind = Clang_getCString(kind_) toString
Clang_disposeString(name_)
Clang_disposeString(kind_)
^CXChildVisit_Continue if name length == 0
"«kind»: «name»" print
^CXChildVisit_Continue
}