llcppsigfetch:lvalue & rvalue refer

This commit is contained in:
luoliwoshang
2024-08-22 12:15:06 +08:00
parent 0a8e25b405
commit a4f850c0c6
4 changed files with 99 additions and 0 deletions

View File

@@ -237,6 +237,8 @@ func (ct *Converter) ProcessType(t clang.Type) ast.Expr {
switch t.Kind { switch t.Kind {
case clang.TypePointer: case clang.TypePointer:
expr = &ast.PointerType{X: ct.ProcessType(t.PointeeType())} expr = &ast.PointerType{X: ct.ProcessType(t.PointeeType())}
case clang.TypeLValueReference, clang.TypeRValueReference:
expr = &ast.LvalueRefType{X: ct.ProcessType(t.NonReferenceType())}
case clang.TypeFunctionProto: case clang.TypeFunctionProto:
// function type will only collect return type, params will be collected in ProcessFunc // function type will only collect return type, params will be collected in ProcessFunc
ret := ct.ProcessType(t.ResultType()) ret := ct.ProcessType(t.ResultType())

View File

@@ -18,6 +18,9 @@ func TestFuncDecl() {
`void foo(char str[]);`, `void foo(char str[]);`,
`void foo(int arr[3][4]);`, `void foo(int arr[3][4]);`,
`void foo(int& a);`,
`void foo(int&& a);`,
} }
test.RunTest("TestFuncDecl", testCases) test.RunTest("TestFuncDecl", testCases)
} }

View File

@@ -384,6 +384,96 @@ TestFuncDecl Case 8:
} }
} }
TestFuncDecl Case 9:
{
"temp.h": {
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
"X": {
"Kind": 6,
"Flags": 0
}
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}]
},
"Ret": {
"Kind": 0,
"Flags": 0
}
}
}],
"includes": [],
"macros": []
}
}
TestFuncDecl Case 10:
{
"temp.h": {
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
"X": {
"Kind": 6,
"Flags": 0
}
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}]
},
"Ret": {
"Kind": 0,
"Flags": 0
}
}
}],
"includes": [],
"macros": []
}
}
#stderr #stderr

View File

@@ -146,6 +146,10 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
case *ast.BasicLit: case *ast.BasicLit:
root.SetItem(c.Str("Kind"), cjson.Number(float64(d.Kind))) root.SetItem(c.Str("Kind"), cjson.Number(float64(d.Kind)))
root.SetItem(c.Str("Value"), cjson.String(c.AllocaCStr(d.Value))) root.SetItem(c.Str("Value"), cjson.String(c.AllocaCStr(d.Value)))
case *ast.LvalueRefType:
root.SetItem(c.Str("X"), MarshalASTExpr(d.X))
case *ast.RvalueRefType:
root.SetItem(c.Str("X"), MarshalASTExpr(d.X))
case *ast.PointerType: case *ast.PointerType:
root.SetItem(c.Str("X"), MarshalASTExpr(d.X)) root.SetItem(c.Str("X"), MarshalASTExpr(d.X))
case *ast.ArrayType: case *ast.ArrayType: