Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
CastStatement.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ast/Statement.h>
9#include <common/CastHelper.h>
10
11namespace cli {
12
13class CastStatement final : public Statement {
14 std::unique_ptr < cli::Arg > m_type;
15 std::shared_ptr < Statement > m_statement;
16
17public:
18 CastStatement ( std::unique_ptr < cli::Arg > type, std::shared_ptr < Statement > statement ) : m_type ( std::move ( type ) ), m_statement ( std::move ( statement ) ) {
19 }
20
21 std::shared_ptr < abstraction::Value > translateAndEval ( const std::shared_ptr < abstraction::Value > & prev, Environment & environment ) const override {
22 std::string type = m_type->eval ( environment );
23
24 std::shared_ptr < abstraction::Value > translatedStatement = m_statement->translateAndEval ( prev, environment );
25
26 environment.holdTemporary ( translatedStatement );
27
28 return abstraction::CastHelper::eval ( environment, translatedStatement, type );
29 }
30
31};
32
33} /* namespace cli */
34
static std::shared_ptr< abstraction::Value > eval(abstraction::TemporariesHolder &environment, const std::shared_ptr< abstraction::Value > &param, const std::string &type)
Definition: CastHelper.cpp:13
void holdTemporary(std::shared_ptr< abstraction::Value > temporary)
Definition: TemporariesHolder.cpp:10
Definition: CastStatement.h:13
CastStatement(std::unique_ptr< cli::Arg > type, std::shared_ptr< Statement > statement)
Definition: CastStatement.h:18
std::shared_ptr< abstraction::Value > translateAndEval(const std::shared_ptr< abstraction::Value > &prev, Environment &environment) const override
Definition: CastStatement.h:21
Definition: Environment.h:29
Definition: Statement.h:14
Definition: Arg.h:11
Definition: FordFulkerson.hpp:16