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 // may overlap if underlying locations overlap 00067 // however, if other is also a LocFieldSubSet, 00068 // the fields must also match. 00069 assert(!getLoc().ptrEqual(NULL)); 00070 return getLoc()->mayOverlap(other); 00071 } 00072 00073 00074 class LocFieldSubSetMustOverlapVisitor : public virtual LocationVisitor { 00075 private: 00076 LocFieldSubSet& mThisLoc; 00077 public: 00078 bool mMustOverlap; 00079 00080 LocFieldSubSetMustOverlapVisitor(LocFieldSubSet& thisLoc) 00081 : mThisLoc(thisLoc), mMustOverlap(false) {} 00082 ~LocFieldSubSetMustOverlapVisitor() {} 00083 00084 void visitNamedLoc(NamedLoc& loc) { mMustOverlap = false; } 00085 void visitUnnamedLoc(UnnamedLoc& loc) { mMustOverlap = false; } 00086 void visitInvisibleLoc(InvisibleLoc& loc) { mMustOverlap = false; } 00087 void visitUnknownLoc(UnknownLoc& loc) { mMustOverlap = false; } 00088 void visitLocSubSet(LocSubSet& loc) { mMustOverlap = false; } 00089 void visitLocIdxSubSet(LocIdxSubSet& loc) { mMustOverlap = false; } 00090 void visitLocFieldSubSet(LocFieldSubSet& loc) 00091 // if other is a LocFieldSubSet then the underlying 00092 // locations must overlap and they must have same field 00093 { if ( loc.getLoc()->mustOverlap(*(mThisLoc.getLoc())) 00094 && mThisLoc.getFieldName() == loc.getFieldName() ) 00095 { mMustOverlap = true; } else { mMustOverlap = false; } 00096 } 00097 }; 00098 00099 bool LocFieldSubSet::mustOverlap(Location& other) 00100 { 00101 // apply the visitor to the other location and return result 00102 LocFieldSubSetMustOverlapVisitor mustOverlapVisitor(*this); 00103 other.acceptVisitor(mustOverlapVisitor); 00104 return mustOverlapVisitor.mMustOverlap; 00105 } 00106 00107 // FIXME 00108 bool LocFieldSubSet::subSetOf(Location & other) 00109 { 00110 // if our location must overlap the other location then 00111 // we are a subset of the other location 00112 if (getLoc()->mustOverlap(other)) { 00113 return true; 00114 } else { 00115 return false; 00116 } 00117 } 00118 00119 void LocFieldSubSet::output(IRHandlesIRInterface& pIR) 00120 { 00121 sOutBuild->objStart("LocFieldSubSet"); 00122 00123 //LocSubSet::output(pIR); 00124 00125 sOutBuild->fieldStart("mLoc"); 00126 mLoc->output(pIR); 00127 sOutBuild->fieldEnd("mLoc"); 00128 00129 sOutBuild->field("mFieldName", mFieldName); 00130 00131 sOutBuild->objEnd("LocFieldSubSet"); 00132 } 00133 00134 00135 void LocFieldSubSet::dump(std::ostream& os) 00136 { 00137 os << "LocFieldSubSet(this=" << this << ", mLoc="; 00138 getLoc()->dump(os); 00139 os << "\tmField=" << mFieldName << " )"; 00140 os << std::endl; 00141 } 00142 00143 void LocFieldSubSet::dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR) 00144 { 00145 os << "LocFieldSubSet(this=" << this << ", mLoc="; 00146 getLoc()->dump(os,pIR); 00147 os << "\tmFieldName()=" << mFieldName << " )"; 00148 os << std::endl; 00149 } 00150 00151 std::string LocFieldSubSet::toString(OA_ptr<IRHandlesIRInterface> pIR) 00152 { 00153 std::ostringstream oss; 00154 oss << "LocFieldSubSet( mLoc = "; 00155 assert(!getLoc().ptrEqual(NULL)); 00156 oss << getLoc()->toString(pIR); 00157 oss << "\tmFieldName()=" << mFieldName << " )"; 00158 return oss.str(); 00159 } 00160 00161 } // end namespace
1.7.1