1 //===- string.go - Stringer implementation for Type -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Stringer interface for the Type type.
12 //===----------------------------------------------------------------------===//
18 func (t TypeKind) String() string {
23 return "FloatTypeKind"
25 return "DoubleTypeKind"
26 case X86_FP80TypeKind:
27 return "X86_FP80TypeKind"
29 return "FP128TypeKind"
30 case PPC_FP128TypeKind:
31 return "PPC_FP128TypeKind"
33 return "LabelTypeKind"
35 return "IntegerTypeKind"
36 case FunctionTypeKind:
37 return "FunctionTypeKind"
39 return "StructTypeKind"
41 return "ArrayTypeKind"
43 return "PointerTypeKind"
45 return "VectorTypeKind"
46 case MetadataTypeKind:
47 return "MetadataTypeKind"
52 func (t Type) String() string {
53 ts := typeStringer{s: make(map[Type]string)}
54 return ts.typeString(t)
57 type typeStringer struct {
61 func (ts *typeStringer) typeString(t Type) string {
62 if s, ok := ts.s[t]; ok {
68 s = s[:len(s)-len("Kind")]
72 s += fmt.Sprintf("(%v[%v])", ts.typeString(t.ElementType()), t.ArrayLength())
74 s += fmt.Sprintf("(%v)", ts.typeString(t.ElementType()))
75 case FunctionTypeKind:
76 params := t.ParamTypes()
79 s += fmt.Sprintf("%v", ts.typeString(params[0]))
80 for i := 1; i < len(params); i++ {
81 s += fmt.Sprintf(", %v", ts.typeString(params[i]))
84 s += fmt.Sprintf("):%v", ts.typeString(t.ReturnType()))
86 if name := t.StructName(); name != "" {
88 s = fmt.Sprintf("%%%s: %s", name, s)
90 etypes := t.StructElementTypes()
92 if n := len(etypes); n > 0 {
93 s += ts.typeString(etypes[0])
94 for i := 1; i < n; i++ {
95 s += fmt.Sprintf(", %v", ts.typeString(etypes[i]))
100 s += fmt.Sprintf("(%d bits)", t.IntTypeWidth())