File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ const (
2323 ExpressionTypeCall
2424 ExpressionTypeIndex
2525 ExpressionTypeStar
26+ ExpressionTypeSelector
2627 ExpressionTypeParameter
2728 ExpressionTypeResult
2829)
@@ -49,6 +50,9 @@ func (expr *Expression) String() string {
4950 case ExpressionTypeStar :
5051 // *flag
5152 res = fmt .Sprintf ("*%s" , expr .Children [0 ])
53+ case ExpressionTypeSelector :
54+ // fmt.Printf, object.Event, ..
55+ res = fmt .Sprintf ("%s.%s" , expr .Children [0 ], expr .Name )
5256 default :
5357 res = expr .Name
5458 }
Original file line number Diff line number Diff line change @@ -124,6 +124,20 @@ func parseStarExpression(expr *ast.StarExpr) *Expression {
124124 return res
125125}
126126
127+ func parseSelectorExpression (expr * ast.SelectorExpr ) * Expression {
128+ // Selector expression like:
129+ // fmt.Printf
130+ before := parseExpression (& expr .X ) // fmt
131+ after := expr .Sel .Name // Printf
132+
133+ res := & Expression {
134+ Type : ExpressionTypeSelector ,
135+ Name : after , // Printf
136+ Children : Expressions {before }, // fmt
137+ }
138+ return res
139+ }
140+
127141func parseExpression (expr * ast.Expr ) * Expression {
128142 e , ok := (* expr ).(* ast.BasicLit )
129143 if ok {
@@ -165,5 +179,10 @@ func parseExpression(expr *ast.Expr) *Expression {
165179 return parseStarExpression (e8 )
166180 }
167181
182+ e9 , ok := (* expr ).(* ast.SelectorExpr )
183+ if ok {
184+ return parseSelectorExpression (e9 )
185+ }
186+
168187 panic ("parseExpression(): unknown expression type" )
169188}
Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ func parseStarNameType(nameType *ast.StarExpr) string {
2323 return parseNameType (& nameType .X ) + "*"
2424}
2525
26+ func parseSelectorNameType (expr * ast.SelectorExpr ) string {
27+ // Selector type like:
28+ // object.Event
29+ return parseSelectorExpression (expr ).String ()
30+ }
31+
2632func parseNameType (nameType * ast.Expr ) string {
2733 e , ok := (* nameType ).(* ast.Ident )
2834 if ok {
@@ -39,5 +45,10 @@ func parseNameType(nameType *ast.Expr) string {
3945 return parseStarNameType (e3 )
4046 }
4147
48+ e4 , ok := (* nameType ).(* ast.SelectorExpr )
49+ if ok {
50+ return parseSelectorNameType (e4 )
51+ }
52+
4253 panic ("parseNameType(): unknown name type" )
4354}
Original file line number Diff line number Diff line change @@ -11,21 +11,18 @@ import (
1111func parseCallStatement (stmt * ast.ExprStmt , level int ) * Statement {
1212 expr := stmt .X .(* ast.CallExpr )
1313
14- fun := expr .Fun .(* ast.SelectorExpr )
15- x := fun .X .(* ast.Ident ).Name
16- sel := fun .Sel .Name
17- name := x + "." + sel
14+ name := parseSelectorExpression (expr .Fun .(* ast.SelectorExpr )).String ()
1815
19- exprs := []* Expression {}
16+ args := []* Expression {}
2017 for _ , arg := range expr .Args {
2118 expr := parseExpression (& arg )
22- exprs = append (exprs , expr )
19+ args = append (args , expr )
2320 }
2421
2522 s := & Statement {
2623 Level : level ,
2724 Name : name ,
28- Args : exprs ,
25+ Args : args ,
2926 }
3027 return s
3128}
Original file line number Diff line number Diff line change 11package parse
22
3- import "fmt"
3+ import (
4+ "fmt"
45
5- func test (a string , bb []* int ) int {
6+ "github.com/microsoft/mouselog/object"
7+ )
8+
9+ func test (a string , events []* object.Event ) (int , string ) {
610 fmt .Printf ("Hello, World!\n " )
711 res := 0
812 array := []int {1 , 2 }
913 for i := 0 ; i < 10 ; i ++ {
1014 res += 10 / 2
1115 array = append (array , 1 )
12- if res != 10 && (array [0 ] >= 10 || * bb [3 ] == 5 ) {
16+ if res != 10 && (array [0 ] >= 10 || events [3 ]. X == 5 ) {
1317 continue
1418 }
1519 }
1620
17- return res
21+ return res , a
1822}
You can’t perform that action at this time.
0 commit comments