github.com/euank/go@v0.0.0-20160829210321-495514729181/src/cmd/compile/internal/ssa/type_test.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ssa
     6  
     7  // Stub implementation used for testing.
     8  type TypeImpl struct {
     9  	Size_   int64
    10  	Align   int64
    11  	Boolean bool
    12  	Integer bool
    13  	Signed  bool
    14  	Float   bool
    15  	Complex bool
    16  	Ptr     bool
    17  	string  bool
    18  	slice   bool
    19  	array   bool
    20  	struct_ bool
    21  	inter   bool
    22  	Elem_   Type
    23  
    24  	Name string
    25  }
    26  
    27  func (t *TypeImpl) Size() int64            { return t.Size_ }
    28  func (t *TypeImpl) Alignment() int64       { return t.Align }
    29  func (t *TypeImpl) IsBoolean() bool        { return t.Boolean }
    30  func (t *TypeImpl) IsInteger() bool        { return t.Integer }
    31  func (t *TypeImpl) IsSigned() bool         { return t.Signed }
    32  func (t *TypeImpl) IsFloat() bool          { return t.Float }
    33  func (t *TypeImpl) IsComplex() bool        { return t.Complex }
    34  func (t *TypeImpl) IsPtrShaped() bool      { return t.Ptr }
    35  func (t *TypeImpl) IsString() bool         { return t.string }
    36  func (t *TypeImpl) IsSlice() bool          { return t.slice }
    37  func (t *TypeImpl) IsArray() bool          { return t.array }
    38  func (t *TypeImpl) IsStruct() bool         { return t.struct_ }
    39  func (t *TypeImpl) IsInterface() bool      { return t.inter }
    40  func (t *TypeImpl) IsMemory() bool         { return false }
    41  func (t *TypeImpl) IsFlags() bool          { return false }
    42  func (t *TypeImpl) IsTuple() bool          { return false }
    43  func (t *TypeImpl) IsVoid() bool           { return false }
    44  func (t *TypeImpl) String() string         { return t.Name }
    45  func (t *TypeImpl) SimpleString() string   { return t.Name }
    46  func (t *TypeImpl) ElemType() Type         { return t.Elem_ }
    47  func (t *TypeImpl) PtrTo() Type            { panic("not implemented") }
    48  func (t *TypeImpl) NumFields() int         { panic("not implemented") }
    49  func (t *TypeImpl) FieldType(i int) Type   { panic("not implemented") }
    50  func (t *TypeImpl) FieldOff(i int) int64   { panic("not implemented") }
    51  func (t *TypeImpl) FieldName(i int) string { panic("not implemented") }
    52  func (t *TypeImpl) NumElem() int64         { panic("not implemented") }
    53  
    54  func (t *TypeImpl) Equal(u Type) bool {
    55  	x, ok := u.(*TypeImpl)
    56  	if !ok {
    57  		return false
    58  	}
    59  	return x == t
    60  }
    61  
    62  func (t *TypeImpl) Compare(u Type) Cmp {
    63  	x, ok := u.(*TypeImpl)
    64  	// ssa.CompilerType < ssa.TypeImpl < gc.Type
    65  	if !ok {
    66  		_, ok := u.(*CompilerType)
    67  		if ok {
    68  			return CMPgt
    69  		}
    70  		return CMPlt
    71  	}
    72  	if t == x {
    73  		return CMPeq
    74  	}
    75  	if t.Name < x.Name {
    76  		return CMPlt
    77  	}
    78  	if t.Name > x.Name {
    79  		return CMPgt
    80  	}
    81  	return CMPeq
    82  
    83  }
    84  
    85  var (
    86  	// shortcuts for commonly used basic types
    87  	TypeInt8       = &TypeImpl{Size_: 1, Align: 1, Integer: true, Signed: true, Name: "int8"}
    88  	TypeInt16      = &TypeImpl{Size_: 2, Align: 2, Integer: true, Signed: true, Name: "int16"}
    89  	TypeInt32      = &TypeImpl{Size_: 4, Align: 4, Integer: true, Signed: true, Name: "int32"}
    90  	TypeInt64      = &TypeImpl{Size_: 8, Align: 8, Integer: true, Signed: true, Name: "int64"}
    91  	TypeFloat32    = &TypeImpl{Size_: 4, Align: 4, Float: true, Name: "float32"}
    92  	TypeFloat64    = &TypeImpl{Size_: 8, Align: 8, Float: true, Name: "float64"}
    93  	TypeComplex64  = &TypeImpl{Size_: 8, Align: 4, Complex: true, Name: "complex64"}
    94  	TypeComplex128 = &TypeImpl{Size_: 16, Align: 8, Complex: true, Name: "complex128"}
    95  	TypeUInt8      = &TypeImpl{Size_: 1, Align: 1, Integer: true, Name: "uint8"}
    96  	TypeUInt16     = &TypeImpl{Size_: 2, Align: 2, Integer: true, Name: "uint16"}
    97  	TypeUInt32     = &TypeImpl{Size_: 4, Align: 4, Integer: true, Name: "uint32"}
    98  	TypeUInt64     = &TypeImpl{Size_: 8, Align: 8, Integer: true, Name: "uint64"}
    99  	TypeBool       = &TypeImpl{Size_: 1, Align: 1, Boolean: true, Name: "bool"}
   100  	TypeBytePtr    = &TypeImpl{Size_: 8, Align: 8, Ptr: true, Name: "*byte"}
   101  	TypeInt64Ptr   = &TypeImpl{Size_: 8, Align: 8, Ptr: true, Name: "*int64"}
   102  )