亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

annuaire recherche
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結構heap) container/list(容器數(shù)據(jù)結構list) container/ring(容器數(shù)據(jù)結構ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫/sql) database/sql/driver(數(shù)據(jù)庫/sql/driver) debug debug/dwarf(調試/dwarf) debug/elf(調試/elf) debug/gosym(調試/gosym) debug/macho(調試/macho) debug/pe(調試/pe) debug/plan9obj(調試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達式) regexp/syntax runtime runtime(運行時) runtime/debug(調試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
personnages

  • import "go/ast"

  • 概述

  • 索引

  • 示例

概述

ast包聲明 了用于表示 Go 包的語法樹的類型。

索引

  • func FileExports(src *File) bool

  • func FilterDecl(decl Decl, f Filter) bool

  • func FilterFile(src *File, f Filter) bool

  • func FilterPackage(pkg *Package, f Filter) bool

  • func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) error

  • func Inspect(node Node, f func(Node) bool)

  • func IsExported(name string) bool

  • func NotNilFilter(_ string, v reflect.Value) bool

  • func PackageExports(pkg *Package) bool

  • func Print(fset *token.FileSet, x interface{}) error

  • func SortImports(fset *token.FileSet, f *File)

  • func Walk(v Visitor, node Node)

  • type ArrayType

  • func (x *ArrayType) End() token.Pos

  • func (x *ArrayType) Pos() token.Pos

  • type AssignStmt

  • func (s *AssignStmt) End() token.Pos

  • func (s *AssignStmt) Pos() token.Pos

  • type BadDecl

  • func (d *BadDecl) End() token.Pos

  • func (d *BadDecl) Pos() token.Pos

  • type BadExpr

  • func (x *BadExpr) End() token.Pos

  • func (x *BadExpr) Pos() token.Pos

  • type BadStmt

  • func (s *BadStmt) End() token.Pos

  • func (s *BadStmt) Pos() token.Pos

  • type BasicLit

  • func (x *BasicLit) End() token.Pos

  • func (x *BasicLit) Pos() token.Pos

  • type BinaryExpr

  • func (x *BinaryExpr) End() token.Pos

  • func (x *BinaryExpr) Pos() token.Pos

  • type BlockStmt

  • func (s *BlockStmt) End() token.Pos

  • func (s *BlockStmt) Pos() token.Pos

  • type BranchStmt

  • func (s *BranchStmt) End() token.Pos

  • func (s *BranchStmt) Pos() token.Pos

  • type CallExpr

  • func (x *CallExpr) End() token.Pos

  • func (x *CallExpr) Pos() token.Pos

  • type CaseClause

  • func (s *CaseClause) End() token.Pos

  • func (s *CaseClause) Pos() token.Pos

  • type ChanDir

  • type ChanType

  • func (x *ChanType) End() token.Pos

  • func (x *ChanType) Pos() token.Pos

  • type CommClause

  • func (s *CommClause) End() token.Pos

  • func (s *CommClause) Pos() token.Pos

  • type Comment

  • func (c *Comment) End() token.Pos

  • func (c *Comment) Pos() token.Pos

  • type CommentGroup

  • func (g *CommentGroup) End() token.Pos

  • func (g *CommentGroup) Pos() token.Pos

  • func (g *CommentGroup) Text() string

  • type CommentMap

  • func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap

  • func (cmap CommentMap) Comments() []*CommentGroup

  • func (cmap CommentMap) Filter(node Node) CommentMap

  • func (cmap CommentMap) String() string

  • func (cmap CommentMap) Update(old, new Node) Node

  • type CompositeLit

  • func (x *CompositeLit) End() token.Pos

  • func (x *CompositeLit) Pos() token.Pos

  • type Decl

  • type DeclStmt

  • func (s *DeclStmt) End() token.Pos

  • func (s *DeclStmt) Pos() token.Pos

  • type DeferStmt

  • func (s *DeferStmt) End() token.Pos

  • func (s *DeferStmt) Pos() token.Pos

  • type Ellipsis

  • func (x *Ellipsis) End() token.Pos

  • func (x *Ellipsis) Pos() token.Pos

  • type EmptyStmt

  • func (s *EmptyStmt) End() token.Pos

  • func (s *EmptyStmt) Pos() token.Pos

  • type Expr

  • type ExprStmt

  • func (s *ExprStmt) End() token.Pos

  • func (s *ExprStmt) Pos() token.Pos

  • type Field

  • func (f *Field) End() token.Pos

  • func (f *Field) Pos() token.Pos

  • type FieldFilter

  • type FieldList

  • func (f *FieldList) End() token.Pos

  • func (f *FieldList) NumFields() int

  • func (f *FieldList) Pos() token.Pos

  • type File

  • func MergePackageFiles(pkg *Package, mode MergeMode) *File

  • func (f *File) End() token.Pos

  • func (f *File) Pos() token.Pos

  • type Filter

  • type ForStmt

  • func (s *ForStmt) End() token.Pos

  • func (s *ForStmt) Pos() token.Pos

  • type FuncDecl

  • func (d *FuncDecl) End() token.Pos

  • func (d *FuncDecl) Pos() token.Pos

  • type FuncLit

  • func (x *FuncLit) End() token.Pos

  • func (x *FuncLit) Pos() token.Pos

  • type FuncType

  • func (x *FuncType) End() token.Pos

  • func (x *FuncType) Pos() token.Pos

  • type GenDecl

  • func (d *GenDecl) End() token.Pos

  • func (d *GenDecl) Pos() token.Pos

  • type GoStmt

  • func (s *GoStmt) End() token.Pos

  • func (s *GoStmt) Pos() token.Pos

  • type Ident

  • func NewIdent(name string) *Ident

  • func (x *Ident) End() token.Pos

  • func (id *Ident) IsExported() bool

  • func (x *Ident) Pos() token.Pos

  • func (id *Ident) String() string

  • type IfStmt

  • func (s *IfStmt) End() token.Pos

  • func (s *IfStmt) Pos() token.Pos

  • type ImportSpec

  • func (s *ImportSpec) End() token.Pos

  • func (s *ImportSpec) Pos() token.Pos

  • type Importer

  • type IncDecStmt

  • func (s *IncDecStmt) End() token.Pos

  • func (s *IncDecStmt) Pos() token.Pos

  • type IndexExpr

  • func (x *IndexExpr) End() token.Pos

  • func (x *IndexExpr) Pos() token.Pos

  • type InterfaceType

  • func (x *InterfaceType) End() token.Pos

  • func (x *InterfaceType) Pos() token.Pos

  • type KeyValueExpr

  • func (x *KeyValueExpr) End() token.Pos

  • func (x *KeyValueExpr) Pos() token.Pos

  • type LabeledStmt

  • func (s *LabeledStmt) End() token.Pos

  • func (s *LabeledStmt) Pos() token.Pos

  • type MapType

  • func (x *MapType) End() token.Pos

  • func (x *MapType) Pos() token.Pos

  • type MergeMode

  • type Node

  • type ObjKind

  • func (kind ObjKind) String() string

  • type Object

  • func NewObj(kind ObjKind, name string) *Object

  • func (obj *Object) Pos() token.Pos

  • type Package

  • func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error)

  • func (p *Package) End() token.Pos

  • func (p *Package) Pos() token.Pos

  • type ParenExpr

  • func (x *ParenExpr) End() token.Pos

  • func (x *ParenExpr) Pos() token.Pos

  • type RangeStmt

  • func (s *RangeStmt) End() token.Pos

  • func (s *RangeStmt) Pos() token.Pos

  • type ReturnStmt

  • func (s *ReturnStmt) End() token.Pos

  • func (s *ReturnStmt) Pos() token.Pos

  • type Scope

  • func NewScope(outer *Scope) *Scope

  • func (s *Scope) Insert(obj *Object) (alt *Object)

  • func (s *Scope) Lookup(name string) *Object

  • func (s *Scope) String() string

  • type SelectStmt

  • func (s *SelectStmt) End() token.Pos

  • func (s *SelectStmt) Pos() token.Pos

  • type SelectorExpr

  • func (x *SelectorExpr) End() token.Pos

  • func (x *SelectorExpr) Pos() token.Pos

  • type SendStmt

  • func (s *SendStmt) End() token.Pos

  • func (s *SendStmt) Pos() token.Pos

  • type SliceExpr

  • func (x *SliceExpr) End() token.Pos

  • func (x *SliceExpr) Pos() token.Pos

  • type Spec

  • type StarExpr

  • func (x *StarExpr) End() token.Pos

  • func (x *StarExpr) Pos() token.Pos

  • type Stmt

  • type StructType

  • func (x *StructType) End() token.Pos

  • func (x *StructType) Pos() token.Pos

  • type SwitchStmt

  • func (s *SwitchStmt) End() token.Pos

  • func (s *SwitchStmt) Pos() token.Pos

  • type TypeAssertExpr

  • func (x *TypeAssertExpr) End() token.Pos

  • func (x *TypeAssertExpr) Pos() token.Pos

  • type TypeSpec

  • func (s *TypeSpec) End() token.Pos

  • func (s *TypeSpec) Pos() token.Pos

  • type TypeSwitchStmt

  • func (s *TypeSwitchStmt) End() token.Pos

  • func (s *TypeSwitchStmt) Pos() token.Pos

  • type UnaryExpr

  • func (x *UnaryExpr) End() token.Pos

  • func (x *UnaryExpr) Pos() token.Pos

  • type ValueSpec

  • func (s *ValueSpec) End() token.Pos

  • func (s *ValueSpec) Pos() token.Pos

  • type Visitor

