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
2 changes: 1 addition & 1 deletion include/swift/Reflection/MetadataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class MetadataSource {
}

void dump() const;
void dump(FILE *file, unsigned Indent = 0) const;
void dump(std::ostream &stream, unsigned Indent = 0) const;
template <typename Allocator>
static const MetadataSource *decode(Allocator &A, const std::string &str) {
auto begin = str.begin();
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Reflection/TypeLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class TypeInfo {
bool isBitwiseTakable() const { return BitwiseTakable; }

void dump() const;
void dump(FILE *file, unsigned Indent = 0) const;
void dump(std::ostream &stream, unsigned Indent = 0) const;

// Using the provided reader, inspect our value.
// Return false if we can't inspect value.
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Reflection/TypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "swift/ABI/MetadataValues.h"
#include "swift/Remote/MetadataReader.h"
#include "swift/Basic/Unreachable.h"

#include <ostream>
namespace swift {
namespace reflection {

Expand Down Expand Up @@ -177,7 +177,7 @@ class alignas(8) TypeRef {
}

void dump() const;
void dump(FILE *file, unsigned Indent = 0) const;
void dump(std::ostream &stream, unsigned Indent = 0) const;

/// Build a demangle tree from this TypeRef.
Demangle::NodePointer getDemangling(Demangle::Demangler &Dem) const;
Expand Down
17 changes: 9 additions & 8 deletions include/swift/Reflection/TypeRefBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#include "swift/Reflection/TypeLowering.h"
#include "swift/Reflection/TypeRef.h"
#include "llvm/ADT/Optional.h"
#include <vector>
#include <ostream>
#include <unordered_map>
#include <vector>

namespace swift {
namespace reflection {
Expand Down Expand Up @@ -209,7 +210,7 @@ struct ClosureContextInfo {
unsigned NumBindings = 0;

void dump() const;
void dump(FILE *file) const;
void dump(std::ostream &stream) const;
};

struct FieldTypeInfo {
Expand Down Expand Up @@ -728,12 +729,12 @@ class TypeRefBuilder {
///

void dumpTypeRef(RemoteRef<char> MangledName,
FILE *file, bool printTypeName = false);
void dumpFieldSection(FILE *file);
void dumpAssociatedTypeSection(FILE *file);
void dumpBuiltinTypeSection(FILE *file);
void dumpCaptureSection(FILE *file);
void dumpAllSections(FILE *file);
std::ostream &stream, bool printTypeName = false);
void dumpFieldSection(std::ostream &stream);
void dumpAssociatedTypeSection(std::ostream &stream);
void dumpBuiltinTypeSection(std::ostream &stream);
void dumpCaptureSection(std::ostream &stream);
void dumpAllSections(std::ostream &stream);
};


Expand Down
41 changes: 20 additions & 21 deletions stdlib/public/Reflection/MetadataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,50 @@
//===----------------------------------------------------------------------===//

#include "swift/Reflection/MetadataSource.h"
#include <iostream>

using namespace swift;
using namespace reflection;

class PrintMetadataSource
: public MetadataSourceVisitor<PrintMetadataSource, void> {
FILE *file;
std::ostream &stream;
unsigned Indent;

FILE * indent(unsigned Amount) {
std::ostream &indent(unsigned Amount) {
for (unsigned i = 0; i < Amount; ++i)
fprintf(file, " ");
return file;
stream << " ";
return stream;
}

FILE * printHeader(std::string Name) {
fprintf(indent(Indent), "(%s", Name.c_str());
return file;
std::ostream &printHeader(std::string Name) {
indent(Indent) << "(" << Name;
return stream;
}

FILE * printField(std::string name, std::string value) {
std::ostream &printField(std::string name, std::string value) {
if (!name.empty())
fprintf(file, " %s=%s", name.c_str(), value.c_str());
stream << " " << name << "=" << value;
else
fprintf(file, " %s", value.c_str());
return file;
stream << " " << value;
return stream;
}

void printRec(const MetadataSource *MS) {
fprintf(file, "\n");
stream << "\n";

Indent += 2;
visit(MS);
Indent -= 2;
}

void closeForm() {
fprintf(file, ")");
stream << ")";
}

public:
PrintMetadataSource(FILE *file, unsigned Indent)
: file(file), Indent(Indent) {}
PrintMetadataSource(std::ostream &stream, unsigned Indent)
: stream(stream), Indent(Indent) {}

void
visitClosureBindingMetadataSource(const ClosureBindingMetadataSource *CB) {
Expand Down Expand Up @@ -96,11 +97,9 @@ class PrintMetadataSource
}
};

void MetadataSource::dump() const {
dump(stderr, 0);
}
void MetadataSource::dump() const { dump(std::cerr, 0); }

void MetadataSource::dump(FILE *file, unsigned Indent) const {
PrintMetadataSource(file, Indent).visit(this);
fprintf(file, "\n");
void MetadataSource::dump(std::ostream &stream, unsigned Indent) const {
PrintMetadataSource(stream, Indent).visit(this);
stream << "\n";
}
55 changes: 28 additions & 27 deletions stdlib/public/Reflection/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "swift/Reflection/TypeRef.h"
#include "swift/Reflection/TypeRefBuilder.h"
#include "swift/Basic/Unreachable.h"
#include <iostream>

#ifdef DEBUG_TYPE_LOWERING
#define DEBUG_LOG(expr) expr;
Expand All @@ -35,36 +36,36 @@ namespace swift {
namespace reflection {

void TypeInfo::dump() const {
dump(stderr);
dump(std::cerr);
}

namespace {

class PrintTypeInfo {
FILE *file;
std::ostream &stream;
unsigned Indent;

FILE * &indent(unsigned Amount) {
std::ostream &indent(unsigned Amount) {
for (unsigned i = 0; i < Amount; ++i)
fprintf(file, " ");
return file;
stream << " ";
return stream;
}

FILE * &printHeader(const std::string &name) {
fprintf(indent(Indent), "(%s", name.c_str());
return file;
std::ostream &printHeader(const std::string &name) {
indent(Indent) << "(" << name;
return stream;
}

FILE * &printField(const std::string &name, const std::string &value) {
std::ostream &printField(const std::string &name, const std::string &value) {
if (!name.empty())
fprintf(file, " %s=%s", name.c_str(), value.c_str());
stream << " " << name << "=" << value;
else
fprintf(file, " %s", value.c_str());
return file;
stream << " " << name;
return stream;
}

void printRec(const TypeInfo &TI) {
fprintf(file, "\n");
stream << "\n";

Indent += 2;
print(TI);
Expand All @@ -82,13 +83,13 @@ class PrintTypeInfo {
void printFields(const RecordTypeInfo &TI) {
Indent += 2;
for (auto Field : TI.getFields()) {
fprintf(file, "\n");
stream << "\n";
printHeader("field");
if (!Field.Name.empty())
printField("name", Field.Name);
printField("offset", std::to_string(Field.Offset));
printRec(Field.TI);
fprintf(file, ")");
stream << ")";
}
Indent -= 2;
}
Expand All @@ -98,7 +99,7 @@ class PrintTypeInfo {
int Index = -1;
for (auto Case : TI.getCases()) {
Index += 1;
fprintf(file, "\n");
stream << "\n";
printHeader("case");
if (!Case.Name.empty())
printField("name", Case.Name);
Expand All @@ -107,26 +108,26 @@ class PrintTypeInfo {
printField("offset", std::to_string(Case.Offset));
printRec(Case.TI);
}
fprintf(file, ")");
stream << ")";
}
Indent -= 2;
}

public:
PrintTypeInfo(FILE *file, unsigned Indent)
: file(file), Indent(Indent) {}
PrintTypeInfo(std::ostream &stream, unsigned Indent)
: stream(stream), Indent(Indent) {}

void print(const TypeInfo &TI) {
switch (TI.getKind()) {
case TypeInfoKind::Invalid:
printHeader("invalid");
fprintf(file, ")");
stream << ")";
return;

case TypeInfoKind::Builtin:
printHeader("builtin");
printBasic(TI);
fprintf(file, ")");
stream << ")";
return;

case TypeInfoKind::Record: {
Expand Down Expand Up @@ -165,7 +166,7 @@ class PrintTypeInfo {
}
printBasic(TI);
printFields(RecordTI);
fprintf(file, ")");
stream << ")";
return;
}

Expand All @@ -184,7 +185,7 @@ class PrintTypeInfo {
}
printBasic(TI);
printCases(EnumTI);
fprintf(file, ")");
stream << ")";
return;
}

Expand All @@ -207,7 +208,7 @@ class PrintTypeInfo {
break;
}

fprintf(file, ")");
stream << ")";
return;
}
}
Expand All @@ -218,9 +219,9 @@ class PrintTypeInfo {

} // end anonymous namespace

void TypeInfo::dump(FILE *file, unsigned Indent) const {
PrintTypeInfo(file, Indent).print(*this);
fprintf(file, "\n");
void TypeInfo::dump(std::ostream &stream, unsigned Indent) const {
PrintTypeInfo(stream, Indent).print(*this);
stream << "\n";
}

BuiltinTypeInfo::BuiltinTypeInfo(TypeRefBuilder &builder,
Expand Down
Loading