c/clang: castdump
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/clang"
|
||||
)
|
||||
@@ -13,13 +16,21 @@ func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitRe
|
||||
|
||||
func printAST(cursor clang.Cursor, depth c.Uint) {
|
||||
cursorKind := cursor.Kind.String()
|
||||
cursorSpelling := cursor.String()
|
||||
println("cursor.Kind.String done")
|
||||
c.Printf(c.Str("cursorKind = %s\n"), cursorKind.CStr())
|
||||
|
||||
cursorSpelling := clang.GetCursorSpelling(cursor) // cursor.String()
|
||||
println("clang.GetCursorSpelling done")
|
||||
|
||||
for i := c.Uint(0); i < depth; i++ {
|
||||
println("c.Fputs start")
|
||||
c.Fputs(c.Str(" "), c.Stdout)
|
||||
println("c.Fputs end")
|
||||
}
|
||||
|
||||
println("c.Printf start")
|
||||
c.Printf(c.Str("%s: %s\n"), cursorKind.CStr(), cursorSpelling.CStr())
|
||||
println("c.Printf end")
|
||||
|
||||
cursorKind.Dispose()
|
||||
cursorSpelling.Dispose()
|
||||
@@ -28,13 +39,22 @@ func printAST(cursor clang.Cursor, depth c.Uint) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
if c.Argc != 2 {
|
||||
fmt.Fprintln(os.Stderr, "Usage: castdump <headerFile>")
|
||||
return
|
||||
}
|
||||
sourceFile := *c.Advance(c.Argv, 1)
|
||||
|
||||
index := clang.CreateIndex(0, 0)
|
||||
println("clang.CreateIndex done")
|
||||
|
||||
unit := index.ParseTranslationUnit(
|
||||
c.Str("todo"),
|
||||
sourceFile,
|
||||
nil, 0,
|
||||
nil, 0,
|
||||
clang.TranslationUnit_None,
|
||||
)
|
||||
println("index.ParseTranslationUnit done")
|
||||
|
||||
if unit == nil {
|
||||
println("Unable to parse translation unit. Quitting.")
|
||||
@@ -42,6 +62,8 @@ func main() {
|
||||
}
|
||||
|
||||
cursor := unit.Cursor()
|
||||
println("unit.Cursor done")
|
||||
|
||||
printAST(cursor, 0)
|
||||
|
||||
unit.Dispose()
|
||||
|
||||
7
c/clang/_wrap/llgo_check.cpp
Normal file
7
c/clang/_wrap/llgo_check.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
int main() {
|
||||
printf("sizeof(clang.Cursor) = %lu\n", sizeof(CXCursor));
|
||||
return 0;
|
||||
}
|
||||
16
c/clang/_wrap/llgo_check.go
Normal file
16
c/clang/_wrap/llgo_check.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/clang"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoCFlags = "-I$(llvm-config --includedir)"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("sizeof(clang.Cursor) = %lu\n"), unsafe.Sizeof(clang.Cursor{}))
|
||||
}
|
||||
@@ -38,13 +38,13 @@ type String struct {
|
||||
/**
|
||||
* Retrieve the character data associated with the given string.
|
||||
*/
|
||||
// llgo:link C.clang_getCString
|
||||
// llgo:link String.CStr C.clang_getCString
|
||||
func (String) CStr() *c.Char { return nil }
|
||||
|
||||
/**
|
||||
* Free the given string.
|
||||
*/
|
||||
// llgo:link C.clang_disposeString
|
||||
// llgo:link String.Dispose C.clang_disposeString
|
||||
func (String) Dispose() {}
|
||||
|
||||
type StringSet struct {
|
||||
@@ -55,5 +55,5 @@ type StringSet struct {
|
||||
/**
|
||||
* Free the given string set.
|
||||
*/
|
||||
// llgo:link C.clang_disposeStringSet
|
||||
// llgo:link (*StringSet).Dispose C.clang_disposeStringSet
|
||||
func (*StringSet) Dispose() {}
|
||||
|
||||
@@ -152,7 +152,7 @@ type TranslationUnit struct {
|
||||
/**
|
||||
* Destroy the specified CXTranslationUnit object.
|
||||
*/
|
||||
// llgo:linke (*TranslationUnit).Dispose C.clang_disposeTranslationUnit
|
||||
// llgo:link (*TranslationUnit).Dispose C.clang_disposeTranslationUnit
|
||||
func (*TranslationUnit) Dispose() {}
|
||||
|
||||
/**
|
||||
@@ -204,11 +204,14 @@ type Cursor struct {
|
||||
/**
|
||||
* Retrieve a name for the entity referenced by this cursor.
|
||||
*/
|
||||
// llgo:link C.clang_getCursorSpelling
|
||||
// llgo:link Cursor.String C.clang_getCursorSpelling
|
||||
func (Cursor) String() (ret String) {
|
||||
return
|
||||
}
|
||||
|
||||
//go:linkname GetCursorSpelling C.clang_getCursorSpelling
|
||||
func GetCursorSpelling(cursor Cursor) String
|
||||
|
||||
/**
|
||||
* Describes how the traversal of the children of a particular
|
||||
* cursor should proceed after visiting a particular child cursor.
|
||||
|
||||
Reference in New Issue
Block a user