aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/expression/RBASetOfOperator.cpp
blob: 8bf7e8254ec1a831168cbbf8d4232aee8190930f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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,
                                         RBAArbitratorImpl* 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, RBAArbitratorImpl* 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

}