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


Golang FuncDecl.Pos方法代码示例

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


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

示例1: method

func (v *fileVisitor) method(n *ast.FuncDecl) *Method {
	method := &Method{Name: n.Name.Name}
	method.Lines = []*Line{}

	start := v.fset.Position(n.Pos())
	end := v.fset.Position(n.End())
	startLine := start.Line
	startCol := start.Column
	endLine := end.Line
	endCol := end.Column
	// The blocks are sorted, so we can stop counting as soon as we reach the end of the relevant block.
	for _, b := range v.profile.Blocks {
		if b.StartLine > endLine || (b.StartLine == endLine && b.StartCol >= endCol) {
			// Past the end of the function.
			break
		}
		if b.EndLine < startLine || (b.EndLine == startLine && b.EndCol <= startCol) {
			// Before the beginning of the function
			continue
		}
		for i := b.StartLine; i <= b.EndLine; i++ {
			method.Lines = append(method.Lines, &Line{Number: i, Hits: int64(b.Count)})
		}
	}
	return method
}
开发者ID:rvdwijngaard,项目名称:gocover-cobertura,代码行数:26,代码来源:gocover-cobertura.go

示例2: checkFuncLength

func (p *Parser) checkFuncLength(x *ast.FuncDecl) {
	numStatements := statementCount(x)
	if numStatements <= *statementThreshold {
		return
	}

	p.summary.addStatement(p.offender(x.Name.String(), numStatements, x.Pos()))
}
开发者ID:stathat,项目名称:splint,代码行数:8,代码来源:splint.go

示例3: checkFunctionBody

func (f *file) checkFunctionBody(funcDecl *ast.FuncDecl) {
	if funcDecl.Body != nil {
		return
	}
	start := f.fset.Position(funcDecl.Pos())
	problem := genFuncBodyProblem(funcDecl.Name.Name, start)
	f.problems = append(f.problems, problem)
}
开发者ID:qiniu,项目名称:checkstyle,代码行数:8,代码来源:checkstyle.go

示例4: checkResultCount

func (p *Parser) checkResultCount(x *ast.FuncDecl) {
	numResults := x.Type.Results.NumFields()
	if numResults <= *resultThreshold {
		return
	}

	p.summary.addResult(p.offender(x.Name.String(), numResults, x.Pos()))
}
开发者ID:stathat,项目名称:splint,代码行数:8,代码来源:splint.go

示例5: checkTestFunc

func checkTestFunc(fn *ast.FuncDecl, arg string) error {
	if !isTestFunc(fn, arg) {
		name := fn.Name.String()
		pos := testFileSet.Position(fn.Pos())
		return fmt.Errorf("%s: wrong signature for %s, must be: func %s(%s *testing.%s)", pos, name, name, strings.ToLower(arg), arg)
	}
	return nil
}
开发者ID:Greentor,项目名称:go,代码行数:8,代码来源:test.go

示例6: checkParamCount

func (p *Parser) checkParamCount(x *ast.FuncDecl) {
	numFields := x.Type.Params.NumFields()
	if numFields <= *paramThreshold {
		return
	}

	p.summary.addParam(p.offender(x.Name.String(), numFields, x.Pos()))
}
开发者ID:stathat,项目名称:splint,代码行数:8,代码来源:splint.go

示例7: processFunction

func processFunction(funcDecl *ast.FuncDecl) {
	m := function{}

	m.bodyStart = fset.Position(funcDecl.Pos()).Line
	m.bodyEnd = fset.Position(funcDecl.End()).Line
	m.variables = getFunctionVariables(funcDecl)

	addFoundFunctions(m)
}
开发者ID:meonlol,项目名称:gosem,代码行数:9,代码来源:gosem.go

示例8: parseFunction

