diff --git a/test/5_Stress/CMakeLists.txt b/test/5_Stress/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..04e81aff93b2a7e34bb45f92efb368da2eee257f --- /dev/null +++ b/test/5_Stress/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.16) +project(StressTest) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include_directories(include) +add_executable(test + main.cpp + ) + +add_compile_definitions(test -DStatics=True) + +add_subdirectory(src) + + diff --git a/test/5_Stress/demo.sh b/test/5_Stress/demo.sh new file mode 100644 index 0000000000000000000000000000000000000000..e4b311f670eaf590d24152f31c241402275c41ca --- /dev/null +++ b/test/5_Stress/demo.sh @@ -0,0 +1,8 @@ +cgcollector --metacg-format-version=2 --extra-arg=-I$(clang --print-resource-dir)/include -p build --capture-ctors-dtors --capture-stack-ctors-dtors main.cpp +cgcollector --metacg-format-version=2 --extra-arg=-I$(clang --print-resource-dir)/include -p build --capture-ctors-dtors --capture-stack-ctors-dtors src/uses.cpp +cgcollector --metacg-format-version=2 --extra-arg=-I$(clang --print-resource-dir)/include -p build --capture-ctors-dtors --capture-stack-ctors-dtors src/combinations.cpp +cgcollector --metacg-format-version=2 --extra-arg=-I$(clang --print-resource-dir)/include -p build --capture-ctors-dtors --capture-stack-ctors-dtors src/geometry.cpp + +echo "null" > merged.mcg +cgmerge merged.mcg main.ipcg src/combinations.ipcg src/geometry.ipcg src/uses.ipcg +cat merged.mcg | python3 -m json.tool > mergedFormatted.mcg diff --git a/test/5_Stress/include/combinations.h b/test/5_Stress/include/combinations.h new file mode 100644 index 0000000000000000000000000000000000000000..4d9cab47303a6bddbd907367e33d8a5c65f2a10a --- /dev/null +++ b/test/5_Stress/include/combinations.h @@ -0,0 +1,16 @@ +// +// Created by tim on 16.12.24. +// + +#ifndef CTUAPEX_COMBINATIONS_H +#define CTUAPEX_COMBINATIONS_H + +void useAll(); + +void useAllLater(); + +void useAllViaPtr(); + +void useDefined(); + +#endif //CTUAPEX_COMBINATIONS_H diff --git a/test/5_Stress/include/functionContents.h b/test/5_Stress/include/functionContents.h new file mode 100644 index 0000000000000000000000000000000000000000..2fbf930df292116cc9efbc90586f822b04a028d6 --- /dev/null +++ b/test/5_Stress/include/functionContents.h @@ -0,0 +1,13 @@ +// +// Created by tim on 16.12.24. +// + +#ifndef CTUAPEX_FUNCTIONCONTENTS_H +#define CTUAPEX_FUNCTIONCONTENTS_H +useGeometry(); + +#ifdef Statics +useStatics(); +#endif +usePtrCall(); +#endif //CTUAPEX_FUNCTIONCONTENTS_H diff --git a/test/5_Stress/include/geometry.h b/test/5_Stress/include/geometry.h new file mode 100644 index 0000000000000000000000000000000000000000..f535abe322f895743c71ae61ad3343d98e752cb0 --- /dev/null +++ b/test/5_Stress/include/geometry.h @@ -0,0 +1,94 @@ +// +// Created by tim on 03.12.24. +// + +#ifndef CTUAPEX_GEOMETRY_H +#define CTUAPEX_GEOMETRY_H +#include <iostream> +namespace Geometry { + + // Struct + struct Point { + int x, y; + Point(int x, int y); + }; + + // Base class for Virtual Inheritance + class Shape { + public: + virtual void draw() const; + virtual double area() const = 0; + virtual ~Shape() = default; + }; + + // Virtual Inheritance + class TwoDimensionalShape : public virtual Shape { + public: + virtual double perimeter() const = 0; + }; + + // Derived class from TwoDimensionalShape + class Circle : public TwoDimensionalShape { + private: + Point center; + double radius; + public: + Circle(int x, int y, double r); + + // Overriding virtual functions + void draw() const override; + + double area() const override; + double perimeter() const override; + + // Operator Overloading (for output) + friend std::ostream& operator<<(std::ostream& os, const Circle& c){ + os << "Circle at (" << c.center.x << ", " << c.center.y << "), radius " << c.radius; + return os; + } + + // Constructor Overloading + Circle(double r); + + // Function Overloading + void setRadius(double r); + void setRadius(int r) ; + }; + + // Template Class + template <typename T> + class Box { + private: + T value; + public: + Box(T value) : value(value) {} + T getValue() const { return value; } + }; + + // Template Function + template <typename T> + T add(T a, T b) { + return a + b; + } + + // Static and Non-static Variables + class Counter { + public: + static int staticCount; + int nonStaticCount; + + Counter(); + + void increment(); + + static void reset(); + }; + + + // Function Pointer + typedef void (*DrawFunc)(const Shape&); + + void printShape(const Shape& shape); +} + +#endif //CTUAPEX_GEOMETRY_H diff --git a/test/5_Stress/include/macros.h b/test/5_Stress/include/macros.h new file mode 100644 index 0000000000000000000000000000000000000000..1338afd3959e8d45d7cfdee921813f69d599c9d1 --- /dev/null +++ b/test/5_Stress/include/macros.h @@ -0,0 +1,11 @@ +// +// Created by tim on 03.12.24. +// +// Pragmas +#pragma once +// Macros +#define PI 3.14159 +#define PRINT(msg) std::cout << msg << std::endl; + + + diff --git a/test/5_Stress/include/uses.h b/test/5_Stress/include/uses.h new file mode 100644 index 0000000000000000000000000000000000000000..aee2e71fe20ed9cdfbb090f406b5760a9a4bf504 --- /dev/null +++ b/test/5_Stress/include/uses.h @@ -0,0 +1,22 @@ +// +// Created by tim on 16.12.24. +// + +#ifndef CTUAPEX_USES_H +#define CTUAPEX_USES_H + +void useGlobal(); + +void useShapes(); + +void useGeometry(); + +#ifdef Statics +void useStatics(); +#endif + +void usePtrCall(); + +void useLambdaFunction(); + +#endif //CTUAPEX_USES_H diff --git a/test/5_Stress/main.cpp b/test/5_Stress/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..46ea55c9535dbe735fa38e38e16c7cf148f599d5 --- /dev/null +++ b/test/5_Stress/main.cpp @@ -0,0 +1,16 @@ +#include <iostream> +#include <functional> +#include <vector> +#include <string> + +#include "combinations.h" + + +int main() { + + useAllLater(); + + useDefined(); + + return 0; +} \ No newline at end of file diff --git a/test/5_Stress/src/CMakeLists.txt b/test/5_Stress/src/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9fcd4d997cbecb6755009b80bbb5a60ab33c7fe5 --- /dev/null +++ b/test/5_Stress/src/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(test PRIVATE + geometry.cpp + uses.cpp + combinations.cpp + ) \ No newline at end of file diff --git a/test/5_Stress/src/combinations.cpp b/test/5_Stress/src/combinations.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b3face5d8d6f0ad53549410f71832cb096be27a --- /dev/null +++ b/test/5_Stress/src/combinations.cpp @@ -0,0 +1,41 @@ +// +// Created by tim on 16.12.24. +// + +#include "combinations.h" +#include "uses.h" + +void useAll(){ + useGlobal(); + + useGeometry(); + +#ifdef Statics + useStatics(); +#endif + usePtrCall(); + + useLambdaFunction(); +} + +void useAllLater(){ + auto f= useAllViaPtr; + f(); +} + +void useAllViaPtr(){ + useAll(); +} + +void useDefined(){ +#include "functionContents.h" +} + +cgcollector --metacg-format-version=2 --extra-arg=-I$(clang --print-resource-dir)/include -p build --capture-ctors-dtors --capture-stack-ctors-dtors main.cpp +cgcollector --metacg-format-version=2 --extra-arg=-I$(clang --print-resource-dir)/include -p build --capture-ctors-dtors --capture-stack-ctors-dtors src/uses.cpp +cgcollector --metacg-format-version=2 --extra-arg=-I$(clang --print-resource-dir)/include -p build --capture-ctors-dtors --capture-stack-ctors-dtors src/combinations.cpp +cgcollector --metacg-format-version=2 --extra-arg=-I$(clang --print-resource-dir)/include -p build --capture-ctors-dtors --capture-stack-ctors-dtors src/geometry.cpp + +echo "null" > merged.mcg +cgmerge merged.mcg main.ipcg src/combinations.ipcg src/geometry.ipcg src/uses.ipcg +cat merged.mcg | python3 -m json.tool > mergedFormatted.mcg diff --git a/test/5_Stress/src/geometry.cpp b/test/5_Stress/src/geometry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9456d20cf967442621f381fba610b811ade914b0 --- /dev/null +++ b/test/5_Stress/src/geometry.cpp @@ -0,0 +1,59 @@ +// +// Created by tim on 03.12.24. +// + +#include "geometry.h" +#include "macros.h" + +// Namespace +namespace Geometry { + + + Point::Point(int x, int y) : x(x), y(y) {} + + + // Base class for Virtual Inheritance + void Shape::draw() const { std::cout << "Drawing shape" << std::endl; } + + // Derived class from TwoDimensionalShape + + Circle::Circle(int x, int y, double r) : center(x, y), radius(r) {} + + // Overriding virtual functions + void Circle::draw() const { + std::cout << "Drawing circle at (" << center.x << ", " << center.y << ") with radius " << radius + << std::endl; + } + + double Circle::area() const { return PI * radius * radius; } + + double Circle::perimeter() const { return 2 * PI * radius; } + + + // Constructor Overloading + Circle::Circle(double r) : center(0, 0), radius(r) {} + + // Function Overloading + void Circle::setRadius(double r) { radius = r; } + + void Circle::setRadius(int r) { radius = static_cast<double>(r); } + //} + + // Static and Non-static Variables + + + Counter::Counter() : nonStaticCount(0) {} + + void Counter::increment() { + staticCount++; + nonStaticCount++; + } + + void Counter::reset() { staticCount = 0; } + + int Counter::staticCount = 0; +void printShape(const Shape &shape) { + shape.draw(); +} + +}; diff --git a/test/5_Stress/src/uses.cpp b/test/5_Stress/src/uses.cpp new file mode 100644 index 0000000000000000000000000000000000000000..198fa917b3de2df33e5e160a9be1e6025052350c --- /dev/null +++ b/test/5_Stress/src/uses.cpp @@ -0,0 +1,77 @@ +// +// Created by tim on 16.12.24. +// +#include "uses.h" +#include <iostream> +#include "geometry.h" +#include "macros.h" + +// Global variable +int globalVar = 100; + +//Define macro in main file +//We would need to extract this, but we can rely on the header files to supply other macro definitions +#define MY_ASSERT(BOOL_EXPRESSION) \ + do { \ + _Pragma("warning(suppress: 4127)") /* C4127 conditional expression is constant */ \ + if (!(BOOL_EXPRESSION)) { \ + printf("MY_ASSERT FAILED: \"" #BOOL_EXPRESSION "\" on %s(%d)", __FILE__, __LINE__); \ + exit(-1); \ + } \ + } while (0) + +// Lambda Function +auto multiply = [](int a, int b) { return a * b; }; + + +void useGlobal(){ + + // Global variable usage + std::cout << "Global Variable: " << globalVar << std::endl; +} + +void useShapes(){ + + // Creating a Circle object + Geometry::Circle circle1(10); + circle1.draw(); + std::cout << "Circle Area: " << circle1.area() << ", Perimeter: " << circle1.perimeter() << std::endl; + + // Using Operator Overloading (for Circle) + std::cout << "Circle: " << circle1 << std::endl; + + // Template Class usage + Geometry::Box<int> intBox(42); + std::cout << "Box value: " << intBox.getValue() << std::endl; +} + +void useGeometry(){ + useShapes(); + // Template Function usage + std::cout << "Add(3, 5): " << Geometry::add(3, 5) << std::endl; +} + +#ifdef Statics +void useStatics(){ + // Static and Non-static variables + Geometry::Counter counter; + counter.increment(); + std::cout << "Static count: " << Geometry::Counter::staticCount << ", Non-static count: " << counter.nonStaticCount << std::endl; + +} +#endif + +void usePtrCall(){ + // Using Function Pointer + Geometry::Circle circle1(10); + Geometry::DrawFunc drawFunc = Geometry::printShape; + drawFunc(circle1); // Calling the printShape function via pointer + + MY_ASSERT(true); +} + +void useLambdaFunction(){ + + // Lambda Function + std::cout << "Lambda Multiply: " << multiply(4, 5) << std::endl; +} \ No newline at end of file