本文整理汇总了Golang中github.com/quarnster/completion/content.Method.Returns方法的典型用法代码示例。如果您正苦于以下问题:Golang Method.Returns方法的具体用法?Golang Method.Returns怎么用?Golang Method.Returns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/quarnster/completion/content.Method
的用法示例。
在下文中一共展示了Method.Returns方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: toContentMethod
func (d *DWARFHelper) toContentMethod(e *dwarf.Entry) (content.Method, error) {
var m content.Method
if v, ok := e.Val(dwarf.AttrName).(string); ok {
m.Name.Relative = v
}
if v, ok := e.Val(dwarf.AttrType).(dwarf.Offset); ok {
if t, err := d.GetType(v); err != nil {
return m, err
} else {
m.Returns = append(m.Returns, content.Variable{Type: t})
}
} else {
m.Returns = append(m.Returns, content.Variable{Type: content.Type{Name: content.FullyQualifiedName{Relative: "void"}}})
}
m.Flags = d.Flags(e)
if e.Children {
r := d.df.Reader()
r.Seek(e.Offset)
for {
if e, err := r.Next(); err != nil {
return m, err
} else if e == nil || e.Tag == 0 {
break
} else if e.Tag == dwarf.TagFormalParameter {
var p content.Variable
if v, ok := e.Val(dwarf.AttrType).(dwarf.Offset); ok {
if t, err := d.GetType(v); err != nil {
return m, err
} else {
p.Type = t
}
}
if v, ok := e.Val(dwarf.AttrName).(string); ok {
p.Name.Relative = v
}
if v, ok := e.Val(dwarf.AttrArtificial).(bool); ok && v {
if p.Type.Flags&content.FLAG_TYPE_MASK != content.FLAG_TYPE_POINTER {
m.Parameters = append(m.Parameters, p)
continue
}
// C++ "this" pointer
t := p.Type.Specialization[0]
if t.Flags&content.FLAG_CONST != 0 {
m.Flags |= content.FLAG_CONST
}
//m.Name.Absolute = t.Name.Relative + "::" + m.Name.Relative
} else {
m.Parameters = append(m.Parameters, p)
}
}
}
}
return m, nil
}
示例2: complete_pkg
func (g *Go) complete_pkg(pkg string, cmp *content.CompletionResult) error {
if g.imports == nil {
g.imports = make(map[string]*types.Package)
}
if p, err := types.GcImport(g.imports, pkg); err != nil {
return err
} else {
nn := p.Scope()
for i := 0; i < nn.NumEntries(); i++ {
t := nn.At(i)
var flags content.Flags
if n := t.Name(); n[0] != strings.ToUpper(n)[0] {
flags = content.FLAG_ACC_PROTECTED
} else {
flags = content.FLAG_ACC_PUBLIC
}
switch t.(type) {
case *types.Func:
var m content.Method
m.Flags |= flags
m.Name.Relative = t.Name()
sig := t.Type().Underlying().(*types.Signature)
if sig.Recv() != nil {
continue
}
par := sig.Params()
for j := 0; j < par.Len(); j++ {
m.Parameters = append(m.Parameters, g.pkg_var(par.At(j)))
}
ret := sig.Results()
for j := 0; j < ret.Len(); j++ {
m.Returns = append(m.Returns, g.pkg_var(ret.At(j)))
}
cmp.Methods = append(cmp.Methods, m)
case *types.TypeName:
var t2 content.Type
t2.Flags |= flags
t2.Name.Relative = t.Name()
switch t.Type().Underlying().(type) {
case *types.Interface:
t2.Flags |= content.FLAG_TYPE_INTERFACE
case *types.Struct:
t2.Flags |= content.FLAG_TYPE_STRUCT
}
cmp.Types = append(cmp.Types, t2)
case *types.Const, *types.Var:
var f content.Field
f.Name.Relative = t.Name()
f.Type = g.pkg_type(t.Type())
cmp.Fields = append(cmp.Fields, f)
default:
log4go.Warn("Unimplemented type in package completion: at: %+v, %v, %v", t, reflect.TypeOf(t), reflect.TypeOf(t.Type().Underlying()))
}
}
}
return nil
}
示例3: parseresult
func parseresult(in string) (ret content.CompletionResult, err error) {
var p cp.PARSER
p.Parse(in)
n := p.RootNode()
for i := range n.Children {
child := n.Children[i]
switch child.Name {
case "Variable":
v := content.Field{}
v.Type.Name.Relative = child.Children[0].Data()
v.Name.Relative = data(child.Children[1])
ret.Fields = append(ret.Fields, v)
case "CFunction":
f := content.Method{}
f.Returns = append(f.Returns, content.Variable{Type: content.Type{Name: content.FullyQualifiedName{Relative: child.Children[0].Data()}}})
f.Name.Relative = data(child.Children[1])
args := child.Children[2:]
for j := range args {
if args[j].Name == "ConstQualifier" {
// TODO
break
}
p := content.Variable{}
p.Type.Name.Relative = data(args[j])
f.Parameters = append(f.Parameters, p)
}
ret.Methods = append(ret.Methods, f)
case "ObjCFunction":
f := content.Method{}
f.Returns = append(f.Returns, content.Variable{Type: content.Type{Name: content.FullyQualifiedName{Relative: child.Children[1].Data()}}})
args := child.Children[2:]
for j := range args {
p := content.Variable{}
p.Type.Name.Relative = data(args[j].Children[1])
p.Name.Relative = data(args[j].Children[0])
f.Parameters = append(f.Parameters, p)
}
ret.Methods = append(ret.Methods, f)
}
}
return
}
示例4: GetType
func (d *DWARFHelper) GetType(off dwarf.Offset) (content.Type, error) {
var t content.Type
r := d.df.Reader()
r.Seek(off)
recurse := false
if e, err := r.Next(); err != nil {
return t, err
} else {
switch e.Tag {
case dwarf.TagVolatileType, dwarf.TagReferenceType, dwarf.TagRestrictType, dwarf.TagConstType, dwarf.TagSubroutineType:
recurse = true
case dwarf.TagPointerType:
t.Flags |= content.FLAG_TYPE_POINTER
recurse = true
case dwarf.TagArrayType:
recurse = true
t.Flags |= content.FLAG_TYPE_ARRAY
case dwarf.TagClassType, dwarf.TagTypedef, dwarf.TagBaseType, dwarf.TagEnumerationType, dwarf.TagStructType:
if v, ok := e.Val(dwarf.AttrName).(string); ok {
t.Name.Relative = v
}
case dwarf.TagUnionType:
t.Name.Relative = "union"
default:
return t, errors.New(fmt.Sprintf("Don't know how to handle %+v", e))
}
if recurse {
if v, ok := e.Val(dwarf.AttrType).(dwarf.Offset); ok {
if t2, err := d.GetType(v); err != nil {
return t, err
} else {
t.Specialization = append(t.Specialization, t2)
}
}
}
switch e.Tag {
case dwarf.TagVolatileType, dwarf.TagReferenceType, dwarf.TagRestrictType, dwarf.TagConstType:
if len(t.Specialization) == 0 {
t.Name.Relative = "void"
} else {
t = t.Specialization[0]
}
}
switch e.Tag {
case dwarf.TagPointerType:
if len(t.Specialization) == 0 {
t.Specialization = append(t.Specialization, content.Type{Name: content.FullyQualifiedName{Relative: "void"}})
}
case dwarf.TagVolatileType:
t.Flags |= content.FLAG_VOLATILE
case dwarf.TagReferenceType:
t.Flags |= content.FLAG_REFERENCE
case dwarf.TagRestrictType:
t.Flags |= content.FLAG_RESTRICT
case dwarf.TagConstType:
t.Flags |= content.FLAG_CONST
case dwarf.TagSubroutineType:
var m content.Method
if len(t.Specialization) > 0 {
m.Returns = append(m.Returns, content.Variable{Type: t.Specialization[0]})
} else {
m.Returns = append(m.Returns, content.Variable{Type: content.Type{Name: content.FullyQualifiedName{Relative: "void"}}})
}
t.Specialization = t.Specialization[0:0]
t.Flags = content.FLAG_TYPE_METHOD
for {
if e, err := r.Next(); err != nil {
return t, err
} else if e == nil || e.Tag == 0 {
break
} else if e.Tag == dwarf.TagFormalParameter {
var p content.Variable
if v, ok := e.Val(dwarf.AttrType).(dwarf.Offset); ok {
if t2, err := d.GetType(v); err != nil {
return t, err
} else {
p.Type = t2
}
}
if v, ok := e.Val(dwarf.AttrName).(string); ok {
p.Name.Relative = v
}
m.Parameters = append(m.Parameters, p)
}
}
t.Methods = append(t.Methods, m)
}
return t, nil
}
}
示例5: Methods
func (td *TypeDef) Methods() (methods []content.Method, err error) {
if td.ct.Name.Relative != "" {
return td.ct.Methods, nil
}
var (
mu = td.index.(*ConcreteTableIndex).metadataUtil
startRow, endRow = td.ListRange(td.index.Index(), id_TypeDef, id_MethodDef, func(i interface{}) uint32 { return i.(*TypeDefRow).MethodList.Index() })
idx = &ConcreteTableIndex{mu, startRow, id_MethodDef}
)
cn := stripProto(td.Name().Absolute)
for i := startRow; i < endRow; i++ {
idx.index = i
if rawmethod, err := idx.Data(); err != nil {
return nil, err
} else {
var (
m content.Method
method = rawmethod.(*MethodDefRow)
dec *SignatureDecoder
sig MethodDefSig
)
if n := string(method.Name); n == ".cctor" {
// Static constructor, we don't care about that one
continue
} else {
m.Name.Relative = n
}
m.Name.Absolute = fmt.Sprintf("net://method/%s;%d", cn, i-startRow)
if m.Parameters, err = td.Parameters(idx); err != nil {
return nil, err
}
if dec, err = NewSignatureDecoder(method.Signature); err != nil {
return nil, err
} else if err = dec.Decode(&sig); err != nil {
return nil, err
} else {
// TODO: need to figure out why this mismatch happens
l := len(sig.Params)
if l2 := len(m.Parameters); l2 < l {
l = l2
}
for i := range sig.Params[:l] {
m.Parameters[i].Type = td.initContentType(td.index, &sig.Params[i].Type)
}
if method.Flags&MethodAttributes_Final != 0 {
m.Flags |= content.FLAG_FINAL
}
if method.Flags&MethodAttributes_Static != 0 {
m.Flags |= content.FLAG_STATIC
}
if method.Flags&MethodAttributes_Public != 0 {
m.Flags |= content.FLAG_ACC_PUBLIC
} else if method.Flags&MethodAttributes_Private != 0 {
m.Flags |= content.FLAG_ACC_PRIVATE
} else if method.Flags&MethodAttributes_Family != 0 {
m.Flags |= content.FLAG_ACC_PROTECTED
}
if m.Name.Relative == ".ctor" {
m.Name.Relative = td.row.Name()
m.Flags |= content.FLAG_CONSTRUCTOR
} else {
m.Returns = make([]content.Variable, 1)
m.Returns[0].Type = td.initContentType(td.index, &sig.RetType.Type)
}
}
if err := check(&m, m.Name); err != nil {
log4go.Fine("Skipping method: %s, %+v, %+v", err, m, method)
continue
}
methods = append(methods, m)
}
}
return methods, nil
}
示例6: CompleteAt
func (t *Clang) CompleteAt(args *content.CompleteAtArgs, res *content.CompletionResult) error {
origargs, _ := args.Settings().Get("compiler_flags").([]string)
var unsaved map[string]string
if args.Location.File.Contents != "" {
unsaved = map[string]string{args.Location.File.Name: args.Location.File.Contents}
}
if tu := t.GetTranslationUnit(args.Location.File.Name, origargs, "", unsaved); tu == nil {
return nil
}
cres := tu.CompleteAt(args.Location.File.Name, int(args.Location.Line), int(args.Location.Column), unsaved, 0)
if !cres.IsValid() {
return fmt.Errorf("CompleteResults is not valid")
}
defer cres.Dispose()
for _, r := range cres.Results() {
var (
buf bytes.Buffer
)
switch r.CursorKind {
case clang.CK_StructDecl, clang.CK_TypedefDecl:
for _, c := range r.CompletionString.Chunks() {
buf.WriteString(c.Text())
}
var tt content.Type
tt.Flags = content.FLAG_TYPE_CLASS
tt.Name.Absolute = buf.String()
res.Types = append(res.Types, tt)
case clang.CK_FunctionDecl:
var (
m content.Method
paramstarted bool
argCount int
)
for _, c := range r.CompletionString.Chunks() {
switch k := c.Kind(); k {
case clang.CompletionChunk_ResultType:
var v content.Variable
v.Name.Relative = c.Text()
m.Returns = append(m.Returns, v)
case clang.CompletionChunk_Placeholder:
var v content.Variable
v.Type.Name.Relative = c.Text()
v.Name.Relative = fmt.Sprintf("arg%d", argCount)
argCount++
m.Parameters = append(m.Parameters, v)
case clang.CompletionChunk_LeftParen:
paramstarted = true
case clang.CompletionChunk_RightParen, clang.CompletionChunk_Comma:
case clang.CompletionChunk_TypedText:
if !paramstarted {
buf.WriteString(c.Text())
}
default:
log4go.Warn("Unimplemented CompletionChunkKind: %s", k)
}
}
m.Name.Relative = buf.String()
res.Methods = append(res.Methods, m)
default:
log4go.Warn("Unimplemented CursorKind: %s", r.CursorKind)
}
}
return nil
}