提交 027eef0e 编写于 作者: R Richard Wilkes

Cleanup

上级 a36031ce
package main
import (
"regexp"
"sort"
"strings"
"text/template"
......@@ -9,6 +10,11 @@ import (
"github.com/richardwilkes/toolbox/txt"
)
var (
defRegex = regexp.MustCompile(` struct\s+_(cef_\S+)\s+definition$`)
fieldRegex = regexp.MustCompile(`-FieldDecl .*>\s+\S+\s+(\S+)\s+'([^']+)'`)
)
type structDef struct {
Name string
GoName string
......@@ -75,29 +81,17 @@ func translateStructTypeName(name string) string {
}
func processRecordDecl(block []lineInfo) {
line := block[0].Line
if strings.HasSuffix(line, " definition") {
if i := strings.Index(line, " struct _cef_"); i != -1 {
name := line[i+9 : len(line)-11]
if _, exclude := excludeMap[name]; !exclude {
if _, exists := sdefsMap[name]; !exists {
sdef := newStructDef(name, block[0].Position)
for i := 1; i < len(block); i++ {
line = block[i].Line
if len(line) > 3 && strings.HasPrefix(line[3:], "-FieldDecl ") {
if start := strings.Index(line, "> "); start != -1 {
line = line[start+2:]
if space := strings.Index(line, " "); space != -1 {
line = line[space+1:]
if start = strings.Index(line, " "); space != -1 {
sdef.Fields = append(sdef.Fields, newField(sdef, line[:start], strings.Trim(line[start+1:], "'"), block[i].Position))
}
}
}
}
if result := defRegex.FindAllStringSubmatch(block[0].Line, -1); result != nil {
name := result[0][1]
if _, exclude := excludeMap[name]; !exclude {
if _, exists := sdefsMap[name]; !exists {
sdef := newStructDef(name, block[0].Position)
for i := 1; i < len(block); i++ {
if result = fieldRegex.FindAllStringSubmatch(block[i].Line, -1); result != nil {
sdef.Fields = append(sdef.Fields, newField(sdef, result[0][1], result[0][2], block[i].Position))
}
sdefsMap[name] = sdef
}
sdefsMap[name] = sdef
}
}
}
......
......@@ -29,10 +29,10 @@ type variable struct {
func newCVar(name, typeInfo string, pos position) *variable {
name = strings.TrimSpace(name)
typeInfo = strings.Replace(strings.TrimPrefix(strings.Trim(strings.TrimSpace(strings.Replace(typeInfo, "const ", "", -1)), "'"), "struct _"), "long long", "int64_t", -1)
if i := strings.Index(typeInfo, "':'"); i != -1 {
typeInfo = typeInfo[:i]
}
typeInfo = strings.Replace(typeInfo, "const ", "", -1)
typeInfo = strings.TrimSpace(typeInfo)
typeInfo = strings.TrimPrefix(typeInfo, "struct _")
typeInfo = strings.Replace(typeInfo, "long long", "int64_t", -1)
v := &variable{
Name: name,
GoName: txt.ToCamelCase(name),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册