在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:sbinet/go-clang开源软件地址:https://github.com/sbinet/go-clang开源编程语言:C 54.4%开源软件介绍:go-clangNaive Go bindings to the C-API of WARNING - DEPRECATEDWARNING: This repository is DEPRECATED.
Please use instead one of the InstallationAs there is no
ExampleAn example on how to use the AST visitor of https://github.com/sbinet/go-clang/blob/master/go-clang-dump/main.go package main
import (
"flag"
"fmt"
"os"
"github.com/sbinet/go-clang"
)
var fname *string = flag.String("fname", "", "the file to analyze")
func main() {
fmt.Printf(":: go-clang-dump...\n")
flag.Parse()
fmt.Printf(":: fname: %s\n", *fname)
fmt.Printf(":: args: %v\n", flag.Args())
if *fname == "" {
flag.Usage()
fmt.Printf("please provide a file name to analyze\n")
os.Exit(1)
}
idx := clang.NewIndex(0, 1)
defer idx.Dispose()
nidx := 0
args := []string{}
if len(flag.Args()) > 0 && flag.Args()[0] == "-" {
nidx = 1
args = make([]string, len(flag.Args()[nidx:]))
copy(args, flag.Args()[nidx:])
}
tu := idx.Parse(*fname, args, nil, 0)
defer tu.Dispose()
fmt.Printf("tu: %s\n", tu.Spelling())
cursor := tu.ToCursor()
fmt.Printf("cursor-isnull: %v\n", cursor.IsNull())
fmt.Printf("cursor: %s\n", cursor.Spelling())
fmt.Printf("cursor-kind: %s\n", cursor.Kind().Spelling())
tu_fname := tu.File(*fname).Name()
fmt.Printf("tu-fname: %s\n", tu_fname)
fct := func(cursor, parent clang.Cursor) clang.ChildVisitResult {
if cursor.IsNull() {
fmt.Printf("cursor: <none>\n")
return clang.CVR_Continue
}
fmt.Printf("%s: %s (%s)\n",
cursor.Kind().Spelling(), cursor.Spelling(), cursor.USR())
switch cursor.Kind() {
case clang.CK_ClassDecl, clang.CK_EnumDecl,
clang.CK_StructDecl, clang.CK_Namespace:
return clang.CVR_Recurse
}
return clang.CVR_Continue
}
cursor.Visit(fct)
fmt.Printf(":: bye.\n")
} which can be installed like so:
Limitations
DocumentationIs available at http://godoc.org/github.com/sbinet/go-clang |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论