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
This commit is contained in:
parent
b42fb19e9b
commit
20b9bc8638
|
@ -2751,7 +2751,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, UnaryTypeTrait UTT,
|
||||||
llvm_unreachable("Type trait not covered by switch");
|
llvm_unreachable("Type trait not covered by switch");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ExprResult Sema::BuildUnaryTypeTrait(UnaryTypeTrait UTT,
|
ExprResult Sema::BuildUnaryTypeTrait(UnaryTypeTrait UTT,
|
||||||
SourceLocation KWLoc,
|
SourceLocation KWLoc,
|
||||||
TypeSourceInfo *TSInfo,
|
TypeSourceInfo *TSInfo,
|
||||||
|
@ -3017,21 +3016,28 @@ ExprResult Sema::BuildArrayTypeTrait(ArrayTypeTrait ATT,
|
||||||
|
|
||||||
ExprResult Sema::ActOnExpressionTrait(ExpressionTrait ET,
|
ExprResult Sema::ActOnExpressionTrait(ExpressionTrait ET,
|
||||||
SourceLocation KWLoc,
|
SourceLocation KWLoc,
|
||||||
Expr* Queried,
|
Expr *Queried,
|
||||||
SourceLocation RParen) {
|
SourceLocation RParen) {
|
||||||
// If error parsing the expression, ignore.
|
// If error parsing the expression, ignore.
|
||||||
if (!Queried)
|
if (!Queried)
|
||||||
return ExprError();
|
return ExprError();
|
||||||
|
|
||||||
ExprResult Result
|
ExprResult Result = BuildExpressionTrait(ET, KWLoc, Queried, RParen);
|
||||||
= BuildExpressionTrait(ET, KWLoc, Queried, RParen);
|
|
||||||
|
|
||||||
return move(Result);
|
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,
|
ExprResult Sema::BuildExpressionTrait(ExpressionTrait ET,
|
||||||
SourceLocation KWLoc,
|
SourceLocation KWLoc,
|
||||||
Expr* Queried,
|
Expr *Queried,
|
||||||
SourceLocation RParen) {
|
SourceLocation RParen) {
|
||||||
if (Queried->isTypeDependent()) {
|
if (Queried->isTypeDependent()) {
|
||||||
// Delay type-checking for type-dependent expressions.
|
// Delay type-checking for type-dependent expressions.
|
||||||
|
@ -3041,17 +3047,10 @@ ExprResult Sema::BuildExpressionTrait(ExpressionTrait ET,
|
||||||
return BuildExpressionTrait(ET, KWLoc, PE.take(), RParen);
|
return BuildExpressionTrait(ET, KWLoc, PE.take(), RParen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value = false;
|
bool Value = EvaluateExpressionTrait(ET, Queried);
|
||||||
switch (ET) {
|
|
||||||
default: llvm_unreachable("Unknown or unimplemented expression trait");
|
|
||||||
case ET_IsLValueExpr: Value = Queried->isLValue(); break;
|
|
||||||
case ET_IsRValueExpr: Value = Queried->isRValue(); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
|
// C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
|
||||||
return Owned(
|
return Owned(new (Context) ExpressionTraitExpr(KWLoc, ET, Queried, Value,
|
||||||
new (Context) ExpressionTraitExpr(
|
RParen, Context.BoolTy));
|
||||||
KWLoc, ET, Queried, Value, RParen, Context.BoolTy));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex,
|
QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex,
|
||||||
|
|
Loading…
Reference in New Issue