1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // ignore-tidy-linelength
13 // ignore-android: FIXME(#10381)
16 // gdb-command:rbreak zzz
22 // gdb-command:whatis simple_struct
23 // gdb-check:type = struct Struct1
25 // gdb-command:whatis generic_struct1
26 // gdb-check:type = struct GenericStruct<type-names::Mod1::Struct2, type-names::Mod1::Mod2::Struct3>
28 // gdb-command:whatis generic_struct2
29 // gdb-check:type = struct GenericStruct<type-names::Struct1, extern "fastcall" fn(int) -> uint>
31 // gdb-command:whatis mod_struct
32 // gdb-check:type = struct Struct2
36 // gdb-command:whatis simple_enum_1
37 // gdb-check:type = union Enum1
39 // gdb-command:whatis simple_enum_2
40 // gdb-check:type = union Enum1
42 // gdb-command:whatis simple_enum_3
43 // gdb-check:type = union Enum2
45 // gdb-command:whatis generic_enum_1
46 // gdb-check:type = union Enum3<type-names::Mod1::Struct2>
48 // gdb-command:whatis generic_enum_2
49 // gdb-check:type = union Enum3<type-names::Struct1>
53 // gdb-command:whatis tuple1
54 // gdb-check:type = struct (u32, type-names::Struct1, type-names::Mod1::Mod2::Enum3<type-names::Mod1::Struct2>)
56 // gdb-command:whatis tuple2
57 // gdb-check:type = struct ((type-names::Struct1, type-names::Mod1::Mod2::Struct3), type-names::Mod1::Enum2, char)
61 // gdb-command:whatis box1
62 // gdb-check:type = struct (Box<f32>, i32)
64 // gdb-command:whatis box2
65 // gdb-check:type = struct (Box<type-names::Mod1::Mod2::Enum3<f32>>, i32)
69 // gdb-command:whatis ref1
70 // gdb-check:type = struct (&type-names::Struct1, i32)
72 // gdb-command:whatis ref2
73 // gdb-check:type = struct (&type-names::GenericStruct<char, type-names::Struct1>, i32)
75 // gdb-command:whatis mut_ref1
76 // gdb-check:type = struct (&mut type-names::Struct1, i32)
78 // gdb-command:whatis mut_ref2
79 // gdb-check:type = struct (&mut type-names::GenericStruct<type-names::Mod1::Enum2, f64>, i32)
83 // gdb-command:whatis mut_ptr1
84 // gdb-check:type = struct (*mut type-names::Struct1, int)
86 // gdb-command:whatis mut_ptr2
87 // gdb-check:type = struct (*mut int, int)
89 // gdb-command:whatis mut_ptr3
90 // gdb-check:type = struct (*mut type-names::Mod1::Mod2::Enum3<type-names::Struct1>, int)
92 // gdb-command:whatis const_ptr1
93 // gdb-check:type = struct (*const type-names::Struct1, int)
95 // gdb-command:whatis const_ptr2
96 // gdb-check:type = struct (*const int, int)
98 // gdb-command:whatis const_ptr3
99 // gdb-check:type = struct (*const type-names::Mod1::Mod2::Enum3<type-names::Struct1>, int)
103 // gdb-command:whatis fixed_size_vec1
104 // gdb-check:type = struct ([type-names::Struct1, ..3], i16)
106 // gdb-command:whatis fixed_size_vec2
107 // gdb-check:type = struct ([uint, ..3], i16)
109 // gdb-command:whatis slice1
110 // gdb-check:type = struct &[uint]
112 // gdb-command:whatis slice2
113 // gdb-check:type = struct &[type-names::Mod1::Enum2]
117 // gdb-command:whatis box_trait
118 // gdb-check:type = struct Box<Trait1>
120 // gdb-command:whatis ref_trait
121 // gdb-check:type = struct &Trait1
123 // gdb-command:whatis mut_ref_trait
124 // gdb-check:type = struct &mut Trait1
126 // gdb-command:whatis generic_box_trait
127 // gdb-check:type = struct Box<Trait2<i32, type-names::Mod1::Struct2>>
129 // gdb-command:whatis generic_ref_trait
130 // gdb-check:type = struct &Trait2<type-names::Struct1, type-names::Struct1>
132 // gdb-command:whatis generic_mut_ref_trait
133 // gdb-check:type = struct &mut Trait2<type-names::Mod1::Mod2::Struct3, type-names::GenericStruct<uint, int>>
137 // gdb-command:whatis rust_fn
138 // gdb-check:type = struct (fn(core::option::Option<int>, core::option::Option<&type-names::Mod1::Struct2>), uint)
140 // gdb-command:whatis extern_c_fn
141 // gdb-check:type = struct (extern "C" fn(int), uint)
143 // gdb-command:whatis unsafe_fn
144 // gdb-check:type = struct (unsafe fn(core::result::Result<char, f64>), uint)
146 // gdb-command:whatis extern_stdcall_fn
147 // gdb-check:type = struct (extern "stdcall" fn(), uint)
149 // gdb-command:whatis rust_fn_with_return_value
150 // gdb-check:type = struct (fn(f64) -> uint, uint)
152 // gdb-command:whatis extern_c_fn_with_return_value
153 // gdb-check:type = struct (extern "C" fn() -> type-names::Struct1, uint)
155 // gdb-command:whatis unsafe_fn_with_return_value
156 // gdb-check:type = struct (unsafe fn(type-names::GenericStruct<u16, u8>) -> type-names::Mod1::Struct2, uint)
158 // gdb-command:whatis extern_stdcall_fn_with_return_value
159 // gdb-check:type = struct (extern "stdcall" fn(Box<int>) -> uint, uint)
161 // gdb-command:whatis generic_function_int
162 // gdb-check:type = struct (fn(int) -> int, uint)
164 // gdb-command:whatis generic_function_struct3
165 // gdb-check:type = struct (fn(type-names::Mod1::Mod2::Struct3) -> type-names::Mod1::Mod2::Struct3, uint)
167 // gdb-command:whatis variadic_function
168 // gdb-check:type = struct (unsafe extern "C" fn(*const u8, ...) -> int, uint)
172 // gdb-command:whatis some_proc
173 // gdb-check:type = struct (once proc(int, u8) -> (int, u8), uint)
175 // gdb-command:whatis stack_closure1
176 // gdb-check:type = struct (&mut|int|, uint)
178 // gdb-command:whatis stack_closure2
179 // gdb-check:type = struct (&mut|i8, f32| -> f32, uint)
184 struct GenericStruct<T1, T2>;
196 Variant2_2(super::Struct1)
210 trait Trait2<T1, T2> { }
212 impl Trait1 for int {}
213 impl<T1, T2> Trait2<T1, T2> for int {}
215 fn rust_fn(_: Option<int>, _: Option<&Mod1::Struct2>) {}
216 extern "C" fn extern_c_fn(_: int) {}
217 unsafe fn unsafe_fn(_: Result<char, f64>) {}
218 extern "stdcall" fn extern_stdcall_fn() {}
220 fn rust_fn_with_return_value(_: f64) -> uint { 4 }
221 extern "C" fn extern_c_fn_with_return_value() -> Struct1 { Struct1 }
222 unsafe fn unsafe_fn_with_return_value(_: GenericStruct<u16, u8>) -> Mod1::Struct2 { Mod1::Struct2 }
223 extern "stdcall" fn extern_stdcall_fn_with_return_value(_: Box<int>) -> uint { 0 }
225 fn generic_function<T>(x: T) -> T { x }
228 fn printf(_:*const u8, ...) -> int;
231 // In many of the cases below, the type that is actually under test is wrapped
232 // in a tuple, e.g. Box<T>, references, raw pointers, fixed-size vectors, ...
233 // This is because GDB will not print the type name from DWARF debuginfo for
234 // some kinds of types (pointers, arrays, functions, ...)
235 // Since tuples are structs as far as GDB is concerned, their name will be
236 // printed correctly, so the tests below just construct a tuple type that will
237 // then *contain* the type name that we want to see.
241 let simple_struct = Struct1;
242 let generic_struct1: GenericStruct<Mod1::Struct2, Mod1::Mod2::Struct3> = GenericStruct;
243 let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(int) -> uint> = GenericStruct;
244 let mod_struct = Mod1::Struct2;
247 let simple_enum_1 = Variant1_1;
248 let simple_enum_2 = Variant1_2(0);
249 let simple_enum_3 = Mod1::Variant2_2(Struct1);
251 let generic_enum_1: Mod1::Mod2::Enum3<Mod1::Struct2> = Mod1::Mod2::Variant3_1;
252 let generic_enum_2 = Mod1::Mod2::Variant3_2(Struct1);
255 let tuple1 = (8u32, Struct1, Mod1::Mod2::Variant3_2(Mod1::Struct2));
256 let tuple2 = ((Struct1, Mod1::Mod2::Struct3), Mod1::Variant2_1, 'x');
259 let box1 = (box 1f32, 0i32);
260 let box2 = (box Mod1::Mod2::Variant3_2(1f32), 0i32);
263 let ref1 = (&Struct1, 0i32);
264 let ref2 = (&GenericStruct::<char, Struct1>, 0i32);
266 let mut mut_struct1 = Struct1;
267 let mut mut_generic_struct = GenericStruct::<Mod1::Enum2, f64>;
268 let mut_ref1 = (&mut mut_struct1, 0i32);
269 let mut_ref2 = (&mut mut_generic_struct, 0i32);
272 let mut_ptr1: (*mut Struct1, int) = (ptr::null_mut(), 0);
273 let mut_ptr2: (*mut int, int) = (ptr::null_mut(), 0);
274 let mut_ptr3: (*mut Mod1::Mod2::Enum3<Struct1>, int) = (ptr::null_mut(), 0);
276 let const_ptr1: (*const Struct1, int) = (ptr::null(), 0);
277 let const_ptr2: (*const int, int) = (ptr::null(), 0);
278 let const_ptr3: (*const Mod1::Mod2::Enum3<Struct1>, int) = (ptr::null(), 0);
281 let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
282 let fixed_size_vec2 = ([0u, 1u, 2u], 0i16);
284 let vec1 = vec![0u, 2u, 3u];
285 let slice1 = vec1.as_slice();
286 let vec2 = vec![Mod1::Variant2_2(Struct1)];
287 let slice2 = vec2.as_slice();
290 let box_trait = (box 0i) as Box<Trait1>;
291 let ref_trait = &0i as &Trait1;
292 let mut mut_int1 = 0i;
293 let mut_ref_trait = (&mut mut_int1) as &mut Trait1;
295 let generic_box_trait = (box 0i) as Box<Trait2<i32, Mod1::Struct2>>;
296 let generic_ref_trait = (&0i) as &Trait2<Struct1, Struct1>;
298 let mut generic_mut_ref_trait_impl = 0i;
299 let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl) as
300 &mut Trait2<Mod1::Mod2::Struct3, GenericStruct<uint, int>>;
303 let rust_fn = (rust_fn, 0u);
304 let extern_c_fn = (extern_c_fn, 0u);
305 let unsafe_fn = (unsafe_fn, 0u);
306 let extern_stdcall_fn = (extern_stdcall_fn, 0u);
308 let rust_fn_with_return_value = (rust_fn_with_return_value, 0u);
309 let extern_c_fn_with_return_value = (extern_c_fn_with_return_value, 0u);
310 let unsafe_fn_with_return_value = (unsafe_fn_with_return_value, 0u);
311 let extern_stdcall_fn_with_return_value = (extern_stdcall_fn_with_return_value, 0u);
313 let generic_function_int = (generic_function::<int>, 0u);
314 let generic_function_struct3 = (generic_function::<Mod1::Mod2::Struct3>, 0u);
316 let variadic_function = (printf, 0u);
319 // I (mw) am a bit unclear about the current state of closures, their
320 // various forms (boxed, unboxed, proc, capture-by-ref, by-val, once) and
321 // how that maps to rustc's internal representation of these forms.
322 // Once closures have reached their 1.0 form, the tests below should
323 // probably be expanded.
324 let some_proc = (proc(a:int, b:u8) (a, b), 0u);
326 let stack_closure1 = (|x:int| {}, 0u);
327 let stack_closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0u);