types

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2018 License: MIT Imports: 3 Imported by: 34

Documentation

Index

Constants

View Source
const (
	ChanDirSend = 1
	ChanDirRecv = 2
	ChanDirAny  = ChanDirSend | ChanDirRecv
)

Variables

View Source
var (
	// Checks, is type contain array.
	IsArray = IsType(TypeArray)
	// Checks, is type contain map.
	IsMap = IsType(TypeMap)
	// Checks, is type contain interface.
	IsInterface = IsType(TypeInterface)
	IsEllipsis  = IsType(TypeEllipsis)
	IsStruct    = IsType(TypeStruct)
	IsFunction  = IsType(TypeFunction)
)

Checks, is type contain some type. Generic checkers.

View Source
var BuiltinFunctions = map[string]bool{
	"append":  true,
	"copy":    true,
	"delete":  true,
	"len":     true,
	"cap":     true,
	"make":    true,
	"new":     true,
	"complex": true,
	"real":    true,
	"imag":    true,
	"close":   true,
	"panic":   true,
	"recover": true,
	"print":   true,
	"println": true,
}

List of all builtin functions.

View Source
var BuiltinTypes = map[string]bool{
	"bool":       true,
	"uint8":      true,
	"uint16":     true,
	"uint32":     true,
	"uint64":     true,
	"int8":       true,
	"int16":      true,
	"int32":      true,
	"int64":      true,
	"float32":    true,
	"float64":    true,
	"complex64":  true,
	"complex128": true,
	"string":     true,
	"int":        true,
	"uint":       true,
	"uintptr":    true,
	"byte":       true,
	"rune":       true,
	"error":      true,
}

List of all builtin types.

Functions

func IsBuiltin

func IsBuiltin(t Type) bool

Checks is type is builtin type.

func IsBuiltinFuncString

func IsBuiltinFuncString(t string) bool

func IsBuiltinString

func IsBuiltinString(t string) bool

func IsBuiltinTypeString

func IsBuiltinTypeString(t string) bool

func IsType

func IsType(f func(Type) Type) func(Type) bool

func TypeName

func TypeName(t Type) *string

Returns name of type if it has it. Raw maps and interfaces do not have names.

Types

type Base

type Base struct {
	Name string   `json:"name,omitempty"`
	Docs []string `json:"docs,omitempty"`
}

Base type for all (almost) entities. It contains name of entity and docs. Docs is a comments in golang syntax above entity declaration. Each block comment is counted as one.

type File

type File struct {
	Base                   // `File.Name` is package name, `File.Docs` is a comments above `package ...`
	Imports    []*Import   `json:"imports,omitempty"`    // Contains imports and their aliases from `import` blocks.
	Constants  []Variable  `json:"constants,omitempty"`  // Contains constant variables from `const` blocks.
	Vars       []Variable  `json:"vars,omitempty"`       // Contains variables from `var` blocks.
	Interfaces []Interface `json:"interfaces,omitempty"` // Contains `type Foo interface` declarations.
	Structures []Struct    `json:"structures,omitempty"` // Contains `type Foo struct` declarations.
	Functions  []Function  `json:"functions,omitempty"`  // Contains `func Foo() {}` declarations.
	Methods    []Method    `json:"methods,omitempty"`    // Contains `func (a A) Foo(b B) (c C) {}` declarations.
	Types      []FileType  `json:"types,omitempty"`      // Contains `type X int` declarations.
}

File is a top-level entity, that contains all top-level declarations of the file.

func (File) HasPackage

func (f File) HasPackage(packageName string) bool

type FileType

type FileType struct {
	Base
	Type    Type      `json:"type,omitempty"`
	Methods []*Method `json:"methods,omitempty"`
}

type Function

type Function struct {
	Base
	Args    []Variable `json:"args,omitempty"`
	Results []Variable `json:"results,omitempty"`
}

func (Function) GoString

func (f Function) GoString() string

func (Function) String

func (f Function) String() string

type Import

type Import struct {
	Base
	Package string `json:"package,omitempty"`
}

func TypeImport

func TypeImport(t Type) *Import

