From c069d3115c33d94cbcbf8bc80ca390f4c77f79bc Mon Sep 17 00:00:00 2001 From: Marko Ristin Date: Sun, 11 Feb 2024 11:39:58 +0100 Subject: [PATCH] Fix c++ stringification of enums We fix all the bugs in the C++ generator so that the tests now pass. --- .../cpp/stringification/_generate.py | 4 +- .../cpp/wstringification/_generate.py | 8 ++-- .../expected_output/stringification.cpp | 24 +++++----- .../expected_output/wstringification.cpp | 48 +++++++++---------- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/aas_core_codegen/cpp/stringification/_generate.py b/aas_core_codegen/cpp/stringification/_generate.py index 169e2de53..209ddd600 100644 --- a/aas_core_codegen/cpp/stringification/_generate.py +++ b/aas_core_codegen/cpp/stringification/_generate.py @@ -145,7 +145,7 @@ def _generate_model_type_from_string_implementation( {I}if (it == {map_name}.end()) {{ {II}throw std::invalid_argument( {III}common::Concat( -{IIII}"Unexpected model type literal: ", +{IIII}"Unexpected {enum_name} literal: ", {IIII}text {III}) {II}); @@ -364,7 +364,7 @@ def _generate_enum_from_string_implementation( {I}if (it == {map_name}.end()) {{ {II}throw std::invalid_argument( {III}common::Concat( -{IIII}"Unexpected model type literal: ", +{IIII}"Unexpected {enum_name} literal: ", {IIII}text {III}) {II}); diff --git a/aas_core_codegen/cpp/wstringification/_generate.py b/aas_core_codegen/cpp/wstringification/_generate.py index 8d94b2c11..bffd30ced 100644 --- a/aas_core_codegen/cpp/wstringification/_generate.py +++ b/aas_core_codegen/cpp/wstringification/_generate.py @@ -146,7 +146,7 @@ def _generate_model_type_from_wstring_implementation( {II}throw std::invalid_argument( {III}common::WstringToUtf8( {IIII}common::Concat( -{IIIII}L"Unexpected model type literal: ", +{IIIII}L"Unexpected {enum_name} literal: ", {IIIII}text {IIII}) {III}) @@ -214,7 +214,7 @@ def _generate_model_type_to_wstring_implementation( default: {I}throw std::invalid_argument( {II}common::Concat( -{III}"Unexpected model type: ", +{III}"Unexpected {enum_name} literal: ", {III}std::to_string( {IIII}static_cast({model_type_arg}) {III}) @@ -365,7 +365,7 @@ def _generate_enum_from_wstring_implementation( {II}throw std::invalid_argument( {III}common::WstringToUtf8( {IIII}common::Concat( -{IIIII}L"Unexpected model type literal: ", +{IIIII}L"Unexpected {enum_name} literal: ", {IIIII}text {IIII}) {III}) @@ -432,7 +432,7 @@ def _generate_enum_to_wstring_implementation( default: {I}throw std::invalid_argument( {II}common::Concat( -{III}"Unexpected literal: ", +{III}"Unexpected {enum_name} literal: ", {III}std::to_string( {IIII}static_cast({literal_arg}) {III}) diff --git a/test_data/cpp/test_main/aas_core_meta.v3/expected_output/stringification.cpp b/test_data/cpp/test_main/aas_core_meta.v3/expected_output/stringification.cpp index 05f5238ee..1545ca006 100644 --- a/test_data/cpp/test_main/aas_core_meta.v3/expected_output/stringification.cpp +++ b/test_data/cpp/test_main/aas_core_meta.v3/expected_output/stringification.cpp @@ -190,7 +190,7 @@ types::ModelType MustModelTypeFromString( if (it == kModelTypeFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected ModelType literal: ", text ) ); @@ -327,7 +327,7 @@ types::ModellingKind MustModellingKindFromString( if (it == kModellingKindFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected ModellingKind literal: ", text ) ); @@ -396,7 +396,7 @@ types::QualifierKind MustQualifierKindFromString( if (it == kQualifierKindFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected QualifierKind literal: ", text ) ); @@ -467,7 +467,7 @@ types::AssetKind MustAssetKindFromString( if (it == kAssetKindFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected AssetKind literal: ", text ) ); @@ -594,7 +594,7 @@ types::AasSubmodelElements MustAasSubmodelElementsFromString( if (it == kAasSubmodelElementsFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected AasSubmodelElements literal: ", text ) ); @@ -689,7 +689,7 @@ types::EntityType MustEntityTypeFromString( if (it == kEntityTypeFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected EntityType literal: ", text ) ); @@ -754,7 +754,7 @@ types::Direction MustDirectionFromString( if (it == kDirectionFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected Direction literal: ", text ) ); @@ -819,7 +819,7 @@ types::StateOfEvent MustStateOfEventFromString( if (it == kStateOfEventFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected StateOfEvent literal: ", text ) ); @@ -884,7 +884,7 @@ types::ReferenceTypes MustReferenceTypesFromString( if (it == kReferenceTypesFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected ReferenceTypes literal: ", text ) ); @@ -1037,7 +1037,7 @@ types::KeyTypes MustKeyTypesFromString( if (it == kKeyTypesFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected KeyTypes literal: ", text ) ); @@ -1258,7 +1258,7 @@ types::DataTypeDefXsd MustDataTypeDefXsdFromString( if (it == kDataTypeDefXsdFromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected DataTypeDefXsd literal: ", text ) ); @@ -1447,7 +1447,7 @@ types::DataTypeIec61360 MustDataTypeIec61360FromString( if (it == kDataTypeIec61360FromStringMap.end()) { throw std::invalid_argument( common::Concat( - "Unexpected model type literal: ", + "Unexpected DataTypeIec61360 literal: ", text ) ); diff --git a/test_data/cpp/test_main/aas_core_meta.v3/expected_output/wstringification.cpp b/test_data/cpp/test_main/aas_core_meta.v3/expected_output/wstringification.cpp index 0c2b6d12e..e704e381f 100644 --- a/test_data/cpp/test_main/aas_core_meta.v3/expected_output/wstringification.cpp +++ b/test_data/cpp/test_main/aas_core_meta.v3/expected_output/wstringification.cpp @@ -191,7 +191,7 @@ types::ModelType MustModelTypeFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected ModelType literal: ", text ) ) @@ -283,7 +283,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected model type: ", + "Unexpected ModelType literal: ", std::to_string( static_cast(model_type) ) @@ -328,7 +328,7 @@ types::ModellingKind MustModellingKindFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected ModellingKind literal: ", text ) ) @@ -348,7 +348,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected ModellingKind literal: ", std::to_string( static_cast(literal) ) @@ -397,7 +397,7 @@ types::QualifierKind MustQualifierKindFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected QualifierKind literal: ", text ) ) @@ -419,7 +419,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected QualifierKind literal: ", std::to_string( static_cast(literal) ) @@ -468,7 +468,7 @@ types::AssetKind MustAssetKindFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected AssetKind literal: ", text ) ) @@ -490,7 +490,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected AssetKind literal: ", std::to_string( static_cast(literal) ) @@ -595,7 +595,7 @@ types::AasSubmodelElements MustAasSubmodelElementsFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected AasSubmodelElements literal: ", text ) ) @@ -645,7 +645,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected AasSubmodelElements literal: ", std::to_string( static_cast(literal) ) @@ -690,7 +690,7 @@ types::EntityType MustEntityTypeFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected EntityType literal: ", text ) ) @@ -710,7 +710,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected EntityType literal: ", std::to_string( static_cast(literal) ) @@ -755,7 +755,7 @@ types::Direction MustDirectionFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected Direction literal: ", text ) ) @@ -775,7 +775,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected Direction literal: ", std::to_string( static_cast(literal) ) @@ -820,7 +820,7 @@ types::StateOfEvent MustStateOfEventFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected StateOfEvent literal: ", text ) ) @@ -840,7 +840,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected StateOfEvent literal: ", std::to_string( static_cast(literal) ) @@ -885,7 +885,7 @@ types::ReferenceTypes MustReferenceTypesFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected ReferenceTypes literal: ", text ) ) @@ -905,7 +905,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected ReferenceTypes literal: ", std::to_string( static_cast(literal) ) @@ -1038,7 +1038,7 @@ types::KeyTypes MustKeyTypesFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected KeyTypes literal: ", text ) ) @@ -1102,7 +1102,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected KeyTypes literal: ", std::to_string( static_cast(literal) ) @@ -1259,7 +1259,7 @@ types::DataTypeDefXsd MustDataTypeDefXsdFromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected DataTypeDefXsd literal: ", text ) ) @@ -1335,7 +1335,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected DataTypeDefXsd literal: ", std::to_string( static_cast(literal) ) @@ -1448,7 +1448,7 @@ types::DataTypeIec61360 MustDataTypeIec61360FromWstring( throw std::invalid_argument( common::WstringToUtf8( common::Concat( - L"Unexpected model type literal: ", + L"Unexpected DataTypeIec61360 literal: ", text ) ) @@ -1502,7 +1502,7 @@ std::wstring to_wstring( default: throw std::invalid_argument( common::Concat( - "Unexpected literal: ", + "Unexpected DataTypeIec61360 literal: ", std::to_string( static_cast(literal) )