2424#include " swift/Reflection/TypeRef.h"
2525#include " swift/Reflection/TypeRefBuilder.h"
2626#include " swift/Basic/Unreachable.h"
27+ #include < iostream>
2728
2829#ifdef DEBUG_TYPE_LOWERING
2930 #define DEBUG_LOG (expr ) expr;
@@ -35,36 +36,36 @@ namespace swift {
3536namespace reflection {
3637
3738void TypeInfo::dump () const {
38- dump (stderr );
39+ dump (std::cerr );
3940}
4041
4142namespace {
4243
4344class PrintTypeInfo {
44- FILE *file ;
45+ std::ostream &stream ;
4546 unsigned Indent;
4647
47- FILE * &indent (unsigned Amount) {
48+ std::ostream &indent (unsigned Amount) {
4849 for (unsigned i = 0 ; i < Amount; ++i)
49- fprintf (file, " " ) ;
50- return file ;
50+ stream << " " ;
51+ return stream ;
5152 }
5253
53- FILE * &printHeader (const std::string &name) {
54- fprintf ( indent (Indent), " (%s " , name. c_str ()) ;
55- return file ;
54+ std::ostream &printHeader (const std::string &name) {
55+ indent (Indent) << " ( " << name;
56+ return stream ;
5657 }
5758
58- FILE * &printField (const std::string &name, const std::string &value) {
59+ std::ostream &printField (const std::string &name, const std::string &value) {
5960 if (!name.empty ())
60- fprintf (file, " %s=%s " , name. c_str (), value. c_str ()) ;
61+ stream << " " << name << " = " << value;
6162 else
62- fprintf (file, " %s " , value. c_str ()) ;
63- return file ;
63+ stream << " " << name ;
64+ return stream ;
6465 }
6566
6667 void printRec (const TypeInfo &TI) {
67- fprintf (file, " \n " ) ;
68+ stream << " \n " ;
6869
6970 Indent += 2 ;
7071 print (TI);
@@ -82,13 +83,13 @@ class PrintTypeInfo {
8283 void printFields (const RecordTypeInfo &TI) {
8384 Indent += 2 ;
8485 for (auto Field : TI.getFields ()) {
85- fprintf (file, " \n " ) ;
86+ stream << " \n " ;
8687 printHeader (" field" );
8788 if (!Field.Name .empty ())
8889 printField (" name" , Field.Name );
8990 printField (" offset" , std::to_string (Field.Offset ));
9091 printRec (Field.TI );
91- fprintf (file, " )" ) ;
92+ stream << " )" ;
9293 }
9394 Indent -= 2 ;
9495 }
@@ -98,7 +99,7 @@ class PrintTypeInfo {
9899 int Index = -1 ;
99100 for (auto Case : TI.getCases ()) {
100101 Index += 1 ;
101- fprintf (file, " \n " ) ;
102+ stream << " \n " ;
102103 printHeader (" case" );
103104 if (!Case.Name .empty ())
104105 printField (" name" , Case.Name );
@@ -107,26 +108,26 @@ class PrintTypeInfo {
107108 printField (" offset" , std::to_string (Case.Offset ));
108109 printRec (Case.TI );
109110 }
110- fprintf (file, " )" ) ;
111+ stream << " )" ;
111112 }
112113 Indent -= 2 ;
113114 }
114115
115116public:
116- PrintTypeInfo (FILE *file , unsigned Indent)
117- : file(file ), Indent(Indent) {}
117+ PrintTypeInfo (std::ostream &stream , unsigned Indent)
118+ : stream(stream ), Indent(Indent) {}
118119
119120 void print (const TypeInfo &TI) {
120121 switch (TI.getKind ()) {
121122 case TypeInfoKind::Invalid:
122123 printHeader (" invalid" );
123- fprintf (file, " )" ) ;
124+ stream << " )" ;
124125 return ;
125126
126127 case TypeInfoKind::Builtin:
127128 printHeader (" builtin" );
128129 printBasic (TI);
129- fprintf (file, " )" ) ;
130+ stream << " )" ;
130131 return ;
131132
132133 case TypeInfoKind::Record: {
@@ -165,7 +166,7 @@ class PrintTypeInfo {
165166 }
166167 printBasic (TI);
167168 printFields (RecordTI);
168- fprintf (file, " )" ) ;
169+ stream << " )" ;
169170 return ;
170171 }
171172
@@ -184,7 +185,7 @@ class PrintTypeInfo {
184185 }
185186 printBasic (TI);
186187 printCases (EnumTI);
187- fprintf (file, " )" ) ;
188+ stream << " )" ;
188189 return ;
189190 }
190191
@@ -207,7 +208,7 @@ class PrintTypeInfo {
207208 break ;
208209 }
209210
210- fprintf (file, " )" ) ;
211+ stream << " )" ;
211212 return ;
212213 }
213214 }
@@ -218,9 +219,9 @@ class PrintTypeInfo {
218219
219220} // end anonymous namespace
220221
221- void TypeInfo::dump (FILE *file , unsigned Indent) const {
222- PrintTypeInfo (file , Indent).print (*this );
223- fprintf (file, " \n " ) ;
222+ void TypeInfo::dump (std::ostream &stream , unsigned Indent) const {
223+ PrintTypeInfo (stream , Indent).print (*this );
224+ stream << " \n " ;
224225}
225226
226227BuiltinTypeInfo::BuiltinTypeInfo (TypeRefBuilder &builder,
0 commit comments