UnnamedLoc.cpp

Go to the documentation of this file.
00001 
00014 #include "UnnamedLoc.hpp"
00015 #include <OpenAnalysis/Location/LocationVisitor.hpp>
00016 
00017 namespace OA {
00018 
00019 static bool debug = false;
00020 
00021 UnnamedLoc::UnnamedLoc(UnnamedLoc &other) : mExprHandle(other.mExprHandle),
00022                                             mLocal(other.mLocal)
00023 {
00024     OA_DEBUG_CTRL_MACRO("DEBUG_UnnamedLoc:ALL", debug);
00025 }
00026 
00027 void UnnamedLoc::acceptVisitor(LocationVisitor& pVisitor)
00028 {
00029     pVisitor.visitUnnamedLoc(*this);
00030 }
00031 
00032 OA_ptr<Location> UnnamedLoc::getBaseLoc() 
00033 { 
00034     OA_ptr<Location> retval; 
00035     retval = new UnnamedLoc(*this);
00036     return retval;
00037 }
00038 
00046 bool UnnamedLoc::operator<(Location& other)
00047 {
00048     if(getOrder() < other.getOrder()) { return true; }
00049     else if(getOrder() > other.getOrder()) { return false; }
00050 
00051     // if execution gets here then we're comparing two instances of the same
00052     // class
00053     UnnamedLoc& loc = static_cast<UnnamedLoc&>(other);
00054 
00055     if (getExprHandle() < loc.getExprHandle()) 
00056     { return true; } else { return false; }
00057 }  
00058 
00059 bool UnnamedLoc::operator==(Location& other)
00060 {
00061     if(getOrder() != other.getOrder()) { return false; }
00062 
00063     // if execution gets here then we're comparing two instances of the same
00064     // class
00065     UnnamedLoc& loc = static_cast<UnnamedLoc&>(other);
00066 
00067     if (getExprHandle() == loc.getExprHandle()
00068         && loc.isLocal() == isLocal() ) 
00069     { return true; } else { return false; }
00070 }   
00071 
00072 class UnnamedLocMayOverlapVisitor : public virtual LocationVisitor {
00073   private:
00074     UnnamedLoc& mThisLoc;
00075 
00076   public:
00077     bool mMayOverlap;
00078 
00079     UnnamedLocMayOverlapVisitor(UnnamedLoc& thisLoc) 
00080         : mThisLoc(thisLoc), mMayOverlap(true) {}
00081     ~UnnamedLocMayOverlapVisitor() {}
00082     
00083     // we don't overlap other named locations
00084     void visitNamedLoc(NamedLoc& loc) { mMayOverlap = false; }
00085 
00086     // we don't overlap other unnamed locations allocated at different stmts
00087     void visitUnnamedLoc(UnnamedLoc& loc)
00088       { if (mThisLoc.getExprHandle() != loc.getExprHandle())
00089         { mMayOverlap = false; } else { mMayOverlap = true; }
00090       }
00091 
00092     // don't overlap with Invisibles because anything that does should
00093     // be mapped to same Invisible by alias analysis
00094     void visitInvisibleLoc(InvisibleLoc& loc) { mMayOverlap = false; }
00095 
00096     // all locs overlap with the UnknownLoc
00097     void visitUnknownLoc(UnknownLoc& loc) { mMayOverlap = true; }
00098 
00099     // if the other location is a subset and we are not then
00100     // make the other location do the work
00101     void visitLocSubSet(LocSubSet& loc) 
00102       { mMayOverlap = loc.mayOverlap(mThisLoc); }
00103 
00104 };
00105 
00106 bool UnnamedLoc::mayOverlap(Location& other)
00107 {
00108     // apply the visitor to the other location and return result
00109     UnnamedLocMayOverlapVisitor mayOverlapVisitor(*this);
00110     other.acceptVisitor(mayOverlapVisitor);
00111     return mayOverlapVisitor.mMayOverlap;
00112 }
00113 
00114 bool UnnamedLoc::mustOverlap(Location& other)
00115 {
00116     return false;
00117 }
00118 
00122 bool UnnamedLoc::subSetOf(Location & other)
00123 {
00124     return false;
00125 }
00126 
00127 void UnnamedLoc::output(IRHandlesIRInterface& pIR)
00128 {
00129     sOutBuild->objStart("UnnamedLoc");
00130 
00131     sOutBuild->fieldStart("mExprHandle");
00132     sOutBuild->outputIRHandle(mExprHandle,pIR);
00133     sOutBuild->fieldEnd("mExprHandle");
00134 
00135     sOutBuild->field("mLocal", bool2string(mLocal));
00136    
00137     sOutBuild->objEnd("UnnamedLoc");
00138 }
00139 
00140 
00141 void UnnamedLoc::dump(std::ostream& os)
00142 {
00143     os << "UnnamedLoc(this=" << this << ", mExprHandle.hval()="
00144        << mExprHandle.hval() << ")";
00145     os << std::endl;
00146 }
00147 
00148 void UnnamedLoc::dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR)
00149 {
00150     os << "UnnamedLoc(this=" << this << ", mExprHandle.hval()="
00151        << mExprHandle.hval() << "): "
00152        << pIR->toString(mExprHandle);
00153     os << std::endl;
00154 }
00155 
00156 std::string UnnamedLoc::toString(OA_ptr<IRHandlesIRInterface> pIR)
00157 {
00158     std::ostringstream oss;
00159     oss << "UnnamedLoc(" << mExprHandle << "):" << pIR->toString(mExprHandle);
00160     return oss.str();
00161 }
00162 
00163 } // end namespace

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