@@ -158,15 +158,15 @@ class Remangler {
158
158
SmallVector<std::string, 16 > Subs;
159
159
bool Failed = false ;
160
160
161
- OutputStream printNode (const Node *node) {
162
- OutputStream nodeOutStream ;
163
- initializeOutputStream (nullptr , nullptr , nodeOutStream , 1024 );
164
- node->print (nodeOutStream );
165
- return nodeOutStream ;
161
+ OutputBuffer printNode (const Node *node) {
162
+ OutputBuffer nodeOutBuffer ;
163
+ initializeOutputBuffer (nullptr , nullptr , nodeOutBuffer , 1024 );
164
+ node->print (nodeOutBuffer );
165
+ return nodeOutBuffer ;
166
166
}
167
167
168
168
void addSub (const Node *node) {
169
- OutputStream nodeOut = printNode (node);
169
+ OutputBuffer nodeOut = printNode (node);
170
170
char *nodeOutBuf = nodeOut.getBuffer ();
171
171
auto nodeOutStr =
172
172
std::string (nodeOutBuf, nodeOutBuf + nodeOut.getCurrentPosition ());
@@ -175,7 +175,7 @@ class Remangler {
175
175
}
176
176
177
177
bool findSub (const Node *node, size_t *index) {
178
- OutputStream nodeOut = printNode (node);
178
+ OutputBuffer nodeOut = printNode (node);
179
179
char *nodeOutBuf = nodeOut.getBuffer ();
180
180
auto nodeOutStr =
181
181
std::string (nodeOutBuf, nodeOutBuf + nodeOut.getCurrentPosition ());
@@ -190,59 +190,59 @@ class Remangler {
190
190
return false ;
191
191
}
192
192
193
- bool remangleSub (const Node *node, OutputStream &S ) {
193
+ bool remangleSub (const Node *node, OutputBuffer &OB ) {
194
194
size_t index = 0 ;
195
195
if (findSub (node, &index)) {
196
- S << ' S' ;
196
+ OB << ' S' ;
197
197
if (index != 0 )
198
- S << index;
199
- S << ' _' ;
198
+ OB << index;
199
+ OB << ' _' ;
200
200
return true ;
201
201
}
202
202
return false ;
203
203
}
204
204
205
- void remangleOpenCLCName (const Node *nameNode, OutputStream &S ,
205
+ void remangleOpenCLCName (const Node *nameNode, OutputBuffer &OB ,
206
206
bool Substitutable, bool isNameRoot = true ) {
207
- if (Substitutable && remangleSub (nameNode, S ))
207
+ if (Substitutable && remangleSub (nameNode, OB ))
208
208
return ;
209
209
switch (nameNode->getKind ()) {
210
210
case Node::Kind::KNameType: {
211
211
const NameType *name = static_cast <const NameType *>(nameNode);
212
- S << name->getName ().size ();
213
- S << name->getName ();
212
+ OB << name->getName ().size ();
213
+ OB << name->getName ();
214
214
break ;
215
215
}
216
216
case Node::Kind::KNestedName: {
217
217
if (isNameRoot)
218
- S << ' N' ;
218
+ OB << ' N' ;
219
219
const NestedName *nestedName = static_cast <const NestedName *>(nameNode);
220
- remangleOpenCLCName (nestedName->Qual , S , Substitutable,
220
+ remangleOpenCLCName (nestedName->Qual , OB , Substitutable,
221
221
/* isNameRoot= */ false );
222
- remangleOpenCLCName (nestedName->Name , S , /* Substitutable= */ false ,
222
+ remangleOpenCLCName (nestedName->Name , OB , /* Substitutable= */ false ,
223
223
/* isNameRoot= */ false );
224
224
if (isNameRoot)
225
- S << ' E' ;
225
+ OB << ' E' ;
226
226
break ;
227
227
}
228
228
case Node::Kind::KNameWithTemplateArgs: {
229
229
const NameWithTemplateArgs *templateName =
230
230
static_cast <const NameWithTemplateArgs *>(nameNode);
231
231
assert (templateName->TemplateArgs ->getKind () ==
232
232
Node::Kind::KTemplateArgs);
233
- remangleOpenCLCName (templateName->Name , S , /* Substitutable= */ false ,
233
+ remangleOpenCLCName (templateName->Name , OB , /* Substitutable= */ false ,
234
234
/* isNameRoot= */ false );
235
- S << ' I' ;
235
+ OB << ' I' ;
236
236
const TemplateArgs *templateArgs =
237
237
static_cast <const TemplateArgs *>(templateName->TemplateArgs );
238
238
for (auto templateArgType : templateArgs->getParams ())
239
- remangleOpenCLCType (templateArgType, S );
240
- S << ' E' ;
239
+ remangleOpenCLCType (templateArgType, OB );
240
+ OB << ' E' ;
241
241
break ;
242
242
}
243
243
default : {
244
- OutputStream errorTypeOut;
245
- initializeOutputStream (nullptr , nullptr , errorTypeOut, 1024 );
244
+ OutputBuffer errorTypeOut;
245
+ initializeOutputBuffer (nullptr , nullptr , errorTypeOut, 1024 );
246
246
errorTypeOut << " Unhandled name : " ;
247
247
nameNode->print (errorTypeOut);
248
248
errorTypeOut << " \n " ;
@@ -255,165 +255,165 @@ class Remangler {
255
255
addSub (nameNode);
256
256
}
257
257
258
- void remangleOpenCLCTypeName (const NameType *typeName, OutputStream &S ) {
258
+ void remangleOpenCLCTypeName (const NameType *typeName, OutputBuffer &OB ) {
259
259
StringView name = typeName->getName ();
260
260
261
261
auto it = TypeReplacements.find (name.begin ());
262
262
if (it != TypeReplacements.end ())
263
263
name = StringView (it->second );
264
264
265
265
if (name == " void" )
266
- S << ' v' ;
266
+ OB << ' v' ;
267
267
else if (name == " wchar_t" )
268
- S << ' w' ;
268
+ OB << ' w' ;
269
269
else if (name == " bool" )
270
- S << ' b' ;
270
+ OB << ' b' ;
271
271
else if (name == " char" )
272
- S << ' c' ;
272
+ OB << ' c' ;
273
273
else if (name == " signed char" )
274
- S << ' a' ;
274
+ OB << ' a' ;
275
275
else if (name == " unsigned char" )
276
- S << ' h' ;
276
+ OB << ' h' ;
277
277
else if (name == " short" )
278
- S << ' s' ;
278
+ OB << ' s' ;
279
279
else if (name == " unsigned short" )
280
- S << ' t' ;
280
+ OB << ' t' ;
281
281
else if (name == " int" )
282
- S << ' i' ;
282
+ OB << ' i' ;
283
283
else if (name == " unsigned int" )
284
- S << ' j' ;
284
+ OB << ' j' ;
285
285
else if (name == " long" )
286
- S << ' l' ;
286
+ OB << ' l' ;
287
287
else if (name == " unsigned long" )
288
- S << ' m' ;
288
+ OB << ' m' ;
289
289
else if (name == " long long" )
290
- S << ' x' ;
290
+ OB << ' x' ;
291
291
else if (name == " unsigned long long" )
292
- S << ' y' ;
292
+ OB << ' y' ;
293
293
else if (name == " __int128" )
294
- S << ' n' ;
294
+ OB << ' n' ;
295
295
else if (name == " unsigned __int128" )
296
- S << ' o' ;
296
+ OB << ' o' ;
297
297
else if (name == " float" )
298
- S << ' f' ;
298
+ OB << ' f' ;
299
299
else if (name == " double" )
300
- S << ' d' ;
300
+ OB << ' d' ;
301
301
else if (name == " long double" )
302
- S << ' e' ;
302
+ OB << ' e' ;
303
303
else if (name == " __float128" )
304
- S << ' g' ;
304
+ OB << ' g' ;
305
305
else if (name == " ..." )
306
- S << ' z' ;
306
+ OB << ' z' ;
307
307
// TODO: u
308
308
else if (name == " decimal64" )
309
- S << " Dd" ;
309
+ OB << " Dd" ;
310
310
else if (name == " decimal128" )
311
- S << " De" ;
311
+ OB << " De" ;
312
312
else if (name == " decimal32" )
313
- S << " Df" ;
313
+ OB << " Df" ;
314
314
else if (name == " decimal16" )
315
- S << " Dh" ;
315
+ OB << " Dh" ;
316
316
else if (name == " char32_t" )
317
- S << " Di" ;
317
+ OB << " Di" ;
318
318
else if (name == " char16_t" )
319
- S << " Ds" ;
319
+ OB << " Ds" ;
320
320
else if (name == " char8_t" )
321
- S << " Du" ;
321
+ OB << " Du" ;
322
322
else if (name == " _Float16" )
323
- S << " DF16_" ;
323
+ OB << " DF16_" ;
324
324
else if (name == " auto" )
325
- S << ' a' ;
325
+ OB << ' a' ;
326
326
else if (name == " decltype(auto)" )
327
- S << ' c' ;
327
+ OB << ' c' ;
328
328
else if (name == " std::nullptr_t" )
329
- S << ' n' ;
329
+ OB << ' n' ;
330
330
// Enum
331
331
else
332
- remangleOpenCLCName (typeName, S , /* Substitutable= */ true );
332
+ remangleOpenCLCName (typeName, OB , /* Substitutable= */ true );
333
333
}
334
334
335
335
void remangleOpenCLCQualifiers (const itanium_demangle::Qualifiers quals,
336
- OutputStream &S ) {
336
+ OutputBuffer &OB ) {
337
337
if (quals & QualConst)
338
- S << " K" ;
338
+ OB << " K" ;
339
339
if (quals & QualVolatile)
340
- S << " V" ;
340
+ OB << " V" ;
341
341
if (quals & QualRestrict)
342
- S << " r" ;
342
+ OB << " r" ;
343
343
}
344
344
345
- void remangleOpenCLCType (const Node *typeNode, OutputStream &S ) {
345
+ void remangleOpenCLCType (const Node *typeNode, OutputBuffer &OB ) {
346
346
switch (typeNode->getKind ()) {
347
347
case Node::Kind::KPointerType: {
348
348
const itanium_demangle::PointerType *ptype =
349
349
static_cast <const itanium_demangle::PointerType *>(typeNode);
350
- S << ' P' ;
351
- remangleOpenCLCType (ptype->getPointee (), S );
350
+ OB << ' P' ;
351
+ remangleOpenCLCType (ptype->getPointee (), OB );
352
352
break ;
353
353
}
354
354
case Node::Kind::KVectorType: {
355
- if (remangleSub (typeNode, S ))
355
+ if (remangleSub (typeNode, OB ))
356
356
return ;
357
357
358
358
const itanium_demangle::VectorType *vecType =
359
359
static_cast <const itanium_demangle::VectorType *>(typeNode);
360
360
assert (vecType->getDimension ()->getKind () == Node::Kind::KNameType);
361
361
const NameType *dims =
362
362
static_cast <const NameType *>(vecType->getDimension ());
363
- S << " Dv" ;
364
- S << dims->getName ();
365
- S << ' _' ;
366
- remangleOpenCLCType (vecType->getBaseType (), S );
363
+ OB << " Dv" ;
364
+ OB << dims->getName ();
365
+ OB << ' _' ;
366
+ remangleOpenCLCType (vecType->getBaseType (), OB );
367
367
addSub (typeNode);
368
368
break ;
369
369
}
370
370
case Node::Kind::KBinaryFPType: {
371
- if (remangleSub (typeNode, S ))
371
+ if (remangleSub (typeNode, OB ))
372
372
return ;
373
373
374
374
const BinaryFPType *BFPType = static_cast <const BinaryFPType *>(typeNode);
375
375
assert (BFPType->getDimension ()->getKind () == Node::Kind::KNameType);
376
376
const NameType *dims =
377
377
static_cast <const NameType *>(BFPType->getDimension ());
378
378
379
- S << " DF" ;
380
- S << dims->getName ();
381
- S << ' _' ;
379
+ OB << " DF" ;
380
+ OB << dims->getName ();
381
+ OB << ' _' ;
382
382
break ;
383
383
}
384
384
case Node::Kind::KVendorExtQualType: {
385
- if (remangleSub (typeNode, S ))
385
+ if (remangleSub (typeNode, OB ))
386
386
return ;
387
387
388
388
const VendorExtQualType *extQualType =
389
389
static_cast <const VendorExtQualType *>(typeNode);
390
- S << ' U' ;
391
- S << extQualType->getExt ().size ();
392
- S << extQualType->getExt ();
393
- remangleOpenCLCType (extQualType->getTy (), S );
390
+ OB << ' U' ;
391
+ OB << extQualType->getExt ().size ();
392
+ OB << extQualType->getExt ();
393
+ remangleOpenCLCType (extQualType->getTy (), OB );
394
394
addSub (typeNode);
395
395
break ;
396
396
}
397
397
case Node::Kind::KQualType: {
398
398
const itanium_demangle::QualType *qtype =
399
399
static_cast <const itanium_demangle::QualType *>(typeNode);
400
- remangleOpenCLCQualifiers (qtype->getQuals (), S );
401
- remangleOpenCLCType (qtype->getChild (), S );
400
+ remangleOpenCLCQualifiers (qtype->getQuals (), OB );
401
+ remangleOpenCLCType (qtype->getChild (), OB );
402
402
break ;
403
403
}
404
404
case Node::Kind::KNameType: {
405
405
const NameType *typeName = static_cast <const NameType *>(typeNode);
406
- remangleOpenCLCTypeName (typeName, S );
406
+ remangleOpenCLCTypeName (typeName, OB );
407
407
break ;
408
408
}
409
409
case Node::Kind::KNestedName: {
410
410
// Enum type with nested name
411
- remangleOpenCLCName (typeNode, S , /* Substitutable= */ true );
411
+ remangleOpenCLCName (typeNode, OB , /* Substitutable= */ true );
412
412
break ;
413
413
}
414
414
default : {
415
- OutputStream errorTypeOut;
416
- initializeOutputStream (nullptr , nullptr , errorTypeOut, 1024 );
415
+ OutputBuffer errorTypeOut;
416
+ initializeOutputBuffer (nullptr , nullptr , errorTypeOut, 1024 );
417
417
errorTypeOut << " Unhandled type : " ;
418
418
typeNode->print (errorTypeOut);
419
419
errorTypeOut << " \n " ;
@@ -424,23 +424,23 @@ class Remangler {
424
424
}
425
425
}
426
426
427
- void remangleOpenCLCFunction (const Node *root, OutputStream &S ) {
427
+ void remangleOpenCLCFunction (const Node *root, OutputBuffer &OB ) {
428
428
assert (root->getKind () == Node::Kind::KFunctionEncoding);
429
- S << " _Z" ;
429
+ OB << " _Z" ;
430
430
431
431
const FunctionEncoding *encoding =
432
432
static_cast <const FunctionEncoding *>(root);
433
433
434
- remangleOpenCLCName (encoding->getName (), S , /* Substitutable= */ false );
434
+ remangleOpenCLCName (encoding->getName (), OB , /* Substitutable= */ false );
435
435
436
436
if (encoding->getReturnType ())
437
- remangleOpenCLCType (encoding->getReturnType (), S );
437
+ remangleOpenCLCType (encoding->getReturnType (), OB );
438
438
439
439
for (const Node *paramType : encoding->getParams ())
440
- remangleOpenCLCType (paramType, S );
440
+ remangleOpenCLCType (paramType, OB );
441
441
442
442
if (encoding->getParams ().size () == 0 )
443
- S << ' v' ;
443
+ OB << ' v' ;
444
444
}
445
445
446
446
public:
@@ -452,8 +452,8 @@ class Remangler {
452
452
453
453
std::string remangle () {
454
454
Subs.clear ();
455
- OutputStream remanglingStream;
456
- initializeOutputStream (nullptr , nullptr , remanglingStream, 1024 );
455
+ OutputBuffer remanglingStream;
456
+ initializeOutputBuffer (nullptr , nullptr , remanglingStream, 1024 );
457
457
remangleOpenCLCFunction (Root, remanglingStream);
458
458
std::string remangled = std::string (remanglingStream.getBuffer (),
459
459
remanglingStream.getCurrentPosition ());
0 commit comments