Add Dump methods to printable types. (#681)

This commit is contained in:
Geoff Romer
2021-07-29 14:17:35 -07:00
committed by GitHub
parent 61abc44aef
commit a8f56797b8
15 changed files with 43 additions and 3 deletions
+9 -1
View File
@@ -17,6 +17,7 @@ cc_library(
"//executable_semantics/ast:expression",
"//executable_semantics/ast:function_definition",
"//executable_semantics/ast:statement",
"@llvm-project//llvm:Support",
],
)
@@ -26,6 +27,7 @@ cc_library(
deps = [
":field_path",
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
@@ -44,7 +46,10 @@ cc_library(
cc_library(
name = "field_path",
hdrs = ["field_path.h"],
deps = ["//common:ostream"],
deps = [
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
cc_library(
@@ -56,6 +61,7 @@ cc_library(
":address",
":containers",
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
@@ -67,6 +73,7 @@ cc_library(
":address",
":value",
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
@@ -120,5 +127,6 @@ cc_library(
"//common:ostream",
"//executable_semantics/ast:function_definition",
"//executable_semantics/ast:statement",
"@llvm-project//llvm:Support",
],
)
@@ -12,6 +12,7 @@
#include "executable_semantics/ast/statement.h"
#include "executable_semantics/interpreter/stack.h"
#include "executable_semantics/interpreter/value.h"
#include "llvm/Support/Compiler.h"
namespace Carbon {
@@ -56,6 +57,7 @@ struct Action {
auto GetValAction() const -> const ValAction&;
void Print(llvm::raw_ostream& out) const;
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
inline auto tag() const -> ActionKind {
return std::visit([](const auto& t) { return t.Kind; }, value);
@@ -11,6 +11,7 @@
#include "common/ostream.h"
#include "executable_semantics/interpreter/field_path.h"
#include "llvm/Support/Compiler.h"
namespace Carbon {
@@ -42,6 +43,8 @@ class Address {
out << "Address(" << index << ")" << field_path;
}
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
// If *this represents the address of an object with a field named
// `field_name`, this method returns the address of that field.
auto SubobjectAddress(std::string field_name) const -> Address {
@@ -9,6 +9,7 @@
#include <vector>
#include "common/ostream.h"
#include "llvm/Support/Compiler.h"
namespace Carbon {
@@ -50,6 +51,8 @@ class FieldPath {
}
}
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
private:
// The representation of FieldPath describes how to locate a Value within
// another Value, so its implementation details are tied to the implementation
+1 -2
View File
@@ -4,8 +4,7 @@
#include "executable_semantics/interpreter/frame.h"
#include <ostream>
#include "common/ostream.h"
#include "executable_semantics/interpreter/action.h"
namespace Carbon {
+2
View File
@@ -13,6 +13,7 @@
#include "executable_semantics/interpreter/address.h"
#include "executable_semantics/interpreter/dictionary.h"
#include "executable_semantics/interpreter/stack.h"
#include "llvm/Support/Compiler.h"
namespace Carbon {
@@ -51,6 +52,7 @@ struct Frame {
: name(std::move(std::move(n))), scopes(s), todo(c), continuation() {}
void Print(llvm::raw_ostream& out) const;
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
};
} // namespace Carbon
+3
View File
@@ -10,6 +10,7 @@
#include "common/ostream.h"
#include "executable_semantics/interpreter/address.h"
#include "executable_semantics/interpreter/value.h"
#include "llvm/Support/Compiler.h"
namespace Carbon {
@@ -42,6 +43,8 @@ class Heap {
// Print all the values on the heap to the stream `out`.
void Print(llvm::raw_ostream& out) const;
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
private:
// Signal an error if the address is no longer alive.
void CheckAlive(const Address& address, int line_num);
+2
View File
@@ -17,6 +17,7 @@
#include "executable_semantics/interpreter/address.h"
#include "executable_semantics/interpreter/field_path.h"
#include "executable_semantics/interpreter/stack.h"
#include "llvm/Support/Compiler.h"
namespace Carbon {
@@ -242,6 +243,7 @@ struct Value {
int line_num) const -> const Value*;
void Print(llvm::raw_ostream& out) const;
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
private:
std::variant<IntValue, FunctionValue, PointerValue, BoolValue, StructValue,