File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ const (
2222 ExpressionTypeArray
2323 ExpressionTypeCall
2424 ExpressionTypeIndex
25+ ExpressionTypeStar
2526 ExpressionTypeParameter
2627 ExpressionTypeResult
2728)
@@ -45,6 +46,9 @@ func (expr *Expression) String() string {
4546 case ExpressionTypeIndex :
4647 // array[123]
4748 res = fmt .Sprintf ("%s[%s]" , expr .Name , expr .Children )
49+ case ExpressionTypeStar :
50+ // *flag
51+ res = fmt .Sprintf ("*%s" , expr .Children [0 ])
4852 default :
4953 res = expr .Name
5054 }
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ func parseArrayExpression(expr *ast.CompositeLit) *Expression {
7373 // []int{1, 2}
7474 nameType := parseNameType (& expr .Type )
7575 res := & Expression {
76- Type : ExpressionTypeArray ,
76+ Type : ExpressionTypeArray ,
7777 NameType : nameType , // int*
7878 }
7979
@@ -112,6 +112,18 @@ func parseIndexExpression(expr *ast.IndexExpr) *Expression {
112112 return res
113113}
114114
115+ func parseStarExpression (expr * ast.StarExpr ) * Expression {
116+ // Star expression like:
117+ // *flag
118+ inside := parseExpression (& expr .X )
119+
120+ res := & Expression {
121+ Type : ExpressionTypeStar ,
122+ Children : Expressions {inside }, // flag
123+ }
124+ return res
125+ }
126+
115127func parseExpression (expr * ast.Expr ) * Expression {
116128 e , ok := (* expr ).(* ast.BasicLit )
117129 if ok {
@@ -148,5 +160,10 @@ func parseExpression(expr *ast.Expr) *Expression {
148160 return parseIndexExpression (e7 )
149161 }
150162
163+ e8 , ok := (* expr ).(* ast.StarExpr )
164+ if ok {
165+ return parseStarExpression (e8 )
166+ }
167+
151168 panic ("parseExpression(): unknown expression type" )
152169}
Original file line number Diff line number Diff line change @@ -6,11 +6,21 @@ package parse
66import "go/ast"
77
88func parseIdentifierNameType (nameType * ast.Ident ) string {
9+ // Normal type like:
10+ // int, string, ..
911 return nameType .Name
1012}
1113
1214func parseArrayNameType (nameType * ast.ArrayType ) string {
13- return nameType .Elt .(* ast.Ident ).Name + "*"
15+ // Array type like:
16+ // []int
17+ return parseNameType (& nameType .Elt ) + "*"
18+ }
19+
20+ func parseStarNameType (nameType * ast.StarExpr ) string {
21+ // Star type like:
22+ // *int
23+ return parseNameType (& nameType .X ) + "*"
1424}
1525
1626func parseNameType (nameType * ast.Expr ) string {
@@ -24,5 +34,10 @@ func parseNameType(nameType *ast.Expr) string {
2434 return parseArrayNameType (e2 )
2535 }
2636
37+ e3 , ok := (* nameType ).(* ast.StarExpr )
38+ if ok {
39+ return parseStarNameType (e3 )
40+ }
41+
2742 panic ("parseNameType(): unknown name type" )
2843}
Original file line number Diff line number Diff line change @@ -2,14 +2,14 @@ package parse
22
33import "fmt"
44
5- func test (a string , bb []int ) int {
5+ func test (a string , bb []* int ) int {
66 fmt .Printf ("Hello, World!\n " )
77 res := 0
88 array := []int {1 , 2 }
99 for i := 0 ; i < 10 ; i ++ {
1010 res += 10 / 2
1111 array = append (array , 1 )
12- if res != 10 && (array [0 ] >= 10 || bb [3 ] == 5 ) {
12+ if res != 10 && (array [0 ] >= 10 || * bb [3 ] == 5 ) {
1313 continue
1414 }
1515 }
You can’t perform that action at this time.
0 commit comments