]> granicus.if.org Git - clang/commitdiff
Added TypeLocs to TypesCompatibleExpr node.
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Tue, 10 Aug 2010 08:50:03 +0000 (08:50 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Tue, 10 Aug 2010 08:50:03 +0000 (08:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110663 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
include/clang/AST/RecursiveASTVisitor.h
lib/Frontend/PCHReaderStmt.cpp
lib/Frontend/PCHWriterStmt.cpp
lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp
lib/Sema/TreeTransform.h

index 12cf2626e635a33cea0fd217fecbfec47c2ce2a5..047d250d5b0d7e5aaf5221a106e82fa8d0160bdd 100644 (file)
@@ -2537,23 +2537,27 @@ public:
 /// expressions) are compatible. The result of this built-in function can be
 /// used in integer constant expressions.
 class TypesCompatibleExpr : public Expr {
-  QualType Type1;
-  QualType Type2;
+  TypeSourceInfo *TInfo1;
+  TypeSourceInfo *TInfo2;
   SourceLocation BuiltinLoc, RParenLoc;
 public:
   TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
-                      QualType t1, QualType t2, SourceLocation RP) :
+                      TypeSourceInfo *tinfo1, TypeSourceInfo *tinfo2,
+                      SourceLocation RP) :
     Expr(TypesCompatibleExprClass, ReturnType, false, false),
-    Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {}
+    TInfo1(tinfo1), TInfo2(tinfo2), 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; }
+  TypeSourceInfo *getArgTInfo1() const { return TInfo1; }
+  void setArgTInfo1(TypeSourceInfo *TInfo) { TInfo1 = TInfo; }
+  TypeSourceInfo *getArgTInfo2() const { return TInfo2; }
+  void setArgTInfo2(TypeSourceInfo *TInfo) { TInfo2 = TInfo; }
+
+  QualType getArgType1() const { return TInfo1->getType(); }
+  QualType getArgType2() const { return TInfo2->getType(); }
 
   SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
   void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
index 4f36f359dd4e5ad062f91756d72c9aece9fdbc95..f599787a359e7b070cda83822f43cfab7c323af7 100644 (file)
@@ -1633,8 +1633,8 @@ DEF_TRAVERSE_STMT(CXXTypeidExpr, {
   })
 
 DEF_TRAVERSE_STMT(TypesCompatibleExpr, {
-    TRY_TO(TraverseType(S->getArgType1()));
-    TRY_TO(TraverseType(S->getArgType2()));
+    TRY_TO(TraverseTypeLoc(S->getArgTInfo1()->getTypeLoc()));
+    TRY_TO(TraverseTypeLoc(S->getArgTInfo2()->getTypeLoc()));
   })
 
 DEF_TRAVERSE_STMT(UnaryTypeTraitExpr, {
index d5d527d32e3ab60a61ae0b7db59e01d2ef24bc0a..938ff9a48afcd24b4a00ce46639fc2c964eb8803 100644 (file)
@@ -730,8 +730,8 @@ void PCHStmtReader::VisitStmtExpr(StmtExpr *E) {
 
 void PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
   VisitExpr(E);
-  E->setArgType1(Reader.GetType(Record[Idx++]));
-  E->setArgType2(Reader.GetType(Record[Idx++]));
+  E->setArgTInfo1(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
+  E->setArgTInfo2(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx));
   E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
index 3a65785b0f797bd717aabfa2bfcea15bc65dcfad..2c4452c8884a1aad744a04973873533e73e21248 100644 (file)
@@ -718,8 +718,8 @@ void PCHStmtWriter::VisitStmtExpr(StmtExpr *E) {
 
 void PCHStmtWriter::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
   VisitExpr(E);
-  Writer.AddTypeRef(E->getArgType1(), Record);
-  Writer.AddTypeRef(E->getArgType2(), Record);
+  Writer.AddTypeSourceInfo(E->getArgTInfo1(), Record);
+  Writer.AddTypeSourceInfo(E->getArgTInfo2(), Record);
   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
   Writer.AddSourceLocation(E->getRParenLoc(), Record);
   Code = pch::EXPR_TYPES_COMPATIBLE;
index 1e5da3d339982a98a6ba5a6fe575794536687123..74d0f2afad672a509bef0eea338cb142b06aa950 100644 (file)
@@ -2154,6 +2154,10 @@ public:
   virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
                                                     TypeTy *arg1, TypeTy *arg2,
                                                     SourceLocation RPLoc);
+  OwningExprResult BuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
+                                            TypeSourceInfo *argTInfo1,
+                                            TypeSourceInfo *argTInfo2,
+                                            SourceLocation RPLoc);
 
   // __builtin_choose_expr(constExpr, expr1, expr2)
   virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
index d573ca9bbbdf003ddba2e1e32bd86b270d82eeda..e5a50656874fcb89323d2e7248c24157c545459a 100644 (file)
@@ -7019,12 +7019,21 @@ Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
 Sema::OwningExprResult Sema::ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
                                                       TypeTy *arg1,TypeTy *arg2,
                                                       SourceLocation RPLoc) {
-  // FIXME: Preserve type source info.
-  QualType argT1 = GetTypeFromParser(arg1);
-  QualType argT2 = GetTypeFromParser(arg2);
+  TypeSourceInfo *argTInfo1;
+  QualType argT1 = GetTypeFromParser(arg1, &argTInfo1);
+  TypeSourceInfo *argTInfo2;
+  QualType argT2 = GetTypeFromParser(arg2, &argTInfo2);
 
   assert((!argT1.isNull() && !argT2.isNull()) && "Missing type argument(s)");
 
+  return BuildTypesCompatibleExpr(BuiltinLoc, argTInfo1, argTInfo2, RPLoc);
+}
+
+Sema::OwningExprResult
+Sema::BuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
+                               TypeSourceInfo *argTInfo1,
+                               TypeSourceInfo *argTInfo2,
+                               SourceLocation RPLoc) {
   if (getLangOptions().CPlusPlus) {
     Diag(BuiltinLoc, diag::err_types_compatible_p_in_cplusplus)
       << SourceRange(BuiltinLoc, RPLoc);
@@ -7032,9 +7041,10 @@ Sema::OwningExprResult Sema::ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
   }
 
   return Owned(new (Context) TypesCompatibleExpr(Context.IntTy, BuiltinLoc,
-                                                 argT1, argT2, RPLoc));
+                                                 argTInfo1, argTInfo2, RPLoc));
 }
 
