Skip to content

Commit

Permalink
llcppg/codegen:avoid re typedef in gogensig for correct USR ref
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Jan 24, 2025
1 parent 02ef032 commit ef18c3b
Show file tree
Hide file tree
Showing 10 changed files with 602 additions and 66 deletions.
13 changes: 0 additions & 13 deletions _xtool/llcppsigfetch/parse/cvt.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,6 @@ func (ct *Converter) ProcessUnderlyingType(cursor clang.Cursor) ast.Expr {
underName := toStr(referTypeCursor.String())
ct.logln("ProcessUnderlyingType: defName:", defName, "underName:", underName)

// For a typedef like "typedef struct xxx xxx;", the underlying type declaration
// can appear in two locations:
// 1. Inside the typedef itself when the struct is defined inline
// 2. At the implementation location when there's a separate struct xxx definition
// in the source file
// Therefore, we shouldn't use declaration location to determine whether to remove
// extra typedef nodes

if defName == underName {
ct.logln("ProcessUnderlyingType: is self reference")
return nil
}

return ct.ProcessElaboratedType(underlyingTyp)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "bar",
"USR": "c:forwarddecl.h@T@bar"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "bar",
"USR": "c:@S@bar"
},
"Tag": 0
}
}, {
"_Type": "TypeDecl",
"Loc": {
Expand Down Expand Up @@ -110,6 +132,28 @@
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "sqlite3_pcache_page",
"USR": "c:forwarddecl.h@T@sqlite3_pcache_page"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "sqlite3_pcache_page",
"USR": "c:@S@sqlite3_pcache_page"
},
"Tag": 0
}
}, {
"_Type": "TypeDecl",
"Loc": {
Expand Down Expand Up @@ -173,6 +217,28 @@
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "sqlite3_pcache",
"USR": "c:forwarddecl.h@T@sqlite3_pcache"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "sqlite3_pcache",
"USR": "c:@S@sqlite3_pcache"
},
"Tag": 0
}
}, {
"_Type": "TypeDecl",
"Loc": {
Expand All @@ -195,6 +261,28 @@
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "sqlite3_pcache_methods2",
"USR": "c:forwarddecl.h@T@sqlite3_pcache_methods2"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "sqlite3_pcache_methods2",
"USR": "c:@S@sqlite3_pcache_methods2"
},
"Tag": 0
}
}, {
"_Type": "TypeDecl",
"Loc": {
Expand Down Expand Up @@ -361,6 +449,28 @@
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "sqlite3_file",
"USR": "c:forwarddecl.h@T@sqlite3_file"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "sqlite3_file",
"USR": "c:@S@sqlite3_file"
},
"Tag": 0
}
}, {
"_Type": "TypeDecl",
"Loc": {
Expand Down Expand Up @@ -402,6 +512,28 @@
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "sqlite3_io_methods",
"USR": "c:forwarddecl.h@T@sqlite3_io_methods"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "sqlite3_io_methods",
"USR": "c:@S@sqlite3_io_methods"
},
"Tag": 0
}
}, {
"_Type": "TypeDecl",
"Loc": {
Expand Down Expand Up @@ -514,6 +646,28 @@
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "lua_State",
"USR": "c:forwarddecl.h@T@lua_State"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "lua_State",
"USR": "c:@S@lua_State"
},
"Tag": 0
}
}, {
"_Type": "TypeDecl",
"Loc": {
Expand All @@ -536,6 +690,28 @@
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/forwarddecl.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "lua_Debug",
"USR": "c:forwarddecl.h@T@lua_Debug"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "lua_Debug",
"USR": "c:@S@lua_Debug"
},
"Tag": 0
}
}, {
"_Type": "FuncDecl",
"Loc": {
Expand Down Expand Up @@ -719,6 +895,28 @@
"doc": {
"_Type": "File",
"decls": [{
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "./hfile/def.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "foo",
"USR": "c:def.h@T@foo"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "foo",
"USR": "c:@S@foo"
},
"Tag": 0
}
}, {
"_Type": "FuncDecl",
"Loc": {
"_Type": "Location",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,28 @@ TestFuncDecl Case 8:
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "temp_8.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "OSSL_CORE_HANDLE",
"USR": "c:temp_8.h@T@OSSL_CORE_HANDLE"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "OSSL_CORE_HANDLE",
"USR": "c:@S@OSSL_CORE_HANDLE"
},
"Tag": 0
}
}, {
"_Type": "TypeDecl",
"Loc": {
Expand All @@ -587,6 +609,28 @@ TestFuncDecl Case 8:
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "temp_8.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "OSSL_DISPATCH",
"USR": "c:temp_8.h@T@OSSL_DISPATCH"
},
"Type": {
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "OSSL_DISPATCH",
"USR": "c:@S@OSSL_DISPATCH"
},
"Tag": 0
}
}, {
"_Type": "TypedefDecl",
"Loc": {
Expand Down
Loading

0 comments on commit ef18c3b

Please sign in to comment.