llcppsigfetch:anonymous elaborated type refer

This commit is contained in:
luoliwoshang
2024-08-27 18:50:51 +08:00
parent 0ac48369fe
commit 9351a1f900
7 changed files with 346 additions and 14 deletions

View File

@@ -226,6 +226,106 @@ TestStructDecl Case 4:
}
}
TestStructDecl Case 5:
{
"temp.h": {
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "Person"
},
"Type": {
"Tag": 0,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "age"
}]
}, {
"Type": {
"Tag": 0,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "year"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "day"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "month"
}]
}]
},
"Methods": []
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "birthday"
}]
}]
},
"Methods": []
}
}],
"includes": [],
"macros": []
}
}
#stderr

View File

@@ -22,6 +22,14 @@ func TestStructDecl() {
int a;
int (*Foo)(int, int);
};`,
`struct Person {
int age;
struct {
int year;
int day;
int month;
} birthday;
};`,
}
test.RunTest("TestStructDecl", testCases)
}

View File

@@ -107,6 +107,106 @@ TestUnionDecl Case 2:
}
}
TestUnionDecl Case 3:
{
"temp.h": {
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "OuterUnion"
},
"Type": {
"Tag": 1,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "i"
}]
}, {
"Type": {
"Kind": 8,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "f"
}]
}, {
"Type": {
"Tag": 1,
"Fields": {
"List": [{
"Type": {
"Kind": 2,
"Flags": 1
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "c"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 32
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "s"
}]
}]
},
"Methods": []
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "inner"
}]
}]
},
"Methods": []
}
}],
"includes": [],
"macros": []
}
}
#stderr

View File

@@ -16,6 +16,14 @@ func TestUnionDecl() {
int a;
int b;
};`,
`union OuterUnion {
int i;
float f;
union {
char c;
short s;
} inner;
};`,
}
test.RunTest("TestUnionDecl", testCases)
}

View File

@@ -105,6 +105,28 @@ Type: struct Foo:
},
"Tag": 0
}
Type: struct (unnamed struct at temp.h:1:1):
{
"Tag": 0,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "x"
}]
}]
},
"Methods": []
}
Type: Foo:
{
"Name": "Foo"
@@ -116,6 +138,28 @@ Type: union Foo:
},
"Tag": 1
}
Type: union (unnamed union at temp.h:1:1):
{
"Tag": 1,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "x"
}]
}]
},
"Methods": []
}
Type: Foo:
{
"Name": "Foo"
@@ -127,6 +171,18 @@ Type: enum Foo:
},
"Tag": 2
}
Type: enum (unnamed enum at temp.h:1:1):
{
"Items": [{
"Name": {
"Name": "x"
},
"Value": {
"Kind": 0,
"Value": "42"
}
}]
}
Type: Foo:
{
"Name": "Foo"
@@ -138,6 +194,28 @@ Type: class Foo:
},
"Tag": 3
}
Type: class (unnamed class at temp.h:1:1):
{
"Tag": 3,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "x"
}]
}]
},
"Methods": []
}
Type: a::b::c:
{
"X": {

View File

@@ -80,21 +80,31 @@ func TestNonBuiltinTypes() {
Foo`,
`struct Foo {};
struct Foo`,
`struct {
int x;
}`,
`union Foo {};
Foo`,
`union Foo {};
union Foo`,
`union {
int x;
}`,
`enum Foo {};
Foo`,
`enum Foo {};
enum Foo`,
`enum { x = 42 }`,
`class Foo {};
Foo`,
`class Foo {};
class Foo`,
`class {
int x;
}`,
`namespace a {
namespace b {
@@ -123,10 +133,12 @@ func TestNonBuiltinTypes() {
expr := converter.ProcessType(typ)
json := parse.MarshalASTExpr(expr)
str := json.Print()
typstr := typ.String()
c.Printf(c.Str("Type: %s:\n"), typ.String())
c.Printf(c.Str("Type: %s:\n"), typstr)
c.Printf(c.Str("%s\n"), str)
typstr.Dispose()
cjson.FreeCStr(str)
json.Delete()
index.Dispose()