Skip to content
Snippets Groups Projects
StatementList.h 1.13 KiB
Newer Older
  • Learn to ignore specific revisions
  • #ifndef _CLI_STATEMENT_LIST_H_
    #define _CLI_STATEMENT_LIST_H_
    
    #include <ast/Statement.h>
    
    namespace cli {
    
    
    class StatementList final : public Statement {
    
    	ext::vector < std::shared_ptr < Statement > > m_statements;
    
    	StatementList ( ext::vector < std::shared_ptr < Statement > > statements ) : m_statements ( statements ) {
    
    	virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override {
    		if ( m_statements.empty ( ) )
    			throw std::invalid_argument ( "Statement list can't be empty" );
    
    		std::shared_ptr < abstraction::OperationAbstraction > next = m_statements [ 0 ]->translateAndEval ( nullptr, environment );
    		for ( unsigned i = 1; i < m_statements.size ( ); ++ i )
    			next = m_statements [ i ]->translateAndEval ( next, environment );
    
    		return next;
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    
    	void append ( std::shared_ptr < Statement > statement ) {
    
    		m_statements.emplace_back ( std::move ( statement ) );
    	}
    
    	virtual bool getImplicitMove ( ) const override {
    		return false;
    
    };
    
    } /* namespace cli */
    
    #endif /* _CLI_STATEMENT_LIST_H_ */