mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add Dump methods to printable types. (#681)
This commit is contained in:
@@ -20,6 +20,7 @@ cc_library(
|
||||
"//common:ostream",
|
||||
"//executable_semantics/interpreter:address",
|
||||
"//executable_semantics/interpreter:containers",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -31,6 +32,7 @@ cc_library(
|
||||
"//common:indirect_value",
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:error",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -41,6 +43,7 @@ cc_library(
|
||||
deps = [
|
||||
":expression",
|
||||
":statement",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -51,6 +54,7 @@ cc_library(
|
||||
deps = [
|
||||
":expression",
|
||||
"//common:ostream",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -62,6 +66,7 @@ cc_library(
|
||||
":expression",
|
||||
"//common:check",
|
||||
"//common:ostream",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -71,5 +76,6 @@ cc_library(
|
||||
deps = [
|
||||
":member",
|
||||
"//common:ostream",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "executable_semantics/ast/struct_definition.h"
|
||||
#include "executable_semantics/interpreter/address.h"
|
||||
#include "executable_semantics/interpreter/dictionary.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -84,6 +85,7 @@ class Declaration {
|
||||
auto GetVariableDeclaration() const -> const VariableDeclaration&;
|
||||
|
||||
void Print(llvm::raw_ostream& out) const;
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
|
||||
inline auto tag() const -> DeclarationKind {
|
||||
return std::visit([](const auto& t) { return t.Kind; }, value);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "common/ostream.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -179,6 +180,7 @@ struct Expression {
|
||||
auto GetFunctionTypeLiteral() const -> const FunctionTypeLiteral&;
|
||||
|
||||
void Print(llvm::raw_ostream& out) const;
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
|
||||
inline auto tag() const -> ExpressionKind {
|
||||
return std::visit([](const auto& t) { return t.Kind; }, value);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "executable_semantics/ast/statement.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -33,6 +34,7 @@ struct FunctionDefinition {
|
||||
|
||||
void Print(llvm::raw_ostream& out) const { PrintDepth(-1, out); }
|
||||
void PrintDepth(int depth, llvm::raw_ostream& out) const;
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
|
||||
int line_num;
|
||||
std::string name;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -27,6 +28,7 @@ struct Member {
|
||||
auto GetFieldMember() const -> const FieldMember&;
|
||||
|
||||
void Print(llvm::raw_ostream& out) const;
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
|
||||
inline auto tag() const -> MemberKind {
|
||||
return std::visit([](const auto& t) { return t.Kind; }, value);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -163,7 +164,9 @@ struct Statement {
|
||||
auto GetRun() const -> const Run&;
|
||||
auto GetAwait() const -> const Await&;
|
||||
|
||||
void Print(llvm::raw_ostream& out) const { PrintDepth(-1, out); }
|
||||
void PrintDepth(int depth, llvm::raw_ostream& out) const;
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
|
||||
inline auto tag() const -> StatementKind {
|
||||
return std::visit([](const auto& t) { return t.Kind; }, value);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
#include "executable_semantics/interpreter/frame.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/interpreter/action.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user