feat(verify): add --call and --buf flags for single-function invocation
Assisted-by: GLM 5.2
This commit is contained in:
+31
-7
@@ -44,25 +44,49 @@ func ParseFuncSig(comment string) (FuncSig, bool) {
|
||||
return sig, true
|
||||
}
|
||||
|
||||
// parseParamsExported splits "a []byte, b []int32" into typed parameters.
|
||||
// parseParamsExported splits a parameter list like "a []byte, b []int32" or
|
||||
// "dst, src []byte" into typed parameters. Go syntax allows grouped names
|
||||
// where the type at the end applies to every name in the group:// "dst, src []byte" means both dst and src are []byte.
|
||||
func parseParamsExported(s string) []Param {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
fields := strings.Split(s, ",")
|
||||
// First pass: extract the type from each field (if present).
|
||||
types := make([]string, len(fields))
|
||||
for i, field := range fields {
|
||||
parts := strings.Fields(strings.TrimSpace(field))
|
||||
if len(parts) >= 2 {
|
||||
types[i] = parts[len(parts)-1]
|
||||
}
|
||||
}
|
||||
// Propagate types backward: a field without a type inherits the type from
|
||||
// the next field that has one (e.g. "dst" inherits "[]byte" from "src []byte").
|
||||
for i := range fields {
|
||||
if types[i] == "" {
|
||||
for j := i + 1; j < len(fields); j++ {
|
||||
if types[j] != "" {
|
||||
types[i] = types[j]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Second pass: build params.
|
||||
var out []Param
|
||||
for _, field := range strings.Split(s, ",") {
|
||||
for i, field := range fields {
|
||||
field = strings.TrimSpace(field)
|
||||
if field == "" {
|
||||
continue
|
||||
}
|
||||
parts := strings.Fields(field)
|
||||
if len(parts) == 1 {
|
||||
// Unnamed: "int" or "[]byte".
|
||||
out = append(out, Param{Typ: parts[0]})
|
||||
typ := types[i]
|
||||
if typ == "" {
|
||||
typ = parts[0] // unnamed: the whole field is the type
|
||||
out = append(out, Param{Typ: typ})
|
||||
} else {
|
||||
// Named: "a []byte".
|
||||
out = append(out, Param{Name: parts[0], Typ: parts[1]})
|
||||
out = append(out, Param{Name: parts[0], Typ: typ})
|
||||
}
|
||||
}
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user