]> granicus.if.org Git - clang/commitdiff
Add an iterator for walking the primary base chain.
authorAnders Carlsson <andersca@mac.com>
Sat, 28 Nov 2009 00:50:23 +0000 (00:50 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 28 Nov 2009 00:50:23 +0000 (00:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90023 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/RecordLayout.h

index 93ca2799bca0802047ddb598bf2c112de40e004e..a8334b694080b6ac001d8f980598cdf6a79f2e93 100644 (file)
@@ -64,8 +64,40 @@ public:
   
     /// isVirtual - Returns whether the primary base is virtual or not.
     bool isVirtual() const { return Value.getInt(); }
+
+    friend bool operator==(const PrimaryBaseInfo &X, const PrimaryBaseInfo &Y) {
+      return X.Value == Y.Value;
+    }
   }; 
   
+  /// primary_base_info_iterator - An iterator for iterating the primary base
+  /// class chain.
+  class primary_base_info_iterator {
+    /// Current - The current base class info.
+    PrimaryBaseInfo Current;
+    
+  public:
+    primary_base_info_iterator() {}
+    primary_base_info_iterator(PrimaryBaseInfo Info) : Current(Info) {}
+
+    const PrimaryBaseInfo &operator*() const { return Current; }
+
+    primary_base_info_iterator& operator++() {
+      const CXXRecordDecl *RD = Current.getBase();
+      Current = RD->getASTContext().getASTRecordLayout(RD).getPrimaryBaseInfo();
+      return *this;
+    }
+
+    friend bool operator==(const primary_base_info_iterator &X,
+                           const primary_base_info_iterator &Y) {
+      return X.Current == Y.Current;
+    }
+    friend bool operator!=(const primary_base_info_iterator &X,
+                           const primary_base_info_iterator &Y) {
+      return !(X == Y);
+    }
+  };
+    
 private:
   /// CXXRecordLayoutInfo - Contains C++ specific layout information.
   struct CXXRecordLayoutInfo {
@@ -212,6 +244,18 @@ public:
 
     return CXXInfo->VBaseOffsets[VBase];
   }
+  
+  primary_base_info_iterator primary_base_begin() const {
+    assert(CXXInfo && "Record layout does not have C++ specific info!");
+  
+    return primary_base_info_iterator(getPrimaryBaseInfo());
+  }
+
+  primary_base_info_iterator primary_base_end() const {
+    assert(CXXInfo && "Record layout does not have C++ specific info!");
+    
+    return primary_base_info_iterator();
+  }
 };
 
 }  // end namespace clang