[cfe-commits] r69233 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/exprs.c test/PCH/exprs.h

Douglas Gregor dgregor at apple.com
Wed Apr 15 15:19:55 PDT 2009


Author: dgregor
Date: Wed Apr 15 17:19:53 2009
New Revision: 69233

URL: http://llvm.org/viewvc/llvm-project?rev=69233&view=rev
Log:
PCH support for ImaginaryLiteral and ArraySubscriptExpr

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/test/PCH/exprs.c
    cfe/trunk/test/PCH/exprs.h

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 15 17:19:53 2009
@@ -526,9 +526,14 @@
   ImaginaryLiteral(Expr *val, QualType Ty)
     : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
   
+  /// \brief Build an empty imaginary literal.
+  explicit ImaginaryLiteral(EmptyShell Empty) 
+    : Expr(ImaginaryLiteralClass, Empty) { }
+
   const Expr *getSubExpr() const { return cast<Expr>(Val); }
   Expr *getSubExpr() { return cast<Expr>(Val); }
-  
+  void setSubExpr(Expr *E) { Val = E; }
+
   virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() == ImaginaryLiteralClass; 
@@ -891,6 +896,10 @@
     SubExprs[RHS] = rhs;
   }
   
+  /// \brief Create an empty array subscript expression.
+  explicit ArraySubscriptExpr(EmptyShell Shell)
+    : Expr(ArraySubscriptExprClass, Shell) { }
+
   /// An array access can be written A[4] or 4[A] (both are equivalent).
   /// - getBase() and getIdx() always present the normalized view: A[4].
   ///    In this case getBase() returns "A" and getIdx() returns "4".
@@ -902,9 +911,11 @@
   /// integer type
   Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
   const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
-  
+  void setLHS(Expr *E) { SubExprs[LHS] = E; }
+
   Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
   const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
+  void setRHS(Expr *E) { SubExprs[RHS] = E; }
   
   Expr *getBase() { 
     return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
@@ -927,6 +938,8 @@
   }
   
   SourceLocation getRBracketLoc() const { return RBracketLoc; }
+  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
+
   virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
 
   static bool classof(const Stmt *T) { 

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69233&r1=69232&r2=69233&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 15 17:19:53 2009
@@ -391,6 +391,8 @@
       EXPR_INTEGER_LITERAL,
       /// \brief A FloatingLiteral record.
       EXPR_FLOATING_LITERAL,
+      /// \brief An ImaginaryLiteral record.
+      EXPR_IMAGINARY_LITERAL,
       /// \brief A StringLiteral record.
       EXPR_STRING_LITERAL,
       /// \brief A CharacterLiteral record.
@@ -401,6 +403,8 @@
       EXPR_UNARY_OPERATOR,
       /// \brief A SizefAlignOfExpr record.
       EXPR_SIZEOF_ALIGN_OF,
+      /// \brief An ArraySubscriptExpr record.
+      EXPR_ARRAY_SUBSCRIPT,
       /// \brief A CallExpr record.
       EXPR_CALL,
       /// \brief A MemberExpr record.

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69233&r1=69232&r2=69233&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 15 17:19:53 2009
@@ -179,7 +179,7 @@
 void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
   VisitVarDecl(PD);
   PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
-  // FIXME: default argument
+  // FIXME: default argument (C++ only)
 }
 
 void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) {
@@ -241,11 +241,13 @@
     unsigned VisitDeclRefExpr(DeclRefExpr *E);
     unsigned VisitIntegerLiteral(IntegerLiteral *E);
     unsigned VisitFloatingLiteral(FloatingLiteral *E);
+    unsigned VisitImaginaryLiteral(ImaginaryLiteral *E);
     unsigned VisitStringLiteral(StringLiteral *E);
     unsigned VisitCharacterLiteral(CharacterLiteral *E);
     unsigned VisitParenExpr(ParenExpr *E);
     unsigned VisitUnaryOperator(UnaryOperator *E);
     unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
+    unsigned VisitArraySubscriptExpr(ArraySubscriptExpr *E);
     unsigned VisitCallExpr(CallExpr *E);
     unsigned VisitMemberExpr(MemberExpr *E);
     unsigned VisitCastExpr(CastExpr *E);
@@ -293,6 +295,12 @@
   return 0;
 }
 
+unsigned PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
+  VisitExpr(E);
+  E->setSubExpr(ExprStack.back());
+  return 1;
+}
+
 unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) {
   VisitExpr(E);
   unsigned Len = Record[Idx++];
@@ -351,6 +359,14 @@
   return E->isArgumentType()? 0 : 1;
 }
 
+unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
+  VisitExpr(E);
+  E->setLHS(ExprStack[ExprStack.size() - 2]);
+  E->setRHS(ExprStack[ExprStack.size() - 2]);
+  E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 2;
+}
+
 unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) {
   VisitExpr(E);
   E->setNumArgs(Reader.getContext(), Record[Idx++]);
@@ -1648,7 +1664,6 @@
 
 /// \brief Read a floating-point value
 llvm::APFloat PCHReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) {
-  // FIXME: is this really correct?
   return llvm::APFloat(ReadAPInt(Record, Idx));
 }
 
