llvm.org GIT mirror llvm / 6a72c57
[Go] Subtypes function This patch adds LLVMGetSubtypes to Go API (as Type.Subtypes), tests included. Patch by Ekaterina Vaartis! Differential Revision: https://reviews.llvm.org/D33901 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304968 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Wilkins 2 years ago
2 changed file(s) with 32 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
610610 }
611611
612612 // Operations on array, pointer, and vector types (sequence types)
613 func (t Type) Subtypes() (ret []Type) {
614 ret = make([]Type, C.LLVMGetNumContainedTypes(t.C))
615 C.LLVMGetSubtypes(t.C, llvmTypeRefPtr(&ret[0]))
616 return
617 }
618
613619 func ArrayType(elementType Type, elementCount int) (t Type) {
614620 t.C = C.LLVMArrayType(elementType.C, C.unsigned(elementCount))
615621 return
133133 t.Errorf("Got metadata %v as scope, though wanted %v", loc.Scope.C, scope.C)
134134 }
135135 }
136
137 func TestSubtypes(t *testing.T) {
138 cont := NewContext()
139 defer cont.Dispose()
140
141 int_pointer := PointerType(cont.Int32Type(), 0)
142 int_inner := int_pointer.Subtypes()
143 if len(int_inner) != 1 {
144 t.Errorf("Got size %d, though wanted 1")
145 }
146 if int_inner[0] != cont.Int32Type() {
147 t.Errorf("Expected int32 type")
148 }
149
150 st_pointer := cont.StructType([]Type{cont.Int32Type(), cont.Int8Type()}, false)
151 st_inner := st_pointer.Subtypes()
152 if len(st_inner) != 2 {
153 t.Errorf("Got size %d, though wanted 2")
154 }
155 if st_inner[0] != cont.Int32Type() {
156 t.Errorf("Expected first struct field to be int32")
157 }
158 if st_inner[1] != cont.Int8Type() {
159 t.Errorf("Expected second struct field to be int8")
160 }
161 }