Rename referencesBegin() to begin() so that C++11 range based for loops can be used

llvm-svn: 154301
diff --git a/lld/include/lld/Core/DefinedAtom.h b/lld/include/lld/Core/DefinedAtom.h
index 10b3536..05bbf15 100644
--- a/lld/include/lld/Core/DefinedAtom.h
+++ b/lld/include/lld/Core/DefinedAtom.h
@@ -279,14 +279,10 @@
   };
 
   /// Returns an iterator to the beginning of this Atom's References
-  virtual reference_iterator referencesBegin() const = 0;
+  virtual reference_iterator begin() const = 0;
 
   /// Returns an iterator to the end of this Atom's References
-  virtual reference_iterator referencesEnd() const = 0;
-
-  reference_iterator begin() const { return referencesBegin(); }
-  reference_iterator end() const { return referencesEnd(); }
-
+  virtual reference_iterator end() const = 0;
 
   static inline bool classof(const Atom *a) {
     return a->definition() == definitionRegular;
diff --git a/lld/lib/Core/NativeReader.cpp b/lld/lib/Core/NativeReader.cpp
index 01466d3..2908614 100644
--- a/lld/lib/Core/NativeReader.cpp
+++ b/lld/lib/Core/NativeReader.cpp
@@ -92,9 +92,9 @@
 
   virtual ArrayRef<uint8_t> rawContent() const;
 
-  virtual reference_iterator referencesBegin() const;
+  virtual reference_iterator begin() const;
 
-  virtual reference_iterator referencesEnd() const;
+  virtual reference_iterator end() const;
 
   virtual const Reference* derefIterator(const void*) const;
 
@@ -731,13 +731,13 @@
   return _file->string(offset);
 }
 
