NamedLoc.cpp

Go to the documentation of this file.
00001 
00014 #include "NamedLoc.hpp"
00015 #include <OpenAnalysis/Location/LocationVisitor.hpp>
00016 #include <OpenAnalysis/Location/Iterators/OverlapSymIterator.hpp>
00017 
00018 namespace OA {
00019 
00020 static bool debug = false;
00021 
00022 NamedLoc::NamedLoc(NamedLoc & other) : mSymHandle(other.mSymHandle),
00023                                        mLocal(other.mLocal)
00024 {
00025     OA_DEBUG_CTRL_MACRO("DEBUG_NamedLoc:ALL", debug);
00026 
00027     //std::copy(other.mFullOverlap->begin(), other.mFullOverlap->end(),
00028     //          mFullOverlap->begin());
00029     //std::copy(other.mPartOverlap.begin(), other.mPartOverlap.end(),
00030     //          mPartOverlap.begin());
00031     mFullOverlap = other.mFullOverlap;
00032     mPartOverlap = other.mPartOverlap;
00033 }
00034 
00035 void NamedLoc::acceptVisitor(LocationVisitor& pVisitor)
00036 {
00037     pVisitor.visitNamedLoc(*this);
00038 }
00039 
00040 OA_ptr<Location> NamedLoc::getBaseLoc() 
00041 { 
00042     OA_ptr<Location> retval; 
00043     retval = new NamedLoc(*this);
00044     return retval;
00045 }
00046 
00047 OA_ptr<SymHandleIterator> NamedLoc::getPartOverlapIter()
00048 {
00049     OA_ptr<SymHandleIterator> retval;
00050     OA_ptr<std::set<SymHandle> > setCopy;
00051     setCopy = new std::set<SymHandle>(mPartOverlap);
00052     retval = new OverlapSymIterator(setCopy);
00053     return retval;
00054 }
00055 
00056 OA_ptr<SymHandleIterator> NamedLoc::getFullOverlapIter()
00057 {
00058     OA_ptr<SymHandleIterator> retval;
00059     OA_ptr<std::set<SymHandle> > setCopy;
00060     setCopy = new std::set<SymHandle>(mFullOverlap);
00061     retval = new OverlapSymIterator(setCopy);
00062     return retval;
00063 }
00064 
00075 bool NamedLoc::operator<(Location& other)
00076 {
00077     if (debug) { 
00078         std::cout << "NamedLoc::operator<, *this = ";
00079         this->dump(std::cout);
00080         std::cout << ", other = ";
00081         other.dump(std::cout);
00082     }
00083 
00084     if(getOrder() < other.getOrder()) { return true; }
00085     else if(getOrder() > other.getOrder()) { return false; }
00086 
00087     // if execution gets here then we're comparing two instances of the same
00088     // class
00089     NamedLoc& loc = static_cast<NamedLoc&>(other);
00090 
00091     if (getSymHandle() < loc.getSymHandle())
00092     { return true; } else { return false; }
00093 }  
00094 
00096 bool NamedLoc::operator==(Location& other)
00097 {
00098     // FIXME: what about may and must overlap lists
00099     if (debug) { 
00100         std::cout << "NamedLoc::operator==, *this = ";
00101         this->dump(std::cout);
00102         std::cout << ", other = ";
00103         other.dump(std::cout);
00104     }
00105 
00106     if(getOrder() != other.getOrder()) { return false; }
00107 
00108     // if execution gets here then we're comparing two instances of the same
00109     // class
00110     NamedLoc& loc = static_cast<NamedLoc&>(other);
00111 
00112     if (getSymHandle() == loc.getSymHandle()
00113         && loc.isLocal() == isLocal() )
00114     { return true; } else { return false; }
00115 }   
00116 
00117 bool NamedLoc::staticFullOverlap(SymHandle sym)
00118 {
00119   //return std::find(mFullOverlap->begin(),mFullOverlap->end(),sym) 
00120   //       != mFullOverlap->end();
00121   //return std::find(mFullOverlap.begin(),mFullOverlap.end(),sym) 
00122   //       != mFullOverlap.end();
00123   return mFullOverlap.find(sym) != mFullOverlap.end();
00124 }
00125 
00126 bool NamedLoc::staticPartOverlap(SymHandle sym)
00127 {
00128   return mPartOverlap.find(sym) != mPartOverlap.end();
00129 }
00130 
00131 class NamedLocMayOverlapVisitor : public virtual LocationVisitor {
00132   private:
00133     NamedLoc& mThisLoc;
00134   public:
00135     bool mMayOverlap;
00136 
00137     NamedLocMayOverlapVisitor(NamedLoc& thisLoc) 
00138         : mThisLoc(thisLoc), mMayOverlap(true) {}
00139     ~NamedLocMayOverlapVisitor() {}
00140     
00141     // we don't overlap other named locations if we have a different
00142     // symbol and have not been declared to statically overlap
00143     void visitNamedLoc(NamedLoc& otherLoc) 
00144       { 
00145         if (debug) {
00146           if (mThisLoc.getSymHandle() != otherLoc.getSymHandle()) {
00147             std::cout << "NOT MAY OVERLAP due to SYMHANDLE\n";
00148           } else if ( !mThisLoc.staticFullOverlap(otherLoc.getSymHandle())) {
00149             std::cout << "NOT MAY OVERLAP due to staticFullOverlap\n";
00150           } else if ( !mThisLoc.staticPartOverlap(otherLoc.getSymHandle())) {
00151             std::cout << "NOT MAY OVERLAP due to staticPartOverlap\n";
00152           } else {
00153             std::cout << "MAY OVERLAP\n";
00154           }
00155         }
00156         if (mThisLoc.getSymHandle() != otherLoc.getSymHandle()
00157             && !mThisLoc.staticFullOverlap(otherLoc.getSymHandle())
00158             && !mThisLoc.staticPartOverlap(otherLoc.getSymHandle()) )
00159         { mMayOverlap = false; } else { mMayOverlap = true; }
00160       }
00161 
00162     void visitUnnamedLoc(UnnamedLoc& loc) { mMayOverlap = false; }
00163 
00164     // don't overlap with Invisibles because anything that does should
00165     // be mapped to same Invisible by alias analysis
00166     void visitInvisibleLoc(InvisibleLoc& loc) { mMayOverlap = false; }
00167 
00168     // all locs overlap with the UnknownLoc
00169     void visitUnknownLoc(UnknownLoc& loc) { mMayOverlap = true; }
00170 
00171     // if the other location is a subset and we are not then
00172     // make the other location do the work
00173     void visitLocSubSet(LocSubSet& loc) 
00174       { mMayOverlap = loc.mayOverlap(mThisLoc); }
00175 };
00176 
00177 bool NamedLoc::mayOverlap(Location& other)
00178 {
00179     // apply the visitor to the other location and return result
00180     NamedLocMayOverlapVisitor mayOverlapVisitor(*this);
00181     other.acceptVisitor(mayOverlapVisitor);
00182     return mayOverlapVisitor.mMayOverlap;
00183 }
00184 
00185 class NamedLocMustOverlapVisitor : public virtual LocationVisitor {
00186   private:
00187     NamedLoc& mThisLoc;
00188 
00189   public:
00190     bool mMustOverlap;
00191 
00192     NamedLocMustOverlapVisitor(NamedLoc& thisLoc) 
00193         : mThisLoc(thisLoc), mMustOverlap(false) {}
00194     ~NamedLocMustOverlapVisitor() {}
00195     
00196     // we don't overlap other named locations if we have a different
00197     // symbol and have not been declared to statically overlap
00198     void visitNamedLoc(NamedLoc& loc) 
00199       { if (mThisLoc.getSymHandle() == loc.getSymHandle()
00200             || mThisLoc.staticFullOverlap(loc.getSymHandle()) )
00201         { mMustOverlap = true; } else { mMustOverlap = false; }
00202       }
00203 
00204     void visitUnnamedLoc(UnnamedLoc& loc) { mMustOverlap = false; }
00205 
00206     // don't overlap with Invisibles because anything that does should
00207     // be mapped to same Invisible by alias analysis
00208     void visitInvisibleLoc(InvisibleLoc& loc) { mMustOverlap = false; }
00209 
00210     // no locs must overlap with the UnknownLoc
00211     void visitUnknownLoc(UnknownLoc& loc) { mMustOverlap = false; }
00212 
00213     // if the other location is a subset and we are not then
00214     // make the other location do the work
00215     void visitLocSubSet(LocSubSet& loc) 
00216       { mMustOverlap = loc.mustOverlap(mThisLoc); }
00217 };
00218 
00219 
00220 bool NamedLoc::mustOverlap(Location& other)
00221 {
00222     // apply the visitor to the other location and return result
00223     NamedLocMustOverlapVisitor mustOverlapVisitor(*this);
00224     other.acceptVisitor(mustOverlapVisitor);
00225     return mustOverlapVisitor.mMustOverlap;
00226 }
00227 
00228 
00234 bool NamedLoc::subSetOf(Location & other)
00235 {
00236     return mustOverlap(other);
00237 }
00238 
00239 void NamedLoc::output(IRHandlesIRInterface& pIR)
00240 {
00241     sOutBuild->objStart("NamedLoc");
00242 
00243     sOutBuild->fieldStart("mSymHandle");
00244     sOutBuild->outputIRHandle(mSymHandle,pIR);
00245     sOutBuild->fieldEnd("mSymHandle");
00246 
00247     sOutBuild->field("mLocal", bool2string(mLocal));
00248    
00249     std::set<SymHandle>::iterator listIter;
00250     sOutBuild->fieldStart("mFullOverlap");
00251     sOutBuild->listStart();
00252     for (listIter=mFullOverlap.begin(); listIter!=mFullOverlap.end(); listIter++)   {
00253       sOutBuild->listItemStart();
00254       sOutBuild->outputIRHandle(*listIter,pIR);
00255       sOutBuild->listItemEnd();
00256     }
00257     sOutBuild->listEnd();
00258     sOutBuild->fieldEnd("mFullOverlap");
00259 
00260     sOutBuild->fieldStart("mPartOverlap");
00261     sOutBuild->listStart();
00262     for (listIter=mPartOverlap.begin(); listIter!=mPartOverlap.end(); listIter++)   {
00263       sOutBuild->outputIRHandle(*listIter,pIR);
00264       sOutBuild->listItemStart();
00265       sOutBuild->listItemEnd();
00266     }
00267     sOutBuild->listEnd();
00268     sOutBuild->fieldEnd("mPartOverlap");
00269 
00270     sOutBuild->objEnd("NamedLoc");
00271 }
00272 
00273 void NamedLoc::dump(std::ostream& os)
00274 {
00275     os << "NamedLoc(this=" << this << ", mSymHandle.hval()="
00276        << mSymHandle.hval() << ", mLocal=" << mLocal << ")";
00277     os << std::endl;
00278 }
00279 
00280 void NamedLoc::dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR)
00281 {
00282     // string for mSymHandle
00283     os << "NamedLoc(this=" << this << ", mSymHandle.hval()=" 
00284        << mSymHandle.hval() << ", mLocal=" << mLocal << "):";
00285     os << pIR->toString(mSymHandle);
00286     os << std::endl;
00287 }
00288 
00289 std::string NamedLoc::toString(OA_ptr<IRHandlesIRInterface> pIR)
00290 {
00291     std::ostringstream oss;
00292     // string for mSymHandle
00293     oss << "NamedLoc(" << mSymHandle.hval() << "):" 
00294         << pIR->toString(mSymHandle);
00295     return oss.str();
00296 }
00297 
00298 } // end namespace

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