github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/sqlparse/tidbparser/parser/opcode/opcode.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 opcode
    15  
    16  import (
    17  	"fmt"
    18  	"io"
    19  )
    20  
    21  // Op is opcode type.
    22  type Op int
    23  
    24  // List operators.
    25  const (
    26  	LogicAnd Op = iota + 1
    27  	LeftShift
    28  	RightShift
    29  	LogicOr
    30  	GE
    31  	LE
    32  	EQ
    33  	NE
    34  	LT
    35  	GT
    36  	Plus
    37  	Minus
    38  	And
    39  	Or
    40  	Mod
    41  	Xor
    42  	Div
    43  	Mul
    44  	Not
    45  	BitNeg
    46  	IntDiv
    47  	LogicXor
    48  	NullEQ
    49  	In
    50  	Like
    51  	Case
    52  	Regexp
    53  	IsNull
    54  	IsTruth
    55  	IsFalsity
    56  )
    57  
    58  // Ops maps opcode to string.
    59  var Ops = map[Op]string{
    60  	LogicAnd:   "and",
    61  	LogicOr:    "or",
    62  	LogicXor:   "xor",
    63  	LeftShift:  "leftshift",
    64  	RightShift: "rightshift",
    65  	GE:         "ge",
    66  	LE:         "le",
    67  	EQ:         "eq",
    68  	NE:         "ne",
    69  	LT:         "lt",
    70  	GT:         "gt",
    71  	Plus:       "plus",
    72  	Minus:      "minus",
    73  	And:        "bitand",
    74  	Or:         "bitor",
    75  	Mod:        "mod",
    76  	Xor:        "bitxor",
    77  	Div:        "div",
    78  	Mul:        "mul",
    79  	Not:        "not",
    80  	BitNeg:     "bitneg",
    81  	IntDiv:     "intdiv",
    82  	NullEQ:     "nulleq",
    83  	In:         "in",
    84  	Like:       "like",
    85  	Case:       "case",
    86  	Regexp:     "regexp",
    87  	IsNull:     "isnull",
    88  	IsTruth:    "istrue",
    89  	IsFalsity:  "isfalse",
    90  }
    91  
    92  // String implements Stringer interface.
    93  func (o Op) String() string {
    94  	str, ok := Ops[o]
    95  	if !ok {
    96  		panic(fmt.Sprintf("%d", o))
    97  	}
    98  
    99  	return str
   100  }
   101  
   102  var opsLiteral = map[Op]string{
   103  	LogicAnd:   "&&",
   104  	LogicOr:    "||",
   105  	LogicXor:   "^",
   106  	LeftShift:  "<<",
   107  	RightShift: ">>",
   108  	GE:         ">=",
   109  	LE:         "<=",
   110  	EQ:         "==",
   111  	NE:         "!=",
   112  	LT:         "<",
   113  	GT:         ">",
   114  	Plus:       "+",
   115  	Minus:      "-",
   116  	And:        "&",
   117  	Or:         "|",
   118  	Mod:        "%",
   119  	Xor:        "^",
   120  	Div:        "/",
   121  	Mul:        "*",
   122  	Not:        "!",
   123  	BitNeg:     "~",
   124  	IntDiv:     "//",
   125  	NullEQ:     "<=>",
   126  	In:         "IN",
   127  	Like:       "LIKE",
   128  	Case:       "CASE",
   129  	Regexp:     "REGEXP",
   130  	IsNull:     "IS NULL",
   131  	IsTruth:    "IS TRUE",
   132  	IsFalsity:  "IS FALSE",
   133  }
   134  
   135  // Format the ExprNode into a Writer.
   136  func (o Op) Format(w io.Writer) {
   137  	fmt.Fprintf(w, opsLiteral[o])
   138  }