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