llcppsigfetch:typedef refer same anony struct & fix typedef 's underlying token out of bound

This commit is contained in:
luoliwoshang
2024-11-20 16:58:18 +08:00
parent 97c61404ca
commit bf34f553bb
6 changed files with 216 additions and 413 deletions

View File

@@ -484,39 +484,6 @@ TestTypeDefDecl Case 7:
},
"Doc": null,
"Parent": null,
"Name": null,
"Type": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "temp.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "MyStruct"
@@ -563,39 +530,6 @@ TestTypeDefDecl Case 8:
},
"Doc": null,
"Parent": null,
"Name": null,
"Type": {
"_Type": "RecordType",
"Tag": 1,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "temp.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "MyUnion"
@@ -642,52 +576,6 @@ TestTypeDefDecl Case 9:
},
"Doc": null,
"Parent": null,
"Name": null,
"Type": {
"_Type": "EnumType",
"Items": [{
"_Type": "EnumItem",
"Name": {
"_Type": "Ident",
"Name": "RED"
},
"Value": {
"_Type": "BasicLit",
"Kind": 0,
"Value": "0"
}
}, {
"_Type": "EnumItem",
"Name": {
"_Type": "Ident",
"Name": "GREEN"
},
"Value": {
"_Type": "BasicLit",
"Kind": 0,
"Value": "1"
}
}, {
"_Type": "EnumItem",
"Name": {
"_Type": "Ident",
"Name": "BLUE"
},
"Value": {
"_Type": "BasicLit",
"Kind": 0,
"Value": "2"
}
}]
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "temp.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "MyEnum"
@@ -747,39 +635,6 @@ TestTypeDefDecl Case 10:
},
"Doc": null,
"Parent": null,
"Name": null,
"Type": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "temp.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "MyStruct"
@@ -821,28 +676,12 @@ TestTypeDefDecl Case 10:
"Name": "MyStruct2"
},
"Type": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "MyStruct"
},
"Methods": []
"Tag": 0
}
}, {
"_Type": "TypedefDecl",
@@ -859,28 +698,12 @@ TestTypeDefDecl Case 10:
"Type": {
"_Type": "PointerType",
"X": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "MyStruct"
},
"Methods": []
"Tag": 0
}
}
}, {
@@ -898,28 +721,12 @@ TestTypeDefDecl Case 10:
"Type": {
"_Type": "ArrayType",
"Elt": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
"_Type": "TagExpr",
"Name": {
"_Type": "Ident",
"Name": "MyStruct"
},
"Methods": []
"Tag": 0
},
"Len": null
}
@@ -951,49 +758,6 @@ TestTypeDefDecl Case 11:
"Name": "A"
}
},
"Name": null,
"Type": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
},
"Methods": []
}
}, {
"_Type": "TypedefDecl",
"Loc": {
"_Type": "Location",
"File": "temp.h"
},
"Doc": null,
"Parent": {
"_Type": "ScopingExpr",
"X": {
"_Type": "Ident",
"Name": "B"
},
"Parent": {
"_Type": "Ident",
"Name": "A"
}
},
"Name": {
"_Type": "Ident",
"Name": "MyStruct"
@@ -1045,28 +809,26 @@ TestTypeDefDecl Case 11:
"Name": "MyStruct2"
},
"Type": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
"_Type": "TagExpr",
"Name": {
"_Type": "ScopingExpr",
"X": {
"_Type": "Ident",
"Name": "MyStruct"
},
"Parent": {
"_Type": "ScopingExpr",
"X": {
"_Type": "Ident",
"Name": "B"
},
"Parent": {
"_Type": "Ident",
"Name": "A"
}
}
},
"Methods": []
"Tag": 0
}
}, {
"_Type": "TypedefDecl",
@@ -1093,28 +855,26 @@ TestTypeDefDecl Case 11:
"Type": {
"_Type": "PointerType",
"X": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
"_Type": "TagExpr",
"Name": {
"_Type": "ScopingExpr",
"X": {
"_Type": "Ident",
"Name": "MyStruct"
},
"Parent": {
"_Type": "ScopingExpr",
"X": {
"_Type": "Ident",
"Name": "B"
},
"Parent": {
"_Type": "Ident",
"Name": "A"
}
}
},
"Methods": []
"Tag": 0
}
}
}, {
@@ -1142,28 +902,26 @@ TestTypeDefDecl Case 11:
"Type": {
"_Type": "ArrayType",
"Elt": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "x"
}]
}]
"_Type": "TagExpr",
"Name": {
"_Type": "ScopingExpr",
"X": {
"_Type": "Ident",
"Name": "MyStruct"
},
"Parent": {
"_Type": "ScopingExpr",
"X": {
"_Type": "Ident",
"Name": "B"
},
"Parent": {
"_Type": "Ident",
"Name": "A"
}
}
},
"Methods": []
"Tag": 0
},
"Len": null
}

