aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <tingwei.lan@cobinhood.com>2019-03-27 16:02:48 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit599f65cc61f985c71d4fa1227fba55287bcb1d98 (patch)
treedcc747485fa2c66eafa446d8296662ab1f9b173b
parenta80a7eaa8ecaf56ae98c07a53f410506ccfc603e (diff)
downloaddexon-599f65cc61f985c71d4fa1227fba55287bcb1d98.tar.gz
dexon-599f65cc61f985c71d4fa1227fba55287bcb1d98.tar.zst
dexon-599f65cc61f985c71d4fa1227fba55287bcb1d98.zip
core: vm: sqlvm: ast: rename DataTypeUnknown to DataTypePending
SQL uses three-valued logic which includes an unknown state. To prevent the reader of the code from confusing the unknown value with the unknown data type defined here, we rename 'unknown' data type to 'pending' because it is intended to be used by nodes whose type has not been determined.
-rw-r--r--core/vm/sqlvm/ast/ast.go20
-rw-r--r--core/vm/sqlvm/ast/types.go10
-rw-r--r--core/vm/sqlvm/ast/types_test.go3
3 files changed, 19 insertions, 14 deletions
diff --git a/core/vm/sqlvm/ast/ast.go b/core/vm/sqlvm/ast/ast.go
index 672770b84..80daacfe1 100644
--- a/core/vm/sqlvm/ast/ast.go
+++ b/core/vm/sqlvm/ast/ast.go
@@ -341,15 +341,15 @@ func (n *IntTypeNode) GetType() (DataType, errors.ErrorCode, string) {
code = errors.ErrorCodeInvalidUintSize
}
if !isMultiple {
- return DataTypeUnknown, code, fmt.Sprintf(
+ return DataTypeBad, code, fmt.Sprintf(
"%s size %d is not a multiple of 8", name, n.Size)
}
if !isNotZero {
- return DataTypeUnknown, code, fmt.Sprintf(
+ return DataTypeBad, code, fmt.Sprintf(
"%s size cannot be zero", name)
}
if !isInRange {
- return DataTypeUnknown, code, fmt.Sprintf(
+ return DataTypeBad, code, fmt.Sprintf(
"%s size %d cannot be larger than 256", name, n.Size)
}
panic("unreachable")
@@ -395,15 +395,15 @@ func (n *FixedTypeNode) GetType() (DataType, errors.ErrorCode, string) {
code = errors.ErrorCodeInvalidFixedSize
}
if !sizeIsMultiple {
- return DataTypeUnknown, code, fmt.Sprintf(
+ return DataTypeBad, code, fmt.Sprintf(
"%s size %d is not a multiple of 8", name, n.Size)
}
if !sizeIsNotZero {
- return DataTypeUnknown, code, fmt.Sprintf(
+ return DataTypeBad, code, fmt.Sprintf(
"%s size cannot be zero", name)
}
if !sizeIsInRange {
- return DataTypeUnknown, code, fmt.Sprintf(
+ return DataTypeBad, code, fmt.Sprintf(
"%s size %d cannot be larger than 256", name, n.Size)
}
code = errors.ErrorCodeInvalidFixedFractionalDigits
@@ -411,7 +411,7 @@ func (n *FixedTypeNode) GetType() (DataType, errors.ErrorCode, string) {
code = errors.ErrorCodeInvalidUfixedFractionalDigits
}
if !fractionalDigitsInRange {
- return DataTypeUnknown, code, fmt.Sprintf(
+ return DataTypeBad, code, fmt.Sprintf(
"%s fractional digits %d cannot be larger than 80",
name, n.FractionalDigits)
}
@@ -467,10 +467,10 @@ func (n *FixedBytesTypeNode) GetType() (DataType, errors.ErrorCode, string) {
if !isNotZero || !isInRange {
code := errors.ErrorCodeInvalidBytesSize
if !isNotZero {
- return DataTypeUnknown, code, "bytes size cannot be zero"
+ return DataTypeBad, code, "bytes size cannot be zero"
}
if !isInRange {
- return DataTypeUnknown, code, fmt.Sprintf(
+ return DataTypeBad, code, fmt.Sprintf(
"bytes size %d cannot be larger than 32", n.Size)
}
panic("unreachable")
@@ -881,7 +881,7 @@ func (n *CastOperatorNode) GetType() DataType {
if dt, code, _ := n.TargetType.GetType(); code == errors.ErrorCodeNil {
return dt
}
- return DataTypeUnknown
+ return DataTypeBad
}
// ---------------------------------------------------------------------------
diff --git a/core/vm/sqlvm/ast/types.go b/core/vm/sqlvm/ast/types.go
index 41c35ac78..9d7efc430 100644
--- a/core/vm/sqlvm/ast/types.go
+++ b/core/vm/sqlvm/ast/types.go
@@ -2,6 +2,7 @@ package ast
import (
"fmt"
+ "math"
"math/big"
"github.com/shopspring/decimal"
@@ -27,7 +28,7 @@ type DataType uint16
// DataTypeMajor enums.
const (
- DataTypeMajorUnknown DataTypeMajor = iota
+ DataTypeMajorPending DataTypeMajor = iota
DataTypeMajorSpecial
DataTypeMajorBool
DataTypeMajorAddress
@@ -47,8 +48,11 @@ const (
DataTypeMinorSpecialDefault DataTypeMinor = 0x02
)
-// DataTypeUnknown for unknown data type.
-const DataTypeUnknown DataType = 0
+// Special data types which are commonly used.
+const (
+ DataTypePending DataType = (DataType(DataTypeMajorPending) << 8) | DataType(DataTypeMinorDontCare)
+ DataTypeBad DataType = math.MaxUint16
+)
// DecomposeDataType to major and minor part with given data type.
func DecomposeDataType(t DataType) (DataTypeMajor, DataTypeMinor) {
diff --git a/core/vm/sqlvm/ast/types_test.go b/core/vm/sqlvm/ast/types_test.go
index b44f818cb..89a000251 100644
--- a/core/vm/sqlvm/ast/types_test.go
+++ b/core/vm/sqlvm/ast/types_test.go
@@ -82,7 +82,8 @@ func (s *TypesTestSuite) TestEncodeDataTypeError() {
}
func (s *TypesTestSuite) TestDecodeDataTypeError() {
- s.requireDecodeDataTypeError(DataTypeUnknown)
+ s.requireDecodeDataTypeError(DataTypePending)
+ s.requireDecodeDataTypeError(DataTypeBad)
s.requireDecodeDataTypeError(ComposeDataType(DataTypeMajorInt, 0x20))
s.requireDecodeDataTypeError(ComposeDataType(DataTypeMajorUint, 0x20))
s.requireDecodeDataTypeError(ComposeDataType(DataTypeMajorFixedBytes, 0x20))