Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion toolchain/check/pattern_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ enum class MatchKind : uint8_t {
// The collected state of a pattern-matching operation.
class MatchContext {
public:
struct WorkItem {
struct WorkItem : Printable<WorkItem> {
SemIR::InstId pattern_id;
// `None` when processing the callee side.
SemIR::InstId scrutinee_id;

auto Print(llvm::raw_ostream& out) const -> void {
out << "{pattern_id: " << pattern_id << ", scrutinee_id: " << scrutinee_id
<< "}";
}
};

// Constructs a MatchContext. If `callee_specific_id` is not `None`, this
Expand Down
22 changes: 22 additions & 0 deletions toolchain/sem_ir/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ struct ClassFields {
// The virtual function table. `None` if the class has no (direct or
// inherited) virtual functions.
InstId vtable_id = InstId::None;

auto PrintClassFields(llvm::raw_ostream& out) const -> void {
out << "self_type_id: " << self_type_id << ", inheritance_kind: ";
switch (inheritance_kind) {
case Abstract:
out << "Abstract";
break;
case Base:
out << "Base";
break;
case Final:
out << "Final";
break;
}
out << ", is_dynamic: " << is_dynamic << ", scope_id: " << scope_id
<< ", body_block_id: " << body_block_id << ", adapt_id: " << adapt_id
<< ", base_id: " << base_id
<< ", complete_type_witness_id: " << complete_type_witness_id
<< ", vtable_id: " << vtable_id << "}";
}
};

// A class. See EntityWithParamsBase regarding the inheritance here.
Expand All @@ -72,6 +92,8 @@ struct Class : public EntityWithParamsBase,
auto Print(llvm::raw_ostream& out) const -> void {
out << "{";
PrintBaseFields(out);
out << ", ";
PrintClassFields(out);
out << "}";
}

Expand Down
10 changes: 9 additions & 1 deletion toolchain/sem_ir/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct Function : public EntityWithParamsBase,

class File;

struct CalleeFunction {
struct CalleeFunction : public Printable<CalleeFunction> {
// The function. `None` if not a function.
FunctionId function_id;
// The specific that contains the function.
Expand All @@ -147,6 +147,14 @@ struct CalleeFunction {
InstId self_id;
// True if an error instruction was found.
bool is_error;

auto Print(llvm::raw_ostream& out) const -> void {
out << "{function_id: " << function_id
<< ", enclosing_specific_id: " << enclosing_specific_id
<< ", resolved_specific_id: " << resolved_specific_id
<< ", self_type_id: " << self_type_id << ", self_id: " << self_id
<< ", is_error: " << is_error << "}";
}
};

// Returns information for the function corresponding to callee_id.
Expand Down
27 changes: 25 additions & 2 deletions toolchain/sem_ir/type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct CompleteTypeInfo : public Printable<CompleteTypeInfo> {
};

// The initializing representation to use when returning by value.
struct InitRepr {
struct InitRepr : Printable<InitRepr> {
// Returns information about the initializing representation to use for a
// type.
static auto ForType(const File& file, TypeId type_id) -> InitRepr;
Expand Down Expand Up @@ -116,10 +116,29 @@ struct InitRepr {
// Returns whether the initializing representation is a copy of the object
// representation of the type. Provided for symmetry with `ValueRepr`.
auto IsCopyOfObjectRepr() const -> bool { return kind == ByCopy; }

auto Print(llvm::raw_ostream& out) const -> void {
out << "{kind: ";
switch (kind) {
case None:
out << "None";
break;
case ByCopy:
out << "ByCopy";
break;
case InPlace:
out << "InPlace";
break;
case Incomplete:
out << "Incomplete";
break;
}
out << "}";
}
};

// Information about a function's return type.
struct ReturnTypeInfo {
struct ReturnTypeInfo : public Printable<ReturnTypeInfo> {
// Builds return type information for a given declared return type.
static auto ForType(const File& file, TypeId type_id) -> ReturnTypeInfo {
return {.type_id = type_id,
Expand All @@ -145,6 +164,10 @@ struct ReturnTypeInfo {
return init_repr.kind == InitRepr::InPlace;
}

auto Print(llvm::raw_ostream& out) const -> void {
out << "{type_id: " << type_id << ", init_repr: " << init_repr << "}";
}

// The declared return type. `None` if no return type was specified.
TypeId type_id;
// The initializing representation for the return type.
Expand Down
Loading