2024-05-14 13:07:09 +00:00
|
|
|
package swag
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go/ast"
|
|
|
|
"go/token"
|
|
|
|
"reflect"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"unicode/utf8"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ConstVariable a model to record a const variable
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
type ConstVariable struct {
|
2024-07-24 23:45:04 +00:00
|
|
|
Name *ast.Ident
|
|
|
|
|
|
|
|
Type ast.Expr
|
|
|
|
|
|
|
|
Value interface{}
|
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
Comment *ast.CommentGroup
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
File *ast.File
|
|
|
|
|
|
|
|
Pkg *PackageDefinitions
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var escapedChars = map[uint8]uint8{
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
'n': '\n',
|
|
|
|
|
|
|
|
'r': '\r',
|
|
|
|
|
|
|
|
't': '\t',
|
|
|
|
|
|
|
|
'v': '\v',
|
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
'\\': '\\',
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
'"': '"',
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EvaluateEscapedChar parse escaped character
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
func EvaluateEscapedChar(text string) rune {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if len(text) == 1 {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(text[0])
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(text) == 2 && text[0] == '\\' {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(escapedChars[text[1]])
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(text) == 6 && text[0:2] == "\\u" {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
n, err := strconv.ParseInt(text[2:], 16, 32)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if err == nil {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(n)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EvaluateEscapedString parse escaped characters in string
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
func EvaluateEscapedString(text string) string {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if !strings.ContainsRune(text, '\\') {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return text
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
result := make([]byte, 0, len(text))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
for i := 0; i < len(text); i++ {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if text[i] == '\\' {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
i++
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if text[i] == 'u' {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
i++
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
char, err := strconv.ParseInt(text[i:i+4], 16, 32)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if err == nil {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
result = utf8.AppendRune(result, rune(char))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
i += 3
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if c, ok := escapedChars[text[i]]; ok {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
result = append(result, c)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
result = append(result, text[i])
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return string(result)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EvaluateDataConversion evaluate the type a explicit type conversion
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
func EvaluateDataConversion(x interface{}, typeName string) interface{} {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch value := x.(type) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "string":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return string(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "byte":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return byte(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "int64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return int64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint8":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint8(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint16":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint16(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint32":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint32(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "uint64":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return uint64(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "rune":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return rune(value)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case string:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch typeName {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case "string":
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return value
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return nil
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EvaluateUnary evaluate the type and value of a unary expression
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
func EvaluateUnary(x interface{}, operator token.Token, xtype ast.Expr) (interface{}, ast.Expr) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch operator {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.SUB:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch value := x.(type) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return -value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return -value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return -value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return -value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return -value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.XOR:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch value := x.(type) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return ^value, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return nil, nil
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EvaluateBinary evaluate the type and value of a binary expression
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
func EvaluateBinary(x, y interface{}, operator token.Token, xtype, ytype ast.Expr) (interface{}, ast.Expr) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if operator == token.SHR || operator == token.SHL {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
var rightOperand uint64
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
yValue := reflect.ValueOf(y)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
rightOperand = yValue.Uint()
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
rightOperand = uint64(yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch operator {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.SHL:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch xValue := x.(type) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue << rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.SHR:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
switch xValue := x.(type) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case int64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint8:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint16:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint32:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case uint64:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue >> rightOperand, xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return nil, nil
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
evalType := xtype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if evalType == nil {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
evalType = ytype
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xValue := reflect.ValueOf(x)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
yValue := reflect.ValueOf(y)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.Kind() == reflect.String && yValue.Kind() == reflect.String {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return xValue.String() + yValue.String(), evalType
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var targetValue reflect.Value
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.Kind() != reflect.Int {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue = reflect.New(xValue.Type()).Elem()
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue = reflect.New(yValue.Type()).Elem()
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch operator {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.ADD:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.CanInt() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetInt(xValue.Int() + yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() + yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanInt() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(uint64(xValue.Int()) + yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() + uint64(yValue.Int()))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.SUB:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.CanInt() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetInt(xValue.Int() - yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() - yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanInt() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(uint64(xValue.Int()) - yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() - uint64(yValue.Int()))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.MUL:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.CanInt() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetInt(xValue.Int() * yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() * yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanInt() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(uint64(xValue.Int()) * yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() * uint64(yValue.Int()))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.QUO:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.CanInt() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetInt(xValue.Int() / yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() / yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanInt() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(uint64(xValue.Int()) / yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() / uint64(yValue.Int()))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.REM:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.CanInt() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetInt(xValue.Int() % yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() % yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanInt() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(uint64(xValue.Int()) % yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() % uint64(yValue.Int()))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.AND:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.CanInt() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetInt(xValue.Int() & yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() & yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanInt() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(uint64(xValue.Int()) & yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() & uint64(yValue.Int()))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.OR:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.CanInt() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetInt(xValue.Int() | yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() | yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanInt() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(uint64(xValue.Int()) | yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() | uint64(yValue.Int()))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
case token.XOR:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
if xValue.CanInt() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetInt(xValue.Int() ^ yValue.Int())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() ^ yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanInt() && yValue.CanUint() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(uint64(xValue.Int()) ^ yValue.Uint())
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
} else if xValue.CanUint() && yValue.CanInt() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
targetValue.SetUint(xValue.Uint() ^ uint64(yValue.Int()))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
return targetValue.Interface(), evalType
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-14 13:07:09 +00:00
|
|
|
}
|