Inferno  0.2
soft_patterns.cpp
Go to the documentation of this file.
00001 #include "soft_patterns.hpp"
00002 #include "coupling.hpp"
00003 
00004 shared_ptr<Key> TransformOfBase::DecidedCompare( const CompareReplace *sr,
00005                                                          const TreePtrInterface &x,
00006                                                          bool can_key,
00007                                                          Conjecture &conj )
00008 {
00009     INDENT;
00010     // Transform the candidate expression
00011     TreePtr<Node> xt = (*transformation)( sr->GetContext(), x );
00012   if( xt )
00013   {
00014       // Punt it back into the search/replace engine
00015       bool r = sr->DecidedCompare( xt, TreePtr<Node>(pattern), can_key, conj );
00016         if( r )
00017         {
00018             // If we have a match, make the output of the transformation be a terminus
00019             // for substitution during replace - if it is under the original node x
00020             // then the replace will resume overlaying at the correct place. If not, no
00021             // harm done since the replace won't see the terminus (there would be no
00022             // right place to overlay)
00023             shared_ptr<TerminusKey> k( new TerminusKey );
00024             k->root = x;
00025             k->terminus = xt;
00026             terminus = pattern; // TODO go through and replace pattern with terminus, and do not declare pattern in this class
00027             return k;
00028         }
00029         else
00030         {
00031             return shared_ptr<Key>();
00032         }
00033   }
00034   else
00035   {
00036       // Transformation returned NULL, probably because the candidate was of the wrong
00037     // type, so just don't match
00038     // TODO no need for this, the pre-restriction will take care of wrong type. But maybe
00039     // want this for other invalid cases?
00040       return shared_ptr<Key>();
00041   }
00042 }
00043