From 8c199ce43c4d3789f84e5459c1cc14ebfc75c06b Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Mon, 31 Jan 2022 15:22:34 +0000 Subject: [PATCH] Split virtual methods diff test in two files --- test/FirstDerivative/Overloads.C | 112 ++++++++++++++++++++++ test/FirstDerivative/VirtualMethodsCall.C | 84 +--------------- 2 files changed, 113 insertions(+), 83 deletions(-) create mode 100644 test/FirstDerivative/Overloads.C diff --git a/test/FirstDerivative/Overloads.C b/test/FirstDerivative/Overloads.C new file mode 100644 index 000000000..6f5a09aeb --- /dev/null +++ b/test/FirstDerivative/Overloads.C @@ -0,0 +1,112 @@ +// RUN: %cladclang %s -I%S/../../include -lstdc++ -oOverloads.out 2>&1 | FileCheck %s +// RUN: ./Overloads.out | FileCheck -check-prefix=CHECK-EXEC %s +//CHECK-NOT: {{.*error|warning|note:.*}} + +#include "clad/Differentiator/Differentiator.h" + +extern "C" int printf(const char* fmt, ...); + +// Overload + +float func(float x) { + return x; +} + +double func(double x) { + return x+x; +} + +// Classes: forward, hide, overload, virtual and overriden methods + +class A { +public: + float f1(float x) { + return x+x+x; + } + + double f1(double x) { + return x+x+x+x; + } +}; + +class B : public A { +public: + float f1(float x) { + return x+x+x+x+x; + } + + int f1(int x) { + return x; + } +}; + +class B1 : public A { +public: + double f1(double x) { + return x+x+x+x+x+x; + } +}; +int main () { + A a; + B b; + B1 b1; + + // Function overloads + + auto func_darg0_float = clad::differentiate(static_cast(&func), 0); +//CHECK: float func_darg0(float x) { +//CHECK-NEXT: float _d_x = 1; +//CHECK-NEXT: return _d_x; +//CHECK-NEXT: } + auto func_darg0_double = clad::differentiate((double(*)(double))&func, 0); +//CHECK: double func_darg0(double x) { +//CHECK-NEXT: double _d_x = 1; +//CHECK-NEXT: return _d_x + _d_x; +//CHECK-NEXT: } + printf("Result is = %f\n", func_darg0_float.execute(2.0)); // CHECK-EXEC: Result is = 1.0000 + printf("Result is = %f\n", func_darg0_double.execute(2.0)); // CHECK-EXEC: Result is = 2.0000 + + printf("---\n"); // CHECK-EXEC: --- + + // Method overloads + + auto f1_darg0_float_A = clad::differentiate((float(A::*)(float))&A::f1, 0); +//CHECK: float f1_darg0(float x) { +//CHECK-NEXT: float _d_x = 1; +//CHECK-NEXT: return _d_x + _d_x + _d_x; +//CHECK-NEXT: } + auto f1_darg0_double_A = clad::differentiate((double(A::*)(double))&A::f1, 0); +//CHECK: double f1_darg0(double x) { +//CHECK-NEXT: double _d_x = 1; +//CHECK-NEXT: return _d_x + _d_x + _d_x + _d_x; +//CHECK-NEXT: } + auto f1_darg0_float_B = clad::differentiate((float(B::*)(float))&B::f1, 0); +//CHECK: float f1_darg0(float x) { +//CHECK-NEXT: float _d_x = 1; +//CHECK-NEXT: return _d_x + _d_x + _d_x + _d_x + _d_x; +//CHECK-NEXT: } + auto f1_darg0_int_B = clad::differentiate((int(B::*)(int))&B::f1, 0); +//CHECK: int f1_darg0(int x) { +//CHECK-NEXT: int _d_x = 1; +//CHECK-NEXT: return _d_x; +//CHECK-NEXT: } + // resolve to float(B::*)(float) + //auto f1_darg0_double_B = clad::differentiate((double(B::*)(double))&B::f1, 0); // ?EXPECTED-ERROR {{address of overloaded function 'f1' does not match required type 'double (double)'}} + // resolve to double(B1::*)(double) + auto f1_darg0_float_B1 = clad::differentiate((float(B1::*)(float))&B1::f1, 0); + // + auto f1_darg0_double_B1 = clad::differentiate((double(B1::*)(double))&B1::f1, 0); +//CHECK: double f1_darg0(double x) { +//CHECK-NEXT: double _d_x = 1; +//CHECK-NEXT: return _d_x + _d_x + _d_x + _d_x + _d_x + _d_x; +//CHECK-NEXT: } + printf("Result is = %f\n", f1_darg0_float_A.execute(a, 2.0)); // CHECK-EXEC: Result is = 3.0000 + printf("Result is = %f\n", f1_darg0_double_A.execute(a, 2.0)); // CHECK-EXEC: Result is = 4.0000 + printf("Result is = %f\n", f1_darg0_float_B.execute(b, 2.0)); // CHECK-EXEC: Result is = 5.0000 + printf("Result is = %i\n", f1_darg0_int_B.execute(b, 2)); // CHECK-EXEC: Result is = 1 + //printf("Result is %s\n", f1_darg0_double_B.execute(b, 2.0)<1 ? "float" : "other"); // -CHECK-EXEC: Result is float + printf("Result is %s\n", f1_darg0_float_B1.execute(b1, 2.0f)<1 ? "double" : "other"); // CHECK-EXEC: Result is double + printf("Result is = %f\n", f1_darg0_double_B1.execute(b1, 2.0)); // CHECK-EXEC: Result is = 6.0000 + + return 0; +} diff --git a/test/FirstDerivative/VirtualMethodsCall.C b/test/FirstDerivative/VirtualMethodsCall.C index e05c0fffc..483ae3fd8 100644 --- a/test/FirstDerivative/VirtualMethodsCall.C +++ b/test/FirstDerivative/VirtualMethodsCall.C @@ -6,17 +6,7 @@ extern "C" int printf(const char* fmt, ...); -// Overload - -float func(float x) { - return x; -} - -double func(double x) { - return x+x; -} - -// Classes: forward, hide, overload, virtual and overriden methods +// Classes: forward, hide, virtual and overriden methods class A { public: @@ -29,16 +19,6 @@ public: return x; } - // Overload - - float f1(float x) { - return x+x+x; - } - - double f1(double x) { - return x+x+x+x; - } - // Virtual/Override virtual float vm(float x, float y) { @@ -87,7 +67,6 @@ float A::m(float x, float y) { //return vm_darg0_cf.execute(*this, x, y) + vm_darg1_cf.execute(*this, x, y); } - class B : public A { public: B() {} @@ -99,12 +78,6 @@ public: return x*x; } - // Overload - - float f1(float x) { - return x+x+x+x+x; - } - // Virtual/Override float vm(float x, float y) override { @@ -147,12 +120,6 @@ public: return x*x*x; } - // Overload - - double f1(double x) { - return x+x+x+x+x+x; - } - // Virtual/Override float vm(float x, float y) override { @@ -173,22 +140,6 @@ int main () { B b; B1 b1; - // functions overload - auto func_darg0_float = clad::differentiate(static_cast(&func), 0); -//CHECK: float func_darg0(float x) { -//CHECK-NEXT: float _d_x = 1; -//CHECK-NEXT: return _d_x; -//CHECK-NEXT: } - auto func_darg0_double = clad::differentiate((double(*)(double))&func, 0); -//CHECK: double func_darg0(double x) { -//CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: return _d_x + _d_x; -//CHECK-NEXT: } - printf("Result is = %f\n", func_darg0_float.execute(2.0)); // CHECK-EXEC: Result is = 1.0000 - printf("Result is = %f\n", func_darg0_double.execute(2.0)); // CHECK-EXEC: Result is = 2.0000 - - printf("---\n"); // CHECK-EXEC: --- - // printf("Result is = %f\n", a.f(2.0)); // CHECK-EXEC: Result is = 2.0000 printf("Result is = %f\n", b.f(2.0)); // CHECK-EXEC: Result is = 4.0000 @@ -218,39 +169,6 @@ int main () { printf("---\n"); // CHECK-EXEC: --- - auto f1_darg0_float_A = clad::differentiate((float(A::*)(float))&A::f1, 0); -//CHECK: float f1_darg0(float x) { -//CHECK-NEXT: float _d_x = 1; -//CHECK-NEXT: return _d_x + _d_x + _d_x; -//CHECK-NEXT: } - auto f1_darg0_double_A = clad::differentiate((double(A::*)(double))&A::f1, 0); -//CHECK: double f1_darg0(double x) { -//CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: return _d_x + _d_x + _d_x + _d_x; -//CHECK-NEXT: } - auto f1_darg0_float_B = clad::differentiate((float(B::*)(float))&B::f1, 0); -//CHECK: float f1_darg0(float x) { -//CHECK-NEXT: float _d_x = 1; -//CHECK-NEXT: return _d_x + _d_x + _d_x + _d_x + _d_x; -//CHECK-NEXT: } - auto f1_darg0_double_B = clad::differentiate((double(B::*)(double))&B::f1, 0); // resolve to float(B::*)(float) -// - auto f1_darg0_float_B1 = clad::differentiate((float(B1::*)(float))&B1::f1, 0); // resolve to double(B1::*)(double) -// - auto f1_darg0_double_B1 = clad::differentiate((double(B1::*)(double))&B1::f1, 0); -//CHECK: double f1_darg0(double x) { -//CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: return _d_x + _d_x + _d_x + _d_x + _d_x + _d_x; -//CHECK-NEXT: } - printf("Result is = %f\n", f1_darg0_float_A.execute(a, 2.0)); // CHECK-EXEC: Result is = 3.0000 - printf("Result is = %f\n", f1_darg0_double_A.execute(a, 2.0)); // CHECK-EXEC: Result is = 4.0000 - printf("Result is = %f\n", f1_darg0_float_B.execute(b, 2.0)); // CHECK-EXEC: Result is = 5.0000 - printf("Result is %s\n", f1_darg0_double_B.execute(b, 2.0)<1 ? "float" : "other"); // CHECK-EXEC: Result is float - printf("Result is %s\n", f1_darg0_float_B1.execute(b1, 2.0f)<1 ? "double" : "other"); // CHECK-EXEC: Result is double - printf("Result is = %f\n", f1_darg0_double_B1.execute(b1, 2.0)); // CHECK-EXEC: Result is = 6.0000 - - printf("---\n"); // CHECK-EXEC: --- - auto vm_darg0_A = clad::differentiate((float(A::*)(float,float))&A::vm, 0); //CHECK: float vm_darg0(float x, float y) override { //CHECK-NEXT: float _d_x = 1;