@@ -1861,6 +1876,10 @@
       E = new (Context) FloatingLiteral(Empty);
       break;
       
+    case pch::EXPR_IMAGINARY_LITERAL:
+      E = new (Context) ImaginaryLiteral(Empty);
+      break;
+
     case pch::EXPR_STRING_LITERAL:
       E = StringLiteral::CreateEmpty(Context, 
                                      Record[PCHStmtReader::NumExprFields + 1]);
@@ -1882,6 +1901,10 @@
       E = new (Context) SizeOfAlignOfExpr(Empty);
       break;
 
+    case pch::EXPR_ARRAY_SUBSCRIPT:
+      E = new (Context) ArraySubscriptExpr(Empty);
+      break;
+
     case pch::EXPR_CALL:
       E = new (Context) CallExpr(Context, Empty);
       break;

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69233&r1=69232&r2=69233&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 15 17:19:53 2009
@@ -448,11 +448,13 @@
     void VisitDeclRefExpr(DeclRefExpr *E);
     void VisitIntegerLiteral(IntegerLiteral *E);
     void VisitFloatingLiteral(FloatingLiteral *E);
+    void VisitImaginaryLiteral(ImaginaryLiteral *E);
     void VisitStringLiteral(StringLiteral *E);
     void VisitCharacterLiteral(CharacterLiteral *E);
     void VisitParenExpr(ParenExpr *E);
     void VisitUnaryOperator(UnaryOperator *E);
     void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
+    void VisitArraySubscriptExpr(ArraySubscriptExpr *E);
     void VisitCallExpr(CallExpr *E);
     void VisitMemberExpr(MemberExpr *E);
     void VisitCastExpr(CastExpr *E);
@@ -498,6 +500,12 @@
   Code = pch::EXPR_FLOATING_LITERAL;
 }
 
+void PCHStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
+  VisitExpr(E);
+  Writer.WriteSubExpr(E->getSubExpr());
+  Code = pch::EXPR_IMAGINARY_LITERAL;
+}
+
 void PCHStmtWriter::VisitStringLiteral(StringLiteral *E) {
   VisitExpr(E);
   Record.push_back(E->getByteLength());
@@ -552,6 +560,14 @@
   Code = pch::EXPR_SIZEOF_ALIGN_OF;
 }
 
+void PCHStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
+  VisitExpr(E);
+  Writer.WriteSubExpr(E->getLHS());
+  Writer.WriteSubExpr(E->getRHS());
+  Writer.AddSourceLocation(E->getRBracketLoc(), Record);
+  Code = pch::EXPR_ARRAY_SUBSCRIPT;
+}
+
 void PCHStmtWriter::VisitCallExpr(CallExpr *E) {
   VisitExpr(E);
   Record.push_back(E->getNumArgs());

Modified: cfe/trunk/test/PCH/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.c?rev=69233&r1=69232&r2=69233&view=diff

==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Wed Apr 15 17:19:53 2009
@@ -8,6 +8,7 @@
 int integer;
 long long_integer;
 double floating;
+_Complex double floating_complex;
 
 // DeclRefExpr
 int_decl_ref *int_ptr1 = &integer;
@@ -20,6 +21,9 @@
 // FloatingLiteral + ParenExpr
 floating_literal *double_ptr = &floating;
 
+// ImaginaryLiteral
+imaginary_literal *cdouble_ptr = &floating_complex;
+
 // StringLiteral
 const char* printHello() {
   return hello;
@@ -36,6 +40,9 @@
 typeof_sizeof *size_t_ptr = &size_t_value;
 typeof_sizeof2 *size_t_ptr2 = &size_t_value;
 
+// ArraySubscriptExpr
+array_subscript *double_ptr1_5 = &floating;
+
 // CallExpr
 call_returning_double *double_ptr2 = &floating;
 

Modified: cfe/trunk/test/PCH/exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=69233&r1=69232&r2=69233&view=diff

==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 15 17:19:53 2009
@@ -13,6 +13,9 @@
 // FloatingLiteral and ParenExpr
 typedef typeof((42.5)) floating_literal;
 
+// ImaginaryLiteral
+typedef typeof(17.0i) imaginary_literal;
+
 // StringLiteral
 const char *hello = "Hello" "PCH" "World";
 
@@ -26,6 +29,10 @@
 typedef typeof(sizeof(int)) typeof_sizeof;
 typedef typeof(sizeof(Enumerator)) typeof_sizeof2;
 
+// ArraySubscriptExpr
+extern double values[];
+typedef typeof(values[2]) array_subscript;
+
 // CallExpr
 double dplus(double x, double y);
 double d0, d1;





More information about the cfe-commits mailing list