func parseFunction(funcDecl *ast.FuncDecl, fileInBytes []byte) (string, bool) {
	if ast.IsExported(funcDecl.Name.Name) {
		fmt.Printf("Function exported: %s\n", funcDecl.Name.Name)
		return string(fileInBytes[funcDecl.Pos()-1 : funcDecl.Body.Lbrace-1]), true
	} else {
		fmt.Printf("Function not exported: %s\n", funcDecl.Name.Name)
	}
	return "", false
}
开发者ID:CodeHipster,项目名称:go-code-visualizer,代码行数:9,代码来源:ast-scanner.go

示例9: getFunc

// Functions
//
// http://golang.org/doc/go_spec.html#Function_declarations
// https://developer.mozilla.org/en/JavaScript/Reference/Statements/function
func (tr *transform) getFunc(decl *ast.FuncDecl) {
	// godoc go/ast FuncDecl
	//  Doc  *CommentGroup // associated documentation; or nil
	//  Recv *FieldList    // receiver (methods); or nil (functions)
	//  Name *Ident        // function/method name
	//  Type *FuncType     // position of Func keyword, parameters and results
	//  Body *BlockStmt    // function body; or nil (forward declaration)

	// Check empty functions
	if len(decl.Body.List) == 0 {
		return
	}

	isFuncInit := false // function init()

	// == Initialization to save variables created on this function
	if decl.Name != nil { // discard literal functions
		tr.funcTotal++
		tr.funcId = tr.funcTotal
		tr.blockId = 0

		tr.vars[tr.funcId] = make(map[int]map[string]bool)
		tr.addr[tr.funcId] = make(map[int]map[string]bool)
		tr.maps[tr.funcId] = make(map[int]map[string]struct{})
		tr.slices[tr.funcId] = make(map[int]map[string]struct{})
		tr.zeroType[tr.funcId] = make(map[int]map[string]string)
	}
	// ==

	tr.addLine(decl.Pos())
	tr.addIfExported(decl.Name)

	if decl.Name.Name != "init" {
		tr.writeFunc(decl.Recv, decl.Name, decl.Type)
	} else {
		isFuncInit = true
		tr.WriteString("(function()" + SP)
	}

	tr.getStatement(decl.Body)

	if isFuncInit {
		tr.WriteString("());")
	}

	// At exiting of the function, it returns at the global scope.
	if decl.Name != nil {
		tr.funcId = 0
		tr.blockId = 0
	}
	if decl.Recv != nil {
		tr.recvVar = ""
	}
}
开发者ID:ojowinter,项目名称:test,代码行数:58,代码来源:func.go

示例10: funcDecl

// Handle a function declaration.
func funcDecl(fset *token.FileSet, decl *ast.FuncDecl) {
	var recvType string
	if decl.Recv != nil {
		// Method definition.  There's always only one receiver.
		recvType = "class:" + typeName(decl.Recv.List[0].Type)
	} else {
		// Normal function
		recvType = ""
	}
	emitTag(decl.Name.Name, decl.Pos(), fset, FUNC, recvType)
}
开发者ID:ArjenL,项目名称:taggo,代码行数:12,代码来源:main.go

示例11: funcDecl

func (p *printer) funcDecl(d *ast.FuncDecl) {
	p.setComment(d.Doc)
	p.print(d.Pos(), token.FUNC, blank)
	if d.Recv != nil {
		p.parameters(d.Recv) // method: print receiver
		p.print(blank)
	}
	p.expr(d.Name)
	p.signature(d.Type.Params, d.Type.Results)
	p.adjBlock(p.distanceFrom(d.Pos()), vtab, d.Body)
}
开发者ID:ZeusbasePython,项目名称:appscale,代码行数:11,代码来源:nodes.go

示例12: funcDecl

