[cfe-commits] r59483 - /cfe/trunk/lib/Sema/SemaExpr.cpp

Chris Lattner sabre at nondot.org
Mon Nov 17 17:22:50 PST 2008


Author: lattner
Date: Mon Nov 17 19:22:49 2008
New Revision: 59483

URL: http://llvm.org/viewvc/llvm-project?rev=59483&view=rev
Log:
factor some code out into a helper function

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Nov 17 19:22:49 2008
@@ -2328,50 +2328,64 @@
   return InvalidOperands(loc, lex, rex);
 }
 
-inline QualType Sema::CheckAssignmentOperands( // C99 6.5.16.1
-  Expr *lex, Expr *&rex, SourceLocation loc, QualType compoundType) 
-{
-  QualType lhsType = lex->getType();
-  QualType rhsType = compoundType.isNull() ? rex->getType() : compoundType;
-  Expr::isModifiableLvalueResult mlval = lex->isModifiableLvalue(Context); 
-
-  switch (mlval) { // C99 6.5.16p2
-  case Expr::MLV_Valid: 
-    break;
-  case Expr::MLV_ConstQualified:
-    Diag(loc, diag::err_typecheck_assign_const, lex->getSourceRange());
-    return QualType();
+/// CheckForModifiableLvalue - Verify that E is a modifiable lvalue.  If not,
+/// emit an error and return true.  If so, return false.
+static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
+  Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context); 
+  if (IsLV == Expr::MLV_Valid)
+    return false;
+  
+  unsigned Diag = 0;
+  bool NeedType = false;
+  switch (IsLV) { // C99 6.5.16p2
+  default: assert(0 && "Unknown result from isModifiableLvalue!");
+  case Expr::MLV_ConstQualified: Diag = diag::err_typecheck_assign_const; break;
   case Expr::MLV_ArrayType: 
-    Diag(loc, diag::err_typecheck_array_not_modifiable_lvalue,
-         lhsType.getAsString(), lex->getSourceRange());
-    return QualType(); 
+    Diag = diag::err_typecheck_array_not_modifiable_lvalue;
+    NeedType = true;
+    break;
   case Expr::MLV_NotObjectType: 
-    Diag(loc, diag::err_typecheck_non_object_not_modifiable_lvalue,
-         lhsType.getAsString(), lex->getSourceRange());
-    return QualType();
+    Diag = diag::err_typecheck_non_object_not_modifiable_lvalue;
+    NeedType = true;
+    break;
   case Expr::MLV_LValueCast:
-    Diag(loc, diag::err_typecheck_lvalue_casts_not_supported, 
-         lex->getSourceRange());
-    return QualType();
+    Diag = diag::err_typecheck_lvalue_casts_not_supported;
+    break;
   case Expr::MLV_InvalidExpression:
-    Diag(loc, diag::err_typecheck_expression_not_modifiable_lvalue,
-         lex->getSourceRange());
-    return QualType();
+    Diag = diag::err_typecheck_expression_not_modifiable_lvalue;
+    break;
   case Expr::MLV_IncompleteType:
   case Expr::MLV_IncompleteVoidType:
-    Diag(loc, diag::err_typecheck_incomplete_type_not_modifiable_lvalue,
-         lhsType.getAsString(), lex->getSourceRange());
-    return QualType();
+    Diag = diag::err_typecheck_incomplete_type_not_modifiable_lvalue;
+    NeedType = true;
+    break;
   case Expr::MLV_DuplicateVectorComponents:
-    Diag(loc, diag::err_typecheck_duplicate_vector_components_not_mlvalue,
-         lex->getSourceRange());
-    return QualType();
+    Diag = diag::err_typecheck_duplicate_vector_components_not_mlvalue;
+    break;
   case Expr::MLV_NotBlockQualified:
-    Diag(loc, diag::err_block_decl_ref_not_modifiable_lvalue,
-         lex->getSourceRange());
-    return QualType();
+    Diag = diag::err_block_decl_ref_not_modifiable_lvalue;
+    break;
   }
 
+  if (NeedType)
+    S.Diag(Loc, Diag, E->getType().getAsString(), SR);
+  else
+    S.Diag(Loc, Diag, E->getSourceRange());
+  return true;
+}
+
+
+
+// C99 6.5.16.1
+QualType Sema::CheckAssignmentOperands(Expr *lex, Expr *&rex,SourceLocation loc,
+                                       QualType compoundType) {
+  QualType lhsType = lex->getType();
+  QualType rhsType = compoundType.isNull() ? rex->getType() : compoundType;
+
+  // Verify that lex is a modifiable lvalue, and emit error if not.
+  if (CheckForModifiableLvalue(lex, loc, *this))
+    return QualType();
+  
   AssignConvertType ConvTy;
   if (compoundType.isNull()) {
     // Simple assignment "x = y".





More information about the cfe-commits mailing list