MCPcopy
hub / github.com/sqlc-dev/sqlc / convertUnaryExpr

Method convertUnaryExpr

internal/engine/sqlite/convert.go:806–847  ·  view source on GitHub ↗
(n *parser.Expr_unaryContext)

Source from the content-addressed store, hash-verified

804}
805
806func (c *cc) convertUnaryExpr(n *parser.Expr_unaryContext) ast.Node {
807 op := n.Unary_operator()
808 if op == nil {
809 return c.convert(n.Expr())
810 }
811
812 // Get the inner expression
813 expr := c.convert(n.Expr())
814
815 // Check the operator type
816 if opCtx, ok := op.(*parser.Unary_operatorContext); ok {
817 if opCtx.NOT_() != nil {
818 // NOT expression
819 return &ast.BoolExpr{
820 Boolop: ast.BoolExprTypeNot,
821 Args: &ast.List{
822 Items: []ast.Node{expr},
823 },
824 }
825 }
826 if opCtx.MINUS() != nil {
827 // Negative number: -expr
828 return &ast.A_Expr{
829 Name: &ast.List{Items: []ast.Node{&ast.String{Str: "-"}}},
830 Rexpr: expr,
831 }
832 }
833 if opCtx.PLUS() != nil {
834 // Positive number: +expr (just return expr)
835 return expr
836 }
837 if opCtx.TILDE() != nil {
838 // Bitwise NOT: ~expr
839 return &ast.A_Expr{
840 Name: &ast.List{Items: []ast.Node{&ast.String{Str: "~"}}},
841 Rexpr: expr,
842 }
843 }
844 }
845
846 return expr
847}
848
849func (c *cc) convertParam(n *parser.Expr_bindContext) ast.Node {
850 if n.NUMBERED_BIND_PARAMETER() != nil {

Callers 1

convertMethod · 0.95

Calls 7

convertMethod · 0.95
ExprMethod · 0.65
NOT_Method · 0.65
MINUSMethod · 0.65
PLUSMethod · 0.65
TILDEMethod · 0.65
Unary_operatorMethod · 0.45

Tested by

no test coverage detected