github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/cover/cover.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "github.com/shogo82148/std/go/ast" 9 "github.com/shogo82148/std/go/token" 10 "github.com/shogo82148/std/internal/coverage" 11 "github.com/shogo82148/std/internal/coverage/encodemeta" 12 13 "github.com/shogo82148/std/cmd/internal/edit" 14 ) 15 16 // Blockは解析で記録する基本ブロックに関する情報を表します。 17 // 注:基本ブロックの定義は制御構造に基づいています。&&や||は分割しません。 18 // 分割することはできますが、重要ではないと思われますので、手間をかける価値はありません。 19 type Block struct { 20 startByte token.Pos 21 endByte token.Pos 22 numStmt int 23 } 24 25 // パッケージはパッケージ固有の状態を保持します。 26 type Package struct { 27 mdb *encodemeta.CoverageMetaDataBuilder 28 counterLengths []int 29 } 30 31 // 関数は関数特有の状態を持ちます。 32 type Func struct { 33 units []coverage.CoverableUnit 34 counterVar string 35 } 36 37 // Fileはパーサーで使用されるファイルの状態のラッパーです。 38 // 基本的なパースツリーウォーカーは、このタイプのメソッドです。 39 type File struct { 40 fset *token.FileSet 41 name string 42 astFile *ast.File 43 blocks []Block 44 content []byte 45 edit *edit.Buffer 46 mdb *encodemeta.CoverageMetaDataBuilder 47 fn Func 48 pkg *Package 49 } 50 51 // Visitはast.Visitorインターフェースを実装します。 52 func (f *File) Visit(node ast.Node) ast.Visitor