github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/cgo/main.go (about)

     1  // Copyright 2009 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  // Cgo; 概要についてはdoc.goを参照してください。
     6  
     7  // TODO(rsc):
     8  // 正しい行番号のアノテーションを出力する。
     9  // gcがアノテーションを理解するようにする。
    10  
    11  package main
    12  
    13  import (
    14  	"github.com/shogo82148/std/go/ast"
    15  	"github.com/shogo82148/std/go/token"
    16  
    17  	"github.com/shogo82148/std/cmd/internal/edit"
    18  )
    19  
    20  // パッケージは書く予定のパッケージに関する情報を集めます。
    21  type Package struct {
    22  	PackageName string
    23  	PackagePath string
    24  	PtrSize     int64
    25  	IntSize     int64
    26  	GccOptions  []string
    27  	GccIsClang  bool
    28  	LdFlags     []string
    29  	Written     map[string]bool
    30  	Name        map[string]*Name
    31  	ExpFunc     []*ExpFunc
    32  	Decl        []ast.Decl
    33  	GoFiles     []string
    34  	GccFiles    []string
    35  	Preamble    string
    36  	typedefs    map[string]bool
    37  	typedefList []typedefInfo
    38  	noCallbacks map[string]bool
    39  	noEscapes   map[string]bool
    40  }
    41  
    42  type File struct {
    43  	AST         *ast.File
    44  	Comments    []*ast.CommentGroup
    45  	Package     string
    46  	Preamble    string
    47  	Ref         []*Ref
    48  	Calls       []*Call
    49  	ExpFunc     []*ExpFunc
    50  	Name        map[string]*Name
    51  	NamePos     map[*Name]token.Pos
    52  	NoCallbacks map[string]bool
    53  	NoEscapes   map[string]bool
    54  	Edit        *edit.Buffer
    55  }
    56  
    57  // Callは、ASTのC.xxx関数の呼び出しを参照します。
    58  type Call struct {
    59  	Call     *ast.CallExpr
    60  	Deferred bool
    61  	Done     bool
    62  }
    63  
    64  // Ref型はAST内のC.xxxの形式の式を参照します。
    65  type Ref struct {
    66  	Name    *Name
    67  	Expr    *ast.Expr
    68  	Context astContext
    69  	Done    bool
    70  }
    71  
    72  func (r *Ref) Pos() token.Pos
    73  
    74  // NameはC.xxxに関する情報を収集します。
    75  type Name struct {
    76  	Go       string
    77  	Mangle   string
    78  	C        string
    79  	Define   string
    80  	Kind     string
    81  	Type     *Type
    82  	FuncType *FuncType
    83  	AddError bool
    84  	Const    string
    85  }
    86  
    87  // IsVarは、Kindが "var" または "fpvar" であるかどうかを報告します。
    88  func (n *Name) IsVar() bool
    89  
    90  // IsConstはKindが「iconst」、「fconst」または「sconst」であるかどうか報告します。
    91  func (n *Name) IsConst() bool
    92  
    93  // ExpFuncはCから呼び出すことができるエクスポートされた関数です。
    94  // このような関数は、Goの入力ファイルに含まれるドキュメントコメントの行//export ExpNameによって識別されます。
    95  type ExpFunc struct {
    96  	Func    *ast.FuncDecl
    97  	ExpName string
    98  	Doc     string
    99  }
   100  
   101  // TypeReprは型の文字列表現を含む
   102  type TypeRepr struct {
   103  	Repr       string
   104  	FormatArgs []interface{}
   105  }
   106  
   107  // TypeはCとGoの世界の両方でタイプに関する情報を収集します。
   108  type Type struct {
   109  	Size       int64
   110  	Align      int64
   111  	C          *TypeRepr
   112  	Go         ast.Expr
   113  	EnumValues map[string]int64
   114  	Typedef    string
   115  	BadPointer bool
   116  }
   117  
   118  // FuncTypeはCとGoの両方の世界における関数型に関する情報を収集します。
   119  type FuncType struct {
   120  	Params []*Type
   121  	Result *Type
   122  	Go     *ast.FuncType
   123  }
   124  
   125  // fについて記録すべきことを記録する
   126  func (p *Package) Record(f *File)