[cfe-commits] r71968 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp

Anders Carlsson andersca at mac.com
Sat May 16 16:58:38 PDT 2009


Author: andersca
Date: Sat May 16 18:58:37 2009
New Revision: 71968

URL: http://llvm.org/viewvc/llvm-project?rev=71968&view=rev
Log:
Add setters/getters to CXXMethodDecl so it can keep track of which virtual member functions it overrides (if any)

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/AST/DeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=71968&r1=71967&r2=71968&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sat May 16 18:58:37 2009
@@ -478,9 +478,17 @@
   }
 
   bool isVirtual() const { 
-    // FIXME: Check if it's inherited virtual as well.
-    return isVirtualAsWritten();
+    return isVirtualAsWritten() ||
+      (begin_overridden_methods() != end_overridden_methods());
   }
+
+  /// 
+  void addOverriddenMethod(const CXXMethodDecl *MD);
+  
+  typedef const CXXMethodDecl ** method_iterator;
+  
+  method_iterator begin_overridden_methods() const;
+  method_iterator end_overridden_methods() const;
   
   /// getParent - Returns the parent of this method declaration, which
   /// is the class in which this method is defined.

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=71968&r1=71967&r2=71968&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sat May 16 18:58:37 2009
@@ -194,6 +194,47 @@
   return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline);
 }
 
+
+typedef llvm::DenseMap<const CXXMethodDecl*, 
+                       std::vector<const CXXMethodDecl *> *> 
+                       OverriddenMethodsMapTy;
+
+static OverriddenMethodsMapTy *OverriddenMethods = 0;
+
+void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
+  // FIXME: The CXXMethodDecl dtor needs to remove and free the entry.
+  
+  if (!OverriddenMethods)
+    OverriddenMethods = new OverriddenMethodsMapTy();
+  
+  std::vector<const CXXMethodDecl *> *&Methods = (*OverriddenMethods)[this];
+  if (!Methods)
+    Methods = new std::vector<const CXXMethodDecl *>;
+  
+  Methods->push_back(MD);
+}
+
+CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
+  if (!OverriddenMethods)
+    return 0;
+  
+  OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this);
+  if (it == OverriddenMethods->end())
+    return 0;
+  return &(*it->second)[0];
+}
+
+CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
+  if (!OverriddenMethods)
+    return 0;
+  
+  OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this);
+  if (it == OverriddenMethods->end())
+    return 0;
+
+  return &(*it->second)[it->second->size()];
+}
+
 QualType CXXMethodDecl::getThisType(ASTContext &C) const {
   // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
   // If the member function is declared const, the type of this is const X*,





More information about the cfe-commits mailing list