Update to Big Sur 15.5.2 / Clang 12.0.5. Improved handing of avaiability

attributes and boolean values.
This commit is contained in:
gmp
2021-11-16 16:02:08 -05:00
parent f4a9dae250
commit e4f7e32887
21 changed files with 482 additions and 9157 deletions
+1 -4
View File
@@ -453,7 +453,7 @@ func GoToC(sname, name string, pnames, snames []string, rtype *Type, ptypes []*T
ret.ptr = unsafe.Pointer(`, rtgt[1:]))
default:
if rtgt == "BOOL" {
ret.WriteString("ret := (")
ret.WriteString("ret := (bool)(")
rtgt = "bool"
} else {
ret.WriteString("ret := (" + rtgt + ")(")
@@ -501,9 +501,6 @@ func GoToC(sname, name string, pnames, snames []string, rtype *Type, ptypes []*T
if isptr {
ret.WriteString(")")
}
if rt == "BOOL" {
ret.WriteString(" != 0")
}
for i, sname := range snames {
if sname == "" {
continue
+1 -1
View File
@@ -286,7 +286,7 @@ func (o *Id) NSString() *NSString {
rtype = bl
chk_gotoc(
`ret := (C.myFun(p1.Ptr(), p2.Ptr(), (C.int)(p3), unsafe.Pointer(p4))) != 0
`ret := (bool)(C.myFun(p1.Ptr(), p2.Ptr(), (C.int)(p3), unsafe.Pointer(p4)))
runtime.KeepAlive(o)
return ret`)
+85
View File
@@ -37,6 +37,7 @@ func MethodSignature(s string, n *Node) (string, *Node) {
Parenthesized(TypeName),
Identifier,
Opt(MethodParameterList),
Opt(Word("NS_RETURNS_INNER_POINTER")),
))(s, n)
}
@@ -66,6 +67,16 @@ func MethodParameter(s string, n *Node) (string, *Node) {
func _TypeName(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("TypeName"), Seq(
Opt(APIAvailable),
Opt(APIUnavailable),
Opt(SwiftUnavailable),
Opt(APIDeprecated),
Opt(APIDeprecatedWithReplacement),
Opt(NSAvailable),
Opt(NSAvailableMac),
Opt(NSDeprecated),
Opt(DispatchReturns),
Opt(ReturnsInnerPointer),
SpecifierQualifierList,
Opt(AbstractDeclarator),
))(s, n)
@@ -256,6 +267,80 @@ func TypeQualifier(s string, n *Node) (string, *Node) {
))(s, n)
}
func APIAvailable(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("APIAvailable"), Seq(
Word("API_AVAILABLE"),
Parenthesized(NodeNamed("Version",Regexp(`\w+\(\d+(\.\d+(\.\d+)?)?\)`))),
))(s, n)
}
func APIUnavailable(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("APIUnavailable"), Seq(
Word("API_UNAVAILABLE"),
Parenthesized(NodeNamed("Version",Regexp(`[^)]*`))),
))(s, n)
}
func APIDeprecated(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("APIDeprecated"), Seq(
NodeNamed("APIDeprecated",Regexp(`API_DEPRECATED`)),
Parenthesized(Seq(
NodeNamed("Message",Regexp(`"[^"]*"`)),
Lit(","),
NodeNamed("Version",Regexp(`\w+\(\d+(\.\d+)?,\s*((\d+(\.\d+)?)|(API_TO_BE_DEPRECATED))\)`)),
)),
))(s, n)
}
func APIDeprecatedWithReplacement(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("APIDeprecated"), Seq(
NodeNamed("APIDeprecated",Regexp(`API_DEPRECATED_WITH_REPLACEMENT`)),
Parenthesized(Seq(
NodeNamed("Message",Regexp(`"[^"]*"`)),
Lit(","),
NodeNamed("Version",Regexp(`\w+\(\d+(\.\d+)?,\s*((\d+(\.\d+)?)|(API_TO_BE_DEPRECATED))\)`)),
)),
))(s, n)
}
func SwiftUnavailable(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("SwiftUnavailable"), Seq(
Word("NS_SWIFT_UNAVAILABLE"),
Parenthesized(NodeNamed("Message",Regexp(`[^)]*`))),
))(s, n)
}
func NSAvailable(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("NSAvailable"), Seq(
Word("NS_AVAILABLE"),
Parenthesized(NodeNamed("Versions",Regexp(`\d+_\d+(,\s*\d+_\d+)?`))),
))(s, n)
}
func NSAvailableMac(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("NSAvailableMac"), Seq(
Word("NS_AVAILABLE_MAC"),
Parenthesized(NodeNamed("Versions",Regexp(`\d+_\d+(,\s*\d+_\d+)?`))),
))(s, n)
}
func NSDeprecated(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("NSDeprecated"), Seq(
Word("NS_DEPRECATED"),
Parenthesized(NodeNamed("Versions",Regexp(`\d+_\d+(,\s*\d+_\d+(,\s*\d+_\d+(,\s*\d+_\d+)?)?)?`))),
))(s, n)
}
func DispatchReturns(s string, n *Node) (string, *Node) {
return NodeNamed("DispatchReturns",Regexp("DISPATCH_[A-Z_]+"))(s, n)
}
func ReturnsInnerPointer(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("ReturnsInnerPointer"),
Word("NS_RETURNS_INNER_POINTER"),
)(s, n)
}
func StructOrUnionSpecifier(s string, n *Node) (string, *Node) {
return OneOf(
// Seq(StructOrUnion,Opt(Identifier),StructDeclarationList),
+13 -6
View File
@@ -117,13 +117,22 @@ func (n *Node) IsArray() bool {
return n.ArrayOf() != nil
}
func isQualifier(s string) bool {
return (s == "KindQualifier" ||
s == "APIAvailable" ||
s == "APIUnavailable" ||
s == "APIDeprecated" ||
s == "SwiftUnavailable" ||
s == "NSAvailable" ||
s == "NSAvailableMac")
}
func (n *Node) IsStruct() bool {
if n == nil || len(n.Children) < 1 {
return false
}
i := 0
for ; i < len(n.Children) &&
n.Children[i].Kind == "KindQualifier"; i++ {
for ; i < len(n.Children) && isQualifier(n.Children[i].Kind); i++ {
}
return n.Children[i].Kind == "Struct"
}
@@ -152,8 +161,7 @@ func (n *Node) IsId() bool {
return false
}
i := 0
for ; i < len(n.Children) &&
n.Children[i].Kind == "KindQualifier"; i++ {
for ; i < len(n.Children) && isQualifier(n.Children[i].Kind); i++ {
}
return !n.IsFunction() &&
n.Children[i].Kind == "TypedefName" &&
@@ -165,8 +173,7 @@ func (n *Node) IsInstancetype() bool {
return false
}
i := 0
for ; i < len(n.Children) &&
n.Children[i].Kind == "KindQualifier"; i++ {
for ; i < len(n.Children) && isQualifier(n.Children[i].Kind); i++ {
}
return n.Children[i].Kind == "TypedefName" &&
n.Children[i].Content == "instancetype"
+10
View File
@@ -127,6 +127,16 @@ func (n *Node) _CType(ignore map[string]bool) string {
return ret
}
switch n.Kind {
case "APIAvailable":
case "DispatchReturns":
case "APIUnavailable":
case "APIDeprecated":
case "APIDeprecatedWithReplacement":
case "NSAvailable":
case "NSAvailableMac":
case "NSDeprecated":
case "SwiftUnavailable":
case "ReturnsInnerPointer":
case "Parenthesized":
ret.WriteString("(" + strings.Join(childStrings(n), " ") + ")")
case "Function":