LocSubSet.cpp

Go to the documentation of this file.
00001 
00014 #include "LocSubSet.hpp"
00015 #include <OpenAnalysis/Location/LocationVisitor.hpp>
00016 
00017 namespace OA {
00018 
00019 static bool debug = false;
00020 
00021 LocSubSet::LocSubSet(OA_ptr<Location> baseLoc) : mFull(false) 
00022 { 
00023     OA_DEBUG_CTRL_MACRO("DEBUG_LocSubSet:ALL", debug);
00024 
00025     // will compose this loc sub set with baseLoc and set mLoc
00026     // accordingly
00027     composeWithBaseLoc(baseLoc);
00028 }
00029 
00030 LocSubSet::LocSubSet(OA_ptr<Location> baseLoc, bool full) : mFull(full) 
00031 {
00032     // will compose this loc sub set with baseLoc and set mLoc
00033     // accordingly
00034     composeWithBaseLoc(baseLoc);
00035 }
00036 
00043 void LocSubSet::composeWithBaseLoc(OA_ptr<Location> baseLoc)
00044 {    
00045     if (baseLoc->isaSubSet()) {
00046         /* PLM 1/23/07 deprecated hasFullAccuracy
00047         mFull = mFull && baseLoc->hasFullAccuracy();
00048         */
00049         mLoc = baseLoc->getBaseLoc();
00050 
00051     } else {
00052         mLoc = baseLoc;
00053     }
00054 }
00055 
00056 void LocSubSet::acceptVisitor(LocationVisitor& pVisitor)
00057 {
00058     pVisitor.visitLocSubSet(*this);
00059 }
00060 
00061 void LocSubSet::output(IRHandlesIRInterface& pIR)
00062 {
00063     sOutBuild->objStart("LocSubSet");
00064 
00065     sOutBuild->fieldStart("mLoc");
00066     mLoc->output(pIR);
00067     sOutBuild->fieldEnd("mLoc");
00068     sOutBuild->field("mFull", bool2string(mFull));
00069 
00070     sOutBuild->objEnd("LocSubSet");
00071 }
00072 
00081 bool LocSubSet::operator<(Location& other)
00082 {
00083     if(getOrder() < other.getOrder()) { return true; }
00084     else if(getOrder() > other.getOrder()) { return false; }
00085 
00086     // if execution gets here then we're comparing two instances of the same
00087     // class
00088     LocSubSet& loc = static_cast<LocSubSet&>(other);
00089 
00090     // is the location we wrap less than the other guy
00091     if (getLoc() < loc.getLoc())  {
00092       return true;
00093     } else if (getLoc() == loc.getLoc() &&
00094                isFull() && !loc.isFull()) {
00095       return true;
00096     } else { return false; }
00097 }          
00098 
00099 bool LocSubSet::operator==(Location& other)
00100 {
00101     if(getOrder() != other.getOrder()) { return false; }
00102 
00103     // if execution gets here then we're comparing two instances of the same
00104     // class
00105     LocSubSet& loc = static_cast<LocSubSet&>(other);
00106 
00107 
00108     if ( getLoc() == loc.getLoc() &&
00109          isFull() == loc.isFull() )  
00110     { return true; } else { return false; }
00111 }  
00112 
00113 bool LocSubSet::mayOverlap(Location& other)
00114 {
00115     // may overlap if underlying locations overlap
00116     assert(!getLoc().ptrEqual(NULL));
00117     return getLoc()->mayOverlap(other);
00118 }
00119 
00120 class LocSubSetMustOverlapVisitor : public virtual LocationVisitor {
00121   private:
00122     LocSubSet& mThisLoc;
00123   public:
00124     bool mMustOverlap;
00125 
00126     LocSubSetMustOverlapVisitor(LocSubSet& thisLoc) 
00127         : mThisLoc(thisLoc), mMustOverlap(false) {}
00128     ~LocSubSetMustOverlapVisitor() {}
00129 
00130     // helper method that determines if mThisLoc is a full
00131     // subset and if the underlying location for it must
00132     // overlap with the given location
00133     void fullAndLocMustOverlap(Location &loc)
00134       { if ( loc.mustOverlap(*(mThisLoc.getLoc()))
00135              && mThisLoc.isFull() )
00136         { mMustOverlap = true; } else { mMustOverlap = false; }
00137       }
00138     
00139     // we overlap with named locations if we are a full subset
00140     // of that NamedLoc
00141     void visitNamedLoc(NamedLoc& loc) { fullAndLocMustOverlap(loc); }
00142 
00143     // we overlap with unnamed locations if we are a full subset
00144     // of that NamedLoc
00145     void visitUnnamedLoc(UnnamedLoc& loc) { fullAndLocMustOverlap(loc); }
00146 
00147     // we overlap with invisible locations if we are a full subset
00148     // of that NamedLoc
00149     void visitInvisibleLoc(InvisibleLoc& loc) { fullAndLocMustOverlap(loc);}
00150     // no locs must overlap with the UnknownLoc
00151     void visitUnknownLoc(UnknownLoc& loc) { mMustOverlap = false; }
00152 
00153     // if the other location is a subset then we must
00154     // overlap with them if we are a full subset
00155     // and they must overlap with our underlying location
00156     void visitLocSubSet(LocSubSet& loc) { fullAndLocMustOverlap(loc); }
00157 
00158 };
00159 
00160 bool LocSubSet::mustOverlap(Location& other)
00161 {
00162     // apply the visitor to the other location and return result
00163     LocSubSetMustOverlapVisitor mustOverlapVisitor(*this);
00164     other.acceptVisitor(mustOverlapVisitor);
00165     return mustOverlapVisitor.mMustOverlap;
00166 }
00167 
00168 // FIXME
00169 bool LocSubSet::subSetOf(Location & other)
00170 {
00171     // if our location must overlap the other location then
00172     // we are a subset of the other location
00173     assert(!getLoc().ptrEqual(NULL));
00174     if (getLoc()->mustOverlap(other)) {
00175         return true;
00176     } else {
00177         return false;
00178     }
00179 }
00180 
00181 
00182 void LocSubSet::dump(std::ostream& os)
00183 {
00184     os << "LocSubSet(this=" << this << " ,mLoc=";
00185     getLoc()->dump(os);
00186     os << "\tisFull=" << isFull() << " )"; 
00187     os << std::endl;
00188 }
00189 
00190 void LocSubSet::dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR)
00191 {
00192     os << "LocSubSet(this=" << this << " ,mLoc=";
00193     getLoc()->dump(os,pIR);
00194     os << "\tisFull=" << isFull() << " )"; 
00195     os << std::endl;
00196 }
00197 
00198 std::string LocSubSet::toString(OA_ptr<IRHandlesIRInterface> pIR)
00199 {
00200   std::ostringstream oss;
00201     oss << "LocSubSet( mLoc = ";
00202     assert(!getLoc().ptrEqual(NULL));
00203     oss << getLoc()->toString(pIR);
00204     oss << "\tisFull = " << isFull() << " )"; 
00205     return oss.str();
00206 }
00207 
00208 } // end namespace

Generated on Sat Oct 31 05:21:22 2009 for OpenAnalysis by  doxygen 1.6.1