LocFieldSubSet.cpp

Go to the documentation of this file.
00001 
00014 #include "LocFieldSubSet.hpp"
00015 #include <OpenAnalysis/Location/LocationVisitor.hpp>
00016 
00017 namespace OA {
00018 
00019 static bool debug = false;
00020 
00021 void LocFieldSubSet::acceptVisitor(LocationVisitor& pVisitor)
00022 {
00023     OA_DEBUG_CTRL_MACRO("DEBUG_LocFieldSubSet:ALL", debug);
00024     pVisitor.visitLocFieldSubSet(*this);
00025 }
00026 
00036 bool LocFieldSubSet::operator<(Location& other)
00037 {
00038     if(getOrder() < other.getOrder()) { return true; }
00039     else if(getOrder() > other.getOrder()) { return false; }
00040 
00041     // if execution gets here then we're comparing two instances of the same
00042     // class
00043     LocFieldSubSet& loc = static_cast<LocFieldSubSet&>(other);
00044 
00045     if (getLoc() < loc.getLoc()
00046           || ( (getLoc() == loc.getLoc()) &&
00047                (getFieldName() < loc.getFieldName()) ) ) 
00048       { return true; } else { return false; }
00049 }   
00050 
00051 bool LocFieldSubSet::operator==(Location& other)
00052 {
00053     if(getOrder() != other.getOrder()) { return false; }
00054 
00055     // if execution gets here then we're comparing two instances of the same
00056     // class, same underlying loc, and same field name
00057     LocFieldSubSet& loc = static_cast<LocFieldSubSet&>(other);
00058 
00059         if (getLoc() == loc.getLoc() &&
00060         getFieldName() == loc.getFieldName() )  
00061     { return true; } else { return false; }
00062 }
00063 
00064 bool LocFieldSubSet::mayOverlap(Location& other)
00065 {
00066   // this code is incomplete/wrong.
00067   // FIXME: have to handle unions
00068   assert(0);
00069     // may overlap if underlying locations overlap
00070     // however, if other is also a LocFieldSubSet, 
00071     // the fields must also match.
00072     assert(!getLoc().ptrEqual(NULL));
00073     bool underlyingLocsOverlap = getLoc()->mayOverlap(other);
00074     return getLoc()->mayOverlap(other);
00075 }
00076 
00077 
00078 class LocFieldSubSetMustOverlapVisitor : public virtual LocationVisitor {
00079   private:
00080     LocFieldSubSet& mThisLoc;
00081   public:
00082     bool mMustOverlap;
00083 
00084     LocFieldSubSetMustOverlapVisitor(LocFieldSubSet& thisLoc) 
00085         : mThisLoc(thisLoc), mMustOverlap(false) {}
00086     ~LocFieldSubSetMustOverlapVisitor() {}
00087 
00088     void visitNamedLoc(NamedLoc& loc) { mMustOverlap = false; }
00089     void visitUnnamedLoc(UnnamedLoc& loc) { mMustOverlap = false; } 
00090     void visitInvisibleLoc(InvisibleLoc& loc) { mMustOverlap = false; } 
00091     void visitUnknownLoc(UnknownLoc& loc) { mMustOverlap = false; }
00092     void visitLocSubSet(LocSubSet& loc) { mMustOverlap = false; }
00093     void visitLocIdxSubSet(LocIdxSubSet& loc) { mMustOverlap = false; }
00094     void visitLocFieldSubSet(LocFieldSubSet& loc) 
00095       // if other is a LocFieldSubSet then the underlying
00096       // locations must overlap and they must have same field
00097       { if ( loc.getLoc()->mustOverlap(*(mThisLoc.getLoc())) 
00098              && mThisLoc.getFieldName() == loc.getFieldName() )  
00099         { mMustOverlap = true; } else { mMustOverlap = false; }
00100       }
00101 };
00102 
00103 bool LocFieldSubSet::mustOverlap(Location& other)
00104 {
00105     // apply the visitor to the other location and return result
00106     LocFieldSubSetMustOverlapVisitor mustOverlapVisitor(*this);
00107     other.acceptVisitor(mustOverlapVisitor);
00108     return mustOverlapVisitor.mMustOverlap;
00109 }   
00110 
00111 // FIXME
00112 bool LocFieldSubSet::subSetOf(Location & other)
00113 {
00114     // if our location must overlap the other location then
00115     // we are a subset of the other location
00116     if (getLoc()->mustOverlap(other)) {
00117         return true;
00118     } else {
00119         return false;
00120     }
00121 }
00122 
00123 void LocFieldSubSet::output(IRHandlesIRInterface& pIR)
00124 {
00125     sOutBuild->objStart("LocFieldSubSet");
00126 
00127     //LocSubSet::output(pIR);
00128 
00129     sOutBuild->fieldStart("mLoc");
00130     mLoc->output(pIR);
00131     sOutBuild->fieldEnd("mLoc");
00132 
00133     sOutBuild->field("mFieldName", mFieldName);
00134 
00135     sOutBuild->objEnd("LocFieldSubSet");
00136 }
00137 
00138 
00139 void LocFieldSubSet::dump(std::ostream& os)
00140 {
00141     os << "LocFieldSubSet(this=" << this << ", mLoc=";
00142     getLoc()->dump(os);
00143     os << "\tmField=" << mFieldName << " )"; 
00144     os << std::endl;
00145 }
00146 
00147 void LocFieldSubSet::dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR)
00148 {
00149     os << "LocFieldSubSet(this=" << this << ", mLoc=";
00150     getLoc()->dump(os,pIR);
00151     os << "\tmFieldName()=" << mFieldName << " )";
00152     os << std::endl;
00153 }
00154 
00155 std::string LocFieldSubSet::toString(OA_ptr<IRHandlesIRInterface> pIR)
00156 {
00157     std::ostringstream oss;
00158     oss << "LocFieldSubSet( mLoc = ";
00159     assert(!getLoc().ptrEqual(NULL));
00160     oss << getLoc()->toString(pIR);
00161     oss << "\tmFieldName()=" << mFieldName << " )";
00162     return oss.str();
00163 }
00164 
00165 } // end namespace

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