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


Golang Stmt.End方法代码示例

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


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

示例1: insertInWithin

// insertInWithin places before/after advice around a statement
func (wb *WithinBlock) insertInWithin(a ast.Stmt, w *Weave) string {
	rout := ""

	mName := grabMethodName(a)

	// begin line
	begin := wb.fset.Position(a.Pos()).Line - 1
	after := wb.fset.Position(a.End()).Line + 1

	// until this is refactored - any lines we add in our
	// advice need to be accounted for w/begin
	before_advice := formatAdvice(wb.aspect.advize.before, mName)
	after_advice := formatAdvice(wb.aspect.advize.after, mName)

	if before_advice != "" {
		rout = w.writeAtLine(wb.fname, begin+wb.linecnt, before_advice)
		wb.linecnt += strings.Count(before_advice, "\n") + 1
	}

	if after_advice != "" {
		rout = w.writeAtLine(wb.fname, after+wb.linecnt-1, after_advice)

		wb.linecnt += strings.Count(after_advice, "\n") + 1
	}

	for t := 0; t < len(wb.aspect.importz); t++ {
		wb.importsNeeded = append(wb.importsNeeded, wb.aspect.importz[t])
	}

	return rout
}
开发者ID:AkihiroSuda,项目名称:goweave,代码行数:32,代码来源:within.go

示例2: statementBoundary

