[llvm] r218471 - Object: Add range iterators for Archive children
David Majnemer
david.majnemer at gmail.com
Thu Sep 25 15:56:55 PDT 2014
Author: majnemer
Date: Thu Sep 25 17:56:54 2014
New Revision: 218471
URL: http://llvm.org/viewvc/llvm-project?rev=218471&view=rev
Log:
Object: Add range iterators for Archive children
No functional change intended.
Modified:
llvm/trunk/include/llvm/Object/Archive.h
llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp
Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=218471&r1=218470&r2=218471&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Thu Sep 25 17:56:54 2014
@@ -14,6 +14,7 @@
#ifndef LLVM_OBJECT_ARCHIVE_H
#define LLVM_OBJECT_ARCHIVE_H
+#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/Binary.h"
#include "llvm/Support/ErrorHandling.h"
@@ -97,12 +98,12 @@ public:
class child_iterator {
Child child;
+
public:
child_iterator() : child(Child(nullptr, nullptr)) {}
child_iterator(const Child &c) : child(c) {}
- const Child* operator->() const {
- return &child;
- }
+ const Child *operator->() const { return &child; }
+ const Child &operator*() const { return child; }
bool operator==(const child_iterator &other) const {
return child == other.child;
@@ -112,11 +113,11 @@ public:
return !(*this == other);
}
- bool operator <(const child_iterator &other) const {
+ bool operator<(const child_iterator &other) const {
return child < other.child;
}
- child_iterator& operator++() { // Preincrement
+ child_iterator &operator++() { // Preincrement
child = child.getNext();
return *this;
}
@@ -178,6 +179,10 @@ public:
child_iterator child_begin(bool SkipInternal = true) const;
child_iterator child_end() const;
+ iterator_range<child_iterator> children(bool SkipInternal = true) const {
+ return iterator_range<child_iterator>(child_begin(SkipInternal),
+ child_end());
+ }
symbol_iterator symbol_begin() const;
symbol_iterator symbol_end() const;
Modified: llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp?rev=218471&r1=218470&r2=218471&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp (original)
+++ llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp Thu Sep 25 17:56:54 2014
@@ -137,10 +137,8 @@ static void dumpVTables(const ObjectFile
}
static void dumpArchive(const Archive *Arc) {
- for (Archive::child_iterator ArcI = Arc->child_begin(),
- ArcE = Arc->child_end();
- ArcI != ArcE; ++ArcI) {
- ErrorOr<std::unique_ptr<Binary>> ChildOrErr = ArcI->getAsBinary();
+ for (const Archive::Child &ArcC : Arc->children()) {
+ ErrorOr<std::unique_ptr<Binary>> ChildOrErr = ArcC.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
// Ignore non-object files.
if (EC != object_error::invalid_file_type)
More information about the llvm-commits
mailing list