本文整理汇总了Golang中github.com/gsrpc/gslang/ast.Type类的典型用法代码示例。如果您正苦于以下问题:Golang Type类的具体用法?Golang Type怎么用?Golang Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Type类的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"
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:30,代码来源:codegen.go
示例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"
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:35,代码来源:codegen.go
示例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"
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:30,代码来源:codegen.go
示例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"
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:75,代码来源:codegen.go
注:本文中的github.com/gsrpc/gslang/ast.Type类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论