// statementBoundary finds the location in s that terminates the current basic
// block in the source.
func (f *File) statementBoundary(s ast.Stmt) token.Pos {
	// Control flow statements are easy.
	switch s := s.(type) {
	case *ast.BlockStmt:
		// Treat blocks like basic blocks to avoid overlapping counters.
		return s.Lbrace
	case *ast.IfStmt:
		return s.Body.Lbrace
	case *ast.ForStmt:
		return s.Body.Lbrace
	case *ast.LabeledStmt:
		return f.statementBoundary(s.Stmt)
	case *ast.RangeStmt:
		return s.Body.Lbrace
	case *ast.SwitchStmt:
		return s.Body.Lbrace
	case *ast.SelectStmt:
		return s.Body.Lbrace
	case *ast.TypeSwitchStmt:
		return s.Body.Lbrace
	}
	// If not a control flow statement, it is a declaration, expression, call, etc. and it may have a function literal.
	// If it does, that's tricky because we want to exclude the body of the function from this block.
	// Draw a line at the start of the body of the first function literal we find.
	// TODO: what if there's more than one? Probably doesn't matter much.
	var literal funcLitFinder
	ast.Walk(&literal, s)
	if literal.found() {
		return token.Pos(literal)
	}
	return s.End()
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:34,代码来源:cover.go

示例3: emitTraceStmt

func emitTraceStmt(f *Function, event TraceEvent, syntax ast.Stmt) Value {
	t := &Trace{
		Event:      event,
		Start:      syntax.Pos(),
		End:        syntax.End(),
		Breakpoint: false,
		syntax:     syntax,
	}
	return emitTraceCommon(f, t)
}
开发者ID:rocky,项目名称:ssa-interp,代码行数:10,代码来源:emit4gub.go

示例4: makeExpr

func (p *parser) makeExpr(s ast.Stmt) ast.Expr {
	if s == nil {
		return nil
	}
	if es, isExpr := s.(*ast.ExprStmt); isExpr {
		return p.checkExpr(es.X)
	}
	p.error(s.Pos(), "expected condition, found simple statement")
	return &ast.BadExpr{s.Pos(), s.End()}
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:10,代码来源:parser.go

示例5: VisitStmt

func (v *ShortError) VisitStmt(scope *ast.Scope, stmt ast.Stmt) ScopeVisitor {
	v.stmt = stmt
	switch stmt := stmt.(type) {
	case *ast.BlockStmt:
		return &ShortError{v.file, v.patches, v.stmt, stmt, 0, new([]byte)}
	case *ast.ExprStmt:
		if call := calltomust(stmt.X); call != nil {
			// TODO(elazarl): depends on number of variables it returns, currently we assume one
			pos := v.file.Fset.Position(stmt.Pos())
			fmt.Printf("%s:%d:%d: 'must' builtin must be assigned into variable\n",
				pos.Filename, pos.Line, pos.Column)
		}
	case *ast.AssignStmt:
		if len(stmt.Rhs) != 1 {
			return v
		}
		if rhs, ok := stmt.Rhs[0].(*ast.CallExpr); ok {
			if fun, ok := rhs.Fun.(*ast.Ident); ok && fun.Name == MustKeyword {
				if stmt.Tok == token.DEFINE {
					tmpVar := v.tempVar("assignerr_", scope)
					*v.patches = append(*v.patches,
						patch.Insert(stmt.TokPos, ", "+tmpVar+" "),
						patch.Replace(fun, ""),
						patch.Insert(stmt.End(),
							"; if "+tmpVar+" != nil "+
								"{ panic("+tmpVar+") };"),
					)
					for _, arg := range rhs.Args {
						v.VisitExpr(scope, arg)
					}
					return nil
				} else if stmt.Tok == token.ASSIGN {
					vars := []string{}
					for i := 0; i < len(stmt.Lhs); i++ {
						vars = append(vars, v.tempVar(fmt.Sprint("assgn", i, "_"), scope))
					}
					assgnerr := v.tempVar("assgnErr_", scope)

					*v.patches = append(*v.patches,
						patch.Insert(stmt.Pos(),
							strings.Join(append(vars, assgnerr), ", ")+":="),
						patch.InsertNode(stmt.Pos(), rhs.Args[0]),
						patch.Insert(stmt.Pos(),
							"; if "+assgnerr+" != nil "+
								"{ panic("+assgnerr+") };"),
						patch.Replace(rhs, strings.Join(vars, ", ")),
					)
					v.VisitExpr(scope, rhs.Args[0])
					return nil
				}
			}
		}
	}
	return v
}
开发者ID:soniah,项目名称:gosloppy,代码行数:55,代码来源:shorterror.go

示例6: statementBoundary

// statementBoundary finds the location in s that terminates the current basic
// block in the source.
func (f *File) statementBoundary(s ast.Stmt) token.Pos {
	// Control flow statements are easy.
	switch s := s.(type) {
	case *ast.BlockStmt:
		// Treat blocks like basic blocks to avoid overlapping counters.
		return s.Lbrace
	case *ast.IfStmt:
		return s.Body.Lbrace
	case *ast.ForStmt:
		return s.Body.Lbrace
	case *ast.LabeledStmt:
		return f.statementBoundary(s.Stmt)
	case *ast.RangeStmt:
		// Ranges might loop over things with function literals.: for _ = range []func(){ ... } {.
		// TODO: There are a few other such possibilities, but they're extremely unlikely.
		found, pos := hasFuncLiteral(s.X)
		if found {
			return pos
		}
		return s.Body.Lbrace
	case *ast.SwitchStmt:
		return s.Body.Lbrace
	case *ast.SelectStmt:
		return s.Body.Lbrace
	case *ast.TypeSwitchStmt:
		return s.Body.Lbrace
	}
	// If not a control flow statement, it is a declaration, expression, call, etc. and it may have a function literal.
	// If it does, that's tricky because we want to exclude the body of the function from this block.
	// Draw a line at the start of the body of the first function literal we find.
	// TODO: what if there's more than one? Probably doesn't matter much.
	found, pos := hasFuncLiteral(s)
	if found {
		return pos
	}
	return s.End()
}
开发者ID:8limbs,项目名称:gotools,代码行数:39,代码来源:cover.go

示例7: stmt


//.........这里部分代码省略.........
		if x.mode == invalid {
			return
		}
		xtyp, _ := x.typ.Underlying().(*Interface)
		if xtyp == nil {
			check.errorf(x.pos(), "%s is not an interface", &x)
			return
		}

		check.multipleDefaults(s.Body.List)

		var lhsVars []*Var               // list of implicitly declared lhs variables
		seen := make(map[Type]token.Pos) // map of seen types to positions
		for _, s := range s.Body.List {
			clause, _ := s.(*ast.CaseClause)
			if clause == nil {
				check.invalidAST(s.Pos(), "incorrect type switch case")
				continue
			}
			// Check each type in this type switch case.
			T := check.caseTypes(&x, xtyp, clause.List, seen)
			check.openScope(clause, "case")
			// If lhs exists, declare a corresponding variable in the case-local scope.
			if lhs != nil {
				// spec: "The TypeSwitchGuard may include a short variable declaration.
				// When that form is used, the variable is declared at the beginning of
				// the implicit block in each clause. In clauses with a case listing
				// exactly one type, the variable has that type; otherwise, the variable
				// has the type of the expression in the TypeSwitchGuard."
				if len(clause.List) != 1 || T == nil {
					T = x.typ
				}
				obj := NewVar(lhs.Pos(), check.pkg, lhs.Name, T)
				scopePos := clause.End()
				if len(clause.Body) > 0 {
					scopePos = clause.Body[0].Pos()
				}
				check.declare(check.scope, nil, obj, scopePos)
				check.recordImplicit(clause, obj)
				// For the "declared but not used" error, all lhs variables act as
				// one; i.e., if any one of them is 'used', all of them are 'used'.
				// Collect them for later analysis.
				lhsVars = append(lhsVars, obj)
			}
			check.stmtList(inner, clause.Body)
			check.closeScope()
		}

		// If lhs exists, we must have at least one lhs variable that was used.
		if lhs != nil {
			var used bool
			for _, v := range lhsVars {
				if v.used {
					used = true
				}
				v.used = true // avoid usage error when checking entire function
			}
			if !used {
				check.softErrorf(lhs.Pos(), "%s declared but not used", lhs.Name)
			}
		}

	case *ast.SelectStmt:
		inner |= breakOk

		check.multipleDefaults(s.Body.List)
开发者ID:duhaibo0404,项目名称:go-1,代码行数:67,代码来源:stmt.go

示例8: openScope

func (check *Checker) openScope(s ast.Stmt, comment string) {
	scope := NewScope(check.scope, s.Pos(), s.End(), comment)
	check.recordScope(s, scope)
	check.scope = scope
}
开发者ID:duhaibo0404,项目名称:go-1,代码行数:5,代码来源:stmt.go

示例9: VisitStmt

func (v *stmtVisitor) VisitStmt(s ast.Stmt) {
	var statements *[]ast.Stmt
	switch s := s.(type) {
	case *ast.BlockStmt:
		statements = &s.List
	case *ast.CaseClause:
		statements = &s.Body
	case *ast.CommClause:
		statements = &s.Body
	case *ast.ForStmt:
		if s.Init != nil {
			v.VisitStmt(s.Init)
		}
		if s.Post != nil {
			v.VisitStmt(s.Post)
		}
		v.VisitStmt(s.Body)
	case *ast.IfStmt:
		if s.Init != nil {
			v.VisitStmt(s.Init)
		}
		v.VisitStmt(s.Body)
		if s.Else != nil {
			v.VisitStmt(s.Else)
		}
	case *ast.LabeledStmt:
		v.VisitStmt(s.Stmt)
	case *ast.RangeStmt:
		v.VisitStmt(s.Body)
	case *ast.SelectStmt:
		v.VisitStmt(s.Body)
	case *ast.SwitchStmt:
		if s.Init != nil {
			v.VisitStmt(s.Init)
		}
		v.VisitStmt(s.Body)
	case *ast.TypeSwitchStmt:
		if s.Init != nil {
			v.VisitStmt(s.Init)
		}
		v.VisitStmt(s.Assign)
		v.VisitStmt(s.Body)
	}
	if statements == nil {
		return
	}
	for i := 0; i < len(*statements); i++ {
		s := (*statements)[i]
		switch s.(type) {
		case *ast.CaseClause, *ast.CommClause, *ast.BlockStmt:
			break
		default:
			start, end := v.fset.Position(s.Pos()), v.fset.Position(s.End())
			stmtObj := v.functions[len(v.functions)-1].RegisterStatement(start.Offset, end.Offset)
			expr := makeCall(fmt.Sprint(stmtObj, ".At"))
			stmt := &ast.ExprStmt{X: expr}
			item := []ast.Stmt{stmt}
			*statements = append((*statements)[:i], append(item, (*statements)[i:]...)...)
			i++
		}
		v.VisitStmt(s)
	}
}
开发者ID:fiber,项目名称:gocov,代码行数:63,代码来源:instrument.go

示例10: statementBoundary

func (f *File) statementBoundary(s ast.Stmt) token.Pos {
	// Control flow statements are easy.
	switch s := s.(type) {
	case *ast.BlockStmt:
		// Treat blocks like basic blocks to avoid overlapping counters.
		return s.Lbrace
	case *ast.IfStmt:
		found, pos := hasFuncLiteral(s.Init)
		if found {
			return pos
		}
		found, pos = hasFuncLiteral(s.Cond)
		if found {
			return pos
		}
		return s.Body.Lbrace
	case *ast.ForStmt:
		found, pos := hasFuncLiteral(s.Init)
		if found {
			return pos
		}
		found, pos = hasFuncLiteral(s.Cond)
		if found {
			return pos
		}
		found, pos = hasFuncLiteral(s.Post)
		if found {
			return pos
		}
		return s.Body.Lbrace
	case *ast.LabeledStmt:
		return f.statementBoundary(s.Stmt)
	case *ast.RangeStmt:
		found, pos := hasFuncLiteral(s.X)
		if found {
			return pos
		}
		return s.Body.Lbrace
	case *ast.SwitchStmt:
		found, pos := hasFuncLiteral(s.Init)
		if found {
			return pos
		}
		found, pos = hasFuncLiteral(s.Tag)
		if found {
			return pos
		}
		return s.Body.Lbrace
	case *ast.SelectStmt:
		return s.Body.Lbrace
	case *ast.TypeSwitchStmt:
		found, pos := hasFuncLiteral(s.Init)
		if found {
			return pos
		}
		return s.Body.Lbrace
	}
	found, pos := hasFuncLiteral(s)
	if found {
		return pos
	}
	return s.End()
}
开发者ID:pierrec,项目名称:go-fuzz,代码行数:63,代码来源:cover.go

示例11: VisitStmt

func (v *StmtVisitor) VisitStmt(s ast.Stmt) {
	var statements *[]ast.Stmt
	switch s := s.(type) {
	case *ast.BlockStmt:
		statements = &s.List
	case *ast.CaseClause:
		statements = &s.Body
	case *ast.CommClause:
		statements = &s.Body
	case *ast.ForStmt:
		if s.Init != nil {
			v.VisitStmt(s.Init)
		}
		if s.Post != nil {
			v.VisitStmt(s.Post)
		}
		v.VisitStmt(s.Body)
	case *ast.IfStmt:
		if s.Init != nil {
			v.VisitStmt(s.Init)
		}
		v.VisitStmt(s.Body)
		if s.Else != nil {
			// Code copied from go.tools/cmd/cover, to deal with "if x {} else if y {}"
			const backupToElse = token.Pos(len("else ")) // The AST doesn't remember the else location. We can make an accurate guess.
			switch stmt := s.Else.(type) {
			case *ast.IfStmt:
				block := &ast.BlockStmt{
					Lbrace: stmt.If - backupToElse, // So the covered part looks like it starts at the "else".
					List:   []ast.Stmt{stmt},
					Rbrace: stmt.End(),
				}
				s.Else = block
			case *ast.BlockStmt:
				stmt.Lbrace -= backupToElse // So the block looks like it starts at the "else".
			default:
				panic("unexpected node type in if")
			}
			v.VisitStmt(s.Else)
		}
	case *ast.LabeledStmt:
		v.VisitStmt(s.Stmt)
	case *ast.RangeStmt:
		v.VisitStmt(s.Body)
	case *ast.SelectStmt:
		v.VisitStmt(s.Body)
	case *ast.SwitchStmt:
		if s.Init != nil {
			v.VisitStmt(s.Init)
		}
		v.VisitStmt(s.Body)
	case *ast.TypeSwitchStmt:
		if s.Init != nil {
			v.VisitStmt(s.Init)
		}
		v.VisitStmt(s.Assign)
		v.VisitStmt(s.Body)
	}
	if statements == nil {
		return
	}
	for i := 0; i < len(*statements); i++ {
		s := (*statements)[i]
		switch s.(type) {
		case *ast.CaseClause, *ast.CommClause, *ast.BlockStmt:
			break
		default:
			start, end := v.fset.Position(s.Pos()), v.fset.Position(s.End())
			se := &StmtExtent{
				startOffset: start.Offset,
				startLine:   start.Line,
				startCol:    start.Column,
				endOffset:   end.Offset,
				endLine:     end.Line,
				endCol:      end.Column,
			}
			v.function.stmts = append(v.function.stmts, se)
		}
		v.VisitStmt(s)
	}
}
开发者ID:litixsoft,项目名称:lxb,代码行数:81,代码来源:convert.go


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