Returns Import of type or nil.

func (Import) GoString

func (i Import) GoString() string

func (Import) String

func (i Import) String() string

type Interface

type Interface struct {
	Base
	Methods    []*Function `json:"methods,omitempty"`    // List of functions (methods) of the interface.
	Interfaces []Variable  `json:"interfaces,omitempty"` // List of embedded interfaces.
}

func (Interface) GoString

func (i Interface) GoString() string

func (Interface) IsEmpty added in v1.1.0

func (i Interface) IsEmpty() bool

func (Interface) String

func (i Interface) String() string

type LinearType

type LinearType interface {
	NextType() Type
}

type Method

type Method struct {
	Function
	Receiver Variable `json:"receiver,omitempty"`
}

func (Method) GoString

func (f Method) GoString() string

func (Method) String

func (f Method) String() string

type Struct

type Struct struct {
	Base
	Fields  []StructField `json:"fields,omitempty"`
	Methods []*Method     `json:"methods,omitempty"`
}

func (Struct) IsEmpty added in v1.1.0

func (s Struct) IsEmpty() bool

func (Struct) String

func (s Struct) String() string

type StructField

type StructField struct {
	Variable
	Tags    map[string][]string `json:"tags,omitempty"`
	RawTags string              `json:"raw,omitempty"` // Raw string from source.
}

func (StructField) String

func (f StructField) String() string

type TArray

type TArray struct {
	ArrayLen   int  `json:"array_len,omitempty"`
	IsSlice    bool `json:"is_slice,omitempty"` // [] declaration
	IsEllipsis bool `json:"is_ellipsis,omitempty"`
	Next       Type `json:"next,omitempty"`
}

func (TArray) NextType

func (i TArray) NextType() Type

func (TArray) String

func (i TArray) String() string

type TChan

type TChan struct {
	Direction int  `json:"direction"`
	Next      Type `json:"next"`
}

func (TChan) NextType

func (c TChan) NextType() Type

func (TChan) String

func (c TChan) String() string

type TEllipsis

type TEllipsis struct {
	Next Type `json:"next,omitempty"`
}

TEllipsis used only for function params in declarations like `strs ...string`

func (TEllipsis) NextType

func (i TEllipsis) NextType() Type

func (TEllipsis) String

func (i TEllipsis) String() string

type TImport

type TImport struct {
	Import *Import `json:"import,omitempty"`
	Next   Type    `json:"next,omitempty"`
}

func (TImport) NextType

func (i TImport) NextType() Type

func (TImport) String

func (i TImport) String() string

type TInterface

type TInterface struct {
	Interface *Interface `json:"interface,omitempty"`
}

func (TInterface) String

func (i TInterface) String() string

type TMap

type TMap struct {
	Key   Type `json:"key,omitempty"`
	Value Type `json:"value,omitempty"`
}

func (TMap) String

func (m TMap) String() string

type TName

type TName struct {
	TypeName string `json:"type_name,omitempty"`
}

func (TName) NextType

func (i TName) NextType() Type

func (TName) String

func (i TName) String() string

type TPointer

type TPointer struct {
	NumberOfPointers int  `json:"number_of_pointers,omitempty"`
	Next             Type `json:"next,omitempty"`
}

func (TPointer) NextType

func (i TPointer) NextType() Type

func (TPointer) String

func (i TPointer) String() string

type Type

type Type interface {
	String() string
	// contains filtered or unexported methods
}

func TypeArray

func TypeArray(t Type) Type

Returns first array entity of type. If array not found, returns nil.

func TypeEllipsis

func TypeEllipsis(t Type) Type

func TypeFunction added in v1.1.0

func TypeFunction(t Type) Type

func TypeInterface

func TypeInterface(t Type) Type

func TypeMap

func TypeMap(t Type) Type

func TypeStruct added in v1.1.0

func TypeStruct(t Type) Type

type Variable

type Variable struct {
	Base
	Type Type `json:"type,omitempty"`
}

func (Variable) GoString

func (v Variable) GoString() string

func (Variable) String

func (v Variable) String() string

String representation of variable without docs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL