feat(lint): eleven new rules over directives, data and addressing
Assisted-by: GLM 5.3
This commit is contained in:
+52
@@ -67,6 +67,58 @@ func abiParamNames(doc string) ([]string, bool) {
|
||||
return names, true
|
||||
}
|
||||
|
||||
// resultSlot is one named result of a // func signature and the byte range
|
||||
// its ABI0 stack slot occupies, relative to FP.
|
||||
type resultSlot struct {
|
||||
name string
|
||||
off int64
|
||||
size int64
|
||||
}
|
||||
|
||||
// abiResultSlots lays out the named result slots of the `// func …`
|
||||
// signature in a doc comment: parameters first, then the result area on a
|
||||
// word (8-byte) boundary, matching the ABI0 stack layout signatureSize
|
||||
// computes. A nameless result field contributes no slot; it is the field
|
||||
// the generic ret spelling documents. It returns ok=false when there is no
|
||||
// parseable signature or a type size cannot be determined.
|
||||
func abiResultSlots(doc string) ([]resultSlot, bool) {
|
||||
sig := signatureLine(doc)
|
||||
if sig == "" {
|
||||
return nil, false
|
||||
}
|
||||
fn, ok := parseSignature(sig)
|
||||
if !ok || fn == nil {
|
||||
return nil, false
|
||||
}
|
||||
paramsSize, _, pok := fieldsSizeAlign(fn.Type.Params)
|
||||
if !pok {
|
||||
return nil, false
|
||||
}
|
||||
results := fn.Type.Results
|
||||
if results == nil || len(results.List) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
off := int64(alignUp(paramsSize, 8))
|
||||
var slots []resultSlot
|
||||
for _, field := range results.List {
|
||||
es, ea, fieldOK := typeSizeAlign(field.Type)
|
||||
if !fieldOK {
|
||||
return nil, false
|
||||
}
|
||||
n := len(field.Names)
|
||||
if n == 0 {
|
||||
off = int64(alignUp(int(off), ea)) + int64(es)
|
||||
continue
|
||||
}
|
||||
for _, nm := range field.Names {
|
||||
off = int64(alignUp(int(off), ea))
|
||||
slots = append(slots, resultSlot{name: nm.Name, off: off, size: int64(es)})
|
||||
off += int64(es)
|
||||
}
|
||||
}
|
||||
return slots, true
|
||||
}
|
||||
|
||||
// parseSignature parses a `func …` line into a Go FuncDecl.
|
||||
func parseSignature(sig string) (*ast.FuncDecl, bool) {
|
||||
fset := token.NewFileSet()
|
||||
|
||||
Reference in New Issue
Block a user