diff options
author | Steve Naroff <snaroff@apple.com> | 2007-08-01 23:45:51 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-08-01 23:45:51 +0000 |
commit | 363bcff47df2fda3cfcfcd994b7888157df58c43 (patch) | |
tree | 292eb4d90e27aa308cc84f0b34eb72a2e7454c0e | |
parent | d34e915f33224c508ad55fbf975bd10b7876e197 (diff) |
- Finish hooking up support for __builtin_types_compatible_p().
- 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
-rw-r--r-- | AST/Type.cpp | 8 | ||||
-rw-r--r-- | Parse/ParseExpr.cpp | 11 | ||||
-rw-r--r-- | Sema/Sema.h | 2 | ||||
-rw-r--r-- | Sema/SemaExpr.cpp | 4 | ||||
-rw-r--r-- | include/clang/AST/Expr.h | 12 | ||||
-rw-r--r-- | include/clang/Parse/Action.h | 2 |
6 files changed, 25 insertions, 14 deletions
diff --git a/AST/Type.cpp b/AST/Type.cpp index 63a681a52c..2ef457e453 100644 --- a/AST/Type.cpp +++ b/AST/Type.cpp @@ -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 { diff --git a/Parse/ParseExpr.cpp b/Parse/ParseExpr.cpp index 15aca62179..b932342044 100644 --- a/Parse/ParseExpr.cpp +++ b/Parse/ParseExpr.cpp @@ -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); diff --git a/Sema/Sema.h b/Sema/Sema.h index 86378a4f06..ff2e5d1fd0 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -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); diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 9ef2e67990..b0b1794da5 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -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); } diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 568d3e02b7..0e3ea58967 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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) { diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index c019a0b22c..2c3ec162e4 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -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; |