Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] gogensig: typedef havent defined type cause panic #88

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions _xtool/llcppsigfetch/parse/cvt.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ func (ct *Converter) ProcessBuiltinType(t clang.Type) *ast.BuiltinType {
// For anonymous decl of typedef references, use their anonymous name
func (ct *Converter) BuildScopingExpr(cursor clang.Cursor) ast.Expr {
parts := clangutils.BuildScopingParts(cursor)
return buildScopingFromParts(parts)
return buildScopingFromParts(cursor, parts)
}

func (ct *Converter) MarshalASTFiles() *cjson.JSON {
Expand Down Expand Up @@ -999,12 +999,19 @@ func isMethod(cursor clang.Cursor) bool {
return cursor.Kind == clang.CursorCXXMethod || cursor.Kind == clang.CursorConstructor || cursor.Kind == clang.CursorDestructor
}

func buildScopingFromParts(parts []string) ast.Expr {
func buildScopingFromParts(cursor clang.Cursor, parts []string) ast.Expr {
if len(parts) == 0 {
return nil
}

var expr ast.Expr = &ast.Ident{Name: parts[0]}
loc := clang.GoString(cursor.Definition().Location().File().FileName())
var expr ast.Expr = &ast.Ident{
Name: parts[0],
DefLoc: &ast.Location{
File: loc,
},
}

for _, part := range parts[1:] {
expr = &ast.ScopingExpr{
Parent: expr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "Foo"
},
"Type": {
Expand All @@ -27,6 +28,10 @@
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"DefLoc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Name": "bar"
},
"Tag": 0
Expand All @@ -38,6 +43,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "b"
}]
}]
Expand All @@ -54,6 +60,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "bar"
},
"Type": {
Expand All @@ -74,6 +81,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "a"
}]
}]
Expand All @@ -90,6 +98,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "sqlite3_pcache_page"
},
"Type": {
Expand All @@ -111,6 +120,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "sqlite3_pcache_page"
},
"Type": {
Expand All @@ -134,6 +144,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "pExtra"
}]
}]
Expand All @@ -150,6 +161,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "sqlite3_pcache"
},
"Type": {
Expand All @@ -171,6 +183,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "sqlite3_pcache_methods2"
},
"Type": {
Expand All @@ -192,6 +205,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "sqlite3_pcache_methods2"
},
"Type": {
Expand All @@ -212,6 +226,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "iVersion"
}]
}, {
Expand Down Expand Up @@ -252,6 +267,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "xShutdown"
}]
}, {
Expand Down Expand Up @@ -304,6 +320,10 @@
"_Type": "PointerType",
"X": {
"_Type": "Ident",
"DefLoc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Name": "sqlite3_pcache"
}
}
Expand All @@ -315,6 +335,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "xCreate"
}]
}]
Expand All @@ -331,6 +352,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "sqlite3_file"
},
"Type": {
Expand All @@ -352,6 +374,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "sqlite3_file"
},
"Type": {
Expand All @@ -365,6 +388,10 @@
"_Type": "PointerType",
"X": {
"_Type": "Ident",
"DefLoc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Name": "sqlite3_io_methods"
}
},
Expand All @@ -374,6 +401,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "pMethods"
}]
}]
Expand All @@ -390,6 +418,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "sqlite3_io_methods"
},
"Type": {
Expand All @@ -411,6 +440,10 @@
"_Type": "PointerType",
"X": {
"_Type": "Ident",
"DefLoc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Name": "sqlite3_file"
}
},
Expand Down Expand Up @@ -461,6 +494,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "xUnfetch"
}]
}]
Expand All @@ -477,6 +511,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "lua_State"
},
"Type": {
Expand All @@ -498,6 +533,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "lua_Debug"
},
"Type": {
Expand All @@ -519,6 +555,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "lua_getstack"
},
"MangledName": "lua_getstack",
Expand All @@ -532,6 +569,10 @@
"_Type": "PointerType",
"X": {
"_Type": "Ident",
"DefLoc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Name": "lua_State"
}
},
Expand All @@ -541,6 +582,7 @@
"Access": 0,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "L"
}]
}, {
Expand All @@ -556,6 +598,7 @@
"Access": 0,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "level"
}]
}, {
Expand All @@ -564,6 +607,10 @@
"_Type": "PointerType",
"X": {
"_Type": "Ident",
"DefLoc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Name": "lua_Debug"
}
},
Expand All @@ -573,6 +620,7 @@
"Access": 0,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "ar"
}]
}]
Expand Down Expand Up @@ -601,6 +649,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "lua_Debug"
},
"Type": {
Expand Down Expand Up @@ -629,6 +678,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "short_src"
}]
}, {
Expand All @@ -639,6 +689,10 @@
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"DefLoc": {
"_Type": "Location",
"File": ""
},
"Name": "CallInfo"
},
"Tag": 0
Expand All @@ -650,6 +704,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "i_ci"
}]
}]
Expand Down Expand Up @@ -687,6 +742,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "f"
},
"MangledName": "f",
Expand All @@ -700,6 +756,10 @@
"_Type": "PointerType",
"X": {
"_Type": "Ident",
"DefLoc": {
"_Type": "Location",
"File": "./hfile/def.h"
},
"Name": "foo"
}
},
Expand All @@ -709,6 +769,7 @@
"Access": 0,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "f"
}]
}]
Expand Down Expand Up @@ -746,6 +807,7 @@
"Parent": null,
"Name": {
"_Type": "Ident",
"DefLoc": null,
"Name": "foo"
},
"Type": {
Expand All @@ -766,6 +828,7 @@
"Access": 1,
"Names": [{
"_Type": "Ident",
"DefLoc": null,
"Name": "a"
}]
}]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typedef gnutls_cipher_algorithm_t gnutls_cipher_algorithm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
typedef enum gnutls_cipher_algorithm {
GNUTLS_CIPHER_UNKNOWN = 0,
GNUTLS_CIPHER_NULL = 1,
} gnutls_cipher_algorithm_t;

#include <compact.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
test "github.com/goplus/llcppg/_xtool/llcppsigfetch/parse/cvt_test"
"github.com/goplus/llcppg/_xtool/llcppsymg/clangutils"
)

func main() {
TestInclude()
}

func TestInclude() {
test.RunTestWithConfig(&clangutils.Config{
File: "./hfile/temp.h",
Temp: false,
IsCpp: false,
})
}
Loading
Loading