本文整理汇总了Golang中github.com/gsrpc/gslang/ast.Type.Package方法的典型用法代码示例。如果您正苦于以下问题:Golang Type.Package方法的具体用法?Golang Type.Package怎么用?Golang Type.Package使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gsrpc/gslang/ast.Type
的用法示例。
在下文中一共展示了Type.Package方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: typeName
func (codegen *_CodeGen) typeName(typeDecl ast.Type) string {
switch typeDecl.(type) {
case *ast.BuiltinType:
builtinType := typeDecl.(*ast.BuiltinType)
return builtin[builtinType.Type]
case *ast.TypeRef:
typeRef := typeDecl.(*ast.TypeRef)
return codegen.typeName(typeRef.Ref)
case *ast.Enum, *ast.Table:
_, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())
if gslang.IsException(typeDecl) {
return exception(name)
}
return name
case *ast.Seq:
seq := typeDecl.(*ast.Seq)
return fmt.Sprintf("%s[]", codegen.typeName(seq.Component))
}
gserrors.Panicf(nil, "typeName error: unsupport type(%s)", typeDecl)
return "unknown"
}
示例2: defaultVal
func (codegen *_CodeGen) defaultVal(typeDecl ast.Type) string {
switch typeDecl.(type) {
case *ast.BuiltinType:
builtinType := typeDecl.(*ast.BuiltinType)
return defaultval[builtinType.Type]
case *ast.TypeRef:
typeRef := typeDecl.(*ast.TypeRef)
return codegen.defaultVal(typeRef.Ref)
case *ast.Enum:
enum := typeDecl.(*ast.Enum)
_, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())
//
// if prefix != "" {
// return prefix + "." + name + "." + enum.Constants[0].Name()
// }
return name + "." + enum.Constants[0].Name()
case *ast.Table:
return "new " + codegen.typeName(typeDecl) + "()"
case *ast.Seq:
return fmt.Sprintf("new %s", codegen.arrayDefaultVal(typeDecl))
}
gserrors.Panicf(nil, "typeName error: unsupport type(%s)", typeDecl)
return "unknown"
}
示例3: objTypeName
func (codegen *_CodeGen) objTypeName(typeDecl ast.Type) string {
switch typeDecl.(type) {
case *ast.BuiltinType:
builtinType := typeDecl.(*ast.BuiltinType)
return builtinObj[builtinType.Type]
case *ast.TypeRef:
typeRef := typeDecl.(*ast.TypeRef)
return codegen.typeName(typeRef.Ref)
case *ast.Enum, *ast.Table:
prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())
if prefix != "" {
return prefix + "." + name
}
return name
case *ast.Seq:
seq := typeDecl.(*ast.Seq)
return fmt.Sprintf("%s[]", codegen.typeName(seq.Component))
}
gserrors.Panicf(nil, "typeName error: unsupport type(%s)", typeDecl)
return "unknown"
}
示例4: readType
func (codegen *_CodeGen) readType(typeDecl ast.Type) string {
switch typeDecl.(type) {
case *ast.BuiltinType:
builtinType := typeDecl.(*ast.BuiltinType)
return readMapping[builtinType.Type]
case *ast.TypeRef:
typeRef := typeDecl.(*ast.TypeRef)
return codegen.readType(typeRef.Ref)
case *ast.Enum:
prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())
if prefix != "" {
return prefix + ".Read" + name
}
return "Read" + name
case *ast.Table:
prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())
if prefix != "" {
return "" + prefix + ".Read" + name
}
return "Read" + name
case *ast.Seq:
seq := typeDecl.(*ast.Seq)
var buff bytes.Buffer
isbytes := false
builtinType, ok := seq.Component.(*ast.BuiltinType)
if ok && builtinType.Type == lexer.KeyByte {
isbytes = true
}
if seq.Size != -1 {
if isbytes {
if err := codegen.tpl.ExecuteTemplate(&buff, "readByteArray", seq); err != nil {
gserrors.Panicf(err, "exec template(readByteArray) for %s errir", seq)
}
} else {
if err := codegen.tpl.ExecuteTemplate(&buff, "readArray", seq); err != nil {
gserrors.Panicf(err, "exec template(readArray) for %s errir", seq)
}
}
} else {
if isbytes {
if err := codegen.tpl.ExecuteTemplate(&buff, "readByteList", seq); err != nil {
gserrors.Panicf(err, "exec template(readByteList) for %s errir", seq)
}
} else {
if err := codegen.tpl.ExecuteTemplate(&buff, "readList", seq); err != nil {
gserrors.Panicf(err, "exec template(readList) for %s errir", seq)
}
}
}
return buff.String()
}
gserrors.Panicf(nil, "typeName error: unsupport type(%s)", typeDecl)
return "unknown"
}