当前位置: 首页>>代码示例>>Golang>>正文


Golang ast.AssignStmt类代码示例

本文整理汇总了Golang中go/ast.AssignStmt的典型用法代码示例。如果您正苦于以下问题:Golang AssignStmt类的具体用法?Golang AssignStmt怎么用?Golang AssignStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AssignStmt类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: compileSubAssign

func (w *World) compileSubAssign(a *ast.AssignStmt, lhs ast.Expr, r Expr) Expr {
	l := w.compileLvalue(lhs)
	x := typeConv(a.Pos(), l, float64_t)
	y := typeConv(a.Pos(), r, float64_t)
	sub := &sub{binaryExpr{x, y}}
	return &assignStmt{lhs: l, rhs: typeConv(a.Pos(), sub, inputType(l))}
}
开发者ID:callistoaz,项目名称:3,代码行数:7,代码来源:assignstmt.go

示例2: AppendTryBlock

func AppendTryBlock(block []ast.Stmt, node ast.Node, errBlock []ast.Stmt) []ast.Stmt {
	var try, call *ast.CallExpr
	var assign *ast.AssignStmt
	_err, _nil := ast.NewIdent("err"), ast.NewIdent("nil")
	// err != nil
	errNil := &ast.BinaryExpr{_err, 0, token.NEQ, _nil}
	// if errNil { stmt }
	ifBlock := &ast.IfStmt{0, nil, errNil, &ast.BlockStmt{0, errBlock, 0}, nil}

	switch n := node.(type) {
	case *ast.AssignStmt:
		assign = n
		try = n.Rhs[0].(*ast.CallExpr)
	case *ast.ExprStmt:
		try = n.X.(*ast.CallExpr)
	default:
		log.Fatalf("unhandled try() node type: %T\n", node)
	}
	if assign == nil {
		assign = &ast.AssignStmt{nil, 0, token.ASSIGN, nil}
	}
	call = StripTry(try)
	assign.Rhs = []ast.Expr{call}
	assign.Lhs = append(assign.Lhs, _err)

	block = append(block, assign)
	block = append(block, ifBlock)
	return block
}
开发者ID:jmptrader,项目名称:og,代码行数:29,代码来源:plugin_try.go

示例3: compileDefine

// compile a := b
func (w *World) compileDefine(a *ast.AssignStmt, lhs ast.Expr, r Expr) Expr {
	ident, ok := lhs.(*ast.Ident)
	if !ok {
		panic(err(a.Pos(), "non-name on left side of :="))
	}
	addr := reflect.New(r.Type())
	ok = w.safeDeclare(ident.Name, &reflectLvalue{addr.Elem()})
	if !ok {
		panic(err(a.Pos(), "already defined: "+ident.Name))
	}
	return w.compileAssign(a, lhs, r)
}
开发者ID:callistoaz,项目名称:3,代码行数:13,代码来源:assignstmt.go

示例4: compileAssignStmt

// compiles a (single) assign statement lhs = rhs
func (w *World) compileAssignStmt(a *ast.AssignStmt) Expr {
	if len(a.Lhs) != 1 || len(a.Rhs) != 1 {
		panic(err(a.Pos(), "multiple assignment not allowed"))
	}
	lhs, rhs := a.Lhs[0], a.Rhs[0]
	r := w.compileExpr(rhs)

	switch a.Tok {
	default:
		panic(err(a.Pos(), a.Tok, "not allowed"))
	case token.ASSIGN: // =
		return w.compileAssign(a, lhs, r)
	case token.DEFINE: // :=
		return w.compileDefine(a, lhs, r)
	case token.ADD_ASSIGN: // +=
		return w.compileAddAssign(a, lhs, r)
	case token.SUB_ASSIGN: // -=
		return w.compileSubAssign(a, lhs, r)
	}
}
开发者ID:callistoaz,项目名称:3,代码行数:21,代码来源:assignstmt.go

示例5: doAssignOp

func (a *stmtCompiler) doAssignOp(s *ast.AssignStmt) {
	if len(s.Lhs) != 1 || len(s.Rhs) != 1 {
		a.diag("tuple assignment cannot be combined with an arithmetic operation")
		return
	}

	// Create temporary block for extractEffect
	bc := a.enterChild()
	defer bc.exit()

	l := a.compileExpr(bc.block, false, s.Lhs[0])
	r := a.compileExpr(bc.block, false, s.Rhs[0])
	if l == nil || r == nil {
		return
	}

	if l.evalAddr == nil {
		l.diag("cannot assign to %s", l.desc)
		return
	}

	effect, l := l.extractEffect(bc.block, "operator-assignment")

	binop := r.compileBinaryExpr(assignOpToOp[s.Tok], l, r)
	if binop == nil {
		return
	}

	assign := a.compileAssign(s.Pos(), bc.block, l.t, []*expr{binop}, "assignment", "value")
	if assign == nil {
		log.Panicf("compileAssign type check failed")
	}

	lf := l.evalAddr
	a.push(func(t *Thread) {
		effect(t)
		assign(lf(t), t)
	})
}
开发者ID:go-nosql,项目名称:golang,代码行数:39,代码来源:stmt.go

示例6: checkAssignStmt

// checkAssignStmt checks for assignments of the form "<expr> = <expr>".
// These are almost always useless, and even when they aren't they are usually a mistake.
func (f *File) checkAssignStmt(stmt *ast.AssignStmt) {
	if !vet("assign") {
		return
	}
	if stmt.Tok != token.ASSIGN {
		return // ignore :=
	}
	if len(stmt.Lhs) != len(stmt.Rhs) {
		// If LHS and RHS have different cardinality, they can't be the same.
		return
	}
	for i, lhs := range stmt.Lhs {
		rhs := stmt.Rhs[i]
		if reflect.TypeOf(lhs) != reflect.TypeOf(rhs) {
			continue // short-circuit the heavy-weight gofmt check
		}
		le := f.gofmt(lhs)
		re := f.gofmt(rhs)
		if le == re {
			f.Badf(stmt.Pos(), "self-assignment of %s to %s", re, le)
		}
	}
}
开发者ID:Karthikvb,项目名称:15640_projects,代码行数:25,代码来源:assign.go

示例7: compileAssign

// compile a = b
func (w *World) compileAssign(a *ast.AssignStmt, lhs ast.Expr, r Expr) Expr {
	l := w.compileLvalue(lhs)
	return &assignStmt{lhs: l, rhs: typeConv(a.Pos(), r, inputType(l))}
}
开发者ID:callistoaz,项目名称:3,代码行数:5,代码来源:assignstmt.go


注:本文中的go/ast.AssignStmt类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。