[cfe-commits] r54102 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/ASTContext.cpp lib/AST/Expr.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaStmt.cpp

Chris Lattner sabre at nondot.org
Sat Jul 26 14:30:37 PDT 2008


Author: lattner
Date: Sat Jul 26 16:30:36 2008
New Revision: 54102

URL: http://llvm.org/viewvc/llvm-project?rev=54102&view=rev
Log:
convert more code to use ASTContext to get canonical types instead
of doing it directly.  This is required for PR2189.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=54102&r1=54101&r2=54102&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jul 26 16:30:36 2008
@@ -74,7 +74,7 @@
     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 @@
     MLV_ConstQualified,
     MLV_ArrayType
   };
-  isModifiableLvalueResult isModifiableLvalue() const;
+  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const;
   
   bool isNullPointerConstant(ASTContext &Ctx) const;
 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=54102&r1=54101&r2=54102&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Jul 26 16:30:36 2008
@@ -1542,15 +1542,15 @@
       lhs.getAddressSpace() != rhs.getAddressSpace())
     return false;
     
-  QualType ltype = cast<PointerType>(lhs.getCanonicalType())->getPointeeType();
-  QualType rtype = cast<PointerType>(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<FunctionType>(lhs.getCanonicalType());
-  const FunctionType *rbase = cast<FunctionType>(rhs.getCanonicalType());
+  const FunctionType *lbase = lhs->getAsFunctionType();
+  const FunctionType *rbase = rhs->getAsFunctionType();
   const FunctionTypeProto *lproto = dyn_cast<FunctionTypeProto>(lbase);
   const FunctionTypeProto *rproto = dyn_cast<FunctionTypeProto>(rbase);
 
@@ -1673,8 +1673,8 @@
 /// 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

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=54102&r1=54101&r2=54102&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sat Jul 26 16:30:36 2008
@@ -387,13 +387,13 @@
 ///  - (__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 @@
   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<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
-      return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue();
+      return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(Ctx);
     return LV_Valid;
   case DeclRefExprClass: { // C99 6.5.1p2
     const Decl *RefdDecl = cast<DeclRefExpr>(this)->getDecl();
@@ -416,7 +416,7 @@
   }
   case MemberExprClass: { // C99 6.5.2.3p4
     const MemberExpr *m = cast<MemberExpr>(this);
-    return m->isArrow() ? LV_Valid : m->getBase()->isLvalue();
+    return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
   }
   case UnaryOperatorClass:
     if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
@@ -425,10 +425,10 @@
     if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
         cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag ||
         cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension)
-      return cast<UnaryOperator>(this)->getSubExpr()->isLvalue();  // GNU.
+      return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx);  // GNU.
     break;
   case ParenExprClass: // C99 6.5.1p5
-    return cast<ParenExpr>(this)->getSubExpr()->isLvalue();
+    return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx);
   case CompoundLiteralExprClass: // C99 6.5.2.5p5
     return LV_Valid;
   case ExtVectorElementExprClass:
@@ -444,7 +444,7 @@
                == PreDefinedExpr::CXXThis
             ? LV_InvalidExpression : LV_Valid);
   case CXXDefaultArgExprClass:
-    return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue();
+    return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue(Ctx);
   default:
     break;
   }
@@ -456,8 +456,8 @@
 /// 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 @@
   if (TR->isIncompleteType())
     return MLV_IncompleteType;
     
-  if (const RecordType *r = dyn_cast<RecordType>(TR.getCanonicalType())) {
+  if (const RecordType *r = TR->getAsRecordType()) {
     if (r->hasConstFields()) 
       return MLV_ConstQualified;
   }

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=54102&r1=54101&r2=54102&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Jul 26 16:30:36 2008
@@ -50,7 +50,7 @@
     // 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 @@
 {
   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 @@
   }
   // 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 @@
     // 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<FunctionDecl>(dcl)) {// allow function designators

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=54102&r1=54101&r2=54102&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sat Jul 26 16:30:36 2008
@@ -712,7 +712,7 @@
     
     // 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<ParenExpr>(OutputExpr);
       





More information about the cfe-commits mailing list