Source File
reader.go
Belonging Package
go/doc
package doc
import (
)
return
type embeddedSet map[*namedType]bool
type namedType struct {
doc string // doc comment for type
name string // type name
decl *ast.GenDecl // nil if declaration hasn't been seen yet
isEmbedded bool // true if this type is embedded
isStruct bool // true if this type is a struct
embedded embeddedSet // true if the embedded type is a pointer
func ( *reader) ( *namedType, ast.Expr) ( string) {
, := baseTypeName()
if == nil || {
return
}
if := .lookupType(); != nil {
.isEmbedded = true
, := .(*ast.StarExpr)
.embedded[] =
}
return
}
if , := baseTypeName(.Type); ! {
=
}
=
}
= ""
break
}
=
++
}
=
++
}
if == 0 {
return
}
:= &.values
const = 0.75
.order++
}
.decl =
:= .Doc
if .mode&PreserveAST == 0 {
.Body = nil
}
return
}
, := baseTypeName(.Recv.List[0].Type)
return
}
if := .lookupType(); != nil {
.methods.set(, .mode&PreserveAST != 0)
return
}
= .Elt
}
if , := baseTypeName(); ! && .isVisible() && !.isPredeclared() {
if := .lookupType(); != nil {
=
++
if > 1 {
break
}
}
}
if == 1 {
.funcs.set(, .mode&PreserveAST != 0)
return
}
}
.funcs.set(, .mode&PreserveAST != 0)
}
var (
noteMarker = `([A-Z][A-Z]+)\(([^)]+)\):?` // MARKER(uid), MARKER at least 2 chars, uid at least 1 char
noteMarkerRx = lazyregexp.New(`^[ \t]*` + noteMarker) // MARKER(uid) at text start
noteCommentRx = lazyregexp.New(`^/[/*][ \t]*` + noteMarker) // MARKER(uid) at comment start
)
func ( *reader) ( []*ast.CommentGroup) {
for , := range {
:= -1 // comment index of most recent note start, valid if >= 0
:= .List
for , := range {
if noteCommentRx.MatchString(.Text) {
if >= 0 {
.readNote([:])
}
=
}
}
if >= 0 {
.readNote([:])
}
}
}
.readValue()
for , := range .filenames {
:= .Files[]
if &AllDecls == 0 {
.fileExports()
}
.readFile()
}
:= *
.Decl = &
.Level =
return &
}
:= ||
if .Level == 0 {
.add(customizeRecv(, , , ))
}
}
if ![] {
.(, , , , +1, )
}
}
delete(, )
}
func ( *reader) () {
.collectEmbeddedMethods(.methods, , .name, false, 1, make(embeddedSet))
}
}
if .errorDecl {
for , := range .fixlist {
removeErrorField()
}
}
}
.funcs[] =
if ! {
func ( *ast.GenDecl) string {
if len(.Specs) == 1 {
if , := .Specs[0].(*ast.ValueSpec); {
return .Names[0].Name
}
}
return ""
}
func ( []*Value, token.Token) []*Value {
:= make([]*Value, len()) // big enough in any case
:= 0
for , := range {
if .Decl.Tok == {
[] =
++
}
}
= [0:]
sortBy(
func(, int) bool {
if , := sortingName([].Decl), sortingName([].Decl); != {
return <
}
return [].order < [].order
},
func(, int) { [], [] = [], [] },
len(),
)
return
}
func ( map[string]*namedType, bool) []*Type {
:= make([]*Type, len())
:= 0
for , := range {
[] = &Type{
Doc: .doc,
Name: .name,
Decl: .decl,
Consts: sortedValues(.values, token.CONST),
Vars: sortedValues(.values, token.VAR),
Funcs: sortedFuncs(.funcs, true),
Methods: sortedFuncs(.methods, ),
}
++
}
sortBy(
func(, int) bool { return [].Name < [].Name },
func(, int) { [], [] = [], [] },
len(),
)
return
}
func ( string) string {
if len() > 0 && [0] == '*' {
return [1:]
}
return
}
func ( methodSet, bool) []*Func {
:= make([]*Func, len())
:= 0
switch {
func ( string) bool {
return predeclaredTypes[] || predeclaredFuncs[] || predeclaredConstants[]
}
var predeclaredTypes = map[string]bool{
"bool": true,
"byte": true,
"complex64": true,
"complex128": true,
"error": true,
"float32": true,
"float64": true,
"int": true,
"int8": true,
"int16": true,
"int32": true,
"int64": true,
"rune": true,
"string": true,
"uint": true,
"uint8": true,
"uint16": true,
"uint32": true,
"uint64": true,
"uintptr": true,
}
var predeclaredFuncs = map[string]bool{
"append": true,
"cap": true,
"close": true,
"complex": true,
"copy": true,
"delete": true,
"imag": true,
"len": true,
"make": true,
"new": true,
"panic": true,
"print": true,
"println": true,
"real": true,
"recover": true,
}
var predeclaredConstants = map[string]bool{
"false": true,
"iota": true,
"nil": true,
"true": true,
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |