Newer
Older
#include <ast/statements/ContainerStatement.h>
#include <ast/Option.h>
#include <ast/Param.h>
#include <ast/Arg.h>
#include <abstraction/common/CastHelper.h>
#include <exception/CommonException.h>
#include <iostream>
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
namespace cli {
ContainerStatement::ContainerStatement ( std::string container, ext::vector < std::unique_ptr < Param > > params, ext::vector < std::unique_ptr < Option > > options ) : m_container ( std::move ( container ) ), m_params ( std::move ( params ) ), m_options ( std::move ( options ) ) {
for ( const std::unique_ptr < Option > & option : m_options ) {
option->eval ( * this );
}
}
std::shared_ptr < abstraction::OperationAbstraction > ContainerStatement::translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const {
ext::vector < std::shared_ptr < abstraction::OperationAbstraction > > params;
for ( const std::unique_ptr < Param > & param : m_params ) {
params.push_back ( param->translateAndEval ( prev, environment ) );
}
std::vector < bool > moves;
for ( const std::unique_ptr < Param > & param : m_params ) {
moves.push_back ( param->getMove ( ) );
}
std::shared_ptr < abstraction::OperationAbstraction > algo = abstraction::Registry::getContainerAbstraction ( m_container, m_type );
unsigned i = 0;
ext::vector < std::shared_ptr < abstraction::OperationAbstraction > > casted_params;
for ( const std::shared_ptr < abstraction::OperationAbstraction > & param : params ) {
if ( abstraction::Registry::isCastNoOp ( algo->getParamType ( i ), param->getReturnType ( ) ) ) {
casted_params.push_back ( param );
} else {
casted_params.push_back ( abstraction::CastHelper::eval ( param, algo->getParamType ( i ), moves [ i ] ) );
moves [ i ] = true;
}
++ i;
}
i = 0;
for ( const std::shared_ptr < abstraction::OperationAbstraction > & param : casted_params ) {
if ( ! algo->attachInput ( param, i, moves [ i ] ) )
throw exception::CommonException ( "Can't connect param at " + ext::to_string ( i ) + " of algorithm " + m_container + " with result of type " + param->getReturnType ( ) + "." );
++ i;
}
if ( ! algo->eval ( ) )
throw exception::CommonException ( "Eval of algorithm " + m_container + " failed." );
return algo;
}
void ContainerStatement::setType ( std::string type ) {
m_type = std::move ( type );
}
} /* namespace cli */