interpretation-instructions.cpp
No OneTemporary

File Metadata

Created
Tue, Aug 25, 10:36 AM

interpretation-instructions.cpp

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Author: pgess <v.melnychenko@xreate.org>
* Created on June 15, 2018, 5:32 PM
*
*/
#include "compilation/interpretation-instructions.h"
#include "analysis/interpretation.h"
#include "transcendlayer.h"
#include "targets.h"
using namespace std;
namespace xreate{
namespace interpretation{
Expression
IntrinsicQueryInstruction::process(const Expression& expression) {
AST* ast = static_cast<TargetInterpretation*> (__scope->function->man)->ast;
TranscendLayer* transcend = static_cast<TargetInterpretation*> (__scope->function->man)->pass->man->transcend;
InterpretationFunction* function = static_cast<InterpretationFunction*> (__scope->function);
ExpandedType targetT = ast->expandType(expression.type);
assert(expression.operands.size() == 1);
assert(expression.operands.front().__state == Expression::STRING);
assert(targetT->__operator == TypeOperator::LIST);
std::string namePredicate = expression.operands.front().getValueString();
StaticModel model = (static_cast<TargetInterpretation*> (function->man))->pass->man->transcend->query(namePredicate);
Expression result(Operator::LIST,{});
result.operands.reserve(model.size());
ExpandedType elementT = targetT->__operands.at(0).__operator == TypeOperator::SLAVE
? dereferenceSlaveType(ExpandedType(targetT->__operands.at(0)), transcend)
: ExpandedType(targetT->__operands.at(0));
if(model.size()) {
if (elementT->__operator == TypeOperator::LIST_NAMED) {
//edge case, content's type is LIST_NAMED:
for(const auto& row : model) {
result.operands.push_back(representTransExpression(row.second, elementT, transcend));
}
} else {
for (const auto& row : model) {
assert(row.second.args().size);
result.operands.push_back(representTransExpression(row.second.args()[0], elementT, transcend));
}
}
}
return result;
}
}
} //end of xreate::interpretation

Event Timeline