summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExprCXX.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-05-01 07:44:20 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-05-01 07:44:20 +0000
commit20b9bc86381580b9505536345f3d55ed7b41fee0 (patch)
tree815dbd981207aa3f76b1494d4608a800f09dee26 /clang/lib/Sema/SemaExprCXX.cpp
parentb42fb19e9b7381375b214324730566fb53114522 (diff)
downloadbcm5719-llvm-20b9bc86381580b9505536345f3d55ed7b41fee0.tar.gz
bcm5719-llvm-20b9bc86381580b9505536345f3d55ed7b41fee0.zip
Convert the expression trait evaluation to a static function and
a switch with any default case. This both warns when an enumerator is missing and asserts if a value sneaks through despite the warning. While in there fix a bunch of coding style issues with this code. llvm-svn: 130648
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r--clang/lib/Sema/SemaExprCXX.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4d5074a13b7..acbe4154caf 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2751,7 +2751,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, UnaryTypeTrait UTT,
llvm_unreachable("Type trait not covered by switch");
}
-
ExprResult Sema::BuildUnaryTypeTrait(UnaryTypeTrait UTT,
SourceLocation KWLoc,
TypeSourceInfo *TSInfo,
@@ -3016,23 +3015,30 @@ ExprResult Sema::BuildArrayTypeTrait(ArrayTypeTrait ATT,
}
ExprResult Sema::ActOnExpressionTrait(ExpressionTrait ET,
- SourceLocation KWLoc,
- Expr* Queried,
- SourceLocation RParen) {
+ SourceLocation KWLoc,
+ Expr *Queried,
+ SourceLocation RParen) {
// If error parsing the expression, ignore.
if (!Queried)
- return ExprError();
+ return ExprError();
- ExprResult Result
- = BuildExpressionTrait(ET, KWLoc, Queried, RParen);
+ ExprResult Result = BuildExpressionTrait(ET, KWLoc, Queried, RParen);
return move(Result);
}
+static bool EvaluateExpressionTrait(ExpressionTrait ET, Expr *E) {
+ switch (ET) {
+ case ET_IsLValueExpr: return E->isLValue();
+ case ET_IsRValueExpr: return E->isRValue();
+ }
+ llvm_unreachable("Expression trait not covered by switch");
+}
+
ExprResult Sema::BuildExpressionTrait(ExpressionTrait ET,
- SourceLocation KWLoc,
- Expr* Queried,
- SourceLocation RParen) {
+ SourceLocation KWLoc,
+ Expr *Queried,
+ SourceLocation RParen) {
if (Queried->isTypeDependent()) {
// Delay type-checking for type-dependent expressions.
} else if (Queried->getType()->isPlaceholderType()) {
@@ -3041,17 +3047,10 @@ ExprResult Sema::BuildExpressionTrait(ExpressionTrait ET,
return BuildExpressionTrait(ET, KWLoc, PE.take(), RParen);
}
- bool Value = false;
- switch (ET) {
- default: llvm_unreachable("Unknown or unimplemented expression trait");
- case ET_IsLValueExpr: Value = Queried->isLValue(); break;
- case ET_IsRValueExpr: Value = Queried->isRValue(); break;
- }
-
+ bool Value = EvaluateExpressionTrait(ET, Queried);
// C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
- return Owned(
- new (Context) ExpressionTraitExpr(
- KWLoc, ET, Queried, Value, RParen, Context.BoolTy));
+ return Owned(new (Context) ExpressionTraitExpr(KWLoc, ET, Queried, Value,
+ RParen, Context.BoolTy));
}
QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex,
OpenPOWER on IntegriCloud