]> granicus.if.org Git - clang/commitdiff
More work on the FullExpr class.
authorAnders Carlsson <andersca@mac.com>
Wed, 16 Dec 2009 06:10:22 +0000 (06:10 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 16 Dec 2009 06:10:22 +0000 (06:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91513 91177308-0d34-0410-b5e6-96231b3b80d8

clang.xcodeproj/project.pbxproj
include/clang/AST/FullExpr.h
lib/AST/FullExpr.cpp

index 3f00073f880233269dd949c70e399dd6d4acc5a3..ea72c9e6f04f3fa2257bcd8476f18faff55fe8b0 100644 (file)
                1AA1D91610125DE30078DEBC /* RecordLayoutBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = RecordLayoutBuilder.cpp; path = lib/AST/RecordLayoutBuilder.cpp; sourceTree = "<group>"; tabWidth = 2; };
                1AA1D91710125DE30078DEBC /* RecordLayoutBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = RecordLayoutBuilder.h; path = lib/AST/RecordLayoutBuilder.h; sourceTree = "<group>"; tabWidth = 2; };
                1AA963AB10D8576800786C86 /* FullExpr.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = FullExpr.h; path = clang/AST/FullExpr.h; sourceTree = "<group>"; tabWidth = 2; };
-               1AA963C310D85A7300786C86 /* FullExpr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FullExpr.cpp; path = lib/AST/FullExpr.cpp; sourceTree = "<group>"; };
+               1AA963C310D85A7300786C86 /* FullExpr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = FullExpr.cpp; path = lib/AST/FullExpr.cpp; sourceTree = "<group>"; tabWidth = 2; };
                1AB290021045858B00FE33D8 /* PartialDiagnostic.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; path = PartialDiagnostic.h; sourceTree = "<group>"; tabWidth = 2; };
                1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGBuiltin.cpp; path = lib/CodeGen/CGBuiltin.cpp; sourceTree = "<group>"; tabWidth = 2; };
                1ADD795110A90C6100741BBA /* TypePrinter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TypePrinter.cpp; path = lib/AST/TypePrinter.cpp; sourceTree = "<group>"; };
index 727036a5cfc5df6cc0e074052e9084e773f83878..5503e67354788165440867d20fb04d6227e609cc 100644 (file)
@@ -29,11 +29,14 @@ namespace clang {
       
       unsigned NumTemps;
       
-      typedef CXXTemporary** iterator;
+      typedef CXXTemporary** temps_iterator;
       
-      iterator begin() { return reinterpret_cast<CXXTemporary **>(this + 1); }
-      iterator end() { return begin() + NumTemps; }
-
+      temps_iterator temps_begin() { 
+        return reinterpret_cast<CXXTemporary **>(this + 1); 
+      }
+      temps_iterator temps_end() { 
+        return temps_begin() + NumTemps;
+      }
     };
   
     llvm::PointerUnion<Expr *, ExprAndTemporaries *> SubExpr;
@@ -43,6 +46,33 @@ namespace clang {
   public:
     static FullExpr Create(ASTContext &Context, Expr *SubExpr, 
                            CXXTemporary **Temps, unsigned NumTemps);
+    void Destroy(ASTContext &Context);
+    
+    Expr *getExpr() {
+      if (Expr *E = SubExpr.dyn_cast<Expr *>())
+        return E;
+      
+      return SubExpr.get<ExprAndTemporaries *>()->SubExpr;
+    }
+    
+    const Expr *getExpr() const { 
+      return const_cast<FullExpr*>(this)->getExpr();
+    }
+    
+    typedef CXXTemporary** temps_iterator;
+
+    temps_iterator temps_begin() {
+      if (ExprAndTemporaries *ET = SubExpr.dyn_cast<ExprAndTemporaries *>())
+        return ET->temps_begin();
+      
+      return 0;
+    }
+    temps_iterator temps_end() {
+      if (ExprAndTemporaries *ET = SubExpr.dyn_cast<ExprAndTemporaries *>())
+        return ET->temps_end();
+      
+      return 0;
+    }
   };
   
 
index 39c3bad0a77eeb91cdfaabe967cde370f9a998e0..f47284f3d06045439e1f2190794eefa8f2069c04 100644 (file)
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/FullExpr.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "llvm/Support/AlignOf.h"
 using namespace clang;
 
-FullExpr FullExpr::Create(ASTContext &Context, Expr *SubExpr, 
+FullExpr FullExpr::Create(ASTContext &Context, Expr *SubExpr,
                           CXXTemporary **Temporaries, unsigned NumTemporaries) {
-    FullExpr E;
-    
-    if (!NumTemporaries) {
-        E.SubExpr = SubExpr;
-        return E;
-    }
-    
-    unsigned Size = sizeof(FullExpr) 
-        + sizeof(CXXTemporary *) * NumTemporaries;
-    
-    unsigned Align = llvm::AlignOf<ExprAndTemporaries>::Alignment;
-    ExprAndTemporaries *ET = 
-        static_cast<ExprAndTemporaries *>(Context.Allocate(Size, Align));
-    
-    ET->SubExpr = SubExpr;
-    std::copy(Temporaries, Temporaries + NumTemporaries, ET->begin());
+  FullExpr E;
+
+  if (!NumTemporaries) {
+      E.SubExpr = SubExpr;
+      return E;
+  }
+
+  unsigned Size = sizeof(FullExpr) 
+      + sizeof(CXXTemporary *) * NumTemporaries;
+
+  unsigned Align = llvm::AlignOf<ExprAndTemporaries>::Alignment;
+  ExprAndTemporaries *ET = 
+      static_cast<ExprAndTemporaries *>(Context.Allocate(Size, Align));
+
+  ET->SubExpr = SubExpr;
+  std::copy(Temporaries, Temporaries + NumTemporaries, ET->temps_begin());
     
-    return E;
+  return E;
+}
+
+void FullExpr::Destroy(ASTContext &Context) {
+  if (Expr *E = SubExpr.dyn_cast<Expr *>()) {
+    E->Destroy(Context);
+    return;
+  }
+  
+  ExprAndTemporaries *ET = SubExpr.get<ExprAndTemporaries *>();
+  for (ExprAndTemporaries::temps_iterator i = ET->temps_begin(), 
+       e = ET->temps_end(); i != e; ++i)
+    (*i)->Destroy(Context);
+
+  Context.Deallocate(ET);
 }