From 8261f2c37c7181fb4a40e8f8d9eaebb96deea9bb Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 31 Jul 2013 15:01:54 -0700 Subject: [PATCH] test: add more codegen tests, add copyright headers to all. --- src/test/codegen/iterate-over-array.cc | 10 +++++++ src/test/codegen/iterate-over-array.rs | 10 +++++++ src/test/codegen/scalar-function-call.cc | 10 +++++++ src/test/codegen/scalar-function-call.rs | 10 +++++++ src/test/codegen/small-dense-int-switch.cc | 10 +++++++ src/test/codegen/small-dense-int-switch.rs | 10 +++++++ src/test/codegen/stack-alloc-string-slice.cc | 10 +++++++ src/test/codegen/stack-alloc-string-slice.rs | 10 +++++++ src/test/codegen/static-method-call-multi.cc | 27 ++++++++++++++++++ src/test/codegen/static-method-call-multi.rs | 28 +++++++++++++++++++ src/test/codegen/static-method-call.cc | 23 +++++++++++++++ src/test/codegen/static-method-call.rs | 24 ++++++++++++++++ .../virtual-method-call-struct-return.cc | 25 +++++++++++++++++ .../virtual-method-call-struct-return.rs | 23 +++++++++++++++ src/test/codegen/virtual-method-call.cc | 20 +++++++++++++ src/test/codegen/virtual-method-call.rs | 18 ++++++++++++ 16 files changed, 268 insertions(+) create mode 100644 src/test/codegen/static-method-call-multi.cc create mode 100644 src/test/codegen/static-method-call-multi.rs create mode 100644 src/test/codegen/static-method-call.cc create mode 100644 src/test/codegen/static-method-call.rs create mode 100644 src/test/codegen/virtual-method-call-struct-return.cc create mode 100644 src/test/codegen/virtual-method-call-struct-return.rs create mode 100644 src/test/codegen/virtual-method-call.cc create mode 100644 src/test/codegen/virtual-method-call.rs diff --git a/src/test/codegen/iterate-over-array.cc b/src/test/codegen/iterate-over-array.cc index 7eca21b13d70b..9261bddb74788 100644 --- a/src/test/codegen/iterate-over-array.cc +++ b/src/test/codegen/iterate-over-array.cc @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #include #include diff --git a/src/test/codegen/iterate-over-array.rs b/src/test/codegen/iterate-over-array.rs index cf54e6eafbaf1..e3bd7f5521628 100644 --- a/src/test/codegen/iterate-over-array.rs +++ b/src/test/codegen/iterate-over-array.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #[no_mangle] fn test(x: &[int]) -> int { let mut y = 0; diff --git a/src/test/codegen/scalar-function-call.cc b/src/test/codegen/scalar-function-call.cc index 91ed882f68a9f..ce3173ce464b1 100644 --- a/src/test/codegen/scalar-function-call.cc +++ b/src/test/codegen/scalar-function-call.cc @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #include size_t foo(size_t x) { diff --git a/src/test/codegen/scalar-function-call.rs b/src/test/codegen/scalar-function-call.rs index 7e4a566749ba6..e3631b73c022c 100644 --- a/src/test/codegen/scalar-function-call.rs +++ b/src/test/codegen/scalar-function-call.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + fn foo(x: int) -> int { x * x } diff --git a/src/test/codegen/small-dense-int-switch.cc b/src/test/codegen/small-dense-int-switch.cc index 87bc5bf852eb4..db93829c62b86 100644 --- a/src/test/codegen/small-dense-int-switch.cc +++ b/src/test/codegen/small-dense-int-switch.cc @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #include extern "C" diff --git a/src/test/codegen/small-dense-int-switch.rs b/src/test/codegen/small-dense-int-switch.rs index 6840dc7411b34..c6bab3da958c1 100644 --- a/src/test/codegen/small-dense-int-switch.rs +++ b/src/test/codegen/small-dense-int-switch.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #[no_mangle] fn test(x: int, y: int) -> int { match x { diff --git a/src/test/codegen/stack-alloc-string-slice.cc b/src/test/codegen/stack-alloc-string-slice.cc index 01eae9b16bb6f..a81f76eee0bc5 100644 --- a/src/test/codegen/stack-alloc-string-slice.cc +++ b/src/test/codegen/stack-alloc-string-slice.cc @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #include struct slice { diff --git a/src/test/codegen/stack-alloc-string-slice.rs b/src/test/codegen/stack-alloc-string-slice.rs index e7cd84f63f2b0..b776f5a46a721 100644 --- a/src/test/codegen/stack-alloc-string-slice.rs +++ b/src/test/codegen/stack-alloc-string-slice.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #[no_mangle] fn test() { let _x = "hello"; diff --git a/src/test/codegen/static-method-call-multi.cc b/src/test/codegen/static-method-call-multi.cc new file mode 100644 index 0000000000000..6c03e32b98c4f --- /dev/null +++ b/src/test/codegen/static-method-call-multi.cc @@ -0,0 +1,27 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include + +struct Struct { + size_t field; + size_t method(size_t x) { + return this->field + x; + } +}; + +extern "C" +size_t test(Struct &a, + Struct &b, + Struct &c, + Struct &d, + Struct &e) { + return a.method(b.method(c.method(d.method(e.method(1))))); +} diff --git a/src/test/codegen/static-method-call-multi.rs b/src/test/codegen/static-method-call-multi.rs new file mode 100644 index 0000000000000..9cb011a49f82a --- /dev/null +++ b/src/test/codegen/static-method-call-multi.rs @@ -0,0 +1,28 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Struct { + field: int +} + +impl Struct { + fn method(&self, x: int) -> int { + self.field + x + } +} + +#[no_mangle] +fn test(a: &Struct, + b: &Struct, + c: &Struct, + d: &Struct, + e: &Struct) -> int { + a.method(b.method(c.method(d.method(e.method(1))))) +} diff --git a/src/test/codegen/static-method-call.cc b/src/test/codegen/static-method-call.cc new file mode 100644 index 0000000000000..36cfa4f4d84d4 --- /dev/null +++ b/src/test/codegen/static-method-call.cc @@ -0,0 +1,23 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include + +struct Struct { + size_t field; + size_t method() { + return this->field; + } +}; + +extern "C" +size_t test(Struct &s) { + return s.method(); +} diff --git a/src/test/codegen/static-method-call.rs b/src/test/codegen/static-method-call.rs new file mode 100644 index 0000000000000..a1cf6d1dda774 --- /dev/null +++ b/src/test/codegen/static-method-call.rs @@ -0,0 +1,24 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Struct { + field: int +} + +impl Struct { + fn method(&self) -> int { + self.field + } +} + +#[no_mangle] +fn test(s: &Struct) -> int { + s.method() +} diff --git a/src/test/codegen/virtual-method-call-struct-return.cc b/src/test/codegen/virtual-method-call-struct-return.cc new file mode 100644 index 0000000000000..345f21c56472b --- /dev/null +++ b/src/test/codegen/virtual-method-call-struct-return.cc @@ -0,0 +1,25 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include + +struct Stuff { + size_t a; + double b; +}; + +struct Struct { + virtual Stuff method() = 0; +}; + +extern "C" +size_t test(Struct &s) { + return s.method().a; +} diff --git a/src/test/codegen/virtual-method-call-struct-return.rs b/src/test/codegen/virtual-method-call-struct-return.rs new file mode 100644 index 0000000000000..86d737118d62f --- /dev/null +++ b/src/test/codegen/virtual-method-call-struct-return.rs @@ -0,0 +1,23 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Stuff { + a: int, + b: f64 +} + +trait Trait { + fn method(&self) -> Stuff; +} + +#[no_mangle] +fn test(t: &Trait) -> int { + t.method().a +} diff --git a/src/test/codegen/virtual-method-call.cc b/src/test/codegen/virtual-method-call.cc new file mode 100644 index 0000000000000..9fcafdf659499 --- /dev/null +++ b/src/test/codegen/virtual-method-call.cc @@ -0,0 +1,20 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include + +struct Struct { + virtual size_t method() = 0; +}; + +extern "C" +size_t test(Struct &s) { + return s.method(); +} diff --git a/src/test/codegen/virtual-method-call.rs b/src/test/codegen/virtual-method-call.rs new file mode 100644 index 0000000000000..66dd41984a7ce --- /dev/null +++ b/src/test/codegen/virtual-method-call.rs @@ -0,0 +1,18 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Trait { + fn method(&self) -> int; +} + +#[no_mangle] +fn test(t: &Trait) -> int { + t.method() +}