From: Chris Lattner Date: Sat, 26 Jul 2008 21:30:36 +0000 (+0000) Subject: convert more code to use ASTContext to get canonical types instead X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28be73f74c9e241a23ea24fe5756623de6bf1084;p=clang convert more code to use ASTContext to get canonical types instead of doing it directly. This is required for PR2189. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54102 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 5569bb6c73..5d8cd43ac3 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -74,7 +74,7 @@ public: LV_DuplicateVectorComponents, LV_InvalidExpression }; - isLvalueResult isLvalue() const; + isLvalueResult isLvalue(ASTContext &Ctx) const; /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, /// does not have an incomplete type, does not have a const-qualified type, @@ -91,7 +91,7 @@ public: MLV_ConstQualified, MLV_ArrayType }; - isModifiableLvalueResult isModifiableLvalue() const; + isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const; bool isNullPointerConstant(ASTContext &Ctx) const; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index dedc9b8376..47a3e3ac67 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1542,15 +1542,15 @@ bool ASTContext::pointerTypesAreCompatible(QualType lhs, QualType rhs) { lhs.getAddressSpace() != rhs.getAddressSpace()) return false; - QualType ltype = cast(lhs.getCanonicalType())->getPointeeType(); - QualType rtype = cast(rhs.getCanonicalType())->getPointeeType(); + QualType ltype = lhs->getAsPointerType()->getPointeeType(); + QualType rtype = rhs->getAsPointerType()->getPointeeType(); return typesAreCompatible(ltype, rtype); } bool ASTContext::functionTypesAreCompatible(QualType lhs, QualType rhs) { - const FunctionType *lbase = cast(lhs.getCanonicalType()); - const FunctionType *rbase = cast(rhs.getCanonicalType()); + const FunctionType *lbase = lhs->getAsFunctionType(); + const FunctionType *rbase = rhs->getAsFunctionType(); const FunctionTypeProto *lproto = dyn_cast(lbase); const FunctionTypeProto *rproto = dyn_cast(rbase); @@ -1673,8 +1673,8 @@ static bool areCompatObjCInterfaces(const ObjCInterfaceType *LHS, /// C99 6.2.7p1: Two types have compatible types if their types are the /// same. See 6.7.[2,3,5] for additional rules. bool ASTContext::typesAreCompatible(QualType LHS_NC, QualType RHS_NC) { - QualType LHS = LHS_NC.getCanonicalType(); - QualType RHS = RHS_NC.getCanonicalType(); + QualType LHS = getCanonicalType(LHS_NC); + QualType RHS = getCanonicalType(RHS_NC); // C++ [expr]: If an expression initially has the type "reference to T", the // type is adjusted to "T" prior to any further analysis, the expression diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index d31bde283b..60b762f66d 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -387,13 +387,13 @@ bool Expr::hasLocalSideEffect() const { /// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension] /// - reference type [C++ [expr]] /// -Expr::isLvalueResult Expr::isLvalue() const { +Expr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const { // first, check the type (C99 6.3.2.1) if (TR->isFunctionType()) // from isObjectType() return LV_NotObjectType; // Allow qualified void which is an incomplete type other than void (yuck). - if (TR->isVoidType() && !TR.getCanonicalType().getCVRQualifiers()) + if (TR->isVoidType() && !Ctx.getCanonicalType(TR).getCVRQualifiers()) return LV_IncompleteVoidType; if (TR->isReferenceType()) // C++ [expr] @@ -406,7 +406,7 @@ Expr::isLvalueResult Expr::isLvalue() const { case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2)))) // For vectors, make sure base is an lvalue (i.e. not a function call). if (cast(this)->getBase()->getType()->isVectorType()) - return cast(this)->getBase()->isLvalue(); + return cast(this)->getBase()->isLvalue(Ctx); return LV_Valid; case DeclRefExprClass: { // C99 6.5.1p2 const Decl *RefdDecl = cast(this)->getDecl(); @@ -416,7 +416,7 @@ Expr::isLvalueResult Expr::isLvalue() const { } case MemberExprClass: { // C99 6.5.2.3p4 const MemberExpr *m = cast(this); - return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(); + return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx); } case UnaryOperatorClass: if (cast(this)->getOpcode() == UnaryOperator::Deref) @@ -425,10 +425,10 @@ Expr::isLvalueResult Expr::isLvalue() const { if (cast(this)->getOpcode() == UnaryOperator::Real || cast(this)->getOpcode() == UnaryOperator::Imag || cast(this)->getOpcode() == UnaryOperator::Extension) - return cast(this)->getSubExpr()->isLvalue(); // GNU. + return cast(this)->getSubExpr()->isLvalue(Ctx); // GNU. break; case ParenExprClass: // C99 6.5.1p5 - return cast(this)->getSubExpr()->isLvalue(); + return cast(this)->getSubExpr()->isLvalue(Ctx); case CompoundLiteralExprClass: // C99 6.5.2.5p5 return LV_Valid; case ExtVectorElementExprClass: @@ -444,7 +444,7 @@ Expr::isLvalueResult Expr::isLvalue() const { == PreDefinedExpr::CXXThis ? LV_InvalidExpression : LV_Valid); case CXXDefaultArgExprClass: - return cast(this)->getExpr()->isLvalue(); + return cast(this)->getExpr()->isLvalue(Ctx); default: break; } @@ -456,8 +456,8 @@ Expr::isLvalueResult Expr::isLvalue() const { /// if it is a structure or union, does not have any member (including, /// recursively, any member or element of all contained aggregates or unions) /// with a const-qualified type. -Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const { - isLvalueResult lvalResult = isLvalue(); +Expr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const { + isLvalueResult lvalResult = isLvalue(Ctx); switch (lvalResult) { case LV_Valid: break; @@ -473,7 +473,7 @@ Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const { if (TR->isIncompleteType()) return MLV_IncompleteType; - if (const RecordType *r = dyn_cast(TR.getCanonicalType())) { + if (const RecordType *r = TR->getAsRecordType()) { if (r->hasConstFields()) return MLV_ConstQualified; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index bb5ed509e5..d69a0dc061 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -50,7 +50,7 @@ void Sema::DefaultFunctionArrayConversion(Expr *&E) { // to type'...". In C99 this was changed to: C99 6.3.2.1p3: "an expression // that has type 'array of type' ...". The relevant change is "an lvalue" // (C90) to "an expression" (C99). - if (getLangOptions().C99 || E->isLvalue() == Expr::LV_Valid) + if (getLangOptions().C99 || E->isLvalue(Context) == Expr::LV_Valid) ImpCastExprToType(E, Context.getArrayDecayedType(Ty)); } } @@ -1864,7 +1864,7 @@ inline QualType Sema::CheckAssignmentOperands( // C99 6.5.16.1 { QualType lhsType = lex->getType(); QualType rhsType = compoundType.isNull() ? rex->getType() : compoundType; - Expr::isModifiableLvalueResult mlval = lex->isModifiableLvalue(); + Expr::isModifiableLvalueResult mlval = lex->isModifiableLvalue(Context); switch (mlval) { // C99 6.5.16p2 case Expr::MLV_Valid: @@ -1952,7 +1952,7 @@ QualType Sema::CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc) { } // At this point, we know we have a real, complex or pointer type. // Now make sure the operand is a modifiable lvalue. - Expr::isModifiableLvalueResult mlval = op->isModifiableLvalue(); + Expr::isModifiableLvalueResult mlval = op->isModifiableLvalue(Context); if (mlval != Expr::MLV_Valid) { // FIXME: emit a more precise diagnostic... Diag(OpLoc, diag::err_typecheck_invalid_lvalue_incr_decr, @@ -2015,7 +2015,7 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { // expressions here, but the result of one is always an lvalue anyway. } ValueDecl *dcl = getPrimaryDecl(op); - Expr::isLvalueResult lval = op->isLvalue(); + Expr::isLvalueResult lval = op->isLvalue(Context); if (lval != Expr::LV_Valid) { // C99 6.5.3.2p1 if (!dcl || !isa(dcl)) {// allow function designators diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index a4e8946b45..e743810ed4 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -712,7 +712,7 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, // Check that the output exprs are valid lvalues. Expr *OutputExpr = (Expr *)Exprs[i]; - Expr::isLvalueResult Result = OutputExpr->isLvalue(); + Expr::isLvalueResult Result = OutputExpr->isLvalue(Context); if (Result != Expr::LV_Valid) { ParenExpr *PE = cast(OutputExpr);