func (p *cgoPackage) addFuncDecls() {
	names := make([]string, 0, len(p.functions))
	for name := range p.functions {
		names = append(names, name)
	}
	sort.Strings(names)
	for _, name := range names {
		fn := p.functions[name]
		obj := &ast.Object{
			Kind: ast.Fun,
			Name: "C." + name,
		}
		args := make([]*ast.Field, len(fn.args))
		decl := &ast.FuncDecl{
			Name: &ast.Ident{
				NamePos: fn.pos,
				Name:    "C." + name,
				Obj:     obj,
			},
			Type: &ast.FuncType{
				Func: fn.pos,
				Params: &ast.FieldList{
					Opening: fn.pos,
					List:    args,
					Closing: fn.pos,
				},
				Results: fn.results,
			},
		}
		obj.Decl = decl
		for i, arg := range fn.args {
			args[i] = &ast.Field{
				Names: []*ast.Ident{
					&ast.Ident{
						NamePos: fn.pos,
						Name:    arg.name,
						Obj: &ast.Object{
							Kind: ast.Var,
							Name: arg.name,
							Decl: decl,
						},
					},
				},
				Type: arg.typeExpr,
			}
		}
		p.generated.Decls = append(p.generated.Decls, decl)
	}
}
// addFuncDecls adds the C function declarations found by libclang in the
// comment above the `import "C"` statement.
addFuncDecls adds the C function declarations found by libclang in the
comment above the `import "C"` statement.
// addFuncDecls adds the C function declarations found by libclang in the // comment above the ` import " C " ` statement .
func (p *cgoPackage) addFuncDecls() {
	names := make([]string, 0, len(p.functions))
	for name := range p.functions {
		names = append(names, name)
	}
	sort.Strings(names)
	for _, name := range names {
		fn := p.functions[name]
		obj := &ast.Object{
			Kind: ast.Fun,
			Name: "C." + name,
		}
		args := make([]*ast.Field, len(fn.args))
		decl := &ast.FuncDecl{
			Name: &ast.Ident{
				NamePos: fn.pos,
				Name:    "C." + name,
				Obj:     obj,
			},
			Type: &ast.FuncType{
				Func: fn.pos,
				Params: &ast.FieldList{
					Opening: fn.pos,
					List:    args,
					Closing: fn.pos,
				},
				Results: fn.results,
			},
		}
		obj.Decl = decl
		for i, arg := range fn.args {
			args[i] = &ast.Field{
				Names: []*ast.Ident{
					&ast.Ident{
						NamePos: fn.pos,
						Name:    arg.name,
						Obj: &ast.Object{
							Kind: ast.Var,
							Name: arg.name,
							Decl: decl,
						},
					},
				},
				Type: arg.typeExpr,
			}
		}
		p.generated.Decls = append(p.generated.Decls, decl)
	}
}
func ( p * cgoPackage ) addFuncDecls ( ) { names := make ( [ ] string , 0 , len ( p . functions ) ) for name := range p . functions { names = append ( names , name ) } sort . Strings ( names ) for _ , name := range names { fn := p . functions [ name ] obj := & ast . Object { Kind : ast . Fun , Name : " " + name , } args := make ( [ ] * ast . Field , len ( fn . args ) ) decl := & ast . FuncDecl { Name : & ast . Ident { NamePos : fn . pos , Name : " " + name , Obj : obj , } , Type : & ast . FuncType { Func : fn . pos , Params : & ast . FieldList { Opening : fn . pos , List : args , Closing : fn . pos , } , Results : fn . results , } , } obj . Decl = decl for i , arg := range fn . args { args [ i ] = & ast . Field { Names : [ ] * ast . Ident { & ast . Ident { NamePos : fn . pos , Name : arg . name , Obj : & ast . Object { Kind : ast . Var , Name : arg . name , Decl : decl , } , } , } , Type : arg . typeExpr , } } p . generated . Decls = append ( p . generated . Decls , decl ) } }
addFuncDecls adds the C function declarations found by libclang in the
comment above the `import "C"` statement.
addFuncDecls adds the C function declarations found by libclang in the comment above the ` import " C " ` statement .