diff options
author | Ting-Wei Lan <tingwei.lan@cobinhood.com> | 2019-03-27 11:01:46 +0800 |
---|---|---|
committer | lantw44 <lantw44@gmail.com> | 2019-03-29 18:40:42 +0800 |
commit | 55f8e6a9c909256d1e363d787e2df96abc7ffa44 (patch) | |
tree | b1f80b86f03414a3bb9ff447449bbbd6713f95f6 /core/vm/sqlvm/ast/types.go | |
parent | b7896e6fca1dac7c4d206abeb229049b3403aaba (diff) | |
download | dexon-55f8e6a9c909256d1e363d787e2df96abc7ffa44.tar dexon-55f8e6a9c909256d1e363d787e2df96abc7ffa44.tar.gz dexon-55f8e6a9c909256d1e363d787e2df96abc7ffa44.tar.bz2 dexon-55f8e6a9c909256d1e363d787e2df96abc7ffa44.tar.lz dexon-55f8e6a9c909256d1e363d787e2df96abc7ffa44.tar.xz dexon-55f8e6a9c909256d1e363d787e2df96abc7ffa44.tar.zst dexon-55f8e6a9c909256d1e363d787e2df96abc7ffa44.zip |
core: vm: sqlvm: ast: make DataTypeDecode a method of DataType
Since we have dropped DataTypeEncode in favor of GetType method of
TypeNode, rename DataTypeDecode to GetNode and make it a method.
Drop unnecessary zero checks because we don't care minor bytes when
there is only one type belong to a category.
Diffstat (limited to 'core/vm/sqlvm/ast/types.go')
-rw-r--r-- | core/vm/sqlvm/ast/types.go | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/core/vm/sqlvm/ast/types.go b/core/vm/sqlvm/ast/types.go index 5151334a9..d75d29294 100644 --- a/core/vm/sqlvm/ast/types.go +++ b/core/vm/sqlvm/ast/types.go @@ -101,60 +101,55 @@ func (dt DataType) Size() uint8 { } } -// DataTypeDecode decodes DataType into data type node. -func DataTypeDecode(t DataType) (TypeNode, error) { - major, minor := DecomposeDataType(t) +// GetNode constructs an AST node from a data type. +func (dt DataType) GetNode() TypeNode { + major, minor := DecomposeDataType(dt) switch major { - // TODO(wmin0): define unsupported error for special type. case DataTypeMajorBool: - if minor == 0 { - return &BoolTypeNode{}, nil - } + return &BoolTypeNode{} case DataTypeMajorAddress: - if minor == 0 { - return &AddressTypeNode{}, nil - } + return &AddressTypeNode{} case DataTypeMajorInt: if minor <= 0x1f { size := (uint32(minor) + 1) * 8 - return &IntTypeNode{Unsigned: false, Size: size}, nil + return &IntTypeNode{Unsigned: false, Size: size} } case DataTypeMajorUint: if minor <= 0x1f { size := (uint32(minor) + 1) * 8 - return &IntTypeNode{Unsigned: true, Size: size}, nil + return &IntTypeNode{Unsigned: true, Size: size} } case DataTypeMajorFixedBytes: if minor <= 0x1f { size := uint32(minor) + 1 - return &FixedBytesTypeNode{Size: size}, nil + return &FixedBytesTypeNode{Size: size} } case DataTypeMajorDynamicBytes: - if minor == 0 { - return &DynamicBytesTypeNode{}, nil - } + return &DynamicBytesTypeNode{} } switch { case major.IsFixedRange(): if minor <= 80 { size := (uint32(major-DataTypeMajorFixed) + 1) * 8 + fractionalDigits := uint32(minor) return &FixedTypeNode{ Unsigned: false, Size: size, - FractionalDigits: uint32(minor), - }, nil + FractionalDigits: fractionalDigits, + } } case major.IsUfixedRange(): if minor <= 80 { size := (uint32(major-DataTypeMajorUfixed) + 1) * 8 + fractionalDigits := uint32(minor) return &FixedTypeNode{ Unsigned: true, Size: size, - FractionalDigits: uint32(minor), - }, nil + FractionalDigits: fractionalDigits, + } } } - return nil, se.ErrorCodeDataTypeDecode + return nil } func decimalToBig(d decimal.Decimal) (b *big.Int) { |