示例

CommentMap Inspect Print

包文件

ast.go commentmap.go filter.go import.go print.go resolve.go scope.go walk.go

func FileExports

func FileExports(src *File) bool

FileExports 將 AST 文件修剪為適當?shù)?Go 源文件,以便只保留導出的節(jié)點:刪除所有未導出的頂級標識符及其關聯(lián)信息(如類型,初始值或函數(shù)體)。非導出字段和導出類型的方法被刪除。File.Comments 列表不會更改。

FileExports 報告是否有導出聲明。

func FilterDecl

func FilterDecl(decl Decl, f Filter) bool

FilterDecl 通過刪除不通過過濾器f的所有名稱(包括struct 字段和接口方法名稱,但不包括參數(shù)列表)來修飾 AST 的 Go 聲明。

FilterDecl 報告過濾后是否有任何聲明的名稱。

func FilterFile

func FilterFile(src *File, f Filter) bool

FilterFile 通過刪除不通過過濾器f的頂級聲明(包括 struct字段和接口方法名稱,但不包含參數(shù)列表)中的所有名稱來修剪 AST 文件。如果后面的聲明為空,則聲明將從 AST 中刪除。導入聲明總是被刪除。File.Comments 列表不會更改。

FilterFile 報告過濾后是否還有任何頂級聲明。

func FilterPackage

func FilterPackage(pkg *Package, f Filter) bool

FilterPackage 通過刪除不通過過濾器f的頂級聲明(包括struct 字段和接口方法名稱,但不包括參數(shù)列表)中的所有名稱來修剪適用于 Go 包的 AST。如果后面的聲明為空,則聲明將從 AST 中刪除。pkg.Files 列表未更改,因此文件名和頂級包注釋不會丟失。

FilterPackage 報告過濾后是否有任何頂級聲明。

func Fprint

func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) error

Fprint 將從 AST 節(jié)點x開始的(sub-)樹打印到 w。如果 fset!= nil,則相對于該文件集解釋位置信息。否則,位置將被打印為整數(shù)值(文件集特定的偏移量)。

可以提供非零 FieldFilter f 來控制輸出:打印f(fieldname,fieldvalue)為 true 的 struct 字段;所有其他的都從輸出中過濾掉。未導出的結構字段從不打印。

func Inspect

func Inspect(node Node, f func(Node) bool)

檢查以深度優(yōu)先順序遍歷AST:它通過調用f(node) 開始;節(jié)點不能為零。如果 f 返回 true,Inspect 會為節(jié)點的每個非零子節(jié)點遞歸調用f,然后調用 f(nil)。

示例

這個例子演示了如何檢查 Go 程序的 AST。

package mainimport ("fmt""go/ast""go/parser""go/token")func main() {// src是我們要檢查AST的輸入。
	src := `
package p
const c = 1.0
var X = f(3.14)*2 + c
`// 通過解析src來創(chuàng)建AST。
	fset := token.NewFileSet() // 職位相對于fset
	f, err := parser.ParseFile(fset, "src.go", src, 0)if err != nil {panic(err)}// 檢查AST并打印所有標識符和文字。
	ast.Inspect(f, func(n ast.Node) bool {var s stringswitch x := n.(type) {case *ast.BasicLit:
			s = x.Valuecase *ast.Ident:
			s = x.Name}if s != "" {
			fmt.Printf("%s:\t%s\n", fset.Position(n.Pos()), s)}return true})}