+
 Sema::OwningExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc,
                                              ExprArg cond,
                                              ExprArg expr1, ExprArg expr2,
index d13219dbcf542c470c2c6686e67b427c53b905e6..65107ccfe79340743249c62d35ea784593dad834 100644 (file)
@@ -1354,11 +1354,11 @@ public:
   /// By default, performs semantic analysis to build the new expression.
   /// Subclasses may override this routine to provide different behavior.
   OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
-                                              QualType T1, QualType T2,
+                                              TypeSourceInfo *TInfo1,
+                                              TypeSourceInfo *TInfo2,
                                               SourceLocation RParenLoc) {
-    return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
-                                              T1.getAsOpaquePtr(),
-                                              T2.getAsOpaquePtr(),
+    return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
+                                              TInfo1, TInfo2,
                                               RParenLoc);
   }
 
@@ -4855,27 +4855,29 @@ TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
 template<typename Derived>
 Sema::OwningExprResult
 TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
-  QualType T1, T2;
+  TypeSourceInfo *TInfo1;
+  TypeSourceInfo *TInfo2;
   {
     // FIXME: Source location isn't quite accurate.
     TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
 
-    T1 = getDerived().TransformType(E->getArgType1());
-    if (T1.isNull())
+    TInfo1 = getDerived().TransformType(E->getArgTInfo1());
+    if (!TInfo1)
       return SemaRef.ExprError();
 
-    T2 = getDerived().TransformType(E->getArgType2());
-    if (T2.isNull())
+    TInfo2 = getDerived().TransformType(E->getArgTInfo2());
+    if (!TInfo2)
       return SemaRef.ExprError();
   }
 
   if (!getDerived().AlwaysRebuild() &&
-      T1 == E->getArgType1() &&
-      T2 == E->getArgType2())
+      TInfo1 == E->getArgTInfo1() &&
+      TInfo2 == E->getArgTInfo2())
     return SemaRef.Owned(E->Retain());
 
   return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
-                                                 T1, T2, E->getRParenLoc());
+                                                 TInfo1, TInfo2,
+                                                 E->getRParenLoc());
 }
 
 template<typename Derived>