diff options
author | 2020-08-24 21:58:42 +0900 | |
---|---|---|
committer | 2020-08-24 21:58:42 +0900 | |
commit | 2b4ae7fde370bc3316ab30cc38b74d23e785b360 (patch) | |
tree | 41b6eb70b3419c2fbd192ed133c5890a985eddec /src/core/expression | |
parent | 6694a4d2952ebd171564932200cac00d6e5792f4 (diff) |
First commitjellyfish_9.99.4jellyfish/9.99.49.99.4
Signed-off-by: Kenji Hosokawa <khosokawa@jp.adit-jv.com>
Change-Id: I381abb0a6521f5349768a76ef7ceecbce4b2d701
Diffstat (limited to 'src/core/expression')
191 files changed, 12903 insertions, 0 deletions
diff --git a/src/core/expression/RBAActionOperator.cpp b/src/core/expression/RBAActionOperator.cpp new file mode 100644 index 0000000..7cd38ec --- /dev/null +++ b/src/core/expression/RBAActionOperator.cpp @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Action operator class definition + */ + +#include "RBAActionOperator.hpp" +#include "RBAExpressionType.hpp" + +namespace rba +{ + +#ifdef RBA_USE_LOG +RBAExpressionType +RBAActionOperator::getUnderlyingType() const +{ + return RBAExpressionType::ACTION; +} +#endif + +} diff --git a/src/core/expression/RBAActionOperator.hpp b/src/core/expression/RBAActionOperator.hpp new file mode 100644 index 0000000..677f699 --- /dev/null +++ b/src/core/expression/RBAActionOperator.hpp @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Action operator class + */ + +#ifndef RBAACTIONOPERATOR_HPP +#define RBAACTIONOPERATOR_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAActionOperator : public RBAOperator +{ +protected: + RBAActionOperator()=default; + RBAActionOperator(const RBAActionOperator&)=delete; + RBAActionOperator(const RBAActionOperator&&)=delete; + RBAActionOperator& operator=(const RBAActionOperator&)=delete; + RBAActionOperator& operator=(const RBAActionOperator&&)=delete; + +public: + // Log +#ifdef RBA_USE_LOG + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAActiveContents.cpp b/src/core/expression/RBAActiveContents.cpp new file mode 100644 index 0000000..b5d88a7 --- /dev/null +++ b/src/core/expression/RBAActiveContents.cpp @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Select operator class definition + */ + +#include <memory> +#include "RBAActiveContents.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAArbitrator.hpp" +#include "RBAAllocatable.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +RBAActiveContents::RBAActiveContents() +: RBAAllocatableOperator(), + contentSet_{std::make_unique<RBAContentSet>()} +{ +} + +void +RBAActiveContents::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAActiveContents::getModelElementType() const +{ + return RBAModelElementType::ActiveContents; +} + +const RBARuleObject* +RBAActiveContents::getReferenceObjectCore(RBAConstraintInfo* info, RBAArbitrator* arb) const +{ + LOG_addHierarchy(LOG_getSymbol()); + const RBARuleObject* returnObj {nullptr}; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const lhsObj {getLhsOperand()->getReferenceObject(leftInfo, arb)}; + + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } + else if (lhsObj != nullptr) { + contentSet_->clear(); + const RBAAllocatable* const alloc {dynamic_cast<const RBAAllocatable*>(lhsObj->getRawObject())}; +#ifdef RBA_USE_LOG + if (arb == nullptr) { + // Follow this path when called from createHierarchy() + returnObj = alloc->getContentSet(); + } else { +#endif + for (auto& content : alloc->getInternalContents()) { + if (alloc->isPrevious()) { + if (arb->getResult()->isPreActive(content)) { + contentSet_->addTarget(content); + } + } else { + if (arb->getResult()->isActive(content)) { + contentSet_->addTarget(content); + } + } + } + returnObj = contentSet_.get(); +#ifdef RBA_USE_LOG + } +#endif + } else { + ; + } +#ifdef RBA_USE_LOG + std::string objName = "NULL"; + if (returnObj != nullptr) { + objName = returnObj->getElementName(); + } + LOG_arbitrateConstraintLogicLogLine( + " " + LOG_getExpressionText() + " is " + objName); +#endif + LOG_removeHierarchy(); + return returnObj; +} +#ifdef RBA_USE_LOG +const std::string +RBAActiveContents::getSymbol() const +{ + return ".activeContents()"; +} +#endif + +} diff --git a/src/core/expression/RBAActiveContents.hpp b/src/core/expression/RBAActiveContents.hpp new file mode 100644 index 0000000..3ee9f7d --- /dev/null +++ b/src/core/expression/RBAActiveContents.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ActiveContents operator + */ + +#ifndef RBAACTIVECONTENTS_HPP +#define RBAACTIVECONTENTS_HPP + +#include "RBAAllocatableOperator.hpp" +#include "RBAContentSet.hpp" + +namespace rba +{ + +class RBAActiveContents : public RBAAllocatableOperator +{ + public: + RBAActiveContents(); + RBAActiveContents(const RBAActiveContents&)=delete; + RBAActiveContents(const RBAActiveContents&&)=delete; + RBAActiveContents& operator=(const RBAActiveContents&)=delete; + RBAActiveContents& operator=(const RBAActiveContents&&)=delete; + virtual ~RBAActiveContents()=default; + + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; +#endif + private: + std::unique_ptr<RBAContentSet> contentSet_; +}; + +} + +#endif diff --git a/src/core/expression/RBAActiveContentsMaker.cpp b/src/core/expression/RBAActiveContentsMaker.cpp new file mode 100644 index 0000000..f883fee --- /dev/null +++ b/src/core/expression/RBAActiveContentsMaker.cpp @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAActiveContentsMaker.cpp +/// @brief ActiveContents object creation class defintion +/// + +#include "RBAActiveContentsMaker.hpp" +#include "RBAActiveContents.hpp" + +namespace rba +{ + +RBAActiveContentsMaker::RBAActiveContentsMaker() + : RBAOperatorMaker{"ActiveContents"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAActiveContentsMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAActiveContents>(); +} + +} diff --git a/src/core/expression/RBAActiveContentsMaker.hpp b/src/core/expression/RBAActiveContentsMaker.hpp new file mode 100644 index 0000000..493e569 --- /dev/null +++ b/src/core/expression/RBAActiveContentsMaker.hpp @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAActiveContentsMaker.hpp +/// @brief ActiveContents object creation class header +/// + +#ifndef RBAACTIVECONTENTSMAKER_HPP +#define RBAACTIVECONTENTSMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief ActiveContents object creation class +class RBAActiveContentsMaker : public RBAOperatorMaker +{ +public: + RBAActiveContentsMaker(); + RBAActiveContentsMaker(const RBAActiveContentsMaker&)=delete; + RBAActiveContentsMaker(const RBAActiveContentsMaker&&)=delete; + RBAActiveContentsMaker& operator=(const RBAActiveContentsMaker&)=delete; + RBAActiveContentsMaker& operator=(const RBAActiveContentsMaker&&)=delete; + virtual ~RBAActiveContentsMaker()=default; + +public: + /// @brief Empty instanciation + /// @details Create an empty instance of unique_ptr in a derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAActiveState.cpp b/src/core/expression/RBAActiveState.cpp new file mode 100644 index 0000000..1e0f6b3 --- /dev/null +++ b/src/core/expression/RBAActiveState.cpp @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * activeState definition + */ + +#include "RBAActiveState.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBAModelElementType.hpp" +#include "RBAContent.hpp" +#include "RBAContentState.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAArbitrator.hpp" +#include "RBALogManager.hpp" + +namespace rba +{ + +void RBAActiveState::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} +RBAModelElementType RBAActiveState::getModelElementType() const +{ + return RBAModelElementType::ActiveState; +} +const RBARuleObject* RBAActiveState::getReferenceObjectCore( + RBAConstraintInfo* info, RBAArbitrator* arb) const +{ + LOG_addHierarchy(LOG_getSymbol()); + const RBARuleObject* returnObj {nullptr}; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const ruleObj {getLhsOperand()->getReferenceObject(leftInfo, + arb)}; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else if (ruleObj != nullptr) { + const RBAContent* const c { + dynamic_cast<const RBAContent*>(ruleObj->getRawObject())}; + if (ruleObj->isPrevious()) { + returnObj = arb->getResult()->getPreActiveState(c); + } else { + returnObj = arb->getResult()->getActiveState(c); + } + } else { + ; + } +#ifdef RBA_USE_LOG + std::string str; + if (info->isExceptionBeforeArbitrate()) { + str = " is before arbitrate skip"; + } else if (ruleObj == nullptr) { + str = " no Content"; + } else if (returnObj == nullptr) { + str = " has no Active State"; + } else { + str = " is " + returnObj->getElementName(); + } + LOG_arbitrateConstraintLogicLogLine(" " + getExpressionText() + str); +#endif + LOG_removeHierarchy(); + return returnObj; +} +#ifdef RBA_USE_LOG +const std::string RBAActiveState::getSymbol() const +{ + return ".activeState()"; +} +#endif +} /* namespace rba */ diff --git a/src/core/expression/RBAActiveState.hpp b/src/core/expression/RBAActiveState.hpp new file mode 100644 index 0000000..3876c78 --- /dev/null +++ b/src/core/expression/RBAActiveState.hpp @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// activeState header +// + +#ifndef RBAACTIVESTATE_HPP +#define RBAACTIVESTATE_HPP + +#include "RBAContentOperator.hpp" + +namespace rba +{ + +class RBAActiveState : public RBAContentOperator +{ + public: + RBAActiveState()=default; + RBAActiveState(const RBAActiveState&)=delete; + RBAActiveState(const RBAActiveState&&)=delete; + RBAActiveState& operator=(const RBAActiveState&)=delete; + RBAActiveState& operator=(const RBAActiveState&&)=delete; + virtual ~RBAActiveState()=default; + + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; +#endif +}; + +} /* namespace rba */ + +#endif /* RBAACTIVESTATE_HPP */ diff --git a/src/core/expression/RBAActiveStateMaker.cpp b/src/core/expression/RBAActiveStateMaker.cpp new file mode 100644 index 0000000..16d8f4c --- /dev/null +++ b/src/core/expression/RBAActiveStateMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAActiveStateMaker.cpp +/// @brief ActiveState objeckt maker class definition + +#include "RBAActiveStateMaker.hpp" +#include "RBAActiveState.hpp" + +namespace rba +{ + +RBAActiveStateMaker::RBAActiveStateMaker() + : RBAOperatorMaker{"ActiveState"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAActiveStateMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAActiveState>(); +} + +} diff --git a/src/core/expression/RBAActiveStateMaker.hpp b/src/core/expression/RBAActiveStateMaker.hpp new file mode 100644 index 0000000..7d42cbe --- /dev/null +++ b/src/core/expression/RBAActiveStateMaker.hpp @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAActiveStateMaker.hpp +/// @brief ActiveState object maker class header +/// + +#ifndef RBAACTIVESTATEMAKER_HPP +#define RBAACTIVESTATEMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief ActiveState object maker class +class RBAActiveStateMaker : public RBAOperatorMaker +{ +public: + RBAActiveStateMaker(); + RBAActiveStateMaker(const RBAActiveStateMaker&)=delete; + RBAActiveStateMaker(const RBAActiveStateMaker&&)=delete; + RBAActiveStateMaker& operator=(const RBAActiveStateMaker&)=delete; + RBAActiveStateMaker& operator=(const RBAActiveStateMaker&&)=delete; + virtual ~RBAActiveStateMaker()=default; + +protected: + /// @brief Empty instanciation + /// @details Create an empty instance of unique_ptr in a derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAAllocatableOperator.cpp b/src/core/expression/RBAAllocatableOperator.cpp new file mode 100644 index 0000000..15a9104 --- /dev/null +++ b/src/core/expression/RBAAllocatableOperator.cpp @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Allcatable operator class definitio + */ + +#include "RBAAllocatableOperator.hpp" + +namespace rba +{ + +#ifdef RBA_USE_LOG +const std::string +RBAAllocatableOperator::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol(); +} + +const std::string +RBAAllocatableOperator::getCoverageExpressionText() const +{ + return getLhsOperand()->getCoverageExpressionText() + getSymbol(); +} +#endif + +} diff --git a/src/core/expression/RBAAllocatableOperator.hpp b/src/core/expression/RBAAllocatableOperator.hpp new file mode 100644 index 0000000..7a4f40a --- /dev/null +++ b/src/core/expression/RBAAllocatableOperator.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Allocatable operator class header + */ + +#ifndef RBAALLOCATABLEOPERATOR_HPP +#define RBAALLOCATABLEOPERATOR_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAAllocatableOperator : public RBAOperator +{ +protected: + RBAAllocatableOperator()=default; + RBAAllocatableOperator(const RBAAllocatableOperator&)=delete; + RBAAllocatableOperator(const RBAAllocatableOperator&&)=delete; + RBAAllocatableOperator& operator=(const RBAAllocatableOperator&)=delete; + RBAAllocatableOperator& operator=(const RBAAllocatableOperator&&)=delete; + +public: + virtual ~RBAAllocatableOperator()=default; + // Log +#ifdef RBA_USE_LOG + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAAllocatedContent.cpp b/src/core/expression/RBAAllocatedContent.cpp new file mode 100644 index 0000000..923717d --- /dev/null +++ b/src/core/expression/RBAAllocatedContent.cpp @@ -0,0 +1,118 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Allocated Content class + */ + +#include "RBAAllocatedContent.hpp" + +#include "RBAAllocatable.hpp" +#include "RBAArbitrator.hpp" +#include "RBAContentState.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void RBAAllocatedContent::accept(RBAExpressionVisitor& visitor) +{ + // RBASceneAllocatableCollector which is the only visitor at the moment + // does not accept this content, so it will not pass this path. + // + // However, in the future, another visitor may accept it, so leave this. + visitor.visit(*this); +} + +RBAModelElementType +RBAAllocatedContent::getModelElementType() const +{ + return RBAModelElementType::AllocatedContent; +} + +const RBARuleObject* +RBAAllocatedContent::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + const RBARuleObject* object {nullptr}; // return value + const auto leftInfo = info->getChild(0U); + const auto ruleObj = getLhsOperand()->getReferenceObject(leftInfo, arb); + if (ruleObj != nullptr) { + if (!leftInfo->isExceptionBeforeArbitrate()) { + const RBAAllocatable* const alloc {dynamic_cast<const RBAAllocatable*>(ruleObj->getRawObject())}; + if (ruleObj->isPrevious() == true) { + const auto contentState = arb->getResult()->getDirectPreContentState(alloc); + if(contentState != nullptr) { + object = contentState->getOwner(); + } + } else if (alloc->isChecked()) { + const auto contentState = alloc->getState(); + if (contentState != nullptr) { + object = contentState->getOwner(); + } + // At this point, it is unsure whether the constraint expression will be False or True, + // so put it in both. + info->addTrueAllocatable(alloc); + info->addFalseAllocatable(alloc); + } else { + info->setExceptionBeforeArbitrate(true); + } + } else { + info->setExceptionBeforeArbitrate(true); + } + } +#ifdef RBA_USE_LOG + bool pre = false; + std::string str; + if (ruleObj == nullptr) { + // Currently there is no constraint expression that returns an area. + // Therefore, ruleObj never becomes NULL. + // In the future, a constraint expression that returns an area + // may be created, so leave this processing. + str = "Allocatable[NULL] has no Content skip"; + } else { + pre = ruleObj->isPrevious(); + if (info->isExceptionBeforeArbitrate()) { + str = "Allocatable[" + ruleObj->getElementName() + "] is before arbitrate skip"; + } else if (object == nullptr) { + str = "Allocatable[" + ruleObj->getElementName() + "] has no Allocated Content"; + } else { + str = "Allocatable[" + ruleObj->getElementName() + "] has Allocated Content[" + + object->getElementName() + "]"; + } + } + LOG_arbitrateConstraintLogicLogLine(" " + getPreMsg(pre) + str); +#endif + return object; +} + +#ifdef RBA_USE_LOG +const std::string +RBAAllocatedContent::getSymbol() const +{ + return ".allocatedContent()"; +} + +void +RBAAllocatedContent::createHierarchy() +{ + getLhsOperand()->createHierarchy(); +} +#endif + +} diff --git a/src/core/expression/RBAAllocatedContent.hpp b/src/core/expression/RBAAllocatedContent.hpp new file mode 100644 index 0000000..6fb44e2 --- /dev/null +++ b/src/core/expression/RBAAllocatedContent.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Allocated Content class + */ + +#ifndef RBAALLOCATEDCONTENT_HPP +#define RBAALLOCATEDCONTENT_HPP + +#include "RBAAllocatableOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAAllocatedContent : public RBAAllocatableOperator +{ + public: + RBAAllocatedContent()=default; + RBAAllocatedContent(const RBAAllocatedContent&)=delete; + RBAAllocatedContent(const RBAAllocatedContent&&)=delete; + RBAAllocatedContent& operator=(const RBAAllocatedContent&)=delete; + RBAAllocatedContent& operator=(const RBAAllocatedContent&&)=delete; + virtual ~RBAAllocatedContent()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + void createHierarchy() override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAAllocatedContentMaker.cpp b/src/core/expression/RBAAllocatedContentMaker.cpp new file mode 100644 index 0000000..36d3ad7 --- /dev/null +++ b/src/core/expression/RBAAllocatedContentMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAAllocatedContentMaker.cpp +/// @brief AllocatedContent object maker class + +#include "RBAAllocatedContentMaker.hpp" +#include "RBAAllocatedContent.hpp" + +namespace rba +{ + +RBAAllocatedContentMaker::RBAAllocatedContentMaker() + : RBAOperatorMaker{"AllocatedContent"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAAllocatedContentMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAAllocatedContent>(); +} + +} diff --git a/src/core/expression/RBAAllocatedContentMaker.hpp b/src/core/expression/RBAAllocatedContentMaker.hpp new file mode 100644 index 0000000..10f83b9 --- /dev/null +++ b/src/core/expression/RBAAllocatedContentMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAAllocatedContentMaker.hpp +/// @brief AllocatedContent object maker class header file + +#ifndef RBAALLOCATEDCONTENTMAKER_HPP +#define RBAALLOCATEDCONTENTMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief AllocatedContent object maker class +class RBAAllocatedContentMaker : public RBAOperatorMaker +{ +public: + RBAAllocatedContentMaker(); + RBAAllocatedContentMaker(const RBAAllocatedContentMaker&)=delete; + RBAAllocatedContentMaker(const RBAAllocatedContentMaker&&)=delete; + RBAAllocatedContentMaker& operator=(const RBAAllocatedContentMaker&)=delete; + RBAAllocatedContentMaker& operator=(const RBAAllocatedContentMaker&&)=delete; + virtual ~RBAAllocatedContentMaker()=default; + +protected: + /// @brief Empty instanciation + /// @details Create an empty instance of unique_ptr in a derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAAndOperator.cpp b/src/core/expression/RBAAndOperator.cpp new file mode 100644 index 0000000..0f3a30d --- /dev/null +++ b/src/core/expression/RBAAndOperator.cpp @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * AND operator class definition + */ + +#include "RBAAndOperator.hpp" + +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +void +RBAAndOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAAndOperator::getModelElementType() const +{ + return RBAModelElementType::AndOperator; +} + +bool +RBAAndOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator * arb) const +{ + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + + std::uint32_t falseCount {0U}; + std::uint32_t exceptionCount {0U}; + std::uint32_t index {0U}; + for(const auto& ope : getOperand()) { + // Add count to constraint hierarchy for coverage + LOG_addHierarchy("#" + std::to_string(index)); + + RBAConstraintInfo* const childInfo {info->getChild(index)}; + const bool res {ope->execute(childInfo, arb)}; + if(childInfo->isExceptionBeforeArbitrate()) { + exceptionCount++; + } else if(!res) { + falseCount++; + } else { + ; + } + + // Remove count to constraint hierarchy for coverage + LOG_removeHierarchy(); + index++; + } + + // with fail + if (falseCount > 0U) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + // Rmove count to constraint hierarchy for coverage + LOG_removeHierarchy(); + return false; + } + + // exception + if (exceptionCount > 0U) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + // Rmove count to constraint hierarchy for coverage + LOG_removeHierarchy(); + info->setExceptionBeforeArbitrate(true); + return false; + } + + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + // Rmove count to constraint hierarchy for coverage + LOG_removeHierarchy(); + + return true; +} + +#ifdef RBA_USE_LOG +const std::string +RBAAndOperator::getSymbol() const +{ + return "AND"; +} +#endif + +} diff --git a/src/core/expression/RBAAndOperator.hpp b/src/core/expression/RBAAndOperator.hpp new file mode 100644 index 0000000..229c69f --- /dev/null +++ b/src/core/expression/RBAAndOperator.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * AND operator class header fiel + */ + +#ifndef RBAANDOPERATOR_HPP +#define RBAANDOPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAAndOperator : public RBALogicalOperator +{ + public: + RBAAndOperator()=default; + RBAAndOperator(const RBAAndOperator&)=delete; + RBAAndOperator(const RBAAndOperator&&)=delete; + RBAAndOperator& operator=(const RBAAndOperator&)=delete; + RBAAndOperator& operator=(const RBAAndOperator&&)=delete; + virtual ~RBAAndOperator()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAAndOperatorMaker.cpp b/src/core/expression/RBAAndOperatorMaker.cpp new file mode 100644 index 0000000..1606e6b --- /dev/null +++ b/src/core/expression/RBAAndOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAAndOperatorMaker.cpp +/// @brief AndOperator object maker class defintion file + +#include "RBAAndOperatorMaker.hpp" +#include "RBAAndOperator.hpp" + +namespace rba +{ + +RBAAndOperatorMaker::RBAAndOperatorMaker() + : RBAOperatorMaker{"AndOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAAndOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAAndOperator>(); +} + +} diff --git a/src/core/expression/RBAAndOperatorMaker.hpp b/src/core/expression/RBAAndOperatorMaker.hpp new file mode 100644 index 0000000..6198440 --- /dev/null +++ b/src/core/expression/RBAAndOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAAndOperatorMaker.hpp +/// @brief AndOperator object maker classs header file + +#ifndef RBAANDOPERATORMAKER_HPP +#define RBAANDOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief AndOperator object maker classs +class RBAAndOperatorMaker : public RBAOperatorMaker +{ +public: + RBAAndOperatorMaker(); + RBAAndOperatorMaker(const RBAAndOperatorMaker&)=delete; + RBAAndOperatorMaker(const RBAAndOperatorMaker&&)=delete; + RBAAndOperatorMaker& operator=(const RBAAndOperatorMaker&)=delete; + RBAAndOperatorMaker& operator=(const RBAAndOperatorMaker&&)=delete; + virtual ~RBAAndOperatorMaker()=default; + +protected: + /// @brief Empty instanciation + /// @details Create an empty instance of unique_ptr in a derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAArithmeticOperator.cpp b/src/core/expression/RBAArithmeticOperator.cpp new file mode 100644 index 0000000..2bf25de --- /dev/null +++ b/src/core/expression/RBAArithmeticOperator.cpp @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ArithmeticOperator class definition + */ + +#include "RBAArithmeticOperator.hpp" + +namespace rba +{ + +} diff --git a/src/core/expression/RBAArithmeticOperator.hpp b/src/core/expression/RBAArithmeticOperator.hpp new file mode 100644 index 0000000..5113a84 --- /dev/null +++ b/src/core/expression/RBAArithmeticOperator.hpp @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ArithmeticOperator class header file + */ + +#ifndef RBAARITHMETICOPERATOR_HPP +#define RBAARITHMETICOPERATOR_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAArithmeticOperator : public RBAOperator +{ +protected: + RBAArithmeticOperator()=default; + RBAArithmeticOperator(const RBAArithmeticOperator&)=delete; + RBAArithmeticOperator(const RBAArithmeticOperator&&)=delete; + RBAArithmeticOperator& operator=(const RBAArithmeticOperator&)=delete; + RBAArithmeticOperator& operator=(const RBAArithmeticOperator&&)=delete; + +}; + +} + +#endif diff --git a/src/core/expression/RBAContentOperator.cpp b/src/core/expression/RBAContentOperator.cpp new file mode 100644 index 0000000..6f7083b --- /dev/null +++ b/src/core/expression/RBAContentOperator.cpp @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ContentOperator class definition + */ + +#include "RBAContentOperator.hpp" + +namespace rba +{ + +#ifdef RBA_USE_LOG +const std::string +RBAContentOperator::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol(); +} + +const std::string +RBAContentOperator::getCoverageExpressionText() const +{ + return getLhsOperand()->getCoverageExpressionText() + getSymbol(); +} +#endif + +} diff --git a/src/core/expression/RBAContentOperator.hpp b/src/core/expression/RBAContentOperator.hpp new file mode 100644 index 0000000..fef5ec3 --- /dev/null +++ b/src/core/expression/RBAContentOperator.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ContentOperator class + */ + +#ifndef RBACONTENTOPERATOR_HPP +#define RBACONTENTOPERATOR_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAContentOperator : public RBAOperator +{ +protected: + RBAContentOperator()=default; + RBAContentOperator(const RBAContentOperator&)=delete; + RBAContentOperator(const RBAContentOperator&&)=delete; + RBAContentOperator& operator=(const RBAContentOperator&)=delete; + RBAContentOperator& operator=(const RBAContentOperator&&)=delete; + +public: + // Log +#ifdef RBA_USE_LOG + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAContentValue.cpp b/src/core/expression/RBAContentValue.cpp new file mode 100644 index 0000000..23b1b20 --- /dev/null +++ b/src/core/expression/RBAContentValue.cpp @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * ContentValue class definition + */ + +#include <string> +#include "RBAContentValue.hpp" +#include "RBAAllocatable.hpp" +#include "RBAContentState.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void RBAContentValue::accept(RBAExpressionVisitor& visitor) +{ + // RBA SceneAllocatableCollector which is only existing vistor at this time + // does not accept the value of the content state. + // So this code doesn't work. + // + // But, leave this because another visitor may accept it in the future. + visitor.visit(*this); +} + +RBAModelElementType +RBAContentValue::getModelElementType() const +{ + return RBAModelElementType::ContentValue; +} + +std::int32_t +RBAContentValue::getValueCore(RBAConstraintInfo* info, RBAArbitrator* arb) const +{ + std::int32_t result { -99 }; + const auto leftInfo = info->getChild(0U); + const auto r = getLhsOperand()->getReferenceObject(leftInfo, arb); + const RBAContentState* cs { nullptr }; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else { + if (r != nullptr) { + const auto a = dynamic_cast<const RBAAllocatable*>(r->getRawObject()); + if (a != nullptr) { + if (r->isPrevious()) { + cs = arb->getResult()->getDirectPreContentState(a); + if (cs != nullptr) { + result = cs->getContentStatePriority(); + } + } else { + info->addOperandAllocatable(a); + if (a->isChecked()) { + cs = a->getState(); + if (cs != nullptr) { + result = cs->getContentStatePriority(); + } + } else { + // Throw an Exception if arbitration is not over + info->setExceptionBeforeArbitrate(true); + } + } + } + } + } +#ifdef RBA_USE_LOG + std::string pre; + std::string aName = "NULL"; + std::string resultText = "no Content skip"; + if (r != nullptr) { + aName = r->getElementName(); + pre = getPreMsg(r->isPrevious()); + } + if (info->isExceptionBeforeArbitrate()) { + resultText = "before arbitrate skip"; + } else { + if (cs != nullptr) { + resultText = cs->getOwner()->getElementName() + "::" + cs->getElementName() + " : " + cs->getPriorityString(); + } + } + LOG_arbitrateConstraintLogicLogLine( + " " + + pre + + "Allocatable[" + + aName + + "] has Content Priority [" + + resultText + + "]"); + #endif + return result; +} +#ifdef RBA_USE_LOG +const std::string +RBAContentValue::getSymbol() const +{ + return ".contentValue()"; +} +#endif +} diff --git a/src/core/expression/RBAContentValue.hpp b/src/core/expression/RBAContentValue.hpp new file mode 100644 index 0000000..52bd841 --- /dev/null +++ b/src/core/expression/RBAContentValue.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * ContentValue class header file + */ + +#ifndef RBACONTENTVALUE_HPP +#define RBACONTENTVALUE_HPP + +#include <cstdint> +#include "RBAAllocatableOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAContentValue : public RBAAllocatableOperator +{ +public: + RBAContentValue()=default; + RBAContentValue(const RBAContentValue&)=delete; + RBAContentValue(RBAContentValue&&)=delete; + RBAContentValue& operator=(const RBAContentValue&)=delete; + RBAContentValue& operator=(RBAContentValue&&)=delete; + virtual ~RBAContentValue()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + std::int32_t getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAContentValueMaker.cpp b/src/core/expression/RBAContentValueMaker.cpp new file mode 100644 index 0000000..48aaaeb --- /dev/null +++ b/src/core/expression/RBAContentValueMaker.cpp @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAContentValueMaker.cpp +/// @brief ContentValue object maker classs definition + +#include "RBAContentValueMaker.hpp" +#include "RBAContentValue.hpp" + +namespace rba +{ + +RBAContentValueMaker::RBAContentValueMaker() + : RBAOperatorMaker{"ContentValue"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAContentValueMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAContentValue>(); +} + + +} diff --git a/src/core/expression/RBAContentValueMaker.hpp b/src/core/expression/RBAContentValueMaker.hpp new file mode 100644 index 0000000..8f14c95 --- /dev/null +++ b/src/core/expression/RBAContentValueMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAContentValueMaker.hpp +/// @brief ContentValue object maker calss header file + +#ifndef RBACONTENTVALUEMAKER_HPP +#define RBACONTENTVALUEMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief ContentValue object generation class +class RBAContentValueMaker : public RBAOperatorMaker +{ +public: + RBAContentValueMaker(); + RBAContentValueMaker(const RBAContentValueMaker&)=delete; + RBAContentValueMaker(const RBAContentValueMaker&&)=delete; + RBAContentValueMaker& operator=(const RBAContentValueMaker&)=delete; + RBAContentValueMaker& operator=(const RBAContentValueMaker&&)=delete; + virtual ~RBAContentValueMaker()=default; + +protected: + /// @brief Create empty instance + /// @details Create an empty instance of unique_ptr in a derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAExecuteResult.hpp b/src/core/expression/RBAExecuteResult.hpp new file mode 100644 index 0000000..1eaf2a5 --- /dev/null +++ b/src/core/expression/RBAExecuteResult.hpp @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A type that withdraws requests when arbitration loses + */ + +#ifndef RBAEXECUTERESULT_HPP +#define RBAEXECUTERESULT_HPP + +namespace rba +{ + +enum class RBAExecuteResult : std::uint8_t +{ + TRUE, + FALSE, + EXE, // In case of action is performed by doAction() + // (Excludes SetOfAction and IfAction) + NOTEXE, // In case of action is NOT performed by doAction() + // (Excludes SetOfAction and IfAction) + SKIP // In case of getValue() or getReferenceObject() +}; + +} + +#endif diff --git a/src/core/expression/RBAExistsOperator.cpp b/src/core/expression/RBAExistsOperator.cpp new file mode 100644 index 0000000..8bb8f05 --- /dev/null +++ b/src/core/expression/RBAExistsOperator.cpp @@ -0,0 +1,175 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Exists operator Class definition + */ + +#include "RBAExistsOperator.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAAllocatable.hpp" +#include "RBAContentSet.hpp" +#include "RBAContent.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALambdaExpression.hpp" +#include "RBALogManager.hpp" +#include "RBAExpressionType.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAExistsOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAExistsOperator::getModelElementType() const +{ + return RBAModelElementType::ExistsOperator; +} + +bool +RBAExistsOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator * arb) const +{ + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + + const RBAExpression* const setObj {getLhsOperand()}; + RBALambdaExpression* const lambda {getLambda()}; + + // Get rule object and loop + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + + std::vector<const RBARuleObject*> objs; + + const RBARuleObject* const ruleObj {setObj->getReferenceObject(leftInfo, arb)}; + const RBARuleObject* objset {nullptr}; + if (ruleObj != nullptr) { + objset = ruleObj->getRawObject(); + } + + if (leftInfo->isExceptionBeforeArbitrate() || (objset == nullptr)) { + // Remove itself form the constraint hierarchy for coverage + LOG_removeHierarchy(); + + info->setExceptionBeforeArbitrate(true); + return false; + } + + if (dynamic_cast<const RBAAllocatableSet*>(objset) != nullptr) { + objs.clear(); + for(const RBAAllocatable* alloc + : dynamic_cast<const RBAAllocatableSet*>(objset)->getLeafAllocatable() ) { + objs.push_back(alloc); + } + } + else { + objs.clear(); + for(const auto& cont : dynamic_cast<const RBAContentSet*>(objset)->getLeafContent() ){ + objs.push_back(cont); + } + } + + bool isTrue {false}; + std::uint32_t i {0U}; + for(const RBARuleObject* const obj : objs) { + // Add count to the constraint hierarchy for coverage + LOG_addHierarchy("#" + std::to_string(i)); + + RBAConstraintInfo* const childInfo {info->getChild(i)}; + lambda->setRuleObj(obj); + + const bool res {lambda->execute(childInfo, arb)}; + + // Remove count from the constraint hierarchy for coverage + LOG_removeHierarchy(); + + if(childInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else { + isTrue = (isTrue || res); + } + i++; + } + + if (isTrue == true) { + // Succeed + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); + info->setExceptionBeforeArbitrate(false); + return true; + } else if (info->isExceptionBeforeArbitrate()) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); + return false; + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); + return false; + } +} + +#ifdef RBA_USE_LOG +const std::string +RBAExistsOperator::getSymbol() const +{ + return "Exists"; +} + +const std::string +RBAExistsOperator::getExpressionText() const +{ + RBAExpression* exprLhs = getLhsOperand(); + return getSymbol() + " " + + exprLhs->getExpressionText() + " " + + getLambda()->getExpressionText(); +} + +const std::string +RBAExistsOperator::getCoverageExpressionText() const +{ + getLambda()->clearRuleObj(); + RBAExpression* exprLhs = getLhsOperand(); + return getSymbol() + " " + + exprLhs->getCoverageExpressionText() + " " + + getLambda()->getCoverageExpressionText(); +} + +RBAExpressionType +RBAExistsOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAExistsOperator.hpp b/src/core/expression/RBAExistsOperator.hpp new file mode 100644 index 0000000..e75af32 --- /dev/null +++ b/src/core/expression/RBAExistsOperator.hpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Exists operator Class header file + */ + +#ifndef RBAEXISTSOPERATOR_HPP +#define RBAEXISTSOPERATOR_HPP + +#include "RBALambdaContext.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAExistsOperator : public RBALambdaContext +{ +public: + RBAExistsOperator()=default; + RBAExistsOperator(const RBAExistsOperator&)=delete; + RBAExistsOperator(const RBAExistsOperator&&)=delete; + RBAExistsOperator& operator=(const RBAExistsOperator&)=delete; + RBAExistsOperator& operator=(const RBAExistsOperator&&)=delete; + virtual ~RBAExistsOperator()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAExistsOperatorMaker.cpp b/src/core/expression/RBAExistsOperatorMaker.cpp new file mode 100644 index 0000000..eb8250a --- /dev/null +++ b/src/core/expression/RBAExistsOperatorMaker.cpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAExistsOperatorMaker.cpp +/// @brief Exists Operator object maker Class definition + +#include "RBAExistsOperatorMaker.hpp" +#include "RBAExistsOperator.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelFactory.hpp" +#include "RBALambdaExpression.hpp" + +namespace rba +{ + +RBAExistsOperatorMaker::RBAExistsOperatorMaker() + : RBALambdaContextMaker{"ExistsOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAExistsOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAExistsOperator>(); +} + +RBAModelElement* +RBAExistsOperatorMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>( + RBALambdaContextMaker::setProperty(element, jsonElem, model, owner)); + + return element; +} + +std::unique_ptr<RBALambdaContext> +RBAExistsOperatorMaker::createLambdaContext() +{ + return std::make_unique<RBAExistsOperator>(); +} + +} diff --git a/src/core/expression/RBAExistsOperatorMaker.hpp b/src/core/expression/RBAExistsOperatorMaker.hpp new file mode 100644 index 0000000..c88f610 --- /dev/null +++ b/src/core/expression/RBAExistsOperatorMaker.hpp @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAExistsOperatorMaker.hpp +/// @brief ExistsOperator object maker Class header + +#ifndef RBAEXISTSOPERATORMAKER_HPP +#define RBAEXISTSOPERATORMAKER_HPP + +#include "RBALambdaContextMaker.hpp" + +namespace rba +{ + +/// @brief ExistsOperator object maker Class +class RBAExistsOperatorMaker : public RBALambdaContextMaker +{ +public: + RBAExistsOperatorMaker(); + RBAExistsOperatorMaker(const RBAExistsOperatorMaker&)=delete; + RBAExistsOperatorMaker(const RBAExistsOperatorMaker&&)=delete; + RBAExistsOperatorMaker& operator=(const RBAExistsOperatorMaker&)=delete; + RBAExistsOperatorMaker& operator=(const RBAExistsOperatorMaker&&)=delete; + virtual ~RBAExistsOperatorMaker()=default; + +protected: + /// @brief Create empty instance + /// @details Create an empty instance of unique_ptr in a derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set attributes of model element for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model Model for storing created object + /// @param[in,out] owner parent object(Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + + /// @brief Crate empty object of LambdaContext + /// @details Create empty object of unique_ptr + /// @return unique_ptr for LambdaContext object + std::unique_ptr<RBALambdaContext> createLambdaContext() override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAExpression.cpp b/src/core/expression/RBAExpression.cpp new file mode 100644 index 0000000..2b9b6fc --- /dev/null +++ b/src/core/expression/RBAExpression.cpp @@ -0,0 +1,156 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Expression class definition + */ + +#include "RBAExpression.hpp" + +#include "RBALetStatement.hpp" +#include "RBAConstraintInfo.hpp" +#ifdef RBA_USE_LOG +#include "RBAExpressionType.hpp" +#endif + +namespace rba +{ + +void RBAExpression::addLetStatement(RBALetStatement* const letStatement) +{ + letStatements_.push_back(letStatement); +} + +void +RBAExpression::accept(RBAExpressionVisitor& visitor) +{ + // Not be called because the function of the derived class is called +} + +bool +RBAExpression::execute(RBAConstraintInfo* const info, RBAArbitrator * const arb) const +{ + info->setExpression(this); + for (RBALetStatement* const& letStatement : letStatements_) { + letStatement->setVariable(arb); + } + const bool result {executeCore(info, arb)}; + if (result) { + info->setResult(RBAExecuteResult::TRUE); + } else { + info->setResult(RBAExecuteResult::FALSE); + } + return result; +} + +bool +RBAExpression::executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const +{ + // This function is called when an Expression that does not define + // getReferenceObject() in evaluate() is specified. + info->setExceptionBeforeArbitrate(true); + return false; +} + +const RBARuleObject* +RBAExpression::getReferenceObject(RBAConstraintInfo* const info, + RBAArbitrator* const arb) const +{ + info->setExpression(this); + for (RBALetStatement* const& letStatement : letStatements_) { + letStatement->setVariable(arb); + } + return getReferenceObjectCore(info, arb); +} + +const RBARuleObject* +RBAExpression::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + // This function is called when an Expression that does not define + // getReferenceObject() in evaluateObject() is specified. + return nullptr; +} + +std::int32_t +RBAExpression::getValue(RBAConstraintInfo* const info, RBAArbitrator * const arb) const +{ + info->setExpression(this); + for (RBALetStatement* const& letStatement : letStatements_) { + letStatement->setVariable(arb); + } + return getValueCore(info, arb); +} + +const std::vector<RBALetStatement*>& +RBAExpression::getLetStatements() const +{ + return letStatements_; +} +std::int32_t +RBAExpression::getValueCore(RBAConstraintInfo* info, RBAArbitrator * arb) const +{ + // This function is called when an Expression that does not define + // getValue() in evaluateValue() is specified. + return -99; +} + +void +RBAExpression::doAction(RBAConstraintInfo* const info, RBAArbitrator* const arb) +{ + info->setExpression(this); + doActionCore(info, arb); + return; +} + +void +RBAExpression::doActionCore(RBAConstraintInfo* info, RBAArbitrator* arb) +{ + // This function is called when an Expression that does not define + // doAction() in evaluateDoAction() is specified. + return; +} + +#ifdef RBA_USE_LOG +const std::string +RBAExpression::getExpressionText() const +{ + // Not called because the function of the derived class is called + return "Unsupported operation exception"; +} + +const std::string +RBAExpression::getCoverageExpressionText() const +{ + // Not called because the function of the derived class is called + return "Unsupported operation exception"; +} + +void +RBAExpression::createHierarchy() +{ + // Not called because the function of the derived class is called +} + +RBAExpressionType +RBAExpression::getUnderlyingType() const +{ + // Not called because the function of the derived class is called + return RBAExpressionType::EXCEPTION; +} +#endif + +} diff --git a/src/core/expression/RBAExpression.hpp b/src/core/expression/RBAExpression.hpp new file mode 100644 index 0000000..9cd14e5 --- /dev/null +++ b/src/core/expression/RBAExpression.hpp @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Expression class header file + */ + +#ifndef RBAEXPRESSION_HPP +#define RBAEXPRESSION_HPP + +#include <cstdint> +#include <string> +#include <vector> +#include "RBAModelElement.hpp" + +namespace rba +{ + +class RBAExpressionVisitor; +class RBALetStatement; +class RBAArbitrator; +class RBARuleObject; +class RBAConstraintInfo; +#ifdef RBA_USE_LOG +enum class RBAExpressionType : std::uint8_t; +#endif + +class DLL_EXPORT RBAExpression : public RBAModelElement +{ +protected: + RBAExpression()=default; + RBAExpression(const RBAExpression&)=delete; + RBAExpression(const RBAExpression&&)=delete; + RBAExpression& operator=(const RBAExpression&)=delete; + RBAExpression& operator=(const RBAExpression&&)=delete; + +public: + virtual ~RBAExpression()=default; + void addLetStatement(RBALetStatement* const letStatement); + virtual void accept(RBAExpressionVisitor& visitor); + bool execute(RBAConstraintInfo* const info, RBAArbitrator* const arb) const; + const RBARuleObject* getReferenceObject(RBAConstraintInfo* const info, + RBAArbitrator* const arb) const; + std::int32_t getValue(RBAConstraintInfo* const info, RBAArbitrator* const arb) const; + void doAction(RBAConstraintInfo* const info, RBAArbitrator* const arb); + const std::vector<RBALetStatement*>& getLetStatements() const; + + // Log +#ifdef RBA_USE_LOG + virtual const std::string getExpressionText() const; + virtual const std::string getCoverageExpressionText() const; + virtual void createHierarchy(); + virtual RBAExpressionType getUnderlyingType() const; +#endif + +protected: + virtual bool executeCore(RBAConstraintInfo* info, RBAArbitrator* arb) const; + virtual const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const; + virtual std::int32_t getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const; + virtual void doActionCore(RBAConstraintInfo* info, RBAArbitrator* arb); + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::vector<RBALetStatement*> letStatements_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAExpressionMaker.cpp b/src/core/expression/RBAExpressionMaker.cpp new file mode 100644 index 0000000..250ace0 --- /dev/null +++ b/src/core/expression/RBAExpressionMaker.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAExpreessionMaker.cpp +/// @brief Abstract class definition file for expression object generation + +#include "RBAExpressionMaker.hpp" +#include "RBAJsonElement.hpp" +#include "RBALetStatementMaker.hpp" +#include "RBALetStatement.hpp" + +namespace rba +{ + +RBAExpressionMaker::RBAExpressionMaker(const std::string& label) + : RBAModelElementMaker{label} +{ +} + +std::int32_t +RBAExpressionMaker::setLetStatement(RBAModelImpl* const model, + RBAExpression* const expr, + const RBAJsonElement* const jsonElem) +{ + std::int32_t var_num {0}; + const RBAJsonElement* const letElem {jsonElem->findChildren("letStatements")}; + if(letElem != nullptr) { + RBALetStatementMaker letMaker; + letMaker.setFactory(getFactory()); + for(const auto& param : letElem->getChildren()) { + // execute pushVariable() in letMaker::create() + RBALetStatement* const letExpr + {dynamic_cast<RBALetStatement*>(letMaker.create(param.get(), model))}; + expr->addLetStatement(letExpr); + var_num += 1; + } + } + + return var_num; +} + +} diff --git a/src/core/expression/RBAExpressionMaker.hpp b/src/core/expression/RBAExpressionMaker.hpp new file mode 100644 index 0000000..282a093 --- /dev/null +++ b/src/core/expression/RBAExpressionMaker.hpp @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAExpreessionMaker.hpp +/// @brief Abstract class definition header file for expression object generation + +#ifndef RBAEXPRESSIONMAKER_HPP +#define RBAEXPRESSIONMAKER_HPP + +#include <cstdint> +#include "RBAModelElementMaker.hpp" + +namespace rba +{ + +class RBAExpression; + +/// @brief Abstract class for expression object gcreation +class DLL_EXPORT RBAExpressionMaker : public RBAModelElementMaker +{ +public: + explicit RBAExpressionMaker(const std::string& label=""); + RBAExpressionMaker(const RBAExpressionMaker&)=delete; + RBAExpressionMaker(const RBAExpressionMaker&&)=delete; + RBAExpressionMaker& operator=(const RBAExpressionMaker&)=delete; + RBAExpressionMaker& operator=(const RBAExpressionMaker&&)=delete; + virtual ~RBAExpressionMaker()=default; + +protected: + /// @brief To set ”Let" expression + /// @details Generate Let expression from jsonElem and register it in expr. + /// Return the number of variables that have been registered + /// (pushed) to ModelFactory, and pop them when the reference of + /// variables is completed in function that called this function. + /// @return the number of pushed variables + std::int32_t setLetStatement(RBAModelImpl* model, + RBAExpression* expr, + const RBAJsonElement* jsonElem); + +}; + +} + +#endif diff --git a/src/core/expression/RBAExpressionType.hpp b/src/core/expression/RBAExpressionType.hpp new file mode 100644 index 0000000..6b6fcd8 --- /dev/null +++ b/src/core/expression/RBAExpressionType.hpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Expression type enumeration class header file + */ + +#ifndef RBAEXPRESSIONTYPE_HPP +#define RBAEXPRESSIONTYPE_HPP + +#ifdef RBA_USE_LOG + +#include <cstdint> + +namespace rba +{ + +enum class RBAExpressionType : std::uint8_t +{ + VALUE = 0, + BOOLEAN, + AREA, + CONTENT, + SET_OF_AREA, + SET_OF_CONTENT, + LAMBDA, + SCENE, + ZONE, + SET_OF_ZONE, + SOUND, + SET_OF_SOUND, + ACTION, + SET_OF_ACTION, + PROPERTY, + EXTENSION, + CONTENT_STATE, + EXCEPTION +}; + +} + +#endif +#endif diff --git a/src/core/expression/RBAExpressionVisitor.hpp b/src/core/expression/RBAExpressionVisitor.hpp new file mode 100644 index 0000000..e678b42 --- /dev/null +++ b/src/core/expression/RBAExpressionVisitor.hpp @@ -0,0 +1,168 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Expression visitor class header file + */ + +#ifndef RBAEXPRESSIONVISITOR_HPP +#define RBAEXPRESSIONVISITOR_HPP + +namespace rba { +class RBAIsDisplayed; +class RBADisplayingContent; +class RBAAllocatedContent; +class RBAIsHidden; +class RBAContentValue; +class RBAGetContentsList; +class RBAIsActive; +class RBAIsVisible; +class RBAStateValue; +class RBAHasBeenDisplayed; +class RBAHasComeEarlierThan; +class RBAHasComeLaterThan; +class RBAGetAllocatables; +class RBAIsOutputted; +class RBAOutputtingSound; +class RBAIsMuted; +class RBAIsAttenuated; +class RBAIsSounding; +class RBAIsOn; +class RBAGetProperty; +class RBAAndOperator; +class RBAOrOperator; +class RBANotOperator; +class RBAImpliesOperator; +class RBAIsEqualToOperator; +class RBAObjectCompare; +class RBAIsGreaterThanOperator; +class RBAIsGreaterThanEqualOperator; +class RBAIsLowerThanOperator; +class RBAIsLowerThanEqualOperator; +class RBAForAllOperator; +class RBAExistsOperator; +class RBAAllInstanceOfArea; +class RBAAllInstanceOfViewContent; +class RBAAllInstanceOfZone; +class RBAAllInstanceOfSoundContent; +class RBAIfStatement; +class RBALetStatement; +class RBAPreviousModifier; +class RBAActiveState; +class RBAActiveContents; +class RBAMaxOperator; +class RBAMinOperator; +class RBASelectOperator; +class RBASizeOperator; +class RBAObjectReference; +class RBASetOfOperator; +class RBAIsTypeOfOperator; + +class RBAExpressionVisitor { + public: + RBAExpressionVisitor()=default; + RBAExpressionVisitor(const RBAExpressionVisitor&)=delete; + RBAExpressionVisitor(const RBAExpressionVisitor&&)=delete; + RBAExpressionVisitor& operator=(const RBAExpressionVisitor&)=delete; + RBAExpressionVisitor& operator=(const RBAExpressionVisitor&&)=delete; + virtual ~RBAExpressionVisitor() = default; + + // Refer to Area status + virtual void visit(RBAIsDisplayed& exp) = 0; + virtual void visit(RBADisplayingContent& exp) = 0; + virtual void visit(RBAAllocatedContent& exp) = 0; + virtual void visit(RBAIsHidden& exp) = 0; + virtual void visit(RBAContentValue& exp) = 0; + virtual void visit(RBAGetContentsList& exp) = 0; + virtual void visit(RBAActiveContents& exp) = 0; + + // Refer to display content status + virtual void visit(RBAIsActive& exp) = 0; + virtual void visit(RBAIsVisible& exp) = 0; + virtual void visit(RBAStateValue& exp) = 0; + virtual void visit(RBAHasBeenDisplayed& exp) = 0; + virtual void visit(RBAHasComeEarlierThan& exp) = 0; + virtual void visit(RBAHasComeLaterThan& exp) = 0; + virtual void visit(RBAGetAllocatables& exp) = 0; + virtual void visit(RBAActiveState& exp) = 0; + + // Refer to Zone status + virtual void visit(RBAIsOutputted& exp) = 0; + virtual void visit(RBAOutputtingSound& exp) = 0; + // allocatedContent is common with Area + virtual void visit(RBAIsMuted& exp) = 0; + virtual void visit(RBAIsAttenuated& exp) = 0; + // contentValue is common with Area + // contentsList is common with Area + + // Refer to sound content status + // isActive is common with display content + virtual void visit(RBAIsSounding& exp) = 0; + // stateValue is common with display content + // hasComeEarlierThan is common with display content + // hasComeLaterThan is common with display content + // allocatables is common with display content + // activeState is common with display content + + // Refer to Scene + virtual void visit(RBAIsOn& exp) = 0; + virtual void visit(RBAGetProperty& exp) = 0; + + virtual void visit(RBAIsTypeOfOperator& exp) = 0; + + // Operators + virtual void visit(RBAAndOperator& exp) = 0; + virtual void visit(RBAOrOperator& exp) = 0; + virtual void visit(RBANotOperator& exp) = 0; + virtual void visit(RBAImpliesOperator& exp) = 0; + virtual void visit(RBAIsEqualToOperator& exp) = 0; + virtual void visit(RBAObjectCompare& exp) = 0; + virtual void visit(RBAIsGreaterThanOperator& exp) = 0; + virtual void visit(RBAIsGreaterThanEqualOperator& exp) = 0; + virtual void visit(RBAIsLowerThanOperator& exp) = 0; + virtual void visit(RBAIsLowerThanEqualOperator& exp) = 0; + + // Quantification symbol + virtual void visit(RBAForAllOperator& exp) = 0; + virtual void visit(RBAExistsOperator& exp) = 0; + + // Built-in definition expression + virtual void visit(RBAAllInstanceOfArea& exp) = 0; + virtual void visit(RBAAllInstanceOfViewContent& exp) = 0; + virtual void visit(RBAAllInstanceOfZone& exp) = 0; + virtual void visit(RBAAllInstanceOfSoundContent& exp) = 0; + + // Syntax + virtual void visit(RBAIfStatement& exp) = 0; + virtual void visit(RBALetStatement& exp) = 0; + + // Modifier + virtual void visit(RBAPreviousModifier& exp) = 0; + + // Set operator + virtual void visit(RBAMaxOperator& exp) = 0; + virtual void visit(RBAMinOperator& exp) = 0; + virtual void visit(RBASelectOperator& exp) = 0; + virtual void visit(RBASizeOperator& exp) = 0; + + // Object references + virtual void visit(RBAObjectReference& exp) = 0; + virtual void visit(RBASetOfOperator& exp) = 0; +}; + +} + +#endif diff --git a/src/core/expression/RBAForAllOperator.cpp b/src/core/expression/RBAForAllOperator.cpp new file mode 100644 index 0000000..93a2894 --- /dev/null +++ b/src/core/expression/RBAForAllOperator.cpp @@ -0,0 +1,173 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ForAll operator class + */ + +#include "RBAForAllOperator.hpp" + +#include "RBAAllocatable.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAContent.hpp" +#include "RBAContentSet.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALambdaExpression.hpp" +#include "RBALogManager.hpp" +#include "RBAExpressionType.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAForAllOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAForAllOperator::getModelElementType() const +{ + return RBAModelElementType::ForAllOperator; +} + +bool +RBAForAllOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator * arb) const +{ + const RBAExpression* const setObj {getLhsOperand()}; + RBALambdaExpression* const lambda {getLambda()}; + + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + + // get Rule object and loop + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + + std::vector<const RBARuleObject*> objs; + const RBARuleObject* const ruleObj {setObj->getReferenceObject(leftInfo, arb)}; + const RBARuleObject* objset {nullptr}; + if (ruleObj != nullptr) { + objset = ruleObj->getRawObject(); + } + + if(leftInfo->isExceptionBeforeArbitrate() || (objset == nullptr)) { + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); + + info->setExceptionBeforeArbitrate(true); + return false; + } + if (dynamic_cast<const RBAAllocatableSet*>(objset) != nullptr) { + objs.clear(); + for(const RBAAllocatable* alloc + : dynamic_cast<const RBAAllocatableSet*>(objset)->getLeafAllocatable()) { + objs.push_back(alloc); + } + } + else { + objs.clear(); + for(const auto& cont : dynamic_cast<const RBAContentSet*>(objset)->getLeafContent() ){ + objs.push_back(cont); + } + } + + bool isTrue {true}; + std::uint32_t i {0U}; + for(const RBARuleObject* const obj : objs) { + // Add count to the constraint hierarchy for coverage + LOG_addHierarchy("#" + std::to_string(i)); + + RBAConstraintInfo* const childInfo {info->getChild(i)}; + lambda->setRuleObj(obj); + + const bool res {lambda->execute(childInfo, arb)}; + + // Remove count from the constraint hierarchy for coverage + LOG_removeHierarchy(); + + if(childInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else { + isTrue = (isTrue && res); + } + i++; + } + + if (isTrue == false) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + // Remove count from the constraint hierarchy for coverage + LOG_removeHierarchy(); + info->setExceptionBeforeArbitrate(false); + return false; + } else if (info->isExceptionBeforeArbitrate()) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + // Remove count from the constraint hierarchy for coverage + LOG_removeHierarchy(); + return false; + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + // Remove count from the constraint hierarchy for coverage + LOG_removeHierarchy(); + return true; + } +} + +#ifdef RBA_USE_LOG +const std::string +RBAForAllOperator::getSymbol() const +{ + return "For All"; +} + +const std::string +RBAForAllOperator::getExpressionText() const +{ + RBAExpression* exprLhs = getLhsOperand(); + return getSymbol() + " " + + exprLhs->getExpressionText() + " " + + getLambda()->getExpressionText(); +} + +const std::string +RBAForAllOperator::getCoverageExpressionText() const +{ + getLambda()->clearRuleObj(); + RBAExpression* exprLhs = getLhsOperand(); + return getSymbol() + " " + + exprLhs->getCoverageExpressionText() + " " + + getLambda()->getCoverageExpressionText(); +} + +RBAExpressionType +RBAForAllOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAForAllOperator.hpp b/src/core/expression/RBAForAllOperator.hpp new file mode 100644 index 0000000..7c0c7cc --- /dev/null +++ b/src/core/expression/RBAForAllOperator.hpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ForAll operator class header file + */ + +#ifndef RBAFORALLOPERATOR_HPP +#define RBAFORALLOPERATOR_HPP + +#include "RBALambdaContext.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAForAllOperator : public RBALambdaContext +{ +public: + RBAForAllOperator()=default; + RBAForAllOperator(const RBAForAllOperator&)=delete; + RBAForAllOperator(const RBAForAllOperator&&)=delete; + RBAForAllOperator& operator=(const RBAForAllOperator&)=delete; + RBAForAllOperator& operator=(const RBAForAllOperator&&)=delete; + virtual ~RBAForAllOperator()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAForAllOperatorMaker.cpp b/src/core/expression/RBAForAllOperatorMaker.cpp new file mode 100644 index 0000000..eb1068d --- /dev/null +++ b/src/core/expression/RBAForAllOperatorMaker.cpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAForAllOperatorMaker.cpp +/// @brief ForAllOperator object generation class + +#include "RBAForAllOperatorMaker.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelFactory.hpp" +#include "RBAForAllOperator.hpp" +#include "RBALambdaExpression.hpp" + +namespace rba +{ + +RBAForAllOperatorMaker::RBAForAllOperatorMaker() + : RBALambdaContextMaker{"ForAllOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAForAllOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAForAllOperator>(); +} + +RBAModelElement* +RBAForAllOperatorMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>( + RBALambdaContextMaker::setProperty(element, jsonElem, model, owner)); + + return element; +} + +std::unique_ptr<RBALambdaContext> +RBAForAllOperatorMaker::createLambdaContext() +{ + return std::make_unique<RBAForAllOperator>(); +} + +} diff --git a/src/core/expression/RBAForAllOperatorMaker.hpp b/src/core/expression/RBAForAllOperatorMaker.hpp new file mode 100644 index 0000000..9c5de92 --- /dev/null +++ b/src/core/expression/RBAForAllOperatorMaker.hpp @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAForAllOperatorMaker.hpp +/// @brief ForAllOperator object generation class header + +#ifndef RBAFORALLOPERATORMAKER_HPP +#define RBAFORALLOPERATORMAKER_HPP + +#include "RBALambdaContextMaker.hpp" + +namespace rba +{ + +/// @brief ForAllOperator object generation class +class RBAForAllOperatorMaker : public RBALambdaContextMaker +{ +public: + RBAForAllOperatorMaker(); + RBAForAllOperatorMaker(const RBAForAllOperatorMaker&)=delete; + RBAForAllOperatorMaker(const RBAForAllOperatorMaker&&)=delete; + RBAForAllOperatorMaker& operator=(const RBAForAllOperatorMaker&)=delete; + RBAForAllOperatorMaker& operator=(const RBAForAllOperatorMaker&&)=delete; + virtual ~RBAForAllOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in a derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model M\model to store the generated object + /// @param[in,out] owner parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + + /// @brief generate an empty object of LambdaContext + /// @details generate an empty object of unique_ptr in a derived class + /// @return unique_ptr for LambdaContext object + std::unique_ptr<RBALambdaContext> createLambdaContext() override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAGetAllocatables.cpp b/src/core/expression/RBAGetAllocatables.cpp new file mode 100644 index 0000000..8494a01 --- /dev/null +++ b/src/core/expression/RBAGetAllocatables.cpp @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /** + * GetAllocatables class definition file + */ + +#include "RBAGetAllocatables.hpp" + +#include "RBAContent.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAGetAllocatables::accept(RBAExpressionVisitor& visitor) +{ + // This path is not used, because RBASceneAllocatableCollector, + // the only existing visitor as of now, does not accept content. + // But, keep this because another visitor may accept, in the future. + visitor.visit(*this); +} + +RBAModelElementType +RBAGetAllocatables::getModelElementType() const +{ + return RBAModelElementType::GetAllocatables; +} + +const RBARuleObject* +RBAGetAllocatables::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + + const RBARuleObject* const ruleObj + {getLhsOperand()->getReferenceObject(leftInfo, arb)}; + const RBAContent* content {nullptr}; + if (ruleObj != nullptr) { + content = dynamic_cast<const RBAContent*>(ruleObj->getRawObject()); + } + + if (content == nullptr) { + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } + return nullptr; + } + + return content->getAllocatableSet(); +} + +#ifdef RBA_USE_LOG +const std::string +RBAGetAllocatables::getSymbol() const +{ + return ".allocatables()"; +} + +const std::string +RBAGetAllocatables::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol(); +} + +// At the moment, the arbitration FW cannot write a constraint expression +// to call createHierarchy() of GetAllocatables, +// so it does not go through this path. +// But, defined this for maintainability (especially expandability. +void +RBAGetAllocatables::createHierarchy() +{ + // No operation because it does not affect structure. +} + +#endif + +} diff --git a/src/core/expression/RBAGetAllocatables.hpp b/src/core/expression/RBAGetAllocatables.hpp new file mode 100644 index 0000000..d1c7167 --- /dev/null +++ b/src/core/expression/RBAGetAllocatables.hpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * GetAllocatables class header file + */ + +#ifndef RBAGETALLOCATABLES_HPP +#define RBAGETALLOCATABLES_HPP + +#include "RBAContentOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAGetAllocatables : public RBAContentOperator +{ +public: + RBAGetAllocatables()=default; + RBAGetAllocatables(const RBAGetAllocatables&)=delete; + RBAGetAllocatables(const RBAGetAllocatables&&)=delete; + RBAGetAllocatables& operator=(const RBAGetAllocatables&)=delete; + RBAGetAllocatables& operator=(const RBAGetAllocatables&&)=delete; + virtual ~RBAGetAllocatables()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + void createHierarchy() override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAGetAllocatablesMaker.cpp b/src/core/expression/RBAGetAllocatablesMaker.cpp new file mode 100644 index 0000000..aac81a2 --- /dev/null +++ b/src/core/expression/RBAGetAllocatablesMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAGetAllocatablesMaker.cpp +/// @brief GetAllocatables object generation class definition + +#include "RBAGetAllocatablesMaker.hpp" +#include "RBAGetAllocatables.hpp" + +namespace rba +{ + +RBAGetAllocatablesMaker::RBAGetAllocatablesMaker() + : RBAOperatorMaker{"GetAllocatables"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAGetAllocatablesMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAGetAllocatables>(); +} + +} diff --git a/src/core/expression/RBAGetAllocatablesMaker.hpp b/src/core/expression/RBAGetAllocatablesMaker.hpp new file mode 100644 index 0000000..722845f --- /dev/null +++ b/src/core/expression/RBAGetAllocatablesMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAGetAllocatablesMaker.hpp +/// @brief GetAllocatables object generation class header file + +#ifndef RBAGETALLOCATABLESMAKER_HPP +#define RBAGETALLOCATABLESMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief GetAllocatables object gneration class +class RBAGetAllocatablesMaker : public RBAOperatorMaker +{ +public: + RBAGetAllocatablesMaker(); + RBAGetAllocatablesMaker(const RBAGetAllocatablesMaker&)=delete; + RBAGetAllocatablesMaker(const RBAGetAllocatablesMaker&&)=delete; + RBAGetAllocatablesMaker& operator=(const RBAGetAllocatablesMaker&)=delete; + RBAGetAllocatablesMaker& operator=(const RBAGetAllocatablesMaker&&)=delete; + virtual ~RBAGetAllocatablesMaker()=default; + +protected: + /// @brief Generate an empty instance + /// @details Generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAGetContentsList.cpp b/src/core/expression/RBAGetContentsList.cpp new file mode 100644 index 0000000..5f14b33 --- /dev/null +++ b/src/core/expression/RBAGetContentsList.cpp @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * GetContentsList class definition file + */ + +#include "RBAGetContentsList.hpp" + +#include "RBAAllocatable.hpp" +#include "RBAContentSet.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void RBAGetContentsList::accept(RBAExpressionVisitor& visitor) +{ + // This path is not used, because RBASceneAllocatableCollector, + // the only existing visitor as of now, does not accept content. + // But, keep this because another visitor may accept, in the future. + visitor.visit(*this); +} + +RBAModelElementType +RBAGetContentsList::getModelElementType() const +{ + return RBAModelElementType::GetContentsList; +} + +const RBARuleObject* +RBAGetContentsList::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + + const RBARuleObject* const ruleObj + {getLhsOperand()->getReferenceObject(leftInfo, arb)}; + const RBAAllocatable* allocatable {nullptr}; + if (ruleObj != nullptr) { + allocatable = dynamic_cast<const RBAAllocatable*>(ruleObj->getRawObject()); + } + // Indicates whether the content referenced by this constraint expression + // is the result of the previous arbitration result. + + if (leftInfo->isExceptionBeforeArbitrate() || (allocatable == nullptr)) { + // As of now, this path is not used due to the following reasons. + // - The expression below GetContentsList is before arbitration + // - Constraint expression that returns null as allocatable + // can not be described(specified) + // But, defined this for maintainability (especially expandability). + info->setExceptionBeforeArbitrate(true); + return nullptr; + } + + return allocatable->getContentSet(); +} + +#ifdef RBA_USE_LOG +// At the moment, the arbitration FW cannot write a constraint expression +// to call createHierarchy() of GetContentsList, +// so it does not go through this path. +// But, defined this for maintainability (especially expandability. +void +RBAGetContentsList::createHierarchy() +{ + // No operation because it does not affect structure. +} +#endif + +} diff --git a/src/core/expression/RBAGetContentsList.hpp b/src/core/expression/RBAGetContentsList.hpp new file mode 100644 index 0000000..240a50c --- /dev/null +++ b/src/core/expression/RBAGetContentsList.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * GetContentsList class header file + */ + +#ifndef RBAGETCONTENTSLIST_HPP +#define RBAGETCONTENTSLIST_HPP + +#include "RBAAllocatableOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAGetContentsList : public RBAAllocatableOperator +{ +public: + RBAGetContentsList()=default; + RBAGetContentsList(const RBAGetContentsList&)=delete; + RBAGetContentsList(const RBAGetContentsList&&)=delete; + RBAGetContentsList& operator=(const RBAGetContentsList&)=delete; + RBAGetContentsList& operator=(const RBAGetContentsList&&)=delete; + virtual ~RBAGetContentsList()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + void createHierarchy() override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAGetContentsListMaker.cpp b/src/core/expression/RBAGetContentsListMaker.cpp new file mode 100644 index 0000000..2081e2d --- /dev/null +++ b/src/core/expression/RBAGetContentsListMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAGetContentsListMaker.cpp +/// @brief GetContentsList object generation class definition file + +#include "RBAGetContentsListMaker.hpp" +#include "RBAGetContentsList.hpp" + +namespace rba +{ + +RBAGetContentsListMaker::RBAGetContentsListMaker() + : RBAOperatorMaker{"GetContentsList"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAGetContentsListMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAGetContentsList>(); +} + +} diff --git a/src/core/expression/RBAGetContentsListMaker.hpp b/src/core/expression/RBAGetContentsListMaker.hpp new file mode 100644 index 0000000..c703f68 --- /dev/null +++ b/src/core/expression/RBAGetContentsListMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAGetContentsListMaker.hpp +/// @brief GetContentsList object generation class header file + +#ifndef RBAGETCONTENTSLISTMAKER_HPP +#define RBAGETCONTENTSLISTMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief GetContentsList object generation class +class RBAGetContentsListMaker : public RBAOperatorMaker +{ +public: + RBAGetContentsListMaker(); + RBAGetContentsListMaker(const RBAGetContentsListMaker&)=delete; + RBAGetContentsListMaker(const RBAGetContentsListMaker&&)=delete; + RBAGetContentsListMaker& operator=(const RBAGetContentsListMaker&)=delete; + RBAGetContentsListMaker& operator=(const RBAGetContentsListMaker&&)=delete; + virtual ~RBAGetContentsListMaker()=default; + +protected: + /// @brief Generate an empty instance + /// @details Generate an empty class of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAGetProperty.cpp b/src/core/expression/RBAGetProperty.cpp new file mode 100644 index 0000000..3a774d8 --- /dev/null +++ b/src/core/expression/RBAGetProperty.cpp @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * RBAGetProperty class defintino file + */ + +#include "RBAGetProperty.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBASceneImpl.hpp" +#include "RBAArbitrator.hpp" +#include "RBALogManager.hpp" +#include "RBAExpressionType.hpp" +#include "RBAModelElementType.hpp" +#include "RBAAbstractProperty.hpp" + +namespace rba +{ + +void +RBAGetProperty::accept(RBAExpressionVisitor& visitor) +{ + // This path is not used, because RBASceneAllocatableCollector, + // the only existing visitor as of now, does not accept content. + // But, keep this because another visitor may accept, in the future. + visitor.visit(*this); +} + +RBAModelElementType +RBAGetProperty::getModelElementType() const +{ + return RBAModelElementType::GetProperty; +} + +std::int32_t +RBAGetProperty::getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + std::int32_t value{0}; + const RBAAbstractProperty* prop{nullptr}; + const RBARuleObject* const ruleObj {getLhsOperand()->getReferenceObject(info, arb)}; + if(ruleObj->isPrevious()) { + prop = dynamic_cast<const RBAAbstractProperty*>(ruleObj->getRawObject()); + value = arb->getResult()->getPreSceneProperty(prop); + } + else { + prop = dynamic_cast<const RBAAbstractProperty*>(ruleObj); + value = arb->getResult()->getSceneProperty(prop); + } + LOG_arbitrateConstraintLogicLogLine(" " + + getPreMsg(ruleObj->isPrevious()) + + "Property[" + + prop->getScene()->getElementName() + + "::" + + prop->getElementName() + + "] get[" + + std::to_string(value) + + "]"); + return value; +} + +#ifdef RBA_USE_LOG +const std::string +RBAGetProperty::getSymbol() const +{ + return ".get()"; +} + +const std::string +RBAGetProperty::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol(); +} + +const std::string +RBAGetProperty::getCoverageExpressionText() const +{ + return getExpressionText(); +} + +RBAExpressionType +RBAGetProperty::getUnderlyingType() const +{ + return RBAExpressionType::VALUE; +} +#endif + +} diff --git a/src/core/expression/RBAGetProperty.hpp b/src/core/expression/RBAGetProperty.hpp new file mode 100644 index 0000000..eff3852 --- /dev/null +++ b/src/core/expression/RBAGetProperty.hpp @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * RBAGetProperty Class + */ + +#ifndef RBAGETPROPERTY_HPP +#define RBAGETPROPERTY_HPP + +#include "RBAPropertyOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAGetProperty : public RBAPropertyOperator +{ +public: + RBAGetProperty()=default; + RBAGetProperty(const RBAGetProperty&)=delete; + RBAGetProperty(const RBAGetProperty&&)=delete; + RBAGetProperty& operator=(const RBAGetProperty&)=delete; + RBAGetProperty& operator=(const RBAGetProperty&&)=delete; + virtual ~RBAGetProperty()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + std::int32_t getValueCore(RBAConstraintInfo* info, + RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAGetPropertyMaker.cpp b/src/core/expression/RBAGetPropertyMaker.cpp new file mode 100644 index 0000000..f2588ad --- /dev/null +++ b/src/core/expression/RBAGetPropertyMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAGetPropertyMaker.cpp +/// @brief GetProperty object generation class defintion file + +#include "RBAGetPropertyMaker.hpp" +#include "RBAGetProperty.hpp" + +namespace rba +{ + +RBAGetPropertyMaker::RBAGetPropertyMaker() + : RBAOperatorMaker{"GetProperty"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAGetPropertyMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAGetProperty>(); +} + +} diff --git a/src/core/expression/RBAGetPropertyMaker.hpp b/src/core/expression/RBAGetPropertyMaker.hpp new file mode 100644 index 0000000..db20ce1 --- /dev/null +++ b/src/core/expression/RBAGetPropertyMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAGetPropertyMaker.hpp +/// @brief GetProperty object generation class heeader file + +#ifndef RBAGETPROPERTYMAKER_HPP +#define RBAGETPROPERTYMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief GetProperty object generation class +class RBAGetPropertyMaker : public RBAOperatorMaker +{ +public: + RBAGetPropertyMaker(); + RBAGetPropertyMaker(const RBAGetPropertyMaker&)=delete; + RBAGetPropertyMaker(const RBAGetPropertyMaker&&)=delete; + RBAGetPropertyMaker& operator=(const RBAGetPropertyMaker&)=delete; + RBAGetPropertyMaker& operator=(const RBAGetPropertyMaker&&)=delete; + virtual ~RBAGetPropertyMaker()=default; + +protected: + /// @brief Generate an empty instance + /// @details Generate an empty class of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAHasBeenDisplayed.cpp b/src/core/expression/RBAHasBeenDisplayed.cpp new file mode 100644 index 0000000..72c1d40 --- /dev/null +++ b/src/core/expression/RBAHasBeenDisplayed.cpp @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * .hasBeenDisplayed() definition + **/ + +#include "RBAHasBeenDisplayed.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" +#include "RBAArbitrator.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAContent.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" + +namespace rba +{ + +void RBAHasBeenDisplayed::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType RBAHasBeenDisplayed::getModelElementType() const +{ + return RBAModelElementType::HasBeenDisplayed; +} + +bool RBAHasBeenDisplayed::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const ruleObj {getLhsOperand()->getReferenceObject(leftInfo, + arb)}; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else if (ruleObj != nullptr) { + const RBAContent* const c { + dynamic_cast<const RBAContent*>(ruleObj->getRawObject())}; + if (!ruleObj->isPrevious()) { + isPassed = arb->getResult()->hasBeenDisplayed(c); + } else { + isPassed = arb->getResult()->hasBeenPreDisplayed(c); + } + } else { + ; + } +#ifdef RBA_USE_LOG + RBAExecuteResult r; + std::string cname; + std::string resultStr; + if (ruleObj != nullptr) { + cname = ruleObj->getRawObject()->getElementName(); + } else { + cname = "NULL"; + } + if (info->isExceptionBeforeArbitrate()) { + resultStr = " before arbitrate skip"; + r = RBAExecuteResult::SKIP; + } else if (isPassed) { + resultStr = " true"; + r = RBAExecuteResult::TRUE; + } else { + resultStr = " false"; + r = RBAExecuteResult::FALSE; + } + LOG_arbitrateConstraintLogicLogLine( + " Content[" + cname + "]" + getSymbol() + resultStr); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), r); +#endif + LOG_removeHierarchy(); + return isPassed; +} + +// Log +#ifdef RBA_USE_LOG +const std::string RBAHasBeenDisplayed::getSymbol() const +{ + return ".hasBeenDisplayed()"; +} +RBAExpressionType RBAHasBeenDisplayed::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif +} /* namespace rba */ diff --git a/src/core/expression/RBAHasBeenDisplayed.hpp b/src/core/expression/RBAHasBeenDisplayed.hpp new file mode 100644 index 0000000..3e3ebde --- /dev/null +++ b/src/core/expression/RBAHasBeenDisplayed.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// .hasBeenDisplayed() header file +// + +#ifndef RBAHASBEENDISPLAYED_HPP +#define RBAHASBEENDISPLAYED_HPP + +#include "RBAContentOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAHasBeenDisplayed : public RBAContentOperator +{ + public: + RBAHasBeenDisplayed()=default; + RBAHasBeenDisplayed(const RBAHasBeenDisplayed&)=delete; + RBAHasBeenDisplayed(const RBAHasBeenDisplayed&&)=delete; + RBAHasBeenDisplayed& operator=(const RBAHasBeenDisplayed&)=delete; + RBAHasBeenDisplayed& operator=(const RBAHasBeenDisplayed&&)=delete; + virtual ~RBAHasBeenDisplayed()=default; + + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + RBAExpressionType getUnderlyingType() const override; +#endif +}; + +} /* namespace rba */ + +#endif /* RBAHASBEENDISPLAYED_HPP */ diff --git a/src/core/expression/RBAHasBeenDisplayedMaker.cpp b/src/core/expression/RBAHasBeenDisplayedMaker.cpp new file mode 100644 index 0000000..36aeecc --- /dev/null +++ b/src/core/expression/RBAHasBeenDisplayedMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAHasBeenDisplayedMaker.cpp +/// @brief HasBeenDisplayed object generation class defintion file + +#include "RBAHasBeenDisplayedMaker.hpp" +#include "RBAHasBeenDisplayed.hpp" + +namespace rba +{ + +RBAHasBeenDisplayedMaker::RBAHasBeenDisplayedMaker() + : RBAOperatorMaker{"HasBeenDisplayed"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAHasBeenDisplayedMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAHasBeenDisplayed>(); +} + +} diff --git a/src/core/expression/RBAHasBeenDisplayedMaker.hpp b/src/core/expression/RBAHasBeenDisplayedMaker.hpp new file mode 100644 index 0000000..5e9bc10 --- /dev/null +++ b/src/core/expression/RBAHasBeenDisplayedMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAHasBeenDisplayedMaker.hpp +/// @brief HasBeenDisplayed object generation class header file + +#ifndef RBAHASBEENDISPLAYEDMAKER_HPP +#define RBAHASBEENDISPLAYEDMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief HasBeenDisplayed object generation class +class RBAHasBeenDisplayedMaker : public RBAOperatorMaker +{ +public: + RBAHasBeenDisplayedMaker(); + RBAHasBeenDisplayedMaker(const RBAHasBeenDisplayedMaker&)=delete; + RBAHasBeenDisplayedMaker(const RBAHasBeenDisplayedMaker&&)=delete; + RBAHasBeenDisplayedMaker& operator=(const RBAHasBeenDisplayedMaker&)=delete; + RBAHasBeenDisplayedMaker& operator=(const RBAHasBeenDisplayedMaker&&)=delete; + virtual ~RBAHasBeenDisplayedMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instancce of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAHasComeEarlierThan.cpp b/src/core/expression/RBAHasComeEarlierThan.cpp new file mode 100644 index 0000000..4b5482a --- /dev/null +++ b/src/core/expression/RBAHasComeEarlierThan.cpp @@ -0,0 +1,151 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * HasComeEarlierThan class + */ + +#include "RBAHasComeEarlierThan.hpp" +#include "RBAContent.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +RBAModelElementType +RBAHasComeEarlierThan::getModelElementType() const +{ + return RBAModelElementType::HasComeEarlier; +} + +void RBAHasComeEarlierThan::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +bool +RBAHasComeEarlierThan::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + + bool isResult {false}; + // Get content in left side of the expression + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* ruleObj {getLhsOperand()->getReferenceObject(leftInfo, arb)}; + const RBAContent* contentLhs {nullptr}; + if(ruleObj != nullptr) { + contentLhs = dynamic_cast<const RBAContent*>(ruleObj->getRawObject()); + } + + // Get content in right hand side of the expression + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + ruleObj = getRhsOperand()->getReferenceObject(rightInfo, arb); + const RBAContent* contentRhs {nullptr}; + if(ruleObj != nullptr) { + contentRhs = dynamic_cast<const RBAContent*>(ruleObj->getRawObject()); + } + + if((contentLhs == nullptr) || (contentRhs == nullptr)) { + info->setExceptionBeforeArbitrate(true); + } else { + if (!((arb->getResult()->isActive(contentLhs)) + && (arb->getResult()->isActive(contentRhs)))) { + info->setExceptionBeforeArbitrate(true); + } + else if(contentLhs == contentRhs) { + isResult = false; + } + else { + isResult = !arb->getResult()->isLater(contentLhs, contentRhs); + } + } +#ifdef RBA_USE_LOG + std::string lhsName; + std::string rhsName; + std::string resultText; + if(contentLhs == nullptr) { + lhsName = "NULL"; + } else { + lhsName = contentLhs->getElementName(); + } + if (contentRhs == nullptr) { + rhsName = "NULL"; + } else { + rhsName = contentRhs->getElementName(); + } + if (info->isExceptionBeforeArbitrate() == true ) { + resultText = "is before arbitrate skip"; + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else { + resultText = RBALogManager::boolToString(isResult); + if(isResult) { + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } + else { + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } + } + LOG_arbitrateConstraintLogicLogLine( + " Content[" + lhsName + "] has come earlier than Content[" + rhsName + "] " + resultText); +#endif + // Remove itself from constraint hierarchy for coverage + LOG_removeHierarchy(); + return isResult; +} + +#ifdef RBA_USE_LOG +const std::string +RBAHasComeEarlierThan::getSymbol() const +{ + return ".hasComeEarlierThan"; +} + +const std::string +RBAHasComeEarlierThan::getExpressionText() const +{ + RBAExpression* exprLhs = getLhsOperand(); + RBAExpression* exprRhs = getRhsOperand(); + return exprLhs->getExpressionText() + getSymbol() + + "(" + exprRhs->getExpressionText() + ")"; +} + +const std::string +RBAHasComeEarlierThan::getCoverageExpressionText() const +{ + RBAExpression* exprLhs = getLhsOperand(); + RBAExpression* exprRhs = getRhsOperand(); + return exprLhs->getCoverageExpressionText() + getSymbol() + + "(" + exprRhs->getCoverageExpressionText() + ")"; +} + +RBAExpressionType +RBAHasComeEarlierThan::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAHasComeEarlierThan.hpp b/src/core/expression/RBAHasComeEarlierThan.hpp new file mode 100644 index 0000000..fd39782 --- /dev/null +++ b/src/core/expression/RBAHasComeEarlierThan.hpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * HasComeEarlierThan class header file + */ + +#ifndef RBAHASCOMEEARLIERTHAN_HPP +#define RBAHASCOMEEARLIERTHAN_HPP + +#include "RBAContentOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAHasComeEarlierThan : public RBAContentOperator +{ +public: + RBAHasComeEarlierThan()=default; + RBAHasComeEarlierThan(const RBAHasComeEarlierThan&)=delete; + RBAHasComeEarlierThan(const RBAHasComeEarlierThan&&)=delete; + RBAHasComeEarlierThan& operator=(const RBAHasComeEarlierThan&)=delete; + RBAHasComeEarlierThan& operator=(const RBAHasComeEarlierThan&&)=delete; + virtual ~RBAHasComeEarlierThan()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAHasComeEarlierThanMaker.cpp b/src/core/expression/RBAHasComeEarlierThanMaker.cpp new file mode 100644 index 0000000..fb5eb08 --- /dev/null +++ b/src/core/expression/RBAHasComeEarlierThanMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAHasComeEarlierThanMaker.cpp +/// @brief HasComeEarlierThan object generation class definition file + +#include "RBAHasComeEarlierThanMaker.hpp" +#include "RBAHasComeEarlierThan.hpp" + +namespace rba +{ + +RBAHasComeEarlierThanMaker::RBAHasComeEarlierThanMaker() + : RBAOperatorMaker{"HasComeEarlierThan"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAHasComeEarlierThanMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAHasComeEarlierThan>(); +} + +} diff --git a/src/core/expression/RBAHasComeEarlierThanMaker.hpp b/src/core/expression/RBAHasComeEarlierThanMaker.hpp new file mode 100644 index 0000000..256a4ea --- /dev/null +++ b/src/core/expression/RBAHasComeEarlierThanMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAHasComeEarlierThanMaker.hpp +/// @brief HasComeEarlierThan object generation class header + +#ifndef RBAHASCOMEEARLIERTHANMAKER_HPP +#define RBAHASCOMEEARLIERTHANMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief HasComeEarlierThan object generation class +class RBAHasComeEarlierThanMaker : public RBAOperatorMaker +{ +public: + RBAHasComeEarlierThanMaker(); + RBAHasComeEarlierThanMaker(const RBAHasComeEarlierThanMaker&)=delete; + RBAHasComeEarlierThanMaker(const RBAHasComeEarlierThanMaker&&)=delete; + RBAHasComeEarlierThanMaker& operator=(const RBAHasComeEarlierThanMaker&)=delete; + RBAHasComeEarlierThanMaker& operator=(const RBAHasComeEarlierThanMaker&&)=delete; + virtual ~RBAHasComeEarlierThanMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAHasComeLaterThan.cpp b/src/core/expression/RBAHasComeLaterThan.cpp new file mode 100644 index 0000000..341d164 --- /dev/null +++ b/src/core/expression/RBAHasComeLaterThan.cpp @@ -0,0 +1,153 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * HasComeLaterThan class + */ + +#include "RBAHasComeLaterThan.hpp" + +#include "RBAContent.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void RBAHasComeLaterThan::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAHasComeLaterThan::getModelElementType() const +{ + return RBAModelElementType::HasComeLater; +} + +bool +RBAHasComeLaterThan::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + + bool isResult {false}; + // pop the Content of left hand side expresion + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* ruleObj {getLhsOperand()->getReferenceObject(leftInfo, arb)}; + const RBAContent* contentLhs {nullptr}; + if(ruleObj != nullptr) { + contentLhs = dynamic_cast<const RBAContent*>(ruleObj->getRawObject()); + } + + // pop the Content of left hand side expresion + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + ruleObj = getRhsOperand()->getReferenceObject(rightInfo, arb); + const RBAContent* contentRhs {nullptr}; + if(ruleObj != nullptr) { + contentRhs = dynamic_cast<const RBAContent*>(ruleObj->getRawObject()); + } + + if((contentLhs == nullptr) || (contentRhs == nullptr)) { + info->setExceptionBeforeArbitrate(true); + } else { + if (!((arb->getResult()->isActive(contentLhs)) + && (arb->getResult()->isActive(contentRhs)))) { + info->setExceptionBeforeArbitrate(true); + } + else if(contentLhs == contentRhs) { + isResult = false; + } + else { + isResult = arb->getResult()->isLater(contentLhs, contentRhs); + } + } +#ifdef RBA_USE_LOG + std::string lhsName; + std::string rhsName; + std::string resultText; + if(contentLhs == nullptr) { + lhsName = "NULL"; + } else { + lhsName = contentLhs->getElementName(); + } + if (contentRhs == nullptr) { + rhsName = "NULL"; + } else { + rhsName = contentRhs->getElementName(); + } + if (info->isExceptionBeforeArbitrate() == true ) { + resultText = "is before arbitrate skip"; + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else { + resultText = RBALogManager::boolToString(isResult); + if(isResult) { + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } + else { + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } + } + LOG_arbitrateConstraintLogicLogLine( + " Content[" + lhsName + "] has come later than Content[" + rhsName + "] " + resultText); +#endif + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); + + return isResult; +} + +#ifdef RBA_USE_LOG +const std::string +RBAHasComeLaterThan::getSymbol() const +{ + return ".hasComeLaterThan"; +} + +const std::string +RBAHasComeLaterThan::getExpressionText() const +{ + RBAExpression* exprLhs = getLhsOperand(); + RBAExpression* exprRhs = getRhsOperand(); + return exprLhs->getExpressionText() + getSymbol() + + "(" + exprRhs->getExpressionText() + ")"; +} + +const std::string +RBAHasComeLaterThan::getCoverageExpressionText() const +{ + RBAExpression* exprLhs = getLhsOperand(); + RBAExpression* exprRhs = getRhsOperand(); + return exprLhs->getCoverageExpressionText() + getSymbol() + + "(" + exprRhs->getCoverageExpressionText() + ")"; +} + +RBAExpressionType +RBAHasComeLaterThan::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAHasComeLaterThan.hpp b/src/core/expression/RBAHasComeLaterThan.hpp new file mode 100644 index 0000000..659068f --- /dev/null +++ b/src/core/expression/RBAHasComeLaterThan.hpp @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * HasComeLaterThan class + */ + +#ifndef RBAHASCOMELATERTHAN_HPP +#define RBAHASCOMELATERTHAN_HPP + +#include "RBAContentOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAHasComeLaterThan : public RBAContentOperator +{ +public: + RBAHasComeLaterThan()=default; + RBAHasComeLaterThan(const RBAHasComeLaterThan&)=delete; + RBAHasComeLaterThan(const RBAHasComeLaterThan&&)=delete; + RBAHasComeLaterThan& operator=(const RBAHasComeLaterThan&)=delete; + RBAHasComeLaterThan& operator=(const RBAHasComeLaterThan&&)=delete; + virtual ~RBAHasComeLaterThan()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAHasComeLaterThanMaker.cpp b/src/core/expression/RBAHasComeLaterThanMaker.cpp new file mode 100644 index 0000000..2b49835 --- /dev/null +++ b/src/core/expression/RBAHasComeLaterThanMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAHasComeLaterThanMaker.cpp +/// @brief HasComeLaterThan object generation class definitino file + +#include "RBAHasComeLaterThanMaker.hpp" +#include "RBAHasComeLaterThan.hpp" + +namespace rba +{ + +RBAHasComeLaterThanMaker::RBAHasComeLaterThanMaker() + : RBAOperatorMaker{"HasComeLaterThan"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAHasComeLaterThanMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAHasComeLaterThan>(); +} + +} diff --git a/src/core/expression/RBAHasComeLaterThanMaker.hpp b/src/core/expression/RBAHasComeLaterThanMaker.hpp new file mode 100644 index 0000000..16a42c3 --- /dev/null +++ b/src/core/expression/RBAHasComeLaterThanMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAHasComeLaterThanMaker.hpp +/// @brief HasComeLaterThan object generation class header file + +#ifndef RBAHASCOMELATERTHANMAKER_HPP +#define RBAHASCOMELATERTHANMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief HasComeLaterThan object generation class +class RBAHasComeLaterThanMaker : public RBAOperatorMaker +{ +public: + RBAHasComeLaterThanMaker(); + RBAHasComeLaterThanMaker(const RBAHasComeLaterThanMaker&)=delete; + RBAHasComeLaterThanMaker(const RBAHasComeLaterThanMaker&&)=delete; + RBAHasComeLaterThanMaker& operator=(const RBAHasComeLaterThanMaker&)=delete; + RBAHasComeLaterThanMaker& operator=(const RBAHasComeLaterThanMaker&&)=delete; + virtual ~RBAHasComeLaterThanMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIfStatement.cpp b/src/core/expression/RBAIfStatement.cpp new file mode 100644 index 0000000..d776bf7 --- /dev/null +++ b/src/core/expression/RBAIfStatement.cpp @@ -0,0 +1,268 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * If statement class defintion file + */ + +#include <sstream> +#include "RBAIfStatement.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAIfStatement::setCondition(RBAExpression* const expr) +{ + condition_ = expr; +} + +void +RBAIfStatement::setThenExpression(RBAExpression* const expr) +{ + thenExpression_ = expr; +} + +void +RBAIfStatement::setElseExpression(RBAExpression* const expr) +{ + elseExpression_ = expr; +} + +RBAExpression* const +RBAIfStatement::getCondition() const +{ + return condition_; +} + +RBAExpression* const +RBAIfStatement::getThenExpression() const +{ + return thenExpression_; +} + +RBAExpression* const +RBAIfStatement::getElseExpression() const +{ + return elseExpression_; +} + +void +RBAIfStatement::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAIfStatement::getModelElementType() const +{ + return RBAModelElementType::IfStatement; +} + +bool +RBAIfStatement::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + LOG_addHierarchy("IF"); + bool isPassed; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + LOG_addHierarchy("#condition:"); + const bool cond {getCondition()->execute(leftInfo, arb)}; + LOG_removeHierarchy(); + if (cond == true) { + LOG_addHierarchy("#then:"); + isPassed = getThenExpression()->execute(rightInfo, arb); + LOG_removeHierarchy(); + } else { + LOG_addHierarchy("#else:"); + isPassed = getElseExpression()->execute(rightInfo, arb); + LOG_removeHierarchy(); + } + if ((leftInfo->isExceptionBeforeArbitrate() == true) + || (rightInfo->isExceptionBeforeArbitrate() == true)) { + info->setExceptionBeforeArbitrate(true); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); +#ifdef RBA_USE_LOG + } else if (isPassed == true) { + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); +#endif + } + LOG_removeHierarchy(); + return isPassed; +} + +const RBARuleObject* +RBAIfStatement::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + LOG_addHierarchy("IF"); + const RBARuleObject* object {nullptr}; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + LOG_addHierarchy("#condition:"); + const bool cond {getCondition()->execute(leftInfo, arb)}; + LOG_removeHierarchy(); + if (cond == true) { + LOG_addHierarchy("#then:"); + object = getThenExpression()->getReferenceObject(rightInfo, arb); + LOG_removeHierarchy(); + } else { + LOG_addHierarchy("#else:"); + object = getElseExpression()->getReferenceObject(rightInfo, arb); + LOG_removeHierarchy(); + if ((leftInfo->isExceptionBeforeArbitrate() == true) + || (rightInfo->isExceptionBeforeArbitrate() == true)) { + info->setExceptionBeforeArbitrate(true); + } + } + LOG_removeHierarchy(); + return object; +} + +std::int32_t +RBAIfStatement::getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + LOG_addHierarchy("IF"); + std::int32_t value; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + LOG_addHierarchy("#condition:"); + const bool cond {getCondition()->execute(leftInfo, arb)}; + LOG_removeHierarchy(); + if (cond == true) { + LOG_addHierarchy("#then:"); + value = getThenExpression()->getValue(rightInfo, arb); + LOG_removeHierarchy(); + } else { + LOG_addHierarchy("#else:"); + value = getElseExpression()->getValue(rightInfo, arb); + LOG_removeHierarchy(); + if ((leftInfo->isExceptionBeforeArbitrate() == true) + || (rightInfo->isExceptionBeforeArbitrate() == true)) { + info->setExceptionBeforeArbitrate(true); + } + } + LOG_removeHierarchy(); + return value; +} + +void +RBAIfStatement::doActionCore(RBAConstraintInfo* info, + RBAArbitrator* arb) +{ + LOG_addHierarchy("IF"); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + LOG_addHierarchy("#condition:"); + const bool cond {getCondition()->execute(leftInfo, arb)}; + LOG_removeHierarchy(); + if (cond == true) { + LOG_addHierarchy("#then:"); + getThenExpression()->doAction(rightInfo, arb); + LOG_removeHierarchy(); + } else { + LOG_addHierarchy("#else:"); + getElseExpression()->doAction(rightInfo, arb); + LOG_removeHierarchy(); + } +#ifdef RBA_USE_LOG + LOG_coverageConstraintExpressionLog2(LOG_getCoverageExpressionText()); +#endif + LOG_removeHierarchy(); + return; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIfStatement::getExpressionText() const +{ + std::ostringstream oss; + oss << "IF("; + oss << condition_->getExpressionText(); + oss << ") THEN "; + oss << thenExpression_->getExpressionText(); + oss << " ELSE "; + oss << elseExpression_->getExpressionText(); + + return oss.str(); +} + +const std::string +RBAIfStatement::getCoverageExpressionText() const +{ + std::ostringstream oss; + oss << "IF("; + oss << condition_->getCoverageExpressionText(); + oss << ") THEN "; + oss << thenExpression_->getCoverageExpressionText(); + oss << " ELSE "; + oss << elseExpression_->getCoverageExpressionText(); + + return oss.str(); +} + +void +RBAIfStatement::createHierarchy() +{ + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy("IF"); + RBALogManager::coverageHierarchyOfConstraintExpressionLog(getCoverageExpressionText(), + this); + + // Add condition to the constraint hierarchy for coverage + LOG_addHierarchy("#condition:"); + condition_->createHierarchy(); + // Remove condtion from to the constraint hierarchy for coverage + LOG_removeHierarchy(); + + if(thenExpression_) { + // Add "then" to the constraint hierarchy for coverage + LOG_addHierarchy("#then:"); + thenExpression_->createHierarchy(); + // Remove "then" from the constraint hierarchy for coverage + LOG_removeHierarchy(); + } + + if(elseExpression_) { + // Add "else" to the constraint hierarchy for coverage + LOG_addHierarchy("#else:"); + elseExpression_->createHierarchy(); + // Remove "else" from the constraint hierarchy for coverage + LOG_removeHierarchy(); + } + + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); +} + +RBAExpressionType +RBAIfStatement::getUnderlyingType() const +{ + return thenExpression_->getUnderlyingType(); +} +#endif +} diff --git a/src/core/expression/RBAIfStatement.hpp b/src/core/expression/RBAIfStatement.hpp new file mode 100644 index 0000000..7059583 --- /dev/null +++ b/src/core/expression/RBAIfStatement.hpp @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * If statement class header file + */ + +#ifndef RBAIFSTATEMENT_HPP +#define RBAIFSTATEMENT_HPP + +#include "RBAExpression.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIfStatement : public RBAExpression +{ +public: + RBAIfStatement()=default; + RBAIfStatement(const RBAIfStatement&)=delete; + RBAIfStatement(const RBAIfStatement&&)=delete; + RBAIfStatement& operator=(const RBAIfStatement&)=delete; + RBAIfStatement& operator=(const RBAIfStatement&&)=delete; + virtual ~RBAIfStatement()=default; + +public: + void setCondition(RBAExpression* const expr); + void setThenExpression(RBAExpression* const expr); + void setElseExpression(RBAExpression* const expr); + RBAExpression* const getCondition() const; + RBAExpression* const getThenExpression() const; + RBAExpression* const getElseExpression() const; + + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator* arb) const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + std::int32_t getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + void doActionCore(RBAConstraintInfo* info, RBAArbitrator* arb) override; + + // Log +#ifdef RBA_USE_LOG + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + void createHierarchy() override; + RBAExpressionType getUnderlyingType() const override; +#endif + + private: + RBAExpression* condition_ {nullptr}; + RBAExpression* thenExpression_ {nullptr}; + RBAExpression* elseExpression_ {nullptr}; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIfStatementMaker.cpp b/src/core/expression/RBAIfStatementMaker.cpp new file mode 100644 index 0000000..b878ada --- /dev/null +++ b/src/core/expression/RBAIfStatementMaker.cpp @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIfStatementMaker.cpp +/// @brief IfStatement object generation class definition file + +#include "RBAIfStatementMaker.hpp" +#include "RBAIfStatement.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAIfStatementMaker::RBAIfStatementMaker() + : RBAExpressionMaker{"IfStatement"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIfStatementMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIfStatement>(); +} + +RBAModelElement* +RBAIfStatementMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBAIfStatement* const ifstmt {dynamic_cast<RBAIfStatement*>(element)}; + + // Set LetStatement + const std::int32_t pop_num {setLetStatement(model, ifstmt, jsonElem)}; + + // Set condition + const RBAJsonElement* const condElem {jsonElem->findChildren("condition")}; + RBAModelElement* const condExpr + {getFactory()->createElement(condElem->getClassName(), condElem)}; + ifstmt->setCondition(dynamic_cast<RBAExpression*>(condExpr)); + // Set "then" + const RBAJsonElement* const thenElem {jsonElem->findChildren("thenExpression")}; + RBAModelElement* thenExpr {nullptr}; + if(thenElem != nullptr) { + thenExpr = getFactory()->createElement(thenElem->getClassName(), thenElem); + } + ifstmt->setThenExpression(dynamic_cast<RBAExpression*>(thenExpr)); + // Set "else" + const RBAJsonElement* const elseElem {jsonElem->findChildren("elseExpression")}; + RBAModelElement* elseExpr {nullptr}; + if(elseElem != nullptr) { + elseExpr = getFactory()->createElement(elseElem->getClassName(), elseElem); + } + ifstmt->setElseExpression(dynamic_cast<RBAExpression*>(elseExpr)); + + // Pop variable + for(std::int32_t i{0}; i<pop_num; i++) { + getFactory()->popVariable(); + } + + return ifstmt; +} + +} diff --git a/src/core/expression/RBAIfStatementMaker.hpp b/src/core/expression/RBAIfStatementMaker.hpp new file mode 100644 index 0000000..57a4133 --- /dev/null +++ b/src/core/expression/RBAIfStatementMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIfStatementMaker.hpp +/// @brief IfStatement object generation class header file + +#ifndef RBAIFSTATEMENTMAKER_HPP +#define RBAIFSTATEMENTMAKER_HPP + +#include "RBAExpressionMaker.hpp" + +namespace rba +{ + +/// @brief IfStatement object generation class +class RBAIfStatementMaker : public RBAExpressionMaker +{ +public: + RBAIfStatementMaker(); + RBAIfStatementMaker(const RBAIfStatementMaker&)=delete; + RBAIfStatementMaker(const RBAIfStatementMaker&&)=delete; + RBAIfStatementMaker& operator=(const RBAIfStatementMaker&)=delete; + RBAIfStatementMaker& operator=(const RBAIfStatementMaker&&)=delete; + virtual ~RBAIfStatementMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief set property of Model Element for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model Model for storing generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAImpliesOperator.cpp b/src/core/expression/RBAImpliesOperator.cpp new file mode 100644 index 0000000..ab95dc7 --- /dev/null +++ b/src/core/expression/RBAImpliesOperator.cpp @@ -0,0 +1,145 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /** + * implication operator class defintion file + */ + +#include "RBAImpliesOperator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAImpliesOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAImpliesOperator::getModelElementType() const +{ + return RBAModelElementType::ImpliesOperator; +} + +bool +RBAImpliesOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + // Add "left-hand side formula" to the constraint hierarchy for coverage + LOG_addHierarchy("#left"); + const bool lhsRes {getLhsOperand()->execute(leftInfo, arb)}; + // Remove "left-hand side formula" from the constraint hierarchy for coverage + LOG_removeHierarchy(); + + if (leftInfo->isExceptionBeforeArbitrate() == false) { + if (lhsRes == false) { + isPassed = true; + } else { + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + // Add "right-hand side formula" to the constraint hierarchy for coverage + LOG_addHierarchy("#right"); + const bool rhsRes {getRhsOperand()->execute(rightInfo, arb)}; + // Remove "right-hand side formula" + // from the constraint hierarchy for coverage + LOG_removeHierarchy(); + if (rightInfo->isExceptionBeforeArbitrate() == true) { + info->setExceptionBeforeArbitrate(true); + } else if (rhsRes == true) { + isPassed = true; + } else { + ; + } + } + } else { + info->setExceptionBeforeArbitrate(true); + // Evaluate the right-hand side fromula + // to get the right side allocatable of arbitration target + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + // Add "right-hand side formula" to the constraint hierarchy for coverage + LOG_addHierarchy("#right"); + static_cast<void>(getRhsOperand()->execute(rightInfo, arb)); + // Remove "right-hand side formula" to the constraint hierarchy for coverage + LOG_removeHierarchy(); + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate()) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAImpliesOperator::getSymbol() const +{ + return "->"; +} + +void +RBAImpliesOperator::createHierarchy() +{ + RBAExpression* exprLhs = getLhsOperand(); + RBAExpression* exprRhs = getRhsOperand(); + + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy(getSymbol()); + RBALogManager::coverageHierarchyOfConstraintExpressionLog(getCoverageExpressionText(), this); + + // Add "left-hand side formula" to the constraint hierarchy for coverage + LOG_addHierarchy("#left"); + exprLhs->createHierarchy(); + // Remove "left-hand side formula" from + // the constraint hierarchy for coverage + LOG_removeHierarchy(); + + // Add "right-hand side formula" to the constraint hierarchy for coverage + LOG_addHierarchy("#right"); + exprRhs->createHierarchy(); + // Remove "right-hand side formula" from + // the constraint hierarchy for coverage + LOG_removeHierarchy(); + + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); +} +#endif + +} diff --git a/src/core/expression/RBAImpliesOperator.hpp b/src/core/expression/RBAImpliesOperator.hpp new file mode 100644 index 0000000..cc1cb33 --- /dev/null +++ b/src/core/expression/RBAImpliesOperator.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * implication operator class defintion file + */ + +#ifndef RBAIMPLIESOPERATOR_HPP +#define RBAIMPLIESOPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAImpliesOperator: public RBALogicalOperator +{ +public: + RBAImpliesOperator()=default; + RBAImpliesOperator(const RBAImpliesOperator&)=delete; + RBAImpliesOperator(const RBAImpliesOperator&&)=delete; + RBAImpliesOperator& operator=(const RBAImpliesOperator&)=delete; + RBAImpliesOperator& operator=(const RBAImpliesOperator&&)=delete; + virtual ~RBAImpliesOperator()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + void createHierarchy() override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAImpliesOperatorMaker.cpp b/src/core/expression/RBAImpliesOperatorMaker.cpp new file mode 100644 index 0000000..00b35fa --- /dev/null +++ b/src/core/expression/RBAImpliesOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAImpliesOperatorMaker.cpp +/// @brief ImpliesOperator object generation class definition file + +#include "RBAImpliesOperatorMaker.hpp" +#include "RBAImpliesOperator.hpp" + +namespace rba +{ + +RBAImpliesOperatorMaker::RBAImpliesOperatorMaker() + : RBAOperatorMaker{"ImpliesOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAImpliesOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAImpliesOperator>(); +} + +} diff --git a/src/core/expression/RBAImpliesOperatorMaker.hpp b/src/core/expression/RBAImpliesOperatorMaker.hpp new file mode 100644 index 0000000..466d36a --- /dev/null +++ b/src/core/expression/RBAImpliesOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAImpliesOperatorMaker.hpp +/// @brief ImpliesOperator object generation class header file + +#ifndef RBAIMPLIEDOPERATORMAKER_HPP +#define RBAIMPLIEDOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief ImpliesOperator object generation class +class RBAImpliesOperatorMaker : public RBAOperatorMaker +{ +public: + RBAImpliesOperatorMaker(); + RBAImpliesOperatorMaker(const RBAImpliesOperatorMaker&)=delete; + RBAImpliesOperatorMaker(const RBAImpliesOperatorMaker&&)=delete; + RBAImpliesOperatorMaker& operator=(const RBAImpliesOperatorMaker&)=delete; + RBAImpliesOperatorMaker& operator=(const RBAImpliesOperatorMaker&&)=delete; + virtual ~RBAImpliesOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIntegerValue.cpp b/src/core/expression/RBAIntegerValue.cpp new file mode 100644 index 0000000..aadffb0 --- /dev/null +++ b/src/core/expression/RBAIntegerValue.cpp @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Integer value class definition file + */ + +#include "RBAIntegerValue.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" + +namespace rba +{ + +void +RBAIntegerValue::setValue(const std::int32_t value) +{ + value_ = value; +} + +std::int32_t +RBAIntegerValue::getValue() const +{ + return value_; +} + +RBAModelElementType +RBAIntegerValue::getModelElementType() const +{ + return RBAModelElementType::IntegerValue; +} + +std::int32_t +RBAIntegerValue::getValueCore(RBAConstraintInfo* info, RBAArbitrator * arb) const +{ + return getValue(); +} + +#ifdef RBA_USE_LOG +const std::string +RBAIntegerValue::getExpressionText() const +{ + return std::to_string(value_); +} + +const std::string +RBAIntegerValue::getCoverageExpressionText() const +{ + return getExpressionText(); +} + +void +RBAIntegerValue::createHierarchy() +{ + // No opration + // because there is no hierarchy below this expression +} + +RBAExpressionType +RBAIntegerValue::getUnderlyingType() const +{ + return RBAExpressionType::VALUE; +} +#endif + +} diff --git a/src/core/expression/RBAIntegerValue.hpp b/src/core/expression/RBAIntegerValue.hpp new file mode 100644 index 0000000..44cf8cb --- /dev/null +++ b/src/core/expression/RBAIntegerValue.hpp @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Integer value class + */ + +#ifndef RBAINTEGERVALUE_HPP +#define RBAINTEGERVALUE_HPP + +#include "RBAValueExpression.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIntegerValue : public RBAValueExpression +{ +public: + RBAIntegerValue()=default; + RBAIntegerValue(const RBAIntegerValue&)=delete; + RBAIntegerValue(const RBAIntegerValue&&)=delete; + RBAIntegerValue& operator=(const RBAIntegerValue&)=delete; + RBAIntegerValue& operator=(const RBAIntegerValue&&)=delete; + virtual ~RBAIntegerValue()=default; + +public: + void setValue(const std::int32_t value); + + std::int32_t getValue() const; + RBAModelElementType getModelElementType() const override; + std::int32_t getValueCore(RBAConstraintInfo* info, + RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + void createHierarchy() override; + RBAExpressionType getUnderlyingType() const override; +#endif + + private: + std::int32_t value_ {0}; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIntegerValueMaker.cpp b/src/core/expression/RBAIntegerValueMaker.cpp new file mode 100644 index 0000000..19a21eb --- /dev/null +++ b/src/core/expression/RBAIntegerValueMaker.cpp @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIntegerValueMaker.cpp +/// @brief IntegerValue object generation class definition file + +#include "RBAIntegerValueMaker.hpp" +#include "RBAIntegerValue.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAIntegerValueMaker::RBAIntegerValueMaker() + : RBAExpressionMaker{"IntegerValue"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIntegerValueMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIntegerValue>(); +} + +RBAModelElement* +RBAIntegerValueMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBAIntegerValue* const intVal {dynamic_cast<RBAIntegerValue*>(element)}; + + // Set LetStatement + const std::int32_t pop_num {setLetStatement(model, intVal, jsonElem)}; + + // Set value + const RBAJsonElement* const valueElem {jsonElem->findChildren("value")}; + intVal->setValue(stoi(valueElem->getString())); + + // Pop variable + for(std::int32_t i{0}; i<pop_num; i++) { + getFactory()->popVariable(); + } + + return intVal; +} + +} diff --git a/src/core/expression/RBAIntegerValueMaker.hpp b/src/core/expression/RBAIntegerValueMaker.hpp new file mode 100644 index 0000000..0f637df --- /dev/null +++ b/src/core/expression/RBAIntegerValueMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIntegerValueMaker.hpp +/// @brief IntegerValue object generation class header file + +#ifndef RBAINTEGERVALUEMAKER_HPP +#define RBAINTEGERVALUEMAKER_HPP + +#include "RBAExpressionMaker.hpp" + +namespace rba +{ + +/// @brief IntegerValue object generation class +class RBAIntegerValueMaker : public RBAExpressionMaker +{ +public: + RBAIntegerValueMaker(); + RBAIntegerValueMaker(const RBAIntegerValueMaker&)=delete; + RBAIntegerValueMaker(const RBAIntegerValueMaker&&)=delete; + RBAIntegerValueMaker& operator=(const RBAIntegerValueMaker&)=delete; + RBAIntegerValueMaker& operator=(const RBAIntegerValueMaker&&)=delete; + virtual ~RBAIntegerValueMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief set property of Model Element for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model Model for storing generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsActive.cpp b/src/core/expression/RBAIsActive.cpp new file mode 100644 index 0000000..a89745f --- /dev/null +++ b/src/core/expression/RBAIsActive.cpp @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * IsActive class definition + */ + +#include "RBAIsActive.hpp" +#include "RBAContent.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void RBAIsActive::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAIsActive::getModelElementType() const +{ + return RBAModelElementType::IsActive; +} + +bool +RBAIsActive::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to the constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const ruleObj + {getLhsOperand()->getReferenceObject(leftInfo, arb)}; + if (leftInfo->isExceptionBeforeArbitrate() == true) { + info->setExceptionBeforeArbitrate(true); + } else if (ruleObj != nullptr) { + const RBAContent* const content {dynamic_cast<const RBAContent*>(ruleObj->getRawObject())}; + if (ruleObj->isPrevious()) { + isPassed = arb->getResult()->isPreActive(content); + } else { + isPassed = arb->getResult()->isActive(content); + } + } else { + ; + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " Content[NULL] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (ruleObj != nullptr) { + const RBAContent* content = dynamic_cast<const RBAContent*>(ruleObj + ->getRawObject()); + if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " " + getPreMsg(ruleObj->isPrevious()) + "Content[" + + content->getElementName() + "] is Active"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " " + getPreMsg(ruleObj->isPrevious()) + "Content[" + + content->getElementName() + "] is not Active"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } + } else { + LOG_arbitrateConstraintLogicLogLine(" Content[NULL] is not Active"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from the constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIsActive::getSymbol() const +{ + return ".isActive()"; +} + +RBAExpressionType +RBAIsActive::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAIsActive.hpp b/src/core/expression/RBAIsActive.hpp new file mode 100644 index 0000000..73ab055 --- /dev/null +++ b/src/core/expression/RBAIsActive.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * IsActive class header file + */ + +#ifndef RBAISACTIVE_HPP +#define RBAISACTIVE_HPP + +#include "RBAContentOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIsActive : public RBAContentOperator +{ +public: + RBAIsActive()=default; + RBAIsActive(const RBAIsActive&)=delete; + RBAIsActive(const RBAIsActive&&)=delete; + RBAIsActive& operator=(const RBAIsActive&)=delete; + RBAIsActive& operator=(const RBAIsActive&&)=delete; + virtual ~RBAIsActive()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsActiveMaker.cpp b/src/core/expression/RBAIsActiveMaker.cpp new file mode 100644 index 0000000..6b2e7ee --- /dev/null +++ b/src/core/expression/RBAIsActiveMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsActiveMaker.cpp +/// @brief IsActive object generation class defintion file + +#include "RBAIsActiveMaker.hpp" +#include "RBAIsActive.hpp" + +namespace rba +{ + +RBAIsActiveMaker::RBAIsActiveMaker() + : RBAOperatorMaker{"IsActive"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIsActiveMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIsActive>(); +} + +} diff --git a/src/core/expression/RBAIsActiveMaker.hpp b/src/core/expression/RBAIsActiveMaker.hpp new file mode 100644 index 0000000..15011fb --- /dev/null +++ b/src/core/expression/RBAIsActiveMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsActiveMaker.hpp +/// @brief IsActive object generation class heaer file + +#ifndef RBAISACTIVEMAKER_HPP +#define RBAISACTIVEMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief IsActive object generation class +class RBAIsActiveMaker : public RBAOperatorMaker +{ +public: + RBAIsActiveMaker(); + RBAIsActiveMaker(const RBAIsActiveMaker&)=delete; + RBAIsActiveMaker(const RBAIsActiveMaker&&)=delete; + RBAIsActiveMaker& operator=(const RBAIsActiveMaker&)=delete; + RBAIsActiveMaker& operator=(const RBAIsActiveMaker&&)=delete; + virtual ~RBAIsActiveMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsEqualToOperator.cpp b/src/core/expression/RBAIsEqualToOperator.cpp new file mode 100644 index 0000000..5dfa929 --- /dev/null +++ b/src/core/expression/RBAIsEqualToOperator.cpp @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsEqualToOperator class definitino file + +#include "RBAIsEqualToOperator.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAIsEqualToOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAIsEqualToOperator::getModelElementType() const +{ + return RBAModelElementType::IsEqualToOperator; +} + +bool +RBAIsEqualToOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + const std::int32_t lhsVal {getLhsOperand()->getValue(leftInfo, arb)}; + const std::int32_t rhsVal {getRhsOperand()->getValue(rightInfo, arb)}; + if ((leftInfo->isExceptionBeforeArbitrate() == true) + || (rightInfo->isExceptionBeforeArbitrate() == true) + || (lhsVal == -99) + || (rhsVal == -99)) { + info->setExceptionBeforeArbitrate(true); + } else { + if (lhsVal == rhsVal) { + isPassed = true; + info->addTrueAllocatableFromOperand(); + } else { + info->addFalseAllocatableFromOperand(); + } + } + +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (lhsVal == rhsVal) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIsEqualToOperator::getSymbol() const +{ + return "="; +} + +RBAExpressionType +RBAIsEqualToOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAIsEqualToOperator.hpp b/src/core/expression/RBAIsEqualToOperator.hpp new file mode 100644 index 0000000..d66efed --- /dev/null +++ b/src/core/expression/RBAIsEqualToOperator.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsEqualToOperator class header file + +#ifndef RBAISEQUALTOOPERATOR_HPP +#define RBAISEQUALTOOPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIsEqualToOperator : public RBALogicalOperator +{ +public: + RBAIsEqualToOperator()=default; + RBAIsEqualToOperator(const RBAIsEqualToOperator&)=delete; + RBAIsEqualToOperator(RBAIsEqualToOperator&&)=delete; + RBAIsEqualToOperator& operator=(const RBAIsEqualToOperator&)=delete; + RBAIsEqualToOperator& operator=(RBAIsEqualToOperator&&)=delete; + virtual ~RBAIsEqualToOperator()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsEqualToOperatorMaker.cpp b/src/core/expression/RBAIsEqualToOperatorMaker.cpp new file mode 100644 index 0000000..32717ce --- /dev/null +++ b/src/core/expression/RBAIsEqualToOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsEqualToOperatorMaker.cpp +/// @brief IsEqualToOperator object generation file + +#include "RBAIsEqualToOperatorMaker.hpp" +#include "RBAIsEqualToOperator.hpp" + +namespace rba +{ + +RBAIsEqualToOperatorMaker::RBAIsEqualToOperatorMaker() + : RBAOperatorMaker{"IsEqualToOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIsEqualToOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIsEqualToOperator>(); +} + +} diff --git a/src/core/expression/RBAIsEqualToOperatorMaker.hpp b/src/core/expression/RBAIsEqualToOperatorMaker.hpp new file mode 100644 index 0000000..9d0fa30 --- /dev/null +++ b/src/core/expression/RBAIsEqualToOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsEqualToOperatorMaker.hpp +/// @brief IsEqualToOperator object generation file + +#ifndef RBAISEQUALTOOPERATORMAKER_HPP +#define RBAISEQUALTOOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief IsEqualToOperator object generation class +class RBAIsEqualToOperatorMaker : public RBAOperatorMaker +{ +public: + RBAIsEqualToOperatorMaker(); + RBAIsEqualToOperatorMaker(const RBAIsEqualToOperatorMaker&)=delete; + RBAIsEqualToOperatorMaker(const RBAIsEqualToOperatorMaker&&)=delete; + RBAIsEqualToOperatorMaker& operator=(const RBAIsEqualToOperatorMaker&)=delete; + RBAIsEqualToOperatorMaker& operator=(const RBAIsEqualToOperatorMaker&&)=delete; + virtual ~RBAIsEqualToOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsGreaterThanEqualOperator.cpp b/src/core/expression/RBAIsGreaterThanEqualOperator.cpp new file mode 100644 index 0000000..368bb3b --- /dev/null +++ b/src/core/expression/RBAIsGreaterThanEqualOperator.cpp @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsGreaterThanEqualOperator class definition file + +#include "RBAIsGreaterThanEqualOperator.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAIsGreaterThanEqualOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAIsGreaterThanEqualOperator::getModelElementType() const +{ + return RBAModelElementType::IsGreaterThanEqualOperator; +} + +bool +RBAIsGreaterThanEqualOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + const std::int32_t lhsVal {getLhsOperand()->getValue(leftInfo, arb)}; + const std::int32_t rhsVal {getRhsOperand()->getValue(rightInfo, arb)}; + // If a pre-arbitration exception occurs on either the left side + // or the right side in the reference, throw it higher + if ((leftInfo->isExceptionBeforeArbitrate() == true) + || (rightInfo->isExceptionBeforeArbitrate() == true) + || (lhsVal == -99) + || (rhsVal == -99)) { + info->setExceptionBeforeArbitrate(true); + } else { + if (lhsVal >= rhsVal) { + isPassed = true; + info->addTrueAllocatableFromOperand(); + } else { + info->addFalseAllocatableFromOperand(); + } + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIsGreaterThanEqualOperator::getSymbol() const +{ + return ">="; +} + +RBAExpressionType +RBAIsGreaterThanEqualOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAIsGreaterThanEqualOperator.hpp b/src/core/expression/RBAIsGreaterThanEqualOperator.hpp new file mode 100644 index 0000000..0d5db61 --- /dev/null +++ b/src/core/expression/RBAIsGreaterThanEqualOperator.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsGreaterThanEqualOperator class header file + +#ifndef RBAISGREATERTHANEQUALOPERATOR_HPP +#define RBAISGREATERTHANEQUALOPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIsGreaterThanEqualOperator : public RBALogicalOperator +{ +public: + RBAIsGreaterThanEqualOperator()=default; + RBAIsGreaterThanEqualOperator(const RBAIsGreaterThanEqualOperator&)=delete; + RBAIsGreaterThanEqualOperator(RBAIsGreaterThanEqualOperator&&)=delete; + RBAIsGreaterThanEqualOperator& operator=(const RBAIsGreaterThanEqualOperator&)=delete; + RBAIsGreaterThanEqualOperator& operator=(RBAIsGreaterThanEqualOperator&&)=delete; + virtual ~RBAIsGreaterThanEqualOperator()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsGreaterThanEqualOperatorMaker.cpp b/src/core/expression/RBAIsGreaterThanEqualOperatorMaker.cpp new file mode 100644 index 0000000..e9e23a9 --- /dev/null +++ b/src/core/expression/RBAIsGreaterThanEqualOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsGreaterThanEqualOperatorMaker.cpp +/// @brief IsGreaterThanEqualOperator object generation class + +#include "RBAIsGreaterThanEqualOperatorMaker.hpp" +#include "RBAIsGreaterThanEqualOperator.hpp" + +namespace rba +{ + +RBAIsGreaterThanEqualOperatorMaker::RBAIsGreaterThanEqualOperatorMaker() + : RBAOperatorMaker{"IsGreaterThanEqualOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIsGreaterThanEqualOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIsGreaterThanEqualOperator>(); +} + +} diff --git a/src/core/expression/RBAIsGreaterThanEqualOperatorMaker.hpp b/src/core/expression/RBAIsGreaterThanEqualOperatorMaker.hpp new file mode 100644 index 0000000..e7f470f --- /dev/null +++ b/src/core/expression/RBAIsGreaterThanEqualOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsGreaterThanEqualOperatorMaker.hpp +/// @brief IsGreaterThanEqualOperator object generation class header file + +#ifndef RBAISGREATERTHANEQUALOPERATORMAKER_HPP +#define RBAISGREATERTHANEQUALOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief IsGreaterThanEqualOperator object generation class +class RBAIsGreaterThanEqualOperatorMaker : public RBAOperatorMaker +{ +public: + RBAIsGreaterThanEqualOperatorMaker(); + RBAIsGreaterThanEqualOperatorMaker(const RBAIsGreaterThanEqualOperatorMaker&)=delete; + RBAIsGreaterThanEqualOperatorMaker(const RBAIsGreaterThanEqualOperatorMaker&&)=delete; + RBAIsGreaterThanEqualOperatorMaker& operator=(const RBAIsGreaterThanEqualOperatorMaker&)=delete; + RBAIsGreaterThanEqualOperatorMaker& operator=(const RBAIsGreaterThanEqualOperatorMaker&&)=delete; + virtual ~RBAIsGreaterThanEqualOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsGreaterThanOperator.cpp b/src/core/expression/RBAIsGreaterThanOperator.cpp new file mode 100644 index 0000000..d9153f1 --- /dev/null +++ b/src/core/expression/RBAIsGreaterThanOperator.cpp @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsGreaterThanOperator class definition file + +#include "RBAIsGreaterThanOperator.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +RBAModelElementType +RBAIsGreaterThanOperator::getModelElementType() const +{ + return RBAModelElementType::IsGreaterThanOperator; +} + +void +RBAIsGreaterThanOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +bool +RBAIsGreaterThanOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + const std::int32_t lhsVal {getLhsOperand()->getValue(leftInfo, arb)}; + const std::int32_t rhsVal {getRhsOperand()->getValue(rightInfo, arb)}; + // If a pre-arbitration exception occurs on either the left side + // or the right side in the reference, throw it higher + if ((leftInfo->isExceptionBeforeArbitrate() == true) + || (rightInfo->isExceptionBeforeArbitrate() == true) + || (lhsVal == -99) + || (rhsVal == -99)) { + info->setExceptionBeforeArbitrate(true); + } else { + if (lhsVal > rhsVal) { + isPassed = true; + info->addTrueAllocatableFromOperand(); + } else { + info->addFalseAllocatableFromOperand(); + } + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIsGreaterThanOperator::getSymbol() const +{ + return ">"; +} + +RBAExpressionType +RBAIsGreaterThanOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAIsGreaterThanOperator.hpp b/src/core/expression/RBAIsGreaterThanOperator.hpp new file mode 100644 index 0000000..9e0938b --- /dev/null +++ b/src/core/expression/RBAIsGreaterThanOperator.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsGreaterThanOperator class header file + +#ifndef RBAISGREATERTHANOPERATOR_HPP +#define RBAISGREATERTHANOPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIsGreaterThanOperator : public RBALogicalOperator +{ +public: + RBAIsGreaterThanOperator()=default; + RBAIsGreaterThanOperator(const RBAIsGreaterThanOperator&)=delete; + RBAIsGreaterThanOperator(RBAIsGreaterThanOperator&&)=delete; + RBAIsGreaterThanOperator& operator=(const RBAIsGreaterThanOperator&)=delete; + RBAIsGreaterThanOperator& operator=(RBAIsGreaterThanOperator&&)=delete; + virtual ~RBAIsGreaterThanOperator()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsGreaterThanOperatorMaker.cpp b/src/core/expression/RBAIsGreaterThanOperatorMaker.cpp new file mode 100644 index 0000000..37a2888 --- /dev/null +++ b/src/core/expression/RBAIsGreaterThanOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsGreaterThanEqualOperatorMaker.cpp +/// @brief IsGreaterThanEqualOperator object generation class definition file + +#include "RBAIsGreaterThanOperatorMaker.hpp" +#include "RBAIsGreaterThanOperator.hpp" + +namespace rba +{ + +RBAIsGreaterThanOperatorMaker::RBAIsGreaterThanOperatorMaker() + : RBAOperatorMaker{"IsGreaterThanOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIsGreaterThanOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIsGreaterThanOperator>(); +} + +} diff --git a/src/core/expression/RBAIsGreaterThanOperatorMaker.hpp b/src/core/expression/RBAIsGreaterThanOperatorMaker.hpp new file mode 100644 index 0000000..40bfc17 --- /dev/null +++ b/src/core/expression/RBAIsGreaterThanOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsGreaterThanEqualOperatorMaker.hpp +/// @brief IsGreaterThanEqualOperator object generation class header file + +#ifndef RBAISGREATERTHANOPERATORMAKER_HPP +#define RBAISGREATERTHANOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief IsGreaterThanEqualOperator object generation class +class RBAIsGreaterThanOperatorMaker : public RBAOperatorMaker +{ +public: + RBAIsGreaterThanOperatorMaker(); + RBAIsGreaterThanOperatorMaker(const RBAIsGreaterThanOperatorMaker&)=delete; + RBAIsGreaterThanOperatorMaker(const RBAIsGreaterThanOperatorMaker&&)=delete; + RBAIsGreaterThanOperatorMaker& operator=(const RBAIsGreaterThanOperatorMaker&)=delete; + RBAIsGreaterThanOperatorMaker& operator=(const RBAIsGreaterThanOperatorMaker&&)=delete; + virtual ~RBAIsGreaterThanOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsLowerThanEqualOperator.cpp b/src/core/expression/RBAIsLowerThanEqualOperator.cpp new file mode 100644 index 0000000..811b34d --- /dev/null +++ b/src/core/expression/RBAIsLowerThanEqualOperator.cpp @@ -0,0 +1,106 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsLowerThanEqualOperator class definition file + +#include "RBAIsLowerThanEqualOperator.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" + +namespace rba +{ + +void +RBAIsLowerThanEqualOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAIsLowerThanEqualOperator::getModelElementType() const +{ + return RBAModelElementType::IsLowerThanEqualOperator; +} + +bool +RBAIsLowerThanEqualOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + const std::int32_t lhsVal {getLhsOperand()->getValue(leftInfo, arb)}; + const std::int32_t rhsVal {getRhsOperand()->getValue(rightInfo, arb)}; + // If a pre-arbitration exception occurs on either the left side + // or the right side in the reference, throw it higher + if ((leftInfo->isExceptionBeforeArbitrate() == true) + || (rightInfo->isExceptionBeforeArbitrate() == true) + || (lhsVal == -99) + || (rhsVal == -99)) { + info->setExceptionBeforeArbitrate(true); + } else { + if (lhsVal <= rhsVal) { + isPassed = true; + info->addTrueAllocatableFromOperand(); + } else { + info->addFalseAllocatableFromOperand(); + } + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIsLowerThanEqualOperator::getSymbol() const +{ + return "<="; +} + +RBAExpressionType +RBAIsLowerThanEqualOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAIsLowerThanEqualOperator.hpp b/src/core/expression/RBAIsLowerThanEqualOperator.hpp new file mode 100644 index 0000000..3459110 --- /dev/null +++ b/src/core/expression/RBAIsLowerThanEqualOperator.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsLowerThanEqualOperator class header file + +#ifndef RBAISLOWERTHANEQUALOPERATOR_HPP +#define RBAISLOWERTHANEQUALOPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIsLowerThanEqualOperator : public RBALogicalOperator +{ +public: + RBAIsLowerThanEqualOperator()=default; + RBAIsLowerThanEqualOperator(const RBAIsLowerThanEqualOperator&)=delete; + RBAIsLowerThanEqualOperator(RBAIsLowerThanEqualOperator&&)=delete; + RBAIsLowerThanEqualOperator& operator=(const RBAIsLowerThanEqualOperator&)=delete; + RBAIsLowerThanEqualOperator& operator=(RBAIsLowerThanEqualOperator&&)=delete; + virtual ~RBAIsLowerThanEqualOperator()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsLowerThanEqualOperatorMaker.cpp b/src/core/expression/RBAIsLowerThanEqualOperatorMaker.cpp new file mode 100644 index 0000000..a04a52b --- /dev/null +++ b/src/core/expression/RBAIsLowerThanEqualOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsLowerThanEqualOperatorMaker.cpp +/// @brief IsLowerThanEqualOperator object geneation class defintion file + +#include "RBAIsLowerThanEqualOperatorMaker.hpp" +#include "RBAIsLowerThanEqualOperator.hpp" + +namespace rba +{ + +RBAIsLowerThanEqualOperatorMaker::RBAIsLowerThanEqualOperatorMaker() + : RBAOperatorMaker{"IsLowerThanEqualOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIsLowerThanEqualOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIsLowerThanEqualOperator>(); +} + +} diff --git a/src/core/expression/RBAIsLowerThanEqualOperatorMaker.hpp b/src/core/expression/RBAIsLowerThanEqualOperatorMaker.hpp new file mode 100644 index 0000000..10cf469 --- /dev/null +++ b/src/core/expression/RBAIsLowerThanEqualOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsLowerThanEqualOperatorMaker.hpp +/// @brief IsLowerThanEqualOperator object geneation class header file + +#ifndef RBAISLOWERTHANEQUALOPERATORMAKER_HPP +#define RBAISLOWERTHANEQUALOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief IsLowerThanEqualOperator object generation class +class RBAIsLowerThanEqualOperatorMaker : public RBAOperatorMaker +{ +public: + RBAIsLowerThanEqualOperatorMaker(); + RBAIsLowerThanEqualOperatorMaker(const RBAIsLowerThanEqualOperatorMaker&)=delete; + RBAIsLowerThanEqualOperatorMaker(const RBAIsLowerThanEqualOperatorMaker&&)=delete; + RBAIsLowerThanEqualOperatorMaker& operator=(const RBAIsLowerThanEqualOperatorMaker&)=delete; + RBAIsLowerThanEqualOperatorMaker& operator=(const RBAIsLowerThanEqualOperatorMaker&&)=delete; + virtual ~RBAIsLowerThanEqualOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsLowerThanOperator.cpp b/src/core/expression/RBAIsLowerThanOperator.cpp new file mode 100644 index 0000000..99a7860 --- /dev/null +++ b/src/core/expression/RBAIsLowerThanOperator.cpp @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsLowerThanOperator class definition file + +#include "RBAIsLowerThanOperator.hpp" +#include "RBAArbitrator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAIsLowerThanOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAIsLowerThanOperator::getModelElementType() const +{ + return RBAModelElementType::IsLowerThanOperator; +} + +bool +RBAIsLowerThanOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + const std::int32_t lhsVal {getLhsOperand()->getValue(leftInfo, arb)}; + const std::int32_t rhsVal {getRhsOperand()->getValue(rightInfo, arb)}; + // If a pre-arbitration exception occurs on either the left side + // or the right side in the reference, throw it higher + if ((leftInfo->isExceptionBeforeArbitrate() == true) + || (rightInfo->isExceptionBeforeArbitrate() == true) + || (lhsVal == -99) + || (rhsVal == -99)) { + info->setExceptionBeforeArbitrate(true); + } else { + if (lhsVal < rhsVal) { + isPassed = true; + info->addTrueAllocatableFromOperand(); + } else { + info->addFalseAllocatableFromOperand(); + } + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIsLowerThanOperator::getSymbol() const +{ + return "<"; +} + +RBAExpressionType +RBAIsLowerThanOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAIsLowerThanOperator.hpp b/src/core/expression/RBAIsLowerThanOperator.hpp new file mode 100644 index 0000000..3a23e45 --- /dev/null +++ b/src/core/expression/RBAIsLowerThanOperator.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// IsLowerThanOperator class header file + +#ifndef RBAISLOWERTHANOPERATOR_HPP +#define RBAISLOWERTHANOPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIsLowerThanOperator : public RBALogicalOperator +{ +public: + RBAIsLowerThanOperator()=default; + RBAIsLowerThanOperator(const RBAIsLowerThanOperator&)=delete; + RBAIsLowerThanOperator(RBAIsLowerThanOperator&&)=delete; + RBAIsLowerThanOperator& operator=(const RBAIsLowerThanOperator&)=delete; + RBAIsLowerThanOperator& operator=(RBAIsLowerThanOperator&&)=delete; + virtual ~RBAIsLowerThanOperator()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsLowerThanOperatorMaker.cpp b/src/core/expression/RBAIsLowerThanOperatorMaker.cpp new file mode 100644 index 0000000..f6ddf53 --- /dev/null +++ b/src/core/expression/RBAIsLowerThanOperatorMaker.cpp @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/// @file RBAIsLowerThanOperatorMaker.cpp +/// @brief IsLowerThanOperator object gerneation class + +#include "RBAIsLowerThanOperatorMaker.hpp" +#include "RBAIsLowerThanOperator.hpp" + +namespace rba +{ + +RBAIsLowerThanOperatorMaker::RBAIsLowerThanOperatorMaker() + : RBAOperatorMaker{"IsLowerThanOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIsLowerThanOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIsLowerThanOperator>(); +} + +} diff --git a/src/core/expression/RBAIsLowerThanOperatorMaker.hpp b/src/core/expression/RBAIsLowerThanOperatorMaker.hpp new file mode 100644 index 0000000..d2c6870 --- /dev/null +++ b/src/core/expression/RBAIsLowerThanOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsLowerThanOperatorMaker.hpp +/// @brief IsLowerThanOperator object gerneation class header file + +#ifndef RBAISLOWERTHANOPERATORMAKER_HPP +#define RBAISLOWERTHANOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief sLowerThanOperator object gerneation class +class RBAIsLowerThanOperatorMaker : public RBAOperatorMaker +{ +public: + RBAIsLowerThanOperatorMaker(); + RBAIsLowerThanOperatorMaker(const RBAIsLowerThanOperatorMaker&)=delete; + RBAIsLowerThanOperatorMaker(const RBAIsLowerThanOperatorMaker&&)=delete; + RBAIsLowerThanOperatorMaker& operator=(const RBAIsLowerThanOperatorMaker&)=delete; + RBAIsLowerThanOperatorMaker& operator=(const RBAIsLowerThanOperatorMaker&&)=delete; + virtual ~RBAIsLowerThanOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsOn.cpp b/src/core/expression/RBAIsOn.cpp new file mode 100644 index 0000000..f8dd769 --- /dev/null +++ b/src/core/expression/RBAIsOn.cpp @@ -0,0 +1,132 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * IsOn class (to judge if a Scene is active) definition file + */ + +#include "RBAIsOn.hpp" +#include "RBAArbitrator.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBASceneImpl.hpp" +#include "RBALogManager.hpp" +#include "RBAExpressionType.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +void +RBAIsOn::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAIsOn::getModelElementType() const +{ + return RBAModelElementType::IsOn; +} + +bool +RBAIsOn::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const ruleObj + {getLhsOperand()->getReferenceObject(leftInfo, arb)}; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else if (ruleObj != nullptr){ + const RBASceneImpl* const scene {dynamic_cast<const RBASceneImpl*>(ruleObj->getRawObject())}; + if (ruleObj->isPrevious() == false) { + isPassed = arb->getResult()->isActive(scene); + } else { + isPassed = arb->getResult()->isPreActive(scene); + } + } else { + // Currently, there is no expression that returns null as "Scene", + // so it does not go through this path. But an expression that returns null + // may be added in the future, so it is described as it is. + ; + } +#ifdef RBA_USE_LOG + if (ruleObj != nullptr) { + const RBASceneImpl* scene = dynamic_cast<const RBASceneImpl*>(ruleObj + ->getRawObject()); + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " Scene[" + scene->getName() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " " + getPreMsg(ruleObj->isPrevious()) + "Scene[" + + scene->getName() + "] is On"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " " + getPreMsg(ruleObj->isPrevious()) + "Scene[" + + scene->getName() + "] is not On"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } + } else { + // Currently, there is no expression that returns null as "Scene", + // so it does not go through this path. But an expression that returns null + // may be added in the future, so it is described as it is. + LOG_arbitrateConstraintLogicLogLine( + " " + getPreMsg(ruleObj->isPrevious()) + "Scene[NULL] is not On"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIsOn::getSymbol() const +{ + return ".isOn()"; +} + +const std::string +RBAIsOn::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol(); +} + +const std::string RBAIsOn::getCoverageExpressionText() const +{ + return getLhsOperand()->getCoverageExpressionText() + getSymbol(); +} + +RBAExpressionType +RBAIsOn::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAIsOn.hpp b/src/core/expression/RBAIsOn.hpp new file mode 100644 index 0000000..9f3f778 --- /dev/null +++ b/src/core/expression/RBAIsOn.hpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * IsOn class (to judge if a Scene is active) header + */ + +#ifndef RBAISON_HPP +#define RBAISON_HPP + +#include "RBASceneOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIsOn : public RBASceneOperator +{ +public: + RBAIsOn()=default; + RBAIsOn(const RBAIsOn&)=delete; + RBAIsOn(const RBAIsOn&&)=delete; + RBAIsOn& operator=(const RBAIsOn&)=delete; + RBAIsOn& operator=(const RBAIsOn&&)=delete; + virtual ~RBAIsOn()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsOnMaker.cpp b/src/core/expression/RBAIsOnMaker.cpp new file mode 100644 index 0000000..79a4e16 --- /dev/null +++ b/src/core/expression/RBAIsOnMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsOnMaker.cpp +/// @brief IsOn (to judge if a Scene is active) class generation definition + +#include "RBAIsOnMaker.hpp" +#include "RBAIsOn.hpp" + +namespace rba +{ + +RBAIsOnMaker::RBAIsOnMaker() + : RBAOperatorMaker{"IsOn"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIsOnMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIsOn>(); +} + +} diff --git a/src/core/expression/RBAIsOnMaker.hpp b/src/core/expression/RBAIsOnMaker.hpp new file mode 100644 index 0000000..824d091 --- /dev/null +++ b/src/core/expression/RBAIsOnMaker.hpp @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsOnMaker.hpp +/// @brief IsOn object generation class header file +/// IsOn is class to judge if a Scene is active + +#ifndef RBAISONMAKER_HPP +#define RBAISONMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief IsOn object generation class +class RBAIsOnMaker : public RBAOperatorMaker +{ +public: + RBAIsOnMaker(); + RBAIsOnMaker(const RBAIsOnMaker&)=delete; + RBAIsOnMaker(const RBAIsOnMaker&&)=delete; + RBAIsOnMaker& operator=(const RBAIsOnMaker&)=delete; + RBAIsOnMaker& operator=(const RBAIsOnMaker&&)=delete; + virtual ~RBAIsOnMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAIsTypeOfOperator.cpp b/src/core/expression/RBAIsTypeOfOperator.cpp new file mode 100644 index 0000000..2104f43 --- /dev/null +++ b/src/core/expression/RBAIsTypeOfOperator.cpp @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// IsTypeOf class defintion file +// + +#include "RBAIsTypeOfOperator.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAExpressionType.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBAModelElementType.hpp" +#include "RBALogManager.hpp" +#include "RBARuleObject.hpp" + +namespace rba +{ + +void RBAIsTypeOfOperator::setTag(const std::string& tag) +{ + tagId_ = tag; +} + +void RBAIsTypeOfOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} +RBAModelElementType RBAIsTypeOfOperator::getModelElementType() const +{ + return RBAModelElementType::IsTypeOfOperator; +} +bool RBAIsTypeOfOperator::executeCore(RBAConstraintInfo* info, RBAArbitrator* arb) const +{ + bool isPassed {false}; + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo * const leftInfo {info->getChild(0U)}; + const RBARuleObject* const ruleObj {getLhsOperand()->getReferenceObject(leftInfo, + arb)}; + if (leftInfo->isExceptionBeforeArbitrate() == true) { + info->setExceptionBeforeArbitrate(true); + } else if (ruleObj != nullptr) { + isPassed = ruleObj->containsTag(tagId_); + } else { + ; + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate()) { + LOG_arbitrateConstraintLogicLogLine( + " " + getExpressionText() + " before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if ((ruleObj == nullptr) || (!isPassed)) { + LOG_arbitrateConstraintLogicLogLine( + " " + getExpressionText() + " false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " " + getExpressionText() + " true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } +#endif + LOG_removeHierarchy(); + return isPassed; +} +#ifdef RBA_USE_LOG +const std::string RBAIsTypeOfOperator::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol(); +} + +const std::string RBAIsTypeOfOperator::getCoverageExpressionText() const +{ + return getLhsOperand()->getCoverageExpressionText() + getSymbol(); +} + +const std::string RBAIsTypeOfOperator::getSymbol() const +{ + return ".isTypeOf(" + tagId_ + ")"; +} + +RBAExpressionType RBAIsTypeOfOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif +} +/* namespace rba */ diff --git a/src/core/expression/RBAIsTypeOfOperator.hpp b/src/core/expression/RBAIsTypeOfOperator.hpp new file mode 100644 index 0000000..ce4d213 --- /dev/null +++ b/src/core/expression/RBAIsTypeOfOperator.hpp @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// IsTypeOfクラスヘッダファイル +// + +#ifndef RBAISTYPEOFOPERATOR_HPP +#define RBAISTYPEOFOPERATOR_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAIsTypeOfOperator : public RBAOperator +{ + public: + RBAIsTypeOfOperator()=default; + RBAIsTypeOfOperator(const RBAIsTypeOfOperator&)=delete; + RBAIsTypeOfOperator(const RBAIsTypeOfOperator&&)=delete; + RBAIsTypeOfOperator& operator=(const RBAIsTypeOfOperator&)=delete; + RBAIsTypeOfOperator& operator=(const RBAIsTypeOfOperator&&)=delete; + virtual ~RBAIsTypeOfOperator()=default; + + public: + void setTag(const std::string& tag); + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + const std::string getSymbol() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::string tagId_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} /* namespace rba */ + +#endif /* RBAISTYPEOFOPERATOR_HPP */ diff --git a/src/core/expression/RBAIsTypeOfOperatorMaker.cpp b/src/core/expression/RBAIsTypeOfOperatorMaker.cpp new file mode 100644 index 0000000..cabd83c --- /dev/null +++ b/src/core/expression/RBAIsTypeOfOperatorMaker.cpp @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsTypeOfOperatorMaker.cpp +/// @brief IsTypeOf object generation class + +#include "RBAIsTypeOfOperatorMaker.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBAIsTypeOfOperator.hpp" + +namespace rba +{ + +RBAIsTypeOfOperatorMaker::RBAIsTypeOfOperatorMaker() + : RBAOperatorMaker{"IsTypeOf"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAIsTypeOfOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAIsTypeOfOperator>(); +} + +RBAModelElement* +RBAIsTypeOfOperatorMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBAIsTypeOfOperator* const isTypeOfOpe + {dynamic_cast<RBAIsTypeOfOperator*>(element)}; + + // Set LetStatement + const std::int32_t pop_num {setLetStatement(model, isTypeOfOpe, jsonElem)}; + + // Set operand + const RBAJsonElement* const operand {jsonElem->findChildren("operand")}; + const RBAJsonElement* const param {operand->getChild()}; + RBAModelElement* const expr {getFactory()->createElement(param->getClassName(), param)}; + isTypeOfOpe->addOperand(dynamic_cast<RBAExpression*>(expr)); + // Set Tag + const RBAJsonElement* const tagElem {jsonElem->findChildren("tagName")}; + isTypeOfOpe->setTag(tagElem->getString()); + + // Pop variable + for(std::int32_t i{0}; i<pop_num; i++) { + getFactory()->popVariable(); + } + + return isTypeOfOpe; +} + +} diff --git a/src/core/expression/RBAIsTypeOfOperatorMaker.hpp b/src/core/expression/RBAIsTypeOfOperatorMaker.hpp new file mode 100644 index 0000000..5877267 --- /dev/null +++ b/src/core/expression/RBAIsTypeOfOperatorMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAIsTypeOfOperatorMaker.hpp +/// @brief IsTypeOf object geneation class header file + +#ifndef RBAISTYPEOFOPERATORMAKER_HPP +#define RBAISTYPEOFOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief IsTypeOf object geneation class +class RBAIsTypeOfOperatorMaker : public RBAOperatorMaker +{ +public: + RBAIsTypeOfOperatorMaker(); + RBAIsTypeOfOperatorMaker(const RBAIsTypeOfOperatorMaker&)=delete; + RBAIsTypeOfOperatorMaker(const RBAIsTypeOfOperatorMaker&&)=delete; + RBAIsTypeOfOperatorMaker& operator=(const RBAIsTypeOfOperatorMaker&)=delete; + RBAIsTypeOfOperatorMaker& operator=(const RBAIsTypeOfOperatorMaker&&)=delete; + virtual ~RBAIsTypeOfOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + +}; + +} + +#endif diff --git a/src/core/expression/RBALambdaContext.cpp b/src/core/expression/RBALambdaContext.cpp new file mode 100644 index 0000000..7d68513 --- /dev/null +++ b/src/core/expression/RBALambdaContext.cpp @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * LambdaContext class definition file + */ + +#include "RBALambdaContext.hpp" +#include "RBALogManager.hpp" +#include "RBAVariable.hpp" +#include "RBAAllocatable.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAContent.hpp" +#include "RBAContentSet.hpp" +#include "RBALambdaExpression.hpp" + +namespace rba +{ + +RBALambdaExpression* const +RBALambdaContext::getLambda() const +{ + return lambda_; +} + +void +RBALambdaContext::setLambda(RBALambdaExpression* const newLambda) +{ + lambda_ = newLambda; +} + +#ifdef RBA_USE_LOG +void +RBALambdaContext::createHierarchy() +{ + lambda_->getX()->clearRuleObj(); + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(getSymbol()); + RBALogManager::coverageHierarchyOfConstraintExpressionLog(getCoverageExpressionText(), this); + + // Get rule object and loop + RBAExpression* setObj = getLhsOperand(); + RBAConstraintInfo dummyInfo; + // Since it is not referenced by "AllInstanceOf..." or "SetOfOperator" + // used for the set of "For-All" or "Exists", nullptr is no problem + RBAArbitrator* dummyArb = nullptr; + const RBARuleObject* objset = setObj->getReferenceObject(&dummyInfo, dummyArb); + std::vector<const RBARuleObject*> objs; + if(objset) { + if(dynamic_cast<const RBAAllocatableSet*>(objset) != nullptr) { + const RBAAllocatableSet* aSet + = dynamic_cast<const RBAAllocatableSet*>(objset); + for(const auto& alloc : aSet->getLeafAllocatable()) { + objs.push_back(alloc); + } + } + else if(dynamic_cast<const RBAContentSet*>(objset) != nullptr) { + const RBAContentSet* cSet = dynamic_cast<const RBAContentSet*>(objset); + for(const auto& cont : cSet->getLeafContent() ){ + objs.push_back(cont); + } + } + } + + // Enable expansion of own variables in the coverage log + std::int32_t idx=0; + for(const RBARuleObject* obj : objs) { + LOG_addHierarchy("#" + std::to_string(idx++)); + lambda_->getX()->setRuleObj(obj); + lambda_->createHierarchy(); + LOG_removeHierarchy(); + } + + // Remove own to Constraint hierarchy for coverage + LOG_removeHierarchy(); +} +#endif + +} diff --git a/src/core/expression/RBALambdaContext.hpp b/src/core/expression/RBALambdaContext.hpp new file mode 100644 index 0000000..219be71 --- /dev/null +++ b/src/core/expression/RBALambdaContext.hpp @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * LambdaContext class header file + */ + +#ifndef RBALAMBDACONTEXT_HPP +#define RBALAMBDACONTEXT_HPP + +#include "RBASetOperator.hpp" + +namespace rba +{ + +class RBALambdaExpression; + +class DLL_EXPORT RBALambdaContext : public RBASetOperator +{ +protected: + RBALambdaContext()=default; + RBALambdaContext(const RBALambdaContext&)=delete; + RBALambdaContext(const RBALambdaContext&&)=delete; + RBALambdaContext& operator=(const RBALambdaContext&)=delete; + RBALambdaContext& operator=(const RBALambdaContext&&)=delete; +public: + virtual ~RBALambdaContext()=default; + +public: + RBALambdaExpression* const getLambda() const; + void setLambda(RBALambdaExpression* const newLambda); + +#ifdef RBA_USE_LOG + void createHierarchy() override; +#endif + +private: + RBALambdaExpression* lambda_ {nullptr}; + +}; + +} + +#endif diff --git a/src/core/expression/RBALambdaContextMaker.cpp b/src/core/expression/RBALambdaContextMaker.cpp new file mode 100644 index 0000000..f0e7e4d --- /dev/null +++ b/src/core/expression/RBALambdaContextMaker.cpp @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBALambdaContextMaker.cpp +/// @brief LambdaContext object generation abstract class definition + +#include "RBALambdaContextMaker.hpp" +#include "RBALambdaContext.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBALambdaExpression.hpp" + +namespace rba +{ + +RBALambdaContextMaker::RBALambdaContextMaker(const std::string& label) + : RBAOperatorMaker{label} +{ +} + +RBAModelElement* +RBALambdaContextMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBALambdaContext* const lambdaContext + {dynamic_cast<RBALambdaContext*>(element)}; + + // Set LetStatement + const std::int32_t pop_num {setLetStatement(model, lambdaContext, jsonElem)}; + // Set lambda + const RBAJsonElement* const lambdaElement {jsonElem->findChildren("lambda")}; + RBAModelElement* const lambdaExpr + {getFactory()->createElement(lambdaElement->getClassName(), lambdaElement)}; + lambdaContext->setLambda(dynamic_cast<RBALambdaExpression*>(lambdaExpr)); + // Set operand + const RBAJsonElement* const param {jsonElem->findChildren("operand")->getChild()}; + RBAModelElement* const expr + {getFactory()->createElement(param->getClassName(), param)}; + lambdaContext->addOperand(dynamic_cast<RBAExpression*>(expr)); + // Pop variable + for(std::int32_t i{0}; i<pop_num; i++) { + getFactory()->popVariable(); + } + + return lambdaContext; +} + +} diff --git a/src/core/expression/RBALambdaContextMaker.hpp b/src/core/expression/RBALambdaContextMaker.hpp new file mode 100644 index 0000000..6df7001 --- /dev/null +++ b/src/core/expression/RBALambdaContextMaker.hpp @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBALambdaContextMaker.cpp +/// @brief LambdaContext object generation abstract class header file + +#ifndef RBASETOPERATORMAKER_HPP +#define RBASETOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +class RBALambdaContext; + +/// @brief LambdaContext object generation abstract class +class RBALambdaContextMaker : public RBAOperatorMaker +{ +public: + explicit RBALambdaContextMaker(const std::string& label=""); + RBALambdaContextMaker(const RBALambdaContextMaker&)=delete; + RBALambdaContextMaker(const RBALambdaContextMaker&&)=delete; + RBALambdaContextMaker& operator=(const RBALambdaContextMaker&)=delete; + RBALambdaContextMaker& operator=(const RBALambdaContextMaker&&)=delete; + virtual ~RBALambdaContextMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + + /// @brief generate an empty object of LambdaContext + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for LambdaContext object + virtual std::unique_ptr<RBALambdaContext> createLambdaContext()=0; + +}; + +} + +#endif diff --git a/src/core/expression/RBALambdaExpression.cpp b/src/core/expression/RBALambdaExpression.cpp new file mode 100644 index 0000000..7638faa --- /dev/null +++ b/src/core/expression/RBALambdaExpression.cpp @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * RBALambdaExpression class defnition + */ + +#include "RBALambdaExpression.hpp" +#include "RBAVariable.hpp" +#include "RBAArbitrator.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +void +RBALambdaExpression::setX(RBAVariable* const x) +{ + variable_ = x; +} + +void +RBALambdaExpression::setBodyText(RBAExpression* const expr) +{ + bodyText_ = expr; +} + +RBAVariable* const +RBALambdaExpression::getX() const +{ + return variable_; +} + +RBAExpression* const +RBALambdaExpression::getBodyText() const +{ + return bodyText_; +} + +RBAModelElementType +RBALambdaExpression::getModelElementType() const +{ + return RBAModelElementType::LambdaExpression; +} + +bool +RBALambdaExpression::executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const +{ + getX()->setRuleObj(ruleObj_); + + RBAConstraintInfo* const childInfo {info->getChild(0U)}; + bool res {getBodyText()->execute(childInfo,arb)}; + if(childInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + res = false; + } + + return res; +} + +const RBARuleObject* +RBALambdaExpression::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + getX()->setRuleObj(ruleObj_); + + RBAConstraintInfo* const childInfo {info->getChild(0U)}; + const RBARuleObject* const res {getBodyText()->getReferenceObject(childInfo, arb)}; + if (childInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } + + return res; +} +std::int32_t +RBALambdaExpression::getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + getX()->setRuleObj(ruleObj_); + + RBAConstraintInfo* const childInfo {info->getChild(0U)}; + const std::int32_t res {getBodyText()->getValue(childInfo, arb)}; + if (childInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } + + return res; +} +#ifdef RBA_USE_LOG +void +RBALambdaExpression::createHierarchy() +{ + bodyText_->createHierarchy(); +} + +const std::string +RBALambdaExpression::getExpressionText() const +{ + return "{ " + getX()->getElementName() + " |" + + bodyText_->getExpressionText() + "}"; +} + +const std::string +RBALambdaExpression::getCoverageExpressionText() const +{ + return "{ " + getX()->getElementName() + " |" + + bodyText_->getCoverageExpressionText() + "}"; +} +#endif + +void +RBALambdaExpression::setRuleObj(const RBARuleObject* const ruleObj) +{ + ruleObj_ = ruleObj; + getX()->setRuleObj(ruleObj); +} + +void +RBALambdaExpression::clearRuleObj() +{ + ruleObj_ = nullptr; + getX()->clearRuleObj(); +} + +} diff --git a/src/core/expression/RBALambdaExpression.hpp b/src/core/expression/RBALambdaExpression.hpp new file mode 100644 index 0000000..76958e7 --- /dev/null +++ b/src/core/expression/RBALambdaExpression.hpp @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * RBALambdaExpression class header + */ + +#ifndef RBALAMBDAEXPRESSION_HPP +#define RBALAMBDAEXPRESSION_HPP + +#include "RBAExpression.hpp" + +namespace rba +{ + +class RBAArbitrator; +class RBAConstraintInfo; +class RBAVariable; +class RBARuleObject; + +class DLL_EXPORT RBALambdaExpression : public RBAExpression +{ +public: + RBALambdaExpression()=default; + RBALambdaExpression(const RBALambdaExpression&)=delete; + RBALambdaExpression(const RBALambdaExpression&&)=delete; + RBALambdaExpression& operator=(const RBALambdaExpression&)=delete; + RBALambdaExpression& operator=(const RBALambdaExpression&&)=delete; + virtual ~RBALambdaExpression()=default; + +public: + void setX(RBAVariable* const x); + void setBodyText(RBAExpression* const expr); + RBAVariable* const getX() const; + RBAExpression* const getBodyText() const; + + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator* arb) const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + std::int32_t getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + + void setRuleObj(const RBARuleObject* const ruleObj); + void clearRuleObj(); + + // Log +#ifdef RBA_USE_LOG + void createHierarchy(); + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; +#endif + +private: + // "variable" is not const because it calls setExpression() + // in the arbitration process. + RBAVariable* variable_; + RBAExpression* bodyText_ {nullptr}; + const RBARuleObject* ruleObj_ {nullptr}; +}; + +} + +#endif diff --git a/src/core/expression/RBALambdaExpressionMaker.cpp b/src/core/expression/RBALambdaExpressionMaker.cpp new file mode 100644 index 0000000..674067f --- /dev/null +++ b/src/core/expression/RBALambdaExpressionMaker.cpp @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBALambdaExpressionMaker.cpp +/// @brief LambdaExpression object generation class definition + +#include "RBALambdaExpressionMaker.hpp" +#include "RBALambdaExpression.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBALambdaExpressionMaker::RBALambdaExpressionMaker() + : RBAExpressionMaker{"LambdaExpression"} +{ +} + +std::unique_ptr<RBAModelElement> +RBALambdaExpressionMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBALambdaExpression>(); +} + +RBAModelElement* +RBALambdaExpressionMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBALambdaExpression* const lambdaExpr + {dynamic_cast<RBALambdaExpression*>(element)}; + + // Set LetStatement + const std::int32_t pop_num {setLetStatement(model, lambdaExpr, jsonElem)}; + + // Set variable + const RBAJsonElement* const varElement {jsonElem->findChildren("x")}; + RBAVariable* const var + {dynamic_cast<RBAVariable*>(getFactory()->createElement("Variable", + varElement))}; + lambdaExpr->setX(var); + // Set bodyText + getFactory()->pushVariable(var); + const RBAJsonElement* const body {jsonElem->findChildren("bodyText")}; + RBAExpression* const expr + {dynamic_cast<RBAExpression*>(getFactory()->createElement(body->getClassName(), + body))}; + lambdaExpr->setBodyText(expr); + + // Pop variable + for(std::int32_t i{0}; i<pop_num; i++) { + getFactory()->popVariable(); + } + + return lambdaExpr; +} + +} diff --git a/src/core/expression/RBALambdaExpressionMaker.hpp b/src/core/expression/RBALambdaExpressionMaker.hpp new file mode 100644 index 0000000..04e5f05 --- /dev/null +++ b/src/core/expression/RBALambdaExpressionMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBALambdaExpressionMaker.hpp +/// @brief LambdaExpression object generation class header + +#ifndef RBALAMBDAEXPRESSIONMAKER_HPP +#define RBALAMBDAEXPRESSIONMAKER_HPP + +#include "RBAExpressionMaker.hpp" + +namespace rba +{ + +/// @brief LambdaExpression object generation class +class RBALambdaExpressionMaker : public RBAExpressionMaker +{ +public: + RBALambdaExpressionMaker(); + RBALambdaExpressionMaker(const RBALambdaExpressionMaker&)=delete; + RBALambdaExpressionMaker(const RBALambdaExpressionMaker&&)=delete; + RBALambdaExpressionMaker& operator=(const RBALambdaExpressionMaker&)=delete; + RBALambdaExpressionMaker& operator=(const RBALambdaExpressionMaker&&)=delete; + virtual ~RBALambdaExpressionMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/expression/RBALetStatement.cpp b/src/core/expression/RBALetStatement.cpp new file mode 100644 index 0000000..f64cc18 --- /dev/null +++ b/src/core/expression/RBALetStatement.cpp @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * LetStatement class definition + */ + +#include "RBALetStatement.hpp" +#include "RBALogManager.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAModelElementType.hpp" +#include "RBAVariable.hpp" +#include "RBAExpressionVisitor.hpp" + +namespace rba +{ + +RBAModelElementType RBALetStatement::getModelElementType() const +{ + return RBAModelElementType::LetStatement; +} + +void RBALetStatement::setVariable(RBAVariable* const var) +{ + variable_ = var; +} + +void +RBALetStatement::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +void RBALetStatement::setVariable(RBAArbitrator* const arb) +{ + RBAConstraintInfo* const info {variable_->createConstraintInfo()}; + variable_->setRuleObj(getLhsOperand()->getReferenceObject(info, arb)); +#ifdef RBA_USE_LOG + std::string valueName; + if (info->isExceptionBeforeArbitrate() == true) { + valueName = "before arbitrate skip"; + } else if (variable_->getRuleObj() == nullptr) { + valueName = "NULL"; + } else { + valueName = variable_->getRuleObj()->getElementName(); + if (valueName == "") { + valueName = variable_->getRuleObj()->getDynamicName(); + } + } + LOG_arbitrateConstraintLogicLogLine( + " let " + variable_->getElementName() + " = " + + getLhsOperand()->getExpressionText() + " = " + valueName); +#endif +} +} /* namespace rba */ diff --git a/src/core/expression/RBALetStatement.hpp b/src/core/expression/RBALetStatement.hpp new file mode 100644 index 0000000..636b07d --- /dev/null +++ b/src/core/expression/RBALetStatement.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * LetStatement class header file + */ + +#ifndef RBALETOPERATOR_HPP_ +#define RBALETOPERATOR_HPP_ + +#include "RBAOperator.hpp" + +namespace rba { + +class RBAVariable; + +class DLL_EXPORT RBALetStatement : public RBAOperator +{ +public: + RBALetStatement()=default; + RBALetStatement(const RBALetStatement&)=delete; + RBALetStatement(const RBALetStatement&&)=delete; + RBALetStatement& operator=(const RBALetStatement&)=delete; + RBALetStatement& operator=(const RBALetStatement&&)=delete; + virtual ~RBALetStatement()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + void setVariable(RBAVariable* const var); + void setVariable(RBAArbitrator* const arb); + +private: + RBAVariable* variable_; + +}; + +} + +#endif diff --git a/src/core/expression/RBALetStatementMaker.cpp b/src/core/expression/RBALetStatementMaker.cpp new file mode 100644 index 0000000..93fcdee --- /dev/null +++ b/src/core/expression/RBALetStatementMaker.cpp @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBALetStatementMaker.cpp +/// @brief LetStatement object generation class defintino. + +#include "RBALetStatementMaker.hpp" +#include "RBALetStatement.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBALetStatementMaker::RBALetStatementMaker() + : RBAExpressionMaker{"LetStatement"} +{ +} + +std::unique_ptr<RBAModelElement> +RBALetStatementMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBALetStatement>(); +} + +RBAModelElement* +RBALetStatementMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBALetStatement* const letStmt {dynamic_cast<RBALetStatement*>(element)}; + + // Set variable + const RBAJsonElement* const varElement {jsonElem->findChildren("variable")}; + RBAVariable* const var + {dynamic_cast<RBAVariable*>(getFactory()->createElement("Variable", + varElement))}; + letStmt->setVariable(var); // Set Body + + // popVariable() is executed by the caller of this function + getFactory()->pushVariable(var); + const RBAJsonElement* const body {jsonElem->findChildren("body")}; + RBAExpression* const expr + {dynamic_cast<RBAExpression*>(getFactory()->createElement(body->getClassName(), + body))}; + letStmt->addOperand(expr); + + return letStmt; +} + +} diff --git a/src/core/expression/RBALetStatementMaker.hpp b/src/core/expression/RBALetStatementMaker.hpp new file mode 100644 index 0000000..348ca71 --- /dev/null +++ b/src/core/expression/RBALetStatementMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBALetStatementMaker.hpp +/// @brief LetStatement object generation class header + +#ifndef RBAISACTIVEMAKER_HPP +#define RBAISACTIVEMAKER_HPP + +#include "RBAExpressionMaker.hpp" + +namespace rba +{ + +/// @brief LetStatement object generation class +class RBALetStatementMaker : public RBAExpressionMaker +{ +public: + RBALetStatementMaker(); + RBALetStatementMaker(const RBALetStatementMaker&)=delete; + RBALetStatementMaker(const RBALetStatementMaker&&)=delete; + RBALetStatementMaker& operator=(const RBALetStatementMaker&)=delete; + RBALetStatementMaker& operator=(const RBALetStatementMaker&&)=delete; + virtual ~RBALetStatementMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + +}; + +} + +#endif diff --git a/src/core/expression/RBALogicalOperator.cpp b/src/core/expression/RBALogicalOperator.cpp new file mode 100644 index 0000000..e931b7a --- /dev/null +++ b/src/core/expression/RBALogicalOperator.cpp @@ -0,0 +1,73 @@ + +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * 論理オペレータクラス定義ファイル + */ + +#include <sstream> +#include "RBALogicalOperator.hpp" +#include "RBAExpressionType.hpp" + +namespace rba +{ + +#ifdef RBA_USE_LOG +const std::string +RBALogicalOperator::getExpressionText() const +{ + std::ostringstream oss; + oss << "("; + const auto& exprList = getOperand(); + const auto& lastExpr = exprList.back(); + for (const auto& expr : exprList) { + oss << expr->getExpressionText(); + if (expr != lastExpr) { + oss << " " << getSymbol() << " "; + } + } + oss << ")"; + + return oss.str(); +} + +const std::string +RBALogicalOperator::getCoverageExpressionText() const +{ + std::ostringstream oss; + oss << "("; + auto exprList = getOperand(); + auto lastExpr = exprList.back(); + for (const auto& expr : exprList) { + oss << expr->getCoverageExpressionText(); + if (expr != lastExpr) { + oss << " " << getSymbol() << " "; + } + } + oss << ")"; + + return oss.str(); +} + +RBAExpressionType +RBALogicalOperator::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBALogicalOperator.hpp b/src/core/expression/RBALogicalOperator.hpp new file mode 100644 index 0000000..b713f5a --- /dev/null +++ b/src/core/expression/RBALogicalOperator.hpp @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * LogicalOperator class header + */ + +#ifndef RBALOGICOPERATOR_HPP +#define RBALOGICOPERATOR_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBALogicalOperator : public RBAOperator +{ + protected: + RBALogicalOperator()=default; + RBALogicalOperator(const RBALogicalOperator&)=delete; + RBALogicalOperator(const RBALogicalOperator&&)=delete; + RBALogicalOperator& operator=(const RBALogicalOperator&)=delete; + RBALogicalOperator& operator=(const RBALogicalOperator&&)=delete; + + public: + // Log +#ifdef RBA_USE_LOG + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAMaxOperator.cpp b/src/core/expression/RBAMaxOperator.cpp new file mode 100644 index 0000000..46d5ed1 --- /dev/null +++ b/src/core/expression/RBAMaxOperator.cpp @@ -0,0 +1,135 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * MaxOperator class definition + */ + +#include "RBAMaxOperator.hpp" +#include "RBAAllocatable.hpp" +#include "RBAContent.hpp" +#include "RBAArbitrator.hpp" +#include "RBALogManager.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALambdaExpression.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +void +RBAMaxOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAMaxOperator::getModelElementType() const +{ + return RBAModelElementType::MaxOperator; +} + +const RBARuleObject* RBAMaxOperator::getReferenceObjectCore( + RBAConstraintInfo* info, RBAArbitrator* arb) const +{ + LOG_addHierarchy(LOG_getSymbol()); + const RBARuleObject* returnObj {nullptr}; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const lhsObj {getLhsOperand()->getReferenceObject(leftInfo, + arb)}; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else { + if (lhsObj != nullptr) { + const RBAAllocatableSet* alloSet = dynamic_cast<const RBAAllocatableSet*>(lhsObj); + if (alloSet != nullptr) { + std::uint32_t i { 0U }; + std::int32_t maxVal { -99 }; + RBALambdaExpression* const lambda { getLambda() }; + for (auto& obj : alloSet->getLeafAllocatable()) { + LOG_addHierarchy("#" + std::to_string(i)); + ++i; + RBAConstraintInfo* const childInfo { info->getChild(i) }; + lambda->setRuleObj(obj); + const std::int32_t val { lambda->getValue(childInfo, arb) }; + LOG_removeHierarchy(); + if ((maxVal < val) && (!childInfo->isExceptionBeforeArbitrate())) { + maxVal = val; + returnObj = obj; + } + } + } else { + const RBAContentSet* contentSet = dynamic_cast<const RBAContentSet*>(lhsObj); + if (contentSet != nullptr) { + std::uint32_t i { 0U }; + std::int32_t maxVal { -99 }; + RBALambdaExpression* const lambda { getLambda() }; + for (auto& obj : contentSet->getLeafContent()) { + LOG_addHierarchy("#" + std::to_string(i)); + ++i; + RBAConstraintInfo* const childInfo { info->getChild(i) }; + lambda->setRuleObj(obj); + const std::int32_t val { lambda->getValue(childInfo, arb) }; + LOG_removeHierarchy(); + if ((maxVal < val) && (!childInfo->isExceptionBeforeArbitrate())) { + maxVal = val; + returnObj = obj; + } + } + } + } + } + } +#ifdef RBA_USE_LOG + std::string objName = "NULL"; + if (info->isExceptionBeforeArbitrate()) { + objName = "before arbitrate skip"; + } else { + if (returnObj != nullptr){ + objName = returnObj->getElementName(); + if (objName == "") { + objName = returnObj->getDynamicName(); + } + } + } + LOG_arbitrateConstraintLogicLogLine( + " " + LOG_getExpressionText() + " is " + objName); +#endif + LOG_removeHierarchy(); + return returnObj; +} +#ifdef RBA_USE_LOG +const std::string RBAMaxOperator::getSymbol() const +{ + return ".max"; +} + +const std::string RBAMaxOperator::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol() + + getLambda()->getExpressionText(); +} + +const std::string RBAMaxOperator::getCoverageExpressionText() const +{ + getLambda()->clearRuleObj(); + return getLhsOperand()->getCoverageExpressionText() + getSymbol() + + getLambda()->getCoverageExpressionText(); +} +#endif + +} // namespace rba diff --git a/src/core/expression/RBAMaxOperator.hpp b/src/core/expression/RBAMaxOperator.hpp new file mode 100644 index 0000000..046cec9 --- /dev/null +++ b/src/core/expression/RBAMaxOperator.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * MaxOperator class header + */ + +#ifndef RBAMAXOPERATOR_HPP +#define RBAMAXOPERATOR_HPP + +#include "RBALambdaContext.hpp" + +namespace rba +{ + +class RBAMaxOperator : public RBALambdaContext +{ + public: + RBAMaxOperator()=default; + RBAMaxOperator(const RBAMaxOperator&)=delete; + RBAMaxOperator(const RBAMaxOperator&&)=delete; + RBAMaxOperator& operator=(const RBAMaxOperator&)=delete; + RBAMaxOperator& operator=(const RBAMaxOperator&&)=delete; + virtual ~RBAMaxOperator()=default; + + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; +#endif +}; + +} /* namespace rba */ + +#endif /* RBAMAXOPERATOR_HPP */ diff --git a/src/core/expression/RBAMaxOperatorMaker.cpp b/src/core/expression/RBAMaxOperatorMaker.cpp new file mode 100644 index 0000000..298bbbf --- /dev/null +++ b/src/core/expression/RBAMaxOperatorMaker.cpp @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAMaxOperatorMaker.cpp +/// @brief MaxOperator object generation class definition + +#include "RBAMaxOperatorMaker.hpp" +#include "RBAMaxOperator.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBALambdaExpression.hpp" + +namespace rba +{ + +RBAMaxOperatorMaker::RBAMaxOperatorMaker() + : RBALambdaContextMaker{"MaxOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAMaxOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAMaxOperator>(); +} + +RBAModelElement* +RBAMaxOperatorMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>( + RBALambdaContextMaker::setProperty(element, jsonElem, model, owner)); + + return element; +} + +std::unique_ptr<RBALambdaContext> +RBAMaxOperatorMaker::createLambdaContext() +{ + return std::make_unique<RBAMaxOperator>(); +} + +} diff --git a/src/core/expression/RBAMaxOperatorMaker.hpp b/src/core/expression/RBAMaxOperatorMaker.hpp new file mode 100644 index 0000000..1216674 --- /dev/null +++ b/src/core/expression/RBAMaxOperatorMaker.hpp @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAMaxOperatorMaker.hpp +/// @brief MaxOperator object generation class header + +#ifndef RBAMAXOPERATORMAKER_HPP +#define RBAMAXOPERATORMAKER_HPP + +#include "RBALambdaContextMaker.hpp" + +namespace rba +{ + +/// @brief MaxOperator object generation class +class RBAMaxOperatorMaker : public RBALambdaContextMaker +{ +public: + RBAMaxOperatorMaker(); + RBAMaxOperatorMaker(const RBAMaxOperatorMaker&)=delete; + RBAMaxOperatorMaker(const RBAMaxOperatorMaker&&)=delete; + RBAMaxOperatorMaker& operator=(const RBAMaxOperatorMaker&)=delete; + RBAMaxOperatorMaker& operator=(const RBAMaxOperatorMaker&&)=delete; + virtual ~RBAMaxOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + + /// @brief generate an empty object of LambdaContext + /// @details generate an empty object of unique_ptr + /// @return unique_ptr for object of LambdaContext + std::unique_ptr<RBALambdaContext> createLambdaContext() override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAMemberFeatureReferenceMaker.cpp b/src/core/expression/RBAMemberFeatureReferenceMaker.cpp new file mode 100644 index 0000000..699bca0 --- /dev/null +++ b/src/core/expression/RBAMemberFeatureReferenceMaker.cpp @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAMemberFeatureReferenceMaker.cpp +/// @brief ObjectReference of property object generator class definition + +#include "RBAMemberFeatureReferenceMaker.hpp" +#include "RBAObjectReference.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBAAbstractProperty.hpp" + +namespace rba +{ + +RBAMemberFeatureReferenceMaker::RBAMemberFeatureReferenceMaker() + : RBAObjectReferenceMaker{"MemberFeatureReference"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAMemberFeatureReferenceMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAObjectReference>(); +} + +RBAModelElement* +RBAMemberFeatureReferenceMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBAObjectReference* const objRef {dynamic_cast<RBAObjectReference*>(element)}; + + // Set reference object + objRef->setRefObject(getRuleObject(jsonElem,model)); + + return objRef; +} + +const RBARuleObject* +RBAMemberFeatureReferenceMaker::getRuleObject(const RBAJsonElement* + const jsonElem, + RBAModelImpl* const model) +{ + const RBARuleObject* refObj {nullptr}; + const auto typeStr = jsonElem->findChildren("type")->getString(); + const auto refObjStr = jsonElem->findChildren("refObject")->getString(); + + if (jsonElem->findChildren("class")->getString() == "ObjectReference") { + refObj = dynamic_cast<RBARuleObject*>(getMaker(typeStr)->getInstance(model, + refObjStr)); + } else { // jsonElem->findChildren("class")->getString() == "MemberFeatureReference" + // @Deviation (MEM05-CPP,Rule-7_5_4,A7-5-2) + // [Contents that deviate from the rules] + // calling getRuleObject() recursively + // [Explain that it is okay to deviate from the rules] + // When "Content name.State machine name.State name" is used + // in the constraint expression, it becomes the STATEMACHINE_STATE of + // Member of "STATEMACHINE" of "CONTENT", so recursive call is used. + // Since the number of elements in the rule model is finite and + // there is no cyclic relationship, stack overflow does not occur and + // there is no problem. + const auto owner = const_cast<RBARuleObject*>(getRuleObject(jsonElem->findChildren("operand")->getChild(), model)); + refObj = owner->getMember(refObjStr); + if (refObj == nullptr) { + if (getMaker(typeStr) != nullptr) { + refObj = dynamic_cast<RBARuleObject*>(getMaker(typeStr)->getInstance(model, + refObjStr, owner)); + } + if ((refObj == nullptr) + && (jsonElem->findChildren("type")->getString() == "PROPERTY")) { + refObj = dynamic_cast<RBASceneImpl*>(owner)->addProperty(refObjStr, -99); + } + } + } + return refObj; +} +} diff --git a/src/core/expression/RBAMemberFeatureReferenceMaker.hpp b/src/core/expression/RBAMemberFeatureReferenceMaker.hpp new file mode 100644 index 0000000..61880a7 --- /dev/null +++ b/src/core/expression/RBAMemberFeatureReferenceMaker.hpp @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAMemberFeatureReferenceMaker.cpp +/// @brief ObjectReference of property object generator class header + +#ifndef RBAMEMBERFEATUREREFERENCEMAKER_HPP +#define RBAMEMBERFEATUREREFERENCEMAKER_HPP + +#include "RBAObjectReferenceMaker.hpp" + +namespace rba +{ + +class RBARuleObject; + +/// @brief ObjectReference of property object generator class +class RBAMemberFeatureReferenceMaker : public RBAObjectReferenceMaker +{ +public: + RBAMemberFeatureReferenceMaker(); + RBAMemberFeatureReferenceMaker(const RBAMemberFeatureReferenceMaker&)=delete; + RBAMemberFeatureReferenceMaker(const RBAMemberFeatureReferenceMaker&&)=delete; + RBAMemberFeatureReferenceMaker& operator=(const RBAMemberFeatureReferenceMaker&)=delete; + RBAMemberFeatureReferenceMaker& operator=(const RBAMemberFeatureReferenceMaker&&)=delete; + virtual ~RBAMemberFeatureReferenceMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; +private: + const RBARuleObject* getRuleObject(const RBAJsonElement* const jsonElem, + RBAModelImpl* const model); +}; + +} + +#endif diff --git a/src/core/expression/RBAMinOperator.cpp b/src/core/expression/RBAMinOperator.cpp new file mode 100644 index 0000000..923088b --- /dev/null +++ b/src/core/expression/RBAMinOperator.cpp @@ -0,0 +1,135 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// MinOperator class definition + +#include "RBAMinOperator.hpp" +#include "RBAAllocatable.hpp" +#include "RBAContent.hpp" +#include "RBAArbitrator.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALambdaExpression.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +void +RBAMinOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAMinOperator::getModelElementType() const +{ + return RBAModelElementType::MinOperator; +} + +const RBARuleObject* RBAMinOperator::getReferenceObjectCore( + RBAConstraintInfo* info, RBAArbitrator* arb) const +{ + LOG_addHierarchy(LOG_getSymbol()); + const RBARuleObject* returnObj {nullptr}; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const lhsObj {getLhsOperand()->getReferenceObject(leftInfo, + arb)}; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else { + if (lhsObj != nullptr) { + const RBAAllocatableSet* alloSet = dynamic_cast<const RBAAllocatableSet*>(lhsObj); + if (alloSet != nullptr) { + std::uint32_t i { 0U }; + std::int32_t minVal { INT32_MAX }; + RBALambdaExpression* const lambda { getLambda() }; + for (auto& obj : alloSet->getLeafAllocatable()) { + LOG_addHierarchy("#" + std::to_string(i)); + ++i; + RBAConstraintInfo* const childInfo { info->getChild(i) }; + lambda->setRuleObj(obj); + const std::int32_t val { lambda->getValue(childInfo, arb) }; + LOG_removeHierarchy(); + if ((val != -99) && (minVal > val) + && (!childInfo->isExceptionBeforeArbitrate())) { + minVal = val; + returnObj = obj; + } + } + } else { + const RBAContentSet* contentSet = dynamic_cast<const RBAContentSet*>(lhsObj); + if (contentSet != nullptr) { + std::uint32_t i { 0U }; + std::int32_t minVal { INT32_MAX }; + RBALambdaExpression* const lambda { getLambda() }; + for (auto& obj : contentSet->getLeafContent()) { + LOG_addHierarchy("#" + std::to_string(i)); + ++i; + RBAConstraintInfo* const childInfo { info->getChild(i) }; + lambda->setRuleObj(obj); + const std::int32_t val { lambda->getValue(childInfo, arb) }; + LOG_removeHierarchy(); + if ((val != -99) && (minVal > val) + && (!childInfo->isExceptionBeforeArbitrate())) { + minVal = val; + returnObj = obj; + } + } + } + } + } + } +#ifdef RBA_USE_LOG + std::string objName = "NULL"; + if (info->isExceptionBeforeArbitrate()) { + objName = "before arbitrate skip"; + } else { + if (returnObj != nullptr){ + objName = returnObj->getElementName(); + if (objName == "") { + objName = returnObj->getDynamicName(); + } + } + } + LOG_arbitrateConstraintLogicLogLine( + " " + LOG_getExpressionText() + " is " + objName); +#endif + LOG_removeHierarchy(); + return returnObj; +} +#ifdef RBA_USE_LOG +const std::string RBAMinOperator::getSymbol() const +{ + return ".mix"; +} + +const std::string RBAMinOperator::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol() + + getLambda()->getExpressionText(); +} + +const std::string RBAMinOperator::getCoverageExpressionText() const +{ + getLambda()->clearRuleObj(); + return getLhsOperand()->getCoverageExpressionText() + getSymbol() + + getLambda()->getCoverageExpressionText(); +} +#endif + +} // namespace rba diff --git a/src/core/expression/RBAMinOperator.hpp b/src/core/expression/RBAMinOperator.hpp new file mode 100644 index 0000000..b128877 --- /dev/null +++ b/src/core/expression/RBAMinOperator.hpp @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// MinOperator class header + +#ifndef RBAMINOPERATOR_HPP +#define RBAMINOPERATOR_HPP + +#include "RBALambdaContext.hpp" + +namespace rba +{ + +class RBAMinOperator : public RBALambdaContext +{ + public: + RBAMinOperator()=default; + RBAMinOperator(const RBAMinOperator&)=delete; + RBAMinOperator(RBAMinOperator&&)=delete; + RBAMinOperator& operator=(const RBAMinOperator&)=delete; + RBAMinOperator& operator=(RBAMinOperator&&)=delete; + virtual ~RBAMinOperator()=default; + + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; +#endif +}; + +} // namespace rba + +#endif // RBAMINOPERATOR_HPP diff --git a/src/core/expression/RBAMinOperatorMaker.cpp b/src/core/expression/RBAMinOperatorMaker.cpp new file mode 100644 index 0000000..060e552 --- /dev/null +++ b/src/core/expression/RBAMinOperatorMaker.cpp @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAMinOperatorMaker.cpp +/// @brief MinOperator object generator class definition + +#include "RBAMinOperatorMaker.hpp" +#include "RBAMinOperator.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBALambdaExpression.hpp" + +namespace rba +{ + +RBAMinOperatorMaker::RBAMinOperatorMaker() + : RBALambdaContextMaker{"MinOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAMinOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAMinOperator>(); +} + +RBAModelElement* +RBAMinOperatorMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>( + RBALambdaContextMaker::setProperty(element, jsonElem, model, owner)); + + return element; +} + +std::unique_ptr<RBALambdaContext> +RBAMinOperatorMaker::createLambdaContext() +{ + return std::make_unique<RBAMinOperator>(); +} + +} diff --git a/src/core/expression/RBAMinOperatorMaker.hpp b/src/core/expression/RBAMinOperatorMaker.hpp new file mode 100644 index 0000000..6eb90e1 --- /dev/null +++ b/src/core/expression/RBAMinOperatorMaker.hpp @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAMinOperatorMaker.hpp +/// @brief MinOperator object generator class header + +#ifndef RBAMINOPERATORMAKER_HPP +#define RBAMINOPERATORMAKER_HPP + +#include "RBALambdaContextMaker.hpp" + +namespace rba +{ + +/// @brief MinOperator object generator class +class RBAMinOperatorMaker : public RBALambdaContextMaker +{ +public: + RBAMinOperatorMaker(); + RBAMinOperatorMaker(const RBAMinOperatorMaker&)=delete; + RBAMinOperatorMaker(const RBAMinOperatorMaker&&)=delete; + RBAMinOperatorMaker& operator=(const RBAMinOperatorMaker&)=delete; + RBAMinOperatorMaker& operator=(const RBAMinOperatorMaker&&)=delete; + virtual ~RBAMinOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + + /// @brief generate an empty object of LambdaContext + /// @details generate an empty object of unique_ptr + /// @return unique_ptr for object of LambdaContext + std::unique_ptr<RBALambdaContext> createLambdaContext() override; + +}; + +} + +#endif diff --git a/src/core/expression/RBANotOperator.cpp b/src/core/expression/RBANotOperator.cpp new file mode 100644 index 0000000..afcf3c8 --- /dev/null +++ b/src/core/expression/RBANotOperator.cpp @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * RBANotOperator class definition + */ + +#include "RBANotOperator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBANotOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBANotOperator::getModelElementType() const +{ + return RBAModelElementType::NotOperator; +} + +bool +RBANotOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const childInfo {info->getChild(0U)}; + const bool isChildPassed {getLhsOperand()->execute(childInfo, arb)}; + if (childInfo->isExceptionBeforeArbitrate() == true) { + info->setExceptionBeforeArbitrate(true); + } else { + isPassed = !isChildPassed; + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBANotOperator::getSymbol() const +{ + return "!"; +} + +const std::string +RBANotOperator::getExpressionText() const +{ + return getSymbol() + getLhsOperand()->getExpressionText(); +} + +const std::string +RBANotOperator::getCoverageExpressionText() const +{ + return getSymbol() + getLhsOperand()->getCoverageExpressionText(); +} +#endif + +} diff --git a/src/core/expression/RBANotOperator.hpp b/src/core/expression/RBANotOperator.hpp new file mode 100644 index 0000000..4af1461 --- /dev/null +++ b/src/core/expression/RBANotOperator.hpp @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * RBANotOperator class header + */ + +#ifndef RBANOTOPERATOR_HPP +#define RBANOTOPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBANotOperator : public RBALogicalOperator +{ +public: + RBANotOperator()=default; + RBANotOperator(const RBANotOperator&)=delete; + RBANotOperator(const RBANotOperator&&)=delete; + RBANotOperator& operator=(const RBANotOperator&)=delete; + RBANotOperator& operator=(const RBANotOperator&&)=delete; + virtual ~RBANotOperator()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBANotOperatorMaker.cpp b/src/core/expression/RBANotOperatorMaker.cpp new file mode 100644 index 0000000..e4e823c --- /dev/null +++ b/src/core/expression/RBANotOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBANotOperatorMaker.cpp +/// @brief NotOperator object generator class definition + +#include "RBANotOperatorMaker.hpp" +#include "RBANotOperator.hpp" + +namespace rba +{ + +RBANotOperatorMaker::RBANotOperatorMaker() + : RBAOperatorMaker{"NotOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBANotOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBANotOperator>(); +} + +} diff --git a/src/core/expression/RBANotOperatorMaker.hpp b/src/core/expression/RBANotOperatorMaker.hpp new file mode 100644 index 0000000..91f39b9 --- /dev/null +++ b/src/core/expression/RBANotOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBANotOperatorMaker.hpp +/// @brief NotOperator object generator class header + +#ifndef RBANOTOPERATORMAKER_HPP +#define RBANOTOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief NotOperator object generator class header +class RBANotOperatorMaker : public RBAOperatorMaker +{ +public: + RBANotOperatorMaker(); + RBANotOperatorMaker(const RBANotOperatorMaker&)=delete; + RBANotOperatorMaker(const RBANotOperatorMaker&&)=delete; + RBANotOperatorMaker& operator=(const RBANotOperatorMaker&)=delete; + RBANotOperatorMaker& operator=(const RBANotOperatorMaker&&)=delete; + virtual ~RBANotOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAObjectCompare.cpp b/src/core/expression/RBAObjectCompare.cpp new file mode 100644 index 0000000..65bee04 --- /dev/null +++ b/src/core/expression/RBAObjectCompare.cpp @@ -0,0 +1,165 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ObjectCompare calss defintion + */ + +#include "RBAObjectCompare.hpp" +#include "RBAAllocatable.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAExpressionType.hpp" +#include "RBAModelElementType.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" + +namespace rba +{ + +void +RBAObjectCompare::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAObjectCompare::getModelElementType() const +{ + return RBAModelElementType::ObjectCompare; +} + +bool +RBAObjectCompare::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBAExpression* const lhs {getLhsOperand()}; + // Add left hand side expression to Constraint hierarchy for coverage + LOG_addHierarchy("#left"); + const RBARuleObject* const lhobj {lhs->getReferenceObject(leftInfo, arb)}; + // Remove left hand side expression from Constraint hierarchy for coverage + LOG_removeHierarchy(); + // Throw if one of the pre-arbitration exceptions appears in the reference + if (leftInfo->isExceptionBeforeArbitrate() == true) { + info->setExceptionBeforeArbitrate(true); + } else { + RBAConstraintInfo* const rightInfo {info->getChild(1U)}; + const RBAExpression* const rhs {getRhsOperand()}; + // Add right hand side expression to Constraint hierarchy for coverage + LOG_addHierarchy("#right"); + const RBARuleObject* const rhobj {rhs->getReferenceObject(rightInfo, arb)}; + // Remove right hand side expression to Constraint hierarchy for coverage + LOG_removeHierarchy(); + // Throw if one of the pre-arbitration exceptions appears in the reference + if (rightInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else { + // False if both objects cannot be got + if ((lhobj != nullptr) && (rhobj != nullptr)) { + if (lhobj->getRawObject() == rhobj->getRawObject()) { + isPassed = true; + // Even if re-arbitration is performed for "ObjectCompare" that uses + // "ObjectRefrence" as an operand, the evaluation result does not + // change from false to True, so it is not necessary to add + // "FalseAllocatable" or "TrueAllocatabe" for re-arbitration. + // When "Expression" such as "AllocatedContent" is used as an operand, + // "FalseAllocatable" and "TrueAllocatabe" are added in the operand, + // so it is not necessary to add in ObjectCompare. + } + } + } + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAObjectCompare::getSymbol() const +{ + return "=="; +} + +const std::string +RBAObjectCompare::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + + " " + getSymbol() + " " + getRhsOperand()->getExpressionText(); +} + +const std::string +RBAObjectCompare::getCoverageExpressionText() const +{ + return getLhsOperand()->getCoverageExpressionText() + + " " + getSymbol() + " " + getRhsOperand()->getCoverageExpressionText(); +} + +void +RBAObjectCompare::createHierarchy() +{ + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(getSymbol()); + RBALogManager::coverageHierarchyOfConstraintExpressionLog(getCoverageExpressionText(), this); + + RBAExpression* expr0 = getLhsOperand(); + RBAExpression* expr1 = getRhsOperand(); + + // Add left hand side expression to Constraint hierarchy for coverage + LOG_addHierarchy("#left"); + expr0->createHierarchy(); + // Remove left hand side expression from Constraint hierarchy for coverage + LOG_removeHierarchy(); + + // Add right hand side expression to Constraint hierarchy for coverage + LOG_addHierarchy("#right"); + expr1->createHierarchy(); + // Remove right hand side expression from Constraint hierarchy for coverage + LOG_removeHierarchy(); + + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); +} + +RBAExpressionType +RBAObjectCompare::getUnderlyingType() const +{ + return RBAExpressionType::BOOLEAN; +} +#endif + +} diff --git a/src/core/expression/RBAObjectCompare.hpp b/src/core/expression/RBAObjectCompare.hpp new file mode 100644 index 0000000..c7c345d --- /dev/null +++ b/src/core/expression/RBAObjectCompare.hpp @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ObjectCompare calss header + */ + +#ifndef RBAOBJECTCOMPARE_HPP +#define RBAOBJECTCOMPARE_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAObjectCompare : public RBAOperator +{ +public: + RBAObjectCompare()=default; + RBAObjectCompare(const RBAObjectCompare&)=delete; + RBAObjectCompare(const RBAObjectCompare&&)=delete; + RBAObjectCompare& operator=(const RBAObjectCompare&)=delete; + RBAObjectCompare& operator=(const RBAObjectCompare&&)=delete; + virtual ~RBAObjectCompare()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + void createHierarchy() override; + RBAExpressionType getUnderlyingType() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAObjectCompareMaker.cpp b/src/core/expression/RBAObjectCompareMaker.cpp new file mode 100644 index 0000000..ab696cf --- /dev/null +++ b/src/core/expression/RBAObjectCompareMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAObjectCompareMaker.cpp +/// @brief ObjectCompare object generator class + +#include "RBAObjectCompareMaker.hpp" +#include "RBAObjectCompare.hpp" + +namespace rba +{ + +RBAObjectCompareMaker::RBAObjectCompareMaker() + : RBAOperatorMaker{"ObjectCompare"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAObjectCompareMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAObjectCompare>(); +} + +} diff --git a/src/core/expression/RBAObjectCompareMaker.hpp b/src/core/expression/RBAObjectCompareMaker.hpp new file mode 100644 index 0000000..3d44a4e --- /dev/null +++ b/src/core/expression/RBAObjectCompareMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAObjectCompareMaker.hpp +/// @brief ObjectCompare object generator class header + +#ifndef RBAOBJECTCOMPAREMAKER_HPP +#define RBAOBJECTCOMPAREMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief ObjectCompare object generator class +class RBAObjectCompareMaker : public RBAOperatorMaker +{ +public: + RBAObjectCompareMaker(); + RBAObjectCompareMaker(const RBAObjectCompareMaker&)=delete; + RBAObjectCompareMaker(const RBAObjectCompareMaker&&)=delete; + RBAObjectCompareMaker& operator=(const RBAObjectCompareMaker&)=delete; + RBAObjectCompareMaker& operator=(const RBAObjectCompareMaker&&)=delete; + virtual ~RBAObjectCompareMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAObjectReference.cpp b/src/core/expression/RBAObjectReference.cpp new file mode 100644 index 0000000..aefe83c --- /dev/null +++ b/src/core/expression/RBAObjectReference.cpp @@ -0,0 +1,133 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// ObjectReference class definition + +#include "RBAObjectReference.hpp" + +#include "RBAExpressionVisitor.hpp" +#include "RBAVariable.hpp" +#include "RBAModelElementType.hpp" +#ifdef RBA_USE_LOG +#include "RBAAbstractProperty.hpp" +#include "RBASceneImpl.hpp" +#endif + +namespace rba +{ + +void +RBAObjectReference::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAObjectReference::getModelElementType() const +{ + return RBAModelElementType::ObjectReference; +} + +const RBARuleObject* +RBAObjectReference::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + const RBARuleObject* obj {refObject_}; + if (obj->isModelElementType(RBAModelElementType::Variable)) { + // in case of varible, its reference + const RBAVariable* const val {dynamic_cast<const RBAVariable*>(obj)}; + obj = val->getRuleObj(); + std::shared_ptr<RBAConstraintInfo> valInfo {val->getConstraintInfo()}; + if (valInfo != nullptr) { + info->setChild(valInfo); + if (valInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } + } + } + return obj; +} + +void +RBAObjectReference::setRefObject(const RBARuleObject* const newRefObject) +{ + refObject_ = newRefObject; +} + +#ifdef RBA_USE_LOG + +void +RBAObjectReference::setExpressionType(RBAExpressionType const newExprType) +{ + expressionType_ = newExprType; +} + +void +RBAObjectReference::createHierarchy() +{ + // No operation, because this does not affect the structure +} + +const std::string +RBAObjectReference::getExpressionText() const +{ + if (refObject_->isModelElementType(RBAModelElementType::Property)) { + return dynamic_cast<const RBAAbstractProperty*>(refObject_)->getScene()->getElementName(); + } + else if ((refObject_->isModelElementType(RBAModelElementType::ViewContentState)) || + (refObject_->isModelElementType(RBAModelElementType::SoundContentState))) { + return (refObject_->getOwner()->getElementName() + "." + refObject_->getElementName()); + } + if(refObject_->getElementName() != ""){ + return refObject_->getElementName(); + } else { + return refObject_->getDynamicName(); + } +} + +const std::string +RBAObjectReference::getCoverageExpressionText() const +{ + if (refObject_->isModelElementType(RBAModelElementType::Variable)) { + const RBAVariable* var = + dynamic_cast<const RBAVariable*>(refObject_); + if (var->getRuleObj()) { + if (var->getRuleObj()->getElementName() != "") { + return var->getRuleObj()->getElementName(); + } else { + return var->getRuleObj()->getDynamicName(); + } + } + } + if ((refObject_->isModelElementType(RBAModelElementType::ViewContentState)) || + (refObject_->isModelElementType(RBAModelElementType::SoundContentState))) { + return (refObject_->getOwner()->getElementName() + "." + refObject_->getElementName()); + } + if(refObject_->getElementName() != ""){ + return refObject_->getElementName(); + } else { + return refObject_->getDynamicName(); + } +} + +RBAExpressionType +RBAObjectReference::getUnderlyingType() const +{ + return expressionType_; +} +#endif + +} diff --git a/src/core/expression/RBAObjectReference.hpp b/src/core/expression/RBAObjectReference.hpp new file mode 100644 index 0000000..2eb38df --- /dev/null +++ b/src/core/expression/RBAObjectReference.hpp @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// ObjectReference class header + +#ifndef RBAOBJECTREFERENCE_HPP +#define RBAOBJECTREFERENCE_HPP + +#include "RBAExpression.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAObjectReference : public RBAExpression +{ +public: + RBAObjectReference()=default; + RBAObjectReference(const RBAObjectReference&)=delete; + RBAObjectReference(const RBAObjectReference&&)=delete; + RBAObjectReference& operator=(const RBAObjectReference&)=delete; + RBAObjectReference& operator=(const RBAObjectReference&&)=delete; + virtual ~RBAObjectReference()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + void setRefObject(const RBARuleObject* const newRefObject); + + // Log +#ifdef RBA_USE_LOG + void setExpressionType(RBAExpressionType const newExprType); + void createHierarchy() override; + const std::string getExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; + const std::string getCoverageExpressionText() const override; +#endif + +private: + const RBARuleObject* refObject_; +#ifdef RBA_USE_LOG + RBAExpressionType expressionType_; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAObjectReferenceMaker.cpp b/src/core/expression/RBAObjectReferenceMaker.cpp new file mode 100644 index 0000000..8c216ba --- /dev/null +++ b/src/core/expression/RBAObjectReferenceMaker.cpp @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAObjectReferenceMaker.cpp +/// @brief ObjectReference object generator class definition + +#include "RBAObjectReferenceMaker.hpp" +#include "RBAObjectReference.hpp" + +#include "RBAJsonElement.hpp" +#include "RBAModelFactory.hpp" +#include "RBAModelImpl.hpp" + +namespace rba +{ + +RBAObjectReferenceMaker::RBAObjectReferenceMaker(const std::string& label) + : RBAExpressionMaker{label} +{ +} + +std::unique_ptr<RBAModelElement> +RBAObjectReferenceMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAObjectReference>(); +} + +RBAModelElement* +RBAObjectReferenceMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBAObjectReference* const objRef {dynamic_cast<RBAObjectReference*>(element)}; + + // Set reference object + //// Getting reference object string + const auto& refObjectStr = jsonElem->findChildren("refObject")->getString(); + + //// Find object + auto ruleObj = model->findModelElement(refObjectStr); + + if(ruleObj == nullptr) { + ruleObj = getFactory()->getVariable(refObjectStr); + if(ruleObj == nullptr) { + const auto& typeStr = jsonElem->findChildren("type")->getString(); + auto maker = getMaker(typeStr); + if (maker != nullptr) { + ruleObj = maker->getInstance(model, refObjectStr, owner); + } + } + } + objRef->setRefObject(dynamic_cast<const RBARuleObject*>(ruleObj)); + +#ifdef RBA_USE_LOG + // Set expression type + const RBAExpressionType exprType {jsonElem->getExpressionType()}; + objRef->setExpressionType(exprType); +#endif + + return objRef; +} + +} diff --git a/src/core/expression/RBAObjectReferenceMaker.hpp b/src/core/expression/RBAObjectReferenceMaker.hpp new file mode 100644 index 0000000..ee58b92 --- /dev/null +++ b/src/core/expression/RBAObjectReferenceMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAObjectReferenceMaker.hpp +/// @brief ObjectReference object generator class header + +#ifndef RBAOBJECTREFERENCEMAKER_HPP +#define RBAOBJECTREFERENCEMAKER_HPP + +#include "RBAExpressionMaker.hpp" + +namespace rba +{ + +/// @brief ObjectReference object generator class header +class DLL_EXPORT RBAObjectReferenceMaker : public RBAExpressionMaker +{ +public: + explicit RBAObjectReferenceMaker(const std::string& label="ObjectReference"); + RBAObjectReferenceMaker(const RBAObjectReferenceMaker&)=delete; + RBAObjectReferenceMaker(const RBAObjectReferenceMaker&&)=delete; + RBAObjectReferenceMaker& operator=(const RBAObjectReferenceMaker&)=delete; + RBAObjectReferenceMaker& operator=(const RBAObjectReferenceMaker&&)=delete; + virtual ~RBAObjectReferenceMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAOperator.cpp b/src/core/expression/RBAOperator.cpp new file mode 100644 index 0000000..7d73f66 --- /dev/null +++ b/src/core/expression/RBAOperator.cpp @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Operator class definition + */ + +#include "RBAOperator.hpp" +#include "RBALogManager.hpp" + +namespace rba +{ + +const std::vector<RBAExpression*>& +RBAOperator::getOperand() const +{ + return operand_; +} + +void +RBAOperator::addOperand(RBAExpression* const newExpr) +{ + if(newExpr != nullptr) { + operand_.push_back(newExpr); + } +} + +RBAExpression* +RBAOperator::getLhsOperand() const +{ + return operand_.front(); +} + +RBAExpression* +RBAOperator::getRhsOperand() const +{ + return operand_.back(); +} + +const std::string +RBAOperator::getPreMsg(const bool isPrevious) const +{ + if(isPrevious) { + return "(pre)"; + } + else { + return ""; + } +} + +#ifdef RBA_USE_LOG +const std::string +RBAOperator::getSymbol() const +{ + return ""; +} + +void +RBAOperator::createHierarchy() +{ + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(getSymbol()); + RBALogManager::coverageHierarchyOfConstraintExpressionLog(getCoverageExpressionText(), this); + + std::uint32_t oprSize{ static_cast<std::uint32_t>(getOperand().size()) }; + if(oprSize == 1U) { + RBAExpression* expr = getLhsOperand(); + expr->createHierarchy(); + } + else { + std::uint32_t num{ 0U }; + for(RBAExpression* expr : getOperand()) { + // Add count to Constraint hierarchy for coverage + LOG_addHierarchy("#" + std::to_string(num++)); + expr->createHierarchy(); + // Remove count from Constraint hierarchy for coverage + LOG_removeHierarchy(); + } + } + + // Remove count from Constraint hierarchy for coverage + LOG_removeHierarchy(); +} +#endif + +} diff --git a/src/core/expression/RBAOperator.hpp b/src/core/expression/RBAOperator.hpp new file mode 100644 index 0000000..5d645f2 --- /dev/null +++ b/src/core/expression/RBAOperator.hpp @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Operator class header + */ + +#ifndef RBAOPERATOR_HPP +#define RBAOPERATOR_HPP + +#include <vector> +#include "RBAExpression.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAOperator : public RBAExpression +{ +protected: + RBAOperator()=default; + RBAOperator(const RBAOperator&)=delete; + RBAOperator(const RBAOperator&&)=delete; + RBAOperator& operator=(const RBAOperator&)=delete; + RBAOperator& operator=(const RBAOperator&&)=delete; + +public: + const std::vector<RBAExpression*>& getOperand() const; + void addOperand(RBAExpression* const newExpr); + RBAExpression* getLhsOperand() const; + RBAExpression* getRhsOperand() const; + + // Log +#ifdef RBA_USE_LOG + virtual const std::string getSymbol() const; + void createHierarchy() override; +#endif + +protected: + std::string const getPreMsg(const bool isPrevious) const; + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::vector<RBAExpression*> operand_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif +}; + +} + +#endif diff --git a/src/core/expression/RBAOperatorMaker.cpp b/src/core/expression/RBAOperatorMaker.cpp new file mode 100644 index 0000000..7da2885 --- /dev/null +++ b/src/core/expression/RBAOperatorMaker.cpp @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAOperatorMaker.cpp +/// @brief Operator object generator abstract class + +#include "RBAOperatorMaker.hpp" +#include "RBAOperator.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAOperatorMaker::RBAOperatorMaker(const std::string& label) + : RBAExpressionMaker{label} +{ +} + +RBAModelElement* +RBAOperatorMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + // Create expression + RBAOperator* const exprOpr {dynamic_cast<RBAOperator*>(element)}; + + // Set LetStatement + const auto pop_num = setLetStatement(model, exprOpr, jsonElem); + + // Set operand + for(auto& param : jsonElem->findChildren("operand")->getChildren()) { + const auto expr = getFactory()->createElement(param->getClassName(), param.get()); + exprOpr->addOperand(dynamic_cast<RBAExpression*>(expr)); + } + + // Pop variable + for(std::int32_t i{0}; i<pop_num; i++) { + getFactory()->popVariable(); + } + + return exprOpr; +} + +} diff --git a/src/core/expression/RBAOperatorMaker.hpp b/src/core/expression/RBAOperatorMaker.hpp new file mode 100644 index 0000000..681ff65 --- /dev/null +++ b/src/core/expression/RBAOperatorMaker.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAOperatorMaker.hpp +/// @brief Operator object generator abstract class header + +#ifndef RBAOPERATORMAKER_HPP +#define RBAOPERATORMAKER_HPP + +#include "RBAExpressionMaker.hpp" + +namespace rba +{ + +/// @brief Operator object generator abstract class +class DLL_EXPORT RBAOperatorMaker : public RBAExpressionMaker +{ +public: + explicit RBAOperatorMaker(const std::string& label=""); + RBAOperatorMaker(const RBAOperatorMaker&)=delete; + RBAOperatorMaker(const RBAOperatorMaker&&)=delete; + RBAOperatorMaker& operator=(const RBAOperatorMaker&)=delete; + RBAOperatorMaker& operator=(const RBAOperatorMaker&&)=delete; + virtual ~RBAOperatorMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAOrOperator.cpp b/src/core/expression/RBAOrOperator.cpp new file mode 100644 index 0000000..d55e4a0 --- /dev/null +++ b/src/core/expression/RBAOrOperator.cpp @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * OrOperator class definition + */ + +#include "RBAOrOperator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void +RBAOrOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBAOrOperator::getModelElementType() const +{ + return RBAModelElementType::OrOperator; +} + +bool +RBAOrOperator::executeCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + bool isPassed {false}; + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy(LOG_getSymbol()); + std::uint32_t index {0U}; + for (const RBAExpression* const ope : getOperand()) { + RBAConstraintInfo* const childInfo {info->getChild(index)}; + // Add count to Constraint hierarchy for coverage + LOG_addHierarchy("#" + std::to_string(index)); + const bool res {ope->execute(childInfo, arb)}; + // Remove count from Constraint hierarchy for coverage + LOG_removeHierarchy(); + if (childInfo->isExceptionBeforeArbitrate() == true) { + info->setExceptionBeforeArbitrate(true); + } else if (res == true) { + isPassed = true; + } else { + ; + } + ++index; + } + if (isPassed == true) { + info->setExceptionBeforeArbitrate(false); + } +#ifdef RBA_USE_LOG + if (info->isExceptionBeforeArbitrate() == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] before arbitrate skip"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::SKIP); + } else if (isPassed == true) { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] true"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::TRUE); + } else { + LOG_arbitrateConstraintLogicLogLine( + " [" + LOG_getExpressionText() + "] false"); + LOG_coverageConstraintExpressionLog(LOG_getCoverageExpressionText(), + RBAExecuteResult::FALSE); + } +#endif + // Remove count from Constraint hierarchy for coverage + LOG_removeHierarchy(); + return isPassed; +} + +#ifdef RBA_USE_LOG +const std::string +RBAOrOperator::getSymbol() const +{ + return "OR"; +} +#endif + +} diff --git a/src/core/expression/RBAOrOperator.hpp b/src/core/expression/RBAOrOperator.hpp new file mode 100644 index 0000000..a52aca4 --- /dev/null +++ b/src/core/expression/RBAOrOperator.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * OrOperator class header + */ + +#ifndef RBAOROPERATOR_HPP +#define RBAOROPERATOR_HPP + +#include "RBALogicalOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAOrOperator : public RBALogicalOperator +{ + public: + RBAOrOperator()=default; + RBAOrOperator(const RBAOrOperator&)=delete; + RBAOrOperator(const RBAOrOperator&&)=delete; + RBAOrOperator& operator=(const RBAOrOperator&)=delete; + RBAOrOperator& operator=(const RBAOrOperator&&)=delete; + virtual ~RBAOrOperator()=default; + + public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + bool executeCore(RBAConstraintInfo* info, RBAArbitrator * arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAOrOperatorMaker.cpp b/src/core/expression/RBAOrOperatorMaker.cpp new file mode 100644 index 0000000..934c7e1 --- /dev/null +++ b/src/core/expression/RBAOrOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAOrOperatorMaker.cpp +/// @brief OrOperator object generator + +#include "RBAOrOperatorMaker.hpp" +#include "RBAOrOperator.hpp" + +namespace rba +{ + +RBAOrOperatorMaker::RBAOrOperatorMaker() + : RBAOperatorMaker{"OrOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAOrOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAOrOperator>(); +} + +} diff --git a/src/core/expression/RBAOrOperatorMaker.hpp b/src/core/expression/RBAOrOperatorMaker.hpp new file mode 100644 index 0000000..def4d8f --- /dev/null +++ b/src/core/expression/RBAOrOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAOrOperatorMaker.hpp +/// @brief OrOperator object generator class header + +#ifndef RBAOROPERATORMAKER_HPP +#define RBAOROPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief OrOperator object generator class +class RBAOrOperatorMaker : public RBAOperatorMaker +{ +public: + RBAOrOperatorMaker(); + RBAOrOperatorMaker(const RBAOrOperatorMaker&)=delete; + RBAOrOperatorMaker(const RBAOrOperatorMaker&&)=delete; + RBAOrOperatorMaker& operator=(const RBAOrOperatorMaker&)=delete; + RBAOrOperatorMaker& operator=(const RBAOrOperatorMaker&&)=delete; + virtual ~RBAOrOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAPlusOperator.cpp b/src/core/expression/RBAPlusOperator.cpp new file mode 100644 index 0000000..8a6dbbb --- /dev/null +++ b/src/core/expression/RBAPlusOperator.cpp @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * PlusOperator class definition + */ + +#include "RBAPlusOperator.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +RBAModelElementType +RBAPlusOperator::getModelElementType() const +{ + return RBAModelElementType::PlusOperator; +} + +} diff --git a/src/core/expression/RBAPlusOperator.hpp b/src/core/expression/RBAPlusOperator.hpp new file mode 100644 index 0000000..ab04ebb --- /dev/null +++ b/src/core/expression/RBAPlusOperator.hpp @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * PlusOperator class header + */ + +#ifndef RBAPLUSOPERATOR_HPP +#define RBAPLUSOPERATOR_HPP + +#include "RBAArithmeticOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAPlusOperator : public RBAArithmeticOperator +{ +public: + RBAPlusOperator()=default; + RBAPlusOperator(const RBAPlusOperator&)=delete; + RBAPlusOperator(const RBAPlusOperator&&)=delete; + RBAPlusOperator& operator=(const RBAPlusOperator&)=delete; + RBAPlusOperator& operator=(const RBAPlusOperator&&)=delete; + virtual ~RBAPlusOperator()=default; + +public: + RBAModelElementType getModelElementType() const override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAPlusOperatorMaker.cpp b/src/core/expression/RBAPlusOperatorMaker.cpp new file mode 100644 index 0000000..677d456 --- /dev/null +++ b/src/core/expression/RBAPlusOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAPlusOperatorsMaker.cpp +/// @brief PlusOperator object generator class definition + +#include "RBAPlusOperatorMaker.hpp" +#include "RBAPlusOperator.hpp" + +namespace rba +{ + +RBAPlusOperatorMaker::RBAPlusOperatorMaker() + : RBAOperatorMaker{"PlusOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAPlusOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAPlusOperator>(); +} + +} diff --git a/src/core/expression/RBAPlusOperatorMaker.hpp b/src/core/expression/RBAPlusOperatorMaker.hpp new file mode 100644 index 0000000..aea1df7 --- /dev/null +++ b/src/core/expression/RBAPlusOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAPlusOperatorsMaker.hpp +/// @brief PlusOperator object generator class header + +#ifndef RBAPLUSOPERATORMAKER_HPP +#define RBAPLUSOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief PlusOperator object generator class +class RBAPlusOperatorMaker : public RBAOperatorMaker +{ +public: + RBAPlusOperatorMaker(); + RBAPlusOperatorMaker(const RBAPlusOperatorMaker&)=delete; + RBAPlusOperatorMaker(const RBAPlusOperatorMaker&&)=delete; + RBAPlusOperatorMaker& operator=(const RBAPlusOperatorMaker&)=delete; + RBAPlusOperatorMaker& operator=(const RBAPlusOperatorMaker&&)=delete; + virtual ~RBAPlusOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAPreviousModifier.cpp b/src/core/expression/RBAPreviousModifier.cpp new file mode 100644 index 0000000..53a7112 --- /dev/null +++ b/src/core/expression/RBAPreviousModifier.cpp @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * PreviousModifier class definition + */ + +#include "RBAPreviousModifier.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBAPreviousObjectWrapper.hpp" + +namespace rba +{ + +RBAPreviousModifier::RBAPreviousModifier() + : RBAExpression(), + previousObj_{std::make_unique<RBAPreviousObjectWrapper>()} +{ +} + +void +RBAPreviousModifier::accept(RBAExpressionVisitor& visitor) +{ + // RBASceneAllocatableCollector, + // which is the only vistor that exists at the moment, + // does not pass this path because it does not accept the rule object. + // In the future, another visitor may accept, so implement this. + visitor.visit(*this); +} + +void +RBAPreviousModifier::setObjReference(RBAExpression* const newObjRef) +{ + objReference_ = newObjRef; +} + +RBAExpression* const +RBAPreviousModifier::getObjReference() const +{ + return objReference_; +} + +const RBARuleObject* +RBAPreviousModifier::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + previousObj_->setRefObject(objReference_->getReferenceObject(info, arb)); + return previousObj_.get(); +} + +#ifdef RBA_USE_LOG +const std::string +RBAPreviousModifier::getSymbol() const +{ + return "(pre)"; +} + +void +RBAPreviousModifier::createHierarchy() +{ + objReference_->createHierarchy(); +} + +const std::string +RBAPreviousModifier::getExpressionText() const +{ + return getSymbol() + objReference_->getExpressionText(); +} + +const std::string +RBAPreviousModifier::getCoverageExpressionText() const +{ + return getSymbol() + objReference_->getCoverageExpressionText(); +} + +RBAExpressionType +RBAPreviousModifier::getUnderlyingType() const +{ + return objReference_->getUnderlyingType(); +} + +#endif + +} diff --git a/src/core/expression/RBAPreviousModifier.hpp b/src/core/expression/RBAPreviousModifier.hpp new file mode 100644 index 0000000..ff34deb --- /dev/null +++ b/src/core/expression/RBAPreviousModifier.hpp @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * PreviousModifier class header + */ + + +#ifndef RBAPREVIOUSMODIFIER_HPP +#define RBAPREVIOUSMODIFIER_HPP + +#include <memory> +#include "RBAExpression.hpp" + +namespace rba +{ + +class RBAPreviousObjectWrapper; + +class DLL_EXPORT RBAPreviousModifier : public RBAExpression +{ +public: + RBAPreviousModifier(); + RBAPreviousModifier(const RBAPreviousModifier&)=delete; + RBAPreviousModifier(const RBAPreviousModifier&&)=delete; + RBAPreviousModifier& operator=(const RBAPreviousModifier&)=delete; + RBAPreviousModifier& operator=(const RBAPreviousModifier&&)=delete; + virtual ~RBAPreviousModifier()=default; + + void accept(RBAExpressionVisitor& visitor) override; + void setObjReference(RBAExpression* const newObjRef); + RBAExpression* const getObjReference() const; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + virtual const std::string getSymbol() const; + void createHierarchy() override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + RBAExpressionType getUnderlyingType() const override; +#endif + +private: + // This pointer is not "const" in order to call + // objReference_->getReferenceObject() + RBAExpression* objReference_; +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::unique_ptr<RBAPreviousObjectWrapper> previousObj_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAPreviousModifierMaker.cpp b/src/core/expression/RBAPreviousModifierMaker.cpp new file mode 100644 index 0000000..764ef34 --- /dev/null +++ b/src/core/expression/RBAPreviousModifierMaker.cpp @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAPreviousModifierMaker.cpp +/// @brief PreviousModifier object generator class definition + +#include "RBAPreviousModifierMaker.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBAPreviousModifier.hpp" +#include "RBAPreviousObjectWrapper.hpp" + +namespace rba +{ + +RBAPreviousModifierMaker::RBAPreviousModifierMaker() + : RBAExpressionMaker{"PreviousModifier"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAPreviousModifierMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAPreviousModifier>(); +} + +RBAModelElement* +RBAPreviousModifierMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + RBAPreviousModifier* const prevMod {dynamic_cast<RBAPreviousModifier*>(element)}; + + // Set LetStatement + const std::int32_t pop_num {setLetStatement(model, prevMod, jsonElem)}; + + // Set object reference + const RBAJsonElement* const objRefElem {jsonElem->findChildren("objReference")}; + RBAModelElement* const expr {getFactory()->createElement(objRefElem->getClassName(), + objRefElem)}; + prevMod->setObjReference(dynamic_cast<RBAExpression*>(expr)); + + // Pop variable + for(std::int32_t i{0}; i<pop_num; i++) { + getFactory()->popVariable(); + } + + return prevMod; +} + +} diff --git a/src/core/expression/RBAPreviousModifierMaker.hpp b/src/core/expression/RBAPreviousModifierMaker.hpp new file mode 100644 index 0000000..0f58892 --- /dev/null +++ b/src/core/expression/RBAPreviousModifierMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAPreviousModifierMaker.cpp +/// @brief PreviousModifier object generator class header + +#ifndef RBAPREVIOUSMODIFIERMAKER_HPP +#define RBAPREVIOUSMODIFIERMAKER_HPP + +#include "RBAExpressionMaker.hpp" + +namespace rba +{ + +/// @brief PreviousModifier object generator class +class RBAPreviousModifierMaker : public RBAExpressionMaker +{ +public: + RBAPreviousModifierMaker(); + RBAPreviousModifierMaker(const RBAPreviousModifierMaker&)=delete; + RBAPreviousModifierMaker(const RBAPreviousModifierMaker&&)=delete; + RBAPreviousModifierMaker& operator=(const RBAPreviousModifierMaker&)=delete; + RBAPreviousModifierMaker& operator=(const RBAPreviousModifierMaker&&)=delete; + virtual ~RBAPreviousModifierMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAPreviousObjectWrapper.cpp b/src/core/expression/RBAPreviousObjectWrapper.cpp new file mode 100644 index 0000000..348b05f --- /dev/null +++ b/src/core/expression/RBAPreviousObjectWrapper.cpp @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * PreviousObjectWrapper (Previous Wrapper of RuleObject) + * generator class definition + */ + +#include "RBAPreviousObjectWrapper.hpp" + +namespace rba +{ + +bool +RBAPreviousObjectWrapper::isPrevious() const +{ + return true; +} + +const RBARuleObject* +RBAPreviousObjectWrapper::getRawObject() const +{ + return refObject_->getRawObject(); +} + +void +RBAPreviousObjectWrapper::setRefObject(const RBARuleObject* const obj) +{ + refObject_ = obj; +} + +} diff --git a/src/core/expression/RBAPreviousObjectWrapper.hpp b/src/core/expression/RBAPreviousObjectWrapper.hpp new file mode 100644 index 0000000..571c450 --- /dev/null +++ b/src/core/expression/RBAPreviousObjectWrapper.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * PreviousObjectWrapper (Previous Wrapper of RuleObject) + * generator class header + */ + +#ifndef RBAPREVIOUSOBJECTWRAPPER_HPP +#define RBAPREVIOUSOBJECTWRAPPER_HPP + +#include "RBARuleObject.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAPreviousObjectWrapper : public RBARuleObject +{ +public: + RBAPreviousObjectWrapper()=default; + RBAPreviousObjectWrapper(const RBAPreviousObjectWrapper&)=delete; + RBAPreviousObjectWrapper(const RBAPreviousObjectWrapper&&)=delete; + RBAPreviousObjectWrapper& operator=(const RBAPreviousObjectWrapper&)=delete; + RBAPreviousObjectWrapper& operator=(const RBAPreviousObjectWrapper&&)=delete; + virtual ~RBAPreviousObjectWrapper()=default; + +public: + bool isPrevious() const override; + const RBARuleObject* getRawObject() const override; + void setRefObject(const RBARuleObject* const obj); + +private: + const RBARuleObject* refObject_ {nullptr}; + +}; + +} + +#endif diff --git a/src/core/expression/RBAPropertyOperator.hpp b/src/core/expression/RBAPropertyOperator.hpp new file mode 100644 index 0000000..250e6a2 --- /dev/null +++ b/src/core/expression/RBAPropertyOperator.hpp @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * PropertyOperator class definition + */ + +#ifndef RBAPROPERTYOPERATOR_HPP +#define RBAPROPERTYOPERATOR_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAPropertyOperator : public RBAOperator +{ +protected: + RBAPropertyOperator()=default; + RBAPropertyOperator(const RBAPropertyOperator&)=delete; + RBAPropertyOperator(const RBAPropertyOperator&&)=delete; + RBAPropertyOperator& operator=(const RBAPropertyOperator&)=delete; + RBAPropertyOperator& operator=(const RBAPropertyOperator&&)=delete; + +public: + virtual ~RBAPropertyOperator()=default; + +}; + +} + +#endif +
\ No newline at end of file diff --git a/src/core/expression/RBASceneCondition.hpp b/src/core/expression/RBASceneCondition.hpp new file mode 100644 index 0000000..44f543c --- /dev/null +++ b/src/core/expression/RBASceneCondition.hpp @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * SceneCondition class header + */ + +#ifndef RBASCENECONDITION_HPP +#define RBASCENECONDITION_HPP + +#include "RBAExpression.hpp" + +namespace rba +{ + +class DLL_EXPORT RBASceneCondition : public RBAExpression +{ +protected: + RBASceneCondition()=default; + RBASceneCondition(const RBASceneCondition&)=delete; + RBASceneCondition(const RBASceneCondition&&)=delete; + RBASceneCondition& operator=(const RBASceneCondition&)=delete; + RBASceneCondition& operator=(const RBASceneCondition&&)=delete; +public: + virtual ~RBASceneCondition()=default; + +}; + +} + +#endif diff --git a/src/core/expression/RBASceneOperator.hpp b/src/core/expression/RBASceneOperator.hpp new file mode 100644 index 0000000..630c655 --- /dev/null +++ b/src/core/expression/RBASceneOperator.hpp @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * SceneOperator class header + */ + +#ifndef RBASCENEOPERATOR_HPP +#define RBASCENEOPERATOR_HPP + +#include "RBADllExport.hpp" +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBASceneOperator : public RBAOperator +{ +protected: + RBASceneOperator()=default; + RBASceneOperator(const RBASceneOperator&)=delete; + RBASceneOperator(const RBASceneOperator&&)=delete; + RBASceneOperator& operator=(const RBASceneOperator&)=delete; + RBASceneOperator& operator=(const RBASceneOperator&&)=delete; +public: + ~RBASceneOperator()=default; + +}; + +} + +#endif diff --git a/src/core/expression/RBASelectOperator.cpp b/src/core/expression/RBASelectOperator.cpp new file mode 100644 index 0000000..be74fa5 --- /dev/null +++ b/src/core/expression/RBASelectOperator.cpp @@ -0,0 +1,140 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * SelectOperator class definition + */ + +#include <memory> +#include "RBASelectOperator.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAContent.hpp" +#include "RBAContentSet.hpp" +#include "RBAAllocatable.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALambdaExpression.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +RBASelectOperator::RBASelectOperator() +: RBALambdaContext(), + allocatableSet_{std::make_unique<RBAAllocatableSet>()}, + contentSet_{std::make_unique<RBAContentSet>()} +{ +} + +void +RBASelectOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBASelectOperator::getModelElementType() const +{ + return RBAModelElementType::SelectOperator; +} + +const RBARuleObject* RBASelectOperator::getReferenceObjectCore( + RBAConstraintInfo* info, RBAArbitrator* arb) const +{ + LOG_addHierarchy(LOG_getSymbol()); + const RBARuleObject* returnObj {nullptr}; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const lhsObj {getLhsOperand()->getReferenceObject(leftInfo, + arb)}; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else if (lhsObj != nullptr) { + if (dynamic_cast<const RBAAllocatableSet*>(lhsObj) != nullptr) { + std::list<const RBAAllocatable*> objs { + dynamic_cast<const RBAAllocatableSet*>(lhsObj)->getLeafAllocatable()}; + allocatableSet_->clear(); + std::uint32_t i {0U}; + RBALambdaExpression* const lambda {getLambda()}; + for (auto& obj : objs) { + LOG_addHierarchy("#" + std::to_string(i)); + ++i; + RBAConstraintInfo* const childInfo {info->getChild(i)}; + lambda->setRuleObj(obj); + const bool isPassed {lambda->execute(childInfo, arb)}; + LOG_removeHierarchy(); + if (isPassed && (!childInfo->isExceptionBeforeArbitrate())) { + allocatableSet_->addTarget(obj); + } + } + returnObj = allocatableSet_.get(); + } else { + std::list<const RBAContent*> objs { + dynamic_cast<const RBAContentSet*>(lhsObj)->getLeafContent()}; + contentSet_->clear(); + std::uint32_t i {0U}; + RBALambdaExpression* const lambda {getLambda()}; + for (auto& obj : objs) { + LOG_addHierarchy("#" + std::to_string(i)); + ++i; + RBAConstraintInfo* const childInfo {info->getChild(i)}; + lambda->setRuleObj(obj); + const bool isPassed {lambda->execute(childInfo, arb)}; + LOG_removeHierarchy(); + if (isPassed && (!childInfo->isExceptionBeforeArbitrate())) { + contentSet_->addTarget(obj); + } + } + returnObj = contentSet_.get(); + } + } else { + ; + } +#ifdef RBA_USE_LOG + std::string objName = "NULL"; + if (returnObj != nullptr) { + objName = returnObj->getElementName(); + if (objName == "") { + objName = returnObj->getDynamicName(); + } + } + LOG_arbitrateConstraintLogicLogLine( + " " + LOG_getExpressionText() + " is " + objName); +#endif + LOG_removeHierarchy(); + return returnObj; +} +#ifdef RBA_USE_LOG +const std::string RBASelectOperator::getSymbol() const +{ + return ".select"; +} + +const std::string RBASelectOperator::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol() + + getLambda()->getExpressionText(); +} + +const std::string RBASelectOperator::getCoverageExpressionText() const +{ + getLambda()->clearRuleObj(); + return getLhsOperand()->getCoverageExpressionText() + getSymbol() + + getLambda()->getCoverageExpressionText(); +} +#endif + +} // namespace rba diff --git a/src/core/expression/RBASelectOperator.hpp b/src/core/expression/RBASelectOperator.hpp new file mode 100644 index 0000000..9c85fb0 --- /dev/null +++ b/src/core/expression/RBASelectOperator.hpp @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * SelectOperator class header + */ + +#ifndef RBASELECTOPERATOR_HPP +#define RBASELECTOPERATOR_HPP + +#include "RBALambdaContext.hpp" + +namespace rba +{ + +class RBAAllocatableSet; +class RBAContentSet; + +class RBASelectOperator : public RBALambdaContext +{ + public: + RBASelectOperator(); + RBASelectOperator(const RBASelectOperator&)=delete; + RBASelectOperator(const RBASelectOperator&&)=delete; + RBASelectOperator& operator=(const RBASelectOperator&)=delete; + RBASelectOperator& operator=(const RBASelectOperator&&)=delete; + virtual ~RBASelectOperator()=default; + + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; +#endif + private: + std::unique_ptr<RBAAllocatableSet> allocatableSet_; + std::unique_ptr<RBAContentSet> contentSet_; +}; + +} /* namespace rba */ + +#endif /* RBASELECTOPERATOR_HPP */ diff --git a/src/core/expression/RBASelectOperatorMaker.cpp b/src/core/expression/RBASelectOperatorMaker.cpp new file mode 100644 index 0000000..d7c1a35 --- /dev/null +++ b/src/core/expression/RBASelectOperatorMaker.cpp @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBASelectOperatorMaker.cpp +/// @brief SelectOperator object generator class definition + +#include "RBASelectOperatorMaker.hpp" +#include "RBASelectOperator.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBALambdaExpression.hpp" + +namespace rba +{ + +RBASelectOperatorMaker::RBASelectOperatorMaker() + : RBALambdaContextMaker{"SelectOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBASelectOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBASelectOperator>(); +} + +RBAModelElement* +RBASelectOperatorMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>( + RBALambdaContextMaker::setProperty(element, jsonElem, model, owner)); + + return element; +} + +std::unique_ptr<RBALambdaContext> +RBASelectOperatorMaker::createLambdaContext() +{ + return std::make_unique<RBASelectOperator>(); +} + +} diff --git a/src/core/expression/RBASelectOperatorMaker.hpp b/src/core/expression/RBASelectOperatorMaker.hpp new file mode 100644 index 0000000..0415331 --- /dev/null +++ b/src/core/expression/RBASelectOperatorMaker.hpp @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBASelectOperatorMaker.cpp +/// @brief SelectOperator object generator class header + +#ifndef RBASELECTOPERATORMAKER_HPP +#define RBASELECTOPERATORMAKER_HPP + +#include "RBALambdaContextMaker.hpp" + +namespace rba +{ + +/// @brief SelectOperator object generator class +class RBASelectOperatorMaker : public RBALambdaContextMaker +{ +public: + RBASelectOperatorMaker(); + RBASelectOperatorMaker(const RBASelectOperatorMaker&)=delete; + RBASelectOperatorMaker(const RBASelectOperatorMaker&&)=delete; + RBASelectOperatorMaker& operator=(const RBASelectOperatorMaker&)=delete; + RBASelectOperatorMaker& operator=(const RBASelectOperatorMaker&&)=delete; + virtual ~RBASelectOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated object + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) override; + + /// @brief generate an empty object of LambdaContext + /// @details generate an empty object of unique_ptr + /// @return unique_ptr for object of LambdaContext + std::unique_ptr<RBALambdaContext> createLambdaContext() override; + +}; + +} + +#endif diff --git a/src/core/expression/RBASetExpression.hpp b/src/core/expression/RBASetExpression.hpp new file mode 100644 index 0000000..5ad1de4 --- /dev/null +++ b/src/core/expression/RBASetExpression.hpp @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * SetExpression class header + */ + +#ifndef RBASETEXPRESSION_HPP +#define RBASETEXPRESSION_HPP + +#include "RBAExpression.hpp" + +namespace rba +{ + +class DLL_EXPORT RBASetExpression : public RBAExpression +{ +protected: + RBASetExpression()=default; + RBASetExpression(const RBASetExpression&)=delete; + RBASetExpression(const RBASetExpression&&)=delete; + RBASetExpression& operator=(const RBASetExpression&)=delete; + RBASetExpression& operator=(const RBASetExpression&&)=delete; +public: + virtual ~RBASetExpression()=default; + +}; + +} + +#endif diff --git a/src/core/expression/RBASetOfOperator.cpp b/src/core/expression/RBASetOfOperator.cpp new file mode 100644 index 0000000..03e82eb --- /dev/null +++ b/src/core/expression/RBASetOfOperator.cpp @@ -0,0 +1,194 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * RBASetOfOperator class definition + */ + +#include <sstream> +#include "RBASetOfOperator.hpp" +#include "RBARuleObject.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAContentSet.hpp" +#include "RBAAllocatable.hpp" +#include "RBAContent.hpp" +#include "RBALogManager.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBAModelElementType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +RBASetOfOperator::RBASetOfOperator() + : RBAOperator(), + allocatableSet_{std::make_unique<RBAAllocatableSet>()}, + contentSet_{std::make_unique<RBAContentSet>()} +{ +} + +void +RBASetOfOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} + +RBAModelElementType +RBASetOfOperator::getModelElementType() const +{ + return RBAModelElementType::SetOfOperator; +} + +const RBARuleObject* +RBASetOfOperator::getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + allocatableSet_->clear(); + contentSet_->clear(); + + bool isAllocatableSet {false}; + bool isContentSet {false}; + + std::uint32_t i {0U}; + for(const RBAExpression* const expr : getOperand()) { + RBAConstraintInfo* const childInfo {info->getChild(i)}; + const RBARuleObject* const obj {expr->getReferenceObject(childInfo,arb)}; + if(childInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + return nullptr; + } + if(obj != nullptr) { + if (obj->isModelElementType(RBAModelElementType::Area) || + obj->isModelElementType(RBAModelElementType::Zone)) { + allocatableSet_->addTarget(dynamic_cast<const RBAAllocatable*>(obj)); + isAllocatableSet = true; + } + else if (obj->isModelElementType(RBAModelElementType::ViewContent) || + obj->isModelElementType(RBAModelElementType::SoundContent)) { + contentSet_->addTarget(dynamic_cast<const RBAContent*>(obj)); + isContentSet = true; + } + else if (dynamic_cast<const RBAAllocatableSet*>(obj) != nullptr) { + for (const RBAAllocatable* const a : dynamic_cast<const RBAAllocatableSet*>(obj)->getLeafAllocatable()) { + allocatableSet_->addTarget(a); + } + isAllocatableSet = true; + } else { + for (const RBAContent* const c : dynamic_cast<const RBAContentSet*>(obj)->getLeafContent()) { + contentSet_->addTarget(c); + } + isContentSet = true; + } + } + i++; + } + if (isAllocatableSet) { + return allocatableSet_.get(); + } else if (isContentSet){ + return contentSet_.get(); + } else { + return nullptr; + } +} + +void +RBASetOfOperator::doActionCore(RBAConstraintInfo* info, RBAArbitrator* arb) +{ + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy("SetOf"); + + std::uint32_t i {0U}; + for(RBAExpression* const expr : getOperand()) { + // Add number of element to Constraint hierarchy for coverage + LOG_addHierarchy("#" + std::to_string(i) + ":"); + + // Since it should only execute Action, info is as it is + expr->doAction(info, arb); + i++; + + // Remove number of element from Constraint hierarchy for coverage + LOG_removeHierarchy(); + } + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); + + return; +} + +#ifdef RBA_USE_LOG +const std::string +RBASetOfOperator::getExpressionText() const +{ + std::ostringstream oss; + oss << "{"; + const auto& exprList = getOperand(); + const auto& lastExpr = exprList.back(); + for (const auto& expr : exprList) { + oss << expr->getExpressionText(); + if (expr != lastExpr) { + oss << ", "; + } + } + oss << "}"; + + return oss.str(); +} + +const std::string +RBASetOfOperator::getCoverageExpressionText() const +{ + std::ostringstream oss; + oss << "{"; + const auto& exprList = getOperand(); + const auto& lastExpr = exprList.back(); + for (const auto& expr : exprList) { + oss << expr->getCoverageExpressionText(); + if (expr != lastExpr) { + oss << ", "; + } + } + oss << "}"; + + return oss.str(); +} + +void +RBASetOfOperator::createHierarchy() +{ + // Add itself to Constraint hierarchy for coverage + LOG_addHierarchy("SetOf"); + RBALogManager::coverageHierarchyOfConstraintExpressionLog(getCoverageExpressionText(), this); + uint32_t idx=0; + for(RBAExpression* expr : getOperand()) { + // Add number of element to Constraint hierarchy for coverage + LOG_addHierarchy("#"+std::to_string(idx)+":"); + expr->createHierarchy(); + // Remove number of element from Constraint hierarchy for coverage + LOG_removeHierarchy(); + idx++; + } + // Remove itself from Constraint hierarchy for coverage + LOG_removeHierarchy(); +} + +RBAExpressionType +RBASetOfOperator::getUnderlyingType() const +{ + return getLhsOperand()->getUnderlyingType(); +} +#endif + +} diff --git a/src/core/expression/RBASetOfOperator.hpp b/src/core/expression/RBASetOfOperator.hpp new file mode 100644 index 0000000..d73e1f7 --- /dev/null +++ b/src/core/expression/RBASetOfOperator.hpp @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * RBASetOfOperator class header + */ + +#ifndef RBASETOFOPERATOR_HPP +#define RBASETOFOPERATOR_HPP + +#include <memory> +#include "RBAOperator.hpp" + +namespace rba +{ + +class RBAAllocatableSet; +class RBAContentSet; + +class DLL_EXPORT RBASetOfOperator : public RBAOperator +{ +public: + RBASetOfOperator(); + RBASetOfOperator(const RBASetOfOperator&)=delete; + RBASetOfOperator(const RBASetOfOperator&&)=delete; + RBASetOfOperator& operator=(const RBASetOfOperator&)=delete; + RBASetOfOperator& operator=(const RBASetOfOperator&&)=delete; + virtual ~RBASetOfOperator()=default; + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; + void createHierarchy() override; + RBAExpressionType getUnderlyingType() const override; +#endif + +protected: + const RBARuleObject* getReferenceObjectCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + void doActionCore(RBAConstraintInfo* info, RBAArbitrator* arb) override; + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::unique_ptr<RBAAllocatableSet> allocatableSet_; + std::unique_ptr<RBAContentSet> contentSet_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBASetOfOperatorMaker.cpp b/src/core/expression/RBASetOfOperatorMaker.cpp new file mode 100644 index 0000000..f17f17d --- /dev/null +++ b/src/core/expression/RBASetOfOperatorMaker.cpp @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBASetOfOperatorMaker.cpp +/// @brief SetOfOperator object generator class + +#include "RBASetOfOperatorMaker.hpp" +#include "RBASetOfOperator.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAContentSet.hpp" + +namespace rba +{ + +RBASetOfOperatorMaker::RBASetOfOperatorMaker() + : RBAOperatorMaker{"SetOfOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBASetOfOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBASetOfOperator>(); +} + +} diff --git a/src/core/expression/RBASetOfOperatorMaker.hpp b/src/core/expression/RBASetOfOperatorMaker.hpp new file mode 100644 index 0000000..87905fa --- /dev/null +++ b/src/core/expression/RBASetOfOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBASetOfOperatorMaker.cpp +/// @brief SetOfOperator object generator class header + +#ifndef RBASETOFOPERATORMAKER_HPP +#define RBASETOFOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief SetOfOperator object generator class +class RBASetOfOperatorMaker : public RBAOperatorMaker +{ +public: + RBASetOfOperatorMaker(); + RBASetOfOperatorMaker(const RBASetOfOperatorMaker&)=delete; + RBASetOfOperatorMaker(const RBASetOfOperatorMaker&&)=delete; + RBASetOfOperatorMaker& operator=(const RBASetOfOperatorMaker&)=delete; + RBASetOfOperatorMaker& operator=(const RBASetOfOperatorMaker&&)=delete; + virtual ~RBASetOfOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBASetOperator.hpp b/src/core/expression/RBASetOperator.hpp new file mode 100644 index 0000000..ded7a16 --- /dev/null +++ b/src/core/expression/RBASetOperator.hpp @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * SetOperator class header + */ + +#ifndef RBASETOPERATOR_HPP +#define RBASETOPERATOR_HPP + +#include "RBAOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBASetOperator : public RBAOperator +{ +protected: + RBASetOperator()=default; + RBASetOperator(const RBASetOperator&)=delete; + RBASetOperator(const RBASetOperator&&)=delete; + RBASetOperator& operator=(const RBASetOperator&)=delete; + RBASetOperator& operator=(const RBASetOperator&&)=delete; +public: + virtual ~RBASetOperator()=default; + +}; + +} + +#endif diff --git a/src/core/expression/RBASizeOperator.cpp b/src/core/expression/RBASizeOperator.cpp new file mode 100644 index 0000000..c928bcf --- /dev/null +++ b/src/core/expression/RBASizeOperator.cpp @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// SizeOperator class definition +// + +#include "RBASizeOperator.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBAModelElementType.hpp" +#include "RBALogManager.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAContentSet.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +void RBASizeOperator::accept(RBAExpressionVisitor& visitor) +{ + visitor.visit(*this); +} +RBAModelElementType RBASizeOperator::getModelElementType() const +{ + return RBAModelElementType::SizeOperator; +} +std::int32_t RBASizeOperator::getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const +{ + LOG_addHierarchy(LOG_getSymbol()); + std::int32_t returnValue {-99}; + RBAConstraintInfo* const leftInfo {info->getChild(0U)}; + const RBARuleObject* const lhsObj {getLhsOperand()->getReferenceObject(leftInfo, + arb)}; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else if (lhsObj != nullptr) { + if (dynamic_cast<const RBAAllocatableSet*>(lhsObj) != nullptr) { + returnValue = static_cast<std::int32_t>(dynamic_cast<const RBAAllocatableSet*>(lhsObj) + ->getLeafAllocatable().size()); + } else { + returnValue = static_cast<std::int32_t>(dynamic_cast<const RBAContentSet*>(lhsObj)->getLeafContent() + .size()); + } + } else { + ; + } +#ifdef RBA_USE_LOG + LOG_arbitrateConstraintLogicLogLine( + " " + LOG_getExpressionText() + " is " + std::to_string(returnValue)); +#endif + LOG_removeHierarchy(); + return returnValue; +} + +#ifdef RBA_USE_LOG +const std::string RBASizeOperator::getSymbol() const +{ + return ".size()"; +} +const std::string RBASizeOperator::getExpressionText() const +{ + return getLhsOperand()->getExpressionText() + getSymbol(); +} +const std::string RBASizeOperator::getCoverageExpressionText() const +{ + return getLhsOperand()->getCoverageExpressionText() + getSymbol(); +} +#endif + +} /* namespace rba */ diff --git a/src/core/expression/RBASizeOperator.hpp b/src/core/expression/RBASizeOperator.hpp new file mode 100644 index 0000000..26f22fa --- /dev/null +++ b/src/core/expression/RBASizeOperator.hpp @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// SizeOperator class header +// + +#ifndef RBASIZEOPERATOR_HPP +#define RBASIZEOPERATOR_HPP + +#include "RBASetOperator.hpp" + +namespace rba +{ + +class RBASizeOperator : public RBASetOperator +{ + public: + RBASizeOperator()=default; + RBASizeOperator(const RBASizeOperator&)=delete; + RBASizeOperator(const RBASizeOperator&&)=delete; + RBASizeOperator& operator=(const RBASizeOperator&)=delete; + RBASizeOperator& operator=(const RBASizeOperator&&)=delete; + virtual ~RBASizeOperator()=default; + + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + std::int32_t getValueCore(RBAConstraintInfo* info, RBAArbitrator* arb) const override; +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; + const std::string getExpressionText() const override; + const std::string getCoverageExpressionText() const override; +#endif +}; + +} /* namespace rba */ + +#endif /* SRC_CORE_EXPRESSION_RBASIZEOPERATOR_HPP_ */ diff --git a/src/core/expression/RBASizeOperatorMaker.cpp b/src/core/expression/RBASizeOperatorMaker.cpp new file mode 100644 index 0000000..2a905c7 --- /dev/null +++ b/src/core/expression/RBASizeOperatorMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBASizeOperatorMaker.cpp +/// @brief SizeOperator object generator class definition + +#include "RBASizeOperatorMaker.hpp" +#include "RBASizeOperator.hpp" + +namespace rba +{ + +RBASizeOperatorMaker::RBASizeOperatorMaker() + : RBAOperatorMaker{"SizeOperator"} +{ +} + +std::unique_ptr<RBAModelElement> +RBASizeOperatorMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBASizeOperator>(); +} + +} diff --git a/src/core/expression/RBASizeOperatorMaker.hpp b/src/core/expression/RBASizeOperatorMaker.hpp new file mode 100644 index 0000000..b5dd0f6 --- /dev/null +++ b/src/core/expression/RBASizeOperatorMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBASizeOperatorMaker.hpp +/// @brief SizeOperator object generator abstract class header + +#ifndef RBASIZEOPERATORMAKER_HPP +#define RBASIZEOPERATORMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief SizeOperator object generator class +class RBASizeOperatorMaker : public RBAOperatorMaker +{ +public: + RBASizeOperatorMaker(); + RBASizeOperatorMaker(const RBASizeOperatorMaker&)=delete; + RBASizeOperatorMaker(const RBASizeOperatorMaker&&)=delete; + RBASizeOperatorMaker& operator=(const RBASizeOperatorMaker&)=delete; + RBASizeOperatorMaker& operator=(const RBASizeOperatorMaker&&)=delete; + virtual ~RBASizeOperatorMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAStateValue.cpp b/src/core/expression/RBAStateValue.cpp new file mode 100644 index 0000000..f2fe5cb --- /dev/null +++ b/src/core/expression/RBAStateValue.cpp @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /// StateValue class denition + +#include <string> +#include "RBAStateValue.hpp" +#include "RBAArbitrator.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAContent.hpp" +#include "RBAContentState.hpp" +#include "RBAExpressionVisitor.hpp" +#include "RBALogManager.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +void RBAStateValue::accept(RBAExpressionVisitor& visitor) +{ + // RBASceneAllocatableCollector which is the only existing vistor + // does not pass this path because it does not accept + // the expression that returns Value. But, in the future, + // another visitor may accept, so implement this. + visitor.visit(*this); +} + +RBAModelElementType +RBAStateValue::getModelElementType() const +{ + return RBAModelElementType::StateValue; +} + +std::int32_t +RBAStateValue::getValueCore(RBAConstraintInfo* info, RBAArbitrator* arb) const +{ + std::int32_t result { -99 }; + const auto leftInfo = info->getChild(0U); + const auto r = getLhsOperand()->getReferenceObject(leftInfo, arb); + const RBAContent* c { nullptr }; + const RBAContentState* cs { nullptr }; + if (leftInfo->isExceptionBeforeArbitrate()) { + info->setExceptionBeforeArbitrate(true); + } else { + if (r != nullptr) { + c = dynamic_cast<const RBAContent*>(r->getRawObject()); + if (c != nullptr) { + if (r->isPrevious()) { + cs = arb->getResult()->getPreActiveState(c); + } else { + cs = arb->getResult()->getActiveState(c); + } + if (cs != nullptr) { + result = cs->getContentStatePriority(); + } + } + } + } +#ifdef RBA_USE_LOG + std::string pre; + std::string cName { "NULL" }; + std::string resultText{ "no Content skip" }; + if (r != nullptr) { + cName = r->getElementName(); + pre = getPreMsg(r->isPrevious()); + } + if (info->isExceptionBeforeArbitrate()) { + resultText = "before arbitrate skip"; + } else { + if (cs != nullptr) { + resultText = cs->getElementName() + " : " + std::to_string(result); + } + } + LOG_arbitrateConstraintLogicLogLine( + " " + + pre + + "Content[" + + cName + + "] state value [" + + resultText + + "]"); +#endif + return result; +} + +#ifdef RBA_USE_LOG +const std::string +RBAStateValue::getSymbol() const +{ + return ".stateValue()"; +} +#endif + +} diff --git a/src/core/expression/RBAStateValue.hpp b/src/core/expression/RBAStateValue.hpp new file mode 100644 index 0000000..52cf8fc --- /dev/null +++ b/src/core/expression/RBAStateValue.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /// StateValue class header + +#ifndef RBASTATEVALUE_HPP +#define RBASTATEVALUE_HPP + +#include <cstdint> +#include "RBAContentOperator.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAStateValue : public RBAContentOperator +{ +public: + RBAStateValue()=default; + RBAStateValue(const RBAStateValue&)=delete; + RBAStateValue(RBAStateValue&&)=delete; + RBAStateValue& operator=(const RBAStateValue&)=delete; + RBAStateValue& operator=(RBAStateValue&&)=delete; + virtual ~RBAStateValue()=default; + +public: + void accept(RBAExpressionVisitor& visitor) override; + RBAModelElementType getModelElementType() const override; + std::int32_t getValueCore(RBAConstraintInfo* info, + RBAArbitrator* arb) const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getSymbol() const override; +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAStateValueMaker.cpp b/src/core/expression/RBAStateValueMaker.cpp new file mode 100644 index 0000000..22a0c81 --- /dev/null +++ b/src/core/expression/RBAStateValueMaker.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAStateValueMaker.cpp +/// @brief StateValue object generator class + +#include "RBAStateValueMaker.hpp" +#include "RBAStateValue.hpp" + +namespace rba +{ + +RBAStateValueMaker::RBAStateValueMaker() + : RBAOperatorMaker{"StateValue"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAStateValueMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAStateValue>(); +} + +} diff --git a/src/core/expression/RBAStateValueMaker.hpp b/src/core/expression/RBAStateValueMaker.hpp new file mode 100644 index 0000000..8b01e09 --- /dev/null +++ b/src/core/expression/RBAStateValueMaker.hpp @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAStateValueMaker.cpp +/// @brief StateValue object generator class header + +#ifndef RBASTATEVALUEMAKER_HPP +#define RBASTATEVALUEMAKER_HPP + +#include "RBAOperatorMaker.hpp" + +namespace rba +{ + +/// @brief StateValue object generator class +class RBAStateValueMaker : public RBAOperatorMaker +{ +public: + RBAStateValueMaker(); + RBAStateValueMaker(const RBAStateValueMaker&)=delete; + RBAStateValueMaker(const RBAStateValueMaker&&)=delete; + RBAStateValueMaker& operator=(const RBAStateValueMaker&)=delete; + RBAStateValueMaker& operator=(const RBAStateValueMaker&&)=delete; + virtual ~RBAStateValueMaker()=default; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + +}; + +} + +#endif diff --git a/src/core/expression/RBAValueExpression.hpp b/src/core/expression/RBAValueExpression.hpp new file mode 100644 index 0000000..111ad02 --- /dev/null +++ b/src/core/expression/RBAValueExpression.hpp @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ValueExpression class header + */ + +#ifndef RBAVALUEEXPRESSION_HPP +#define RBAVALUEEXPRESSION_HPP + +#include "RBAExpression.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAValueExpression : public RBAExpression +{ +protected: + RBAValueExpression()=default; + RBAValueExpression(const RBAValueExpression&)=delete; + RBAValueExpression(const RBAValueExpression&&)=delete; + RBAValueExpression& operator=(const RBAValueExpression&)=delete; + RBAValueExpression& operator=(const RBAValueExpression&&)=delete; +public: + virtual ~RBAValueExpression()=default; + +}; + +} + +#endif diff --git a/src/core/expression/RBAVariable.cpp b/src/core/expression/RBAVariable.cpp new file mode 100644 index 0000000..9220c0a --- /dev/null +++ b/src/core/expression/RBAVariable.cpp @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Variable class defintion + */ + +#include "RBAVariable.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +RBAVariable::RBAVariable(const std::string& name) + : RBARuleObject{name} +{ +} + +RBAModelElementType +RBAVariable::getModelElementType() const +{ + return RBAModelElementType::Variable; +} + +const RBARuleObject* +RBAVariable::getRuleObj() const +{ + return ruleObj_; +} + +void +RBAVariable::setRuleObj(const RBARuleObject* const ruleObj) +{ + ruleObj_ = ruleObj; +} + +void +RBAVariable::clearRuleObj() +{ + ruleObj_ = nullptr; +} + +RBAConstraintInfo* +RBAVariable::createConstraintInfo() +{ + // When the "Let" expression is written in a lambda expression such as + // "For-All", the expansion result of the "Let" expression also changes + // each time the variable of "For-All" changes. Even if the Let expression + // is written in "For-All", there is only one valiable object. + // Therefore, "constraintInfo" cannot be cleared and reused, and it is + // necessary to do "make_shared" each time the "Let" expression is evaluated. + // The ownership of the "ConstraintInfo" of the "Let" expression is + // transferred to the "ConstraintInfo" of the "RBAObjectReference" + // when the RBAObjectReference that refers to the definition of the Let + // expression is evaluated. + constraintInfo_ = std::make_shared<RBAConstraintInfo>(); + return constraintInfo_.get(); +} + +std::shared_ptr<RBAConstraintInfo> +RBAVariable::getConstraintInfo() const +{ + return constraintInfo_; +} + +} diff --git a/src/core/expression/RBAVariable.hpp b/src/core/expression/RBAVariable.hpp new file mode 100644 index 0000000..88f071e --- /dev/null +++ b/src/core/expression/RBAVariable.hpp @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Variable class header + */ + +#ifndef RBAVARIABLE_HPP +#define RBAVARIABLE_HPP + +#include <memory> +#include "RBARuleObject.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAVariable : public RBARuleObject +{ +public: + explicit RBAVariable(const std::string& name=""); + RBAVariable(const RBAVariable&)=delete; + RBAVariable(const RBAVariable&&)=delete; + RBAVariable& operator=(const RBAVariable&)=delete; + RBAVariable& operator=(const RBAVariable&&)=delete; + virtual ~RBAVariable()=default; + +public: + RBAModelElementType getModelElementType() const override; + + const RBARuleObject* getRuleObj() const; + void setRuleObj(const RBARuleObject* const ruleObj); + void clearRuleObj(); + RBAConstraintInfo* createConstraintInfo(); + std::shared_ptr<RBAConstraintInfo> getConstraintInfo() const; + +private: + const RBARuleObject* ruleObj_ {nullptr}; +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::shared_ptr<RBAConstraintInfo> constraintInfo_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/expression/RBAVariableMaker.cpp b/src/core/expression/RBAVariableMaker.cpp new file mode 100644 index 0000000..aa7d5e8 --- /dev/null +++ b/src/core/expression/RBAVariableMaker.cpp @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAVariableMaker.cpp +/// @brief Variable object generator class definition + +#include "RBAVariableMaker.hpp" +#include "RBAVariable.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAVariableMaker::RBAVariableMaker() + : RBAModelElementMaker::RBAModelElementMaker{"Variable"} +{ +} + +RBAModelElement* +RBAVariableMaker::create(const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + // Register the instance without a name, because Variable has the same name + std::unique_ptr<RBAModelElement> inst + {createInstance(jsonElem->findChildren("name")->getString())}; + const auto element = inst.get(); + static_cast<void>(model->addModelElement(std::move(inst))); + + return setProperty(element, jsonElem, model, owner); +} + +std::unique_ptr<RBAModelElement> +RBAVariableMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAVariable>(name); +} + +RBAModelElement* +RBAVariableMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + return element; +} + +} diff --git a/src/core/expression/RBAVariableMaker.hpp b/src/core/expression/RBAVariableMaker.hpp new file mode 100644 index 0000000..e3d52e6 --- /dev/null +++ b/src/core/expression/RBAVariableMaker.hpp @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/// @file RBAVariableMaker.cpp +/// @brief Variable object generator class header + +#ifndef RBAVARIABLEMAKER_HPP +#define RBAVARIABLEMAKER_HPP + +#include "RBAModelElementMaker.hpp" + +namespace rba +{ + +/// @brief Variable object generator class +class RBAVariableMaker : public RBAModelElementMaker +{ +public: + RBAVariableMaker(); + RBAVariableMaker(const RBAVariableMaker&)=delete; + RBAVariableMaker(const RBAVariableMaker&&)=delete; + RBAVariableMaker& operator=(const RBAVariableMaker&)=delete; + RBAVariableMaker& operator=(const RBAVariableMaker&&)=delete; + virtual ~RBAVariableMaker()=default; + +public: + /// @brief Create ModelElement object + /// @details Create ModelElement object and register unique_ptr to model. + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store created object + /// @param[in,out] owner Parent object (Not in use) + /// @return ModelElement object + RBAModelElement* create(const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +protected: + /// @brief generate an empty instance + /// @details generate an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set attributes of model element for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store created object + /// @param[in,out] owner Parent object (Not in use) + /// @return ModelElement object + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif |