From eea0444807e1b573a039ead8263e1c33e8d9adce Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 18 Jan 2020 10:39:00 +0800 Subject: [PATCH] Revert "test: [go] add to add property supporT" This reverts commit db58278ecad75338c689a9a70cee4d97293f74e0. --- .../ast/cocago/cocago_builder.go | 34 +++++++------------ .../ast/cocago/cocago_parser.go | 2 -- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/pkg/infrastructure/ast/cocago/cocago_builder.go b/pkg/infrastructure/ast/cocago/cocago_builder.go index e32846a..51d9e0d 100644 --- a/pkg/infrastructure/ast/cocago/cocago_builder.go +++ b/pkg/infrastructure/ast/cocago/cocago_builder.go @@ -109,27 +109,22 @@ func BuildFieldToProperty(fieldList []*ast.Field) []CodeProperty { return properties } -func BuildMethodCall(codeFunc *CodeFunction, item ast.Stmt, fields []CodeField, localVars []CodeProperty, imports []CodeImport, packageName string) ([]CodeProperty, *CodeCall) { +func BuildMethodCall(codeFunc *CodeFunction, item ast.Stmt, fields []CodeField, localVars []CodeProperty, imports []CodeImport, packageName string) ([]CodeProperty, CodeCall) { var call CodeCall switch it := item.(type) { case *ast.ExprStmt: - call = *BuildMethodCallExprStmt(it, codeFunc, fields, imports, packageName, localVars) + BuildMethodCallExprStmt(it, codeFunc, fields, imports, packageName, localVars) case *ast.DeferStmt: - call = *BuildCallFromExpr(it.Call, codeFunc, fields, imports, packageName, localVars) + call = BuildCallFromExpr(it.Call, codeFunc, fields, imports, packageName, localVars) codeFunc.FunctionCalls = append(codeFunc.FunctionCalls, call) case *ast.AssignStmt: vars := BuildLocalVars(it) localVars = vars - case *ast.ReturnStmt: - for _, result := range it.Results { - expr, s, s2 := BuildExpr(result) - fmt.Println(expr, s, s2) - } default: fmt.Fprintf(output, "methodCall %s\n", reflect.TypeOf(it)) } - return localVars, &call + return localVars, call } func BuildLocalVars(it *ast.AssignStmt) []CodeProperty { @@ -154,20 +149,17 @@ func BuildLocalVars(it *ast.AssignStmt) []CodeProperty { return vars } -func BuildMethodCallExprStmt(it *ast.ExprStmt, codeFunc *CodeFunction, fields []CodeField, imports []CodeImport, currentPackage string, localVars []CodeProperty) *CodeCall { - var call *CodeCall +func BuildMethodCallExprStmt(it *ast.ExprStmt, codeFunc *CodeFunction, fields []CodeField, imports []CodeImport, currentPackage string, localVars []CodeProperty) { switch expr := it.X.(type) { case *ast.CallExpr: - call = BuildCallFromExpr(expr, codeFunc, fields, imports, currentPackage, localVars) - codeFunc.FunctionCalls = append(codeFunc.FunctionCalls, *call) + call := BuildCallFromExpr(expr, nil, fields, imports, currentPackage, localVars) + codeFunc.FunctionCalls = append(codeFunc.FunctionCalls, call) default: fmt.Fprintf(output, "BuildMethodCallExprStmt: %s\n", reflect.TypeOf(expr)) } - - return call } -func BuildCallFromExpr(expr *ast.CallExpr, codeFunc *CodeFunction, fields []CodeField, imports []CodeImport, currentPackage string, localVars []CodeProperty) *CodeCall { +func BuildCallFromExpr(expr *ast.CallExpr, codeFunc *CodeFunction, fields []CodeField, imports []CodeImport, currentPackage string, localVars []CodeProperty) CodeCall { _, selector, selName := BuildExpr(expr.Fun.(ast.Expr)) target := ParseTarget(selector, fields, localVars) packageName := getPackageName(target, imports) @@ -188,12 +180,13 @@ func BuildCallFromExpr(expr *ast.CallExpr, codeFunc *CodeFunction, fields []Code for _, item := range funcLit.Body.List { _, methodCall := BuildMethodCall(codeFunc, item, fields, localVars, imports, packageName) - fmt.Println(methodCall) + fmt.Println("...", methodCall) if methodCall.NodeName != "" { - codeFunc.FunctionCalls = append(codeFunc.FunctionCalls, *methodCall) + fmt.Println(methodCall.NodeName) + codeFunc.FunctionCalls = append(codeFunc.FunctionCalls, methodCall) } } - } + } _, value, kind := BuildExpr(arg.(ast.Expr)) property := &CodeProperty{ @@ -203,8 +196,7 @@ func BuildCallFromExpr(expr *ast.CallExpr, codeFunc *CodeFunction, fields []Code call.Parameters = append(call.Parameters, *property) } - - return &call + return call } func getPackageName(target string, imports []CodeImport) string { diff --git a/pkg/infrastructure/ast/cocago/cocago_parser.go b/pkg/infrastructure/ast/cocago/cocago_parser.go index e7c968a..f29974c 100644 --- a/pkg/infrastructure/ast/cocago/cocago_parser.go +++ b/pkg/infrastructure/ast/cocago/cocago_parser.go @@ -295,8 +295,6 @@ func BuildExpr(expr ast.Expr) (string, string, string) { case *ast.FuncLit: // inner function fmt.Println(x.Body.List) - case *ast.BinaryExpr: - //fmt.Println(x.Op) default: fmt.Fprintf(output, "BuildExpr %s\n", reflect.TypeOf(x)) } -- GitLab