...

Source file src/go/types/basic.go

Documentation: go/types

     1  // Copyright 2011 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  package types
     6  
     7  // BasicKind describes the kind of basic type.
     8  type BasicKind int
     9  
    10  const (
    11  	Invalid BasicKind = iota // type is invalid
    12  
    13  	// predeclared types
    14  	Bool
    15  	Int
    16  	Int8
    17  	Int16
    18  	Int32
    19  	Int64
    20  	Uint
    21  	Uint8
    22  	Uint16
    23  	Uint32
    24  	Uint64
    25  	Uintptr
    26  	Float32
    27  	Float64
    28  	Complex64
    29  	Complex128
    30  	String
    31  	UnsafePointer
    32  
    33  	// types for untyped values
    34  	UntypedBool
    35  	UntypedInt
    36  	UntypedRune
    37  	UntypedFloat
    38  	UntypedComplex
    39  	UntypedString
    40  	UntypedNil
    41  
    42  	// aliases
    43  	Byte = Uint8
    44  	Rune = Int32
    45  )
    46  
    47  // BasicInfo is a set of flags describing properties of a basic type.
    48  type BasicInfo int
    49  
    50  // Properties of basic types.
    51  const (
    52  	IsBoolean BasicInfo = 1 << iota
    53  	IsInteger
    54  	IsUnsigned
    55  	IsFloat
    56  	IsComplex
    57  	IsString
    58  	IsUntyped
    59  
    60  	IsOrdered   = IsInteger | IsFloat | IsString
    61  	IsNumeric   = IsInteger | IsFloat | IsComplex
    62  	IsConstType = IsBoolean | IsNumeric | IsString
    63  )
    64  
    65  // A Basic represents a basic type.
    66  type Basic struct {
    67  	kind BasicKind
    68  	info BasicInfo
    69  	name string
    70  }
    71  
    72  // Kind returns the kind of basic type b.
    73  func (b *Basic) Kind() BasicKind { return b.kind }
    74  
    75  // Info returns information about properties of basic type b.
    76  func (b *Basic) Info() BasicInfo { return b.info }
    77  
    78  // Name returns the name of basic type b.
    79  func (b *Basic) Name() string { return b.name }
    80  
    81  func (t *Basic) Underlying() Type { return t }
    82  func (t *Basic) String() string   { return TypeString(t, nil) }
    83  

View as plain text