// Sets multiLine to true if the declaration spans multiple lines.
func (p *printer) funcDecl(d *ast.FuncDecl, multiLine *bool) {
	p.setComment(d.Doc)
	p.print(d.Pos(), token.FUNC, blank)
	if d.Recv != nil {
		p.parameters(d.Recv, multiLine) // method: print receiver
		p.print(blank)
	}
	p.expr(d.Name, multiLine)
	p.signature(d.Type.Params, d.Type.Results, multiLine)
	p.funcBody(d.Body, distance(d.Pos(), p.pos), false, multiLine)
}
开发者ID:GNA-SERVICES-INC,项目名称:MoNGate,代码行数:12,代码来源:nodes.go

示例13: checkBoolParams

func (p *Parser) checkBoolParams(x *ast.FuncDecl) {
	if *skipBoolParamCheck {
		return
	}
	for _, f := range x.Type.Params.List {
		// this is ugly, but:
		if fmt.Sprintf("%s", f.Type) != "bool" {
			continue
		}
		p.summary.addBoolParam(p.offender(x.Name.String(), 0, x.Pos()))
	}
}
开发者ID:stathat,项目名称:splint,代码行数:12,代码来源:splint.go

示例14: createFunctionMetadata

func (c *compiler) createFunctionMetadata(f *ast.FuncDecl, fn *LLVMValue) llvm.DebugDescriptor {
	if len(c.debug_context) == 0 {
		return nil
	}

	file := c.fileset.File(f.Pos())
	fnptr := fn.value
	fun := fnptr.IsAFunction()
	if fun.IsNil() {
		fnptr = llvm.ConstExtractValue(fn.value, []uint32{0})
	}
	meta := &llvm.SubprogramDescriptor{
		Name:        fnptr.Name(),
		DisplayName: f.Name.Name,
		Path:        llvm.FileDescriptor(file.Name()),
		Line:        uint32(file.Line(f.Pos())),
		ScopeLine:   uint32(file.Line(f.Body.Pos())),
		Context:     &llvm.ContextDescriptor{llvm.FileDescriptor(file.Name())},
		Function:    fnptr}

	var result types.Type
	var metaparams []llvm.DebugDescriptor
	if ftyp, ok := fn.Type().(*types.Signature); ok {
		if recv := ftyp.Recv(); recv != nil {
			metaparams = append(metaparams, c.tollvmDebugDescriptor(recv.Type()))
		}
		if ftyp.Params() != nil {
			for i := 0; i < ftyp.Params().Len(); i++ {
				p := ftyp.Params().At(i)
				metaparams = append(metaparams, c.tollvmDebugDescriptor(p.Type()))
			}
		}
		if ftyp.Results() != nil {
			result = ftyp.Results().At(0).Type()
			// TODO: what to do with multiple returns?
			for i := 1; i < ftyp.Results().Len(); i++ {
				p := ftyp.Results().At(i)
				metaparams = append(metaparams, c.tollvmDebugDescriptor(p.Type()))
			}
		}
	}

	meta.Type = llvm.NewSubroutineCompositeType(
		c.tollvmDebugDescriptor(result),
		metaparams,
	)

	// compile unit is the first context object pushed
	compileUnit := c.debug_context[0].(*llvm.CompileUnitDescriptor)
	compileUnit.Subprograms = append(compileUnit.Subprograms, meta)
	return meta
}
开发者ID:qioixiy,项目名称:llgo,代码行数:52,代码来源:debug.go

示例15: funcDecl

func (check *checker) funcDecl(obj *Func, fdecl *ast.FuncDecl) {
	// func declarations cannot use iota
	assert(check.iota == nil)

	obj.typ = Typ[Invalid] // guard against cycles
	sig := check.funcType(fdecl.Recv, fdecl.Type, nil)
	if sig.recv == nil && obj.name == "init" && (sig.params.Len() > 0 || sig.results.Len() > 0) {
		check.errorf(fdecl.Pos(), "func init must have no arguments and no return values")
		// ok to continue
	}
	obj.typ = sig

	check.later(obj, sig, fdecl.Body)
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:14,代码来源:resolver.go


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