Skip to content

Commit

Permalink
Workaround issue #100 in cc
Browse files Browse the repository at this point in the history
cc parses function pointer declarations slightly incorrectly, which causes
function pointers that return typedefs to simply be typed as the typedef in
c-for-go. This change works around that bug by having the typedef name lookup
function not return the typedef name if the type is a function and wasn't
declared using a typedef.
  • Loading branch information
Zvi Effron committed May 20, 2017
1 parent f5b4843 commit d9011c6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions translator/ast_walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ func memberName(n int, m cc.Member) string {
}

func typedefNameOf(typ cc.Type) string {
// There is a bug in cc's parser that causes it to misidentify the type of
// a function pointer as its return type.
// (See https://github.com/cznic/cc/issues/100)
// To work around this bug, we first check if the type is a function and if
// so, verify it's declared via a typedef before proceeding to get the
// typedef's name.
if typ.Kind() == cc.Function && typ.Declarator().DirectDeclarator.Case != 0 {
return ""
}
rawSpec := typ.Declarator().RawSpecifier()
if name := rawSpec.TypedefName(); name > 0 {
return blessName(xc.Dict.S(name))
Expand Down

0 comments on commit d9011c6

Please sign in to comment.