aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/ast
diff options
context:
space:
mode:
authorTing-Wei Lan <tingwei.lan@cobinhood.com>2019-03-05 16:34:54 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit378cd8b5afc5edb445a9db1790b1ab2e2d64cc33 (patch)
treebceac6f1af0986aaa87a895516c4485b5c8e9582 /core/vm/sqlvm/ast
parented13a910c7c90ff437b3de3c8fdb0828fc0dbe2f (diff)
downloaddexon-378cd8b5afc5edb445a9db1790b1ab2e2d64cc33.tar
dexon-378cd8b5afc5edb445a9db1790b1ab2e2d64cc33.tar.gz
dexon-378cd8b5afc5edb445a9db1790b1ab2e2d64cc33.tar.bz2
dexon-378cd8b5afc5edb445a9db1790b1ab2e2d64cc33.tar.lz
dexon-378cd8b5afc5edb445a9db1790b1ab2e2d64cc33.tar.xz
dexon-378cd8b5afc5edb445a9db1790b1ab2e2d64cc33.tar.zst
dexon-378cd8b5afc5edb445a9db1790b1ab2e2d64cc33.zip
core: vm: sqlvm: make a common interface for statements
So Parse now returns a []ast.StmtNode instead of a generic []ast.Node, which should be clearer on what the return value looks like. This also adds a field recording the verb use to identify the statement in order to provide better error messages.
Diffstat (limited to 'core/vm/sqlvm/ast')
-rw-r--r--core/vm/sqlvm/ast/ast.go40
1 files changed, 34 insertions, 6 deletions
diff --git a/core/vm/sqlvm/ast/ast.go b/core/vm/sqlvm/ast/ast.go
index 9a5afb202..e5de75d45 100644
--- a/core/vm/sqlvm/ast/ast.go
+++ b/core/vm/sqlvm/ast/ast.go
@@ -1109,9 +1109,32 @@ func (n *ForeignOptionNode) GetChildren() []Node {
// Statements
// ---------------------------------------------------------------------------
+// StmtNode defines the interface of a statement.
+type StmtNode interface {
+ Node
+ GetVerb() []byte
+ SetVerb([]byte)
+}
+
+// StmtNodeBase is a base struct embedded by statement nodes.
+type StmtNodeBase struct {
+ Verb []byte `print:"-"`
+}
+
+// GetVerb returns the verb used to identify the statement.
+func (n *StmtNodeBase) GetVerb() []byte {
+ return n.Verb
+}
+
+// SetVerb sets the verb used to identify the statement.
+func (n *StmtNodeBase) SetVerb(verb []byte) {
+ n.Verb = verb
+}
+
// SelectStmtNode is SELECT.
type SelectStmtNode struct {
NodeBase
+ StmtNodeBase
Column []ExprNode
Table *IdentifierNode
Where *WhereOptionNode
@@ -1121,7 +1144,7 @@ type SelectStmtNode struct {
Offset *OffsetOptionNode
}
-var _ Node = (*SelectStmtNode)(nil)
+var _ StmtNode = (*SelectStmtNode)(nil)
// GetChildren returns a list of child nodes used for traversing.
func (n *SelectStmtNode) GetChildren() []Node {
@@ -1172,12 +1195,13 @@ func (n *SelectStmtNode) GetChildren() []Node {
// UpdateStmtNode is UPDATE.
type UpdateStmtNode struct {
NodeBase
+ StmtNodeBase
Table *IdentifierNode
Assignment []*AssignOperatorNode
Where *WhereOptionNode
}
-var _ Node = (*UpdateStmtNode)(nil)
+var _ StmtNode = (*UpdateStmtNode)(nil)
// GetChildren returns a list of child nodes used for traversing.
func (n *UpdateStmtNode) GetChildren() []Node {
@@ -1203,11 +1227,12 @@ func (n *UpdateStmtNode) GetChildren() []Node {
// DeleteStmtNode is DELETE.
type DeleteStmtNode struct {
NodeBase
+ StmtNodeBase
Table *IdentifierNode
Where *WhereOptionNode
}
-var _ Node = (*DeleteStmtNode)(nil)
+var _ StmtNode = (*DeleteStmtNode)(nil)
// GetChildren returns a list of child nodes used for traversing.
func (n *DeleteStmtNode) GetChildren() []Node {
@@ -1220,11 +1245,12 @@ func (n *DeleteStmtNode) GetChildren() []Node {
// InsertStmtNode is INSERT.
type InsertStmtNode struct {
NodeBase
+ StmtNodeBase
Table *IdentifierNode
Insert Node
}
-var _ Node = (*InsertStmtNode)(nil)
+var _ StmtNode = (*InsertStmtNode)(nil)
// GetChildren returns a list of child nodes used for traversing.
func (n *InsertStmtNode) GetChildren() []Node {
@@ -1234,11 +1260,12 @@ func (n *InsertStmtNode) GetChildren() []Node {
// CreateTableStmtNode is CREATE TABLE.
type CreateTableStmtNode struct {
NodeBase
+ StmtNodeBase
Table *IdentifierNode
Column []*ColumnSchemaNode
}
-var _ Node = (*CreateTableStmtNode)(nil)
+var _ StmtNode = (*CreateTableStmtNode)(nil)
// GetChildren returns a list of child nodes used for traversing.
func (n *CreateTableStmtNode) GetChildren() []Node {
@@ -1274,13 +1301,14 @@ func (n *ColumnSchemaNode) GetChildren() []Node {
// CreateIndexStmtNode is CREATE INDEX.
type CreateIndexStmtNode struct {
NodeBase
+ StmtNodeBase
Index *IdentifierNode
Table *IdentifierNode
Column []*IdentifierNode
Unique *UniqueOptionNode
}
-var _ Node = (*CreateIndexStmtNode)(nil)
+var _ StmtNode = (*CreateIndexStmtNode)(nil)
// GetChildren returns a list of child nodes used for traversing.
func (n *CreateIndexStmtNode) GetChildren() []Node {