Documentation ¶
Overview ¶
Package types provide a type-checker for the SubC language.
Index ¶
- Variables
- func ExprString(x ast.Expr) string
- func Identical(x, y Type) bool
- func ObjectString(obj Object) string
- func SelectionString(s *Selection) string
- func TypeString(typ Type) string
- func WriteExpr(buf *bytes.Buffer, x ast.Expr)
- func WriteSignature(buf *bytes.Buffer, sig *Signature)
- func WriteType(buf *bytes.Buffer, typ Type)
- type Array
- type Basic
- type BasicInfo
- type BasicType
- type Config
- type Const
- type Enum
- type Func
- type Fwrd
- type Info
- type Label
- type Named
- type Namespace
- type Object
- type Pointer
- type Record
- type Scope
- type Selection
- type Signature
- type Sizes
- type StdSizes
- type Storage
- type Tuple
- type Type
- type TypeAndValue
- type TypeName
- type Var
Constants ¶
This section is empty.
Variables ¶
var Typ = [...]*Basic{ Invalid: {Invalid, 0, "invalid type"}, Bool: {Bool, IsBoolean, "_Bool"}, Complex: {Complex, IsComplex, "_Complex"}, Char: {Char, IsInteger, "char"}, Short: {Short, IsInteger, "short"}, Int: {Int, IsInteger, "int"}, Long: {Int, IsInteger, "long"}, Float: {Float, IsFloat, "float"}, Double: {Double, IsFloat, "double"}, Void: {Void, IsVoid, "void"}, UntypedString: {UntypedString, IsString | IsUntyped, "untyped string"}, }
Typ is an array containing all the basic types.
Functions ¶
func ExprString ¶
ExprString returns a pretty printed version of an expression.
func ObjectString ¶
ObjectString returns a pretty-printed version of an object.
func SelectionString ¶
SelectionString returns a pretty printed output of a selection.
func TypeString ¶
TypeString returns a pretty printed string of a type.
func WriteSignature ¶
WriteSignature writes the representation of the signature sig to buf,
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array represents an array.
func (*Array) Underlying ¶
type Basic ¶
type Basic struct {
// contains filtered or unexported fields
}
Basic represents a native type like char or int.
func (*Basic) Underlying ¶
type Config ¶
type Config struct { MaxErrors int // the maximum number of errors before bailing out Sizes Sizes // used to determine the size, offset of and alignment of types. }
Config is used to control the behavior of the type checker while it is running.
type Const ¶
type Const struct {
// contains filtered or unexported fields
}
Const represents a constant value.
type Enum ¶
type Enum struct {
// contains filtered or unexported fields
}
Enum represent enums.
func (*Enum) Underlying ¶
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func represents a function.
type Fwrd ¶
type Fwrd struct {
// contains filtered or unexported fields
}
Fwrd represents a forward declaration.
type Info ¶
type Info struct { // stores all the type and values of the expression, values are stored if // the expression is constant Types map[ast.Expr]TypeAndValue // used to store the declaration of objects based on their identifier Defs map[*ast.Ident]Object // stores identifier that are used, it can be used to lookup to its definitions. Uses map[*ast.Ident]Object // selections from struct and unions Selections map[*ast.SelectorExpr]*Selection // scope information Scopes map[ast.Node]*Scope }
Info contains the type checked information after the type checker is ran.
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
Label represents a label.
type Named ¶
type Named struct {
// contains filtered or unexported fields
}
Named represents a name that has been defined by a record. An example is struct file fd, fd will be the Named in this case.
func (*Named) Underlying ¶
type Namespace ¶
type Namespace int
Namespace represents a namespace for the language
type Object ¶
type Object interface { Parent() *Scope // returns the parent scope of the object is in Pos() scanner.Position // the position of the object in the source code Name() string // the name of the object Type() Type // the type of the object String() string // the string of the object // contains filtered or unexported methods }
Object represents a type checked object.
type Pointer ¶
type Pointer struct {
// contains filtered or unexported fields
}
Pointer represents a pointer.
func NewPointer ¶
NewPointer creates a new pointer. The decay represents if this was an array that decayed to a pointer when passing in a function or using it in operations.
func (*Pointer) Underlying ¶
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record represents struct and union types.
func (*Record) Underlying ¶
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope represent a scope.
func (*Scope) Insert ¶
Insert inserts into a namespace the object, if it already exists, it returns the existing object without overwriting it.
func (*Scope) LookupParent ¶
LookupParent will recursively look up to the top level for the object name.
type Selection ¶
type Selection struct {
// contains filtered or unexported fields
}
Selection represents a selection expression. Examples include a.x or a->x.
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
Signature represents a signature.
func NewSignature ¶
NewSignature creates a new signature.
func (*Signature) Underlying ¶
type Sizes ¶
type Sizes interface { // Alignof returns the alignment of a variable of type T. Alignof(T Type) int64 // Offsetsof returns the offsets of the given struct fields, in bytes. Offsetsof(fields []*Var) []int64 // Sizeof returns the size of a variable of type T. Sizeof(T Type) int64 }
Sizes defines the sizing functions.
type StdSizes ¶
type StdSizes struct { WordSize int64 // word size in bytes - must be >= 2 MaxAlign int64 // maximum alignment in bytes - must be >= 1 }
StdSizes is a convenience type for creating commonly used Sizes. It makes the following simplifying assumptions:
- The size of an array of n elements corresponds to the size of a struct of n consecutive fields of the array's element type.
- The size of a struct is the offset of the last field plus that field's size. As with all element types, if the struct is used in an array its size must first be aligned to a multiple of the struct's alignment. All alignments are aligned against WordSize.
- All other types have size WordSize.
- Arrays and structs are aligned per spec definition; all other types are naturally aligned with a maximum alignment MaxAlign.
*StdSizes implements Sizes.
type Storage ¶
type Storage uint
Storage represents a storage location.
type Tuple ¶
type Tuple struct {
// contains filtered or unexported fields
}
Tuple represents function arguments.
func (*Tuple) Underlying ¶
type TypeAndValue ¶
type TypeAndValue struct { Type Type Value constant.Value // contains filtered or unexported fields }
TypeAndValue represents a type and a value.
func (TypeAndValue) Addressable ¶
func (tv TypeAndValue) Addressable() bool
func (TypeAndValue) Assignable ¶
func (tv TypeAndValue) Assignable() bool
func (TypeAndValue) IsType ¶
func (tv TypeAndValue) IsType() bool
IsType returns if the this mode is a type expression.
func (TypeAndValue) IsValue ¶
func (tv TypeAndValue) IsValue() bool
func (TypeAndValue) IsVoid ¶
func (tv TypeAndValue) IsVoid() bool
IsVoid returns if the type is a void value.
type TypeName ¶
type TypeName struct {
// contains filtered or unexported fields
}
TypeName represents a type name object. An example would be struct file fd; fd in this case would be the type name.
func NewTypeName ¶
NewTypeName creates a type name object.