typecheck

package
v0.0.0-...-b83a777 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2017 License: BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package typecheck is a Neugram type checker.

Index

Constants

This section is empty.

Variables

View Source
var Universe = &Scope{Objs: universeObjs}

Functions

func IsError

func IsError(t tipe.Type) bool

Types

type Checker

type Checker struct {
	ImportGo func(path string) (*gotypes.Package, error)

	Values  map[expr.Expr]constant.Value
	NgPkgs  map[string]*tipe.Package // abs file path -> pkg
	GoPkgs  map[string]*tipe.Package // path -> pkg
	GoTypes map[gotypes.Type]tipe.Type

	// TODO: GoEquiv is tricky and deserving of docs. Particular type instance is associated with a Go type. That means EqualType(t1, t2)==true but t1 could have GoEquiv and t2 not.
	GoEquiv map[tipe.Type]gotypes.Type
	NumSpec map[expr.Expr]tipe.Basic // *tipe.Call, *tipe.CompLiteral -> numeric basic type
	Errs    []error
	// contains filtered or unexported fields
}

func New

func New(initPkg string) *Checker

func (*Checker) Add

func (c *Checker) Add(s stmt.Stmt) tipe.Type

func (*Checker) Lookup

func (c *Checker) Lookup(name string) *Obj

func (*Checker) NewScope

func (c *Checker) NewScope() *Checker

NewScope make a copy of Checker with a new, blank current scope. The two checkers share all type checked data.

func (*Checker) Type

func (c *Checker) Type(e expr.Expr) (t tipe.Type)

func (*Checker) TypesWithPrefix

func (c *Checker) TypesWithPrefix(prefix string) (res []string)

TypesWithPrefix returns the names of all types currently in scope that start with prefix.

type Obj

type Obj struct {
	Kind ObjKind
	Type tipe.Type
	Decl interface{} // *expr.FuncLiteral, *stmt.MethodikDecl, constant.Value
	Used bool
}

An Obj represents a declared constant, type, variable, or function.

type ObjKind

type ObjKind int
const (
	ObjUnknown ObjKind = iota
	ObjVar
	ObjConst
	ObjPkg
	ObjType
)

func (ObjKind) String

func (o ObjKind) String() string

type Scope

type Scope struct {
	Parent *Scope
	Objs   map[string]*Obj
	// contains filtered or unexported fields
}

func (*Scope) DebugPrint

func (s *Scope) DebugPrint(indent int)

func (*Scope) LookupRec

func (s *Scope) LookupRec(name string) *Obj

Jump to

Keyboard shortcuts

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