Exemplo n.º 1
0
// c may be nil.
func insertContext(f *ast.File, call *ast.CallExpr, c *ast.Ident) {
	if c == nil {
		// c is unknown, so use a plain "c".
		c = ast.NewIdent("c")
	}

	call.Args = append([]ast.Expr{c}, call.Args...)
}
Exemplo n.º 2
0
// ctx may be nil.
func insertContext(f *ast.File, call *ast.CallExpr, ctx *ast.Ident) {
	if ctx == nil {
		// context is unknown, so use a plain "ctx".
		ctx = ast.NewIdent("ctx")
	}

	call.Args = append([]ast.Expr{ctx}, call.Args...)
}
Exemplo n.º 3
0
func changeFuncNameAndAddWriter(callExpr *ast.CallExpr, newFuncName string) {
	// Hacky; we should really create a proper AST. Fine for now, though, and faster, anyway.
	callExpr.Fun.(*ast.Ident).Name = newFuncName

	// Prepend w to the arg list.
	newArgList := make([]ast.Expr, 0, 1+len(callExpr.Args))
	newArgList = append(newArgList, writerArg)
	newArgList = append(newArgList, callExpr.Args...)
	callExpr.Args = newArgList
}
Exemplo n.º 4
0
// ctx may be nil.
func insertContext(f *ast.File, call *ast.CallExpr, ctx *ast.Ident) {
	if ctx == nil {
		// context is unknown, so use a plain "ctx".
		ctx = ast.NewIdent("ctx")
	} else {
		// Create a fresh *ast.Ident so we drop the position information.
		ctx = ast.NewIdent(ctx.Name)
	}

	call.Args = append([]ast.Expr{ctx}, call.Args...)
}
Exemplo n.º 5
0
func (vis *getUsedMethodsVisitor) checkEditME(callExpr *ast.CallExpr, mId *ast.Ident) {
	m, ok := vis.identMap.GetSymbol(mId).(*st.FunctionSymbol)
	if !ok {
		panic("couldn't find method selector in method expression")
	}
	if id, ok := callExpr.Args[0].(*ast.Ident); ok {
		if vis.identMap.GetSymbol(id) == vis.varS {
			callExpr.Fun = &ast.SelectorExpr{id, mId}
			callExpr.Args = callExpr.Args[1:]
			vis.result[m] = true
		}
	}
}
Exemplo n.º 6
0
func (rp *rewritePackage) wrapCallExprWithTemplatedT(basicLit *ast.BasicLit, callExpr *ast.CallExpr, argIndex int) {
	templatedCallExpr := rp.wrapBasicLitWithTemplatedT(basicLit, callExpr.Args, callExpr, argIndex)
	if templatedCallExpr != callExpr {
		newArgs := []ast.Expr{}

		if argIndex != 0 {
			for i, arg := range callExpr.Args {
				if i < argIndex {
					newArgs = append(newArgs, arg)
				}
			}
		}

		callExpr.Args = append(newArgs, templatedCallExpr)
	}
}
Exemplo n.º 7
0
func (v *powerVisitor) finishCapturing(n *ast.CallExpr) {
	trace("stop capturing. stack size: ", v.nodeStack.Count(), " poped: ", n)
	if selector, ok := n.Fun.(*ast.SelectorExpr); ok {
		if selector.Sel.Name == "Ok" {
			selector.Sel.Name = "PowerOk"
			arg := n.Args[1]
			if modified, ok := captExpr(arg); ok {
				n.Args[1] = modified
			}
			n.Args = append(n.Args, &ast.BasicLit{Kind: token.STRING, Value: fmt.Sprintf("\"%s\"", v.original)})
		}
	}
	//	modified, _ := ToCode(n)
	//	log("-r='", v.original, "->", modified, "'")
	v.capturingCall = nil
	v.original = ""
	v.capturing = false
}