[cfe-commits] r67030 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Sema/Sema.h lib/Sema/SemaTemplateInstantiate.cpp

Anders Carlsson andersca at mac.com
Sun Mar 15 11:34:15 PDT 2009


Author: andersca
Date: Sun Mar 15 13:34:13 2009
New Revision: 67030

URL: http://llvm.org/viewvc/llvm-project?rev=67030&view=rev
Log:
Add the ability to clone integer and string literals. Use it when instantiating template expressions.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Mar 15 13:34:13 2009
@@ -377,6 +377,9 @@
     : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
     assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
   }
+
+  IntegerLiteral* Clone(ASTContext &C) const;
+  
   const llvm::APInt &getValue() const { return Value; }
   virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
 
@@ -515,7 +518,7 @@
   /// strings formed from multiple concatenated tokens.
   static StringLiteral *Create(ASTContext &C, const char *StrData,
                                unsigned ByteLength, bool Wide, QualType Ty,
-                               SourceLocation *Loc, unsigned NumStrs);
+                               const SourceLocation *Loc, unsigned NumStrs);
 
   /// Simple constructor for string literals made from one token.
   static StringLiteral *Create(ASTContext &C, const char *StrData, 
@@ -523,7 +526,8 @@
                                bool Wide, QualType Ty, SourceLocation Loc) {
     return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
   }
-  
+
+  StringLiteral* Clone(ASTContext &C) const;
   void Destroy(ASTContext &C);
   
   const char *getStrData() const { return StrData; }

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

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Mar 15 13:34:13 2009
@@ -26,6 +26,10 @@
 // Primary Expressions.
 //===----------------------------------------------------------------------===//
 
+IntegerLiteral* IntegerLiteral::Clone(ASTContext &C) const {
+  return new (C) IntegerLiteral(Value, getType(), Loc);
+}
+
 /// getValueAsApproximateDouble - This returns the value as an inaccurate
 /// double.  Note that this may cause loss of precision, but is useful for
 /// debugging dumps, etc.
@@ -40,7 +44,8 @@
 StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData,
                                      unsigned ByteLength, bool Wide,
                                      QualType Ty,
-                                     SourceLocation *Loc, unsigned NumStrs) {
+                                     const SourceLocation *Loc, 
+                                     unsigned NumStrs) {
   // Allocate enough space for the StringLiteral plus an array of locations for
   // any concatenated string tokens.
   void *Mem = C.Allocate(sizeof(StringLiteral)+
@@ -62,6 +67,10 @@
   return SL;
 }
 
+StringLiteral* StringLiteral::Clone(ASTContext &C) const {
+  return Create(C, StrData, ByteLength, IsWide, getType(),
+                TokLocs, NumConcatenated);
+}
 
 void StringLiteral::Destroy(ASTContext &C) {
   C.Deallocate(const_cast<char*>(StrData));

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=67030&r1=67029&r2=67030&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Mar 15 13:34:13 2009
@@ -1867,6 +1867,14 @@
                            ClassTemplateSpecializationDecl *ClassTemplateSpec,
                            bool ExplicitInstantiation);
 
+  // Simple function for cloning expressions.
+  template<typename T> 
+  OwningExprResult Clone(T *E) {
+    assert(!E->isValueDependent() && !E->isTypeDependent() &&
+           "expression is value or type dependent!");
+    return Owned(E->Clone(Context));
+  }
+  
   // Objective-C declarations.
   virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
                                            IdentifierInfo *ClassName,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Sun Mar 15 13:34:13 2009
@@ -591,7 +591,8 @@
     OwningExprResult VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
 
     // Base case. I'm supposed to ignore this.
-    Sema::OwningExprResult VisitStmt(Stmt *) { 
+    Sema::OwningExprResult VisitStmt(Stmt *S) { 
+      S->dump();
       assert(false && "Cannot instantiate this kind of expression");
       return SemaRef.ExprError(); 
     }
@@ -600,10 +601,7 @@
 
 Sema::OwningExprResult 
 TemplateExprInstantiator::VisitIntegerLiteral(IntegerLiteral *E) {
-  // FIXME: Can't we just re-use the expression node?
-  return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(E->getValue(), 
-                                                            E->getType(),
-                                                            E->getLocation()));
+  return SemaRef.Clone(E);
 }
 
 Sema::OwningExprResult





More information about the cfe-commits mailing list