From 2eb22a31b7354245a6b92ec0bc50331a9025fd7d Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 29 Feb 2024 22:33:55 +0530 Subject: [PATCH 1/3] DEV: Fix dependency addition for StructType --- src/libasr/pass/pass_utils.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libasr/pass/pass_utils.h b/src/libasr/pass/pass_utils.h index d9b4a10..326e908 100644 --- a/src/libasr/pass/pass_utils.h +++ b/src/libasr/pass/pass_utils.h @@ -440,6 +440,9 @@ namespace LCompilers { if( ASR::is_a(*type) ) { ASR::Struct_t* struct_t = ASR::down_cast(type); vec.push_back(al, ASRUtils::symbol_name(struct_t->m_derived_type)); + } else if( ASR::is_a(*type) ) { + ASR::Enum_t* enum_t = ASR::down_cast(type); + vec.push_back(al, ASRUtils::symbol_name(enum_t->m_enum_type)); } } xx.m_dependencies = vec.p; From 718d077553f74391874acdd5593e65158aa30424 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 29 Feb 2024 22:36:27 +0530 Subject: [PATCH 2/3] TEST: Ported integration_tests/enum_06.py from LPython --- integration_tests/enum_04.cpp | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 integration_tests/enum_04.cpp diff --git a/integration_tests/enum_04.cpp b/integration_tests/enum_04.cpp new file mode 100644 index 0000000..1ff8233 --- /dev/null +++ b/integration_tests/enum_04.cpp @@ -0,0 +1,56 @@ +#include +#include + +enum Color { + RED, + GREEN, + BLUE, + PINK, + WHITE, + YELLOW +}; + +struct Truck_t { + float horsepower; + int32_t seats; + double price; + enum Color color; +}; + +void init_Truck(Truck_t& truck, float horsepower_, int32_t seats_, double price_, enum Color color_) { + truck.horsepower = horsepower_; + truck.seats = seats_; + truck.price = price_; + truck.color = color_; +} + +void print_Truck(const Truck_t& car) { + std::cout << car.horsepower << " " << car.seats << " " << car.price << " " << car.color << std::endl; +} + +void assert_(bool condition) { + if( !condition ) { + exit(2); + } +} + +void test_enum_as_struct_member() { + xt::xtensor_fixed> cars; + init_Truck(cars(0), 700.0, 4, 100000.0, RED); + init_Truck(cars(1), 800.0, 5, 200000.0, BLUE); + init_Truck(cars(2), 400.0, 4, 50000.0, WHITE); + print_Truck(cars(0)); + print_Truck(cars(1)); + print_Truck(cars(2)); + assert_( cars(2).color == WHITE ); + assert_( cars(1).color == BLUE ); + assert_( cars(0).color == RED ); +} + +int main() { + +test_enum_as_struct_member(); + +return 0; + +} From 6fa64e5974bcd9f3684306600e0d03df175490b4 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 29 Feb 2024 22:36:40 +0530 Subject: [PATCH 3/3] TEST: Register enum_04.cpp --- integration_tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 6892ea7..ee610a8 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -226,3 +226,4 @@ RUN(NAME nbody_02.cpp LABELS gcc llvm NOFAST) RUN(NAME enum_01.cpp LABELS gcc llvm NOFAST) RUN(NAME enum_02.cpp LABELS gcc llvm NOFAST) RUN(NAME enum_03.cpp LABELS gcc llvm NOFAST) +RUN(NAME enum_04.cpp LABELS gcc llvm NOFAST)