diff --git a/cl/_testc/doc/in.h b/cl/_testc/doc/in.h index 81872379..75467c4b 100644 --- a/cl/_testc/doc/in.h +++ b/cl/_testc/doc/in.h @@ -25,7 +25,7 @@ int add(int a, int b); typedef int MyInt; /// A documented global variable. -extern MyInt counter; +extern int counter; /// Maximum size limit. #define MAX_SIZE 100 diff --git a/cl/_testc/doc/out.go b/cl/_testc/doc/out.go index 6eb1816f..caf9d20b 100644 --- a/cl/_testc/doc/out.go +++ b/cl/_testc/doc/out.go @@ -40,4 +40,4 @@ func Add(a c.Int, b c.Int) c.Int // A documented global variable. // //go:linkname Counter C.counter -var Counter MyInt +var Counter c.Int diff --git a/cl/class.go b/cl/class.go index a38e4ac1..cb0051bc 100644 --- a/cl/class.go +++ b/cl/class.go @@ -59,7 +59,7 @@ type classCtx struct { decl clang.Cursor typNamed *types.Named fields []*types.Var - publicMethods []*overloadObj + publicMethods []*funcObj polymorphic bool // declares or inherits virtual methods ownsVptr bool // owns the vptr field (polymorphic with no primary base) } @@ -68,7 +68,7 @@ func (p *classCtx) scope() *scopeCtx { return (*scopeCtx)(unsafe.Pointer(p)) } -func compileClassImpl(ctx *pkgCtx, this *classCtx) { +func compileClass(ctx *pkgCtx, this *classCtx) { this.reorder() if this.polymorphic { // Emit the typed vtable and the XGo_vptr() accessor once method @@ -81,8 +81,6 @@ func compileClassImpl(ctx *pkgCtx, this *classCtx) { } } -// ----------------------------------------------------------------------------- - func newTypeParams(ctx *pkgCtx, pkg *types.Package, cls clang.Cursor) (ret []*types.TypeParam, quietIgnore bool) { idx := 0 ret = make([]*types.TypeParam, 0, 2) @@ -112,7 +110,7 @@ func newTypeParams(ctx *pkgCtx, pkg *types.Package, cls clang.Cursor) (ret []*ty } func isParameterPack(decl clang.Cursor) bool { // - tu := clang.TU(decl) + tu := clang.TranslationUnit{TranslationUnit: decl.TranslationUnit()} extent := decl.Extent() tokens, dispose := tu.Tokenize(extent) defer dispose() @@ -124,7 +122,16 @@ func isParameterPack(decl clang.Cursor) bool { // return false } -func loadTemplateClass(ctx *pkgCtx, cName string, this *classCtx, obj *overloadObj) { +func loadTemplateClass(ctx *pkgCtx, cls clang.Cursor, parent *scopeCtx) { + if obj, ok := ctx.addTemplateClass(ctx, cls); ok { + ctx.addCompileUnit(func(ctx *pkgCtx) { + compileTemplateClass(ctx, obj, parent) + }) + } +} + +func compileTemplateClass(ctx *pkgCtx, obj *templateClass, parent *scopeCtx) { + cName := obj.cName cls := obj.decl order := obj.order() if debugCompileDecl { @@ -150,20 +157,23 @@ func loadTemplateClass(ctx *pkgCtx, cName string, this *classCtx, obj *overloadO ctx.typdecls[cName] = typDecl } - if this == nil { - ctx.ignoref(featQuietIgnore, cls, "class %s: no definition, ignored", cName) - return + if cls.IsCursorDefinition() == 0 { + return // declaration only, no definition } goName := typDecl.Type().Obj().Name() - initClassType(ctx, typDecl, this, goName, tparams) + initClassType(ctx, typDecl, cls, goName, tparams, parent) } -// ----------------------------------------------------------------------------- - -func loadClass(ctx *pkgCtx, cName string, this *classCtx, cls clang.Cursor) { +func loadClass(ctx *pkgCtx, cls clang.Cursor, kind typeTag, parent *scopeCtx) { + cName := cNameOf(cls) if debugCompileDecl { - ctx.logf(cls, "%s", tagStrvals[cls.Kind]+cName) + ctx.logf(cls, "%s", tagStrvals[kind]+cName) + } + + if cls.NumTemplateArguments() > 0 { + loadTemplateClass(ctx, cls, parent) + return } var typDecl, ok = ctx.typdecls[cName] @@ -173,16 +183,14 @@ func loadClass(ctx *pkgCtx, cName string, this *classCtx, cls clang.Cursor) { ctx.typdecls[cName] = typDecl } - if this == nil { + if cls.IsCursorDefinition() == 0 { return // declaration only, no definition } goName := typDecl.Type().Obj().Name() - initClassType(ctx, typDecl, this, goName, nil) + initClassType(ctx, typDecl, cls, goName, nil, parent) } -// ----------------------------------------------------------------------------- - func newType(ctx *pkgCtx, cls clang.Cursor, cName, goName string) (ret typDecl) { ret.defs = ctx.pkg.NewTypeDefs() ret.TypeDecl = ret.defs.NewType(goName, goNode(ctx, cls)) @@ -192,20 +200,18 @@ func newType(ctx *pkgCtx, cls clang.Cursor, cName, goName string) (ret typDecl) return } -func initClassType(ctx *pkgCtx, typDecl typDecl, this *classCtx, goName string, tparams []*types.TypeParam) bool { +func initClassType(ctx *pkgCtx, typDecl typDecl, cls clang.Cursor, goName string, tparams []*types.TypeParam, parent *scopeCtx) bool { feats := 0 - initClassTypeEx(ctx, typDecl, this, goName, tparams, &feats) + initClassTypeEx(ctx, typDecl, cls, goName, tparams, parent, &feats) if feats&featAllIgnore != 0 { - ctx.ignoref(feats, this.decl, "class %s: unsupported features, ignored", goName) + ctx.ignoref(feats, cls, "class %s: unsupported features, ignored", goName) typDecl.Delete() return false } return true } -func initClassTypeEx(ctx *pkgCtx, typDecl typDecl, this *classCtx, goName string, tparams []*types.TypeParam, feats *int) { - cls := this.decl - +func initClassTypeEx(ctx *pkgCtx, typDecl typDecl, cls clang.Cursor, goName string, tparams []*types.TypeParam, parent *scopeCtx, feats *int) { // Attach the doc at the TypeDefs (GenDecl) level rather than on the // TypeSpec; see the note in loadTypedef for why a spec-level doc renders as // "type// doc" here. @@ -213,9 +219,13 @@ func initClassTypeEx(ctx *pkgCtx, typDecl typDecl, this *classCtx, goName string typDecl.defs.SetComments(doc) } - this.typNamed = typDecl.Type() - this.tparams = tparams - + this := &classCtx{ + decl: cls, + typNamed: typDecl.Type(), + overloads: make(map[string]*overloads), + tparams: tparams, + parent: parent, + } pkg := ctx.pkg pkgTypes := pkg.Types clang.VisitChildren(cls, func(decl, parent clang.Cursor) clang.ChildVisitResult { @@ -246,28 +256,46 @@ func initClassTypeEx(ctx *pkgCtx, typDecl typDecl, this *classCtx, goName string typStruc := types.NewStruct(this.fields, nil) typDecl.InitType(pkg, typStruc, tparams...) ctx.addCompileUnit(func(ctx *pkgCtx) { - compileClassImpl(ctx, this) + compileClass(ctx, this) }) } func emitClass(ctx *pkgCtx, cls clang.Cursor, goName string, parent *scopeCtx) *types.Named { typDecl := newType(ctx, cls, "", goName) - this := &classCtx{ - decl: cls, - overloads: make(map[string]*overloads), - parent: parent, - } - if !initClassType(ctx, typDecl, this, goName, nil) { + if !initClassType(ctx, typDecl, cls, goName, nil, parent) { ctx.panicf(cls, "class %s: unsupported feature, failed to initialize class", goName) } return typDecl.Type() } +func isPublic(decl clang.Cursor) bool { + return decl.CXXAccessSpecifier() == lc.CXXPublic +} + func loadClassMember(ctx *pkgCtx, pkg *types.Package, this *classCtx, goName string, decl clang.Cursor, feats *int) { switch decl.Kind { case lc.Cursor_CXXMethod, lc.Cursor_FunctionTemplate, lc.Cursor_Constructor, lc.Cursor_Destructor, lc.Cursor_ConversionFunction: - // noop: have been preloaded in newClassCtx + var name string + switch decl.Kind { + case lc.Cursor_Constructor: + name = "XGo_Ctor" + case lc.Cursor_Destructor: + name = "XGo_Dtor" + default: + if decl.CXXMethodIsStatic() != 0 { + if isPublic(decl) { + loadGlobalFunc(ctx, &ctx.scopeCtx, decl) + } + return + } + name = clang.String(decl) + } + if isPublic(decl) { + if fn, ok := this.addFunc(ctx, name, decl, isOperator(name)); ok { + this.publicMethods = append(this.publicMethods, fn) + } + } case lc.Cursor_FieldDecl: var fldType types.Type @@ -294,6 +322,10 @@ func loadClassMember(ctx *pkgCtx, pkg *types.Package, this *classCtx, goName str this.fields = append(this.fields, fld) case lc.Cursor_VarDecl: + // A static member variable is not a field: it has no per-instance + // storage. Load it as a package-level variable whose name is prefixed + // by the enclosing class name (the class name acts like a namespace), + // mirroring how a static method is handled above. if isPublic(decl) { loadVar(ctx, decl) } @@ -338,18 +370,19 @@ func loadClassMember(ctx *pkgCtx, pkg *types.Package, this *classCtx, goName str case decl.IsAnonymous() != 0: // noop default: - nested := newClassCtx(ctx, decl, this.scope()) - loadClass(ctx, cNameOf(decl), nested, decl) + // A named nested class/struct is emitted as a package-level type + // prefixed by the enclosing class name (the class name acts like a + // namespace), e.g. Foo_Shorts. It is emitted regardless of the + // enclosing access specifier: even a private nested type may be the + // declared type of a field (e.g. "struct Shorts shorts;"), and that + // field's type must resolve to a generated Go type. Its own members' + // default visibility still follows C++ rules (struct: public, + // class: private). + loadClass(ctx, decl, decl.Kind, this.scope()) } - case lc.Cursor_ClassTemplate: - nested := newClassCtx(ctx, decl, this.scope()) - loadTemplateClass(ctx, cNameOf(decl), nested, &overloadObj{ - decl: decl, - }) - - case lc.Cursor_ClassTemplatePartialSpecialization: - panic("defining a partial specialization in a class is not supported") + case lc.Cursor_ClassTemplate, lc.Cursor_ClassTemplatePartialSpecialization: + loadTemplateClass(ctx, decl, this.scope()) case lc.Cursor_UnionDecl: switch { @@ -470,4 +503,13 @@ func baseClass(ctx *pkgCtx, decl clang.Cursor, feats *int) *types.TypeName { return nil } +func loadOutsideMethod(ctx *pkgCtx, outsideDecl clang.Cursor) { + fnUSR := funcUSR(outsideDecl) + if m, ok := ctx.fns[fnUSR]; ok { + m.decl = outsideDecl + } else { + ctx.ignoref(featExplicitIgnore, outsideDecl, "[WARN] method undeclared - %s", cNameOf(outsideDecl)) + } +} + // ----------------------------------------------------------------------------- diff --git a/cl/compile.go b/cl/compile.go index 6ac5ce04..1e8093dd 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -19,10 +19,12 @@ package cl import ( "go/token" "go/types" + "log" "maps" "github.com/goplus/gogen" "github.com/goplus/llcppg/clang" + lc "github.com/llarhub/clang-c" ) const ( @@ -245,7 +247,7 @@ func NewPackage(pkgPath, pkgName string, files []Source, conf *Config) (ret Pack nsIgnore: conf.NSIgnore, macroIgnore: conf.MacroIgnore, typeIgnores: conf.TypeIgnore, classes: conf.Class, nonClasses: conf.NonClass, typdecls: typdecls, pkgOf: conf.PackageOf, nameLookup: nameLookup, pubLookup: conf.PubFileLookup, - fileBases: make(map[clang.File]int), ovobjs: make(map[string]*overloadObj), + fileBases: make(map[clang.File]int), fns: make(map[string]*funcObj), macroVals: make(map[string]any), types: make(map[string]typeObj), lastSeen: make(map[string]none), impPkgs: make(map[string]none), } @@ -258,6 +260,16 @@ func NewPackage(pkgPath, pkgName string, files []Source, conf *Config) (ret Pack loadFiles(ctx, files, pkgPath, conf.GoFileOf) + // NOTE(xsw): should complete uninitialized typDecls before compiling + if debugMajorProc { + log.Println("==> complete uninitialized type declarations") + } + for _, typDecl := range typdecls { + if typDecl.State() == gogen.TyStateUninited { + typDecl.InitType(pkg, types.NewStruct(nil, nil)) + } + } + ctx.compile() ret.Package = pkg ret.Wrap = ctx.wrap @@ -304,4 +316,62 @@ func loadFiles(ctx *pkgCtx, files []Source, myPkgPath string, goFileOf func(head scope.reorder() } +func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor) { + switch decl.Kind { + case lc.Cursor_FunctionDecl: + loadGlobalFunc(ctx, scope, decl) + case lc.Cursor_ClassDecl, lc.Cursor_StructDecl: + loadClass(ctx, decl, decl.Kind, nil) + case lc.Cursor_CXXMethod, lc.Cursor_Constructor, lc.Cursor_Destructor: + loadOutsideMethod(ctx, decl) + case lc.Cursor_TypedefDecl, lc.Cursor_TypeAliasDecl, lc.Cursor_TypeAliasTemplateDecl: + loadTypedef(ctx, decl, nil) + case lc.Cursor_EnumDecl: + loadEnum(ctx, decl) + case lc.Cursor_MacroDefinition: + loadMacro(ctx, decl) + case lc.Cursor_InclusionDirective: + loadInclude(ctx, decl) + case lc.Cursor_Namespace: + loadNamespace(ctx, scope, decl) + case lc.Cursor_VarDecl: + loadVar(ctx, decl) + case lc.Cursor_UnionDecl: + loadUnion(ctx, decl) + case lc.Cursor_LinkageSpec: // extern "C" { ... } + loadLinkageSpec(ctx, scope, decl) + case lc.Cursor_MacroExpansion, lc.Cursor_StaticAssert, lc.Cursor_UsingDeclaration: + // noop + case lc.Cursor_FunctionTemplate: + // TODO(xsw): ignore for now + case lc.Cursor_ClassTemplate, lc.Cursor_ClassTemplatePartialSpecialization: + loadTemplateClass(ctx, decl, nil) + case lc.Cursor_UnexposedDecl, lc.Cursor_UnexposedAttr: + // noop + default: + ctx.panicf(decl, "loadDecl: unknown kind - %v", decl.Kind) + } +} + +func loadNamespace(ctx *pkgCtx, scope *scopeCtx, namespace clang.Cursor) { + cName := cNameOf(namespace) + if ctx.isNSIgnored(cName) { + if debugCompileDecl { + ctx.logf(namespace, "namespace %s - ignored", cName) + } + return + } + clang.VisitChildren(namespace, func(decl, parent clang.Cursor) clang.ChildVisitResult { + loadDecl(ctx, scope, decl) + return clang.Continue + }) +} + +func loadLinkageSpec(ctx *pkgCtx, scope *scopeCtx, linkage clang.Cursor) { + clang.VisitChildren(linkage, func(decl, parent clang.Cursor) clang.ChildVisitResult { + loadDecl(ctx, scope, decl) + return clang.Continue + }) +} + // ----------------------------------------------------------------------------- diff --git a/cl/ctx.go b/cl/ctx.go index fbdece40..78393fb2 100644 --- a/cl/ctx.go +++ b/cl/ctx.go @@ -23,6 +23,7 @@ import ( "go/types" "log" "os" + "sort" "github.com/goplus/gogen" "github.com/goplus/lib/c" @@ -142,15 +143,14 @@ type pkgCtx struct { fileBases map[clang.File]int // clang.File => base - macroVals map[string]any // macroName => value - ovobjs map[string]*overloadObj // objUSR => overload object - types map[string]typeObj // c/c++ fullName => type name object (include external types) - typdecls map[string]typDecl // c/c++ fullName => type declaration object (only local types) - impPkgs map[string]none // imported package path set - lastSeen map[string]none // last seen include file set (loaded include files) - thisSeen map[string]none // include file set seen in this translation unit + macroVals map[string]any // macroName => value + fns map[string]*funcObj // fnUSR => func object + types map[string]typeObj // c/c++ fullName => type name object (include external types) + typdecls map[string]typDecl // c/c++ fullName => type declaration object (only local types) + impPkgs map[string]none // imported package path set + lastSeen map[string]none // last seen include file set (loaded include files) + thisSeen map[string]none // include file set seen in this translation unit - loads []compileUnit compiles []compileUnit pubs []Entry @@ -197,13 +197,6 @@ func (p *pkgCtx) getFileBase(c clang.Cursor, file clang.File) int { return base } -func (p *pkgCtx) addLoadUnit(f compileFunc) { - p.loads = append(p.loads, compileUnit{ - fn: f, - at: p.pkg.CurFile(), - }) -} - func (p *pkgCtx) addCompileUnit(f compileFunc) { p.compiles = append(p.compiles, compileUnit{ fn: f, @@ -212,27 +205,13 @@ func (p *pkgCtx) addCompileUnit(f compileFunc) { } func (p *pkgCtx) compile() { - doCompile(p, &p.loads) - if debugMajorProc { - log.Println("==> complete uninitialized type declarations") - } - pkg := p.pkg - for _, typDecl := range p.typdecls { - if typDecl.State() == gogen.TyStateUninited { - typDecl.InitType(pkg, types.NewStruct(nil, nil)) - } - } - doCompile(p, &p.compiles) -} - -func doCompile(p *pkgCtx, pcompiles *[]compileUnit) { pkg := p.pkg for { - compiles := *pcompiles + compiles := p.compiles if len(compiles) == 0 { break } - *pcompiles = nil + p.compiles = nil for _, c := range compiles { pkg.RestoreCurFile(c.at) c.fn(p) @@ -321,3 +300,185 @@ func (p *pkgCtx) isNSIgnored(cName string) bool { } // ----------------------------------------------------------------------------- + +type templateClass struct { + cName string // c/c++ full name + decl clang.Cursor // AST object + overloads *overloads +} + +// order returns the order of the template class in the overloads list. +// -1 means no order (only one overload, or not found). +func (p *templateClass) order() int { + items := p.overloads.classes + if len(items) > 1 { + for i, obj := range items { + if obj == p { + return i + } + } + } + return -1 +} + +type funcObj struct { + cName string // c/c++ full name + decl clang.Cursor // AST object + overloads *overloads + + isOperator bool +} + +// order returns the order of the object in the overloads list. +// -1 means no order (only one overload, or not found). +func (p *funcObj) order() int { + items := p.overloads.fns + if len(items) > 1 { + for i, obj := range items { + if obj == p { + return i + } + } + } + return -1 +} + +type overloads struct { + fns []*funcObj + classes []*templateClass +} + +func (p *overloads) reorder() { + items := p.fns + if len(items) > 1 { + sort.SliceStable(items, func(i, j int) bool { + a, b := items[i].decl, items[j].decl + na, nb := a.NumArguments(), b.NumArguments() + if na != nb { + return na < nb + } + for k := range c.Uint(na) { + ta, tb := a.Argument(k).Type(), b.Argument(k).Type() + if ret := cmpType(ta, tb); ret != 0 { + return ret < 0 + } + } + return false + }) + } +} + +func cloneTypeName(obj *types.TypeName) *types.TypeName { + return types.NewTypeName(obj.Pos(), obj.Pkg(), obj.Name(), obj.Type()) +} + +func cloneTypeParams(tparams []*types.TypeParam) []*types.TypeParam { + if len(tparams) == 0 { + return nil + } + ret := make([]*types.TypeParam, len(tparams)) + for i, tp := range tparams { + obj := cloneTypeName(tp.Obj()) + ret[i] = types.NewTypeParam(obj, tp.Constraint()) + } + return ret +} + +func concatTypeParams(a, b []*types.TypeParam) []*types.TypeParam { + if len(a) == 0 { + return b + } + a = cloneTypeParams(a) + if len(b) == 0 { + return a + } + ret := make([]*types.TypeParam, 0, len(a)+len(b)) + ret = append(ret, a...) + return append(ret, b...) +} + +type scopeCtx struct { + overloads map[string]*overloads // name => overload items + tparams []*types.TypeParam // type parameters, only for class/struct scope + parent *scopeCtx +} + +func (p *scopeCtx) typeParams(in []*types.TypeParam) []*types.TypeParam { + for p != nil { + in = concatTypeParams(p.tparams, in) + p = p.parent + } + return in +} + +func (p *scopeCtx) lookupType(name string) (types.Type, bool) { + for p != nil { + for _, t := range p.tparams { + if t.Obj().Name() == name { + return t, true + } + } + p = p.parent + } + return nil, false +} + +func (p *scopeCtx) addTemplateClass(ctx *pkgCtx, decl clang.Cursor) (*templateClass, bool) { + cName := cNameOf(decl) + if debugCompileDecl { + ctx.logf(decl, "==> addTemplateClass %s", cName) + } + // TODO(xsw): check if the class is already added + obj := &templateClass{ + cName: cName, + decl: decl, + } + ovs, ok := p.overloads[cName] + if ok { + ovs.classes = append(ovs.classes, obj) + } else { + ovs = &overloads{classes: []*templateClass{obj}} + p.overloads[cName] = ovs + } + obj.overloads = ovs + return obj, true +} + +func (p *scopeCtx) addFunc(ctx *pkgCtx, cName string, decl clang.Cursor, isOp bool) (*funcObj, bool) { + fnUSR := funcUSR(decl) + if debugCompileDecl { + ctx.logf(decl, "==> addFunc %s - USR: %s", cName, fnUSR) + } + + if fn, ok := ctx.fns[fnUSR]; ok { // re-declared + if decl.IsFunctionInlined() != 0 { + fn.decl = decl // use the latest inline decl + } + return fn, false + } + + obj := &funcObj{ + cName: cName, + decl: decl, + isOperator: isOp, + } + ovs, ok := p.overloads[cName] + if ok { + ovs.fns = append(ovs.fns, obj) + } else { + ovs = &overloads{fns: []*funcObj{obj}} + p.overloads[cName] = ovs + } + obj.overloads = ovs + ctx.fns[fnUSR] = obj + + return obj, true +} + +func (p *scopeCtx) reorder() { + for _, o := range p.overloads { + o.reorder() + } +} + +// ----------------------------------------------------------------------------- diff --git a/cl/func.go b/cl/func.go index fc338195..28e75a9e 100644 --- a/cl/func.go +++ b/cl/func.go @@ -24,9 +24,8 @@ import ( "github.com/goplus/lib/c" "github.com/goplus/llcppg/clang" - "github.com/qiniu/x/ctype" - lc "github.com/llarhub/clang-c" + "github.com/qiniu/x/ctype" ) // ----------------------------------------------------------------------------- @@ -41,16 +40,22 @@ func isOperator(baseName string) bool { return false } -// ----------------------------------------------------------------------------- - -func loadGlobalFunc(ctx *pkgCtx, obj *overloadObj) { - ctx.addCompileUnit(func(ctx *pkgCtx) { - compileFuncOrMethod(ctx, obj, nil) - }) +func loadGlobalFunc(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor) { + var baseName = clang.String(decl) + var name string + var isOp = isOperator(baseName) + if isOp { + name = baseName[len(operatorPrefix):] + } else { + name = cNameOf(decl) + } + if obj, ok := scope.addFunc(ctx, name, decl, isOp); ok { + ctx.addCompileUnit(func(ctx *pkgCtx) { + compileFuncOrMethod(ctx, obj, nil) + }) + } } -// ----------------------------------------------------------------------------- - // compileFuncOrMethod compiles a C/C++ function or method into a Go function. // // When cls is nil, it is compiled as a receiver-less global function with a @@ -58,11 +63,10 @@ func loadGlobalFunc(ctx *pkgCtx, obj *overloadObj) { // has no implicit "this", so it is loaded as a global function (its Go name is // prefixed by the enclosing class name, which acts like a namespace). When cls // is non-nil, it is an instance method compiled with a "this" receiver. -func compileFuncOrMethod(ctx *pkgCtx, obj *overloadObj, this *classCtx) { +func compileFuncOrMethod(ctx *pkgCtx, obj *funcObj, this *classCtx) { fn := obj.decl - cName := cNameOf(fn) - name := obj.name - isOp := isOperator(name) + cName := obj.cName + isOp := obj.isOperator if debugCompileDecl { fnType := clang.String(fn.Type()) ctx.logf(fn, "func %s: %s - isOp: %v", cName, fnType, isOp) @@ -121,15 +125,13 @@ func compileFuncOrMethod(ctx *pkgCtx, obj *overloadObj, this *classCtx) { recv = types.NewParam(goNodePos(ctx, fn), pkgTypes, "this", types.NewPointer(typNamed)) typName = typNamed.Obj().Name() } - - fnName := ctx.funcName(name, obj.order(), typName, typCName, this == nil, true) - + fnName := ctx.funcName(cName, obj.order(), typName, typCName, this == nil, true) if recv == nil { nameInPkg = fnName } else { if typRecv != nil { if existMember(typRecv, fnName) { - newName := ctx.funcName(name, obj.order(), "", typCName, true, true) + newName := ctx.funcName(cName, obj.order(), "", typCName, true, true) log.Printf("==> member %s.%s already exists, rename to %s\n", typName, fnName, newName) fnName = newName } diff --git a/cl/name.go b/cl/name.go index f471722d..0c4d93ef 100644 --- a/cl/name.go +++ b/cl/name.go @@ -37,7 +37,7 @@ func (p *pkgCtx) nextAnonName() string { return name } -func objUSR(decl clang.Cursor) string { +func funcUSR(decl clang.Cursor) string { return clang.USR(decl) } diff --git a/cl/preload.go b/cl/preload.go deleted file mode 100644 index 3ed06860..00000000 --- a/cl/preload.go +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cl - -import ( - "go/types" - "sort" - - "github.com/goplus/lib/c" - "github.com/goplus/llcppg/clang" - lc "github.com/llarhub/clang-c" -) - -func cloneTypeName(obj *types.TypeName) *types.TypeName { - return types.NewTypeName(obj.Pos(), obj.Pkg(), obj.Name(), obj.Type()) -} - -func cloneTypeParams(tparams []*types.TypeParam) []*types.TypeParam { - if len(tparams) == 0 { - return nil - } - ret := make([]*types.TypeParam, len(tparams)) - for i, tp := range tparams { - obj := cloneTypeName(tp.Obj()) - ret[i] = types.NewTypeParam(obj, tp.Constraint()) - } - return ret -} - -func concatTypeParams(a, b []*types.TypeParam) []*types.TypeParam { - if len(a) == 0 { - return b - } - a = cloneTypeParams(a) - if len(b) == 0 { - return a - } - ret := make([]*types.TypeParam, 0, len(a)+len(b)) - ret = append(ret, a...) - return append(ret, b...) -} - -// ----------------------------------------------------------------------------- - -type scopeCtx struct { - overloads map[string]*overloads // cName => overload items - tparams []*types.TypeParam // type parameters, only for class/struct scope - parent *scopeCtx -} - -func (p *scopeCtx) typeParams(in []*types.TypeParam) []*types.TypeParam { - for p != nil { - in = concatTypeParams(p.tparams, in) - p = p.parent - } - return in -} - -func (p *scopeCtx) lookupType(name string) (types.Type, bool) { - for p != nil { - for _, t := range p.tparams { - if t.Obj().Name() == name { - return t, true - } - } - p = p.parent - } - return nil, false -} - -func (p *scopeCtx) addOveerloadObj(ctx *pkgCtx, name string, decl clang.Cursor) (obj *overloadObj, isNew bool) { - oUSR := objUSR(decl) - if debugCompileDecl { - ctx.logf(decl, "==> addOveerloadObj %s - USR: %s", name, oUSR) - } - - obj, isOld := ctx.ovobjs[oUSR] - if !isOld { - isNew = true - obj = &overloadObj{ - name: name, - decl: decl, - } - ovs, ok := p.overloads[name] - if ok { - ovs.items = append(ovs.items, obj) - } else { - ovs = &overloads{items: []*overloadObj{obj}} - p.overloads[name] = ovs - } - obj.overloads = ovs - ctx.ovobjs[oUSR] = obj - } - if decl.IsCursorDefinition() != 0 { // TODO(xsw): redefinition - obj.decl = decl // use the last definition - } - return -} - -func (p *scopeCtx) reorder() { - for _, o := range p.overloads { - o.reorder() - } -} - -// ----------------------------------------------------------------------------- - -type overloadObj struct { - name string // local name in scope - decl clang.Cursor // AST object - overloads *overloads -} - -// order returns the order of the template class in the overloads list. -// -1 means no order (only one overload, or not found). -func (p *overloadObj) order() int { - ovs := p.overloads - if ovs == nil { - return -1 - } - items := ovs.items - if len(items) > 1 { - for i, obj := range items { - if obj == p { - return i - } - } - } - return -1 -} - -type overloads struct { - items []*overloadObj -} - -func (p *overloads) reorder() { - items := p.items - if len(items) > 1 { - sort.SliceStable(items, func(i, j int) bool { - a, b := items[i].decl, items[j].decl - na, nb := a.NumArguments(), b.NumArguments() - if na != nb { - return na < nb - } - for k := range c.Uint(na) { - ta, tb := a.Argument(k).Type(), b.Argument(k).Type() - if ret := cmpType(ta, tb); ret != 0 { - return ret < 0 - } - } - return false - }) - } -} - -// ----------------------------------------------------------------------------- - -func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor) { - switch decl.Kind { - case lc.Cursor_ClassDecl, lc.Cursor_StructDecl: - preloadClass(ctx, scope, decl) - case lc.Cursor_FunctionDecl: - preloadGlobalFunc(ctx, scope, decl) - case lc.Cursor_CXXMethod, lc.Cursor_Constructor, lc.Cursor_Destructor: - ctx.addLoadUnit(func(ctx *pkgCtx) { - loadOutsideMethod(ctx, decl) - }) - case lc.Cursor_TypedefDecl, lc.Cursor_TypeAliasDecl, lc.Cursor_TypeAliasTemplateDecl: - ctx.addLoadUnit(func(ctx *pkgCtx) { - loadTypedef(ctx, decl, nil) - }) - case lc.Cursor_EnumDecl: - loadEnum(ctx, decl) - case lc.Cursor_MacroDefinition: - loadMacro(ctx, decl) - case lc.Cursor_InclusionDirective: - loadInclude(ctx, decl) - case lc.Cursor_Namespace: - loadNamespace(ctx, scope, decl) - case lc.Cursor_VarDecl: - ctx.addLoadUnit(func(ctx *pkgCtx) { - loadVar(ctx, decl) - }) - case lc.Cursor_UnionDecl: - ctx.addLoadUnit(func(ctx *pkgCtx) { - loadUnion(ctx, decl) - }) - case lc.Cursor_LinkageSpec: // extern "C" { ... } - loadLinkageSpec(ctx, scope, decl) - case lc.Cursor_MacroExpansion, lc.Cursor_StaticAssert, lc.Cursor_UsingDeclaration: - // noop - case lc.Cursor_FunctionTemplate: - // TODO(xsw): - case lc.Cursor_ClassTemplate, lc.Cursor_ClassTemplatePartialSpecialization: - preloadTemplateClass(ctx, scope, decl) - case lc.Cursor_UnexposedDecl, lc.Cursor_UnexposedAttr: - // noop - default: - ctx.panicf(decl, "loadDecl: unknown kind - %v", decl.Kind) - } -} - -func loadNamespace(ctx *pkgCtx, scope *scopeCtx, namespace clang.Cursor) { - cName := cNameOf(namespace) - if ctx.isNSIgnored(cName) { - if debugCompileDecl { - ctx.logf(namespace, "namespace %s - ignored", cName) - } - return - } - clang.VisitChildren(namespace, func(decl, parent clang.Cursor) clang.ChildVisitResult { - loadDecl(ctx, scope, decl) - return clang.Continue - }) -} - -func loadLinkageSpec(ctx *pkgCtx, scope *scopeCtx, linkage clang.Cursor) { - clang.VisitChildren(linkage, func(decl, parent clang.Cursor) clang.ChildVisitResult { - loadDecl(ctx, scope, decl) - return clang.Continue - }) -} - -func loadOutsideMethod(ctx *pkgCtx, outsideDecl clang.Cursor) { - fnUSR := objUSR(outsideDecl) - if m, ok := ctx.ovobjs[fnUSR]; ok { - // TODO(xsw): check another definition of the same method - m.decl = outsideDecl - } else { - ctx.ignoref(featExplicitIgnore, outsideDecl, "[WARN] method undeclared - %s", cNameOf(outsideDecl)) - } -} - -func newClassCtx(ctx *pkgCtx, cls clang.Cursor, parent *scopeCtx) *classCtx { - if cls.IsCursorDefinition() == 0 { - return nil // not a definition - } - this := &classCtx{ - decl: cls, - overloads: make(map[string]*overloads), - parent: parent, - } - clang.VisitChildren(cls, func(decl, parent clang.Cursor) clang.ChildVisitResult { - switch decl.Kind { - case lc.Cursor_CXXMethod, lc.Cursor_FunctionTemplate, - lc.Cursor_Constructor, lc.Cursor_Destructor, lc.Cursor_ConversionFunction: - if !isPublic(decl) { - break - } - var name string - switch decl.Kind { - case lc.Cursor_Constructor: - name = "XGo_Ctor" - case lc.Cursor_Destructor: - name = "XGo_Dtor" - default: - if decl.CXXMethodIsStatic() != 0 { - name = cNameOf(decl) // static method name - } else { - name = clang.String(decl) // method name - } - } - if decl.CXXMethodIsStatic() != 0 { - preloadGlobalFunc(ctx, &ctx.scopeCtx, decl) - break - } - fn, isNew := this.addOveerloadObj(ctx, name, decl) - if isNew { - this.publicMethods = append(this.publicMethods, fn) - } - } - return clang.Continue - }) - return this -} - -func isPublic(decl clang.Cursor) bool { - return decl.CXXAccessSpecifier() == lc.CXXPublic -} - -func preloadClass(ctx *pkgCtx, scope *scopeCtx, cls clang.Cursor) { - cName := cNameOf(cls) - if cls.NumTemplateArguments() >= 0 { // note: -1 means not a template class - scope.addOveerloadObj(ctx, cName, cls) - return - } - this := newClassCtx(ctx, cls, scope) - ctx.addLoadUnit(func(ctx *pkgCtx) { - loadClass(ctx, cName, this, cls) - }) -} - -func preloadTemplateClass(ctx *pkgCtx, scope *scopeCtx, cls clang.Cursor) { - cName := cNameOf(cls) - obj, isNew := scope.addOveerloadObj(ctx, cName, cls) - if isNew { - ctx.addLoadUnit(func(ctx *pkgCtx) { - this := newClassCtx(ctx, obj.decl, scope) - loadTemplateClass(ctx, cName, this, obj) - }) - } -} - -func preloadGlobalFunc(ctx *pkgCtx, scope *scopeCtx, fn clang.Cursor) { - cName := cNameOf(fn) - obj, isNew := scope.addOveerloadObj(ctx, cName, fn) - if isNew { - ctx.addLoadUnit(func(ctx *pkgCtx) { - loadGlobalFunc(ctx, obj) - }) - } -} - -// ----------------------------------------------------------------------------- diff --git a/cl/type.go b/cl/type.go index b5268289..6c9ebf49 100644 --- a/cl/type.go +++ b/cl/type.go @@ -163,20 +163,14 @@ func toTypeEx(ctx *pkgCtx, pkg *types.Package, typ lc.Type, flags int, feats *in if t, ok := scope.lookupType(name); ok { return t } - name = cTypeName(typ) - if o, ok := ctx.getTypeObj(name, feats); ok { - return o.Type() - } case lc.Type_LongDouble: return ctx.basicTyp(cLongDouble) case lc.Type_BlockPointer: *feats |= featQuietIgnore // will always be ignored return types.Typ[types.Invalid] } - if *feats&featQuietIgnore == 0 { - ctx.logtf(typ, "toType: unsupported type - %s (%d: %s)", cTypeName(typ), typ.Kind, clang.String(typ)) - *feats |= featExplicitIgnore - } + ctx.logtf(typ, "toType: unsupported type - %s (%d: %s)", cTypeName(typ), typ.Kind, clang.String(typ)) + *feats |= featExplicitIgnore return types.Typ[types.Invalid] } diff --git a/cl/vtable.go b/cl/vtable.go index 16789a97..f2571ec0 100644 --- a/cl/vtable.go +++ b/cl/vtable.go @@ -348,9 +348,9 @@ func overriddenRoots(m clang.Cursor) []clang.Cursor { } func vtableMethodName(ctx *pkgCtx, m clang.Cursor) string { - fnUSR := objUSR(m) - if fn, ok := ctx.ovobjs[fnUSR]; ok { - return ctx.funcName(fn.name, fn.order(), "", "", false, true) + fnUSR := funcUSR(m) + if fn, ok := ctx.fns[fnUSR]; ok { + return ctx.funcName(fn.cName, fn.order(), "", "", false, true) } panic("vtableMethodName: method not found - " + cNameOf(m)) } diff --git a/tool/_testc/clang-c-22.1.8/CXCompilationDatabase.go b/tool/_testc/clang-c-22.1.8/CXCompilationDatabase.go index 494b362a..6716a206 100644 --- a/tool/_testc/clang-c-22.1.8/CXCompilationDatabase.go +++ b/tool/_testc/clang-c-22.1.8/CXCompilationDatabase.go @@ -7,14 +7,6 @@ import ( _ "unsafe" ) -// Error codes for Compilation Database -type CompilationDatabase_Error c.Uint - -const ( - CompilationDatabase_NoError CompilationDatabase_Error = 0 - CompilationDatabase_CanNotLoadDatabase CompilationDatabase_Error = 1 -) - // A compilation database holds all information used to compile files in a // project. For each file in the database, it can be queried for the working // directory or the command line used for the compiler invocation. @@ -34,6 +26,14 @@ type CompileCommands uintptr // Represents the command line invocation to compile a specific file. type CompileCommand uintptr +// Error codes for Compilation Database +type CompilationDatabase_Error c.Uint + +const ( + CompilationDatabase_NoError CompilationDatabase_Error = 0 + CompilationDatabase_CanNotLoadDatabase CompilationDatabase_Error = 1 +) + // Creates a compilation database from the database found in directory // buildDir. For example, CMake can output a compile_commands.json which can // be used to build the database. diff --git a/tool/_testc/clang-c-22.1.8/CXCompilationDatabase/out.go b/tool/_testc/clang-c-22.1.8/CXCompilationDatabase/out.go index 7e4552e3..cf6186f0 100644 --- a/tool/_testc/clang-c-22.1.8/CXCompilationDatabase/out.go +++ b/tool/_testc/clang-c-22.1.8/CXCompilationDatabase/out.go @@ -8,14 +8,6 @@ import ( const LLGoPackage = "link: -L$(llvm-config --libdir) -lclang; -lclang" -// Error codes for Compilation Database -type CompilationDatabase_Error c.Uint - -const ( - CompilationDatabase_NoError CompilationDatabase_Error = 0 - CompilationDatabase_CanNotLoadDatabase CompilationDatabase_Error = 1 -) - // A compilation database holds all information used to compile files in a // project. For each file in the database, it can be queried for the working // directory or the command line used for the compiler invocation. @@ -35,6 +27,14 @@ type CompileCommands uintptr // Represents the command line invocation to compile a specific file. type CompileCommand uintptr +// Error codes for Compilation Database +type CompilationDatabase_Error c.Uint + +const ( + CompilationDatabase_NoError CompilationDatabase_Error = 0 + CompilationDatabase_CanNotLoadDatabase CompilationDatabase_Error = 1 +) + // Creates a compilation database from the database found in directory // buildDir. For example, CMake can output a compile_commands.json which can // be used to build the database. diff --git a/tool/_testc/clang-c-22.1.8/CXDiagnostic.go b/tool/_testc/clang-c-22.1.8/CXDiagnostic.go index 7af1dcaa..74c2803f 100644 --- a/tool/_testc/clang-c-22.1.8/CXDiagnostic.go +++ b/tool/_testc/clang-c-22.1.8/CXDiagnostic.go @@ -28,6 +28,13 @@ const ( Diagnostic_Fatal DiagnosticSeverity = 4 ) +// A single diagnostic, containing the diagnostic's severity, +// location, text, source ranges, and fix-it hints. +type Diagnostic uintptr + +// A group of CXDiagnostics. +type DiagnosticSet uintptr + // Describes the kind of error that occurred (if any) in a call to // \c clang_loadDiagnostics. type LoadDiag_Error c.Uint @@ -97,13 +104,6 @@ const ( Diagnostic_DisplayCategoryName DiagnosticDisplayOptions = 32 ) -// A single diagnostic, containing the diagnostic's severity, -// location, text, source ranges, and fix-it hints. -type Diagnostic uintptr - -// A group of CXDiagnostics. -type DiagnosticSet uintptr - // Determine the number of diagnostics in a CXDiagnosticSet. // // llgo:link DiagnosticSet.NumDiagnosticsInSet C.clang_getNumDiagnosticsInSet diff --git a/tool/_testc/clang-c-22.1.8/CXDiagnostic/out.go b/tool/_testc/clang-c-22.1.8/CXDiagnostic/out.go index 5b92bbe8..83da3c75 100644 --- a/tool/_testc/clang-c-22.1.8/CXDiagnostic/out.go +++ b/tool/_testc/clang-c-22.1.8/CXDiagnostic/out.go @@ -30,6 +30,13 @@ const ( Diagnostic_Fatal DiagnosticSeverity = 4 ) +// A single diagnostic, containing the diagnostic's severity, +// location, text, source ranges, and fix-it hints. +type Diagnostic uintptr + +// A group of CXDiagnostics. +type DiagnosticSet uintptr + // Describes the kind of error that occurred (if any) in a call to // \c clang_loadDiagnostics. type LoadDiag_Error c.Uint @@ -99,13 +106,6 @@ const ( Diagnostic_DisplayCategoryName DiagnosticDisplayOptions = 32 ) -// A single diagnostic, containing the diagnostic's severity, -// location, text, source ranges, and fix-it hints. -type Diagnostic uintptr - -// A group of CXDiagnostics. -type DiagnosticSet uintptr - // Determine the number of diagnostics in a CXDiagnosticSet. // // llgo:link DiagnosticSet.NumDiagnosticsInSet C.clang_getNumDiagnosticsInSet diff --git a/tool/_testc/clang-c-22.1.8/Documentation.go b/tool/_testc/clang-c-22.1.8/Documentation.go index ce8c15f0..df893477 100644 --- a/tool/_testc/clang-c-22.1.8/Documentation.go +++ b/tool/_testc/clang-c-22.1.8/Documentation.go @@ -7,6 +7,12 @@ import ( "unsafe" ) +// A parsed comment. +type Comment struct { + ASTNode unsafe.Pointer + TranslationUnit TranslationUnit +} + // Describes the type of the comment AST node (\c CXComment). A comment // node can be considered block content (e. g., paragraph), inline content // (plain text) or neither (the root AST node). @@ -111,11 +117,6 @@ const ( CommentParamPassDirection_InOut CommentParamPassDirection = 2 ) -// A parsed comment. -type Comment struct { - ASTNode unsafe.Pointer - TranslationUnit TranslationUnit -} type APISetImpl struct { } diff --git a/tool/_testc/clang-c-22.1.8/Documentation/out.go b/tool/_testc/clang-c-22.1.8/Documentation/out.go index 5535674c..91e289bb 100644 --- a/tool/_testc/clang-c-22.1.8/Documentation/out.go +++ b/tool/_testc/clang-c-22.1.8/Documentation/out.go @@ -10,6 +10,12 @@ import ( const LLGoPackage = "link: -L$(llvm-config --libdir) -lclang; -lclang" +// A parsed comment. +type Comment struct { + ASTNode unsafe.Pointer + TranslationUnit Index.TranslationUnit +} + // Describes the type of the comment AST node (\c CXComment). A comment // node can be considered block content (e. g., paragraph), inline content // (plain text) or neither (the root AST node). @@ -114,11 +120,6 @@ const ( CommentParamPassDirection_InOut CommentParamPassDirection = 2 ) -// A parsed comment. -type Comment struct { - ASTNode unsafe.Pointer - TranslationUnit Index.TranslationUnit -} type APISetImpl struct { } diff --git a/tool/_testc/clang-c-22.1.8/Index.go b/tool/_testc/clang-c-22.1.8/Index.go index ebdade2b..e6d0af8a 100644 --- a/tool/_testc/clang-c-22.1.8/Index.go +++ b/tool/_testc/clang-c-22.1.8/Index.go @@ -10,6 +10,36 @@ import ( const CINDEX_VERSION_MAJOR = 0 const CINDEX_VERSION_MINOR = 64 +// An "index" that consists of a set of translation units that would +// typically be linked together into an executable or library. +type Index uintptr +type TargetInfoImpl struct { +} + +// An opaque type representing target information for a given translation +// unit. +type TargetInfo = *TargetInfoImpl +type TranslationUnitImpl struct { +} + +// A single translation unit, which resides in an index. +type TranslationUnit = *TranslationUnitImpl + +// Opaque pointer representing client data that will be passed through +// to various callbacks and visitors. +type ClientData = unsafe.Pointer + +// Provides the contents of a file that has not yet been saved to disk. +// +// Each CXUnsavedFile instance provides the name of a file on the +// system along with the current contents of that file that have not +// yet been saved to disk. +type UnsavedFile struct { + Filename *c.Char + Contents *c.Char + Length c.Ulong +} + // Describes the availability of a particular entity, which indicates // whether the use of this entity will result in a warning or error due to // it being deprecated or unavailable. @@ -28,6 +58,13 @@ const ( Availability_NotAccessible AvailabilityKind = 3 ) +// Describes a version number of the form major.minor.subminor. +type Version struct { + Major c.Int + Minor c.Int + Subminor c.Int +} + // Describes the exception specification of a cursor. // // A negative value indicates that the cursor is not a function declaration. @@ -90,6 +127,37 @@ const ( GlobalOpt_ThreadBackgroundPriorityForAll GlobalOptFlags = 3 ) +// Index initialization options. +// +// 0 is the default value of each member of this struct except for Size. +// Initialize the struct in one of the following three ways to avoid adapting +// code each time a new member is added to it: +// \code +// CXIndexOptions Opts; +// memset(&Opts, 0, sizeof(Opts)); +// Opts.Size = sizeof(CXIndexOptions); +// \endcode +// or explicitly initialize the first data member and zero-initialize the rest: +// \code +// CXIndexOptions Opts = { sizeof(CXIndexOptions) }; +// \endcode +// or to prevent the -Wmissing-field-initializers warning for the above version: +// \code +// CXIndexOptions Opts{}; +// Opts.Size = sizeof(CXIndexOptions); +// \endcode +type IndexOptions struct { + Size c.Uint + ThreadBackgroundPriorityForIndexing uint8 + ThreadBackgroundPriorityForEditing uint8 + ExcludeDeclarationsFromPCH c.Uint + DisplayDiagnostics c.Uint + StorePreamblesInMemory c.Uint + X c.Uint + PreambleStoragePath *c.Char + InvocationEmissionPath *c.Char +} + // Flags that control the creation of translation units. // // The enumerators in this enumeration type are meant to be bitwise @@ -266,6 +334,18 @@ const ( TUResourceUsage_Last TUResourceUsageKind = 14 ) +type TUResourceUsageEntry struct { + Kind TUResourceUsageKind + Amount c.Ulong +} + +// The memory usage of a CXTranslationUnit, broken into categories. +type TUResourceUsage struct { + Data unsafe.Pointer + NumEntries c.Uint + Entries *TUResourceUsageEntry +} + // Describes the kind of entity that a cursor refers to. type CursorKind c.Uint @@ -1109,6 +1189,28 @@ const ( Cursor_OverloadCandidate CursorKind = 700 ) +// A cursor representing some element in the abstract syntax tree for +// a translation unit. +// +// The cursor abstraction unifies the different kinds of entities in a +// program--declaration, statements, expressions, references to declarations, +// etc.--under a single "cursor" abstraction with a common set of operations. +// Common operation for a cursor include: getting the physical location in +// a source file where the cursor points, getting the name associated with a +// cursor, and retrieving cursors for any child nodes of a particular cursor. +// +// Cursors can be produced in two specific ways. +// clang_getTranslationUnitCursor() produces a cursor for a translation unit, +// from which one can use clang_visitChildren() to explore the rest of the +// translation unit. clang_getCursor() maps from a physical source location +// to the entity that resides at that location, allowing one to map from the +// source code into the AST. +type Cursor struct { + Kind CursorKind + Xdata c.Int + Data [3]unsafe.Pointer +} + // Describe the linkage of the entity referred to by a cursor. type LinkageKind c.Uint @@ -1142,6 +1244,17 @@ const ( Visibility_Default VisibilityKind = 3 ) +// Describes the availability of a given entity on a particular platform, e.g., +// a particular class might only be available on Mac OS 10.7 or newer. +type PlatformAvailability struct { + Platform String + Introduced Version + Deprecated Version + Obsoleted Version + Unavailable c.Int + Message String +} + // Describe the "language" of the entity referred to by a cursor. type LanguageKind c.Uint @@ -1162,6 +1275,12 @@ const ( TLS_Static TLSKind = 2 ) +type CursorSetImpl struct { +} + +// A fast container representing a set of CXCursors. +type CursorSet = *CursorSetImpl + // Describes the kind of type type TypeKind c.Uint @@ -1664,6 +1783,12 @@ const ( CallingConv_Unexposed CallingConv = 200 ) +// The type of an element in the abstract syntax tree. +type Type struct { + Kind TypeKind + Data [2]unsafe.Pointer +} + // Describes the kind of a template argument. // // See the definition of llvm::clang::TemplateArgument::ArgKind for full @@ -1823,6 +1948,24 @@ const ( ChildVisit_Recurse ChildVisitResult = 2 ) +// Visitor invoked for each cursor found by a traversal. +// +// This visitor function will be invoked for each cursor found by +// clang_visitCursorChildren(). Its first argument is the cursor being +// visited, its second argument is the parent visitor for that cursor, +// and its third argument is the client data provided to +// clang_visitCursorChildren(). +// +// The visitor should return one of the \c CXChildVisitResult values +// to direct clang_visitCursorChildren(). +// +// llgo:type C +type CursorVisitor = func(_llcppg_param1 Cursor, _llcppg_param2 Cursor, _llcppg_param3 ClientData) ChildVisitResult + +// Opaque pointer representing a policy that controls pretty printing +// for \c clang_getCursorPrettyPrinted. +type PrintingPolicy uintptr + // Properties for the printing policy. // // See \c clang::PrintingPolicy for more information. @@ -1892,6 +2035,12 @@ const ( ObjCDeclQualifier_Oneway ObjCDeclQualifierKind = 32 ) +// \defgroup CINDEX_MODULE Module introspection +// +// The functions in this group provide access to information about modules. +// +// @{ +type Module uintptr type NameRefFlags c.Uint const ( @@ -1928,6 +2077,31 @@ const ( Token_Comment TokenKind = 4 ) +// Describes a single preprocessing token. +type Token struct { + IntData [4]c.Uint + PtrData unsafe.Pointer +} + +// A semantic string that describes a code-completion result. +// +// A semantic string that describes the formatting of a code-completion +// result as a single "template" of text that should be inserted into the +// source buffer when a particular code-completion result is selected. +// Each semantic string is made up of some number of "chunks", each of which +// contains some text along with a description of what that text means, e.g., +// the name of the entity being referenced, whether the text chunk is part of +// the template, or whether it is a "placeholder" that the user should replace +// with actual code,of a specific kind. See \c CXCompletionChunkKind for a +// description of the different kinds of chunks. +type CompletionString uintptr + +// A single result of code completion. +type CompletionResult struct { + CursorKind CursorKind + CompletionString CompletionString +} + // Describes a single piece of text within a code-completion string. // // Each "chunk" within a code-completion string (\c CXCompletionString) is @@ -2057,6 +2231,16 @@ const ( CompletionChunk_VerticalSpace CompletionChunkKind = 20 ) +// Contains the results of code-completion. +// +// This data structure contains the results of code completion, as +// produced by \c clang_codeCompleteAt(). Its contents must be freed by +// \c clang_disposeCodeCompleteResults. +type CodeCompleteResults struct { + Results *CompletionResult + NumResults c.Uint +} + // Flags that can be passed to \c clang_codeCompleteAt() to // modify its behavior. // @@ -2159,6 +2343,18 @@ const ( CompletionContext_Unknown CompletionContext = 8388607 ) +// Visitor invoked for each file in a translation unit +// (used with clang_getInclusions()). +// +// This visitor function will be invoked by clang_getInclusions() for each +// file included (either at the top-level or by \#include directives) within +// a translation unit. The first argument is the file being included, and +// the second and third arguments provide the inclusion stack. The +// array is sorted in order of immediate inclusion. For example, +// the first element refers to the location that included 'included_file'. +// +// llgo:type C +type InclusionVisitor = func(_llcppg_param1 File, _llcppg_param2 *SourceLocation, _llcppg_param3 c.Uint, _llcppg_param4 ClientData) type EvalResultKind c.Uint const ( @@ -2171,6 +2367,9 @@ const ( Eval_UnExposed EvalResultKind = 0 ) +// Evaluation result of a cursor +type EvalResult uintptr + // \defgroup CINDEX_HIGH Higher level API functions // // @{ @@ -2181,6 +2380,10 @@ const ( Visit_Continue VisitorResult = 1 ) +type CursorAndRangeVisitor struct { + Context unsafe.Pointer + Visit func(_llcppg_param1 unsafe.Pointer, _llcppg_param2 Cursor, _llcppg_param3 SourceRange) VisitorResult +} type Result c.Uint const ( @@ -2193,6 +2396,43 @@ const ( Result_VisitBreak Result = 2 ) +// The client's data object that is associated with a CXFile. +type IdxClientFile uintptr + +// The client's data object that is associated with a semantic entity. +type IdxClientEntity uintptr + +// The client's data object that is associated with a semantic container +// of entities. +type IdxClientContainer uintptr + +// The client's data object that is associated with an AST file (PCH +// or module). +type IdxClientASTFile uintptr + +// Source location passed to index callbacks. +type IdxLoc struct { + PtrData [2]unsafe.Pointer + IntData c.Uint +} + +// Data for ppIncludedFile callback. +type IdxIncludedFileInfo struct { + HashLoc IdxLoc + Filename *c.Char + File File + IsImport c.Int + IsAngled c.Int + IsModuleImport c.Int +} + +// Data for IndexerCallbacks#importedASTFile. +type IdxImportedASTFileInfo struct { + File File + Module Module + Loc IdxLoc + IsImplicit c.Int +} type IdxEntityKind c.Uint const ( @@ -2262,22 +2502,102 @@ const ( IdxAttr_IBOutletCollection IdxAttrKind = 3 ) -type IdxDeclInfoFlags c.Uint - -const IdxDeclFlag_Skipped IdxDeclInfoFlags = 1 - -type IdxObjCContainerKind c.Uint - -const ( - IdxObjCContainer_ForwardRef IdxObjCContainerKind = 0 - IdxObjCContainer_Interface IdxObjCContainerKind = 1 - IdxObjCContainer_Implementation IdxObjCContainerKind = 2 -) - -// Data for IndexerCallbacks#indexEntityReference. -// -// This may be deprecated in a future version as this duplicates -// the \c CXSymbolRole_Implicit bit in \c CXSymbolRole. +type IdxAttrInfo struct { + Kind IdxAttrKind + Cursor Cursor + Loc IdxLoc +} +type IdxEntityInfo struct { + Kind IdxEntityKind + TemplateKind IdxEntityCXXTemplateKind + Lang IdxEntityLanguage + Name *c.Char + USR *c.Char + Cursor Cursor + Attributes **IdxAttrInfo + NumAttributes c.Uint +} +type IdxContainerInfo struct { + Cursor Cursor +} +type IdxIBOutletCollectionAttrInfo struct { + AttrInfo *IdxAttrInfo + ObjcClass *IdxEntityInfo + ClassCursor Cursor + ClassLoc IdxLoc +} +type IdxDeclInfoFlags c.Uint + +const IdxDeclFlag_Skipped IdxDeclInfoFlags = 1 + +type IdxDeclInfo struct { + EntityInfo *IdxEntityInfo + Cursor Cursor + Loc IdxLoc + SemanticContainer *IdxContainerInfo + LexicalContainer *IdxContainerInfo + IsRedeclaration c.Int + IsDefinition c.Int + IsContainer c.Int + DeclAsContainer *IdxContainerInfo + IsImplicit c.Int + Attributes **IdxAttrInfo + NumAttributes c.Uint + Flags c.Uint +} +type IdxObjCContainerKind c.Uint + +const ( + IdxObjCContainer_ForwardRef IdxObjCContainerKind = 0 + IdxObjCContainer_Interface IdxObjCContainerKind = 1 + IdxObjCContainer_Implementation IdxObjCContainerKind = 2 +) + +type IdxObjCContainerDeclInfo struct { + DeclInfo *IdxDeclInfo + Kind IdxObjCContainerKind +} +type IdxBaseClassInfo struct { + Base *IdxEntityInfo + Cursor Cursor + Loc IdxLoc +} +type IdxObjCProtocolRefInfo struct { + Protocol *IdxEntityInfo + Cursor Cursor + Loc IdxLoc +} +type IdxObjCProtocolRefListInfo struct { + Protocols **IdxObjCProtocolRefInfo + NumProtocols c.Uint +} +type IdxObjCInterfaceDeclInfo struct { + ContainerInfo *IdxObjCContainerDeclInfo + SuperInfo *IdxBaseClassInfo + Protocols *IdxObjCProtocolRefListInfo +} +type IdxObjCCategoryDeclInfo struct { + ContainerInfo *IdxObjCContainerDeclInfo + ObjcClass *IdxEntityInfo + ClassCursor Cursor + ClassLoc IdxLoc + Protocols *IdxObjCProtocolRefListInfo +} +type IdxObjCPropertyDeclInfo struct { + DeclInfo *IdxDeclInfo + Getter *IdxEntityInfo + Setter *IdxEntityInfo +} +type IdxCXXClassDeclInfo struct { + DeclInfo *IdxDeclInfo + Bases **IdxBaseClassInfo + NumBases c.Uint +} + +// Data for IndexerCallbacks#indexEntityReference. +// +// This may be deprecated in a future version as this duplicates +// the \c CXSymbolRole_Implicit bit in \c CXSymbolRole. type IdxEntityRefKind c.Uint const ( @@ -2307,6 +2627,33 @@ const ( SymbolRole_Implicit SymbolRole = 256 ) +// Data for IndexerCallbacks#indexEntityReference. +type IdxEntityRefInfo struct { + Kind IdxEntityRefKind + Cursor Cursor + Loc IdxLoc + ReferencedEntity *IdxEntityInfo + ParentEntity *IdxEntityInfo + Container *IdxContainerInfo + Role SymbolRole +} + +// A group of callbacks used by #clang_indexSourceFile and +// #clang_indexTranslationUnit. +type IndexerCallbacks struct { + AbortQuery func(_llcppg_param1 ClientData, _llcppg_param2 unsafe.Pointer) c.Int + Diagnostic func(_llcppg_param1 ClientData, _llcppg_param2 DiagnosticSet, _llcppg_param3 unsafe.Pointer) + EnteredMainFile func(_llcppg_param1 ClientData, _llcppg_param2 File, _llcppg_param3 unsafe.Pointer) IdxClientFile + PpIncludedFile func(_llcppg_param1 ClientData, _llcppg_param2 *IdxIncludedFileInfo) IdxClientFile + ImportedASTFile func(_llcppg_param1 ClientData, _llcppg_param2 *IdxImportedASTFileInfo) IdxClientASTFile + StartedTranslationUnit func(_llcppg_param1 ClientData, _llcppg_param2 unsafe.Pointer) IdxClientContainer + IndexDeclaration func(_llcppg_param1 ClientData, _llcppg_param2 *IdxDeclInfo) + IndexEntityReference func(_llcppg_param1 ClientData, _llcppg_param2 *IdxEntityRefInfo) +} + +// An indexing action/session, to be applied to one or multiple +// translation units. +type IndexAction uintptr type IndexOptFlags c.Uint const ( @@ -2330,6 +2677,19 @@ const ( IndexOpt_SkipParsedBodiesInSession IndexOptFlags = 16 ) +// Visitor invoked for each field found by a traversal. +// +// This visitor function will be invoked for each field found by +// \c clang_Type_visitFields. Its first argument is the cursor being +// visited, its second argument is the client data provided to +// \c clang_Type_visitFields. +// +// The visitor should return one of the \c CXVisitorResult values +// to direct \c clang_Type_visitFields. +// +// llgo:type C +type FieldVisitor = func(_llcppg_param1 Cursor, _llcppg_param2 ClientData) VisitorResult + // Describes the kind of binary operators. type BinaryOperatorKind c.Uint @@ -2442,367 +2802,6 @@ const ( UnaryOperator_Coawait UnaryOperatorKind = 14 ) -// An "index" that consists of a set of translation units that would -// typically be linked together into an executable or library. -type Index uintptr -type TargetInfoImpl struct { -} - -// An opaque type representing target information for a given translation -// unit. -type TargetInfo = *TargetInfoImpl -type TranslationUnitImpl struct { -} - -// A single translation unit, which resides in an index. -type TranslationUnit = *TranslationUnitImpl - -// Opaque pointer representing client data that will be passed through -// to various callbacks and visitors. -type ClientData = unsafe.Pointer - -// Provides the contents of a file that has not yet been saved to disk. -// -// Each CXUnsavedFile instance provides the name of a file on the -// system along with the current contents of that file that have not -// yet been saved to disk. -type UnsavedFile struct { - Filename *c.Char - Contents *c.Char - Length c.Ulong -} - -// Describes a version number of the form major.minor.subminor. -type Version struct { - Major c.Int - Minor c.Int - Subminor c.Int -} - -// Index initialization options. -// -// 0 is the default value of each member of this struct except for Size. -// Initialize the struct in one of the following three ways to avoid adapting -// code each time a new member is added to it: -// \code -// CXIndexOptions Opts; -// memset(&Opts, 0, sizeof(Opts)); -// Opts.Size = sizeof(CXIndexOptions); -// \endcode -// or explicitly initialize the first data member and zero-initialize the rest: -// \code -// CXIndexOptions Opts = { sizeof(CXIndexOptions) }; -// \endcode -// or to prevent the -Wmissing-field-initializers warning for the above version: -// \code -// CXIndexOptions Opts{}; -// Opts.Size = sizeof(CXIndexOptions); -// \endcode -type IndexOptions struct { - Size c.Uint - ThreadBackgroundPriorityForIndexing uint8 - ThreadBackgroundPriorityForEditing uint8 - ExcludeDeclarationsFromPCH c.Uint - DisplayDiagnostics c.Uint - StorePreamblesInMemory c.Uint - X c.Uint - PreambleStoragePath *c.Char - InvocationEmissionPath *c.Char -} -type TUResourceUsageEntry struct { - Kind TUResourceUsageKind - Amount c.Ulong -} - -// The memory usage of a CXTranslationUnit, broken into categories. -type TUResourceUsage struct { - Data unsafe.Pointer - NumEntries c.Uint - Entries *TUResourceUsageEntry -} - -// A cursor representing some element in the abstract syntax tree for -// a translation unit. -// -// The cursor abstraction unifies the different kinds of entities in a -// program--declaration, statements, expressions, references to declarations, -// etc.--under a single "cursor" abstraction with a common set of operations. -// Common operation for a cursor include: getting the physical location in -// a source file where the cursor points, getting the name associated with a -// cursor, and retrieving cursors for any child nodes of a particular cursor. -// -// Cursors can be produced in two specific ways. -// clang_getTranslationUnitCursor() produces a cursor for a translation unit, -// from which one can use clang_visitChildren() to explore the rest of the -// translation unit. clang_getCursor() maps from a physical source location -// to the entity that resides at that location, allowing one to map from the -// source code into the AST. -type Cursor struct { - Kind CursorKind - Xdata c.Int - Data [3]unsafe.Pointer -} - -// Describes the availability of a given entity on a particular platform, e.g., -// a particular class might only be available on Mac OS 10.7 or newer. -type PlatformAvailability struct { - Platform String - Introduced Version - Deprecated Version - Obsoleted Version - Unavailable c.Int - Message String -} -type CursorSetImpl struct { -} - -// A fast container representing a set of CXCursors. -type CursorSet = *CursorSetImpl - -// The type of an element in the abstract syntax tree. -type Type struct { - Kind TypeKind - Data [2]unsafe.Pointer -} - -// Visitor invoked for each cursor found by a traversal. -// -// This visitor function will be invoked for each cursor found by -// clang_visitCursorChildren(). Its first argument is the cursor being -// visited, its second argument is the parent visitor for that cursor, -// and its third argument is the client data provided to -// clang_visitCursorChildren(). -// -// The visitor should return one of the \c CXChildVisitResult values -// to direct clang_visitCursorChildren(). -// -// llgo:type C -type CursorVisitor = func(_llcppg_param1 Cursor, _llcppg_param2 Cursor, _llcppg_param3 ClientData) ChildVisitResult - -// Opaque pointer representing a policy that controls pretty printing -// for \c clang_getCursorPrettyPrinted. -type PrintingPolicy uintptr - -// \defgroup CINDEX_MODULE Module introspection -// -// The functions in this group provide access to information about modules. -// -// @{ -type Module uintptr - -// Describes a single preprocessing token. -type Token struct { - IntData [4]c.Uint - PtrData unsafe.Pointer -} - -// A semantic string that describes a code-completion result. -// -// A semantic string that describes the formatting of a code-completion -// result as a single "template" of text that should be inserted into the -// source buffer when a particular code-completion result is selected. -// Each semantic string is made up of some number of "chunks", each of which -// contains some text along with a description of what that text means, e.g., -// the name of the entity being referenced, whether the text chunk is part of -// the template, or whether it is a "placeholder" that the user should replace -// with actual code,of a specific kind. See \c CXCompletionChunkKind for a -// description of the different kinds of chunks. -type CompletionString uintptr - -// A single result of code completion. -type CompletionResult struct { - CursorKind CursorKind - CompletionString CompletionString -} - -// Contains the results of code-completion. -// -// This data structure contains the results of code completion, as -// produced by \c clang_codeCompleteAt(). Its contents must be freed by -// \c clang_disposeCodeCompleteResults. -type CodeCompleteResults struct { - Results *CompletionResult - NumResults c.Uint -} - -// Visitor invoked for each file in a translation unit -// (used with clang_getInclusions()). -// -// This visitor function will be invoked by clang_getInclusions() for each -// file included (either at the top-level or by \#include directives) within -// a translation unit. The first argument is the file being included, and -// the second and third arguments provide the inclusion stack. The -// array is sorted in order of immediate inclusion. For example, -// the first element refers to the location that included 'included_file'. -// -// llgo:type C -type InclusionVisitor = func(_llcppg_param1 File, _llcppg_param2 *SourceLocation, _llcppg_param3 c.Uint, _llcppg_param4 ClientData) - -// Evaluation result of a cursor -type EvalResult uintptr -type CursorAndRangeVisitor struct { - Context unsafe.Pointer - Visit func(_llcppg_param1 unsafe.Pointer, _llcppg_param2 Cursor, _llcppg_param3 SourceRange) VisitorResult -} - -// The client's data object that is associated with a CXFile. -type IdxClientFile uintptr - -// The client's data object that is associated with a semantic entity. -type IdxClientEntity uintptr - -// The client's data object that is associated with a semantic container -// of entities. -type IdxClientContainer uintptr - -// The client's data object that is associated with an AST file (PCH -// or module). -type IdxClientASTFile uintptr - -// Source location passed to index callbacks. -type IdxLoc struct { - PtrData [2]unsafe.Pointer - IntData c.Uint -} - -// Data for ppIncludedFile callback. -type IdxIncludedFileInfo struct { - HashLoc IdxLoc - Filename *c.Char - File File - IsImport c.Int - IsAngled c.Int - IsModuleImport c.Int -} - -// Data for IndexerCallbacks#importedASTFile. -type IdxImportedASTFileInfo struct { - File File - Module Module - Loc IdxLoc - IsImplicit c.Int -} -type IdxAttrInfo struct { - Kind IdxAttrKind - Cursor Cursor - Loc IdxLoc -} -type IdxEntityInfo struct { - Kind IdxEntityKind - TemplateKind IdxEntityCXXTemplateKind - Lang IdxEntityLanguage - Name *c.Char - USR *c.Char - Cursor Cursor - Attributes **IdxAttrInfo - NumAttributes c.Uint -} -type IdxContainerInfo struct { - Cursor Cursor -} -type IdxIBOutletCollectionAttrInfo struct { - AttrInfo *IdxAttrInfo - ObjcClass *IdxEntityInfo - ClassCursor Cursor - ClassLoc IdxLoc -} -type IdxDeclInfo struct { - EntityInfo *IdxEntityInfo - Cursor Cursor - Loc IdxLoc - SemanticContainer *IdxContainerInfo - LexicalContainer *IdxContainerInfo - IsRedeclaration c.Int - IsDefinition c.Int - IsContainer c.Int - DeclAsContainer *IdxContainerInfo - IsImplicit c.Int - Attributes **IdxAttrInfo - NumAttributes c.Uint - Flags c.Uint -} -type IdxObjCContainerDeclInfo struct { - DeclInfo *IdxDeclInfo - Kind IdxObjCContainerKind -} -type IdxBaseClassInfo struct { - Base *IdxEntityInfo - Cursor Cursor - Loc IdxLoc -} -type IdxObjCProtocolRefInfo struct { - Protocol *IdxEntityInfo - Cursor Cursor - Loc IdxLoc -} -type IdxObjCProtocolRefListInfo struct { - Protocols **IdxObjCProtocolRefInfo - NumProtocols c.Uint -} -type IdxObjCInterfaceDeclInfo struct { - ContainerInfo *IdxObjCContainerDeclInfo - SuperInfo *IdxBaseClassInfo - Protocols *IdxObjCProtocolRefListInfo -} -type IdxObjCCategoryDeclInfo struct { - ContainerInfo *IdxObjCContainerDeclInfo - ObjcClass *IdxEntityInfo - ClassCursor Cursor - ClassLoc IdxLoc - Protocols *IdxObjCProtocolRefListInfo -} -type IdxObjCPropertyDeclInfo struct { - DeclInfo *IdxDeclInfo - Getter *IdxEntityInfo - Setter *IdxEntityInfo -} -type IdxCXXClassDeclInfo struct { - DeclInfo *IdxDeclInfo - Bases **IdxBaseClassInfo - NumBases c.Uint -} - -// Data for IndexerCallbacks#indexEntityReference. -type IdxEntityRefInfo struct { - Kind IdxEntityRefKind - Cursor Cursor - Loc IdxLoc - ReferencedEntity *IdxEntityInfo - ParentEntity *IdxEntityInfo - Container *IdxContainerInfo - Role SymbolRole -} - -// A group of callbacks used by #clang_indexSourceFile and -// #clang_indexTranslationUnit. -type IndexerCallbacks struct { - AbortQuery func(_llcppg_param1 ClientData, _llcppg_param2 unsafe.Pointer) c.Int - Diagnostic func(_llcppg_param1 ClientData, _llcppg_param2 DiagnosticSet, _llcppg_param3 unsafe.Pointer) - EnteredMainFile func(_llcppg_param1 ClientData, _llcppg_param2 File, _llcppg_param3 unsafe.Pointer) IdxClientFile - PpIncludedFile func(_llcppg_param1 ClientData, _llcppg_param2 *IdxIncludedFileInfo) IdxClientFile - ImportedASTFile func(_llcppg_param1 ClientData, _llcppg_param2 *IdxImportedASTFileInfo) IdxClientASTFile - StartedTranslationUnit func(_llcppg_param1 ClientData, _llcppg_param2 unsafe.Pointer) IdxClientContainer - IndexDeclaration func(_llcppg_param1 ClientData, _llcppg_param2 *IdxDeclInfo) - IndexEntityReference func(_llcppg_param1 ClientData, _llcppg_param2 *IdxEntityRefInfo) -} - -// An indexing action/session, to be applied to one or multiple -// translation units. -type IndexAction uintptr - -// Visitor invoked for each field found by a traversal. -// -// This visitor function will be invoked for each field found by -// \c clang_Type_visitFields. Its first argument is the cursor being -// visited, its second argument is the client data provided to -// \c clang_Type_visitFields. -// -// The visitor should return one of the \c CXVisitorResult values -// to direct \c clang_Type_visitFields. -// -// llgo:type C -type FieldVisitor = func(_llcppg_param1 Cursor, _llcppg_param2 ClientData) VisitorResult - // @} type Remapping uintptr diff --git a/tool/_testc/clang-c-22.1.8/Index/out.go b/tool/_testc/clang-c-22.1.8/Index/out.go index 785c4bb4..29b7b788 100644 --- a/tool/_testc/clang-c-22.1.8/Index/out.go +++ b/tool/_testc/clang-c-22.1.8/Index/out.go @@ -15,6 +15,36 @@ const LLGoPackage = "link: -L$(llvm-config --libdir) -lclang; -lclang" const CINDEX_VERSION_MAJOR = 0 const CINDEX_VERSION_MINOR = 64 +// An "index" that consists of a set of translation units that would +// typically be linked together into an executable or library. +type Index uintptr +type TargetInfoImpl struct { +} + +// An opaque type representing target information for a given translation +// unit. +type TargetInfo = *TargetInfoImpl +type TranslationUnitImpl struct { +} + +// A single translation unit, which resides in an index. +type TranslationUnit = *TranslationUnitImpl + +// Opaque pointer representing client data that will be passed through +// to various callbacks and visitors. +type ClientData = unsafe.Pointer + +// Provides the contents of a file that has not yet been saved to disk. +// +// Each CXUnsavedFile instance provides the name of a file on the +// system along with the current contents of that file that have not +// yet been saved to disk. +type UnsavedFile struct { + Filename *c.Char + Contents *c.Char + Length c.Ulong +} + // Describes the availability of a particular entity, which indicates // whether the use of this entity will result in a warning or error due to // it being deprecated or unavailable. @@ -33,6 +63,13 @@ const ( Availability_NotAccessible AvailabilityKind = 3 ) +// Describes a version number of the form major.minor.subminor. +type Version struct { + Major c.Int + Minor c.Int + Subminor c.Int +} + // Describes the exception specification of a cursor. // // A negative value indicates that the cursor is not a function declaration. @@ -95,6 +132,37 @@ const ( GlobalOpt_ThreadBackgroundPriorityForAll GlobalOptFlags = 3 ) +// Index initialization options. +// +// 0 is the default value of each member of this struct except for Size. +// Initialize the struct in one of the following three ways to avoid adapting +// code each time a new member is added to it: +// \code +// CXIndexOptions Opts; +// memset(&Opts, 0, sizeof(Opts)); +// Opts.Size = sizeof(CXIndexOptions); +// \endcode +// or explicitly initialize the first data member and zero-initialize the rest: +// \code +// CXIndexOptions Opts = { sizeof(CXIndexOptions) }; +// \endcode +// or to prevent the -Wmissing-field-initializers warning for the above version: +// \code +// CXIndexOptions Opts{}; +// Opts.Size = sizeof(CXIndexOptions); +// \endcode +type IndexOptions struct { + Size c.Uint + ThreadBackgroundPriorityForIndexing uint8 + ThreadBackgroundPriorityForEditing uint8 + ExcludeDeclarationsFromPCH c.Uint + DisplayDiagnostics c.Uint + StorePreamblesInMemory c.Uint + X c.Uint + PreambleStoragePath *c.Char + InvocationEmissionPath *c.Char +} + // Flags that control the creation of translation units. // // The enumerators in this enumeration type are meant to be bitwise @@ -271,6 +339,18 @@ const ( TUResourceUsage_Last TUResourceUsageKind = 14 ) +type TUResourceUsageEntry struct { + Kind TUResourceUsageKind + Amount c.Ulong +} + +// The memory usage of a CXTranslationUnit, broken into categories. +type TUResourceUsage struct { + Data unsafe.Pointer + NumEntries c.Uint + Entries *TUResourceUsageEntry +} + // Describes the kind of entity that a cursor refers to. type CursorKind c.Uint @@ -1114,6 +1194,28 @@ const ( Cursor_OverloadCandidate CursorKind = 700 ) +// A cursor representing some element in the abstract syntax tree for +// a translation unit. +// +// The cursor abstraction unifies the different kinds of entities in a +// program--declaration, statements, expressions, references to declarations, +// etc.--under a single "cursor" abstraction with a common set of operations. +// Common operation for a cursor include: getting the physical location in +// a source file where the cursor points, getting the name associated with a +// cursor, and retrieving cursors for any child nodes of a particular cursor. +// +// Cursors can be produced in two specific ways. +// clang_getTranslationUnitCursor() produces a cursor for a translation unit, +// from which one can use clang_visitChildren() to explore the rest of the +// translation unit. clang_getCursor() maps from a physical source location +// to the entity that resides at that location, allowing one to map from the +// source code into the AST. +type Cursor struct { + Kind CursorKind + Xdata c.Int + Data [3]unsafe.Pointer +} + // Describe the linkage of the entity referred to by a cursor. type LinkageKind c.Uint @@ -1147,6 +1249,17 @@ const ( Visibility_Default VisibilityKind = 3 ) +// Describes the availability of a given entity on a particular platform, e.g., +// a particular class might only be available on Mac OS 10.7 or newer. +type PlatformAvailability struct { + Platform CXString.String + Introduced Version + Deprecated Version + Obsoleted Version + Unavailable c.Int + Message CXString.String +} + // Describe the "language" of the entity referred to by a cursor. type LanguageKind c.Uint @@ -1167,6 +1280,12 @@ const ( TLS_Static TLSKind = 2 ) +type CursorSetImpl struct { +} + +// A fast container representing a set of CXCursors. +type CursorSet = *CursorSetImpl + // Describes the kind of type type TypeKind c.Uint @@ -1669,6 +1788,12 @@ const ( CallingConv_Unexposed CallingConv = 200 ) +// The type of an element in the abstract syntax tree. +type Type struct { + Kind TypeKind + Data [2]unsafe.Pointer +} + // Describes the kind of a template argument. // // See the definition of llvm::clang::TemplateArgument::ArgKind for full @@ -1828,6 +1953,24 @@ const ( ChildVisit_Recurse ChildVisitResult = 2 ) +// Visitor invoked for each cursor found by a traversal. +// +// This visitor function will be invoked for each cursor found by +// clang_visitCursorChildren(). Its first argument is the cursor being +// visited, its second argument is the parent visitor for that cursor, +// and its third argument is the client data provided to +// clang_visitCursorChildren(). +// +// The visitor should return one of the \c CXChildVisitResult values +// to direct clang_visitCursorChildren(). +// +// llgo:type C +type CursorVisitor = func(_llcppg_param1 Cursor, _llcppg_param2 Cursor, _llcppg_param3 ClientData) ChildVisitResult + +// Opaque pointer representing a policy that controls pretty printing +// for \c clang_getCursorPrettyPrinted. +type PrintingPolicy uintptr + // Properties for the printing policy. // // See \c clang::PrintingPolicy for more information. @@ -1897,6 +2040,12 @@ const ( ObjCDeclQualifier_Oneway ObjCDeclQualifierKind = 32 ) +// \defgroup CINDEX_MODULE Module introspection +// +// The functions in this group provide access to information about modules. +// +// @{ +type Module uintptr type NameRefFlags c.Uint const ( @@ -1933,6 +2082,31 @@ const ( Token_Comment TokenKind = 4 ) +// Describes a single preprocessing token. +type Token struct { + IntData [4]c.Uint + PtrData unsafe.Pointer +} + +// A semantic string that describes a code-completion result. +// +// A semantic string that describes the formatting of a code-completion +// result as a single "template" of text that should be inserted into the +// source buffer when a particular code-completion result is selected. +// Each semantic string is made up of some number of "chunks", each of which +// contains some text along with a description of what that text means, e.g., +// the name of the entity being referenced, whether the text chunk is part of +// the template, or whether it is a "placeholder" that the user should replace +// with actual code,of a specific kind. See \c CXCompletionChunkKind for a +// description of the different kinds of chunks. +type CompletionString uintptr + +// A single result of code completion. +type CompletionResult struct { + CursorKind CursorKind + CompletionString CompletionString +} + // Describes a single piece of text within a code-completion string. // // Each "chunk" within a code-completion string (\c CXCompletionString) is @@ -2062,6 +2236,16 @@ const ( CompletionChunk_VerticalSpace CompletionChunkKind = 20 ) +// Contains the results of code-completion. +// +// This data structure contains the results of code completion, as +// produced by \c clang_codeCompleteAt(). Its contents must be freed by +// \c clang_disposeCodeCompleteResults. +type CodeCompleteResults struct { + Results *CompletionResult + NumResults c.Uint +} + // Flags that can be passed to \c clang_codeCompleteAt() to // modify its behavior. // @@ -2164,6 +2348,18 @@ const ( CompletionContext_Unknown CompletionContext = 8388607 ) +// Visitor invoked for each file in a translation unit +// (used with clang_getInclusions()). +// +// This visitor function will be invoked by clang_getInclusions() for each +// file included (either at the top-level or by \#include directives) within +// a translation unit. The first argument is the file being included, and +// the second and third arguments provide the inclusion stack. The +// array is sorted in order of immediate inclusion. For example, +// the first element refers to the location that included 'included_file'. +// +// llgo:type C +type InclusionVisitor = func(_llcppg_param1 CXFile.File, _llcppg_param2 *CXSourceLocation.SourceLocation, _llcppg_param3 c.Uint, _llcppg_param4 ClientData) type EvalResultKind c.Uint const ( @@ -2176,6 +2372,9 @@ const ( Eval_UnExposed EvalResultKind = 0 ) +// Evaluation result of a cursor +type EvalResult uintptr + // \defgroup CINDEX_HIGH Higher level API functions // // @{ @@ -2186,6 +2385,10 @@ const ( Visit_Continue VisitorResult = 1 ) +type CursorAndRangeVisitor struct { + Context unsafe.Pointer + Visit func(_llcppg_param1 unsafe.Pointer, _llcppg_param2 Cursor, _llcppg_param3 CXSourceLocation.SourceRange) VisitorResult +} type Result c.Uint const ( @@ -2198,6 +2401,43 @@ const ( Result_VisitBreak Result = 2 ) +// The client's data object that is associated with a CXFile. +type IdxClientFile uintptr + +// The client's data object that is associated with a semantic entity. +type IdxClientEntity uintptr + +// The client's data object that is associated with a semantic container +// of entities. +type IdxClientContainer uintptr + +// The client's data object that is associated with an AST file (PCH +// or module). +type IdxClientASTFile uintptr + +// Source location passed to index callbacks. +type IdxLoc struct { + PtrData [2]unsafe.Pointer + IntData c.Uint +} + +// Data for ppIncludedFile callback. +type IdxIncludedFileInfo struct { + HashLoc IdxLoc + Filename *c.Char + File CXFile.File + IsImport c.Int + IsAngled c.Int + IsModuleImport c.Int +} + +// Data for IndexerCallbacks#importedASTFile. +type IdxImportedASTFileInfo struct { + File CXFile.File + Module Module + Loc IdxLoc + IsImplicit c.Int +} type IdxEntityKind c.Uint const ( @@ -2267,22 +2507,102 @@ const ( IdxAttr_IBOutletCollection IdxAttrKind = 3 ) -type IdxDeclInfoFlags c.Uint - -const IdxDeclFlag_Skipped IdxDeclInfoFlags = 1 - -type IdxObjCContainerKind c.Uint - -const ( - IdxObjCContainer_ForwardRef IdxObjCContainerKind = 0 - IdxObjCContainer_Interface IdxObjCContainerKind = 1 - IdxObjCContainer_Implementation IdxObjCContainerKind = 2 -) - -// Data for IndexerCallbacks#indexEntityReference. -// -// This may be deprecated in a future version as this duplicates -// the \c CXSymbolRole_Implicit bit in \c CXSymbolRole. +type IdxAttrInfo struct { + Kind IdxAttrKind + Cursor Cursor + Loc IdxLoc +} +type IdxEntityInfo struct { + Kind IdxEntityKind + TemplateKind IdxEntityCXXTemplateKind + Lang IdxEntityLanguage + Name *c.Char + USR *c.Char + Cursor Cursor + Attributes **IdxAttrInfo + NumAttributes c.Uint +} +type IdxContainerInfo struct { + Cursor Cursor +} +type IdxIBOutletCollectionAttrInfo struct { + AttrInfo *IdxAttrInfo + ObjcClass *IdxEntityInfo + ClassCursor Cursor + ClassLoc IdxLoc +} +type IdxDeclInfoFlags c.Uint + +const IdxDeclFlag_Skipped IdxDeclInfoFlags = 1 + +type IdxDeclInfo struct { + EntityInfo *IdxEntityInfo + Cursor Cursor + Loc IdxLoc + SemanticContainer *IdxContainerInfo + LexicalContainer *IdxContainerInfo + IsRedeclaration c.Int + IsDefinition c.Int + IsContainer c.Int + DeclAsContainer *IdxContainerInfo + IsImplicit c.Int + Attributes **IdxAttrInfo + NumAttributes c.Uint + Flags c.Uint +} +type IdxObjCContainerKind c.Uint + +const ( + IdxObjCContainer_ForwardRef IdxObjCContainerKind = 0 + IdxObjCContainer_Interface IdxObjCContainerKind = 1 + IdxObjCContainer_Implementation IdxObjCContainerKind = 2 +) + +type IdxObjCContainerDeclInfo struct { + DeclInfo *IdxDeclInfo + Kind IdxObjCContainerKind +} +type IdxBaseClassInfo struct { + Base *IdxEntityInfo + Cursor Cursor + Loc IdxLoc +} +type IdxObjCProtocolRefInfo struct { + Protocol *IdxEntityInfo + Cursor Cursor + Loc IdxLoc +} +type IdxObjCProtocolRefListInfo struct { + Protocols **IdxObjCProtocolRefInfo + NumProtocols c.Uint +} +type IdxObjCInterfaceDeclInfo struct { + ContainerInfo *IdxObjCContainerDeclInfo + SuperInfo *IdxBaseClassInfo + Protocols *IdxObjCProtocolRefListInfo +} +type IdxObjCCategoryDeclInfo struct { + ContainerInfo *IdxObjCContainerDeclInfo + ObjcClass *IdxEntityInfo + ClassCursor Cursor + ClassLoc IdxLoc + Protocols *IdxObjCProtocolRefListInfo +} +type IdxObjCPropertyDeclInfo struct { + DeclInfo *IdxDeclInfo + Getter *IdxEntityInfo + Setter *IdxEntityInfo +} +type IdxCXXClassDeclInfo struct { + DeclInfo *IdxDeclInfo + Bases **IdxBaseClassInfo + NumBases c.Uint +} + +// Data for IndexerCallbacks#indexEntityReference. +// +// This may be deprecated in a future version as this duplicates +// the \c CXSymbolRole_Implicit bit in \c CXSymbolRole. type IdxEntityRefKind c.Uint const ( @@ -2312,6 +2632,33 @@ const ( SymbolRole_Implicit SymbolRole = 256 ) +// Data for IndexerCallbacks#indexEntityReference. +type IdxEntityRefInfo struct { + Kind IdxEntityRefKind + Cursor Cursor + Loc IdxLoc + ReferencedEntity *IdxEntityInfo + ParentEntity *IdxEntityInfo + Container *IdxContainerInfo + Role SymbolRole +} + +// A group of callbacks used by #clang_indexSourceFile and +// #clang_indexTranslationUnit. +type IndexerCallbacks struct { + AbortQuery func(_llcppg_param1 ClientData, _llcppg_param2 unsafe.Pointer) c.Int + Diagnostic func(_llcppg_param1 ClientData, _llcppg_param2 CXDiagnostic.DiagnosticSet, _llcppg_param3 unsafe.Pointer) + EnteredMainFile func(_llcppg_param1 ClientData, _llcppg_param2 CXFile.File, _llcppg_param3 unsafe.Pointer) IdxClientFile + PpIncludedFile func(_llcppg_param1 ClientData, _llcppg_param2 *IdxIncludedFileInfo) IdxClientFile + ImportedASTFile func(_llcppg_param1 ClientData, _llcppg_param2 *IdxImportedASTFileInfo) IdxClientASTFile + StartedTranslationUnit func(_llcppg_param1 ClientData, _llcppg_param2 unsafe.Pointer) IdxClientContainer + IndexDeclaration func(_llcppg_param1 ClientData, _llcppg_param2 *IdxDeclInfo) + IndexEntityReference func(_llcppg_param1 ClientData, _llcppg_param2 *IdxEntityRefInfo) +} + +// An indexing action/session, to be applied to one or multiple +// translation units. +type IndexAction uintptr type IndexOptFlags c.Uint const ( @@ -2335,6 +2682,19 @@ const ( IndexOpt_SkipParsedBodiesInSession IndexOptFlags = 16 ) +// Visitor invoked for each field found by a traversal. +// +// This visitor function will be invoked for each field found by +// \c clang_Type_visitFields. Its first argument is the cursor being +// visited, its second argument is the client data provided to +// \c clang_Type_visitFields. +// +// The visitor should return one of the \c CXVisitorResult values +// to direct \c clang_Type_visitFields. +// +// llgo:type C +type FieldVisitor = func(_llcppg_param1 Cursor, _llcppg_param2 ClientData) VisitorResult + // Describes the kind of binary operators. type BinaryOperatorKind c.Uint @@ -2447,367 +2807,6 @@ const ( UnaryOperator_Coawait UnaryOperatorKind = 14 ) -// An "index" that consists of a set of translation units that would -// typically be linked together into an executable or library. -type Index uintptr -type TargetInfoImpl struct { -} - -// An opaque type representing target information for a given translation -// unit. -type TargetInfo = *TargetInfoImpl -type TranslationUnitImpl struct { -} - -// A single translation unit, which resides in an index. -type TranslationUnit = *TranslationUnitImpl - -// Opaque pointer representing client data that will be passed through -// to various callbacks and visitors. -type ClientData = unsafe.Pointer - -// Provides the contents of a file that has not yet been saved to disk. -// -// Each CXUnsavedFile instance provides the name of a file on the -// system along with the current contents of that file that have not -// yet been saved to disk. -type UnsavedFile struct { - Filename *c.Char - Contents *c.Char - Length c.Ulong -} - -// Describes a version number of the form major.minor.subminor. -type Version struct { - Major c.Int - Minor c.Int - Subminor c.Int -} - -// Index initialization options. -// -// 0 is the default value of each member of this struct except for Size. -// Initialize the struct in one of the following three ways to avoid adapting -// code each time a new member is added to it: -// \code -// CXIndexOptions Opts; -// memset(&Opts, 0, sizeof(Opts)); -// Opts.Size = sizeof(CXIndexOptions); -// \endcode -// or explicitly initialize the first data member and zero-initialize the rest: -// \code -// CXIndexOptions Opts = { sizeof(CXIndexOptions) }; -// \endcode -// or to prevent the -Wmissing-field-initializers warning for the above version: -// \code -// CXIndexOptions Opts{}; -// Opts.Size = sizeof(CXIndexOptions); -// \endcode -type IndexOptions struct { - Size c.Uint - ThreadBackgroundPriorityForIndexing uint8 - ThreadBackgroundPriorityForEditing uint8 - ExcludeDeclarationsFromPCH c.Uint - DisplayDiagnostics c.Uint - StorePreamblesInMemory c.Uint - X c.Uint - PreambleStoragePath *c.Char - InvocationEmissionPath *c.Char -} -type TUResourceUsageEntry struct { - Kind TUResourceUsageKind - Amount c.Ulong -} - -// The memory usage of a CXTranslationUnit, broken into categories. -type TUResourceUsage struct { - Data unsafe.Pointer - NumEntries c.Uint - Entries *TUResourceUsageEntry -} - -// A cursor representing some element in the abstract syntax tree for -// a translation unit. -// -// The cursor abstraction unifies the different kinds of entities in a -// program--declaration, statements, expressions, references to declarations, -// etc.--under a single "cursor" abstraction with a common set of operations. -// Common operation for a cursor include: getting the physical location in -// a source file where the cursor points, getting the name associated with a -// cursor, and retrieving cursors for any child nodes of a particular cursor. -// -// Cursors can be produced in two specific ways. -// clang_getTranslationUnitCursor() produces a cursor for a translation unit, -// from which one can use clang_visitChildren() to explore the rest of the -// translation unit. clang_getCursor() maps from a physical source location -// to the entity that resides at that location, allowing one to map from the -// source code into the AST. -type Cursor struct { - Kind CursorKind - Xdata c.Int - Data [3]unsafe.Pointer -} - -// Describes the availability of a given entity on a particular platform, e.g., -// a particular class might only be available on Mac OS 10.7 or newer. -type PlatformAvailability struct { - Platform CXString.String - Introduced Version - Deprecated Version - Obsoleted Version - Unavailable c.Int - Message CXString.String -} -type CursorSetImpl struct { -} - -// A fast container representing a set of CXCursors. -type CursorSet = *CursorSetImpl - -// The type of an element in the abstract syntax tree. -type Type struct { - Kind TypeKind - Data [2]unsafe.Pointer -} - -// Visitor invoked for each cursor found by a traversal. -// -// This visitor function will be invoked for each cursor found by -// clang_visitCursorChildren(). Its first argument is the cursor being -// visited, its second argument is the parent visitor for that cursor, -// and its third argument is the client data provided to -// clang_visitCursorChildren(). -// -// The visitor should return one of the \c CXChildVisitResult values -// to direct clang_visitCursorChildren(). -// -// llgo:type C -type CursorVisitor = func(_llcppg_param1 Cursor, _llcppg_param2 Cursor, _llcppg_param3 ClientData) ChildVisitResult - -// Opaque pointer representing a policy that controls pretty printing -// for \c clang_getCursorPrettyPrinted. -type PrintingPolicy uintptr - -// \defgroup CINDEX_MODULE Module introspection -// -// The functions in this group provide access to information about modules. -// -// @{ -type Module uintptr - -// Describes a single preprocessing token. -type Token struct { - IntData [4]c.Uint - PtrData unsafe.Pointer -} - -// A semantic string that describes a code-completion result. -// -// A semantic string that describes the formatting of a code-completion -// result as a single "template" of text that should be inserted into the -// source buffer when a particular code-completion result is selected. -// Each semantic string is made up of some number of "chunks", each of which -// contains some text along with a description of what that text means, e.g., -// the name of the entity being referenced, whether the text chunk is part of -// the template, or whether it is a "placeholder" that the user should replace -// with actual code,of a specific kind. See \c CXCompletionChunkKind for a -// description of the different kinds of chunks. -type CompletionString uintptr - -// A single result of code completion. -type CompletionResult struct { - CursorKind CursorKind - CompletionString CompletionString -} - -// Contains the results of code-completion. -// -// This data structure contains the results of code completion, as -// produced by \c clang_codeCompleteAt(). Its contents must be freed by -// \c clang_disposeCodeCompleteResults. -type CodeCompleteResults struct { - Results *CompletionResult - NumResults c.Uint -} - -// Visitor invoked for each file in a translation unit -// (used with clang_getInclusions()). -// -// This visitor function will be invoked by clang_getInclusions() for each -// file included (either at the top-level or by \#include directives) within -// a translation unit. The first argument is the file being included, and -// the second and third arguments provide the inclusion stack. The -// array is sorted in order of immediate inclusion. For example, -// the first element refers to the location that included 'included_file'. -// -// llgo:type C -type InclusionVisitor = func(_llcppg_param1 CXFile.File, _llcppg_param2 *CXSourceLocation.SourceLocation, _llcppg_param3 c.Uint, _llcppg_param4 ClientData) - -// Evaluation result of a cursor -type EvalResult uintptr -type CursorAndRangeVisitor struct { - Context unsafe.Pointer - Visit func(_llcppg_param1 unsafe.Pointer, _llcppg_param2 Cursor, _llcppg_param3 CXSourceLocation.SourceRange) VisitorResult -} - -// The client's data object that is associated with a CXFile. -type IdxClientFile uintptr - -// The client's data object that is associated with a semantic entity. -type IdxClientEntity uintptr - -// The client's data object that is associated with a semantic container -// of entities. -type IdxClientContainer uintptr - -// The client's data object that is associated with an AST file (PCH -// or module). -type IdxClientASTFile uintptr - -// Source location passed to index callbacks. -type IdxLoc struct { - PtrData [2]unsafe.Pointer - IntData c.Uint -} - -// Data for ppIncludedFile callback. -type IdxIncludedFileInfo struct { - HashLoc IdxLoc - Filename *c.Char - File CXFile.File - IsImport c.Int - IsAngled c.Int - IsModuleImport c.Int -} - -// Data for IndexerCallbacks#importedASTFile. -type IdxImportedASTFileInfo struct { - File CXFile.File - Module Module - Loc IdxLoc - IsImplicit c.Int -} -type IdxAttrInfo struct { - Kind IdxAttrKind - Cursor Cursor - Loc IdxLoc -} -type IdxEntityInfo struct { - Kind IdxEntityKind - TemplateKind IdxEntityCXXTemplateKind - Lang IdxEntityLanguage - Name *c.Char - USR *c.Char - Cursor Cursor - Attributes **IdxAttrInfo - NumAttributes c.Uint -} -type IdxContainerInfo struct { - Cursor Cursor -} -type IdxIBOutletCollectionAttrInfo struct { - AttrInfo *IdxAttrInfo - ObjcClass *IdxEntityInfo - ClassCursor Cursor - ClassLoc IdxLoc -} -type IdxDeclInfo struct { - EntityInfo *IdxEntityInfo - Cursor Cursor - Loc IdxLoc - SemanticContainer *IdxContainerInfo - LexicalContainer *IdxContainerInfo - IsRedeclaration c.Int - IsDefinition c.Int - IsContainer c.Int - DeclAsContainer *IdxContainerInfo - IsImplicit c.Int - Attributes **IdxAttrInfo - NumAttributes c.Uint - Flags c.Uint -} -type IdxObjCContainerDeclInfo struct { - DeclInfo *IdxDeclInfo - Kind IdxObjCContainerKind -} -type IdxBaseClassInfo struct { - Base *IdxEntityInfo - Cursor Cursor - Loc IdxLoc -} -type IdxObjCProtocolRefInfo struct { - Protocol *IdxEntityInfo - Cursor Cursor - Loc IdxLoc -} -type IdxObjCProtocolRefListInfo struct { - Protocols **IdxObjCProtocolRefInfo - NumProtocols c.Uint -} -type IdxObjCInterfaceDeclInfo struct { - ContainerInfo *IdxObjCContainerDeclInfo - SuperInfo *IdxBaseClassInfo - Protocols *IdxObjCProtocolRefListInfo -} -type IdxObjCCategoryDeclInfo struct { - ContainerInfo *IdxObjCContainerDeclInfo - ObjcClass *IdxEntityInfo - ClassCursor Cursor - ClassLoc IdxLoc - Protocols *IdxObjCProtocolRefListInfo -} -type IdxObjCPropertyDeclInfo struct { - DeclInfo *IdxDeclInfo - Getter *IdxEntityInfo - Setter *IdxEntityInfo -} -type IdxCXXClassDeclInfo struct { - DeclInfo *IdxDeclInfo - Bases **IdxBaseClassInfo - NumBases c.Uint -} - -// Data for IndexerCallbacks#indexEntityReference. -type IdxEntityRefInfo struct { - Kind IdxEntityRefKind - Cursor Cursor - Loc IdxLoc - ReferencedEntity *IdxEntityInfo - ParentEntity *IdxEntityInfo - Container *IdxContainerInfo - Role SymbolRole -} - -// A group of callbacks used by #clang_indexSourceFile and -// #clang_indexTranslationUnit. -type IndexerCallbacks struct { - AbortQuery func(_llcppg_param1 ClientData, _llcppg_param2 unsafe.Pointer) c.Int - Diagnostic func(_llcppg_param1 ClientData, _llcppg_param2 CXDiagnostic.DiagnosticSet, _llcppg_param3 unsafe.Pointer) - EnteredMainFile func(_llcppg_param1 ClientData, _llcppg_param2 CXFile.File, _llcppg_param3 unsafe.Pointer) IdxClientFile - PpIncludedFile func(_llcppg_param1 ClientData, _llcppg_param2 *IdxIncludedFileInfo) IdxClientFile - ImportedASTFile func(_llcppg_param1 ClientData, _llcppg_param2 *IdxImportedASTFileInfo) IdxClientASTFile - StartedTranslationUnit func(_llcppg_param1 ClientData, _llcppg_param2 unsafe.Pointer) IdxClientContainer - IndexDeclaration func(_llcppg_param1 ClientData, _llcppg_param2 *IdxDeclInfo) - IndexEntityReference func(_llcppg_param1 ClientData, _llcppg_param2 *IdxEntityRefInfo) -} - -// An indexing action/session, to be applied to one or multiple -// translation units. -type IndexAction uintptr - -// Visitor invoked for each field found by a traversal. -// -// This visitor function will be invoked for each field found by -// \c clang_Type_visitFields. Its first argument is the cursor being -// visited, its second argument is the client data provided to -// \c clang_Type_visitFields. -// -// The visitor should return one of the \c CXVisitorResult values -// to direct \c clang_Type_visitFields. -// -// llgo:type C -type FieldVisitor = func(_llcppg_param1 Cursor, _llcppg_param2 ClientData) VisitorResult - // @} type Remapping uintptr diff --git a/tool/_testcpp/llvm-22.1.8-support/llcppg.cfg b/tool/_testcpp/llvm-22.1.8-support/llcppg.cfg index bd9db66c..57c1dfb1 100644 --- a/tool/_testcpp/llvm-22.1.8-support/llcppg.cfg +++ b/tool/_testcpp/llvm-22.1.8-support/llcppg.cfg @@ -3,6 +3,6 @@ "LLGoPackage": "link: -L$(llvm-config --libdir) -lLLVM; -lLLVM", "Stdlib": "", "Deps": ["libcxx", "llvm-c"], - "Pkgs": ["adt"], + "Pkgs": ["system", "adt"], "Language": "c++" } diff --git a/tool/_testcpp/llvm-22.1.8-support/system/AMDHSAKernelDescriptor.go b/tool/_testcpp/llvm-22.1.8-support/system/AMDHSAKernelDescriptor.go index a0e29352..0c0d4640 100644 --- a/tool/_testcpp/llvm-22.1.8-support/system/AMDHSAKernelDescriptor.go +++ b/tool/_testcpp/llvm-22.1.8-support/system/AMDHSAKernelDescriptor.go @@ -274,20 +274,6 @@ const ( AMDHSA_KERNARG_PRELOAD_SPEC_OFFSET_WIDTH = 9 AMDHSA_KERNARG_PRELOAD_SPEC_OFFSET = 65408 ) -const ( - AMDHSA_GROUP_SEGMENT_FIXED_SIZE_OFFSET = 0 - AMDHSA_PRIVATE_SEGMENT_FIXED_SIZE_OFFSET = 4 - AMDHSA_KERNARG_SIZE_OFFSET = 8 - AMDHSA_RESERVED0_OFFSET = 12 - AMDHSA_KERNEL_CODE_ENTRY_BYTE_OFFSET_OFFSET = 16 - AMDHSA_RESERVED1_OFFSET = 24 - AMDHSA_COMPUTE_PGM_RSRC3_OFFSET = 44 - AMDHSA_COMPUTE_PGM_RSRC1_OFFSET = 48 - AMDHSA_COMPUTE_PGM_RSRC2_OFFSET = 52 - AMDHSA_KERNEL_CODE_PROPERTIES_OFFSET = 56 - AMDHSA_KERNARG_PRELOAD_OFFSET = 58 - AMDHSA_RESERVED3_OFFSET = 60 -) type AMDHSAKernelDescriptor struct { GroupSegmentFixedSize c.Uint32T @@ -303,3 +289,18 @@ type AMDHSAKernelDescriptor struct { KernargPreload c.Uint16T Reserved3 [4]c.Uint8T } + +const ( + AMDHSA_GROUP_SEGMENT_FIXED_SIZE_OFFSET = 0 + AMDHSA_PRIVATE_SEGMENT_FIXED_SIZE_OFFSET = 4 + AMDHSA_KERNARG_SIZE_OFFSET = 8 + AMDHSA_RESERVED0_OFFSET = 12 + AMDHSA_KERNEL_CODE_ENTRY_BYTE_OFFSET_OFFSET = 16 + AMDHSA_RESERVED1_OFFSET = 24 + AMDHSA_COMPUTE_PGM_RSRC3_OFFSET = 44 + AMDHSA_COMPUTE_PGM_RSRC1_OFFSET = 48 + AMDHSA_COMPUTE_PGM_RSRC2_OFFSET = 52 + AMDHSA_KERNEL_CODE_PROPERTIES_OFFSET = 56 + AMDHSA_KERNARG_PRELOAD_OFFSET = 58 + AMDHSA_RESERVED3_OFFSET = 60 +) diff --git a/tool/gen_test.go b/tool/gen_test.go index 93dcc469..a53331af 100644 --- a/tool/gen_test.go +++ b/tool/gen_test.go @@ -297,7 +297,7 @@ func TestLLVM_Compiler(t *testing.T) { testFromDir(t, "Compiler", "./_testcpp", true, "system") } -func _TestLLVM_DenseMapInfo(t *testing.T) { +func TestLLVM_DenseMapInfo(t *testing.T) { testFromDir(t, "DenseMapInfo", "./_testcpp", true, "adt") } @@ -313,7 +313,6 @@ func TestLLVM_iterator_range(t *testing.T) { testFromDir(t, "iterator_range", "./_testcpp", true, "adt") } -func _TestLLVM_STLForwardCompat(t *testing.T) { - log.Println("===> TestLLVM_STLForwardCompat start") +func TestLLVM_STLForwardCompat(t *testing.T) { testFromDir(t, "STLForwardCompat", "./_testcpp", true, "adt") }