Skip to content

Commit

Permalink
Ignore keywords when part of a variable name (#887)
Browse files Browse the repository at this point in the history
Fixes #886
  • Loading branch information
mpictor committed Aug 14, 2021
1 parent 5fb446c commit 5420ffa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions types/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -570,6 +571,13 @@ func ParseFunction(s string) (f []string, r []string, err error) {
return
}

var (
rxconst = regexp.MustCompile(`\bconst\b`)
rxvolatile = regexp.MustCompile(`\bvolatile\b`)
rxUUrestrict = regexp.MustCompile(`\b__restrict\b`)
rxrestrict = regexp.MustCompile(`\brestrict\b`)
)

// CleanCType - remove from C type not Go type
func CleanCType(s string) (out string) {
out = s
Expand All @@ -583,10 +591,10 @@ func CleanCType(s string) (out string) {
out = strings.Replace(out, "( *)", "(*)", -1)

// Remove any whitespace or attributes that are not relevant to Go.
out = strings.Replace(out, "const", "", -1)
out = strings.Replace(out, "volatile", "", -1)
out = strings.Replace(out, "__restrict", "", -1)
out = strings.Replace(out, "restrict", "", -1)
out = rxconst.ReplaceAllLiteralString(out, "")
out = rxvolatile.ReplaceAllLiteralString(out, "")
out = rxUUrestrict.ReplaceAllLiteralString(out, "")
out = rxrestrict.ReplaceAllLiteralString(out, "")
out = strings.Replace(out, "\t", "", -1)
out = strings.Replace(out, "\n", "", -1)
out = strings.Replace(out, "\r", "", -1)
Expand Down

0 comments on commit 5420ffa

Please sign in to comment.