-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from pingcap/master
Merge pull request from pingcap/tidb
- Loading branch information
Showing
12 changed files
with
2,368 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2015 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package ast is the abstract syntax tree parsed from a SQL statement by parser. | ||
// It can be analysed and transformed by optimizer. | ||
package ast | ||
|
||
import ( | ||
"github.com/pingcap/tidb/util/types" | ||
) | ||
|
||
// Node is the basic element of the AST. | ||
// Interfaces embed Node should have 'Node' name suffix. | ||
type Node interface { | ||
// Accept accepts Visitor to visit itself. | ||
// The returned node should replace original node. | ||
// ok returns false to stop visiting. | ||
Accept(v Visitor) (node Node, ok bool) | ||
// Text returns the original text of the element. | ||
Text() string | ||
// SetText sets original text to the Node. | ||
SetText(text string) | ||
} | ||
|
||
// ExprNode is a node that can be evaluated. | ||
// Name of implementations should have 'Expr' suffix. | ||
type ExprNode interface { | ||
// Node is embeded in ExprNode. | ||
Node | ||
// IsStatic means it can be evaluated independently. | ||
IsStatic() bool | ||
// SetType sets evaluation type to the expression. | ||
SetType(tp *types.FieldType) | ||
// GetType gets the evaluation type of the expression. | ||
GetType() *types.FieldType | ||
} | ||
|
||
// FuncNode represents function call expression node. | ||
type FuncNode interface { | ||
ExprNode | ||
functionExpression() | ||
} | ||
|
||
// StmtNode represents statement node. | ||
// Name of implementations should have 'Stmt' suffix. | ||
type StmtNode interface { | ||
Node | ||
statement() | ||
} | ||
|
||
// DDLNode represents DDL statement node. | ||
type DDLNode interface { | ||
StmtNode | ||
ddlStatement() | ||
} | ||
|
||
// DMLNode represents DML statement node. | ||
type DMLNode interface { | ||
StmtNode | ||
dmlStatement() | ||
} | ||
|
||
// Visitor visits a Node. | ||
type Visitor interface { | ||
// VisitEnter is called before children nodes is visited. | ||
// ok returns false to stop visiting. | ||
Enter(n Node) (ok bool) | ||
// VisitLeave is called after children nodes has been visited. | ||
// ok returns false to stop visiting. | ||
Leave(n Node) (node Node, ok bool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2015 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ast | ||
|
||
import "github.com/pingcap/tidb/util/types" | ||
|
||
// node is the struct implements node interface except for Accept method. | ||
// Node implementations should embed it in. | ||
type node struct { | ||
text string | ||
} | ||
|
||
// SetText implements Node interface. | ||
func (n *node) SetText(text string) { | ||
n.text = text | ||
} | ||
|
||
// Text implements Node interface. | ||
func (n *node) Text() string { | ||
return n.text | ||
} | ||
|
||
// stmtNode implements StmtNode interface. | ||
// Statement implementations should embed it in. | ||
type stmtNode struct { | ||
node | ||
} | ||
|
||
// statement implements StmtNode interface. | ||
func (sn *stmtNode) statement() {} | ||
|
||
// ddlNode implements DDLNode interface. | ||
// DDL implementations should embed it in. | ||
type ddlNode struct { | ||
stmtNode | ||
} | ||
|
||
// ddlStatement implements DDLNode interface. | ||
func (dn *ddlNode) ddlStatement() {} | ||
|
||
// dmlNode is the struct implements DMLNode interface. | ||
// DML implementations should embed it in. | ||
type dmlNode struct { | ||
stmtNode | ||
} | ||
|
||
// dmlStatement implements DMLNode interface. | ||
func (dn *dmlNode) dmlStatement() {} | ||
|
||
// expressionNode is the struct implements Expression interface. | ||
// Expression implementations should embed it in. | ||
type exprNode struct { | ||
node | ||
tp *types.FieldType | ||
} | ||
|
||
// IsStatic implements Expression interface. | ||
func (en *exprNode) IsStatic() bool { | ||
return false | ||
} | ||
|
||
// SetType implements Expression interface. | ||
func (en *exprNode) SetType(tp *types.FieldType) { | ||
en.tp = tp | ||
} | ||
|
||
// GetType implements Expression interface. | ||
func (en *exprNode) GetType() *types.FieldType { | ||
return en.tp | ||
} | ||
|
||
type funcNode struct { | ||
exprNode | ||
} | ||
|
||
// FunctionExpression implements FounctionNode interface. | ||
func (fn *funcNode) functionExpression() {} |
Oops, something went wrong.