meta

package
v0.0.0-...-e00d658 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Invalid BasicKind = "" // type is invalid

	// predeclared types
	Bool          = "bool"
	Int           = "int"
	Int8          = "int8"
	Int16         = "int16"
	Int32         = "int32"
	Int64         = "int64"
	Uint          = "uint"
	Uint8         = "uint8"
	Uint16        = "uint16"
	Uint32        = "uint32"
	Uint64        = "uint64"
	Uintptr       = "uintptr"
	Float32       = "float32"
	Float64       = "float64"
	Complex64     = "complex64"
	Complex128    = "complex128"
	String        = "string"
	UnsafePointer = "unsafe.Pointer"

	// aliases
	Byte = Uint8
	Rune = Int32
)
View Source
const (
	SendRecv ChanDir = "SendRecv"
	SendOnly         = "SendOnly"
	RecvOnly         = "RecvOnly"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	Pos    Location
	Doc    string
	Name   string
	Values map[string]interface{}
}

type Array

type Array struct {
	Len    int64
	DeclId DeclId
}

Arrays has a length and an according type. Generic declarations (like map[x]y) refer to their own type.

type Basic

type Basic struct {
	Kind BasicKind
}

A Basic type represents a build-in type

type BasicKind

type BasicKind string

BasicKind describes the kind of basic type.

func (BasicKind) IsFloat

func (b BasicKind) IsFloat() bool

func (BasicKind) IsInteger

func (b BasicKind) IsInteger() bool

func (BasicKind) IsString

func (b BasicKind) IsString() bool

func (BasicKind) IsUnsigned

func (b BasicKind) IsUnsigned() bool

func (BasicKind) String

func (b BasicKind) String() string

String returns the universe name of the basic kind

type ChanDir

type ChanDir string

A ChanDir specified the declared channel direction

type Channel

type Channel struct {
	ChanDir ChanDir
	DeclId  DeclId
}

A Channel declares the direction and its type.

type DeclId

type DeclId string

DeclId is usually a unique hash for a declaration (not just named types).

type DeclIdBuilder

type DeclIdBuilder struct {
	// contains filtered or unexported fields
}

func NewDeclId

func NewDeclId() *DeclIdBuilder

func (*DeclIdBuilder) Finish

func (b *DeclIdBuilder) Finish() DeclId

func (*DeclIdBuilder) Put

func (b *DeclIdBuilder) Put(values ...interface{}) *DeclIdBuilder

type Interface

type Interface struct {
	// Embeddeds refers only to TypeIds of other embedded Interfaces.
	Embeddeds []DeclId

	// AllMethods refers only to TypeIds of Signatures included by all declared methods, also
	// by embedded ones.
	AllMethods []DeclId
}

An Interface has a set of signatures and embedded types.

type Location

type Location string

func NewLocation

func NewLocation(filename string, line, col int) Location

type Map

type Map struct {
	Key   DeclId
	Value DeclId
}

A Map is a generic build-in with two parameters.

type Named

type Named struct {
	Location    Location
	Doc         string
	Annotations []Annotation `json:",omitempty"`

	// Name is the LHS of the declaration or empty if no such thing
	Name string

	// Underlying is the resolved RHS side of the declaration.
	Underlying DeclId

	// Methods contains the declared methods for this named type (Signature).
	Methods []DeclId `json:",omitempty"`
}

A Named type is a declared type somewhere in the source. It is not a build-in, however it may be also an anonymous type, where the name is just empty.

type Package

type Package struct {
	Path         string
	Name         string
	Declarations []DeclId
}

type PackageQualifier

type PackageQualifier struct {
	// Path is a / separated name to resolve a package.
	Path string
	// Name is the actual identifier of the package. This is also used by default, if not renamed at import.
	Name string
}

A PackageQualifier consists of an import path and the according package name. This is rather obscure, because you can never deduce the actual package name from its path, however it allows at least elegant solutions like this:

  • versioned packages, e.g. github.com/myproject/myapi and github.com/myproject/myapi/v2 should both be named myapi
  • using path with chars which are illegal identifiers, like github.com/myproject/my-api (could still be myapi)

type Param

type Param struct {
	Pos *Location `json:",omitempty"`

	Doc         string       `json:",omitempty"`
	Annotations []Annotation `json:",omitempty"`

	// The Name of the parameter, if not empty
	Name string

	// The type of the parameter
	DeclId DeclId

	// Tag is the raw string literal. The parsed literal is in Tags
	Tag string `json:",omitempty"`

	// Tags are the parsed form of the Tag literal
	Tags tag.Tags `json:",omitempty"`
}

A Param is not a type but declares a tuple of name and type.

type PkgId

type PkgId string

type Pointer

type Pointer struct {
	Base DeclId
}

A Pointer to a base type (which itself may be again a pointer).

type Signature

type Signature struct {
	// Receiver is an optional parameter.
	Receiver *Param `json:",omitempty"`

	// Params represent the incoming parameters.
	Params []Param `json:",omitempty"`

	// Results represent the outgoing parameters.
	Results []Param `json:",omitempty"`

	// Variadic indicates if the last parameter is a ...T declaration.
	Variadic bool `json:",omitempty"`
}

Signature represents a declared function or method.

type Slice

type Slice struct {
	// Underlying of the sliced type.
	DeclId DeclId
}

A Slice wraps a subset of an array of variable length

type Struct

type Struct struct {
	Fields []Param `json:",omitempty"`
}

A Struct contains field definitions. Interestingly the method set does not belong to the underlying type, which makes them assignable to each other. However this is also true for tags, so it is quite inconsistent.

type Table

type Table struct {
	Packages     map[PkgId]*Package
	Declarations map[DeclId]Type
}

Table contains all resolved type declarations and other deduplicated information. Due to the sake of the default value in json for integer types (==0), we use 0 to indicate "undefined".

func NewTable

func NewTable() *Table

func (*Table) CreateImportTable

func (t *Table) CreateImportTable() map[DeclId]PkgId

CreateImportTable creates a new table which assigns each declaration id to its containing package id.

func (*Table) DeclIds

func (t *Table) DeclIds() []DeclId

DeclIds returns a stable and sorted slice of declarations ids

func (*Table) HasDeclaration

func (t *Table) HasDeclaration(q DeclId) bool

func (*Table) PackageByImportPath

func (t *Table) PackageByImportPath(importPath string) (PkgId, bool)

func (*Table) PutDeclaration

func (t *Table) PutDeclaration(q DeclId, p Type)

func (*Table) PutNamedDeclaration

func (t *Table) PutNamedDeclaration(importPath, pkgName string, q DeclId, p *Named)

func (*Table) String

func (t *Table) String() string

type Type

type Type struct {
	Basic     *Basic     `json:",omitempty"`
	Array     *Array     `json:",omitempty"`
	Channel   *Channel   `json:",omitempty"`
	Interface *Interface `json:",omitempty"`
	Map       *Map       `json:",omitempty"`
	Pointer   *Pointer   `json:",omitempty"`
	Slice     *Slice     `json:",omitempty"`
	Struct    *Struct    `json:",omitempty"`
	Named     *Named     `json:",omitempty"`
	Signature *Signature `json:",omitempty"`
}

An Type is a union tuple of exact one of Basic, Array, Channel, Interface, Map Pointer or Struct.

func (Type) Kind

func (t Type) Kind() interface{}

Kind returns the first non-nil union value.

Jump to

Keyboard shortcuts

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