]> granicus.if.org Git - clang/commitdiff
- Finish hooking up support for __builtin_types_compatible_p().
authorSteve Naroff <snaroff@apple.com>
Wed, 1 Aug 2007 23:45:51 +0000 (23:45 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 1 Aug 2007 23:45:51 +0000 (23:45 +0000)
- Fix type printing code for recently added TypeOfExpr/TypeOfType.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40700 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Type.cpp
Parse/ParseExpr.cpp
Sema/Sema.h
Sema/SemaExpr.cpp
include/clang/AST/Expr.h
include/clang/Parse/Action.h

index 63a681a52c32eabb1c894625d5383613ea9a1eb7..2ef457e453552d1a3e210ae5c910c2cc1272d767 100644 (file)
@@ -654,15 +654,19 @@ void OCUVectorType::getAsStringInternal(std::string &S) const {
 }
 
 void TypeOfExpr::getAsStringInternal(std::string &InnerString) const {
+  if (!InnerString.empty())    // Prefix the basic type, e.g. 'typeof(e) X'.
+    InnerString = ' ' + InnerString;
   std::ostringstream s;
   getUnderlyingExpr()->print(s);
   InnerString = "typeof(" + s.str() + ") " + InnerString;
 }
 
-void TypeOfType::getAsStringInternal(std::string &S) const {
+void TypeOfType::getAsStringInternal(std::string &InnerString) const {
+  if (!InnerString.empty())    // Prefix the basic type, e.g. 'typeof(t) X'.
+    InnerString = ' ' + InnerString;
   std::string Tmp;
   getUnderlyingType().getAsStringInternal(Tmp);
-  S += "typeof(" + Tmp + ")";
+  InnerString = "typeof(" + Tmp + ")" + InnerString;
 }
 
 void FunctionTypeNoProto::getAsStringInternal(std::string &S) const {
index 15aca621792907b1f6fe99c00cca1f476805c001..b93234204464694b32cf562a604d4cf3739a388d 100644 (file)
@@ -819,13 +819,18 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() {
     Res = ParseAssignmentExpression();
     break;
   case tok::kw___builtin_types_compatible_p:
-    TypeTy *Type1 = ParseTypeName();
+    TypeTy *Ty1 = ParseTypeName();
     
     if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
       return ExprResult(true);
     
-    TypeTy *Type2 = ParseTypeName();
-    break;
+    TypeTy *Ty2 = ParseTypeName();
+    
+    if (Tok.getKind() != tok::r_paren) {
+      Diag(Tok, diag::err_expected_rparen);
+      return ExprResult(true);
+    }
+    return Actions.ParseTypesCompatibleExpr(StartLoc, Ty1, Ty2, ConsumeParen());
   }      
   
   MatchRHSPunctuation(tok::r_paren, LParenLoc);
index 86378a4f06c74d0d0ec2ccc44a318833f27e0231..ff2e5d1fd049425acdae3edc2e351c1820be6ac5 100644 (file)
@@ -282,7 +282,7 @@ public:
                                    SourceLocation RPLoc); // "({..})"
                                    
   // __builtin_types_compatible_p(type1, type2)
-  virtual ExprResult ParseTypesCompatibleExpr(SourceLocation LPLoc, 
+  virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc, 
                                               TypeTy *arg1, TypeTy *arg2,
                                               SourceLocation RPLoc);
   
index 9ef2e679901dc1be543ef3e67439c848f786479d..b0b1794da587f1db86b499e9094bebf8a3e78b82 100644 (file)
@@ -1566,7 +1566,7 @@ Sema::ExprResult Sema::ParseStmtExpr(SourceLocation LPLoc, StmtTy *substmt,
   return new StmtExpr(Compound, Ty, LPLoc, RPLoc);
 }
 
-Sema::ExprResult Sema::ParseTypesCompatibleExpr(SourceLocation LPLoc, 
+Sema::ExprResult Sema::ParseTypesCompatibleExpr(SourceLocation BuiltinLoc, 
                                                 TypeTy *arg1, TypeTy *arg2,
                                                 SourceLocation RPLoc) {
   QualType argT1 = QualType::getFromOpaquePtr(arg1);
@@ -1574,6 +1574,6 @@ Sema::ExprResult Sema::ParseTypesCompatibleExpr(SourceLocation LPLoc,
   
   assert((!argT1.isNull() && !argT2.isNull()) && "Missing type argument(s)");
   
-  return new TypesCompatibleExpr(Context.IntTy, LPLoc, argT1, argT2, RPLoc);
+  return new TypesCompatibleExpr(Context.IntTy, BuiltinLoc, argT1, argT2, RPLoc);
 }
 
index 568d3e02b7c1225e56e8a6a00b178c18d8e564c6..0e3ea58967fa1609d4df29356c6bc9e2d8870cdf 100644 (file)
@@ -728,18 +728,20 @@ public:
 class TypesCompatibleExpr : public Expr {
   QualType Type1;
   QualType Type2;
-  SourceLocation LParenLoc, RParenLoc;
+  SourceLocation BuiltinLoc, RParenLoc;
 public:
-  TypesCompatibleExpr(QualType ReturnType, SourceLocation LP
+  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc
                       QualType t1, QualType t2, SourceLocation RP) : 
     Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
-    LParenLoc(LP), RParenLoc(RP) {}
+    BuiltinLoc(BLoc), RParenLoc(RP) {}
 
   QualType getArgType1() { return Type1; }
   QualType getArgType2() { return Type2; }
-    
+  
+  int typesAreCompatible() { return Type::typesAreCompatible(Type1,Type2); }
+  
   virtual SourceRange getSourceRange() const {
-    return SourceRange(LParenLoc, RParenLoc);
+    return SourceRange(BuiltinLoc, RParenLoc);
   }
   virtual void visit(StmtVisitor &Visitor);
   static bool classof(const Stmt *T) {
index c019a0b22c14da856f8bb6da09188546b7e3b868..2c3ec162e46a0abb94247208569b0e4fe21e6265 100644 (file)
@@ -376,7 +376,7 @@ public:
     return 0;
   }
   // __builtin_types_compatible_p(type1, type2)
-  virtual ExprResult ParseTypesCompatibleExpr(SourceLocation LPLoc, 
+  virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc, 
                                               TypeTy *arg1, TypeTy *arg2,
                                               SourceLocation RPLoc) {
     return 0;