github.com/XiaoMi/Gaea@v1.2.5/parser/ast/base.go (about)

     1  // Copyright 2015 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package ast
    15  
    16  import "github.com/XiaoMi/Gaea/parser/types"
    17  
    18  // node is the struct implements node interface except for Accept method.
    19  // Node implementations should embed it in.
    20  type node struct {
    21  	text string
    22  }
    23  
    24  // SetText implements Node interface.
    25  func (n *node) SetText(text string) {
    26  	n.text = text
    27  }
    28  
    29  // Text implements Node interface.
    30  func (n *node) Text() string {
    31  	return n.text
    32  }
    33  
    34  // stmtNode implements StmtNode interface.
    35  // Statement implementations should embed it in.
    36  type stmtNode struct {
    37  	node
    38  }
    39  
    40  // statement implements StmtNode interface.
    41  func (sn *stmtNode) statement() {}
    42  
    43  // ddlNode implements DDLNode interface.
    44  // DDL implementations should embed it in.
    45  type ddlNode struct {
    46  	stmtNode
    47  }
    48  
    49  // ddlStatement implements DDLNode interface.
    50  func (dn *ddlNode) ddlStatement() {}
    51  
    52  // dmlNode is the struct implements DMLNode interface.
    53  // DML implementations should embed it in.
    54  type dmlNode struct {
    55  	stmtNode
    56  }
    57  
    58  // dmlStatement implements DMLNode interface.
    59  func (dn *dmlNode) dmlStatement() {}
    60  
    61  // exprNode is the struct implements Expression interface.
    62  // Expression implementations should embed it in.
    63  type exprNode struct {
    64  	node
    65  	Type types.FieldType
    66  	flag uint64
    67  }
    68  
    69  // TexprNode is exported for parser driver.
    70  type TexprNode = exprNode
    71  
    72  // SetType implements ExprNode interface.
    73  func (en *exprNode) SetType(tp *types.FieldType) {
    74  	en.Type = *tp
    75  }
    76  
    77  // GetType implements ExprNode interface.
    78  func (en *exprNode) GetType() *types.FieldType {
    79  	return &en.Type
    80  }
    81  
    82  // SetFlag implements ExprNode interface.
    83  func (en *exprNode) SetFlag(flag uint64) {
    84  	en.flag = flag
    85  }
    86  
    87  // GetFlag implements ExprNode interface.
    88  func (en *exprNode) GetFlag() uint64 {
    89  	return en.flag
    90  }
    91  
    92  type funcNode struct {
    93  	exprNode
    94  }
    95  
    96  // functionExpression implements FunctionNode interface.
    97  func (fn *funcNode) functionExpression() {}
    98  
    99  type resultSetNode struct {
   100  	resultFields []*ResultField
   101  }