本文整理汇总了Golang中go/ast.FuncDecl类的典型用法代码示例。如果您正苦于以下问题:Golang FuncDecl类的具体用法?Golang FuncDecl怎么用?Golang FuncDecl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FuncDecl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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
示例8: 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
示例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
// 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
示例11: 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
示例12: 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
示例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: parseFuncDecl
func (p *parser) parseFuncDecl(n *parse.Node) ast.Decl {
scope := ast.NewScope(p.topScope)
funcDecl := ast.FuncDecl{
Name: p.parseIdent(n.Child(1)),
}
funcOrSig := n.Child(2).Child(0)
if funcOrSig.Rule() == signature {
funcDecl.Type = p.parseSignature(funcOrSig, scope)
} else {
funcDecl.Type, funcDecl.Body = p.parseFunc(funcOrSig, scope)
}
funcDecl.Type.Func = token.Pos(n.Child(0).Pos())
return &funcDecl
}
开发者ID:h12w,项目名称:gombi,代码行数:14,代码来源:parser.go
示例16: topLevelNodeToDecl
// topLevelNodeToDecl converts an AST node to Go ast.Decl
func topLevelNodeToDecl(node *parser.CallNode) ast.Decl {
if node.Callee.(*parser.IdentNode).Ident != "defn" {
panic("Top level node has to be defn")
}
switch node.Callee.(*parser.IdentNode).Ident {
case "defn":
decl := ast.FuncDecl{
Name: &ast.Ident{
NamePos: 2,
Name: node.Args[0].(*parser.IdentNode).Ident,
},
}
fmt.Printf("SHOW ARGS: %+v\n", node.Args[1:])
// @TODO Fix this to support signature properly
params := &ast.FieldList{
Opening: 1,
Closing: 3,
}
params.List = make([]*ast.Field, 1)
params.List[0] = &ast.Field{
Names: []*ast.Ident{
&ast.Ident{
Name: "lol",
},
},
Type: &ast.Ident{
Name: "interface{}",
},
}
decl.Type = &ast.FuncType{
Func: 1,
Params: params,
Results: nil,
}
//decl.Body = nodeFnBody(node.Args[1:])
// TODO: Check argument lengths
decl.Body = nodeFnBody(node.Args[1])
return &decl
default:
// The rest is normal function call probably
//return nodeFnCall(node)
fmt.Println("got nil %+v", node)
return nil
}
}
开发者ID:mochi-lang,项目名称:mochi,代码行数:51,代码来源:ast.go
示例17: 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
示例18: checkFunctionLine
func (f *file) checkFunctionLine(funcDecl *ast.FuncDecl) {
lineLimit := f.config.FunctionLine
if lineLimit <= 0 {
return
}
start := f.fset.Position(funcDecl.Pos())
startLine := start.Line
endLine := f.fset.Position(funcDecl.End()).Line
lineCount := endLine - startLine
if lineCount > lineLimit {
problem := genFuncLineProblem(funcDecl.Name.Name, lineCount, lineLimit, start)
f.problems = append(f.problems, problem)
}
}
开发者ID:qiniu,项目名称:checkstyle,代码行数:15,代码来源:checkstyle.go
示例19: set
// set creates the corresponding Func for f and adds it to mset.
// If there are multiple f's with the same name, set keeps the first
// one with documentation; conflicts are ignored.
//
func (mset methodSet) set(f *ast.FuncDecl) {
name := f.Name.Name
if g := mset[name]; g != nil && g.Doc != "" {
// A function with the same name has already been registered;
// since it has documentation, assume f is simply another
// implementation and ignore it. This does not happen if the
// caller is using go/build.ScanDir to determine the list of
// files implementing a package.
return
}
// function doesn't exist or has no documentation; use f
recv := ""
if f.Recv != nil {
var typ ast.Expr
// be careful in case of incorrect ASTs
if list := f.Recv.List; len(list) == 1 {
typ = list[0].Type
}
recv = recvString(typ)
}
mset[name] = &Func{
Doc: f.Doc.Text(),
Name: name,
Decl: f,
Recv: recv,
Orig: recv,
}
f.Doc = nil // doc consumed - remove from AST
}
开发者ID:funkygao,项目名称:govtil,代码行数:33,代码来源:reader.go
示例20: writeFunc
// writeFunc writes a syscall wrapper for f to w.
// It modifies f's data, so be warned!
func (m *module) writeFunc(w io.Writer, f *ast.FuncDecl) error {
f.Recv = nil // Remove the bogus receiver (really the DLL name).
err := m.printConfig.Fprint(w, m.fileSet, f)
if err != nil {
return err
}
fmt.Fprintln(w, " {")
params, setupCode, resultCode, err := m.analyzeParameterList(f.Type)
if err != nil {
return err
}
prefix := ""
if m.packageName != "com" {
prefix = "com."
}
if setupCode != "" {
fmt.Fprintln(w, setupCode)
}
fmt.Fprintf(w, "\t_res, _, _ := %sSyscall(proc%s.Addr(),\n\t\t%s)\n", prefix, f.Name.Name, strings.Join(params, ",\n\t\t"))
fmt.Fprint(w, resultCode)
fmt.Fprintln(w, "\treturn")
fmt.Fprintln(w, "}")
fmt.Fprintln(w)
return nil
}
开发者ID:vijaygiri10,项目名称:com-and-go,代码行数:32,代码来源:func.go
注:本文中的go/ast.FuncDecl类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论