-DefinedAtom::reference_iterator NativeDefinedAtomV1::referencesBegin() const {
+DefinedAtom::reference_iterator NativeDefinedAtomV1::begin() const {
   uintptr_t index = _ivarData->referencesStartIndex;
   const void* it = reinterpret_cast<const void*>(index);
   return reference_iterator(*this, it);
 }
 
-DefinedAtom::reference_iterator NativeDefinedAtomV1::referencesEnd() const {
+DefinedAtom::reference_iterator NativeDefinedAtomV1::end() const {
   uintptr_t index = _ivarData->referencesStartIndex+_ivarData->referencesCount;
   const void* it = reinterpret_cast<const void*>(index);
   return reference_iterator(*this, it);
diff --git a/lld/lib/Core/NativeWriter.cpp b/lld/lib/Core/NativeWriter.cpp
index 09e0d9a..5c7fc05 100644
--- a/lld/lib/Core/NativeWriter.cpp
+++ b/lld/lib/Core/NativeWriter.cpp
@@ -30,25 +30,17 @@
     // reserve first byte for unnamed atoms
     _stringPool.push_back('\0');
     // visit all atoms
-    for(File::defined_iterator it=file.definedAtomsBegin(),
-                              end=file.definedAtomsEnd();
-                               it != end; ++it) {
-      this->addIVarsForDefinedAtom(**it);
+    for ( const DefinedAtom *defAtom : file.defined() ) {
+      this->addIVarsForDefinedAtom(*defAtom);
     }
-    for(File::undefined_iterator it=file.undefinedAtomsBegin(),
-                              end=file.undefinedAtomsEnd();
-                               it != end; ++it) {
-      this->addIVarsForUndefinedAtom(**it);
+    for ( const UndefinedAtom *undefAtom : file.undefined() ) {
+      this->addIVarsForUndefinedAtom(*undefAtom);
     }
-    for(File::shared_library_iterator it=file.sharedLibraryAtomsBegin(),
-                              end=file.sharedLibraryAtomsEnd();
-                               it != end; ++it) {
-      this->addIVarsForSharedLibraryAtom(**it);
+    for ( const SharedLibraryAtom *shlibAtom : file.sharedLibrary() ) {
+      this->addIVarsForSharedLibraryAtom(*shlibAtom);
     }
-    for(File::absolute_iterator it=file.absoluteAtomsBegin(),
-                              end=file.absoluteAtomsEnd();
-                               it != end; ++it) {
-      this->addIVarsForAbsoluteAtom(**it);
+    for ( const AbsoluteAtom *absAtom : file.absolute() ) {
+      this->addIVarsForAbsoluteAtom(*absAtom);
     }
 
 
@@ -412,9 +404,7 @@
     count = 0;
     size_t startRefSize = _references.size();
     uint32_t result = startRefSize;
-    for (auto it=atom.referencesBegin(), end=atom.referencesEnd();
-                                                    it != end; ++it) {
-      const Reference* ref = *it;
+    for (const Reference *ref : atom) {
       NativeReferenceIvarsV1 nref;
       nref.offsetInAtom = ref->offsetInAtom();
       nref.kind = ref->kind();
diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp
index f0742a2..0cf5838 100644
--- a/lld/lib/Core/Resolver.cpp
+++ b/lld/lib/Core/Resolver.cpp
@@ -175,9 +175,8 @@
     undefineGenCount = _symbolTable.size();
     std::vector<const Atom *> undefines;
     _symbolTable.undefines(undefines);
-    for (std::vector<const Atom *>::iterator it = undefines.begin();
-         it != undefines.end(); ++it) {
-      StringRef undefName = (*it)->name();
+    for ( const Atom *undefAtom : undefines ) {
+      StringRef undefName = undefAtom->name();
       // load for previous undefine may also have loaded this undefine
       if (!_symbolTable.isDefined(undefName)) {
         _inputFiles.searchLibraries(undefName, true, true, false, *this);
@@ -194,18 +193,16 @@
     // search libraries for overrides of common symbols
     if (searchArchives || searchDylibs) {
       std::vector<const Atom *> tents;
-      for (std::vector<const Atom *>::iterator ait = _atoms.begin();
-           ait != _atoms.end(); ++ait) {
-        if (const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(*ait)) {
+      for ( const Atom *tent : tents ) {
+        if (const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(tent)) {
           if ( defAtom->merge() == DefinedAtom::mergeAsTentative )
             tents.push_back(defAtom);
         }
       }
-      for (std::vector<const Atom *>::iterator dit = tents.begin();
-           dit != tents.end(); ++dit) {
+      for ( const Atom *tent : tents ) {
         // load for previous tentative may also have loaded
         // this tentative, so check again
-        StringRef tentName = (*dit)->name();
+        StringRef tentName = tent->name();
         const Atom *curAtom = _symbolTable.findByName(tentName);
         assert(curAtom != nullptr);
         if (const DefinedAtom* curDefAtom = dyn_cast<DefinedAtom>(curAtom)) {
@@ -222,11 +219,9 @@
 // switch all references to undefined or coalesced away atoms
 // to the new defined atom
 void Resolver::updateReferences() {
-  for (auto ait = _atoms.begin(); ait != _atoms.end(); ++ait) {
-    if (const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(*ait)) {
-      for (auto rit=defAtom->referencesBegin(), end=defAtom->referencesEnd();
-                                                        rit != end; ++rit) {
-        const Reference* ref = *rit;
+  for(const Atom *atom : _atoms) {
+    if (const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(atom)) {
+      for (const Reference *ref : *defAtom) {
         const Atom* newTarget = _symbolTable.replacement(ref->target());
         (const_cast<Reference*>(ref))->setTarget(newTarget);
       }
@@ -262,9 +257,7 @@
   thisChain.previous = previous;
   thisChain.referer = &atom;
   if ( const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(&atom)) {
-    for (auto rit=defAtom->referencesBegin(), end=defAtom->referencesEnd();
-                                                        rit != end; ++rit) {
-      const Reference* ref = *rit;
+    for (const Reference *ref : *defAtom) {
       this->markLive(*ref->target(), &thisChain);
     }
   }
@@ -299,12 +292,11 @@
     this->addAtoms(platRootAtoms);
 
   // mark all roots as live, and recursively all atoms they reference
-  for (std::set<const Atom *>::iterator it = _deadStripRoots.begin();
-       it != _deadStripRoots.end(); ++it) {
+  for ( const Atom *dsrAtom : _deadStripRoots) {
     WhyLiveBackChain rootChain;
     rootChain.previous = nullptr;
-    rootChain.referer = *it;
-    this->markLive(**it, &rootChain);
+    rootChain.referer = dsrAtom;
+    this->markLive(*dsrAtom, &rootChain);
   }
 
   // now remove all non-live atoms from _atoms
@@ -342,9 +334,8 @@
 // check for interactions between symbols defined in this linkage unit
 // and same symbol name in linked dynamic shared libraries
 void Resolver::checkDylibSymbolCollisions() {
-  for (std::vector<const Atom *>::const_iterator it = _atoms.begin();
-       it != _atoms.end(); ++it) {
-    const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(*it);
+  for ( const Atom *atom : _atoms ) {
+    const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(atom);
     if (defAtom == nullptr)
       continue;
     if ( defAtom->merge() != DefinedAtom::mergeAsTentative )
@@ -407,8 +398,8 @@
 }
 
 void Resolver::MergedFile::addAtoms(std::vector<const Atom*>& all) {
-  for(std::vector<const Atom*>::iterator it=all.begin(); it != all.end(); ++it){
-    this->addAtom(**it);
+  for ( const Atom *atom : all ) {
+    this->addAtom(*atom);
   }
 }
 
diff --git a/lld/lib/Core/YamlReader.cpp b/lld/lib/Core/YamlReader.cpp
index 8fc8f94..6d7c23c 100644
--- a/lld/lib/Core/YamlReader.cpp
+++ b/lld/lib/Core/YamlReader.cpp
@@ -456,13 +456,13 @@
     return _ord;
   }
 
-  DefinedAtom::reference_iterator referencesBegin() const {
+  DefinedAtom::reference_iterator begin() const {
     uintptr_t index = _refStartIndex;
     const void* it = reinterpret_cast<const void*>(index);
     return reference_iterator(*this, it);
   }
 
-  DefinedAtom::reference_iterator referencesEnd() const {
+  DefinedAtom::reference_iterator end() const {
     uintptr_t index = _refEndIndex;
     const void* it = reinterpret_cast<const void*>(index);
     return reference_iterator(*this, it);
diff --git a/lld/lib/Core/YamlWriter.cpp b/lld/lib/Core/YamlWriter.cpp
index c01bca5..db63b61 100644
--- a/lld/lib/Core/YamlWriter.cpp
+++ b/lld/lib/Core/YamlWriter.cpp
@@ -57,9 +57,7 @@
         buildDuplicateNameMap(*atom);
 
       // Find references to unnamed atoms and create ref-names for them.
-      for (auto rit=atom->referencesBegin(), rend=atom->referencesEnd();
-                                                        rit != rend; ++rit) {
-        const Reference* ref = *rit;
+      for (const Reference *ref : *atom) {
         // create refname for any unnamed reference target
         if ( ref->target()->name().empty() ) {
           std::string Storage;
@@ -313,9 +311,7 @@
     }
 
     bool wroteFirstFixup = false;
-    for (auto it=atom.referencesBegin(), end=atom.referencesEnd();
-                                                    it != end; ++it) {
-      const Reference* ref = *it;
+    for (const Reference *ref : atom) {
       if ( !wroteFirstFixup ) {
         out  << "      fixups:\n";
         wroteFirstFixup = true;
diff --git a/lld/lib/Passes/GOTPass.cpp b/lld/lib/Passes/GOTPass.cpp
index 49e2db3..9bbd08a 100644
--- a/lld/lib/Passes/GOTPass.cpp
+++ b/lld/lib/Passes/GOTPass.cpp
@@ -47,12 +47,8 @@
   llvm::DenseMap<const Atom*, const DefinedAtom*> targetToGOT;
   
   // Scan all references in all atoms.
-  for(auto ait=_file.definedAtomsBegin(), aend=_file.definedAtomsEnd(); 
-                                                      ait != aend; ++ait) {
-    const DefinedAtom* atom = *ait;
-    for (auto rit=atom->referencesBegin(), rend=atom->referencesEnd(); 
-                                                      rit != rend; ++rit) {
-      const Reference* ref = *rit;
+  for(const DefinedAtom *atom : _file.defined()) {
+    for (const Reference *ref : *atom) {
       // Look at instructions accessing the GOT.
       bool canBypassGOT;
       if ( _platform.isGOTAccess(ref->kind(), canBypassGOT) ) {
diff --git a/lld/lib/Passes/StubsPass.cpp b/lld/lib/Passes/StubsPass.cpp
index 39d46a3..b81d0a2 100644
--- a/lld/lib/Passes/StubsPass.cpp
+++ b/lld/lib/Passes/StubsPass.cpp
@@ -31,12 +31,8 @@
     return;
 
   // Scan all references in all atoms.
-  for(auto ait=_file.definedAtomsBegin(), aend=_file.definedAtomsEnd();
-                                                      ait != aend; ++ait) {
-    const DefinedAtom* atom = *ait;
-    for (auto rit=atom->referencesBegin(), rend=atom->referencesEnd();
-                                                      rit != rend; ++rit) {
-      const Reference* ref = *rit;
+  for(const DefinedAtom *atom : _file.defined()) {
+    for (const Reference *ref : *atom) {
       // Look at call-sites.
       if ( _platform.isCallSite(ref->kind()) ) {
         const Atom* target = ref->target();
diff --git a/lld/lib/Platforms/Darwin/ExecutableWriter.cpp b/lld/lib/Platforms/Darwin/ExecutableWriter.cpp
index d10d90b..e9f05e0 100644
--- a/lld/lib/Platforms/Darwin/ExecutableWriter.cpp
+++ b/lld/lib/Platforms/Darwin/ExecutableWriter.cpp
@@ -556,9 +556,7 @@
     ArrayRef<uint8_t> content = atomInfo.atom->rawContent();
     buffer.resize(content.size());
     ::memcpy(buffer.data(), content.data(), content.size());
-    for (auto rit=atomInfo.atom->referencesBegin(), 
-               rend=atomInfo.atom->referencesEnd(); rit != rend; ++rit) {
-      const Reference* ref = *rit;
+    for (const Reference *ref : *atomInfo.atom) {
       uint32_t offset = ref->offsetInAtom();
       uint64_t targetAddress = 0;
       if ( ref->target() != nullptr )
diff --git a/lld/lib/Platforms/Darwin/StubAtoms.hpp b/lld/lib/Platforms/Darwin/StubAtoms.hpp
index 824562f..ed30f93 100644
--- a/lld/lib/Platforms/Darwin/StubAtoms.hpp
+++ b/lld/lib/Platforms/Darwin/StubAtoms.hpp
@@ -126,13 +126,13 @@
     return false;
   }
   
-  virtual DefinedAtom::reference_iterator referencesBegin() const {
+  virtual DefinedAtom::reference_iterator begin() const {
     uintptr_t index = 0;
     const void* it = reinterpret_cast<const void*>(index);
     return reference_iterator(*this, it);
   }
 
-  virtual DefinedAtom::reference_iterator referencesEnd() const {
+  virtual DefinedAtom::reference_iterator end() const {
     uintptr_t index = _references.size();
     const void* it = reinterpret_cast<const void*>(index);
     return reference_iterator(*this, it);
diff --git a/lld/tools/lld-core/lld-core.cpp b/lld/tools/lld-core/lld-core.cpp
index f897cfd..69cd3d3 100644
--- a/lld/tools/lld-core/lld-core.cpp
+++ b/lld/tools/lld-core/lld-core.cpp
@@ -119,11 +119,11 @@
     return ArrayRef<uint8_t>();
   }
   
-  virtual reference_iterator referencesBegin() const {
+  virtual reference_iterator begin() const {
     return reference_iterator(*this, nullptr);
   }
   
-  virtual reference_iterator referencesEnd() const {
+  virtual reference_iterator end() const {
     return reference_iterator(*this, nullptr);
   }
   
@@ -218,11 +218,11 @@
     return ArrayRef<uint8_t>();
   }
   
-  virtual reference_iterator referencesBegin() const {
+  virtual reference_iterator begin() const {
     return reference_iterator(*this, nullptr);
   }
   
-  virtual reference_iterator referencesEnd() const {
+  virtual reference_iterator end() const {
     return reference_iterator(*this, nullptr);
   }
   
@@ -449,9 +449,7 @@
 
   // InputFiles interface
   virtual void forEachInitialAtom(InputFiles::Handler& handler) const {
-    for (std::vector<const File *>::iterator fit = _files.begin();
-                                       fit != _files.end(); ++fit) {
-      const File* file = *fit;
+    for ( const File *file : _files ) {
       handler.doFile(*file);
       for(auto it=file->definedAtomsBegin(),end=file->definedAtomsEnd(); 
                                  it != end; ++it) {