Exemple #1
0
func (codegen *_CodeGen) tagValue(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)

		switch builtinType.Type {
		case lexer.KeySByte, lexer.KeyByte, lexer.KeyBool:
			return "GSTagI8"
		case lexer.KeyInt16, lexer.KeyUInt16:
			return "GSTagI16"
		case lexer.KeyInt32, lexer.KeyUInt32, lexer.KeyFloat32:
			return "GSTagI32"
		case lexer.KeyInt64, lexer.KeyUInt64, lexer.KeyFloat64:
			return "GSTagI64"
		case lexer.KeyString:
			return "GSTagString"
		}

	case *ast.TypeRef:
		return codegen.tagValue(typeDecl.(*ast.TypeRef).Ref)
	case *ast.Enum:

		_, ok := gslang.FindAnnotation(typeDecl, "gslang.Flag")

		if !ok {
			return "GSTagI32"
		}

		return "GSTagI8"

	case *ast.Table:
		return "GSTagTable"
	case *ast.Seq:

		seq := typeDecl.(*ast.Seq)

		component := codegen.tagValue(seq.Component)

		if component == "GSTagList" {
			start, _ := gslang.Pos(typeDecl)
			gserrors.Panicf(nil, "list component %v can't be a list :%v", seq.Component, start)
		}

		return fmt.Sprintf("((%s << 4)|GSTagList)", component)
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return ""
}
Exemple #2
0
func (codegen *_CodeGen) tagValue(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)

		switch builtinType.Type {
		case lexer.KeySByte, lexer.KeyByte, lexer.KeyBool:
			return "com.gsrpc.Tag.I8.getValue()"
		case lexer.KeyInt16, lexer.KeyUInt16:
			return "com.gsrpc.Tag.I16.getValue()"
		case lexer.KeyInt32, lexer.KeyUInt32, lexer.KeyFloat32:
			return "com.gsrpc.Tag.I32.getValue()"
		case lexer.KeyInt64, lexer.KeyUInt64, lexer.KeyFloat64:
			return "com.gsrpc.Tag.I64.getValue()"
		case lexer.KeyString:
			return "com.gsrpc.Tag.String.getValue()"
		}

	case *ast.TypeRef:
		return codegen.tagValue(typeDecl.(*ast.TypeRef).Ref)
	case *ast.Enum:

		if codegen.enumSize(typeDecl) == 4 {
			return "com.gsrpc.Tag.I32.getValue()"
		}

		return "com.gsrpc.Tag.I8.getValue()"

	case *ast.Table:
		return "com.gsrpc.Tag.Table.getValue()"
	case *ast.Seq:

		seq := typeDecl.(*ast.Seq)

		component := codegen.tagValue(seq.Component)

		if component == "com.gsrpc.Tag.List.getValue()" {
			start, _ := gslang.Pos(typeDecl)
			gserrors.Panicf(nil, "list component %v can't be a list :%v", seq.Component, start)
		}

		return fmt.Sprintf("((%s << 4)|com.gsrpc.Tag.List.getValue())", component)
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return ""
}