func IsExported

func IsExported(name string) bool

IsExported 報告名稱是否為導出的 Go 符號(即,它是否以大寫字母開頭)。

func NotNilFilter

func NotNilFilter(_ string, v reflect.Value) bool

NotNilFilter 對不為零的字段值返回 true;否則返回 false。

func PackageExports

func PackageExports(pkg *Package) bool

PackageExports 將適用于 Go 包的 AST 修剪為僅保留導出的節(jié)點。pkg.Files 列表未更改,因此文件名和頂級包注釋不會丟失。

PackageExports 報告是否有導出聲明;否則返回 false。

func Print

func Print(fset *token.FileSet, x interface{}) error

Print打印x到標準輸出,跳過零字段。打?。╢set,x)與Fprint(os.Stdout,fset,x,NotNilFilter)相同。

示例

這個例子顯示了打印進行調試時 AST 的外觀。

package mainimport ("go/ast""go/parser""go/token")func main() {// src是我們要打印AST的輸入。
	src := `
package main
func main() {
	println("Hello, World!")
}
`// 通過解析src來創(chuàng)建AST。
	fset := token.NewFileSet() // 職位相對于fset
	f, err := parser.ParseFile(fset, "", src, 0)if err != nil {panic(err)}// 打印AST。
	ast.Print(fset, f)}

func SortImports

func SortImports(fset *token.FileSet, f *File)

SortImports 對f中的導入塊中的連續(xù)導入行進行排序。它還可以在不丟失數(shù)據(jù)的情況下刪除重復導入。

func Walk

func Walk(v Visitor, node Node)

以深度優(yōu)先順序遍歷 AST:它通過調用 v.Visit(節(jié)點)開始; 節(jié)點不能為零。如果由 v.Visit(節(jié)點)返回的訪問者 w 不為零,則對于節(jié)點的每個非零子節(jié)點,訪問者 w 遞歸地調用 Walk,隨后調用 w.Visit(nil)。

type ArrayType

ArrayType 節(jié)點表示一個數(shù)組或切片類型。

