feat(lint): abi0 register-args rule and go-asm width model
This commit is contained in:
+42
-7
@@ -25,18 +25,53 @@ func abiExpectedArgSize(doc string) (int64, bool) {
|
||||
if sig == "" {
|
||||
return 0, false
|
||||
}
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, "sig.go", "package p\n"+sig+" {}\n", 0)
|
||||
if err != nil || len(f.Decls) == 0 {
|
||||
return 0, false
|
||||
}
|
||||
fn, ok := f.Decls[0].(*ast.FuncDecl)
|
||||
if !ok || fn.Type == nil {
|
||||
fn, ok := parseSignature(sig)
|
||||
if !ok || fn == nil {
|
||||
return 0, false
|
||||
}
|
||||
return signatureSize(fn.Type.Params, fn.Type.Results)
|
||||
}
|
||||
|
||||
// abiParamNames returns the parameter names declared by the `// func …`
|
||||
// signature in a doc comment, in declaration order. Shared names
|
||||
// (`left, right []int32`) expand to one entry per name; a nameless parameter
|
||||
// (`[]int32`) contributes an empty placeholder so offsets stay aligned.
|
||||
func abiParamNames(doc string) ([]string, bool) {
|
||||
sig := signatureLine(doc)
|
||||
if sig == "" {
|
||||
return nil, false
|
||||
}
|
||||
fn, ok := parseSignature(sig)
|
||||
if !ok || fn == nil || fn.Type.Params == nil {
|
||||
return nil, false
|
||||
}
|
||||
var names []string
|
||||
for _, field := range fn.Type.Params.List {
|
||||
if len(field.Names) == 0 {
|
||||
names = append(names, "")
|
||||
continue
|
||||
}
|
||||
for _, n := range field.Names {
|
||||
names = append(names, n.Name)
|
||||
}
|
||||
}
|
||||
return names, true
|
||||
}
|
||||
|
||||
// parseSignature parses a `func …` line into a Go FuncDecl.
|
||||
func parseSignature(sig string) (*ast.FuncDecl, bool) {
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, "sig.go", "package p\n"+sig+" {}\n", 0)
|
||||
if err != nil || len(f.Decls) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
fn, ok := f.Decls[0].(*ast.FuncDecl)
|
||||
if !ok || fn.Type == nil {
|
||||
return nil, false
|
||||
}
|
||||
return fn, true
|
||||
}
|
||||
|
||||
// signatureLine returns the first `func …` line from a doc comment, trimmed.
|
||||
func signatureLine(doc string) string {
|
||||
for _, line := range strings.Split(doc, "\n") {
|
||||
|
||||
Reference in New Issue
Block a user