[cfe-commits] r69169 - 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 08:58:59 PDT 2009


Author: dgregor
Date: Wed Apr 15 10:58:59 2009
New Revision: 69169

URL: http://llvm.org/viewvc/llvm-project?rev=69169&view=rev
Log:
PCH support for UnaryOperator, SizeOfAlignOfExpr

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=69169&r1=69168&r2=69169&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 15 10:58:59 2009
@@ -704,12 +704,20 @@
            input->isValueDependent()), 
       Val(input), Opc(opc), Loc(l) {}
 
+  /// \brief Build an empty unary operator.
+  explicit UnaryOperator(EmptyShell Empty) 
+    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
+
   Opcode getOpcode() const { return Opc; }
+  void setOpcode(Opcode O) { Opc = O; }
+
   Expr *getSubExpr() const { return cast<Expr>(Val); }
-  
+  void setSubExpr(Expr *E) { Val = E; }
+
   /// getOperatorLoc - Return the location of the operator.
   SourceLocation getOperatorLoc() const { return Loc; }
-  
+  void setOperatorLoc(SourceLocation L) { Loc = L; }
+
   /// isPostfix - Return true if this is a postfix operation, like x++.
   static bool isPostfix(Opcode Op) {
     return Op == PostInc || Op == PostDec;
@@ -793,9 +801,15 @@
     Argument.Ex = E;
   }
 
+  /// \brief Construct an empty sizeof/alignof expression.
+  explicit SizeOfAlignOfExpr(EmptyShell Empty)
+    : Expr(SizeOfAlignOfExprClass, Empty) { }
+
   virtual void Destroy(ASTContext& C);
 
   bool isSizeOf() const { return isSizeof; }
+  void setSizeof(bool S) { isSizeof = S; }
+
   bool isArgumentType() const { return isType; }
   QualType getArgumentType() const {
     assert(isArgumentType() && "calling getArgumentType() when arg is expr");
@@ -808,7 +822,13 @@
   const Expr *getArgumentExpr() const {
     return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
   }
-  
+
+  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
+  void setArgument(QualType T) { 
+    Argument.Ty = T.getAsOpaquePtr(); 
+    isType = true; 
+  }
+
   /// Gets the argument type, or the type of the argument expression, whichever
   /// is appropriate.
   QualType getTypeOfArgument() const {
@@ -816,6 +836,10 @@
   }
 
   SourceLocation getOperatorLoc() const { return OpLoc; }
+  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
+
+  SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
   virtual SourceRange getSourceRange() const {
     return SourceRange(OpLoc, RParenLoc);

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

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 15 10:58:59 2009
@@ -385,6 +385,10 @@
       EXPR_CHARACTER_LITERAL,
       /// \brief A ParenExpr record.
       EXPR_PAREN,
+      /// \brief A UnaryOperator record.
+      EXPR_UNARY_OPERATOR,
+      /// \brief A SizefAlignOfExpr record.
+      EXPR_SIZEOF_ALIGN_OF,
       /// \brief A BinaryOperator record.
       EXPR_BINARY_OPERATOR,
       /// \brief An ImplicitCastExpr record.

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 15 10:58:59 2009
@@ -238,6 +238,8 @@
     unsigned VisitFloatingLiteral(FloatingLiteral *E);
     unsigned VisitCharacterLiteral(CharacterLiteral *E);
     unsigned VisitParenExpr(ParenExpr *E);
+    unsigned VisitUnaryOperator(UnaryOperator *E);
+    unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
     unsigned VisitCastExpr(CastExpr *E);
     unsigned VisitBinaryOperator(BinaryOperator *E);
     unsigned VisitImplicitCastExpr(ImplicitCastExpr *E);
@@ -298,6 +300,28 @@
   return 1;
 }
 
+unsigned PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) {
+  VisitExpr(E);
+  E->setSubExpr(ExprStack.back());
+  E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
+  E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 1;
+}
+
+unsigned PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
+  VisitExpr(E);
+  E->setSizeof(Record[Idx++]);
+  if (Record[Idx] == 0) {
+    E->setArgument(ExprStack.back());
+    ++Idx;
+  } else {
+    E->setArgument(Reader.GetType(Record[Idx++]));
+  }
+  E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return E->isArgumentType()? 0 : 1;
+}
+
 unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) {
   VisitExpr(E);
   E->setSubExpr(ExprStack.back());
@@ -1640,6 +1664,14 @@
       E = new (Context) ParenExpr(Empty);
       break;
 
+    case pch::EXPR_UNARY_OPERATOR:
+      E = new (Context) UnaryOperator(Empty);
+      break;
+
+    case pch::EXPR_SIZEOF_ALIGN_OF:
+      E = new (Context) SizeOfAlignOfExpr(Empty);
+      break;
+
     case pch::EXPR_BINARY_OPERATOR:
       E = new (Context) BinaryOperator(Empty);
       break;

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 15 10:58:59 2009
@@ -450,6 +450,8 @@
     void VisitFloatingLiteral(FloatingLiteral *E);
     void VisitCharacterLiteral(CharacterLiteral *E);
     void VisitParenExpr(ParenExpr *E);
+    void VisitUnaryOperator(UnaryOperator *E);
+    void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
     void VisitCastExpr(CastExpr *E);
     void VisitBinaryOperator(BinaryOperator *E);
     void VisitImplicitCastExpr(ImplicitCastExpr *E);
@@ -509,6 +511,28 @@
   Code = pch::EXPR_PAREN;
 }
 
+void PCHStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
+  VisitExpr(E);
+  Writer.WriteSubExpr(E->getSubExpr());
+  Record.push_back(E->getOpcode()); // FIXME: stable encoding
+  Writer.AddSourceLocation(E->getOperatorLoc(), Record);
+  Code = pch::EXPR_UNARY_OPERATOR;
+}
+
+void PCHStmtWriter::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { 
+  VisitExpr(E);
+  Record.push_back(E->isSizeOf());
+  if (E->isArgumentType())
+    Writer.AddTypeRef(E->getArgumentType(), Record);
+  else {
+    Record.push_back(0);
+    Writer.WriteSubExpr(E->getArgumentExpr());
+  }
+  Writer.AddSourceLocation(E->getOperatorLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_SIZEOF_ALIGN_OF;
+}
+
 void PCHStmtWriter::VisitCastExpr(CastExpr *E) {
   VisitExpr(E);
   Writer.WriteSubExpr(E->getSubExpr());

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

==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Wed Apr 15 10:58:59 2009
@@ -23,8 +23,16 @@
 // CharacterLiteral
 char_literal *int_ptr3 = &integer;
 
+// UnaryOperator
+negate_enum *int_ptr4 = &integer;
+
+// SizeOfAlignOfExpr
+typeof(sizeof(float)) size_t_value;
+typeof_sizeof *size_t_ptr = &size_t_value;
+typeof_sizeof2 *size_t_ptr2 = &size_t_value;
+
 // BinaryOperator
-add_result *int_ptr4 = &integer;
+add_result *int_ptr5 = &integer;
 
 // CStyleCastExpr
 void_ptr vp1 = &integer;

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

==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 15 10:58:59 2009
@@ -16,6 +16,13 @@
 // CharacterLiteral
 typedef typeof('a') char_literal;
 
+// UnaryOperator
+typedef typeof(-Enumerator) negate_enum;
+
+// SizeOfAlignOfExpr
+typedef typeof(sizeof(int)) typeof_sizeof;
+typedef typeof(sizeof(Enumerator)) typeof_sizeof2;
+
 // BinaryOperator
 typedef typeof(i + Enumerator) add_result;
 





More information about the cfe-commits mailing list