[clang][dataflow] Debug string for value kinds.

Differential Revision: https://reviews.llvm.org/D131891
This commit is contained in:
Wei Yi Tee 2022-08-16 12:34:42 +00:00
parent bd5cc6575b
commit dbb95c2a85
2 changed files with 35 additions and 4 deletions

View File

@ -20,15 +20,19 @@
#include "clang/Analysis/FlowSensitive/Solver.h"
#include "clang/Analysis/FlowSensitive/Value.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"
namespace clang {
namespace dataflow {
/// Returns a string representation of a value kind.
llvm::StringRef debugString(Value::Kind Kind);
/// Returns a string representation of a boolean assignment to true or false.
std::string debugString(Solver::Result::Assignment Assignment);
llvm::StringRef debugString(Solver::Result::Assignment Assignment);
/// Returns a string representation of the result status of a SAT check.
std::string debugString(Solver::Result::Status Status);
llvm::StringRef debugString(Solver::Result::Status Status);
/// Returns a string representation for the boolean value `B`.
///

View File

@ -18,6 +18,7 @@
#include "clang/Analysis/FlowSensitive/Value.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatAdapters.h"
@ -31,7 +32,33 @@ using llvm::AlignStyle;
using llvm::fmt_pad;
using llvm::formatv;
std::string debugString(Solver::Result::Assignment Assignment) {
llvm::StringRef debugString(Value::Kind Kind) {
switch (Kind) {
case Value::Kind::Integer:
return "Integer";
case Value::Kind::Reference:
return "Reference";
case Value::Kind::Pointer:
return "Pointer";
case Value::Kind::Struct:
return "Struct";
case Value::Kind::AtomicBool:
return "AtomicBool";
case Value::Kind::Conjunction:
return "Conjunction";
case Value::Kind::Disjunction:
return "Disjunction";
case Value::Kind::Negation:
return "Negation";
case Value::Kind::Implication:
return "Implication";
case Value::Kind::Biconditional:
return "Biconditional";
}
llvm_unreachable("Unhandled value kind");
}
llvm::StringRef debugString(Solver::Result::Assignment Assignment) {
switch (Assignment) {
case Solver::Result::Assignment::AssignedFalse:
return "False";
@ -41,7 +68,7 @@ std::string debugString(Solver::Result::Assignment Assignment) {
llvm_unreachable("Booleans can only be assigned true/false");
}
std::string debugString(Solver::Result::Status Status) {
llvm::StringRef debugString(Solver::Result::Status Status) {
switch (Status) {
case Solver::Result::Status::Satisfiable:
return "Satisfiable";