Documentation
¶
Overview ¶
astパッケージはGoのパッケージの構文木を表すために使用される型を宣言します。
Index ¶
- 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 any, f FieldFilter) error
- func Inspect(node Node, f func(Node) bool)
- func IsExported(name string) bool
- func IsGenerated(file *File) bool
- func NotNilFilter(_ string, v reflect.Value) bool
- func PackageExports(pkg *Package) bool
- func Preorder(root Node) iter.Seq[Node]
- func Print(fset *token.FileSet, x any) error
- func SortImports(fset *token.FileSet, f *File)
- func Walk(v Visitor, node Node)
- type ArrayType
- type AssignStmt
- type BadDecl
- type BadExpr
- type BadStmt
- type BasicLit
- type BinaryExpr
- type BlockStmt
- type BranchStmt
- type CallExpr
- type CaseClause
- type ChanDir
- type ChanType
- type CommClause
- type Comment
- type CommentGroup
- type CommentMap
- type CompositeLit
- type Decl
- type DeclStmt
- type DeferStmt
- type Ellipsis
- type EmptyStmt
- type Expr
- type ExprStmt
- type Field
- type FieldFilter
- type FieldList
- type File
- type Filter
- type ForStmt
- type FuncDecl
- type FuncLit
- type FuncType
- type GenDecl
- type GoStmt
- type Ident
- type IfStmt
- type ImportSpec
- type Importerdeprecated
- type IncDecStmt
- type IndexExpr
- type IndexListExpr
- type InterfaceType
- type KeyValueExpr
- type LabeledStmt
- type MapType
- type MergeMode
- type Node
- type ObjKind
- type Objectdeprecated
- type Packagedeprecated
- type ParenExpr
- type RangeStmt
- type ReturnStmt
- type Scopedeprecated
- type SelectStmt
- type SelectorExpr
- type SendStmt
- type SliceExpr
- type Spec
- type StarExpr
- type Stmt
- type StructType
- type SwitchStmt
- type TypeAssertExpr
- type TypeSpec
- type TypeSwitchStmt
- type UnaryExpr
- type ValueSpec
- type Visitor
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileExports ¶
FileExportsは、GoのソースファイルのASTを現在の場所でトリムします。 エクスポートされたノードのみが残り、エクスポートされていないトップレベルの識別子とそれに関連する情報 (型、初期値、または関数本体など)は削除されます。エクスポートされた型の非エクスポートフィールドとメソッドも剥ぎ取られます。 [File.Comments] リストは変更されません。
FileExportsは、エクスポートされた宣言があるかどうかを報告します。
func FilterDecl ¶
FilterDeclはGoの宣言のASTを変更して、フィルターfを通過しない名前(構造体フィールドやインタフェースメソッドの名前を含むが、パラメーターリストからは除外)を削除します。
FilterDeclは、フィルタリング後に残された宣言された名前があるかどうかを報告します。
func FilterFile ¶
FilterFileは、フィルタfを通過しない(構造体のフィールドやインターフェースのメソッド名を含むが、パラメータリストからは含まれない)トップレベルの宣言からすべての名前を削除することで、GoファイルのASTを修正します。もし宣言が空になった場合、宣言はASTから削除されます。Import宣言は必ず削除されます。[File.Comments] のリストは変更されません。 FilterFileは、フィルタリング後にトップレベルの宣言が残っているかどうかを報告します。
func FilterPackage ¶
FilterPackageは、フィルターfを通過しない(構造体フィールドやインターフェースメソッド名を含むが、パラメータリストからは除かれない)トップレベル宣言のすべての名前を削除することにより、GoパッケージのASTを修正します。 宣言がその後空になった場合、宣言はASTから削除されます。 pkg.Filesリストは変更されないため、ファイル名やトップレベルのパッケージコメントが失われることはありません。
FilterPackageは、フィルタリング後にトップレベルの宣言が残っているかどうかを報告します。
func Fprint ¶
FprintはASTノードxから始まる(サブ)ツリーをwに出力します。 もしfset != nilなら、位置情報はそのファイルセットに対して相対的に解釈されます。 それ以外の場合は位置は整数値(ファイルセット固有のオフセット)として表示されます。
非nilの FieldFilter fが提供された場合、出力を制御するために使用されます: f(fieldname, fieldvalue)がtrueを返す構造体フィールドだけが出力されます。 それ以外のものは出力からフィルタリングされます。エクスポートされていない構造体フィールドは常に出力されません。
func Inspect ¶
InspectはASTを深さ優先順で走査します:まずf(node)を呼び出します。nodeはnilであってはなりません。fがtrueを返す場合、Inspectはnodeの非nilな子のそれぞれに対して再帰的にfを呼び出し、その後にf(nil)を呼び出します。
Example ¶
この例は、GoプログラムのASTを検査する方法を示しています。
package main import ( "github.com/shogo82148/std/fmt" "github.com/shogo82148/std/go/ast" "github.com/shogo82148/std/go/parser" "github.com/shogo82148/std/go/token" ) func main() { // srcはASTを検査したい入力です。 src := ` package p const c = 1.0 var X = f(3.14)*2 + c ` // srcを解析して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 string switch x := n.(type) { case *ast.BasicLit: s = x.Value case *ast.Ident: s = x.Name } if s != "" { fmt.Printf("%s:\t%s\n", fset.Position(n.Pos()), s) } return true }) }
Output: src.go:2:9: p src.go:3:7: c src.go:3:11: 1.0 src.go:4:5: X src.go:4:9: f src.go:4:11: 3.14 src.go:4:17: 2 src.go:4:21: c
func IsGenerated ¶ added in v1.21.0
IsGeneratedは、プログラムによって生成されたファイルか、手書きではないかを報告します。 https://go.dev/s/generatedcodeに記載されている特殊コメントを検出します。
構文木は [parser.ParseComments] フラグを使用して解析されている必要があります。 例:
f, err := parser.ParseFile(fset, filename, src, parser.ParseComments|parser.PackageClauseOnly) if err != nil { ... } gen := ast.IsGenerated(f)
func NotNilFilter ¶
NotNilFilterは、フィールド値がnilでない場合にtrueを返す FieldFilter です。 それ以外の場合はfalseを返します。
func PackageExports ¶
PackageExportsは、GoパッケージのASTを変更して、エクスポートされたノードのみが残るようにします。pkg.Filesリストは変更されず、ファイル名とトップレベルのパッケージコメントは失われません。
PackageExportsは、エクスポートされた宣言があるかどうかを報告します。エクスポートされた宣言がない場合、falseを返します。
func Preorder ¶ added in v1.23.0
Preorderは、指定されたルート以下(ルートを含む)の構文木のすべてのノードに対するイテレータを返します。 これは深さ優先のプレオーダーで行われます。
各サブツリーの走査をより細かく制御するには、Inspect を使用します。
Example ¶
package main import ( "github.com/shogo82148/std/fmt" "github.com/shogo82148/std/go/ast" "github.com/shogo82148/std/go/parser" "github.com/shogo82148/std/go/token" ) func main() { src := ` package p func f(x, y int) { print(x + y) } ` fset := token.NewFileSet() f, err := parser.ParseFile(fset, "", src, 0) if err != nil { panic(err) } // Print identifiers in order for n := range ast.Preorder(f) { id, ok := n.(*ast.Ident) if !ok { continue } fmt.Println(id.Name) } }
Output: p f x y int print x y
func Print ¶
Print関数は、nilのフィールドをスキップしてxを標準出力に出力します。 Print(fset, x)は、Fprint(os.Stdout, fset, x, NotNilFilter)と同じです。
Example ¶
この例では、デバッグ用に出力されるASTの形状を示しています。
package main import ( "github.com/shogo82148/std/go/ast" "github.com/shogo82148/std/go/parser" "github.com/shogo82148/std/go/token" ) func main() { // srcはASTを出力したい入力です。 src := ` package main func main() { println("Hello, World!") } ` // src を解析してASTを作成します。 fset := token.NewFileSet() // ポジションはfsetに対して相対的です。 f, err := parser.ParseFile(fset, "", src, 0) if err != nil { panic(err) } // ASTを出力する。 ast.Print(fset, f) }
Output: 0 *ast.File { 1 . Package: 2:1 2 . Name: *ast.Ident { 3 . . NamePos: 2:9 4 . . Name: "main" 5 . } 6 . Decls: []ast.Decl (len = 1) { 7 . . 0: *ast.FuncDecl { 8 . . . Name: *ast.Ident { 9 . . . . NamePos: 3:6 10 . . . . Name: "main" 11 . . . . Obj: *ast.Object { 12 . . . . . Kind: func 13 . . . . . Name: "main" 14 . . . . . Decl: *(obj @ 7) 15 . . . . } 16 . . . } 17 . . . Type: *ast.FuncType { 18 . . . . Func: 3:1 19 . . . . Params: *ast.FieldList { 20 . . . . . Opening: 3:10 21 . . . . . Closing: 3:11 22 . . . . } 23 . . . } 24 . . . Body: *ast.BlockStmt { 25 . . . . Lbrace: 3:13 26 . . . . List: []ast.Stmt (len = 1) { 27 . . . . . 0: *ast.ExprStmt { 28 . . . . . . X: *ast.CallExpr { 29 . . . . . . . Fun: *ast.Ident { 30 . . . . . . . . NamePos: 4:2 31 . . . . . . . . Name: "println" 32 . . . . . . . } 33 . . . . . . . Lparen: 4:9 34 . . . . . . . Args: []ast.Expr (len = 1) { 35 . . . . . . . . 0: *ast.BasicLit { 36 . . . . . . . . . ValuePos: 4:10 37 . . . . . . . . . Kind: STRING 38 . . . . . . . . . Value: "\"Hello, World!\"" 39 . . . . . . . . } 40 . . . . . . . } 41 . . . . . . . Ellipsis: - 42 . . . . . . . Rparen: 4:25 43 . . . . . . } 44 . . . . . } 45 . . . . } 46 . . . . Rbrace: 5:1 47 . . . } 48 . . } 49 . } 50 . FileStart: 1:1 51 . FileEnd: 5:3 52 . Scope: *ast.Scope { 53 . . Objects: map[string]*ast.Object (len = 1) { 54 . . . "main": *(obj @ 11) 55 . . } 56 . } 57 . Unresolved: []*ast.Ident (len = 1) { 58 . . 0: *(obj @ 29) 59 . } 60 . GoVersion: "" 61 }
func SortImports ¶
SortImportsはfのimportブロック内の連続したimport行をソートします。 データの損失なしに重複するimportを削除することも可能です。
Types ¶
type AssignStmt ¶
AssignStmt ノードは、代入または短い変数宣言を表します。
func (*AssignStmt) End ¶
func (s *AssignStmt) End() token.Pos
func (*AssignStmt) Pos ¶
func (s *AssignStmt) Pos() token.Pos
type BinaryExpr ¶
BinaryExprノードはバイナリ式を表します。
func (*BinaryExpr) End ¶
func (x *BinaryExpr) End() token.Pos
func (*BinaryExpr) Pos ¶
func (x *BinaryExpr) Pos() token.Pos
type BranchStmt ¶
BranchStmtノードはbreak、continue、goto、またはfallthroughステートメントを表します。
func (*BranchStmt) End ¶
func (s *BranchStmt) End() token.Pos
func (*BranchStmt) Pos ¶
func (s *BranchStmt) Pos() token.Pos
type CallExpr ¶
A CallExpr node represents an expression followed by an argument list. CallExprノードは、式の後に引数リストが続くことを表します。
type CaseClause ¶
CaseClauseは式や型switch文のケースを表します。
func (*CaseClause) End ¶
func (s *CaseClause) End() token.Pos
func (*CaseClause) Pos ¶
func (s *CaseClause) Pos() token.Pos
type CommClause ¶
CommClauseノードは、select文のcaseを表します。
func (*CommClause) End ¶
func (s *CommClause) End() token.Pos
func (*CommClause) Pos ¶
func (s *CommClause) Pos() token.Pos
type Comment ¶
Commentノードは、単一の//-スタイルまたは/*-スタイルのコメントを表します。
Textフィールドには、ソースに存在した可能性のあるキャリッジリターン(\r)を含まないコメントテキストが含まれます。コメントの終了位置はlen(Text)を使用して計算されるため、Comment.End によって報告される位置は、キャリッジリターンを含むコメントの真のソース終了位置と一致しません。
type CommentGroup ¶
type CommentGroup struct {
List []*Comment
}
CommentGroupは、他のトークンや空の行がないコメントのシーケンスを表します。
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
Textはコメントのテキストを返します。 コメントマーカー(//、/*、および*/)、行コメントの最初のスペース、および 先行および後続の空行は除去されます。 "//line"や"//go:noinline"のようなコメントディレクティブも削除されます。 複数の空行は1つに減らされ、行の末尾のスペースはトリムされます。 結果が空でない場合、改行で終わります。
type CommentMap ¶ added in v1.1.0
type CommentMap map[Node][]*CommentGroup
CommentMapはASTノードをそのノードに関連付けられたコメントグループのリストにマップします。 関連付けについては、NewCommentMap の説明を参照してください。
Example ¶
この例は、ast.CommentMapを使用して、Goプログラム内の変数宣言を削除しつつ、 正しいコメントの関連付けを維持する方法を示しています。
package main import ( "github.com/shogo82148/std/fmt" "github.com/shogo82148/std/go/ast" "github.com/shogo82148/std/go/format" "github.com/shogo82148/std/go/parser" "github.com/shogo82148/std/go/token" "github.com/shogo82148/std/strings" ) func main() { // src は、私たちが操作するための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 をパースしてASTを作成する。 fset := token.NewFileSet() // positionsはfsetに対して相対的です。 f, err := parser.ParseFile(fset, "src.go", src, parser.ParseComments) if err != nil { panic(err) } // ast.File のコメントから ast.CommentMap を作成します。 // これにより、コメントと AST ノードの関連付けが保持されます。 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] break } } // コメントマップを使用して、もはや必要でないコメント(変数宣言に関連するコメント)をフィルタリングし、新しいコメントリストを作成します。 f.Comments = cmap.Filter(f).Comments() // 変更されたASTを出力します。 var buf strings.Builder if err := format.Node(&buf, fset, f); err != nil { panic(err) } fmt.Printf("%s", buf.String()) }
Output: // 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 main function. func main() { fmt.Println(hello) // line comment 3 }
func NewCommentMap ¶ added in v1.1.0
func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap
NewCommentMapは、コメントリストのコメントグループをASTのノードと関連付けて新しいコメントマップを作成します。 コメントグループgは、ノードnと関連付けられます。以下の条件を満たす場合です:
- gは、nの終了する行と同じ行で開始します。
- gは、nの直後の行で始まり、gと次のノードの間に少なくとも1つの空行がある場合。
- gは、nよりも前に開始され、前のルールを介してnの前のノードに関連付けられていない場合。
NewCommentMapは、コメントグループを「最大の」ノードに関連付けようとします。たとえば、コメントが代入文の後に続く行コメントの場合、コメントは代入文全体ではなく、代入文の最後のオペランドに関連づけられます。
func (CommentMap) Comments ¶ added in v1.1.0
func (cmap CommentMap) Comments() []*CommentGroup
Commentsはコメントマップ内のコメントグループのリストを返します。 結果はソースの順にソートされます。
func (CommentMap) Filter ¶ added in v1.1.0
func (cmap CommentMap) Filter(node Node) CommentMap
Filterはnodeによって指定されたASTに対応するノードが存在する場合、cmapのエントリのみで構成される新しいコメントマップを返します。
func (CommentMap) String ¶ added in v1.1.0
func (cmap CommentMap) String() string
func (CommentMap) Update ¶ added in v1.1.0
func (cmap CommentMap) Update(old, new Node) Node
Updateはコメントマップ内の古いノードを新しいノードで置き換え、新しいノードを返します。 古いノードに関連付けられていたコメントは、新しいノードに関連付けられます。
type CompositeLit ¶
type CompositeLit struct { Type Expr Lbrace token.Pos Elts []Expr Rbrace token.Pos Incomplete bool }
CompositeLitノードは複合リテラルを表します。
func (*CompositeLit) End ¶
func (x *CompositeLit) End() token.Pos
func (*CompositeLit) Pos ¶
func (x *CompositeLit) Pos() token.Pos
type Decl ¶
type Decl interface { Node // contains filtered or unexported methods }
すべての宣言ノードはDeclインターフェースを実装します。
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
すべての式のノードは、Exprインターフェースを実装しています。
type Field ¶
type Field struct { Doc *CommentGroup Names []*Ident Type Expr Tag *BasicLit Comment *CommentGroup }
Fieldは、struct型のフィールド宣言リスト、インタフェース型のメソッドリスト、またはシグネチャのパラメータ/結果の宣言を表します。 [Field.Names] は、無名のパラメータ(型のみを含むパラメータリスト)や埋め込まれたstructフィールドの場合はnilです。 後者の場合、フィールド名は型名です。
type FieldFilter ¶
出力を制御するために、Fprint にFieldFilterを指定することができます。
type FieldList ¶
FieldList は、かっこ、中かっこ、又は角かっこで囲まれたフィールドのリストを表します。
type File ¶
type File struct { Doc *CommentGroup Package token.Pos Name *Ident Decls []Decl FileStart, FileEnd token.Pos Scope *Scope Imports []*ImportSpec Unresolved []*Ident Comments []*CommentGroup GoVersion string }
FileノードはGoのソースファイルを表します。
Commentsリストには、出現順にソースファイル内のすべてのコメントが含まれており、 DocとCommentフィールドを介して他のノードから指し示されるコメントも含まれます。
コメントを含むソースコードを正しく出力するために(パッケージgo/formatとgo/printerを使用して)特別な注意が必要です: コメントは、位置に基づいてトークンの間に挿入されます。構文木ノードが削除または移動される場合、 その近くにある関連するコメントも削除( [File.Comments] リストから)またはそれらの位置を更新して移動しなければなりません。 これらの操作の一部を容易にするために、CommentMap を使用することもできます。
コメントがノードとどのように関連付けられるかは、操作するプログラムによる構文木の解釈に依存します: Docと Comment コメント以外の残りのコメントは、「free-floating」です(イシュー #18593、#20744 も参照)。
func MergePackageFiles ¶
MergePackageFilesはパッケージに所属するファイルのASTをマージしてファイルASTを作成します。モードフラグはマージの動作を制御します。
type FuncDecl ¶
type FuncDecl struct { Doc *CommentGroup Recv *FieldList Name *Ident Type *FuncType Body *BlockStmt }
FuncDeclノードは関数宣言を表します。
type GenDecl ¶
type GenDecl struct { Doc *CommentGroup TokPos token.Pos Tok token.Token Lparen token.Pos Specs []Spec Rparen token.Pos }
GenDeclノード(ジェネリック宣言ノード)は、import、constant、type、またはvariableの宣言を表します。有効なLparenの位置(Lparen.IsValid())は、括弧で囲まれた宣言を示します。
Tokの値とSpecs要素の型の関係:
token.IMPORT *ImportSpec token.CONST *ValueSpec token.TYPE *TypeSpec token.VAR *ValueSpec
type Ident ¶
Identノードは、識別子を表します。
type ImportSpec ¶
type ImportSpec struct { Doc *CommentGroup Name *Ident Path *BasicLit Comment *CommentGroup EndPos token.Pos }
ImportSpecノードは1つのパッケージのインポートを表します。
func (*ImportSpec) End ¶
func (s *ImportSpec) End() token.Pos
func (*ImportSpec) Pos ¶
func (s *ImportSpec) Pos() token.Pos
type Importer
deprecated
Importerは、インポートパスをパッケージオブジェクトに解決します。 importsマップは、すでにインポートされたパッケージを記録し、 パッケージID(正規のインポートパス)でインデックス付けします。 Importerは、正規のインポートパスを決定し、 それがすでにimportsマップに存在するかどうかを確認する必要があります。 もしそうであれば、Importerはマップエントリを返すことができます。そうでなければ、 Importerは指定されたパスのパッケージデータを新しい *Object(pkg)にロードし、 pkgをimportsマップに記録し、その後pkgを返すべきです。
Deprecated: 代わりに型チェッカー go/types を使用してください。詳細は Object を参照してください。
type IncDecStmt ¶
IncDecStmtノードは、増分または減分文を表します。
func (*IncDecStmt) End ¶
func (s *IncDecStmt) End() token.Pos
func (*IncDecStmt) Pos ¶
func (s *IncDecStmt) Pos() token.Pos
type IndexListExpr ¶ added in v1.18.0
IndexListExprノードは、複数のインデックスで続く式を表します。
func (*IndexListExpr) End ¶ added in v1.18.0
func (x *IndexListExpr) End() token.Pos
func (*IndexListExpr) Pos ¶ added in v1.18.0
func (x *IndexListExpr) Pos() token.Pos
type InterfaceType ¶
InterfaceTypeノードは、インターフェースの型を表します。
func (*InterfaceType) End ¶
func (x *InterfaceType) End() token.Pos
func (*InterfaceType) Pos ¶
func (x *InterfaceType) Pos() token.Pos
type KeyValueExpr ¶
KeyValueExprノードは、コンポジットリテラル内の(key: value)のペアを表します。
func (*KeyValueExpr) End ¶
func (x *KeyValueExpr) End() token.Pos
func (*KeyValueExpr) Pos ¶
func (x *KeyValueExpr) Pos() token.Pos
type LabeledStmt ¶
LabeledStmtノードは、ラベル付き文を表します。
func (*LabeledStmt) End ¶
func (s *LabeledStmt) End() token.Pos
func (*LabeledStmt) Pos ¶
func (s *LabeledStmt) Pos() token.Pos
type Object
deprecated
オブジェクトは、パッケージ、定数、型、変数、関数(メソッドを含む)、またはラベルなど、名前付きの言語エンティティを表します。
データフィールドには、オブジェクト固有のデータが含まれます:
Kind Data type Data value Pkg *Scope package scope Con int iota for the respective declaration
Deprecated: IdentsとObjectsの関係は、型情報なしでは正しく計算できません。 例えば、式T{K: 0}は、Tの型によって、構造体、マップ、スライス、または配列リテラルを表す可能性があります。 Tが構造体の場合、KはTのフィールドを参照しますが、他の型では環境内の値を参照します。
新しいプログラムは、[parser.SkipObjectResolution] パーサーフラグを設定して、 構文的なオブジェクト解決を無効にするべきです(これによりCPUとメモリも節約されます)。 そして、オブジェクト解決が必要な場合は代わりに型チェッカー go/types を使用します。 詳細は、[types.Info] 構造体のDefs、Uses、およびImplicitsフィールドを参照してください。
type Package
deprecated
A Package node represents a set of source files collectively building a Go package.
Deprecated: use the type checker go/types instead; see Object.
func NewPackage
deprecated
func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error)
NewPackageは、File ノードのセットから新しい Package ノードを作成します。それは ファイル間の未解決の識別子を解決し、それぞれのファイルのUnresolvedリストを それに応じて更新します。非nilのimporterとuniverseスコープが提供されている場合、 パッケージファイルのいずれにも宣言されていない識別子を解決するために使用されます。任意の 残りの未解決の識別子は未宣言として報告されます。ファイルが 異なるパッケージに属している場合、一つのパッケージ名が選択され、 異なるパッケージ名を持つファイルが報告され、その後無視されます。 結果はパッケージノードと、エラーがあった場合は [scanner.ErrorList] です。
Deprecated: 代わりに型チェッカー go/types を使用してください。詳細は Object を参照してください。
type RangeStmt ¶
type RangeStmt struct { For token.Pos Key, Value Expr TokPos token.Pos Tok token.Token Range token.Pos X Expr Body *BlockStmt }
RangeStmtはrange節を持つfor文を表します。
type ReturnStmt ¶
ReturnStmtノードは、return文を表します。
func (*ReturnStmt) End ¶
func (s *ReturnStmt) End() token.Pos
func (*ReturnStmt) Pos ¶
func (s *ReturnStmt) Pos() token.Pos
type Scope
deprecated
Scopeは、スコープ内で宣言された名前付き言語エンティティのセットと、 直接囲む(外側の)スコープへのリンクを維持します。
Deprecated: 代わりに型チェッカー go/types を使用してください。詳細は Object を参照してください。
func (*Scope) Insert ¶
Insertは名前付きオブジェクトobjをスコープsに挿入しようとします。 もしスコープに同じ名前のオブジェクトaltが既に存在する場合、 Insertはスコープを変更せずにaltを返します。そうでなければ、 objを挿入し、nilを返します。
type SelectStmt ¶
SelectStmtノードは、select文を表します。
func (*SelectStmt) End ¶
func (s *SelectStmt) End() token.Pos
func (*SelectStmt) Pos ¶
func (s *SelectStmt) Pos() token.Pos
type SelectorExpr ¶
SelectorExprノードは、セレクターに続く式を表します。
func (*SelectorExpr) End ¶
func (x *SelectorExpr) End() token.Pos
func (*SelectorExpr) Pos ¶
func (x *SelectorExpr) Pos() token.Pos
type SliceExpr ¶
type SliceExpr struct { X Expr Lbrack token.Pos Low Expr High Expr Max Expr Slice3 bool Rbrack token.Pos }
SliceExprノードはスライスのインデックスが続いた式を表します。
type Spec ¶
type Spec interface { Node // contains filtered or unexported methods }
Spec型は、*ImportSpec、*ValueSpec、および*TypeSpecのいずれかを表します。
type Stmt ¶
type Stmt interface { Node // contains filtered or unexported methods }
すべてのステートメントノードは、Stmtインターフェースを実装しています。
type StructType ¶
StructTypeノードはstruct型を表します。
func (*StructType) End ¶
func (x *StructType) End() token.Pos
func (*StructType) Pos ¶
func (x *StructType) Pos() token.Pos
type SwitchStmt ¶
SwitchStmtノードは、式を使ったスイッチ文を表します。
func (*SwitchStmt) End ¶
func (s *SwitchStmt) End() token.Pos
func (*SwitchStmt) Pos ¶
func (s *SwitchStmt) Pos() token.Pos
type TypeAssertExpr ¶
TypeAssertExprノードは、式の後に型アサーションが続くことを表します。
func (*TypeAssertExpr) End ¶
func (x *TypeAssertExpr) End() token.Pos
func (*TypeAssertExpr) Pos ¶
func (x *TypeAssertExpr) Pos() token.Pos
type TypeSpec ¶
type TypeSpec struct { Doc *CommentGroup Name *Ident TypeParams *FieldList Assign token.Pos Type Expr Comment *CommentGroup }
TypeSpecノードは、型の宣言を表します (TypeSpecの生成)。
type TypeSwitchStmt ¶
TypeSwitchStmtノードは、型スイッチ文を表します。
func (*TypeSwitchStmt) End ¶
func (s *TypeSwitchStmt) End() token.Pos
func (*TypeSwitchStmt) Pos ¶
func (s *TypeSwitchStmt) Pos() token.Pos
type ValueSpec ¶
type ValueSpec struct { Doc *CommentGroup Names []*Ident Type Expr Values []Expr Comment *CommentGroup }
ValueSpecノードは定数または変数宣言を表します。 (ConstSpecまたはVarSpecプロダクション)。