type ArrayType struct {
        Lbrack token.Pos // “[”的位置
        Len    Expr      // [...] T數(shù)組類型的省略號節(jié)點,切片類型為零
        Elt    Expr      // 元素類型}

func (*ArrayType) End

func (x *ArrayType) End() token.Pos

func (*ArrayType) Pos

func (x *ArrayType) Pos() token.Pos

type AssignStmt

AssignStmt 節(jié)點表示賦值或短變量聲明。

type AssignStmt struct {
        Lhs    []Expr
        TokPos token.Pos   // Tok的位置
        Tok    token.Token // 賦值令牌,DEFINE
        Rhs    []Expr}

func (*AssignStmt) End

func (s *AssignStmt) End() token.Pos

func (*AssignStmt) Pos

func (s *AssignStmt) Pos() token.Pos

type BadDecl

BadDecl 節(jié)點是包含語法錯誤的聲明的占位符,其中不能創(chuàng)建正確的聲明節(jié)點。

type BadDecl struct {
        From, To token.Pos // 不良聲明的位置范圍}

func (*BadDecl) End

func (d *BadDecl) End() token.Pos

func (*BadDecl) Pos

func (d *BadDecl) Pos() token.Pos

type BadExpr

BadExpr 節(jié)點是包含語法錯誤的表達式的占位符,不能創(chuàng)建正確的表達式節(jié)點。

type BadExpr struct {
        From, To token.Pos // 不良表達的位置范圍}

func (*BadExpr) End

func (x *BadExpr) End() token.Pos

func (*BadExpr) Pos

func (x *BadExpr) Pos() token.Pos

type BadStmt

BadStmt 節(jié)點是包含語法錯誤的語句的占位符,其中不能創(chuàng)建正確的語句節(jié)點。

type BadStmt struct {
        From, To token.Pos // 不良陳述的位置范圍}

func (*BadStmt) End

func (s *BadStmt) End() token.Pos

func (*BadStmt) Pos

func (s *BadStmt) Pos() token.Pos

type BasicLit

BasicLit 節(jié)點表示基本類型的文字。

type BasicLit struct {
        ValuePos token.Pos   // literal position
        Kind     token.Token // token.INT, token.FLOAT, token.IMAG, token.CHAR, or token.STRING
        Value    string      // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 2.4i, 'a', '\x7f', "foo" or `\m\n\o`}

func (*BasicLit) End

func (x *BasicLit) End() token.Pos

func (*BasicLit) Pos

func (x *BasicLit) Pos() token.Pos

type BinaryExpr

BinaryExpr 節(jié)點表示一個二進制表達式。

type BinaryExpr struct {
        X     Expr        // 左操作數(shù)
        OpPos token.Pos   // Op的位置
        Op    token.Token // 操作者
        Y     Expr        // 右操作數(shù)}

func (*BinaryExpr) End

func (x *BinaryExpr) End() token.Pos

func (*BinaryExpr) Pos

func (x *BinaryExpr) Pos() token.Pos

type BlockStmt

BlockStmt 節(jié)點表示一個支撐語句列表。

type BlockStmt struct {
        Lbrace token.Pos // “{”的位置
        List   []Stmt
        Rbrace token.Pos // “}”的位置}

func (*BlockStmt) End

func (s *BlockStmt) End() token.Pos

func (*BlockStmt) Pos

func (s *BlockStmt) Pos() token.Pos

type BranchStmt

BranchStmt 節(jié)點表示中斷,繼續(xù),轉到或直通語句。

type BranchStmt struct {
        TokPos token.Pos   // Tok的位置
        Tok    token.Token // 關鍵字令牌(BREAK,CONTINUE,GOTO,F(xiàn)ALLTHROUGH)
        Label  *Ident      // 標簽名稱; 或者nil}

func (*BranchStmt) End

func (s *BranchStmt) End() token.Pos

func (*BranchStmt) Pos

func (s *BranchStmt) Pos() token.Pos

type CallExpr

CallExpr 節(jié)點代表一個表達式,后跟一個參數(shù)列表。

type CallExpr struct {
        Fun      Expr      // 函數(shù)表達
        Lparen   token.Pos // “(”的位置
        Args     []Expr    // 函數(shù)參數(shù); 或者沒有
        Ellipsis token.Pos // “......”的位置(如果沒有“......”則為token.NoPos)
        Rparen   token.Pos // “)的位置}

func (*CallExpr) End

func (x *CallExpr) End() token.Pos

func (*CallExpr) Pos

func (x *CallExpr) Pos() token.Pos

type CaseClause

CaseClause表示表達式或類型切換語句的一種情況。

type CaseClause struct {
        Case  token.Pos // “case”或“default”關鍵字的位置
        List  []Expr    // 表達式或類型列表; nil表示默認情況
        Colon token.Pos // “:”的位置
        Body  []Stmt    // 聲明清單; 或者沒有}

func (*CaseClause) End

func (s *CaseClause) End() token.Pos

func (*CaseClause) Pos

func (s *CaseClause) Pos() token.Pos

type ChanDir

通道類型的方向由以下常量之一表示。

type ChanDir int
const (
        SEND ChanDir = 1 << iota
        RECV)

type ChanType

ChanType 節(jié)點代表一個通道類型。

type ChanType struct {
        Begin token.Pos // “chan”關鍵字或“< - ”的位置(以先到者為準)
        Arrow token.Pos // “< - ”的位置(如果沒有“< - ”則為token.NoPos)
        Dir   ChanDir   // 渠道方向
        Value Expr      // 值類型}

func (*ChanType) End

func (x *ChanType) End() token.Pos

func (*ChanType) Pos

func (x *ChanType) Pos() token.Pos

type CommClause

CommClause 節(jié)點表示選擇語句的情況。

type CommClause struct {
        Case  token.Pos // “case”或“default”關鍵字的位置
        Comm  Stmt      // 發(fā)送或接收聲明; nil表示默認情況
        Colon token.Pos // “:”的位置
        Body  []Stmt    // 聲明清單; 或者沒有}

func (*CommClause) End

func (s *CommClause) End() token.Pos

func (*CommClause) Pos

func (s *CommClause) Pos() token.Pos

type Comment

Comment 節(jié)點表示一個 //style 或 /*- style 的注釋。

type Comment struct {
        Slash token.Pos // “/”開頭注釋的位置
        Text  string    // 注釋文本(不包括用于//style 注釋的'\n')}

func (*Comment) End

func (c *Comment) End() token.Pos

func (*Comment) Pos

func (c *Comment) Pos() token.Pos

type CommentGroup

CommentGroup 表示一系列注釋,沒有其他標記,也沒有空行。

type CommentGroup struct {
        List []*Comment // len(List) > 0}

func (*CommentGroup) End

func (g *CommentGroup) End() token.Pos

func (*CommentGroup) Pos

func (g *CommentGroup) Pos() token.Pos

func (*CommentGroup) Text

func (g *CommentGroup) Text() string

文本返回注釋的文本。注釋標記(//,/* 和 */),行注釋的第一個空格,以及前導空行和尾行空行被刪除。多個空行減少為一行,行尾的空格被修剪。除非結果是空的,否則它是換行符終止的。

type CommentMap

CommentMap 將 AST 節(jié)點映射到與其關聯(lián)的評論組列表。請參閱 NewCommentMap 以獲取關聯(lián)的描述。

type CommentMap map[Node][]*CommentGroup

示例

這個例子說明了如何使用 ast.CommentMap 去除 Go 程序中的變量聲明,同時保持正確的評論關聯(lián)。

package mainimport ("bytes""fmt""go/ast""go/format""go/parser""go/token")func main() {// src是我們創(chuàng)建AST的輸入// 將要操縱。
	src := `
// This is the package comment.
package main

// This comment is associated with the hello constant.
const hello = "Hello, World!" // line comment 1

// This comment is associated with the foo variable.
var foo = hello // line comment 2 

// This comment is associated with the main function.
func main() {
	fmt.Println(hello) // line comment 3
}
`// 通過解析src來創(chuàng)建AST。
	fset := token.NewFileSet() // 職位相對于fset
	f, err := parser.ParseFile(fset, "src.go", src, parser.ParseComments)if err != nil {panic(err)}// 從ast.File的注釋中創(chuàng)建一個ast.CommentMap。// 這有助于保持注釋之間的關聯(lián)// 和AST節(jié)點。
	cmap := ast.NewCommentMap(fset, f, f.Comments)// 從聲明列表中刪除第一個變量聲明。for i, decl := range f.Decls {if gen, ok := decl.(*ast.GenDecl); ok && gen.Tok == token.VAR {copy(f.Decls[i:], f.Decls[i+1:])
			f.Decls = f.Decls[:len(f.Decls)-1]}}// 使用注釋地圖過濾不再屬于的注釋// (與變量聲明相關的注釋),并創(chuàng)建// 新注釋列表。
	f.Comments = cmap.Filter(f).Comments()// 打印修改后的AST。var buf bytes.Bufferif err := format.Node(&buf, fset, f); err != nil {panic(err)}
	fmt.Printf("%s", buf.Bytes())}

func NewCommentMap

func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap

NewCommentMap 通過將注釋列表的注釋組與節(jié)點指定的 AST 的節(jié)點關聯(lián)來創(chuàng)建新的注釋圖。

如果滿足以下條件,則注釋組 g 與節(jié)點 n 相關聯(lián):

 -  g與n結束時在同一行開始-  g緊跟在n之后的行上開始,并且有
  g之后和下一個節(jié)點之前至少有一個空行-  g在n之前開始,并且不與n之前的節(jié)點相關聯(lián)
  通過以前的規(guī)則

NewCommentMap 嘗試將注釋組關聯(lián)到可能的“l(fā)argest”節(jié)點:例如,如果注釋是一個跟隨分配的行注釋,則注釋與整個分配相關聯(lián),而不僅僅是分配中的最后一個操作數(shù)。

func (CommentMap) Comments

func (cmap CommentMap) Comments() []*CommentGroup

評論返回評論地圖中評論組的列表。結果按來源順序排序。

func (CommentMap) Filter

func (cmap CommentMap) Filter(node Node) CommentMap

篩選器返回一個新的注釋映射,其中只包含由節(jié)點指定的 AST 中存在相應節(jié)點的 cmap 的條目。

func (CommentMap) String

func (cmap CommentMap) String() string

func (CommentMap) Update

func (cmap CommentMap) Update(old, new Node) Node

更新用新節(jié)點替換評論映射中的舊節(jié)點并返回新節(jié)點。與舊節(jié)點相關聯(lián)的注釋與新節(jié)點相關聯(lián)。

type CompositeLit

CompositeLit 節(jié)點表示復合文字。

type CompositeLit struct {
        Type   Expr      // 字面類型; 或者nil
        Lbrace token.Pos // “{”的位置
        Elts   []Expr    // 復合元素列表; 或者nil
        Rbrace token.Pos // “}”的位置}

func (*CompositeLit) End

func (x *CompositeLit) End() token.Pos

func (*CompositeLit) Pos

func (x *CompositeLit) Pos() token.Pos

type Decl

所有聲明節(jié)點都實現(xiàn) Decl 接口。

type Decl interface {
        Node        // 包含過濾或未導出的方法}

type DeclStmt

DeclStmt節(jié)點表示聲明列表中的聲明。

type DeclStmt struct {
        Decl Decl // * GenDecl與CONST,TYPE或VAR令牌}

func (*DeclStmt) End

func (s *DeclStmt) End() token.Pos

func (*DeclStmt) Pos

func (s *DeclStmt) Pos() token.Pos

type DeferStmt

DeferStmt 節(jié)點表示推遲語句。

type DeferStmt struct {
        Defer token.Pos // “defer”關鍵字的位置
        Call  *CallExpr}

func (*DeferStmt) End

func (s *DeferStmt) End() token.Pos

func (*DeferStmt) Pos

func (s *DeferStmt) Pos() token.Pos

type Ellipsis

省略號節(jié)點代表參數(shù)列表中的“...”類型或數(shù)組類型中的“...”長度。

type Ellipsis struct {
        Ellipsis token.Pos // “...”的位置
        Elt      Expr      // 省略號元素類型(僅限參數(shù)列表); 或者沒有

func (*Ellipsis) End

func (x *Ellipsis) End() token.Pos

func (*Ellipsis) Pos

func (x *Ellipsis) Pos() token.Pos

type EmptyStmt

EmptyStmt 節(jié)點表示一個空語句??照Z句的“position”是緊隨其后的(顯式或隱式)分號的位置。

type EmptyStmt struct {
        Semicolon token.Pos // 以下“;”的位置
        Implicit  bool      // 如果設置,“;” 在源中省略了}

func (*EmptyStmt) End

func (s *EmptyStmt) End() token.Pos

func (*EmptyStmt) Pos

func (s *EmptyStmt) Pos() token.Pos

type Expr

所有表達式節(jié)點都實現(xiàn) Expr 接口。

type Expr interface {
        Node        // 包含過濾或未導出的方法}

type ExprStmt

ExprStmt節(jié)點表示語句列表中的(stand-alone)表達式。

type ExprStmt struct {
        X Expr // 表達式}

func (*ExprStmt) End

func (s *ExprStmt) End() token.Pos

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() token.Pos

type Field

字段表示結構類型中的字段聲明列表,接口類型中的方法列表或簽名中的參數(shù)/結果聲明。

type Field struct {
        Doc     *CommentGroup // 相關文件; 或者沒有
        Names   []*Ident      // 字段/方法/參數(shù)名稱;或者如果匿名字段為零
        Type    Expr          // 字段/方法/參數(shù)類型
        Tag     *BasicLit     // 字段標簽; 或者沒有
        Comment *CommentGroup // 行注釋; 或者沒有}

func (*Field) End

func (f *Field) End() token.Pos

func (*Field) Pos

func (f *Field) Pos() token.Pos

type FieldFilter

FieldFilter可以提供給Fprint來控制輸出。

type FieldFilter func(name string, value reflect.Value) bool

type FieldList

FieldList表示一個由圓括號或大括號包圍的字段列表。

type FieldList struct {
        Opening token.Pos // 開括號/括號的位置,如果有的話
        List    []*Field  // 字段列表; 或者沒有
        Closing token.Pos // 右括號/括號的位置,如果有的話}

func (*FieldList) End

func (f *FieldList) End() token.Pos

func (*FieldList) NumFields

func (f *FieldList) NumFields() int

NumFields 返回 FieldList 中的(命名和匿名字段)的數(shù)量。

func (*FieldList) Pos

func (f *FieldList) Pos() token.Pos

type File

一個文件節(jié)點代表一個 Go 源文件。

注釋列表按照外觀順序包含源文件中的所有注釋,包括通過 Doc 和注釋字段從其他節(jié)點指向的注釋。

為了正確打印包含注釋的源代碼(使用軟件包 go/format 和 go/printer),必須特別小心在修改文件語法樹時更新注釋:對于打印,注釋根據(jù)其位置散布在令牌之間。如果語法樹節(jié)點被刪除或移動,則其附近的相關注釋也必須從 File.Comments 列表中移除或相應移動(通過更新其位置)。一個 CommentMap 可以用來方便這些操作。

注釋是否以及如何與節(jié)點相關取決于操作程序對語法樹的解釋:除了與節(jié)點直接相關的文檔和評論評論之外,其余注釋是“自由浮動的(free-floating)”(另見issues #18593, #20744)。

type File struct {
        Doc        *CommentGroup   // 相關文件; 或者沒有
        Package    token.Pos       // “package”關鍵字的位置
        Name       *Ident          // 包名稱
        Decls      []Decl          // 頂級聲明; 或者沒有
        Scope      *Scope          // 包范圍(僅限此文件)
        Imports    []*ImportSpec   // 在此文件中導入
        Unresolved []*Ident        // 此文件中未解析的標識符
        Comments   []*CommentGroup // 源文件中所有注釋的列表}

func MergePackageFiles

func MergePackageFiles(pkg *Package, mode MergeMode) *File

MergePackageFiles 通過合并屬于包的文件的 AST 來創(chuàng)建文件 AST。模式標志控制合并行為。

func (*File) End

func (f *File) End() token.Pos

func (*File) Pos

func (f *File) Pos() token.Pos

type Filter

type Filter func(string) bool

type ForStmt

ForStmt 表示 for 語句。

type ForStmt struct {
        For  token.Pos // “for”關鍵字的位置
        Init Stmt      // 初始化語句; 或者沒有
        Cond Expr      // 條件; 或者沒有
        Post Stmt      // post iteration語句; 或者沒有
        Body *BlockStmt}

func (*ForStmt) End

func (s *ForStmt) End() token.Pos

func (*ForStmt) Pos

func (s *ForStmt) Pos() token.Pos

type FuncDecl

FuncDecl 節(jié)點表示一個函數(shù)聲明。

type FuncDecl struct {
        Doc  *CommentGroup // 相關文件; 或者沒有
        Recv *FieldList    // 接收器(方法); 或零(函數(shù))
        Name *Ident        // 函數(shù)/方法名稱
        Type *FuncType     // 函數(shù)簽名:“func”關鍵字的參數(shù),結果和位置
        Body *BlockStmt    // 功能體; 或者對于外部(非Go)功能為零

func (*FuncDecl) End

func (d *FuncDecl) End() token.Pos

func (*FuncDecl) Pos

func (d *FuncDecl) Pos() token.Pos

type FuncLit

一個FuncLit節(jié)點代表一個函數(shù)文字。

type FuncLit struct {
        Type *FuncType  // 函數(shù)類型
        Body *BlockStmt // 函數(shù)體}

func (*FuncLit) End

func (x *FuncLit) End() token.Pos

func (*FuncLit) Pos

func (x *FuncLit) Pos() token.Pos

type FuncType

FuncType 節(jié)點表示一個函數(shù)類型。

type FuncType struct {
        Func    token.Pos  // “func”關鍵字的位置(如果沒有“func”,則為token.NoPos)
        Params  *FieldList // (傳入)參數(shù);非空
        Results *FieldList // (外向)結果;或者沒有}

func (*FuncType) End

func (x *FuncType) End() token.Pos

func (*FuncType) Pos

func (x *FuncType) Pos() token.Pos

type GenDecl

GenDecl節(jié)點(通用聲明節(jié)點)表示一個導入,常量,類型或變量聲明。有效的 Lparen 位置(Lparen.IsValid())表示括號聲明。

Tok 值與 Specs 元素類型之間的關系:

token.IMPORT  *ImportSpec
token.CONST   *ValueSpec
token.TYPE    *TypeSpec
token.VAR     *ValueSpec
type GenDecl struct {
        Doc    *CommentGroup // 相關文件; 或者沒有
        TokPos token.Pos     // Tok 的位置
        Tok    token.Token   // IMPORT, CONST, TYPE, VAR
        Lparen token.Pos     // “(',如果有的話)的位置
        Specs  []Spec
        Rparen token.Pos // ')'的位置,如果有的話}

func (*GenDecl) End

func (d *GenDecl) End() token.Pos

func (*GenDecl) Pos

func (d *GenDecl) Pos() token.Pos

type GoStmt

GoStmt 節(jié)點表示 go 語句。

type GoStmt struct {
        Go   token.Pos // “go” 關鍵字的位置
        Call *CallExpr}

func (*GoStmt) End

func (s *GoStmt) End() token.Pos

func (*GoStmt) Pos

func (s *GoStmt) Pos() token.Pos

type Ident

一個 Ident 節(jié)點表示一個標識符。

type Ident struct {
        NamePos token.Pos // 確定位置
        Name    string    // 標識符名稱
        Obj     *Object   // 表示對象; 或者沒有}

func NewIdent

func NewIdent(name string) *Ident

NewIdent 創(chuàng)建一個沒有位置的新的 Ident。對于由 Go 解析器以外的代碼生成的 AST 非常有用。

func (*Ident) End

func (x *Ident) End() token.Pos

func (*Ident) IsExported

func (id *Ident) IsExported() bool

IsExported 報告 id 是否是導出的 Go 符號(即,它是否以大寫字母開頭)。

func (*Ident) Pos

func (x *Ident) Pos() token.Pos

func (*Ident) String

func (id *Ident) String() string

type IfStmt

IfStmt 節(jié)點表示一個 if 語句。

type IfStmt struct {
        If   token.Pos // “if”關鍵字的位置
        Init Stmt      // 初始化語句; 或者沒有
        Cond Expr      // 條件
        Body *BlockStmt
        Else Stmt // 別的分支; 或者沒有}

func (*IfStmt) End

func (s *IfStmt) End() token.Pos

func (*IfStmt) Pos

func (s *IfStmt) Pos() token.Pos

type ImportSpec

ImportSpec 節(jié)點表示單個包導入。

type ImportSpec struct {
        Doc     *CommentGroup // 相關文件; 或者沒有
        Name    *Ident        // 本地包名(包括“.”); 或者沒有
        Path    *BasicLit     // 導入路徑
        Comment *CommentGroup // 行注釋;或者沒有
        EndPos  token.Pos     // 規(guī)范結束(如果非零則覆蓋Path.Pos)}

func (*ImportSpec) End

func (s *ImportSpec) End() token.Pos

func (*ImportSpec) Pos

func (s *ImportSpec) Pos() token.Pos

type Importer

導入程序解析導入路徑以打包對象。導入映射記錄已導入的包,并按包ID(規(guī)范導入路徑)進行索引。導入程序必須確定規(guī)范導入路徑并檢查導圖,看它是否已經存在于導入導圖中。如果是這樣,導入器可以返回地圖條目。否則,導入程序應將給定路徑的包數(shù)據(jù)加載到新的 *Object(pkg)中,在導入映射中記錄 pkg,然后返回 pkg。

type Importer func(imports map[string]*Object, path string) (pkg *Object, err error)

type IncDecStmt

IncDecStmt 節(jié)點表示增量或減量語句。

type IncDecStmt struct {
        X      Expr
        TokPos token.Pos   // Tok的位置
        Tok    token.Token // INC或DEC}

func (*IncDecStmt) End

func (s *IncDecStmt) End() token.Pos

func (*IncDecStmt) Pos

func (s *IncDecStmt) Pos() token.Pos

type IndexExpr

IndexExpr 節(jié)點表示后跟一個索引的表達式。

type IndexExpr struct {
        X      Expr      // 表達式
        Lbrack token.Pos // “[”的位置
        Index  Expr      // 索引表達式
        Rbrack token.Pos // “]的位置}

func (*IndexExpr) End

func (x *IndexExpr) End() token.Pos

func (*IndexExpr) Pos

func (x *IndexExpr) Pos() token.Pos

type InterfaceType

InterfaceType 節(jié)點表示接口類型。

type InterfaceType struct {
        Interface  token.Pos  // “interface”關鍵字的位置
        Methods    *FieldList // 方法列表
        Incomplete bool       // 如果“方法”列表中缺少(源)方法,則為true}

func (*InterfaceType) End

func (x *InterfaceType) End() token.Pos

func (*InterfaceType) Pos

func (x *InterfaceType) Pos() token.Pos

type KeyValueExpr

KeyValueExpr節(jié)點表示復合文字中的(鍵:值)對。

type KeyValueExpr struct {
        Key   Expr
        Colon token.Pos // “:”的位置
        Value Expr}

func (*KeyValueExpr) End

func (x *KeyValueExpr) End() token.Pos

func (*KeyValueExpr) Pos

func (x *KeyValueExpr) Pos() token.Pos

type LabeledStmt

LabeledStmt 節(jié)點表示帶標簽的語句。

type LabeledStmt struct {
        Label *Ident
        Colon token.Pos // “:”的位置
        Stmt  Stmt}

func (*LabeledStmt) End

func (s *LabeledStmt) End() token.Pos

func (*LabeledStmt) Pos

func (s *LabeledStmt) Pos() token.Pos

type MapType

MapType節(jié)點表示地圖類型。

type MapType struct {
        Map   token.Pos // “map”關鍵字的位置
        Key   Expr
        Value Expr}

func (*MapType) End

func (x *MapType) End() token.Pos

func (*MapType) Pos

func (x *MapType) Pos() token.Pos

type MergeMode

MergeMode 標志控制 MergePackageFiles 的行為。

type MergeMode uint
const (        // 如果設置,則排除重復的函數(shù)聲明。
        FilterFuncDuplicates MergeMode = 1 << iota        // 如果設置,則與特定的注釋無關        // AST節(jié)點(作為Doc或Comment)被排除在外。
        FilterUnassociatedComments        // 如果設置,則排除重復的導入聲明。
        FilterImportDuplicates)

type Node

所有節(jié)點類型都實現(xiàn) Node 接口。

type Node interface {        Pos() token.Pos // 屬于該節(jié)點的第一個字符的位置        End() token.Pos // 緊接在節(jié)點之后的第一個字符的位置}

type ObjKind

ObjKind 描述了一個對象代表什么。

type ObjKind int

可能的對象種類的列表。

const (
        Bad ObjKind = iota // 用于錯誤處理
        Pkg                // 包
        Con                // 常量
        Typ                // 類型
        Var                // 變量
        Fun                // 函數(shù)或方法
        Lbl                // 標簽)

func (ObjKind) String

func (kind ObjKind) String() string

type Object

一個對象描述了一個命名的語言實體,如包,常量,類型,變量,函數(shù)(包括方法)或標簽。

數(shù)據(jù)字段包含對象特定的數(shù)據(jù):

Kind    Data type         Data value
Pkg     *Scope            package scope
Con     int               iota for the respective declaration
type Object struct {
        Kind ObjKind
        Name string      // 聲明的名稱
        Decl interface{} // 對應的Field,XxxSpec,F(xiàn)uncDecl,LabeledStmt,AssignStmt,Scope; 或者沒有
        Data interface{} // 特定對象數(shù)據(jù);或者沒有
        Type interface{} // 占位符的類型信息; 可能是零}

func NewObj

func NewObj(kind ObjKind, name string) *Object

NewObj 創(chuàng)建一個給定種類和名稱的新對象。

func (*Object) Pos

func (obj *Object) Pos() token.Pos

Pos 計算對象名稱聲明的源位置。如果無法計算結果可能是無效位置(obj.Decl 可能為零或不正確)。

type Package

Package 節(jié)點表示一組源文件,共同構建 Go 包。

type Package struct {
        Name    string             // 包名稱
        Scope   *Scope             // 所有文件的包范圍
        Imports map[string]*Object // 包id的地圖 - >包對象
        Files   map[string]*File   // 按文件名轉到源文件

func NewPackage

func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error)

NewPackage 從一組 File 節(jié)點創(chuàng)建一個新的 Package 節(jié)點。它解決跨文件的未解析標識符,并相應地更新每個文件的未解析列表。如果提供了非零導入器和 Universe 范圍,則它們將用于解析未在任何包文件中聲明的標識符。任何剩余的未解析標識符都會報告為未聲明。如果這些文件屬于不同的軟件包,則會選擇一個軟件包名稱,并報告具有不同軟件包名稱的文件,然后將其忽略。結果是包節(jié)點和 scanner.ErrorList 是否有錯誤。

func (*Package) End

func (p *Package) End() token.Pos

func (*Package) Pos

func (p *Package) Pos() token.Pos

type ParenExpr

一個 ParenExpr 節(jié)點表示一個帶括號的表達式。

type ParenExpr struct {
        Lparen token.Pos // “(”的位置
        X      Expr      // 括號表達式
        Rparen token.Pos // “)”的位置}

func (*ParenExpr) End

func (x *ParenExpr) End() token.Pos

func (*ParenExpr) Pos

func (x *ParenExpr) Pos() token.Pos

type RangeStmt

RangeStmt 表示帶有范圍子句的 for 語句。

type RangeStmt struct {
        For        token.Pos   // “for”關鍵字的位置
        Key, Value Expr        // 關鍵,值可能是零
        TokPos     token.Pos   // Tok的位置; 如果Key == nil則無效
        Tok        token.Token // 如果Key == nil,ASSIGN,DEFINE,則為ILLEGAL
        X          Expr        // 值范圍超過
        Body       *BlockStmt}

func (*RangeStmt) End

func (s *RangeStmt) End() token.Pos

func (*RangeStmt) Pos

func (s *RangeStmt) Pos() token.Pos

type ReturnStmt

ReturnStmt 節(jié)點表示一個返回語句。

type ReturnStmt struct {
        Return  token.Pos // “return”關鍵字的位置
        Results []Expr    // 結果表達式;或者沒有}

func (*ReturnStmt) End

func (s *ReturnStmt) End() token.Pos

func (*ReturnStmt) Pos

func (s *ReturnStmt) Pos() token.Pos

type Scope

Scope 維護在范圍中聲明的一組指定語言實體以及到緊鄰的(外部)范圍的鏈接。

type Scope struct {
        Outer   *Scope
        Objects map[string]*Object}

func NewScope

func NewScope(outer *Scope) *Scope

NewScope 創(chuàng)建一個嵌套在外部作用域中的新作用域。

func (*Scope) Insert

func (s *Scope) Insert(obj *Object) (alt *Object)

Insert 嘗試將命名對象 obj 插入到作用域中。如果范圍已經包含名稱相同的對象 alt,則 Insert 會保持范圍不變并返回 alt。否則,它插入 obj 并返回 nil。

func (*Scope) Lookup

func (s *Scope) Lookup(name string) *Object

如果在范圍s中找到,Lookup 將返回具有給定名稱的對象,否則返回 nil。外部作用域被忽略。

func (*Scope) String

func (s *Scope) String() string

調試支持

type SelectStmt

SelectStmt 節(jié)點表示一個 select 語句。

type SelectStmt struct {
        Select token.Pos  // “select”關鍵字的位置
        Body   *BlockStmt // 僅限CommClauses}

func (*SelectStmt) End

func (s *SelectStmt) End() token.Pos

func (*SelectStmt) Pos

func (s *SelectStmt) Pos() token.Pos

type SelectorExpr

SelectorExpr 節(jié)點表示一個表達式,后跟一個選擇器。

type SelectorExpr struct {
        X   Expr   // 表達式
        Sel *Ident // 場選擇器}

func (*SelectorExpr) End

func (x *SelectorExpr) End() token.Pos

func (*SelectorExpr) Pos

func (x *SelectorExpr) Pos() token.Pos

type SendStmt

SendStmt 節(jié)點表示發(fā)送語句。

type SendStmt struct {
        Chan  Expr
        Arrow token.Pos // “<- ”的位置
        Value Expr}

func (*SendStmt) End

func (s *SendStmt) End() token.Pos

func (*SendStmt) Pos

func (s *SendStmt) Pos() token.Pos

type SliceExpr

SliceExpr 節(jié)點表示一個表達式,后跟切片索引。

type SliceExpr struct {
        X      Expr      // 表達式
        Lbrack token.Pos // “[”的位置
        Low    Expr      // 切片范圍的開始;或者沒有
        High   Expr      // 切片范圍的結束; 或者沒有
        Max    Expr      // 最大切片容量; 或者沒有
        Slice3 bool      // 如果3-index切片(存在2個冒號),則為true
        Rbrack token.Pos // “]"的位置}

func (*SliceExpr) End

func (x *SliceExpr) End() token.Pos

func (*SliceExpr) Pos

func (x *SliceExpr) Pos() token.Pos

type Spec

Spec類型代表 *ImportSpec,*ValueSpec 和 *TypeSpec 中的任何一個。

type Spec interface {
        Node        // 包含過濾或未導出的方法}

type StarExpr

StarExpr 節(jié)點表示形式為“*”表達式的表達式。在語義上它可以是一個一元“*”表達式或指針類型。

type StarExpr struct {
        Star token.Pos // “*”的位置
        X    Expr      // 操作數(shù)}

func (*StarExpr) End

func (x *StarExpr) End() token.Pos

func (*StarExpr) Pos

func (x *StarExpr) Pos() token.Pos

type Stmt

所有語句節(jié)點都實現(xiàn) Stmt 接口。

type Stmt interface {
        Node        // 包含過濾或未導出的方法}

type StructType

StructType 節(jié)點表示一個結構類型。

type StructType struct {
        Struct     token.Pos  // “struct”關鍵字的位置
        Fields     *FieldList // 列表聲明清單
        Incomplete bool       // 如果“字段”列表中缺少(源)字段,則為true}

func (*StructType) End

func (x *StructType) End() token.Pos

func (*StructType) Pos

func (x *StructType) Pos() token.Pos

type SwitchStmt

一個 SwitchStmt 節(jié)點表示一個表達式 switch 語句。

type SwitchStmt struct {
        Switch token.Pos  // “switch”關鍵字的位置
        Init   Stmt       // 初始化語句; 或者沒有
        Tag    Expr       // 標簽表達; 或者沒有
        Body   *BlockStmt // 僅限CaseClauses}

func (*SwitchStmt) End

func (s *SwitchStmt) End() token.Pos

func (*SwitchStmt) Pos

func (s *SwitchStmt) Pos() token.Pos

type TypeAssertExpr

TypeAssertExpr 節(jié)點表示一個表達式,后跟一個類型斷言。

type TypeAssertExpr struct {
        X      Expr      // 表達式
        Lparen token.Pos // “(”的位置
        Type   Expr      // 斷言類型; nil表示類型開關X.(type)
        Rparen token.Pos // “)"的位置}

func (*TypeAssertExpr) End

func (x *TypeAssertExpr) End() token.Pos

func (*TypeAssertExpr) Pos

func (x *TypeAssertExpr) Pos() token.Pos

type TypeSpec

TypeSpec 節(jié)點代表一個類型聲明(TypeSpec 生成)。

type TypeSpec struct {
        Doc     *CommentGroup // 相關文件;或者沒有
        Name    *Ident        // 類型名稱
        Assign  token.Pos     // '='的位置,如果有的話
        Type    Expr          // *Ident,*ParenExpr,*SelectorExpr,*StarExpr或任何*XxxTypes
        Comment *CommentGroup // 行注釋;或者沒有}

func (*TypeSpec) End

func (s *TypeSpec) End() token.Pos

func (*TypeSpec) Pos

func (s *TypeSpec) Pos() token.Pos

type TypeSwitchStmt

TypeSwitchStmt 節(jié)點表示類型切換語句。

type TypeSwitchStmt struct {
        Switch token.Pos  // “switch”關鍵字的位置
        Init   Stmt       // 初始化語句; 或者沒有
        Assign Stmt       // x := y.(type)或y.(type)
        Body   *BlockStmt // 僅限CaseClauses}

func (*TypeSwitchStmt) End

func (s *TypeSwitchStmt) End() token.Pos

func (*TypeSwitchStmt) Pos

func (s *TypeSwitchStmt) Pos() token.Pos

type UnaryExpr

UnaryExpr 節(jié)點表示一個一元表達式。一元“*”表達式通過 StarExpr 節(jié)點表示。

type UnaryExpr struct {
        OpPos token.Pos   // Op 的位置
        Op    token.Token // 操作者
        X     Expr        // 操作數(shù)}

func (*UnaryExpr) End

func (x *UnaryExpr) End() token.Pos

func (*UnaryExpr) Pos

func (x *UnaryExpr) Pos() token.Pos

type ValueSpec

ValueSpec 節(jié)點表示常量或變量聲明(ConstSpec 或 VarSpec 生成)。

type ValueSpec struct {
        Doc     *CommentGroup // 相關文件; 或者沒有
        Names   []*Ident      // 值名稱(len(Names) > 0)
        Type    Expr          // 值類型; 或者沒有
        Values  []Expr        // 初始值; 或者沒有
        Comment *CommentGroup // 行注釋 或者沒有}

func (*ValueSpec) End

func (s *ValueSpec) End() token.Pos

func (*ValueSpec) Pos

func (s *ValueSpec) Pos() token.Pos

type Visitor

為 Walk 遇到的每個節(jié)點調用訪問者訪問方法。如果結果訪問者w不為零,則 Walk 訪問w的每個子節(jié)點,然后調用 w.Visit(nil)。

type Visitor interface {        Visit(node Node) (w Visitor)}
Article précédent: Article suivant: