From ae4fae487bd3c761ffb6a85aa5e84165e3708746 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Mon, 9 Jun 2025 11:31:59 +0800 Subject: [PATCH] feat(gogensig):normal refer func pointer instead --- .../libxml2/2.13.6/libxml2/debugXML.go | 2 +- .../libxml2/2.13.6/libxml2/encoding.go | 4 +- .../testdata/libxml2/2.13.6/libxml2/parser.go | 54 +++++++------- .../testdata/libxml2/2.13.6/libxml2/tree.go | 74 +++++++++---------- .../testdata/libxml2/2.13.6/libxml2/valid.go | 4 +- .../testdata/libxml2/2.13.6/libxml2/xlink.go | 6 +- .../testdata/libxml2/2.13.6/libxml2/xpath.go | 12 +-- .../libxslt/1.1.42/libxslt/xsltInternals.go | 18 ++--- _cmptest/testdata/zlib/1.3.1/zlib/zlib.go | 4 +- .../_testdata/funcrefer/gogensig.expect | 2 +- cl/internal/convert/type.go | 8 +- cmd/gogensig/testdata/lua/gogensig.expect | 4 +- 12 files changed, 93 insertions(+), 99 deletions(-) diff --git a/_cmptest/testdata/libxml2/2.13.6/libxml2/debugXML.go b/_cmptest/testdata/libxml2/2.13.6/libxml2/debugXML.go index 5f9274b0..332c6cad 100644 --- a/_cmptest/testdata/libxml2/2.13.6/libxml2/debugXML.go +++ b/_cmptest/testdata/libxml2/2.13.6/libxml2/debugXML.go @@ -70,7 +70,7 @@ type X_xmlShellCtxt struct { Pctxt XPathContextPtr Loaded c.Int Output *c.FILE - Input c.Pointer + Input ShellReadlineFunc } type ShellCtxt X_xmlShellCtxt type ShellCtxtPtr *ShellCtxt diff --git a/_cmptest/testdata/libxml2/2.13.6/libxml2/encoding.go b/_cmptest/testdata/libxml2/2.13.6/libxml2/encoding.go index 593223f4..d80cb379 100644 --- a/_cmptest/testdata/libxml2/2.13.6/libxml2/encoding.go +++ b/_cmptest/testdata/libxml2/2.13.6/libxml2/encoding.go @@ -53,8 +53,8 @@ type CharEncodingOutputFunc func(*c.Char, *c.Int, *c.Char, *c.Int) c.Int type X_xmlCharEncodingHandler struct { Name *c.Char - Input c.Pointer - Output c.Pointer + Input CharEncodingInputFunc + Output CharEncodingOutputFunc } type CharEncodingHandler X_xmlCharEncodingHandler type CharEncodingHandlerPtr *CharEncodingHandler diff --git a/_cmptest/testdata/libxml2/2.13.6/libxml2/parser.go b/_cmptest/testdata/libxml2/2.13.6/libxml2/parser.go index c95299b8..91cb9e98 100644 --- a/_cmptest/testdata/libxml2/2.13.6/libxml2/parser.go +++ b/_cmptest/testdata/libxml2/2.13.6/libxml2/parser.go @@ -172,33 +172,33 @@ type StartElementNsSAX2Func func(c.Pointer, *Char, *Char, *Char, c.Int, **Char, type EndElementNsSAX2Func func(c.Pointer, *Char, *Char, *Char) type X_xmlSAXHandlerV1 struct { - InternalSubset c.Pointer - IsStandalone c.Pointer - HasInternalSubset c.Pointer - HasExternalSubset c.Pointer - ResolveEntity c.Pointer - GetEntity c.Pointer - EntityDecl c.Pointer - NotationDecl c.Pointer - AttributeDecl c.Pointer - ElementDecl c.Pointer - UnparsedEntityDecl c.Pointer - SetDocumentLocator c.Pointer - StartDocument c.Pointer - EndDocument c.Pointer - StartElement c.Pointer - EndElement c.Pointer - Reference c.Pointer - Characters c.Pointer - IgnorableWhitespace c.Pointer - ProcessingInstruction c.Pointer - Comment c.Pointer - Warning c.Pointer - Error c.Pointer - FatalError c.Pointer - GetParameterEntity c.Pointer - CdataBlock c.Pointer - ExternalSubset c.Pointer + InternalSubset InternalSubsetSAXFunc + IsStandalone IsStandaloneSAXFunc + HasInternalSubset HasInternalSubsetSAXFunc + HasExternalSubset HasExternalSubsetSAXFunc + ResolveEntity ResolveEntitySAXFunc + GetEntity GetEntitySAXFunc + EntityDecl EntityDeclSAXFunc + NotationDecl NotationDeclSAXFunc + AttributeDecl AttributeDeclSAXFunc + ElementDecl ElementDeclSAXFunc + UnparsedEntityDecl UnparsedEntityDeclSAXFunc + SetDocumentLocator SetDocumentLocatorSAXFunc + StartDocument StartDocumentSAXFunc + EndDocument EndDocumentSAXFunc + StartElement StartElementSAXFunc + EndElement EndElementSAXFunc + Reference ReferenceSAXFunc + Characters CharactersSAXFunc + IgnorableWhitespace IgnorableWhitespaceSAXFunc + ProcessingInstruction ProcessingInstructionSAXFunc + Comment CommentSAXFunc + Warning WarningSAXFunc + Error ErrorSAXFunc + FatalError FatalErrorSAXFunc + GetParameterEntity GetParameterEntitySAXFunc + CdataBlock CdataBlockSAXFunc + ExternalSubset ExternalSubsetSAXFunc Initialized c.Uint } type SAXHandlerV1 X_xmlSAXHandlerV1 diff --git a/_cmptest/testdata/libxml2/2.13.6/libxml2/tree.go b/_cmptest/testdata/libxml2/2.13.6/libxml2/tree.go index 040c7a30..70aca250 100644 --- a/_cmptest/testdata/libxml2/2.13.6/libxml2/tree.go +++ b/_cmptest/testdata/libxml2/2.13.6/libxml2/tree.go @@ -10,8 +10,8 @@ const DOCB_DOCUMENT_NODE = 21 type X_xmlParserInputBuffer struct { Context c.Pointer - Readcallback c.Pointer - Closecallback c.Pointer + Readcallback InputReadCallback + Closecallback InputCloseCallback Encoder CharEncodingHandlerPtr Buffer BufPtr Raw BufPtr @@ -24,8 +24,8 @@ type ParserInputBufferPtr *ParserInputBuffer type X_xmlOutputBuffer struct { Context c.Pointer - Writecallback c.Pointer - Closecallback c.Pointer + Writecallback OutputWriteCallback + Closecallback OutputCloseCallback Encoder CharEncodingHandlerPtr Buffer BufPtr Conv BufPtr @@ -46,7 +46,7 @@ type X_xmlParserInput struct { Line c.Int Col c.Int Consumed c.Ulong - Free c.Pointer + Free ParserInputDeallocate Encoding *Char Version *Char Flags c.Int @@ -154,7 +154,7 @@ type X_xmlParserCtxt struct { Nsdb *ParserNsData AttrHashMax c.Uint AttrHash *AttrHashBucket - ErrorHandler c.Pointer + ErrorHandler StructuredErrorFunc ErrorCtxt c.Pointer } type ParserCtxt X_xmlParserCtxt @@ -170,38 +170,38 @@ type SAXLocator X_xmlSAXLocator type SAXLocatorPtr *SAXLocator type X_xmlSAXHandler struct { - InternalSubset c.Pointer - IsStandalone c.Pointer - HasInternalSubset c.Pointer - HasExternalSubset c.Pointer - ResolveEntity c.Pointer - GetEntity c.Pointer - EntityDecl c.Pointer - NotationDecl c.Pointer - AttributeDecl c.Pointer - ElementDecl c.Pointer - UnparsedEntityDecl c.Pointer - SetDocumentLocator c.Pointer - StartDocument c.Pointer - EndDocument c.Pointer - StartElement c.Pointer - EndElement c.Pointer - Reference c.Pointer - Characters c.Pointer - IgnorableWhitespace c.Pointer - ProcessingInstruction c.Pointer - Comment c.Pointer - Warning c.Pointer - Error c.Pointer - FatalError c.Pointer - GetParameterEntity c.Pointer - CdataBlock c.Pointer - ExternalSubset c.Pointer + InternalSubset InternalSubsetSAXFunc + IsStandalone IsStandaloneSAXFunc + HasInternalSubset HasInternalSubsetSAXFunc + HasExternalSubset HasExternalSubsetSAXFunc + ResolveEntity ResolveEntitySAXFunc + GetEntity GetEntitySAXFunc + EntityDecl EntityDeclSAXFunc + NotationDecl NotationDeclSAXFunc + AttributeDecl AttributeDeclSAXFunc + ElementDecl ElementDeclSAXFunc + UnparsedEntityDecl UnparsedEntityDeclSAXFunc + SetDocumentLocator SetDocumentLocatorSAXFunc + StartDocument StartDocumentSAXFunc + EndDocument EndDocumentSAXFunc + StartElement StartElementSAXFunc + EndElement EndElementSAXFunc + Reference ReferenceSAXFunc + Characters CharactersSAXFunc + IgnorableWhitespace IgnorableWhitespaceSAXFunc + ProcessingInstruction ProcessingInstructionSAXFunc + Comment CommentSAXFunc + Warning WarningSAXFunc + Error ErrorSAXFunc + FatalError FatalErrorSAXFunc + GetParameterEntity GetParameterEntitySAXFunc + CdataBlock CdataBlockSAXFunc + ExternalSubset ExternalSubsetSAXFunc Initialized c.Uint X_private c.Pointer - StartElementNs c.Pointer - EndElementNs c.Pointer - Serror c.Pointer + StartElementNs StartElementNsSAX2Func + EndElementNs EndElementNsSAX2Func + Serror StructuredErrorFunc } type SAXHandler X_xmlSAXHandler type SAXHandlerPtr *SAXHandler @@ -559,7 +559,7 @@ type X_xmlDOMWrapCtxt struct { X_private c.Pointer Type c.Int NamespaceMap c.Pointer - GetNsForNodeFunc c.Pointer + GetNsForNodeFunc DOMWrapAcquireNsFunction } type DOMWrapCtxt X_xmlDOMWrapCtxt type DOMWrapCtxtPtr *DOMWrapCtxt diff --git a/_cmptest/testdata/libxml2/2.13.6/libxml2/valid.go b/_cmptest/testdata/libxml2/2.13.6/libxml2/valid.go index 0124ce0a..2ca85a79 100644 --- a/_cmptest/testdata/libxml2/2.13.6/libxml2/valid.go +++ b/_cmptest/testdata/libxml2/2.13.6/libxml2/valid.go @@ -19,8 +19,8 @@ type ValidityWarningFunc func(__llgo_arg_0 c.Pointer, __llgo_arg_1 *c.Char, __ll type X_xmlValidCtxt struct { UserData c.Pointer - Error c.Pointer - Warning c.Pointer + Error ValidityErrorFunc + Warning ValidityWarningFunc Node NodePtr NodeNr c.Int NodeMax c.Int diff --git a/_cmptest/testdata/libxml2/2.13.6/libxml2/xlink.go b/_cmptest/testdata/libxml2/2.13.6/libxml2/xlink.go index 839a8753..638fc3d5 100644 --- a/_cmptest/testdata/libxml2/2.13.6/libxml2/xlink.go +++ b/_cmptest/testdata/libxml2/2.13.6/libxml2/xlink.go @@ -47,9 +47,9 @@ type XlinkExtendedLinkFunk func(c.Pointer, NodePtr, c.Int, *XlinkHRef, *XlinkRol type XlinkExtendedLinkSetFunk func(c.Pointer, NodePtr, c.Int, *XlinkHRef, *XlinkRole, c.Int, *XlinkTitle, **Char) type X_xlinkHandler struct { - Simple c.Pointer - Extended c.Pointer - Set c.Pointer + Simple XlinkSimpleLinkFunk + Extended XlinkExtendedLinkFunk + Set XlinkExtendedLinkSetFunk } type XlinkHandler X_xlinkHandler type XlinkHandlerPtr *XlinkHandler diff --git a/_cmptest/testdata/libxml2/2.13.6/libxml2/xpath.go b/_cmptest/testdata/libxml2/2.13.6/libxml2/xpath.go index 2bc7ce58..37430ff2 100644 --- a/_cmptest/testdata/libxml2/2.13.6/libxml2/xpath.go +++ b/_cmptest/testdata/libxml2/2.13.6/libxml2/xpath.go @@ -33,17 +33,17 @@ type X_xmlXPathContext struct { Here NodePtr Origin NodePtr NsHash HashTablePtr - VarLookupFunc c.Pointer + VarLookupFunc XPathVariableLookupFunc VarLookupData c.Pointer Extra c.Pointer Function *Char FunctionURI *Char - FuncLookupFunc c.Pointer + FuncLookupFunc XPathFuncLookupFunc FuncLookupData c.Pointer TmpNsList *NsPtr TmpNsNr c.Int UserData c.Pointer - Error c.Pointer + Error StructuredErrorFunc LastError Error DebugNode NodePtr Dict DictPtr @@ -142,7 +142,7 @@ type XPathConvertFunc func(XPathObjectPtr, c.Int) c.Int type X_xmlXPathType struct { Name *Char - Func c.Pointer + Func XPathConvertFunc } type XPathType X_xmlXPathType type XPathTypePtr *XPathType @@ -159,7 +159,7 @@ type XPathEvalFunc func(XPathParserContextPtr, c.Int) type X_xmlXPathFunct struct { Name *Char - Func c.Pointer + Func XPathEvalFunc } type XPathFunct X_xmlXPathFunct type XPathFuncPtr *XPathFunct @@ -169,7 +169,7 @@ type XPathAxisFunc func(XPathParserContextPtr, XPathObjectPtr) XPathObjectPtr type X_xmlXPathAxis struct { Name *Char - Func c.Pointer + Func XPathAxisFunc } type XPathAxis X_xmlXPathAxis type XPathAxisPtr *XPathAxis diff --git a/_cmptest/testdata/libxslt/1.1.42/libxslt/xsltInternals.go b/_cmptest/testdata/libxslt/1.1.42/libxslt/xsltInternals.go index 56000327..23d36019 100644 --- a/_cmptest/testdata/libxslt/1.1.42/libxslt/xsltInternals.go +++ b/_cmptest/testdata/libxslt/1.1.42/libxslt/xsltInternals.go @@ -10,7 +10,7 @@ const MAX_SORT = 15 type X_xsltRuntimeExtra struct { Info c.Pointer - Deallocate c.Pointer + Deallocate libxml2.FreeFunc Val struct { Ptr c.Pointer } @@ -200,9 +200,9 @@ type X_xsltTransformContext struct { Extras RuntimeExtraPtr StyleList DocumentPtr Sec c.Pointer - Error c.Pointer + Error libxml2.GenericErrorFunc Errctx c.Pointer - Sortfunc c.Pointer + Sortfunc SortFunc TmpRVT libxml2.DocPtr PersistRVT libxml2.DocPtr Ctxtflags c.Int @@ -232,9 +232,9 @@ type X_xsltTransformContext struct { OpCount c.Ulong SourceDocDirty c.Int CurrentId c.Ulong - NewLocale c.Pointer - FreeLocale c.Pointer - GenSortKey c.Pointer + NewLocale NewLocaleFunc + FreeLocale FreeLocaleFunc + GenSortKey GenSortKeyFunc } type TransformContext X_xsltTransformContext type TransformContextPtr *TransformContext @@ -242,9 +242,9 @@ type TransformContextPtr *TransformContext type X_xsltElemPreComp struct { Next ElemPreCompPtr Type StyleType - Func c.Pointer + Func TransformFunction Inst libxml2.NodePtr - Free c.Pointer + Free ElemPreCompDeallocator } type ElemPreComp X_xsltElemPreComp type ElemPreCompPtr *ElemPreComp @@ -287,7 +287,7 @@ type ElemPreCompDeallocator func(ElemPreCompPtr) type X_xsltStylePreComp struct { Next ElemPreCompPtr Type StyleType - Func c.Pointer + Func TransformFunction Inst libxml2.NodePtr Stype *libxml2.Char HasStype c.Int diff --git a/_cmptest/testdata/zlib/1.3.1/zlib/zlib.go b/_cmptest/testdata/zlib/1.3.1/zlib/zlib.go index 60aa0bab..48a051de 100644 --- a/_cmptest/testdata/zlib/1.3.1/zlib/zlib.go +++ b/_cmptest/testdata/zlib/1.3.1/zlib/zlib.go @@ -55,8 +55,8 @@ type ZStreamS struct { TotalOut ULong Msg *c.Char State *InternalState - Zalloc c.Pointer - Zfree c.Pointer + Zalloc AllocFunc + Zfree FreeFunc Opaque Voidpf DataType c.Int Adler ULong diff --git a/cl/internal/convert/_testdata/funcrefer/gogensig.expect b/cl/internal/convert/_testdata/funcrefer/gogensig.expect index a47e01c0..885a584e 100644 --- a/cl/internal/convert/_testdata/funcrefer/gogensig.expect +++ b/cl/internal/convert/_testdata/funcrefer/gogensig.expect @@ -29,7 +29,7 @@ type Hooks struct { type Stream struct { F *c.FILE - Cb c.Pointer + Cb CallBack } // llgo:type C diff --git a/cl/internal/convert/type.go b/cl/internal/convert/type.go index c9822fed..ca0a8969 100644 --- a/cl/internal/convert/type.go +++ b/cl/internal/convert/type.go @@ -130,6 +130,7 @@ func (p *TypeConv) handlePointerType(t *ast.PointerType) (types.Type, error) { } } + // llgo with a anonymous function type current only support with pointer if baseFuncType, ok := baseType.(*types.Signature); ok { if p.ctx == Record { return p.typeMap.CType("Pointer"), nil @@ -146,13 +147,6 @@ func (p *TypeConv) handleIdentRefer(t ast.Expr) (types.Type, error) { if err != nil { return nil, err } - if p.ctx == Record { - if named, ok := typ.(*types.Named); ok { - if _, ok := named.Underlying().(*types.Signature); ok { - return p.typeMap.CType("Pointer"), nil - } - } - } return typ, nil } switch t := t.(type) { diff --git a/cmd/gogensig/testdata/lua/gogensig.expect b/cmd/gogensig/testdata/lua/gogensig.expect index fe17528a..743b1c50 100644 --- a/cmd/gogensig/testdata/lua/gogensig.expect +++ b/cmd/gogensig/testdata/lua/gogensig.expect @@ -23,7 +23,7 @@ type Buffer struct { type Reg struct { Name *c.Char - Func c.Pointer + Func CFunction } //go:linkname Checkversion C.luaL_checkversion_ @@ -163,7 +163,7 @@ func Buffinitsize(L *State, B *Buffer, sz c.SizeT) *c.Char type Stream struct { F *c.FILE - Closef c.Pointer + Closef CFunction } ===== lua.go =====