llcppsigfetch:basic class & struct 's process

This commit is contained in:
luoliwoshang
2024-08-15 18:21:09 +08:00
parent 762ed994c1
commit 9087dac6fe
4 changed files with 691 additions and 41 deletions

View File

@@ -9,6 +9,8 @@ func main() {
TestFuncDecl()
TestScope()
TestComment()
TestStructDecl()
TestClassDecl()
}
func TestFuncDecl() {
@@ -54,6 +56,14 @@ func TestScope() {
void foo();
}
}`,
`class a {
void foo();
};`,
`namespace a {
class b {
void foo();
};
}`,
}
for i, content := range testCases {
@@ -73,6 +83,7 @@ func TestScope() {
converter.Dispose()
}
}
func TestComment() {
testCases := []string{
`// not read comment 1
@@ -118,3 +129,68 @@ void foo();`,
converter.Dispose()
}
}
func TestStructDecl() {
testCases := []string{
`struct A {
int a;
int b;
};`,
`struct A {
int a, b;
};`,
`struct A {
int a;
int b;
float foo(int a,double b);;
};`,
}
for i, content := range testCases {
converter, err := parse.NewConverter(content, true)
if err != nil {
panic(err)
}
_, err = converter.Convert()
if err != nil {
panic(err)
}
json := converter.GetFilesJSON()
c.Printf(c.Str("TestStructDecl Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
converter.Dispose()
}
}
func TestClassDecl() {
testCases := []string{
`class A {
int a;
int b;
};`,
`class A {
int a;
int b;
float foo(int a,double b);;
};`,
}
for i, content := range testCases {
converter, err := parse.NewConverter(content, true)
if err != nil {
panic(err)
}
_, err = converter.Convert()
if err != nil {
panic(err)
}
json := converter.GetFilesJSON()
c.Printf(c.Str("TestClassDecl Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
converter.Dispose()
}
}

View File

@@ -51,8 +51,12 @@ TestFuncDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
@@ -91,8 +95,12 @@ TestFuncDecl Case 3:
"Kind": 6,
"Flags": 0
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
@@ -101,8 +109,12 @@ TestFuncDecl Case 3:
"Kind": 8,
"Flags": 16
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
@@ -143,8 +155,12 @@ TestFuncDecl Case 4:
"Flags": 1
}
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "str"
}]
@@ -153,8 +169,12 @@ TestFuncDecl Case 4:
"Kind": 8,
"Flags": 16
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "x"
}]
@@ -195,8 +215,12 @@ TestFuncDecl Case 5:
"Flags": 1
}
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "str"
}]
@@ -205,8 +229,12 @@ TestFuncDecl Case 5:
"Kind": 8,
"Flags": 16
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "x"
}]
@@ -253,8 +281,12 @@ TestFuncDecl Case 6:
}
}
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "str"
}]
@@ -263,8 +295,12 @@ TestFuncDecl Case 6:
"Kind": 8,
"Flags": 16
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "x"
}]
@@ -308,8 +344,12 @@ TestFuncDecl Case 7:
},
"Len": null
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "str"
}]
@@ -318,8 +358,12 @@ TestFuncDecl Case 7:
"Kind": 8,
"Flags": 16
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "x"
}]
@@ -372,8 +416,12 @@ TestFuncDecl Case 8:
"Value": "3"
}
},
"Doc": null,
"Comment": null,
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "arr"
}]
@@ -491,6 +539,110 @@ TestScope Case 3:
}
}
TestScope Case 4:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": {
"Name": "a"
},
"Tag": 3,
"Fields": {
"List": []
},
"Methods": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": {
"Name": "a"
},
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": []
},
"Ret": {
"Kind": 0,
"Flags": 0
}
}
}]
}],
"includes": [],
"macros": []
}
}
TestScope Case 5:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": {
"X": {
"Name": "b"
},
"Parent": {
"Name": "a"
}
},
"Tag": 3,
"Fields": {
"List": []
},
"Methods": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": {
"X": {
"Name": "b"
},
"Parent": {
"Name": "a"
}
},
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": []
},
"Ret": {
"Kind": 0,
"Flags": 0
}
}
}]
}],
"includes": [],
"macros": []
}
}
TestComment Case 1:
{
"temp.h": {
@@ -787,6 +939,363 @@ TestComment Case 9:
}
}
TestStructDecl Case 1:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Tag": 0,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": []
}],
"includes": [],
"macros": []
}
}
TestStructDecl Case 2:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Tag": 0,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": []
}],
"includes": [],
"macros": []
}
}
TestStructDecl Case 3:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Tag": 0,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 8,
"Flags": 16
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Ret": {
"Kind": 8,
"Flags": 0
}
}
}]
}],
"includes": [],
"macros": []
}
}
TestClassDecl Case 1:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": {
"Name": "A"
},
"Tag": 3,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": []
}],
"includes": [],
"macros": []
}
}
TestClassDecl Case 2:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": {
"Name": "A"
},
"Tag": 3,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": {
"Name": "A"
},
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 8,
"Flags": 16
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Ret": {
"Kind": 8,
"Flags": 0
}
}
}]
}],
"includes": [],
"macros": []
}
}
#stderr