[cfe-commits] r40700 - in /cfe/trunk: AST/Type.cpp Parse/ParseExpr.cpp Sema/Sema.h Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/Parse/Action.h
Steve Naroff
snaroff at apple.com
Wed Aug 1 16:45:51 PDT 2007
Author: snaroff
Date: Wed Aug 1 18:45:51 2007
New Revision: 40700
URL: http://llvm.org/viewvc/llvm-project?rev=40700&view=rev
Log:
- Finish hooking up support for __builtin_types_compatible_p().
- Fix type printing code for recently added TypeOfExpr/TypeOfType.
Modified:
cfe/trunk/AST/Type.cpp
cfe/trunk/Parse/ParseExpr.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Parse/Action.h
Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=40700&r1=40699&r2=40700&view=diff
==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Wed Aug 1 18:45:51 2007
@@ -654,15 +654,19 @@
}
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 {
Modified: cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseExpr.cpp?rev=40700&r1=40699&r2=40700&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/Parse/ParseExpr.cpp Wed Aug 1 18:45:51 2007
@@ -819,13 +819,18 @@
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);
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=40700&r1=40699&r2=40700&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Wed Aug 1 18:45:51 2007
@@ -282,7 +282,7 @@
SourceLocation RPLoc); // "({..})"
// __builtin_types_compatible_p(type1, type2)
- virtual ExprResult ParseTypesCompatibleExpr(SourceLocation LPLoc,
+ virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1, TypeTy *arg2,
SourceLocation RPLoc);
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=40700&r1=40699&r2=40700&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Aug 1 18:45:51 2007
@@ -1566,7 +1566,7 @@
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 @@
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);
}
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=40700&r1=40699&r2=40700&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Aug 1 18:45:51 2007
@@ -728,18 +728,20 @@
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) {
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=40700&r1=40699&r2=40700&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Aug 1 18:45:51 2007
@@ -376,7 +376,7 @@
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;
More information about the cfe-commits
mailing list