Add CK_DerivedToBase and use it PerformObjectMemberConversion.

llvm-svn: 77652
This commit is contained in:
Anders Carlsson 2009-07-31 01:23:52 +00:00
parent 5b78af9ed7
commit a076d14514
8 changed files with 23 additions and 11 deletions

View File

@ -1167,7 +1167,10 @@ public:
CK_BitCast,
/// CK_NoOp - Used for const_cast.
CK_NoOp
CK_NoOp,
/// CK_DerivedToBase - Derived to base class casts.
CK_DerivedToBase
};
private:

View File

@ -194,7 +194,8 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
/// If there is already an implicit cast, merge into the existing one.
/// If isLvalue, the result of the cast is an lvalue.
void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, bool isLvalue) {
void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty,
CastExpr::CastKind Kind, bool isLvalue) {
QualType ExprTy = Context.getCanonicalType(Expr->getType());
QualType TypeTy = Context.getCanonicalType(Ty);
@ -217,7 +218,7 @@ void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, bool isLvalue) {
ImpCast->setType(Ty);
ImpCast->setLvalueCast(isLvalue);
} else
Expr = new (Context) ImplicitCastExpr(Ty, CastExpr::CK_Unknown, Expr,
Expr = new (Context) ImplicitCastExpr(Ty, Kind, Expr,
isLvalue);
}

View File

@ -2972,7 +2972,9 @@ public:
/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
/// cast. If there is already an implicit cast, merge into the existing one.
/// If isLvalue, the result of the cast is an lvalue.
void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
void ImpCastExprToType(Expr *&Expr, QualType Type,
CastExpr::CastKind Kind = CastExpr::CK_Unknown,
bool isLvalue = false);
// UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
// functions and arrays to their respective pointers (C99 6.3.2.1).

View File

@ -348,7 +348,8 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) {
// If the first type needs to be converted (e.g. void** -> int*), do it now.
if (BuiltinFT->getArgType(0) != FirstArg->getType()) {
ImpCastExprToType(FirstArg, BuiltinFT->getArgType(0), false);
ImpCastExprToType(FirstArg, BuiltinFT->getArgType(0), CastExpr::CK_Unknown,
/*isLvalue=*/false);
TheCall->setArg(0, FirstArg);
}
@ -376,7 +377,8 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) {
// pass in 42. The 42 gets converted to char. This is even more strange
// for things like 45.123 -> char, etc.
// FIXME: Do this check.
ImpCastExprToType(Arg, ValType, false);
ImpCastExprToType(Arg, ValType, CastExpr::CK_Unknown,
/*isLvalue=*/false);
TheCall->setArg(i+1, Arg);
}

View File

@ -2727,7 +2727,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType,
// Perform the conversion.
// FIXME: Binding to a subobject of the lvalue is going to require more
// AST annotation than this.
ImpCastExprToType(Init, T1, /*isLvalue=*/true);
ImpCastExprToType(Init, T1, CastExpr::CK_Unknown, /*isLvalue=*/true);
}
}
@ -2786,7 +2786,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType,
// Perform the conversion.
// FIXME: Binding to a subobject of the lvalue is going to require more
// AST annotation than this.
ImpCastExprToType(Init, T1, /*isLvalue=*/true);
ImpCastExprToType(Init, T1, CastExpr::CK_Unknown, /*isLvalue=*/true);
}
break;
@ -2874,7 +2874,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType,
} else {
// FIXME: Binding to a subobject of the rvalue is going to require more
// AST annotation than this.
ImpCastExprToType(Init, T1, /*isLvalue=*/false);
ImpCastExprToType(Init, T1, CastExpr::CK_Unknown, /*isLvalue=*/false);
}
return false;
}

View File

@ -1045,7 +1045,8 @@ Sema::PerformObjectMemberConversion(Expr *&From, NamedDecl *Member) {
From->getSourceRange().getBegin(),
From->getSourceRange()))
return true;
ImpCastExprToType(From, DestType, /*isLvalue=*/true);
ImpCastExprToType(From, DestType, CastExpr::CK_DerivedToBase,
/*isLvalue=*/true);
}
return false;
}

View File

@ -875,6 +875,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
// constructor or conversion operator, and then cope with the standard
// conversions.
ImpCastExprToType(From, ToType.getNonReferenceType(),
CastExpr::CK_Unknown,
ToType->isLValueReferenceType());
return false;
@ -1008,6 +1009,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
// FIXME: Not sure about lvalue vs rvalue here in the presence of rvalue
// references.
ImpCastExprToType(From, ToType.getNonReferenceType(),
CastExpr::CK_Unknown,
ToType->isLValueReferenceType());
break;

View File

@ -2016,7 +2016,7 @@ Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) {
From->getSourceRange()))
return true;
ImpCastExprToType(From, DestType, /*isLvalue=*/true);
ImpCastExprToType(From, DestType, CastExpr::CK_Unknown, /*isLvalue=*/true);
return false;
}
@ -4476,6 +4476,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
// FIXME: Represent the user-defined conversion in the AST!
ImpCastExprToType(Object,
Conv->getConversionType().getNonReferenceType(),
CastExpr::CK_Unknown,
Conv->getConversionType()->isLValueReferenceType());
return ActOnCallExpr(S, ExprArg(*this, Object), LParenLoc,
MultiExprArg(*this, (ExprTy**)Args, NumArgs),