aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2019-05-06 11:57:55 +0800
committerTing-Wei Lan <tingwei.lan@cobinhood.com>2019-05-14 11:04:15 +0800
commit173270290989eb6911fd194ebac169f9f1349234 (patch)
treedf8373d13e42c57b6d506b21b4dacdde2dfcd0bb
parent1437865c1628e578827fc735730276c9fbd37313 (diff)
downloaddexon-173270290989eb6911fd194ebac169f9f1349234.tar
dexon-173270290989eb6911fd194ebac169f9f1349234.tar.gz
dexon-173270290989eb6911fd194ebac169f9f1349234.tar.bz2
dexon-173270290989eb6911fd194ebac169f9f1349234.tar.lz
dexon-173270290989eb6911fd194ebac169f9f1349234.tar.xz
dexon-173270290989eb6911fd194ebac169f9f1349234.tar.zst
dexon-173270290989eb6911fd194ebac169f9f1349234.zip
code backup 31
-rw-r--r--core/vm/sqlvm/checker/expr.go99
-rw-r--r--core/vm/sqlvm/checker/utils.go34
2 files changed, 93 insertions, 40 deletions
diff --git a/core/vm/sqlvm/checker/expr.go b/core/vm/sqlvm/checker/expr.go
index f12a7d7dd..313f09eac 100644
--- a/core/vm/sqlvm/checker/expr.go
+++ b/core/vm/sqlvm/checker/expr.go
@@ -208,8 +208,8 @@ func checkVariable(n *ast.IdentifierNode,
dt := s[tr].Columns[cr].Type
switch a := ta.(type) {
case typeActionInferDefault:
- case typeActionInferWithMajor:
case typeActionInferWithSize:
+ case typeActionInferWithMajor:
case typeActionAssign:
if !dt.Equal(a.dt) {
elAppendTypeErrorAssignDataType(el, n, fn, a.dt, dt)
@@ -266,8 +266,8 @@ func checkBoolValue(n *ast.BoolValueNode,
switch a := ta.(type) {
case typeActionInferDefault:
- case typeActionInferWithMajor:
case typeActionInferWithSize:
+ case typeActionInferWithMajor:
case typeActionAssign:
major, _ := ast.DecomposeDataType(a.dt)
if major != ast.DataTypeMajorBool {
@@ -285,8 +285,8 @@ func checkAddressValue(n *ast.AddressValueNode,
switch a := ta.(type) {
case typeActionInferDefault:
- case typeActionInferWithMajor:
case typeActionInferWithSize:
+ case typeActionInferWithMajor:
case typeActionAssign:
major, _ := ast.DecomposeDataType(a.dt)
if major != ast.DataTypeMajorAddress {
@@ -441,6 +441,8 @@ func checkIntegerValue(n *ast.IntegerValueNode,
}
dt := ast.DataTypePending
+
+executeTypeAction:
switch a := ta.(type) {
case typeActionInferDefault:
// Default to int256 or uint256.
@@ -457,6 +459,33 @@ func checkIntegerValue(n *ast.IntegerValueNode,
return nil
}
+ case typeActionInferWithMajor:
+ switch a.major {
+ case ast.DataTypeMajorAddress:
+ // address.
+ major := a.major
+ minor := ast.DataTypeMinorDontCare
+ dt = ast.ComposeDataType(major, minor)
+ ta = newTypeActionAssign(dt)
+ case ast.DataTypeMajorInt,
+ ast.DataTypeMajorUint:
+ // int256 and uint256.
+ major := a.major
+ minor := ast.DataTypeMinor(256/8 - 1)
+ dt = ast.ComposeDataType(major, minor)
+ ta = newTypeActionAssign(dt)
+ case ast.DataTypeMajorFixed,
+ ast.DataTypeMajorUfixed:
+ // fixed128x18 and ufixed128x18.
+ major := a.major + (128/8 - 1)
+ minor := ast.DataTypeMinor(18)
+ dt = ast.ComposeDataType(major, minor)
+ ta = newTypeActionAssign(dt)
+ default:
+ ta = newTypeActionInferDefault()
+ }
+ goto executeTypeAction
+
case typeActionAssign:
dt = a.dt
major, _ := ast.DecomposeDataType(dt)
@@ -577,6 +606,8 @@ func checkDecimalValue(n *ast.DecimalValueNode,
// Now we are sure the number we are dealing has fractional part.
dt := ast.DataTypePending
+
+executeTypeAction:
switch a := ta.(type) {
case typeActionInferDefault:
// Default to fixed128x18 and ufixed128x18.
@@ -595,6 +626,27 @@ func checkDecimalValue(n *ast.DecimalValueNode,
return nil
}
+ case typeActionInferWithMajor:
+ switch a.major {
+ case ast.DataTypeMajorFixed,
+ ast.DataTypeMajorUfixed:
+ // fixed128x18 and ufixed128x18.
+ major := a.major + (128/8 - 1)
+ minor := ast.DataTypeMinor(18)
+ dt = ast.ComposeDataType(major, minor)
+ ta = newTypeActionAssign(dt)
+ case ast.DataTypeMajorInt,
+ ast.DataTypeMajorUint:
+ // int256 and uint256.
+ major := a.major
+ minor := ast.DataTypeMinor(256/8 - 1)
+ dt = ast.ComposeDataType(major, minor)
+ ta = newTypeActionAssign(dt)
+ default:
+ ta = newTypeActionInferDefault()
+ }
+ goto executeTypeAction
+
case typeActionAssign:
dt = a.dt
major, _ := ast.DecomposeDataType(dt)
@@ -661,6 +713,13 @@ executeTypeAction:
ta = newTypeActionAssign(dt)
goto executeTypeAction
+ case typeActionInferWithSize:
+ major := ast.DataTypeMajorFixedBytes
+ minor := ast.DataTypeMinor(a.size - 1)
+ dt = ast.ComposeDataType(major, minor)
+ ta = newTypeActionAssign(dt)
+ goto executeTypeAction
+
case typeActionInferWithMajor:
switch a.major {
case ast.DataTypeMajorFixedBytes:
@@ -682,20 +741,14 @@ executeTypeAction:
dt = ast.ComposeDataType(a.major, minor)
ta = newTypeActionAssign(dt)
case ast.DataTypeMajorDynamicBytes:
- dt = ast.ComposeDataType(a.major, ast.DataTypeMinorDontCare)
+ minor := ast.DataTypeMinorDontCare
+ dt = ast.ComposeDataType(a.major, minor)
ta = newTypeActionAssign(dt)
default:
ta = newTypeActionInferDefault()
}
goto executeTypeAction
- case typeActionInferWithSize:
- major := ast.DataTypeMajorFixedBytes
- minor := ast.DataTypeMinor(a.size - 1)
- dt = ast.ComposeDataType(major, minor)
- ta = newTypeActionAssign(dt)
- goto executeTypeAction
-
case typeActionAssign:
dt = a.dt
major, minor := ast.DecomposeDataType(dt)
@@ -741,10 +794,10 @@ func checkNullValue(n *ast.NullValueNode,
switch a := ta.(type) {
case typeActionInferDefault:
dt = ast.DataTypeNull
- case typeActionInferWithMajor:
- dt = ast.DataTypeNull
case typeActionInferWithSize:
dt = ast.DataTypeNull
+ case typeActionInferWithMajor:
+ dt = ast.DataTypeNull
case typeActionAssign:
dt = a.dt
}
@@ -891,12 +944,12 @@ func checkPosOperator(n *ast.PosOperatorNode,
r = checkExpr(r, s, o, c, el, tr, ta)
}
- case typeActionInferWithMajor:
+ case typeActionInferWithSize:
if dt.Pending() {
r = checkExpr(r, s, o, c, el, tr, ta)
}
- case typeActionInferWithSize:
+ case typeActionInferWithMajor:
if dt.Pending() {
r = checkExpr(r, s, o, c, el, tr, ta)
}
@@ -994,12 +1047,12 @@ func checkNegOperator(n *ast.NegOperatorNode,
r = checkExpr(r, s, o, c, el, tr, ta)
}
- case typeActionInferWithMajor:
+ case typeActionInferWithSize:
if dt.Pending() {
r = checkExpr(r, s, o, c, el, tr, ta)
}
- case typeActionInferWithSize:
+ case typeActionInferWithMajor:
if dt.Pending() {
r = checkExpr(r, s, o, c, el, tr, ta)
}
@@ -1087,8 +1140,8 @@ func checkNotOperator(n *ast.NotOperatorNode,
switch a := ta.(type) {
case typeActionInferDefault:
- case typeActionInferWithMajor:
case typeActionInferWithSize:
+ case typeActionInferWithMajor:
case typeActionAssign:
if !dt.Equal(a.dt) {
elAppendTypeErrorAssignDataType(el, n, fn, a.dt, dt)
@@ -1171,8 +1224,8 @@ func checkAndOperator(n *ast.AndOperatorNode,
switch a := ta.(type) {
case typeActionInferDefault:
- case typeActionInferWithMajor:
case typeActionInferWithSize:
+ case typeActionInferWithMajor:
case typeActionAssign:
if !dt.Equal(a.dt) {
elAppendTypeErrorAssignDataType(el, n, fn, a.dt, dt)
@@ -1243,8 +1296,8 @@ func checkOrOperator(n *ast.OrOperatorNode,
switch a := ta.(type) {
case typeActionInferDefault:
- case typeActionInferWithMajor:
case typeActionInferWithSize:
+ case typeActionInferWithMajor:
case typeActionAssign:
if !dt.Equal(a.dt) {
elAppendTypeErrorAssignDataType(el, n, fn, a.dt, dt)
@@ -1541,8 +1594,8 @@ func checkRelationalOperator(n ast.BinaryOperator,
switch a := ta.(type) {
case typeActionInferDefault:
- case typeActionInferWithMajor:
case typeActionInferWithSize:
+ case typeActionInferWithMajor:
case typeActionAssign:
if !dt.Equal(a.dt) {
elAppendTypeErrorAssignDataType(el, n, fn, a.dt, dt)
@@ -1997,12 +2050,12 @@ func checkConcatOperator(n *ast.ConcatOperatorNode,
r = checkExpr(r, s, o, c, el, tr, ta)
}
- case typeActionInferWithMajor:
+ case typeActionInferWithSize:
if dt.Pending() {
r = checkExpr(r, s, o, c, el, tr, ta)
}
- case typeActionInferWithSize:
+ case typeActionInferWithMajor:
if dt.Pending() {
r = checkExpr(r, s, o, c, el, tr, ta)
}
diff --git a/core/vm/sqlvm/checker/utils.go b/core/vm/sqlvm/checker/utils.go
index 7dbe89125..742006234 100644
--- a/core/vm/sqlvm/checker/utils.go
+++ b/core/vm/sqlvm/checker/utils.go
@@ -460,6 +460,23 @@ var _ typeAction = typeActionInferDefault{}
func (typeActionInferDefault) ˉtypeAction() {}
+// typeActionInferWithSize requests the node to infer the type with size
+// requirement. The size is measured in bytes. It is indented to be used in
+// CAST to support conversion between integer and fixed-size bytes types.
+// It is an advisory request. If the type is already determined, the request is
+// ignored and the parent node should be able to handle the problem by itself.
+type typeActionInferWithSize struct {
+ size int
+}
+
+func newTypeActionInferWithSize(bytes int) typeActionInferWithSize {
+ return typeActionInferWithSize{size: bytes}
+}
+
+var _ typeAction = typeActionInferWithSize{}
+
+func (typeActionInferWithSize) ˉtypeAction() {}
+
// typeActionInferWithMajor requests the node to infer the type with preference
// to a specific major type. It usually that the parent node cares the major
// type but does not care the size of it. It is an advisory request. If it is
@@ -480,23 +497,6 @@ var _ typeAction = typeActionInferWithMajor{}
func (typeActionInferWithMajor) ˉtypeAction() {}
-// typeActionInferWithSize requests the node to infer the type with size
-// requirement. The size is measured in bytes. It is indented to be used in
-// CAST to support conversion between integer and fixed-size bytes types.
-// It is an advisory request. If the type is already determined, the request is
-// ignored and the parent node should be able to handle the problem by itself.
-type typeActionInferWithSize struct {
- size int
-}
-
-func newTypeActionInferWithSize(bytes int) typeActionInferWithSize {
- return typeActionInferWithSize{size: bytes}
-}
-
-var _ typeAction = typeActionInferWithSize{}
-
-func (typeActionInferWithSize) ˉtypeAction() {}
-
// typeActionAssign requests the node to have a specific type. It is a
// mandatory request. If the node is unable to meet the requirement, it should
// throw an error. It is not allowed to ignore the request.