目录 搜索
archive archive/tar archive/zip bufio bufio(缓存) builtin builtin(内置包) bytes bytes(包字节) compress compress/bzip2(压缩/bzip2) compress/flate(压缩/flate) compress/gzip(压缩/gzip) compress/lzw(压缩/lzw) compress/zlib(压缩/zlib) container container/heap(容器数据结构heap) container/list(容器数据结构list) container/ring(容器数据结构ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(数据库/sql) database/sql/driver(数据库/sql/driver) debug debug/dwarf(调试/dwarf) debug/elf(调试/elf) debug/gosym(调试/gosym) debug/macho(调试/macho) debug/pe(调试/pe) debug/plan9obj(调试/plan9obj) encoding encoding(编码) encoding/ascii85(编码/ascii85) encoding/asn1(编码/asn1) encoding/base32(编码/base32) encoding/base64(编码/base64) encoding/binary(编码/binary) encoding/csv(编码/csv) encoding/gob(编码/gob) encoding/hex(编码/hex) encoding/json(编码/json) encoding/pem(编码/pem) encoding/xml(编码/xml) errors errors(错误) expvar expvar flag flag(命令行参数解析flag包) fmt fmt go go/ast(抽象语法树) go/build go/constant(常量) go/doc(文档) go/format(格式) go/importer go/parser go/printer go/scanner(扫描仪) go/token(令牌) go/types(类型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(图像) image/color(颜色) image/color/palette(调色板) image/draw(绘图) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系统) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路径) plugin plugin(插件) reflect reflect(反射) regexp regexp(正则表达式) regexp/syntax runtime runtime(运行时) runtime/debug(调试) runtime/internal/sys runtime/pprof runtime/race(竞争) runtime/trace(执行追踪器) sort sort(排序算法) strconv strconv(转换) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系统调用) testing testing(测试) testing/iotest testing/quick text text/scanner(扫描文本) text/tabwriter text/template(定义模板) text/template/parse time time(时间戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
文字

  • import "go/constant"

  • Overview

  • Index

概观

包常量实现了表示无类型的Go常量及其相应操作的值。

由于错误而导致值未知时,可能会使用特殊的未知值。除非另有规定,对未知值的操作会产生未知值。

索引

  • func BitLen(x Value) int

  • func BoolVal(x Value) bool

  • func Bytes(x Value) []byte

  • func Compare(x_ Value, op token.Token, y_ Value) bool

  • func Float32Val(x Value) (float32, bool)

  • func Float64Val(x Value) (float64, bool)

  • func Int64Val(x Value) (int64, bool)

  • func Sign(x Value) int

  • func StringVal(x Value) string

  • func Uint64Val(x Value) (uint64, bool)

  • type Kind

  • type Value

  • func BinaryOp(x_ Value, op token.Token, y_ Value) Value

  • func Denom(x Value) Value

  • func Imag(x Value) Value

  • func MakeBool(b bool) Value

  • func MakeFloat64(x float64) Value

  • func MakeFromBytes(bytes []byte) Value

  • func MakeFromLiteral(lit string, tok token.Token, zero uint) Value

  • func MakeImag(x Value) Value

  • func MakeInt64(x int64) Value

  • func MakeString(s string) Value

  • func MakeUint64(x uint64) Value

  • func MakeUnknown() Value

  • func Num(x Value) Value

  • func Real(x Value) Value

  • func Shift(x Value, op token.Token, s uint) Value

  • func ToComplex(x Value) Value

  • func ToFloat(x Value) Value

  • func ToInt(x Value) Value

  • func UnaryOp(op token.Token, y Value, prec uint) Value

包文件

value.go

func BitLen

func BitLen(x Value) int

BitLen返回以二进制表示形式表示绝对值x所需的位数; x必须是一个Int或一个Unknown。如果x未知,则结果为0。

func BoolVal

func BoolVal(x Value) bool

BoolVal返回x的Go布尔值,它必须是Bool或Unknown。如果x是未知的,结果是错误的。

func Bytes

func Bytes(x Value) []byte

Bytes以little-endian二进制表示形式返回x的绝对值的字节; x必须是一个Int。

func Compare

func Compare(x_ Value, op token.Token, y_ Value) bool

Compare返回比较结果x op y。必须为操作数定义比较。如果其中一个操作数为“未知”,则结果为false。

func Float32Val

func Float32Val(x Value) (float32, bool)

Float32Val就像Float64Val,但是用于float32而不是float64。

func Float64Val

func Float64Val(x Value) (float64, bool)

Float64Val返回x的最接近的Go float64值以及结果是否准确; x必须是数字或未知的,但不是复杂的。对于太小(太接近于0)的值来表示为float64,Float64Val将静默下溢到0.结果符号始终与x的符号匹配,即使为0.如果x为“未知”,则结果为(0,false)。

func Int64Val

func Int64Val(x Value) (int64, bool)

Int64Val返回x的Go int64值以及结果是否准确; x必须是一个Int或一个Unknown。如果结果不准确,则其值不确定。如果x是未知的,结果是(0,false)。

func Sign

func Sign(x Value) int

取决于x <0,x == 0还是x> 0,符号返回-1,0或1; x必须是数字或未知。对于复数值x,如果x == 0,则符号为0,否则为!= 0.如果x为未知,则结果为1。

func StringVal

func StringVal(x Value) string

StringVal返回x的Go字符串值,它必须是String或Unknown。如果x是未知的,结果是“”。

func Uint64Val

func Uint64Val(x Value) (uint64, bool)

Uint64Val返回x的Go uint64值和结果是否确切; x必须是一个Int或一个Unknown。如果结果不准确,则其值不确定。如果x是未知的,结果是(0,false)。

type Kind

Kind指定由值表示的值的种类。

type Kind int
const (        // unknown values
        Unknown Kind = iota        // non-numeric values
        Bool
        String        // numeric values
        Int
        Float
        Complex)

type Value

Value代表Go常数的值。

type Value interface {        // Kind returns the value kind.        Kind() Kind        // String returns a short, quoted (human-readable) form of the value.        // For numeric values, the result may be an approximation;        // for String values the result may be a shortened string.        // Use ExactString for a string representing a value exactly.        String() string        // ExactString returns an exact, quoted (human-readable) form of the value.        // If the Value is of Kind String, use StringVal to obtain the unquoted string.        ExactString() string        // contains filtered or unexported methods}

func BinaryOp

func BinaryOp(x_ Value, op token.Token, y_ Value) Value

BinaryOp返回二进制表达式x op y的结果。该操作必须为操作数定义。如果其中一个操作数为“未知”,则结果为“未知”。BinaryOp不处理比较或转换; 使用Compare或Shift来代替。

要强制Int操作数的整数除法,请使用op == token.QUO_ASSIGN而不是token.QUO; 在这种情况下结果保证为Int。除以零引起运行时恐慌。

func Denom

func Denom(x Value) Value

Denom返回x的分母; x必须是Int,Float或Unknown。如果x是未知的,或者如果它太大或太小而不能表示为分数,则结果为未知。否则结果是一个Int> = 1。

func Imag

func Imag(x Value) Value

Imag返回x的虚部,它必须是数字或未知值。如果x未知,则结果为未知。

func MakeBool

func MakeBool(b bool) Value

MakeBool返回b的Bool值。

func MakeFloat64

func MakeFloat64(x float64) Value

MakeFloat64返回x的Float值。如果x不是有限的,则结果是未知。

func MakeFromBytes

func MakeFromBytes(bytes []byte) Value

MakeFromBytes在给定其小端编码表示的字节的情况下返回Int值。一个空的字节切片参数代表0。

func MakeFromLiteral

func MakeFromLiteral(lit string, tok token.Token, zero uint) Value

MakeFromLiteral为Go文字字符串返回相应的整数,浮点数,虚数,字符或字符串值。tok值必须是token.INT,token.FLOAT,token.IMAG,token.CHAR或token.STRING中的一个。最后的论点必须是零。如果文字字符串语法无效,则结果为未知。

func MakeImag

func MakeImag(x Value) Value

MakeImag返回Complex值x * i; x必须是Int,Float或Unknown。如果x未知,则结果为未知。

func MakeInt64

func MakeInt64(x int64) Value

MakeInt64返回x的Int值。

func MakeString

func MakeString(s string) Value

MakeString返回s的字符串值。

func MakeUint64

func MakeUint64(x uint64) Value

MakeUint64返回x的Int值。

func MakeUnknown

func MakeUnknown() Value

MakeUnknown返回未知值。

func Num

func Num(x Value) Value

Num返回x的分子; x必须是Int,Float或Unknown。如果x是未知的,或者如果它太大或太小而不能表示为分数,则结果为未知。否则,结果是带有与x相同符号的Int。

func Real

func Real(x Value) Value

实数返回x的实数部分,它必须是数字或未知值。如果x未知,则结果为未知。

func Shift

func Shift(x Value, op token.Token, s uint) Value

Shift返回移位表达式x op s的结果与op == token.SHL或token.SHR(<<或>>)。x必须是一个Int或一个Unknown。如果x是未知的,结果是x。

func ToComplex

func ToComplex(x Value) Value

ToComplex将x转换为Complex值,如果x可表示为Complex。否则它返回一个未知。

func ToFloat

func ToFloat(x Value) Value

ToFloat将x转换为Float值(如果x可表示为Float)。否则它返回一个未知。

func ToInt

func ToInt(x Value) Value

如果x可表示为Int,ToInt将x转换为Int值。否则它返回一个未知。

func UnaryOp

func UnaryOp(op token.Token, y Value, prec uint) Value

UnaryOp返回一元表达式op y的结果。该操作必须为操作数定义。如果prec> 0,则它以位为单位指定^(异或)结果大小。如果y未知,则结果为未知。

上一篇: 下一篇: