[cfe-commits] r62605 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp lib/Sema/SemaExpr.cpp

Steve Naroff snaroff at apple.com
Tue Jan 20 11:53:53 PST 2009


Author: snaroff
Date: Tue Jan 20 13:53:53 2009
New Revision: 62605

URL: http://llvm.org/viewvc/llvm-project?rev=62605&view=rev
Log:
Allocate expresssions through ASTContext (still more work to do).
Add debug hook to DeclContext.

Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Tue Jan 20 13:53:53 2009
@@ -471,6 +471,7 @@
   Decl::Kind getDeclKind() const {
     return DeclKind;
   }
+  const char *getDeclKindName() const;
 
   /// getParent - Returns the containing DeclContext if this is a Decl,
   /// else returns NULL.

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

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Jan 20 13:53:53 2009
@@ -92,6 +92,35 @@
   }
 }
 
+const char *DeclContext::getDeclKindName() const {
+  switch (DeclKind) {
+  default: assert(0 && "Unknown decl kind!");
+  case Decl::TranslationUnit:     return "TranslationUnit";
+  case Decl::Namespace:           return "Namespace";
+  case Decl::OverloadedFunction:  return "OverloadedFunction";
+  case Decl::Typedef:             return "Typedef";
+  case Decl::Function:            return "Function";
+  case Decl::Var:                 return "Var";
+  case Decl::ParmVar:             return "ParmVar";
+  case Decl::OriginalParmVar:     return "OriginalParmVar";
+  case Decl::EnumConstant:        return "EnumConstant";
+  case Decl::ObjCIvar:            return "ObjCIvar";
+  case Decl::ObjCInterface:       return "ObjCInterface";
+  case Decl::ObjCImplementation:  return "ObjCImplementation";
+  case Decl::ObjCClass:           return "ObjCClass";
+  case Decl::ObjCMethod:          return "ObjCMethod";
+  case Decl::ObjCProtocol:        return "ObjCProtocol";
+  case Decl::ObjCProperty:        return "ObjCProperty";
+  case Decl::ObjCPropertyImpl:    return "ObjCPropertyImpl";
+  case Decl::ObjCForwardProtocol: return "ObjCForwardProtocol"; 
+  case Decl::Record:              return "Record";
+  case Decl::CXXRecord:           return "CXXRecord";
+  case Decl::Enum:                return "Enum";
+  case Decl::Block:               return "Block";
+  case Decl::Field:               return "Field";
+  }
+}
+
 bool Decl::CollectingStats(bool Enable) {
   if (Enable)
     StatSwitch = true;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=62605&r1=62604&r2=62605&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 20 13:53:53 2009
@@ -373,11 +373,14 @@
 DeclRefExpr *Sema::BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
                                     bool TypeDependent, bool ValueDependent,
                                     const CXXScopeSpec *SS) {
-  if (SS && !SS->isEmpty())
-    return new QualifiedDeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent,
-                                    SS->getRange().getBegin());
-  else
-    return new DeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent);
+  if (SS && !SS->isEmpty()) {
+    void *Mem = Context.getAllocator().Allocate<QualifiedDeclRefExpr>();
+    return new (Mem) QualifiedDeclRefExpr(D, Ty, Loc, TypeDependent, 
+                       ValueDependent, SS->getRange().getBegin());
+  } else {
+    void *Mem = Context.getAllocator().Allocate<DeclRefExpr>();
+    return new (Mem) DeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent);
+  }
 }
 
 /// getObjectForAnonymousRecordDecl - Retrieve the (unnamed) field or
@@ -549,8 +552,9 @@
     // to represent this name. Then, if it turns out that none of the
     // arguments are type-dependent, we'll force the resolution of the
     // dependent name at that point.
-    return Owned(new CXXDependentNameExpr(Name.getAsIdentifierInfo(),
-                                          Context.DependentTy, Loc));
+    void *Mem = Context.getAllocator().Allocate<CXXDependentNameExpr>();
+    return Owned(new (Mem) CXXDependentNameExpr(Name.getAsIdentifierInfo(),
+                                                Context.DependentTy, Loc));
   }
 
   // Could be enum-constant, value decl, instance variable, etc.
@@ -756,14 +760,15 @@
   //
   if (CurBlock && ShouldSnapshotBlockValueReference(CurBlock, VD)) {
     // The BlocksAttr indicates the variable is bound by-reference.
+    void *Mem = Context.getAllocator().Allocate<BlockDeclRefExpr>();
     if (VD->getAttr<BlocksAttr>())
-      return Owned(new BlockDeclRefExpr(VD, VD->getType().getNonReferenceType(),
-                                        Loc, true));
+      return Owned(new (Mem) BlockDeclRefExpr(VD, 
+                               VD->getType().getNonReferenceType(), Loc, true));
 
     // Variable will be bound by-copy, make it const within the closure.
     VD->getType().addConst();
-    return Owned(new BlockDeclRefExpr(VD, VD->getType().getNonReferenceType(),
-                                      Loc, false));
+    return Owned(new (Mem) BlockDeclRefExpr(VD, 
+                             VD->getType().getNonReferenceType(), Loc, false));
   }
   // If this reference is not in a block or if the referenced variable is
   // within the block, create a normal DeclRefExpr.
@@ -859,8 +864,9 @@
 
   QualType type = getLangOptions().CPlusPlus ? Context.CharTy : Context.IntTy;
 
-  return Owned(new CharacterLiteral(Literal.getValue(), Literal.isWide(), type,
-                                    Tok.getLocation()));
+  void *Mem = Context.getAllocator().Allocate<CharacterLiteral>();
+  return Owned(new (Mem) CharacterLiteral(Literal.getValue(), Literal.isWide(),
+                                    type, Tok.getLocation()));
 }
 
 Action::OwningExprResult Sema::ActOnNumericConstant(const Token &Tok) {
@@ -869,8 +875,9 @@
   if (Tok.getLength() == 1) {
     const char Val = PP.getSpelledCharacterAt(Tok.getLocation());
     unsigned IntSize = Context.Target.getIntWidth();
-    return Owned(new IntegerLiteral(llvm::APInt(IntSize, Val-'0'),
-                                    Context.IntTy, Tok.getLocation()));
+    void *Mem = Context.getAllocator().Allocate<IntegerLiteral>();
+    return Owned(new (Mem) IntegerLiteral(llvm::APInt(IntSize, Val-'0'),
+                    Context.IntTy, Tok.getLocation()));
   }
 
   llvm::SmallString<512> IntegerBuffer;
@@ -901,8 +908,9 @@
 
     // isExact will be set by GetFloatValue().
     bool isExact = false;
-    Res = new FloatingLiteral(Literal.GetFloatValue(Format, &isExact), &isExact,
-                              Ty, Tok.getLocation());
+    void *Mem = Context.getAllocator().Allocate<FloatingLiteral>();
+    Res = new (Mem) FloatingLiteral(Literal.GetFloatValue(Format, &isExact), 
+                                    &isExact, Ty, Tok.getLocation());
 
   } else if (!Literal.isIntegerLiteral()) {
     return ExprError();
@@ -989,8 +997,8 @@
       if (ResultVal.getBitWidth() != Width)
         ResultVal.trunc(Width);
     }
-
-    Res = new IntegerLiteral(ResultVal, Ty, Tok.getLocation());
+    void *Mem = Context.getAllocator().Allocate<IntegerLiteral>();
+    Res = new (Mem) IntegerLiteral(ResultVal, Ty, Tok.getLocation());
   }
 
   // If this is an imaginary literal, create the ImaginaryLiteral wrapper.
@@ -1004,7 +1012,8 @@
                                               SourceLocation R, ExprArg Val) {
   Expr *E = (Expr *)Val.release();
   assert((E != 0) && "ActOnParenExpr() missing expr");
-  return Owned(new ParenExpr(L, R, E));
+  void *Mem = Context.getAllocator().Allocate<ParenExpr>();
+  return Owned(new (Mem) ParenExpr(L, R, E));
 }
 
 /// The UsualUnaryConversions() function is *not* called by this routine.
@@ -1056,7 +1065,8 @@
     return ExprError();
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
-  return Owned(new SizeOfAlignOfExpr(isSizeof, isType, TyOrEx,
+  void *Mem = Context.getAllocator().Allocate<SizeOfAlignOfExpr>();
+  return Owned(new (Mem) SizeOfAlignOfExpr(isSizeof, isType, TyOrEx,
                                      Context.getSizeType(), OpLoc,
                                      Range.getEnd()));
 }
@@ -1146,12 +1156,15 @@
         ResultTy = ResultTy.getNonReferenceType();
 
         // Build the actual expression node.
-        Expr *FnExpr = new DeclRefExpr(FnDecl, FnDecl->getType(),
+        void *Mem = Context.getAllocator().Allocate<DeclRefExpr>();
+        Expr *FnExpr = new (Mem) DeclRefExpr(FnDecl, FnDecl->getType(),
                                        SourceLocation());
         UsualUnaryConversions(FnExpr);
 
         Input.release();
-        return Owned(new CXXOperatorCallExpr(FnExpr, Args, 2, ResultTy, OpLoc));
+        Mem = Context.getAllocator().Allocate<CXXOperatorCallExpr>();
+        return Owned(new (Mem) CXXOperatorCallExpr(FnExpr, Args, 2, ResultTy, 
+                                                   OpLoc));
       } else {
         // We matched a built-in operator. Convert the arguments, then
         // break out so that we will build the appropriate built-in





More information about the cfe-commits mailing list