[cfe-commits] r69242 - 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 16:33:31 PDT 2009


Author: dgregor
Date: Wed Apr 15 18:33:31 2009
New Revision: 69242

URL: http://llvm.org/viewvc/llvm-project?rev=69242&view=rev
Log:
PCH support for TypesCompatibleExpr, ChooseExpr, and GNUNullExpr.

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=69242&r1=69241&r2=69242&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 15 18:33:31 2009
@@ -1660,9 +1660,21 @@
     Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
     BuiltinLoc(BLoc), RParenLoc(RP) {}
 
+  /// \brief Build an empty __builtin_type_compatible_p expression.
+  explicit TypesCompatibleExpr(EmptyShell Empty)
+    : Expr(TypesCompatibleExprClass, Empty) { }
+
   QualType getArgType1() const { return Type1; }
+  void setArgType1(QualType T) { Type1 = T; }
   QualType getArgType2() const { return Type2; }
+  void setArgType2(QualType T) { Type2 = T; }
     
+  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
+  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
+  
+  SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
+  
   virtual SourceRange getSourceRange() const {
     return SourceRange(BuiltinLoc, RParenLoc);
   }
@@ -1770,6 +1782,9 @@
       SubExprs[RHS] = rhs;
     }        
 
+  /// \brief Build an empty __builtin_choose_expr.
+  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
+
   /// isConditionTrue - Return whether the condition is true (i.e. not
   /// equal to zero).
   bool isConditionTrue(ASTContext &C) const;
@@ -1781,8 +1796,17 @@
   }
 
   Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
+  void setCond(Expr *E) { SubExprs[COND] = E; }
   Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
+  void setLHS(Expr *E) { SubExprs[LHS] = E; }
   Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
+  void setRHS(Expr *E) { SubExprs[RHS] = E; }
+
+  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
+  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
+  
+  SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
   virtual SourceRange getSourceRange() const {
     return SourceRange(BuiltinLoc, RParenLoc);
@@ -1814,8 +1838,12 @@
   GNUNullExpr(QualType Ty, SourceLocation Loc) 
     : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
 
+  /// \brief Build an empty GNU __null expression.
+  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
+
   /// getTokenLocation - The location of the __null token.
   SourceLocation getTokenLocation() const { return TokenLoc; }
+  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
 
   virtual SourceRange getSourceRange() const {
     return SourceRange(TokenLoc);

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

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 15 18:33:31 2009
@@ -426,7 +426,15 @@
       /// FIXME: DesignatedInitExpr
       /// FIXME: ImplicitValueInitExpr
       /// \brief A VAArgExpr record.
-      EXPR_VA_ARG
+      EXPR_VA_ARG,
+      // FIXME: AddrLabelExpr
+      // FIXME: StmtExpr
+      /// \brief A TypesCompatibleExpr record.
+      EXPR_TYPES_COMPATIBLE,
+      /// \brief A ChooseExpr record.
+      EXPR_CHOOSE,
+      /// \brief A GNUNullExpr record.
+      EXPR_GNU_NULL
     };
     /// @}
   }

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 15 18:33:31 2009
@@ -259,6 +259,9 @@
     unsigned VisitCStyleCastExpr(CStyleCastExpr *E);
     unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E);
     unsigned VisitVAArgExpr(VAArgExpr *E);
+    unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
+    unsigned VisitChooseExpr(ChooseExpr *E);
+    unsigned VisitGNUNullExpr(GNUNullExpr *E);
   };
 }
 
@@ -455,6 +458,30 @@
   return 1;
 }
 
+unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
+  VisitExpr(E);
+  E->setArgType1(Reader.GetType(Record[Idx++]));
+  E->setArgType2(Reader.GetType(Record[Idx++]));
+  E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 0;
+}
+
+unsigned PCHStmtReader::VisitChooseExpr(ChooseExpr *E) {
+  VisitExpr(E);
+  E->setCond(ExprStack[ExprStack.size() - 3]);
+  E->setLHS(ExprStack[ExprStack.size() - 2]);
+  E->setRHS(ExprStack[ExprStack.size() - 1]);
+  E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 3;
+}
+
+unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
+  VisitExpr(E);
+  E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 0;
+}
 
 // FIXME: use the diagnostics machinery
 static bool Error(const char *Str) {
@@ -1977,6 +2004,18 @@
       // FIXME: untested; we need function bodies first
       E = new (Context) VAArgExpr(Empty);
       break;
+
+    case pch::EXPR_TYPES_COMPATIBLE:
+      E = new (Context) TypesCompatibleExpr(Empty);
+      break;
+
+    case pch::EXPR_CHOOSE:
+      E = new (Context) ChooseExpr(Empty);
+      break;
+
+    case pch::EXPR_GNU_NULL:
+      E = new (Context) GNUNullExpr(Empty);
+      break;
     }
 
     // We hit an EXPR_STOP, so we're done with this expression.

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 15 18:33:31 2009
@@ -466,6 +466,9 @@
     void VisitCStyleCastExpr(CStyleCastExpr *E);
     void VisitExtVectorElementExpr(ExtVectorElementExpr *E);
     void VisitVAArgExpr(VAArgExpr *E);
+    void VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
+    void VisitChooseExpr(ChooseExpr *E);
+    void VisitGNUNullExpr(GNUNullExpr *E);
   };
 }
 
@@ -655,6 +658,31 @@
   Code = pch::EXPR_VA_ARG;
 }
 
+void PCHStmtWriter::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
+  VisitExpr(E);
+  Writer.AddTypeRef(E->getArgType1(), Record);
+  Writer.AddTypeRef(E->getArgType2(), Record);
+  Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_TYPES_COMPATIBLE;
+}
+
+void PCHStmtWriter::VisitChooseExpr(ChooseExpr *E) {
+  VisitExpr(E);
+  Writer.WriteSubExpr(E->getCond());
+  Writer.WriteSubExpr(E->getLHS());
+  Writer.WriteSubExpr(E->getRHS());
+  Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_CHOOSE;
+}
+
+void PCHStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
+  VisitExpr(E);
+  Writer.AddSourceLocation(E->getTokenLocation(), Record);
+  Code = pch::EXPR_GNU_NULL;
+}
+
 //===----------------------------------------------------------------------===//
 // PCHWriter Implementation
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Wed Apr 15 18:33:31 2009
@@ -63,3 +63,12 @@
 
 // ExtVectorElementExpr
 ext_vector_element *double_ptr5 = &floating;
+
+// TypesCompatibleExpr
+types_compatible *int_ptr7 = &integer;
+
+// ChooseExpr
+choose_expr *int_ptr8 = &integer;
+
+// GNUNullExpr FIXME: needs C++
+//null_type null = __null;

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

==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 15 18:33:31 2009
@@ -60,3 +60,12 @@
 typedef __attribute__(( ext_vector_type(2) )) double double2;
 double2 vec2;
 typedef typeof(vec2.x) ext_vector_element;
+
+// TypesCompatibleExpr
+typedef typeof(__builtin_types_compatible_p(float, double)) types_compatible;
+
+// ChooseExpr
+typedef typeof(__builtin_choose_expr(17 > 19, d0, 1)) choose_expr;
+
+// GNUNullExpr FIXME: needs C++
+// typedef typeof(__null) null_type;





More information about the cfe-commits mailing list