View File

@@ -118,6 +118,113 @@ TestInclude Case 1:
}
}
TestMacroExpansionOtherFile:
{
"./testdata/macroexpan/ref.h": {
"_Type": "File",
"decls": [{
"_Type": "TypeDecl",
"Loc": {
"_Type": "Location",
"File": "./testdata/macroexpan/ref.h"
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
"Name": "NewType"
},
"Type": {
"_Type": "RecordType",
"Tag": 0,
"Fields": {
"_Type": "FieldList",
"List": [{
"_Type": "Field",
"Type": {
"_Type": "ArrayType",
"Elt": {
"_Type": "BuiltinType",
"Kind": 6,
"Flags": 0
},
"Len": {
"_Type": "BasicLit",
"Kind": 0,
"Value": "2"
}
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
"_Type": "Ident",
"Name": "__val"
}]
}]
},
"Methods": []
}
}],
"includes": [{
"_Type": "Include",
"Path": "def.h"
}],
"macros": []
},
"./testdata/macroexpan/def.h": {
"_Type": "File",
"decls": [],
"includes": [],
"macros": [{
"_Type": "Macro",
"Name": "__FSID_T_TYPE",
"Tokens": [{
"_Type": "Token",
"Token": 3,
"Lit": "__FSID_T_TYPE"
}, {
"_Type": "Token",
"Token": 2,
"Lit": "struct"
}, {
"_Type": "Token",
"Token": 1,
"Lit": "{"
}, {
"_Type": "Token",
"Token": 2,
"Lit": "int"
}, {
"_Type": "Token",
"Token": 3,
"Lit": "__val"
}, {
"_Type": "Token",
"Token": 1,
"Lit": "["
}, {
"_Type": "Token",
"Token": 4,
"Lit": "2"
}, {
"_Type": "Token",
"Token": 1,
"Lit": "]"
}, {
"_Type": "Token",
"Token": 1,
"Lit": ";"
}, {
"_Type": "Token",
"Token": 1,
"Lit": "}"
}]
}]
}
}
#stderr

View File

@@ -1,12 +1,15 @@
package main
import (
"github.com/goplus/llgo/c"
test "github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse/cvt_test"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/clangutils"
)
func main() {
TestDefine()
TestInclude()
TestMacroExpansionOtherFile()
}
func TestDefine() {
@@ -25,3 +28,12 @@ func TestInclude() {
}
test.RunTest("TestInclude", testCases)
}
func TestMacroExpansionOtherFile() {
c.Printf(c.Str("TestMacroExpansionOtherFile:\n"))
test.RunTestWithConfig(&clangutils.Config{
File: "./testdata/macroexpan/ref.h",
Temp: false,
IsCpp: false,
})
}

View File

@@ -0,0 +1,4 @@
#define __FSID_T_TYPE \
struct { \
int __val[2]; \
}

View File

@@ -0,0 +1,2 @@
#include "def.h"
typedef __FSID_T_TYPE NewType;