From a36ac5664975b4c531ed0fd394f544ee4a08767c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tr=C3=A1vn=C3=AD=C4=8Dek?= <jan.travnicek@fit.cvut.cz> Date: Tue, 25 Jan 2022 11:07:24 +0100 Subject: [PATCH] cli: normalize immediate values --- alib2cli/src/ast/expression/ImmediateExpression.h | 4 ++-- alib2cli/src/ast/statements/ImmediateStatement.h | 7 ++++--- alib2cli/test-src/cli/CliBasicParsing.cpp | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/alib2cli/src/ast/expression/ImmediateExpression.h b/alib2cli/src/ast/expression/ImmediateExpression.h index f4ec4d6983..01d67d8ccf 100644 --- a/alib2cli/src/ast/expression/ImmediateExpression.h +++ b/alib2cli/src/ast/expression/ImmediateExpression.h @@ -1,6 +1,7 @@ #pragma once #include <ast/Expression.h> +#include <object/ObjectFactory.h> namespace cli { @@ -13,8 +14,7 @@ public: } std::shared_ptr < abstraction::Value > translateAndEval ( Environment & ) const override { - Type copy = m_value; - return std::make_shared < abstraction::ValueHolder < Type > > ( std::move ( copy ), true ); + return std::make_shared < abstraction::ValueHolder < object::Object > > ( object::ObjectFactory < >::construct ( m_value ), true ); } }; diff --git a/alib2cli/src/ast/statements/ImmediateStatement.h b/alib2cli/src/ast/statements/ImmediateStatement.h index bb60959ab7..071fdeb90f 100644 --- a/alib2cli/src/ast/statements/ImmediateStatement.h +++ b/alib2cli/src/ast/statements/ImmediateStatement.h @@ -1,19 +1,20 @@ #pragma once #include <ast/Statement.h> +#include <object/ObjectFactory.h> namespace cli { template < class Type > class ImmediateStatement final : public Statement { - std::shared_ptr < abstraction::ValueHolder < Type > > m_value; + Type m_value; public: - ImmediateStatement ( Type value ) : m_value ( std::make_shared < abstraction::ValueHolder < Type > > ( std::move ( value ), true ) ) { + ImmediateStatement ( Type value ) : m_value ( value ) { } std::shared_ptr < abstraction::Value > translateAndEval ( const std::shared_ptr < abstraction::Value > &, Environment & ) const override { - return m_value; + return std::make_shared < abstraction::ValueHolder < object::Object > > ( object::ObjectFactory < >::construct ( m_value ), true ); } }; diff --git a/alib2cli/test-src/cli/CliBasicParsing.cpp b/alib2cli/test-src/cli/CliBasicParsing.cpp index cda4982ffa..c01e87a9a9 100644 --- a/alib2cli/test-src/cli/CliBasicParsing.cpp +++ b/alib2cli/test-src/cli/CliBasicParsing.cpp @@ -33,6 +33,8 @@ TEST_CASE ( "Cli Parser", "[unit][cli]" ) { } SECTION ( "Test Routine3" ) { + abstraction::DenormalizeRegistry::registerDenormalize < int > ( ); + cli::Environment environment; testLine ( "procedure consume3 ( auto && $value ) begin print $value; end", environment ); -- GitLab