Show lifetime kind in output (#3285)

This commit is contained in:
Paul Fultz II 2021-06-04 14:41:30 -05:00 committed by GitHub
parent 668b88d7c0
commit f90b05ea7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View File

@ -1773,7 +1773,8 @@ void Token::printValueFlow(bool xml, std::ostream &out) const
out << "end=" << value.intvalue;
break;
case ValueFlow::Value::ValueType::LIFETIME:
out << "lifetime=" << "(" << value.tokvalue->expressionString() << ")";
out << "lifetime[" << ValueFlow::Value::toString(value.lifetimeKind) << "]=("
<< value.tokvalue->expressionString() << ")";
break;
}
if (value.indirect > 0)

View File

@ -6916,6 +6916,22 @@ const char* ValueFlow::Value::toString(MoveKind moveKind)
return "";
}
const char* ValueFlow::Value::toString(LifetimeKind lifetimeKind)
{
switch (lifetimeKind) {
case LifetimeKind::Object:
return "Object";
case LifetimeKind::SubObject:
return "SubObject";
case LifetimeKind::Lambda:
return "Lambda";
case LifetimeKind::Iterator:
return "Iterator";
case LifetimeKind::Address:
return "Address";
}
return "";
}
const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(Token *expr, const Settings *settings)
{

View File

@ -323,11 +323,23 @@ namespace ValueFlow {
/** int value before implicit truncation */
long long wideintvalue;
enum class LifetimeKind {Object, SubObject, Lambda, Iterator, Address} lifetimeKind;
enum class LifetimeKind {
// Pointer points to a member of lifetime
Object,
// A member of object points to the lifetime
SubObject,
// Lambda has captured lifetime(similiar to SubObject)
Lambda,
// Iterator points to the lifetime of a container(similiar to Object)
Iterator,
// A pointer that holds the address of the lifetime
Address
} lifetimeKind;
enum class LifetimeScope { Local, Argument, SubFunction } lifetimeScope;
static const char* toString(MoveKind moveKind);
static const char* toString(LifetimeKind lifetimeKind);
/** How known is this value */
enum class ValueKind {