[cfe-commits] r58242 - in /cfe/trunk/lib/Sema: Sema.h SemaDecl.cpp

Daniel Dunbar daniel at zuster.org
Mon Oct 27 07:32:20 PDT 2008


Some places (although not all), we use a pattern where
InitializerElementNotConstant returns true, and its clients can just write
'return InitializerElementNotConstant'. This would simplify the code a bit
more (assuming you like the pattern).

 - Daniel

On Mon, Oct 27, 2008 at 4:34 AM, Steve Naroff <snaroff at apple.com> wrote:

> Author: snaroff
> Date: Mon Oct 27 06:34:16 2008
> New Revision: 58242
>
> URL: http://llvm.org/viewvc/llvm-project?rev=58242&view=rev
> Log:
> Replace common diagnostic with a convenience function.
> This simplifies debug of this particular diagnostic (and removes some code
> clutter).
>
> Modified:
>    cfe/trunk/lib/Sema/Sema.h
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=58242&r1=58241&r2=58242&view=diff
>
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Mon Oct 27 06:34:16 2008
> @@ -1106,6 +1106,7 @@
>   bool CheckArithmeticConstantExpression(const Expr* e);
>   bool CheckAddressConstantExpression(const Expr* e);
>   bool CheckAddressConstantExpressionLValue(const Expr* e);
> +  void InitializerElementNotConstant(const Expr *e);
>
>   StringLiteral *IsStringLiteralInit(Expr *Init, QualType DeclType);
>   bool CheckStringLiteralInit(StringLiteral *strLiteral, QualType &DeclT);
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=58242&r1=58241&r2=58242&view=diff
>
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Oct 27 06:34:16 2008
> @@ -957,11 +957,15 @@
>   return New;
>  }
>
> +void Sema::InitializerElementNotConstant(const Expr *Init) {
> +  Diag(Init->getExprLoc(),
> +       diag::err_init_element_not_constant, Init->getSourceRange());
> +}
> +
>  bool Sema::CheckAddressConstantExpressionLValue(const Expr* Init) {
>   switch (Init->getStmtClass()) {
>   default:
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   case Expr::ParenExprClass: {
>     const ParenExpr* PE = cast<ParenExpr>(Init);
> @@ -974,14 +978,12 @@
>     if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
>       if (VD->hasGlobalStorage())
>         return false;
> -      Diag(Init->getExprLoc(),
> -           diag::err_init_element_not_constant, Init->getSourceRange());
> +      InitializerElementNotConstant(Init);
>       return true;
>     }
>     if (isa<FunctionDecl>(D))
>       return false;
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   }
>   case Expr::MemberExprClass: {
> @@ -1006,8 +1008,7 @@
>     if (Exp->getOpcode() == UnaryOperator::Deref)
>       return CheckAddressConstantExpression(Exp->getSubExpr());
>
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   }
>   }
> @@ -1016,8 +1017,7 @@
>  bool Sema::CheckAddressConstantExpression(const Expr* Init) {
>   switch (Init->getStmtClass()) {
>   default:
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   case Expr::ParenExprClass:
>     return
> CheckAddressConstantExpression(cast<ParenExpr>(Init)->getSubExpr());
> @@ -1030,8 +1030,7 @@
>            Builtin::BI__builtin___CFStringMakeConstantString)
>       return false;
>
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>
>   case Expr::UnaryOperatorClass: {
> @@ -1044,8 +1043,7 @@
>     if (Exp->getOpcode() == UnaryOperator::Extension)
>       return CheckAddressConstantExpression(Exp->getSubExpr());
>
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   }
>   case Expr::BinaryOperatorClass: {
> @@ -1093,16 +1091,14 @@
>       return CheckArithmeticConstantExpression(SubExpr);
>     }
>
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   }
>   case Expr::ConditionalOperatorClass: {
>     // FIXME: Should we pedwarn here?
>     const ConditionalOperator *Exp = cast<ConditionalOperator>(Init);
>     if (!Exp->getCond()->getType()->isArithmeticType()) {
> -      Diag(Init->getExprLoc(),
> -           diag::err_init_element_not_constant, Init->getSourceRange());
> +      InitializerElementNotConstant(Init);
>       return true;
>     }
>     if (CheckArithmeticConstantExpression(Exp->getCond()))
> @@ -1211,8 +1207,7 @@
>  bool Sema::CheckArithmeticConstantExpression(const Expr* Init) {
>   switch (Init->getStmtClass()) {
>   default:
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   case Expr::ParenExprClass: {
>     const ParenExpr* PE = cast<ParenExpr>(Init);
> @@ -1232,16 +1227,14 @@
>     if (CE->isBuiltinCall() && CE->isEvaluatable(Context))
>       return false;
>
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   }
>   case Expr::DeclRefExprClass: {
>     const Decl *D = cast<DeclRefExpr>(Init)->getDecl();
>     if (isa<EnumConstantDecl>(D))
>       return false;
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   }
>   case Expr::CompoundLiteralExprClass:
> @@ -1249,8 +1242,7 @@
>     // but vectors are allowed to be magic.
>     if (Init->getType()->isVectorType())
>       return false;
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   case Expr::UnaryOperatorClass: {
>     const UnaryOperator *Exp = cast<UnaryOperator>(Init);
> @@ -1259,8 +1251,7 @@
>     // Address, indirect, pre/post inc/dec, etc are not valid constant
> exprs.
>     // See C99 6.6p3.
>     default:
> -      Diag(Init->getExprLoc(),
> -           diag::err_init_element_not_constant, Init->getSourceRange());
> +      InitializerElementNotConstant(Init);
>       return true;
>     case UnaryOperator::SizeOf:
>     case UnaryOperator::AlignOf:
> @@ -1269,8 +1260,7 @@
>       // See C99 6.5.3.4p2 and 6.6p3.
>       if (Exp->getSubExpr()->getType()->isConstantSizeType())
>         return false;
> -      Diag(Init->getExprLoc(),
> -           diag::err_init_element_not_constant, Init->getSourceRange());
> +      InitializerElementNotConstant(Init);
>       return true;
>     case UnaryOperator::Extension:
>     case UnaryOperator::LNot:
> @@ -1288,8 +1278,7 @@
>     // alignof always evaluates to a constant.
>     // FIXME: is sizeof(int[3.0]) a constant expression?
>     if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType()) {
> -      Diag(Init->getExprLoc(),
> -           diag::err_init_element_not_constant, Init->getSourceRange());
> +      InitializerElementNotConstant(Init);
>       return true;
>     }
>     return false;
> @@ -1317,8 +1306,7 @@
>       }
>     }
>
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   }
>   case Expr::ImplicitCastExprClass:
> @@ -1334,8 +1322,7 @@
>         return CheckAddressConstantExpression(SubExpr);
>     }
>
> -    Diag(Init->getExprLoc(),
> -         diag::err_init_element_not_constant, Init->getSourceRange());
> +    InitializerElementNotConstant(Init);
>     return true;
>   }
>   case Expr::ConditionalOperatorClass: {
> @@ -1466,8 +1453,7 @@
>   if (Init->getType()->isBlockPointerType())
>     return false;
>
> -  Diag(Init->getExprLoc(), diag::err_init_element_not_constant,
> -       Init->getSourceRange());
> +  InitializerElementNotConstant(Init);
>   return true;
>  }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20081027/3b0df6bc/attachment.html>


More information about the cfe-commits mailing list