base.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. package ast
  14. import (
  15. "github.com/pingcap/parser/types"
  16. )
  17. // node is the struct implements node interface except for Accept method.
  18. // Node implementations should embed it in.
  19. type node struct {
  20. text string
  21. offset int
  22. }
  23. // SetOriginTextPosition implements Node interface.
  24. func (n *node) SetOriginTextPosition(offset int) {
  25. n.offset = offset
  26. }
  27. // OriginTextPosition implements Node interface.
  28. func (n *node) OriginTextPosition() int {
  29. return n.offset
  30. }
  31. // SetText implements Node interface.
  32. func (n *node) SetText(text string) {
  33. n.text = text
  34. }
  35. // Text implements Node interface.
  36. func (n *node) Text() string {
  37. return n.text
  38. }
  39. // stmtNode implements StmtNode interface.
  40. // Statement implementations should embed it in.
  41. type stmtNode struct {
  42. node
  43. }
  44. // statement implements StmtNode interface.
  45. func (sn *stmtNode) statement() {}
  46. // ddlNode implements DDLNode interface.
  47. // DDL implementations should embed it in.
  48. type ddlNode struct {
  49. stmtNode
  50. }
  51. // ddlStatement implements DDLNode interface.
  52. func (dn *ddlNode) ddlStatement() {}
  53. // dmlNode is the struct implements DMLNode interface.
  54. // DML implementations should embed it in.
  55. type dmlNode struct {
  56. stmtNode
  57. }
  58. // dmlStatement implements DMLNode interface.
  59. func (dn *dmlNode) dmlStatement() {}
  60. // exprNode is the struct implements Expression interface.
  61. // Expression implementations should embed it in.
  62. type exprNode struct {
  63. node
  64. Type types.FieldType
  65. flag uint64
  66. }
  67. // TexprNode is exported for parser driver.
  68. type TexprNode = exprNode
  69. // SetType implements ExprNode interface.
  70. func (en *exprNode) SetType(tp *types.FieldType) {
  71. en.Type = *tp
  72. }
  73. // GetType implements ExprNode interface.
  74. func (en *exprNode) GetType() *types.FieldType {
  75. return &en.Type
  76. }
  77. // SetFlag implements ExprNode interface.
  78. func (en *exprNode) SetFlag(flag uint64) {
  79. en.flag = flag
  80. }
  81. // GetFlag implements ExprNode interface.
  82. func (en *exprNode) GetFlag() uint64 {
  83. return en.flag
  84. }
  85. type funcNode struct {
  86. exprNode
  87. }
  88. // functionExpression implements FunctionNode interface.
  89. func (fn *funcNode) functionExpression() {}