Skip to content
Snippets Groups Projects
Commit f5206c93 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

detect noop casts

parent 6c6c2993
No related branches found
No related tags found
No related merge requests found
......@@ -14,11 +14,17 @@ public:
}
 
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override {
std::string type = m_type->eval ( environment );
std::shared_ptr < abstraction::OperationAbstraction > translatedParam = m_param->translateAndEval ( prev, environment );
 
if ( abstraction::Registry::isCastNoOp ( type, translatedParam->getReturnType ( ) ) ) {
return translatedParam;
}
bool normalize;
 
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( m_type->eval ( environment ), translatedParam->getReturnType ( ), normalize );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( type, translatedParam->getReturnType ( ), normalize );
res->attachInput ( translatedParam, 0 );
res->eval ( );
 
......
......@@ -14,11 +14,17 @@ public:
}
 
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override {
std::string type = m_type->eval ( environment );
std::shared_ptr < abstraction::OperationAbstraction > translatedStatement = m_statement->translateAndEval ( prev, environment );
 
if ( abstraction::Registry::isCastNoOp ( type, translatedStatement->getReturnType ( ) ) ) {
return translatedStatement;
}
bool normalize;
 
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( m_type->eval ( environment ), translatedStatement->getReturnType ( ), normalize );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( type, translatedStatement->getReturnType ( ), normalize );
res->attachInput ( translatedStatement, 0 );
res->eval ( );
 
......
......@@ -105,6 +105,20 @@ public:
throw exception::CommonException ( "Entry from " + param + " to " + target + " not available." );
}
 
static bool isNoOp ( const std::string & target, const std::string & param ) {
std::set < std::string > targetTypes;
if ( alib::namingApi::hasTypes ( target ) )
targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( target ), [ ] ( const ext::type_index & type ) { return ext::to_string ( type ); } );
else
targetTypes.insert ( target );
for ( const std::string & toType : targetTypes )
if ( param == toType )
return true;
return false;
}
static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & target, const std::string & param ) {
bool normalize;
return getAbstraction ( target, param, normalize );
......
......@@ -42,6 +42,10 @@ std::shared_ptr < abstraction::OperationAbstraction > Registry::getCastAbstracti
return CastRegistry::getAbstraction ( target, param, normalize );
}
 
bool Registry::isCastNoOp ( const std::string & target, const std::string & param ) {
return CastRegistry::isNoOp ( target, param );
}
std::shared_ptr < abstraction::OperationAbstraction > Registry::getImmediateAbstraction ( const std::string & result, std::string value ) {
return ImmediateRegistry::getAbstraction ( result, std::move ( value ) );
}
......
......@@ -21,6 +21,7 @@ public:
static std::shared_ptr < abstraction::OperationAbstraction > getAlgorithmAbstraction ( const std::string & name, const ext::vector < std::string > & paramTypes );
static std::shared_ptr < abstraction::OperationAbstraction > getAlgorithmAbstraction ( const std::string & name, const ext::vector < std::string > & paramTypes, bool & unwrap, bool & normalize );
static std::shared_ptr < abstraction::OperationAbstraction > getCastAbstraction ( const std::string & target, const std::string & param, bool & normalize );
static bool isCastNoOp ( const std::string & target, const std::string & param );
static std::shared_ptr < abstraction::OperationAbstraction > getImmediateAbstraction ( const std::string & result, std::string value );
static std::shared_ptr < abstraction::OperationAbstraction > getNormalizeAbstraction ( const std::string & param );
static std::shared_ptr < abstraction::OperationAbstraction > getDowncastAbstraction ( const std::string & concrete, const std::string & base );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment