aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/ast
diff options
context:
space:
mode:
authorTing-Wei Lan <tingwei.lan@cobinhood.com>2019-02-20 16:32:14 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit124183ce94ef9941a077ff7e2a84738dfd7f8dcb (patch)
treedadac101dbc8833c2562c169276751906fa7abb6 /core/vm/sqlvm/ast
parentb414e5491c58bab824d0a6bb9fd94e17b2a9659a (diff)
downloaddexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.gz
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.bz2
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.lz
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.xz
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.zst
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.zip
core: vm: sqlvm: check if a number is a valid address
This commit implements isAddress function to allow a number literal to be considered as an address literal. Since Solidity only allows '0x' to be written in lower case, we remove the handling of upper case '0X' to keep the behavior in sync with Solidity. In addition to isAddress implementation, this commit also removes 'String' methods from AST nodes to prevent them from implementing the builtin 'Stringer' interface. Therefore, our AST printer is now able to print struct fields of value nodes instead of only one string.
Diffstat (limited to 'core/vm/sqlvm/ast')
-rw-r--r--core/vm/sqlvm/ast/ast.go22
-rw-r--r--core/vm/sqlvm/ast/printer.go6
2 files changed, 5 insertions, 23 deletions
diff --git a/core/vm/sqlvm/ast/ast.go b/core/vm/sqlvm/ast/ast.go
index ffd4a1011..ca0f60aa7 100644
--- a/core/vm/sqlvm/ast/ast.go
+++ b/core/vm/sqlvm/ast/ast.go
@@ -1,8 +1,6 @@
package ast
import (
- "strconv"
-
"github.com/dexon-foundation/dexon/core/vm/sqlvm/errors"
"github.com/shopspring/decimal"
)
@@ -142,11 +140,6 @@ func (n BoolValueNode) Value() interface{} {
return n.V
}
-// String is used for printing AST.
-func (n BoolValueNode) String() string {
- return strconv.FormatBool(n.V)
-}
-
// IntegerValueNode is an integer constant.
type IntegerValueNode struct {
TaggedExprNodeBase
@@ -171,11 +164,6 @@ func (n IntegerValueNode) Value() interface{} {
return n.V
}
-// String is used for printing AST.
-func (n IntegerValueNode) String() string {
- return n.V.String()
-}
-
// DecimalValueNode is a number constant.
type DecimalValueNode struct {
TaggedExprNodeBase
@@ -199,11 +187,6 @@ func (n DecimalValueNode) Value() interface{} {
return n.V
}
-// String is used for printing AST.
-func (n DecimalValueNode) String() string {
- return n.V.String()
-}
-
// BytesValueNode is a dynamic or fixed bytes constant.
type BytesValueNode struct {
TaggedExprNodeBase
@@ -227,11 +210,6 @@ func (n BytesValueNode) Value() interface{} {
return n.V
}
-// String is used for printing AST.
-func (n BytesValueNode) String() string {
- return string(n.V)
-}
-
// AnyValueNode is '*' used in SELECT and function call.
type AnyValueNode struct {
UntaggedExprNodeBase
diff --git a/core/vm/sqlvm/ast/printer.go b/core/vm/sqlvm/ast/printer.go
index a3dd1ba07..56cfd07b9 100644
--- a/core/vm/sqlvm/ast/printer.go
+++ b/core/vm/sqlvm/ast/printer.go
@@ -73,7 +73,11 @@ func printAST(w io.Writer, n interface{}, depth int, base string, detail bool) {
}
if stringer, ok := n.(fmt.Stringer); ok {
s := stringer.String()
- fmt.Fprintf(w, "%s%s: %s\n", indent, name, formatString(s))
+ fmt.Fprintf(w, "%s%s\n", indent, formatString(s))
+ return
+ }
+ if s, ok := n.(string); ok {
+ fmt.Fprintf(w, "%s%s\n", indent, formatString(s))
return
}
if bs, ok := n.([]byte); ok {