[cfe-commits] [PATCH] Use ExprResult& instead of Expr *& in Sema
Douglas Gregor
dgregor at apple.com
Tue Mar 8 19:16:26 PST 2011
On Mar 5, 2011, at 12:10 AM, John Wiegley wrote:
> John Wiegley <johnw at boostpro.com> writes:
>
>> I have updated this patch to include a few corrections from Eric, and also
>> resolved some merge conflicts with very recent changes in Subversion.
>
> In my adventures with managing multiple dependent patches at once, I seem to
> have reverted some of Eric's intended changes in my last patch. This is
> corrected in the attached.
I like the direction of this cleanup. There are a number of places where I'd rather we return an ExprResult rather than returning a bool and having an ExprResult& argument mutated. It's far easier to use an ExprResult-returning routine properly.
Unfortunately, it looks like a lot of work to make these changes. Sorry :(
> - bool PerformObjectArgumentInitialization(Expr *&From,
> + bool PerformObjectArgumentInitialization(ExprResult &From,
> NestedNameSpecifier *Qualifier,
> NamedDecl *FoundDecl,
> CXXMethodDecl *Method);
>
> - bool PerformContextuallyConvertToBool(Expr *&From);
> - bool PerformContextuallyConvertToObjCId(Expr *&From);
> + bool PerformContextuallyConvertToBool(ExprResult &From);
> + bool PerformContextuallyConvertToObjCId(ExprResult &From);
All three of these functions should just return an ExprResult, rather than mutating their arguments in place.
> ExprResult
> ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
> @@ -1171,7 +1171,7 @@ public:
> const PartialDiagnostic &AmbigNote,
> const PartialDiagnostic &ConvDiag);
>
> - bool PerformObjectMemberConversion(Expr *&From,
> + bool PerformObjectMemberConversion(ExprResult &From,
> NestedNameSpecifier *Qualifier,
> NamedDecl *FoundDecl,
> NamedDecl *Member);
Same here.
> @@ -2024,7 +2024,7 @@ public:
> const TemplateArgumentListInfo *TemplateArgs,
> bool SuppressQualifierCheck = false);
>
> - ExprResult LookupMemberExpr(LookupResult &R, Expr *&Base,
> + ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base,
> bool &IsArrow, SourceLocation OpLoc,
> CXXScopeSpec &SS,
> Decl *ObjCImpDecl,
It find it very weird that we both return an ExprResult and mutate the Base in place. Oh well.
> @@ -2448,7 +2448,7 @@ public:
>
> //// ActOnCXXThrow - Parse throw expressions.
> ExprResult ActOnCXXThrow(SourceLocation OpLoc, Expr *expr);
> - bool CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E);
> + bool CheckCXXThrowOperand(SourceLocation ThrowLoc, ExprResult &E);
Would be nice to return an ExprResult rather than mutating the argument.
> /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
> /// Can be interpreted either as function-style casting ("int(x)")
> @@ -3359,7 +3359,7 @@ public:
> bool CheckTemplateArgumentPointerToMember(Expr *Arg,
> TemplateArgument &Converted);
> bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
> - QualType InstantiatedParamType, Expr *&Arg,
> + QualType InstantiatedParamType, ExprResult &Arg,
> TemplateArgument &Converted,
> CheckTemplateArgumentKind CTAK = CTAK_Specified);
Same here.
> bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
> @@ -4716,34 +4716,42 @@ public:
> ExprValueKind VK = VK_RValue,
> const CXXCastPath *BasePath = 0);
>
> + void ImpCastExprToType(ExprResult &ExprRes, QualType Type, CastKind CK,
> + ExprValueKind VK = VK_RValue,
> + const CXXCastPath *BasePath = 0) {
> + Expr *E = ExprRes.take();
> + ImpCastExprToType(E, Type, CK, VK, BasePath);
> + ExprRes = Owned(E);
> + }
Same here.
> /// IgnoredValueConversions - Given that an expression's result is
> /// syntactically ignored, perform any conversions that are
> /// required.
> - void IgnoredValueConversions(Expr *&expr);
> + void IgnoredValueConversions(ExprResult &expr);
>
> // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
> // functions and arrays to their respective pointers (C99 6.3.2.1).
> - Expr *UsualUnaryConversions(Expr *&expr);
> + void UsualUnaryConversions(ExprResult &expr);
>
> // DefaultFunctionArrayConversion - converts functions and arrays
> // to their respective pointers (C99 6.3.2.1).
> - void DefaultFunctionArrayConversion(Expr *&expr);
> + void DefaultFunctionArrayConversion(ExprResult &expr);
>
> // DefaultFunctionArrayLvalueConversion - converts functions and
> // arrays to their respective pointers and performs the
> // lvalue-to-rvalue conversion.
> - void DefaultFunctionArrayLvalueConversion(Expr *&expr);
> + void DefaultFunctionArrayLvalueConversion(ExprResult &expr);
>
> // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
> // the operand. This is DefaultFunctionArrayLvalueConversion,
> // except that it assumes the operand isn't of function or array
> // type.
> - void DefaultLvalueConversion(Expr *&expr);
> + void DefaultLvalueConversion(ExprResult &expr);
>
> // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
> // do not have a prototype. Integer promotions are performed on each
> // argument, and arguments that have type float are promoted to double.
> - void DefaultArgumentPromotion(Expr *&Expr);
> + void DefaultArgumentPromotion(ExprResult &Expr);
>
> // Used for emitting the right warning by DefaultVariadicArgumentPromotion
> enum VariadicCallType {
> @@ -4766,7 +4774,7 @@ public:
>
> // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
> // will warn if the resulting type is not a POD type.
> - bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT,
> + bool DefaultVariadicArgumentPromotion(ExprResult &ExprRes, VariadicCallType CT,
> FunctionDecl *FDecl);
Same for all of these.
> - bool PerformImplicitConversion(Expr *&From, QualType ToType,
> + bool PerformImplicitConversion(ExprResult &From, QualType ToType,
> AssignmentAction Action,
> bool AllowExplicit = false);
> - bool PerformImplicitConversion(Expr *&From, QualType ToType,
> + bool PerformImplicitConversion(ExprResult &From, QualType ToType,
> AssignmentAction Action,
> bool AllowExplicit,
> ImplicitConversionSequence& ICS);
> - bool PerformImplicitConversion(Expr *&From, QualType ToType,
> + bool PerformImplicitConversion(ExprResult &From, QualType ToType,
> const ImplicitConversionSequence& ICS,
> AssignmentAction Action,
> bool CStyle = false);
> - bool PerformImplicitConversion(Expr *&From, QualType ToType,
> + bool PerformImplicitConversion(ExprResult &From, QualType ToType,
> const StandardConversionSequence& SCS,
> AssignmentAction Action,
> bool CStyle);
Same for all of these.
> + void ConvertPropertyForRValue(ExprResult &E);
And this one.
>
> @@ -4987,7 +5003,7 @@ public:
>
> /// CheckCastTypes - Check type constraints for casting between types under
> /// C semantics, or forward to CXXCheckCStyleCast in C++.
> - bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr,
> + bool CheckCastTypes(SourceRange TyRange, QualType CastTy, ExprResult &CastExpr,
> CastKind &Kind, ExprValueKind &VK, CXXCastPath &BasePath,
> bool FunctionalStyle = false);
>
> @@ -5003,13 +5019,13 @@ public:
> // We allow casting between vectors and integer datatypes of the same size,
> // or vectors and the element type of that vector.
> // returns true if the cast is invalid
> - bool CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *&CastExpr,
> + bool CheckExtVectorCast(SourceRange R, QualType VectorTy, ExprResult &CastExpr,
> CastKind &Kind);
>
> /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
> /// cast under C++ semantics.
> bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK,
> - Expr *&CastExpr, CastKind &Kind,
> + ExprResult &CastExpr, CastKind &Kind,
> CXXCastPath &BasePath, bool FunctionalStyle);
> /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
> @@ -5029,7 +5045,7 @@ public:
> /// \param Loc - A location associated with the condition, e.g. the
> /// 'if' keyword.
> /// \return true iff there were any errors
> - bool CheckBooleanCondition(Expr *&CondExpr, SourceLocation Loc);
> + bool CheckBooleanCondition(ExprResult &CondExpr, SourceLocation Loc);
>
> ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
> Expr *SubExpr);
> @@ -5043,7 +5059,7 @@ public:
> void DiagnoseEqualityWithExtraParens(ParenExpr *parenE);
>
> /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
> - bool CheckCXXBooleanCondition(Expr *&CondExpr);
> + bool CheckCXXBooleanCondition(ExprResult &CondExpr);
And these.
- Doug
More information about the cfe-commits
mailing list