From 5dec62e8a79979af3adbc30b496202aebc0ac992 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 16 Aug 2017 23:02:14 +0100 Subject: Initial support for operating on local (classes) --- slicer/slicer/modelPartsTypes.cpp | 6 ++++++ slicer/slicer/modelPartsTypes.h | 6 ++++++ slicer/slicer/modelPartsTypes.impl.h | 16 +++++++++++++++- slicer/test/compilation.cpp | 33 +++++++++++++++++++++++++++++++++ slicer/test/locals.ice | 10 ++++++++++ slicer/test/preprocessor.cpp | 1 + 6 files changed, 71 insertions(+), 1 deletion(-) diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index c1661de..7d6edaf 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -116,6 +116,12 @@ namespace Slicer { return (id == className) ? TypeId() : ModelPart::ToExchangeTypeName(id); } + std::string ModelPartForComplexBase::demangle(const char * mangled) + { + auto buf = std::unique_ptr(abi::__cxa_demangle(mangled, NULL, NULL, NULL), std::free); + return "::" + std::string(buf.get()); + } + void ModelPartForOptionalBase::OnEachChild(const ChildHandler & ch) { if (this->hasModel()) { diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 69c29b3..904a88a 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -2,6 +2,7 @@ #define SLICER_MODELPARTSTYPES_H #include "modelParts.h" +#include namespace Slicer { template @@ -116,6 +117,7 @@ namespace Slicer { static void registerClass(const std::string & className, const std::string * typeName, const ClassRef &); static void unregisterClass(const std::string & className, const std::string * typeName); static TypeId GetTypeId(const std::string & id, const std::string & className); + static std::string demangle(const char * mangled); }; template @@ -182,6 +184,10 @@ namespace Slicer { virtual bool HasValue() const override; virtual TypeId GetTypeId() const override; + template + const std::string & getTypeId(typename std::enable_if::value>::type * = nullptr) const; + template + std::string getTypeId(typename std::enable_if::value>::type * = nullptr) const; virtual IceUtil::Optional GetTypeIdProperty() const override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 3f701c2..1567b63 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -411,7 +411,21 @@ namespace Slicer { ModelPartForClass::GetTypeId() const { BOOST_ASSERT(this->Model); - return ModelPartForComplexBase::GetTypeId((*this->Model)->ice_id(), *className); + return ModelPartForComplexBase::GetTypeId(getTypeId(), *className); + } + + template + template + const std::string & ModelPartForClass::getTypeId(typename std::enable_if::value>::type *) const + { + return (*this->Model)->ice_id(); + } + + template + template + std::string ModelPartForClass::getTypeId(typename std::enable_if::value>::type *) const + { + return ModelPartForComplexBase::demangle(typeid(*this->Model->get()).name()); } // ModelPartForStruct diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp index 0ba6b11..3a0f54e 100644 --- a/slicer/test/compilation.cpp +++ b/slicer/test/compilation.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -172,3 +173,35 @@ BOOST_AUTO_TEST_CASE( normalSubSubClassTypeId ) BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D3"); } +BOOST_AUTO_TEST_CASE( localClassTypeId ) +{ + Locals::LocalClassPtr base = new Locals::LocalClass(1, "One"); + BOOST_REQUIRE(base); + auto a = Slicer::ModelPart::CreateFor(base); + BOOST_REQUIRE(a); + auto baseType = a->GetTypeId(); + BOOST_REQUIRE(!baseType); +} + +BOOST_AUTO_TEST_CASE( localSubClassTypeId ) +{ + Locals::LocalClassPtr base = new Locals::LocalSubClass(1, "One", 3.1); + BOOST_REQUIRE(base); + auto a = Slicer::ModelPart::CreateFor(base); + BOOST_REQUIRE(a); + auto baseType = a->GetTypeId(); + BOOST_REQUIRE(baseType); + BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSubClass"); +} + +BOOST_AUTO_TEST_CASE( localSubSubClassTypeId ) +{ + Locals::LocalClassPtr base = new Locals::LocalSub2Class(1, "One", 3.1, 1); + BOOST_REQUIRE(base); + auto a = Slicer::ModelPart::CreateFor(base); + BOOST_REQUIRE(a); + auto baseType = a->GetTypeId(); + BOOST_REQUIRE(baseType); + BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSub2Class"); +} + diff --git a/slicer/test/locals.ice b/slicer/test/locals.ice index eb914dd..1fbe43a 100644 --- a/slicer/test/locals.ice +++ b/slicer/test/locals.ice @@ -10,6 +10,16 @@ module Locals { local enum E { a, b }; + local class LocalClass { + int a; + string b; + }; + local class LocalSubClass extends LocalClass { + double c; + }; + local class LocalSub2Class extends LocalSubClass { + int d; + }; }; #endif diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index b37b18b..869c2a0 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -19,6 +19,7 @@ ComponentsCount COMPONENTS_IN_TEST_ICE = { { "inheritance.ice", 12 }, { "interfaces.ice", 0 }, { "json.ice", 2 }, + { "locals.ice", 7 }, { "optionals.ice", 1 }, { "structs.ice", 4 }, { "types.ice", 3 }, -- cgit v1.2.3