From 2b4ae7fde370bc3316ab30cc38b74d23e785b360 Mon Sep 17 00:00:00 2001 From: Kenji Hosokawa Date: Mon, 24 Aug 2020 21:58:42 +0900 Subject: First commit Signed-off-by: Kenji Hosokawa Change-Id: I381abb0a6521f5349768a76ef7ceecbce4b2d701 --- src/optimize/RBAAbstractCollector.cpp | 598 +++++++++++++++++++++ src/optimize/RBAAbstractCollector.hpp | 160 ++++++ .../RBAAllwaysCheckConstraintCollector.cpp | 52 ++ .../RBAAllwaysCheckConstraintCollector.hpp | 51 ++ 4 files changed, 861 insertions(+) create mode 100644 src/optimize/RBAAbstractCollector.cpp create mode 100644 src/optimize/RBAAbstractCollector.hpp create mode 100644 src/optimize/RBAAllwaysCheckConstraintCollector.cpp create mode 100644 src/optimize/RBAAllwaysCheckConstraintCollector.hpp (limited to 'src/optimize') diff --git a/src/optimize/RBAAbstractCollector.cpp b/src/optimize/RBAAbstractCollector.cpp new file mode 100644 index 0000000..8d1574b --- /dev/null +++ b/src/optimize/RBAAbstractCollector.cpp @@ -0,0 +1,598 @@ +/** + * 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. + */ + +/** + * Abstract search class implementation file + */ + +#include + +#include "RBAAbstractCollector.hpp" + +#include "RBAAllocatable.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAAllocatedContent.hpp" +#include "RBAAndOperator.hpp" +#include "RBAArbitrator.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAContent.hpp" +#include "RBAContentSet.hpp" +#include "RBAContentValue.hpp" +#include "RBADisplayingContent.hpp" +#include "RBAExistsOperator.hpp" +#include "RBAForAllOperator.hpp" +#include "RBAGetAllocatables.hpp" +#include "RBAActiveState.hpp" +#include "RBAActiveContents.hpp" +#include "RBAGetContentsList.hpp" +#include "RBAGetProperty.hpp" +#include "RBAHasBeenDisplayed.hpp" +#include "RBAHasComeEarlierThan.hpp" +#include "RBAHasComeLaterThan.hpp" +#include "RBAIfStatement.hpp" +#include "RBAImpliesOperator.hpp" +#include "RBAIsActive.hpp" +#include "RBAIsAttenuated.hpp" +#include "RBAIsDisplayed.hpp" +#include "RBAIsEqualToOperator.hpp" +#include "RBAIsGreaterThanEqualOperator.hpp" +#include "RBAIsGreaterThanOperator.hpp" +#include "RBAIsHidden.hpp" +#include "RBAIsLowerThanEqualOperator.hpp" +#include "RBAIsLowerThanOperator.hpp" +#include "RBAIsMuted.hpp" +#include "RBAIsOn.hpp" +#include "RBAIsOutputted.hpp" +#include "RBAIsSounding.hpp" +#include "RBAIsVisible.hpp" +#include "RBALambdaExpression.hpp" +#include "RBAModelImpl.hpp" +#include "RBANotOperator.hpp" +#include "RBAObjectCompare.hpp" +#include "RBAOrOperator.hpp" +#include "RBAOutputtingSound.hpp" +#include "RBAPreviousModifier.hpp" +#include "RBAMaxOperator.hpp" +#include "RBAMinOperator.hpp" +#include "RBASelectOperator.hpp" +#include "RBASizeOperator.hpp" +#include "RBAResultImpl.hpp" +#include "RBAResultSet.hpp" +#include "RBAStateValue.hpp" +#include "RBAObjectReference.hpp" +#include "RBASetOfOperator.hpp" +#include "RBALetStatement.hpp" +#include "RBAOperator.hpp" +#include "RBAIsTypeOfOperator.hpp" +#include "RBAPreviousObjectWrapper.hpp" + +namespace rba +{ + +RBAAbstractCollector::RBAAbstractCollector(RBAModelImpl* const model) + : RBAExpressionVisitor(), + model_{model}, + isLhs_{false}, + isPreviousModifier_{false}, + isPositive_{true}, + visitsLetStatement_{false} +{ +} + +// area status +void RBAAbstractCollector::visit(RBAIsDisplayed& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBADisplayingContent& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAAllocatedContent& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAIsHidden& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAContentValue& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAGetContentsList& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} + +void RBAAbstractCollector::visit(RBAActiveContents& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} + +// display content status +void RBAAbstractCollector::visit(RBAIsActive& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAIsVisible& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAStateValue& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAHasBeenDisplayed& exp) +{ + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAHasComeEarlierThan& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); + exp.getRhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAHasComeLaterThan& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); + exp.getRhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAGetAllocatables& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAActiveState& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +// zone status +void RBAAbstractCollector::visit(RBAIsOutputted& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAOutputtingSound& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +// allocatedContent is common with area +void RBAAbstractCollector::visit(RBAIsMuted& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAIsAttenuated& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +// contentValue is common with area +// contentsList is common with area + +// sound content status +// isActive is common with display content +void RBAAbstractCollector::visit(RBAIsSounding& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +// stateValue is common with display content +// hasComeEarlierThan is common with display content +// hasComeLaterThan is common with display content +// allocatables is common with display content + +// scene status +void RBAAbstractCollector::visit(RBAIsOn& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAGetProperty& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} + +void RBAAbstractCollector::visit(RBAIsTypeOfOperator& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} + +// operator +void RBAAbstractCollector::visit(RBAAndOperator& exp) +{ + visitLetStatement(exp); + for (RBAExpression* const ope : exp.getOperand()) { + ope->accept(*this); + } +} +void RBAAbstractCollector::visit(RBAOrOperator& exp) +{ + visitLetStatement(exp); + for (RBAExpression* const ope : exp.getOperand()) { + ope->accept(*this); + } +} +void RBAAbstractCollector::visit(RBANotOperator& exp) +{ + visitLetStatement(exp); + isPositive_ = !isPositive_; + exp.getLhsOperand()->accept(*this); + isPositive_ = !isPositive_; +} +void RBAAbstractCollector::visit(RBAImpliesOperator& exp) +{ + visitLetStatement(exp); + const bool backup {isLhs_}; + exp.getLhsOperand()->accept(*this); + isLhs_ = backup; + exp.getRhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAIsEqualToOperator& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); + exp.getRhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAObjectCompare& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); + exp.getRhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAIsGreaterThanOperator& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); + exp.getRhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAIsGreaterThanEqualOperator& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); + exp.getRhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAIsLowerThanOperator& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); + exp.getRhsOperand()->accept(*this); +} +void RBAAbstractCollector::visit(RBAIsLowerThanEqualOperator& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); + exp.getRhsOperand()->accept(*this); +} + +// Quantification symbol +void RBAAbstractCollector::visit(RBAForAllOperator& exp) +{ + visitLetStatement(exp); + RBAConstraintInfo dummyInfo; + RBAArbitrator dummyArb; + dummyArb.setModel(model_); + dummyArb.setResult(std::make_unique( + &dummyArb, std::make_unique())); + const RBARuleObject* const ruleObj {exp.getLhsOperand()->getReferenceObject( + &dummyInfo, &dummyArb)}; + if (ruleObj != nullptr) { + std::vector objs; + const RBARuleObject* const objset {ruleObj->getRawObject()}; + if (dynamic_cast(objset) != nullptr) { + for (const auto& alloc : dynamic_cast(objset) + ->getLeafAllocatable()) { + objs.push_back(alloc); + } + } else { + for (const auto& cont : dynamic_cast(objset) + ->getLeafContent()) { + objs.push_back(cont); + } + } + for (const RBARuleObject* const obj : objs) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } else { + // As you go through this path, you may be referencing the LetStatement's Variable + for (auto& obj : letVal_) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } +} +void RBAAbstractCollector::visit(RBAExistsOperator& exp) +{ + visitLetStatement(exp); + RBAConstraintInfo dummyInfo; + RBAArbitrator dummyArb; + dummyArb.setModel(model_); + dummyArb.setResult(std::make_unique( + &dummyArb, std::make_unique())); + const RBARuleObject* const ruleObj {exp.getLhsOperand()->getReferenceObject( + &dummyInfo, &dummyArb)}; + if (ruleObj != nullptr) { + std::vector objs; + const RBARuleObject* const objset {ruleObj->getRawObject()}; + if (dynamic_cast(objset) != nullptr) { + for (const auto& alloc : dynamic_cast(objset) + ->getLeafAllocatable()) { + objs.push_back(alloc); + } + } else { + for (const auto& cont : dynamic_cast(objset) + ->getLeafContent()) { + objs.push_back(cont); + } + } + for (const RBARuleObject* const obj : objs) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } else { + // As you go through this path, you may be referencing the LetStatement's Variable + for (auto& obj : letVal_) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } +} + +// Built-in definition expression +void RBAAbstractCollector::visit(RBAAllInstanceOfArea& exp) +{ + // This Visitor implementation refers to the set of ForAll and Exists with + // ReferenceObject, sets it to Variable, and then accepts it to the body. + // It does not accept to the set, so it does not pass through this path. +} +void RBAAbstractCollector::visit(RBAAllInstanceOfViewContent& exp) +{ + // This Visitor implementation refers to the set of ForAll and Exists with + // ReferenceObject, sets it to Variable, and then accepts it to the body. + // It does not accept to the set, so it does not pass through this path. +} +void RBAAbstractCollector::visit(RBAAllInstanceOfZone& exp) +{ + // This Visitor implementation refers to the set of ForAll and Exists with + // ReferenceObject, sets it to Variable, and then accepts it to the body. + // It does not accept to the set, so it does not pass through this path. +} +void RBAAbstractCollector::visit(RBAAllInstanceOfSoundContent& exp) +{ + // This Visitor implementation refers to the set of ForAll and Exists with + // ReferenceObject, sets it to Variable, and then accepts it to the body. + // It does not accept to the set, so it does not pass through this path. +} + +// statement +void RBAAbstractCollector::visit(RBAIfStatement& exp) +{ + visitLetStatement(exp); + const bool backup {isLhs_}; + isLhs_ = true; + exp.getCondition()->accept(*this); + isLhs_ = backup; + exp.getThenExpression()->accept(*this); + exp.getElseExpression()->accept(*this); +} +void RBAAbstractCollector::visit(RBALetStatement& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +// modifier +void RBAAbstractCollector::visit(RBAPreviousModifier& exp) +{ + visitLetStatement(exp); + const bool b_isPreviousModifier_ {isPreviousModifier_}; + isPreviousModifier_ = true; + exp.getObjReference()->accept(*this); + isPreviousModifier_ = b_isPreviousModifier_; +} +// max operator +void RBAAbstractCollector::visit(RBAMaxOperator& exp) +{ + visitLetStatement(exp); + RBAConstraintInfo dummyInfo; + RBAArbitrator dummyArb; + dummyArb.setModel(model_); + dummyArb.setResult(std::make_unique( + &dummyArb, std::make_unique())); + const RBARuleObject* const ruleObj {exp.getLhsOperand()->getReferenceObject( + &dummyInfo, &dummyArb)}; + if (ruleObj != nullptr) { + std::vector objs; + const RBARuleObject* const objset {ruleObj->getRawObject()}; + if (dynamic_cast(objset) != nullptr) { + for (const auto& alloc : dynamic_cast(objset) + ->getLeafAllocatable()) { + objs.push_back(alloc); + } + } else { + for (const auto& cont : dynamic_cast(objset) + ->getLeafContent()) { + objs.push_back(cont); + } + } + for (const RBARuleObject* const obj : objs) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } else { + // As you go through this path, you may be referencing the LetStatement's Variable + for (auto& obj : letVal_) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } +} +void RBAAbstractCollector::visit(RBAMinOperator& exp) +{ + visitLetStatement(exp); + RBAConstraintInfo dummyInfo; + RBAArbitrator dummyArb; + dummyArb.setModel(model_); + dummyArb.setResult(std::make_unique( + &dummyArb, std::make_unique())); + const RBARuleObject* const ruleObj {exp.getLhsOperand()->getReferenceObject( + &dummyInfo, &dummyArb)}; + if (ruleObj != nullptr) { + std::vector objs; + const RBARuleObject* const objset {ruleObj->getRawObject()}; + if (dynamic_cast(objset) != nullptr) { + for (const auto& alloc : dynamic_cast(objset) + ->getLeafAllocatable()) { + objs.push_back(alloc); + } + } else { + for (const auto& cont : dynamic_cast(objset) + ->getLeafContent()) { + objs.push_back(cont); + } + } + for (const RBARuleObject* const obj : objs) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } else { + // As you go through this path, you may be referencing the LetStatement's Variable + for (auto& obj : letVal_) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } +} +void RBAAbstractCollector::visit(RBASelectOperator& exp) +{ + visitLetStatement(exp); + RBAConstraintInfo dummyInfo; + RBAArbitrator dummyArb; + dummyArb.setModel(model_); + dummyArb.setResult(std::make_unique( + &dummyArb, std::make_unique())); + const RBARuleObject* const ruleObj {exp.getLhsOperand()->getReferenceObject( + &dummyInfo, &dummyArb)}; + if (ruleObj != nullptr) { + std::vector objs; + const RBARuleObject* const objset {ruleObj->getRawObject()}; + if (dynamic_cast(objset) != nullptr) { + for (const auto& alloc : dynamic_cast(objset) + ->getLeafAllocatable()) { + objs.push_back(alloc); + } + } else { + for (const auto& cont : dynamic_cast(objset) + ->getLeafContent()) { + objs.push_back(cont); + } + } + for (const RBARuleObject* const obj : objs) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } else { + // As you go through this path, you may be referencing the LetStatement's Variable + for (auto& obj : letVal_) { + exp.getLambda()->setRuleObj(obj); + exp.getLambda()->getBodyText()->accept(*this); + } + } +} +void RBAAbstractCollector::visit(RBASizeOperator& exp) +{ + visitLetStatement(exp); + exp.getLhsOperand()->accept(*this); +} +// object reference +void RBAAbstractCollector::visit(RBAObjectReference& exp) +{ + visitLetStatement(exp); +} +void RBAAbstractCollector::visit(RBASetOfOperator& exp) +{ + visitLetStatement(exp); + for (RBAExpression* const ope : exp.getOperand()) { + ope->accept(*this); + } +} +void RBAAbstractCollector::visitLetStatement(RBAExpression& exp) +{ + const bool backup_let {visitsLetStatement_}; + visitsLetStatement_ = true; + for (auto& letStatement : exp.getLetStatements()) { + letStatement->accept(*this); + } + visitsLetStatement_ = backup_let; +} + +std::set& RBAAbstractCollector::getLetVal() +{ + return letVal_; +} + +void RBAAbstractCollector::addLetVal(const RBARuleObject* const obj) +{ + static_cast(letVal_.insert(obj)); +} + +bool RBAAbstractCollector::isVisitsLetStatement() const +{ + return visitsLetStatement_; +} + +bool RBAAbstractCollector::isLhs() const +{ + return isLhs_; +} + +void RBAAbstractCollector::setLhs(const bool lhs) +{ + isLhs_ = lhs; +} + +bool RBAAbstractCollector::isPositive() const +{ + return isPositive_; +} + +RBAModelImpl* RBAAbstractCollector::getModel() const +{ + return model_; +} + +bool RBAAbstractCollector::isPreviousModifier() const +{ + return isPreviousModifier_; +} + +} /* namespace rba */ diff --git a/src/optimize/RBAAbstractCollector.hpp b/src/optimize/RBAAbstractCollector.hpp new file mode 100644 index 0000000..a77db51 --- /dev/null +++ b/src/optimize/RBAAbstractCollector.hpp @@ -0,0 +1,160 @@ +/** + * 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. + */ + +/** + * Abstract search class header file + */ + +#ifndef RBAABSTRACTCOLLECTOR_HPP +#define RBAABSTRACTCOLLECTOR_HPP + +#include + +#include "RBAExpressionVisitor.hpp" +#include "RBAExpression.hpp" + +namespace rba +{ +class RBAModelImpl; +class RBARuleObject; + +class RBAAbstractCollector : public RBAExpressionVisitor +{ + public: + RBAAbstractCollector(RBAModelImpl* const model); + RBAAbstractCollector(const RBAAbstractCollector&)=default; + RBAAbstractCollector(RBAAbstractCollector&&)=default; + RBAAbstractCollector& operator=(const RBAAbstractCollector&)=default; + RBAAbstractCollector& operator=(RBAAbstractCollector&&)=default; + virtual ~RBAAbstractCollector()=default; + + // area status + void visit(RBAIsDisplayed& exp) override; + void visit(RBADisplayingContent& exp) override; + void visit(RBAAllocatedContent& exp) override; + void visit(RBAIsHidden& exp) override; + void visit(RBAContentValue& exp) override; + void visit(RBAGetContentsList& exp) override; + void visit(RBAActiveContents& exp) override; + + // display content status + void visit(RBAIsActive& exp) override; + void visit(RBAIsVisible& exp) override; + void visit(RBAStateValue& exp) override; + void visit(RBAHasBeenDisplayed& exp) override; + void visit(RBAHasComeEarlierThan& exp) override; + void visit(RBAHasComeLaterThan& exp) override; + void visit(RBAGetAllocatables& exp) override; + void visit(RBAActiveState& exp) override; + + // zone status + void visit(RBAIsOutputted& exp) override; + void visit(RBAOutputtingSound& exp) override; + // allocatedContent is common with area + void visit(RBAIsMuted& exp) override; + void visit(RBAIsAttenuated& exp) override; + // contentValue is common with area + // contentsList is common with area + + // sound content status + // isActive is common with display content + void visit(RBAIsSounding& exp) override; + // 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 + + // scene + void visit(RBAIsOn& exp) override; + void visit(RBAGetProperty& exp) override; + + void visit(RBAIsTypeOfOperator& exp) override; + + // operator + void visit(RBAAndOperator& exp) override; + void visit(RBAOrOperator& exp) override; + void visit(RBANotOperator& exp) override; + void visit(RBAImpliesOperator& exp) override; + void visit(RBAIsEqualToOperator& exp) override; + void visit(RBAObjectCompare& exp) override; + void visit(RBAIsGreaterThanOperator& exp) override; + void visit(RBAIsGreaterThanEqualOperator& exp) override; + void visit(RBAIsLowerThanOperator& exp) override; + void visit(RBAIsLowerThanEqualOperator& exp) override; + + // Quantification symbol + void visit(RBAForAllOperator& exp) override; + void visit(RBAExistsOperator& exp) override; + + // Built-in definition expression + void visit(RBAAllInstanceOfArea& exp) override; + void visit(RBAAllInstanceOfViewContent& exp) override; + void visit(RBAAllInstanceOfZone& exp) override; + void visit(RBAAllInstanceOfSoundContent& exp) override; + + // statement + void visit(RBAIfStatement& exp) override; + void visit(RBALetStatement& exp) override; + + // modifier + void visit(RBAPreviousModifier& exp) override; + + // operator + void visit(RBAMaxOperator& exp) override; + void visit(RBAMinOperator& exp) override; + void visit(RBASelectOperator& exp) override; + void visit(RBASizeOperator& exp) override; + + // object reference + void visit(RBAObjectReference& exp) override; + void visit(RBASetOfOperator& exp) override; + + protected: + void visitLetStatement(RBAExpression& exp) ; + + // getter, setter + std::set& getLetVal(); + void addLetVal(const RBARuleObject* const obj); + bool isVisitsLetStatement() const; + bool isLhs() const; + void setLhs(const bool lhs); + bool isPositive() const; + RBAModelImpl* getModel() const; + bool isPreviousModifier() const; + + private: + // Object that can be taken as the evaluation result of letStatement + std::set letVal_; + // Model referenced in getReferenceObject() + RBAModelImpl* model_; + // True when searching the left side + // Otherwise, false + bool isLhs_; + // true when in Expression under (pre) + // Otherwise, false + bool isPreviousModifier_; + // True if not inverted with Not + // False if inverted with Not + bool isPositive_; + // true when searching through letStatement + // Otherwise, false + bool visitsLetStatement_; +}; + +} /* namespace rba */ + +#endif /* RBAABSTRACTCOLLECTOR_HPP */ diff --git a/src/optimize/RBAAllwaysCheckConstraintCollector.cpp b/src/optimize/RBAAllwaysCheckConstraintCollector.cpp new file mode 100644 index 0000000..9476f52 --- /dev/null +++ b/src/optimize/RBAAllwaysCheckConstraintCollector.cpp @@ -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. + */ + +// +// RBAAllwaysCheckConstraintCollector.hpp +// + +#include "RBAAllwaysCheckConstraintCollector.hpp" + +#include "RBAConstraintImpl.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +RBAAllwaysCheckConstraintCollector::RBAAllwaysCheckConstraintCollector( + RBAModelImpl* const model) + : RBAAbstractCollector{model} +{ +} + +void RBAAllwaysCheckConstraintCollector::init( + const RBAConstraintImpl* const constraint) +{ + constraint_ = constraint; + isAllways_ = false; +} + +bool RBAAllwaysCheckConstraintCollector::isAllways() const +{ + return isAllways_; +} + +void RBAAllwaysCheckConstraintCollector::visit(RBAPreviousModifier& exp) +{ + isAllways_ = true; +} + +} /* namespace rba */ diff --git a/src/optimize/RBAAllwaysCheckConstraintCollector.hpp b/src/optimize/RBAAllwaysCheckConstraintCollector.hpp new file mode 100644 index 0000000..3b552e5 --- /dev/null +++ b/src/optimize/RBAAllwaysCheckConstraintCollector.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. + */ + +// +// RBAAllwaysCheckConstraintCollector.hpp +// + +#ifndef RBAALLWAYSCHECKCONSTRAINTSETTER_HPP +#define RBAALLWAYSCHECKCONSTRAINTSETTER_HPP + +#include "RBAAbstractCollector.hpp" + +namespace rba +{ +class RBAConstraintImpl; + +class RBAAllwaysCheckConstraintCollector : public RBAAbstractCollector +{ + public: + RBAAllwaysCheckConstraintCollector(RBAModelImpl* const model); + RBAAllwaysCheckConstraintCollector(const RBAAllwaysCheckConstraintCollector&)=default; + RBAAllwaysCheckConstraintCollector(RBAAllwaysCheckConstraintCollector&&)=default; + RBAAllwaysCheckConstraintCollector& operator=(const RBAAllwaysCheckConstraintCollector&)=default; + RBAAllwaysCheckConstraintCollector& operator=(RBAAllwaysCheckConstraintCollector&&)=default; + virtual ~RBAAllwaysCheckConstraintCollector()=default; + void init(const RBAConstraintImpl* const constraint); + bool isAllways() const; + void visit(RBAPreviousModifier& exp) final; + private: + // Constraint expression during search + const RBAConstraintImpl* constraint_ {nullptr}; + // True if the constraint expression being searched is a constraint expression that must always be arbitrated + bool isAllways_ {false}; +}; + +} /* namespace rba */ + +#endif /* RBAALLWAYSCHECKCONSTRAINTSETTER_HPP */ -- cgit 1.2.3-korg