-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice_expr.go
47 lines (39 loc) · 1.01 KB
/
slice_expr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package goastutil
import (
"fmt"
"go/ast"
)
type SliceExpr struct {
*ast.SliceExpr
}
func NewSliceExpr(expr *ast.SliceExpr) *SliceExpr {
return &SliceExpr{SliceExpr: expr}
}
func (s *SliceExpr) ExprType() ExprType {
return SliceExprType
}
func (s *SliceExpr) Low() Expr {
return NewExpr(s.SliceExpr.Low)
}
func (s *SliceExpr) High() Expr {
return NewExpr(s.SliceExpr.High)
}
func (s *SliceExpr) Expr() Expr {
return NewExpr(s.SliceExpr.X)
}
// String returns a string representation of the SliceExpr.
//
// String concatenates the expression, low, and high values of the SliceExpr
// into a formatted string. If the Slice3 field is false, it uses the
// expression, low, and high values to construct the string. If the Slice3
// field is true, it returns the string "todo_slice_expr3_expr".
//
// Returns:
//
// string: The string representation of the SliceExpr.
func (s *SliceExpr) String() string {
if !s.Slice3 {
return fmt.Sprintf("%s[%s:%s]", s.Expr(), s.Low(), s.High())
}
return "todo_slice_expr3_expr"
}