[cfe-commits] r79787 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/StmtDumper.cpp lib/Sema/Sema.h lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp
Anders Carlsson
andersca at mac.com
Sat Aug 22 16:33:40 PDT 2009
Author: andersca
Date: Sat Aug 22 18:33:40 2009
New Revision: 79787
URL: http://llvm.org/viewvc/llvm-project?rev=79787&view=rev
Log:
Add CK_NullToMemberPointer and CK_BaseToDerivedMemberPointer cast kinds. Make -ast-dump print out the cast kinds of cast expressions.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/StmtDumper.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=79787&r1=79786&r2=79787&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Aug 22 18:33:40 2009
@@ -1181,7 +1181,14 @@
CK_ToUnion,
/// CK_ArrayToPointerDecay - Array to pointer decay.
- CK_ArrayToPointerDecay
+ CK_ArrayToPointerDecay,
+
+ /// CK_NullToMemberPointer - Null pointer to member pointer.
+ CK_NullToMemberPointer,
+
+ /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
+ /// member pointer in derived class.
+ CK_BaseToDerivedMemberPointer
};
struct CastInfo {
Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=79787&r1=79786&r2=79787&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Sat Aug 22 18:33:40 2009
@@ -117,6 +117,7 @@
// Exprs
void VisitExpr(Expr *Node);
+ void VisitCastExpr(CastExpr *Node);
void VisitDeclRefExpr(DeclRefExpr *Node);
void VisitPredefinedExpr(PredefinedExpr *Node);
void VisitCharacterLiteral(CharacterLiteral *Node);
@@ -298,22 +299,56 @@
DumpExpr(Node);
}
+void StmtDumper::VisitCastExpr(CastExpr *Node) {
+ DumpExpr(Node);
+ fprintf(F, " ");
+ switch (Node->getCastKind()) {
+ case CastExpr::CK_Unknown:
+ fprintf(F, "<Unknown>");
+ break;
+ case CastExpr::CK_BitCast:
+ fprintf(F, "<BitCast>");
+ break;
+ case CastExpr::CK_NoOp:
+ fprintf(F, "<NoOp>");
+ break;
+ case CastExpr::CK_DerivedToBase:
+ fprintf(F, "<DerivedToBase>");
+ break;
+ case CastExpr::CK_Dynamic:
+ fprintf(F, "<Dynamic>");
+ break;
+ case CastExpr::CK_ToUnion:
+ fprintf(F, "<ToUnion>");
+ break;
+ case CastExpr::CK_ArrayToPointerDecay:
+ fprintf(F, "<ArrayToPointerDecay>");
+ break;
+ case CastExpr::CK_NullToMemberPointer:
+ fprintf(F, "<NullToMemberPointer>");
+ break;
+ case CastExpr::CK_BaseToDerivedMemberPointer:
+ fprintf(F, "<BaseToDerivedMemberPointer>");
+ break;
+ }
+}
+
void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
DumpExpr(Node);
fprintf(F, " ");
switch (Node->getDecl()->getKind()) {
- case Decl::Function: fprintf(F,"FunctionDecl"); break;
- case Decl::Var: fprintf(F,"Var"); break;
- case Decl::ParmVar: fprintf(F,"ParmVar"); break;
- case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
- case Decl::Typedef: fprintf(F,"Typedef"); break;
- case Decl::Record: fprintf(F,"Record"); break;
- case Decl::Enum: fprintf(F,"Enum"); break;
- case Decl::CXXRecord: fprintf(F,"CXXRecord"); break;
- case Decl::ObjCInterface: fprintf(F,"ObjCInterface"); break;
- case Decl::ObjCClass: fprintf(F,"ObjCClass"); break;
- default: fprintf(F,"Decl"); break;
+ default: fprintf(F,"Decl"); break;
+ case Decl::Function: fprintf(F,"FunctionDecl"); break;
+ case Decl::Var: fprintf(F,"Var"); break;
+ case Decl::ParmVar: fprintf(F,"ParmVar"); break;
+ case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
+ case Decl::Typedef: fprintf(F,"Typedef"); break;
+ case Decl::Record: fprintf(F,"Record"); break;
+ case Decl::Enum: fprintf(F,"Enum"); break;
+ case Decl::CXXRecord: fprintf(F,"CXXRecord"); break;
+ case Decl::ObjCInterface: fprintf(F,"ObjCInterface"); break;
+ case Decl::ObjCClass: fprintf(F,"ObjCClass"); break;
}
fprintf(F, "='%s' %p", Node->getDecl()->getNameAsString().c_str(),
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=79787&r1=79786&r2=79787&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat Aug 22 18:33:40 2009
@@ -735,7 +735,8 @@
bool CheckPointerConversion(Expr *From, QualType ToType);
bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
QualType &ConvertedType);
- bool CheckMemberPointerConversion(Expr *From, QualType ToType);
+ bool CheckMemberPointerConversion(Expr *From, QualType ToType,
+ CastExpr::CastKind &Kind);
bool IsQualificationConversion(QualType FromType, QualType ToType);
bool IsUserDefinedConversion(Expr *From, QualType ToType,
UserDefinedConversionSequence& User,
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=79787&r1=79786&r2=79787&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Aug 22 18:33:40 2009
@@ -1014,12 +1014,13 @@
ImpCastExprToType(From, ToType);
break;
- case ICK_Pointer_Member:
- if (CheckMemberPointerConversion(From, ToType))
- return true;
- ImpCastExprToType(From, ToType);
- break;
-
+ case ICK_Pointer_Member: {
+ CastExpr::CastKind Kind = CastExpr::CK_Unknown;
+ if (CheckMemberPointerConversion(From, ToType, Kind))
+ return true;
+ ImpCastExprToType(From, ToType, Kind);
+ break;
+ }
case ICK_Boolean_Conversion:
FromType = Context.BoolTy;
ImpCastExprToType(From, FromType);
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=79787&r1=79786&r2=79787&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sat Aug 22 18:33:40 2009
@@ -1199,11 +1199,17 @@
/// for which IsMemberPointerConversion has already returned true. It returns
/// true and produces a diagnostic if there was an error, or returns false
/// otherwise.
-bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType) {
+bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType,
+ CastExpr::CastKind &Kind) {
QualType FromType = From->getType();
const MemberPointerType *FromPtrType = FromType->getAs<MemberPointerType>();
- if (!FromPtrType)
+ if (!FromPtrType) {
+ // This must be a null pointer to member pointer conversion
+ assert(From->isNullPointerConstant(Context) &&
+ "Expr must be null pointer constant!");
+ Kind = CastExpr::CK_NullToMemberPointer;
return false;
+ }
const MemberPointerType *ToPtrType = ToType->getAs<MemberPointerType>();
assert(ToPtrType && "No member pointer cast has a target type "
@@ -1245,6 +1251,8 @@
return true;
}
+ // Must be a base to derived member conversion.
+ Kind = CastExpr::CK_BaseToDerivedMemberPointer;
return false;
}
More information about the cfe-commits
mailing list