@@ -67,17 +67,10 @@ static std::ostream& printLocal(Index index, Function* func, std::ostream& o) {
6767 return printName (name, o);
6868}
6969
70- // Wrapper for printing a type when we try to print the type name as much as
71- // possible. For example, for a signature we will print the signature's name,
72- // not its contents.
73- struct TypeName {
74- Type type;
75- TypeName (Type type) : type(type) {}
76- };
77-
7870static void
7971printHeapTypeName (std::ostream& os, HeapType type, bool first = true );
8072
73+ // Prints the name of a type. This output is guaranteed to not contain spaces.
8174static void printTypeName (std::ostream& os, Type type) {
8275 if (type.isBasic ()) {
8376 os << type;
@@ -131,6 +124,8 @@ static void printFieldName(std::ostream& os, const Field& field) {
131124 }
132125}
133126
127+ // Prints the name of a heap type. As with printTypeName, this output is
128+ // guaranteed to not contain spaces.
134129static void printHeapTypeName (std::ostream& os, HeapType type, bool first) {
135130 if (type.isBasic ()) {
136131 os << type;
@@ -174,8 +169,8 @@ struct SExprType {
174169 SExprType (Type type) : type(type){};
175170};
176171
177- static std::ostream& operator <<(std::ostream& o, const SExprType& localType ) {
178- Type type = localType .type ;
172+ static std::ostream& operator <<(std::ostream& o, const SExprType& sType ) {
173+ Type type = sType .type ;
179174 if (type.isTuple ()) {
180175 o << ' (' ;
181176 auto sep = " " ;
@@ -192,24 +187,17 @@ static std::ostream& operator<<(std::ostream& o, const SExprType& localType) {
192187 }
193188 printHeapTypeName (o, rtt.heapType );
194189 o << ' )' ;
195- } else {
196- printTypeName (o, localType.type );
197- }
198- return o;
199- }
200-
201- std::ostream& operator <<(std::ostream& os, TypeName typeName) {
202- auto type = typeName.type ;
203- if (type.isRef () && !type.isBasic ()) {
204- os << " (ref " ;
190+ } else if (type.isRef () && !type.isBasic ()) {
191+ o << " (ref " ;
205192 if (type.isNullable ()) {
206- os << " null " ;
193+ o << " null " ;
207194 }
208- printHeapTypeName (os, type.getHeapType ());
209- os << ' )' ;
210- return os;
195+ printHeapTypeName (o, type.getHeapType ());
196+ o << ' )' ;
197+ } else {
198+ printTypeName (o, sType .type );
211199 }
212- return os << SExprType (typeName. type ) ;
200+ return o ;
213201}
214202
215203// TODO: try to simplify or even remove this, as we may be able to do the same
@@ -229,10 +217,10 @@ std::ostream& operator<<(std::ostream& os, ResultTypeName typeName) {
229217 for (auto t : type) {
230218 os << sep;
231219 sep = " " ;
232- os << TypeName (t);
220+ os << SExprType (t);
233221 }
234222 } else {
235- os << TypeName (type);
223+ os << SExprType (type);
236224 }
237225 os << ' )' ;
238226 return os;
@@ -2571,7 +2559,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
25712559 o << " (param " ;
25722560 auto sep = " " ;
25732561 for (auto type : curr.params ) {
2574- o << sep << TypeName (type);
2562+ o << sep << SExprType (type);
25752563 sep = " " ;
25762564 }
25772565 o << ' )' ;
@@ -2581,7 +2569,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
25812569 o << " (result " ;
25822570 auto sep = " " ;
25832571 for (auto type : curr.results ) {
2584- o << sep << TypeName (type);
2572+ o << sep << SExprType (type);
25852573 sep = " " ;
25862574 }
25872575 o << ' )' ;
@@ -2601,7 +2589,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
26012589 WASM_UNREACHABLE (" invalid packed type" );
26022590 }
26032591 } else {
2604- o << TypeName (field.type );
2592+ o << SExprType (field.type );
26052593 }
26062594 if (field.mutable_ ) {
26072595 o << ' )' ;
@@ -2736,7 +2724,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
27362724 o << ' (' ;
27372725 printMinor (o, " param " );
27382726 printLocal (i, currFunction, o);
2739- o << ' ' << TypeName (param) << ' )' ;
2727+ o << ' ' << SExprType (param) << ' )' ;
27402728 ++i;
27412729 }
27422730 }
@@ -2750,7 +2738,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
27502738 o << ' (' ;
27512739 printMinor (o, " local " );
27522740 printLocal (i, currFunction, o)
2753- << ' ' << TypeName (curr->getLocalType (i)) << ' )' ;
2741+ << ' ' << SExprType (curr->getLocalType (i)) << ' )' ;
27542742 o << maybeNewLine;
27552743 }
27562744 // Print the body.
0 commit comments