-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsymextract.d
899 lines (742 loc) · 21.8 KB
/
dsymextract.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
// Demangles a mangled D identifier and produces the result in
// inherited container classes such as DType and DSymbol.
// Ideally used to extract code-completion info from a compiled D library
// using the library's symbol table.
// by James Dunne
// Jan. 6 2005
module dsymextract;
import std.ctype;
import std.string;
//version = destructors; // include destructor code (for explicit memory management)
version = error_extrachars; // check for extra characters after end of mangled string
version(linux) {
version = ansi_color; // use ANSI color strings for cheap syntax highlighting
}
//debug = destruct; // dump destructor calls
// A D symbol (inherited usually)
class DSymbol {
public:
char[] name; // name for the symbol
DType type; // type of the symbol
this() {
}
char[] toANSIString() {
return "\033[0;37m" ~ name;
}
char[] toString() {
return name;
}
}
// A D function definition
class DFunction : DSymbol {
public:
//char[] name; // name for the function
//DType type; // return type for the function
DType[] params; // parameters for the function
this() {
}
version (destructors) ~this() {
foreach (inout DType t; params)
if (cast(DReservedType)t is null)
delete t;
}
char[] toANSIString() {
char[] s;
bool first = true;
if (type is null) return name;
s = type.toANSIString() ~ " \033[0;37m" ~ name ~ "\033[0;36m" ~ "(";
foreach (DType dt; params) {
if (!first) s ~= "\033[0;36m" ~ ", ";
s ~= dt.toANSIString();
first = false;
}
s ~= "\033[0;36m)\033[37m";
return s;
}
char[] toString() {
char[] s;
bool first = true;
if (type is null) return name;
s = type.toString() ~ " " ~ name ~ "(";
foreach (DType dt; params) {
if (!first) s ~= ", ";
s ~= dt.toString();
first = false;
}
s ~= ")";
return s;
}
}
// A D class definition:
class DClass : DSymbol {
public:
// Doesn't have much.
// Should expand to contain functions and other symbols.
this(char[] name) {
this.name = name;
}
char[] toANSIString() {
return "\033[0;37mclass " ~ name;
}
char[] toString() {
return "class " ~ name;
}
}
// A D module definition:
class DModule : DSymbol {
public:
// Doesn't have much.
// Should expand to contain class definitions, functions, and other symbols.
this(char[] name) {
this.name = name;
}
char[] toANSIString() {
return "\033[0;37mmodule " ~ name;
}
char[] toString() {
return "module " ~ name;
}
}
// A reserved type:
class DReservedType : DType {
public:
this() {
}
// Initialize a DType with a string representation:
this(char[] chars) {
asString = chars;
}
version (destructors) ~this() {
debug (destruct) printf("DReservedType.~this()\n");
}
}
// A D type:
class DType {
private:
char[] asString; // what this type is as a string
public:
// Some static basic types:
static DReservedType None; // ever used?
static DReservedType Void;
static DReservedType Byte;
static DReservedType UByte;
static DReservedType Short;
static DReservedType UShort;
static DReservedType Int;
static DReservedType UInt;
static DReservedType Long;
static DReservedType ULong;
static DReservedType Float;
static DReservedType Double;
static DReservedType Real;
// imaginary and complex:
static DReservedType IFloat;
static DReservedType IDouble;
static DReservedType IReal;
static DReservedType CFloat;
static DReservedType CDouble;
static DReservedType CReal;
// other types:
static DReservedType Bit;
static DReservedType Char;
static DReservedType WChar;
static DReservedType DChar;
// Initialize the basic types:
static this() {
// basic types:
None = new DReservedType("none"); // ever used?
Void = new DReservedType("void");
Byte = new DReservedType("byte");
UByte = new DReservedType("ubyte");
Short = new DReservedType("short");
UShort = new DReservedType("ushort");
Int = new DReservedType("int");
UInt = new DReservedType("uint");
Long = new DReservedType("long");
ULong = new DReservedType("ulong");
Float = new DReservedType("float");
Double = new DReservedType("double");
Real = new DReservedType("real");
// imaginary and complex:
IFloat = new DReservedType("ifloat");
IDouble = new DReservedType("idouble");
IReal = new DReservedType("ireal");
CFloat = new DReservedType("cfloat");
CDouble = new DReservedType("cdouble");
CReal = new DReservedType("creal");
// other types:
Bit = new DReservedType("bit");
Char = new DReservedType("char");
WChar = new DReservedType("wchar");
DChar = new DReservedType("dchar");
}
version (destructors) static ~this() {
debug (destruct) printf("static DType::~this()\n");
// basic types:
delete None; // ever used?
delete Void;
delete Byte;
delete UByte;
delete Short;
delete UShort;
delete Int;
delete UInt;
delete Long;
delete ULong;
delete Float;
delete Double;
delete Real;
// imaginary and complex:
delete IFloat;
delete IDouble;
delete IReal;
delete CFloat;
delete CDouble;
delete CReal;
// other types:
delete Bit;
delete Char;
delete WChar;
delete DChar;
debug (destruct) printf("static DType::~this() deleted\n");
}
public:
// Not sure why, but the compiler complains without it:
this() {
}
version (destructors) ~this() {
}
// Convert the type to its string representation:
char[] toANSIString() {
return "\033[34m" ~ asString;
}
char[] toString() {
return asString;
}
}
// This exception is thrown on parsing errors and type errors:
class DTypeException : Exception {
public:
this(char[] msg) {
super("DTypeException: " ~ msg);
}
}
// Simple D types:
// Array:
class DTypeArray : DType {
private:
DType internalType; // the type of the array
public:
this(DType singleType) {
this.internalType = singleType;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeArray.~this()\n");
if (cast(DReservedType)internalType is null)
delete internalType;
}
// append a [] to the end of the type:
char[] toANSIString() {
return internalType.toANSIString() ~ "\033[1;31m[]\033[0;37m";
}
char[] toString() {
return internalType.toString() ~ "[]";
}
}
// Static array:
class DTypeSArray : DType {
private:
DType internalType; // the type of the array
public:
this(DType singleType) {
this.internalType = singleType;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeSArray.~this()\n");
if (cast(DReservedType)internalType is null)
delete internalType;
}
// append a [] to the end of the type:
char[] toANSIString() {
return internalType.toANSIString() ~ "\033[1;31m[]\033[0;37m";
}
char[] toString() {
return internalType.toString() ~ "[]";
}
}
// Dynamic array:
class DTypeDArray : DType {
private:
DType internalType; // the type of the array
public:
this(DType singleType) {
this.internalType = singleType;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeDArray.~this()\n");
if (cast(DReservedType)internalType is null)
delete internalType;
}
// append a [] to the end of the type:
char[] toANSIString() {
return internalType.toANSIString() ~ "\033[1;31m[]\033[0;37m";
}
char[] toString() {
return internalType.toString() ~ "[]";
}
}
// Pointer:
class DTypePointer : DType {
private:
DType internalType; // the type of pointer
public:
this(DType singleType) {
this.internalType = singleType;
}
version (destructors) ~this() {
debug (destruct) ("DTypePointer.~this()\n");
if (cast(DReservedType)internalType is null)
delete internalType;
}
char[] toANSIString() {
return internalType.toANSIString() ~ "\033[1;33m*\033[0;37m";
}
char[] toString() {
return internalType.toString() ~ "*";
}
}
// Reference:
class DTypeReference : DType {
private:
DType internalType; // the type of reference
public:
this(DType singleType) {
this.internalType = singleType;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeReference.~this()\n");
if (cast(DReservedType)internalType is null)
delete internalType;
}
char[] toANSIString() {
return internalType.toANSIString() ~ "\033[1;33m&\033[0;37m";
}
char[] toString() {
return internalType.toString() ~ "&";
}
}
// out parameter:
// (in is default)
class DTypeOut : DType {
private:
DType internalType; // an out parameter
public:
this(DType singleType) {
if (!(cast(DTypeInOut)singleType is null))
throw new DTypeException("inout cannot be followed by out!");
if (!(cast(DTypeOut)singleType is null))
throw new DTypeException("out cannot be followed by out!");
this.internalType = singleType;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeOut.~this()\n");
if (cast(DReservedType)internalType is null)
delete internalType;
}
char[] toANSIString() {
return "\033[34mout " ~ internalType.toANSIString();
}
char[] toString() {
return "out " ~ internalType.toString();
}
}
// inout parameter:
class DTypeInOut : DType {
private:
DType internalType; // an inout parameter
public:
this(DType singleType) {
if (!(cast(DTypeInOut)singleType is null))
throw new DTypeException("inout cannot be followed by inout!");
if (!(cast(DTypeOut)singleType is null))
throw new DTypeException("out cannot be followed by inout!");
this.internalType = singleType;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeInOut.~this()\n");
if (cast(DReservedType)internalType is null)
delete internalType;
}
char[] toANSIString() {
return "\033[34minout " ~ internalType.toANSIString();
}
char[] toString() {
return "inout " ~ internalType.toString();
}
}
// enum:
class DTypeEnumeration : DType {
private:
char[] identifier; // the name of the enum type
public:
this(char[] ident) {
this.identifier = ident;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeEnumeration.~this()\n");
}
char[] toANSIString() {
return "\033[0;37m" ~ identifier;
}
char[] toString() {
return identifier;
}
}
// typedef:
class DTypeTypedef : DType {
private:
char[] identifier; // the name of the typedef type
public:
this(char[] ident) {
this.identifier = ident;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeTypedef.~this()\n");
}
char[] toANSIString() {
return "\033[0;37m" ~ identifier;
}
char[] toString() {
return identifier;
}
}
// delegate:
class DTypeDelegate : DType {
private:
char[] identifier; // the name of the delegate type
public:
this(char[] ident) {
this.identifier = ident;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeDelegate.~this()\n");
}
char[] toANSIString() {
return "\033[0;37m" ~ identifier;
}
char[] toString() {
return identifier;
}
}
// class instance:
class DTypeClass : DType {
private:
char[] identifier; // the name of the class type
public:
this(char[] ident) {
this.identifier = ident;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeClass.~this()\n");
}
char[] toANSIString() {
return "\033[0;37m" ~ identifier;
}
char[] toString() {
return identifier;
}
}
// struct instance:
class DTypeStruct : DType {
private:
char[] identifier; // the name of the struct type
public:
this(char[] ident) {
this.identifier = ident;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeStruct.~this()\n");
}
char[] toANSIString() {
return "\033[0;37m" ~ identifier;
}
char[] toString() {
return identifier;
}
}
// identifier:
class DTypeIdentifier : DType {
private:
char[] identifier;
public:
this(char[] ident) {
this.identifier = ident;
}
version (destructors) ~this() {
debug (destruct) printf("DTypeIdentifier.~this()\n");
}
char[] toANSIString() {
return "\033[0;37m" ~ identifier;
}
char[] toString() {
return identifier;
}
}
// The extractor class:
class DSymbolExtractor {
private:
// extracts a series of dot-separated identifiers:
char[] extractidentifiers(char[] id, inout int i) {
char[] s;
bool first = true;
for (;;) {
int num = i;
// Parse numeric length:
while (i < id.length) {
if (!isdigit(id[i])) break;
++i;
}
if (num == i) break;
// Get the length as an integer:
int len = atoi(id[num .. i]);
// Extract the identifier
if (!first) s ~= ".";
if (i+len > id.length)
throw new DTypeException("length of identifier would exceed length of mangled string!");
s ~= id[i .. i+len];
i += len;
// Dot-separate after this:
first = false;
}
// Return the identifier string:
return s;
}
// extracts a single definition (like a parameter)
DType extracttypeinfo(char[] id, inout int i) {
if (i >= id.length)
throw new DTypeException("unexpected end of identifier!");
// Extract the type info:
switch (id[i]) {
// array, static array, dynamic array:
case 'A': ++i; return new DTypeArray(extracttypeinfo(id, i));
case 'G': ++i; return new DTypeSArray(extracttypeinfo(id, i));
case 'H': ++i; return new DTypeDArray(extracttypeinfo(id, i));
// pointer:
case 'P': ++i; return new DTypePointer(extracttypeinfo(id, i));
// reference:
case 'R': ++i; return new DTypeReference(extracttypeinfo(id, i));
// out:
case 'J': ++i; return new DTypeOut(extracttypeinfo(id, i));
// inout:
case 'K': ++i; return new DTypeInOut(extracttypeinfo(id, i));
// enum:
case 'E': ++i; return new DTypeEnumeration(extractidentifiers(id, i));
// typedef:
case 'T': ++i; return new DTypeTypedef(extractidentifiers(id, i));
// delegate:
case 'D': ++i; return new DTypeDelegate(extractidentifiers(id, i));
// class:
case 'C': ++i; return new DTypeClass(extractidentifiers(id, i));
// struct:
case 'S': ++i; return new DTypeStruct(extractidentifiers(id, i));
// identifier:
case 'I': ++i; return new DTypeIdentifier(extractidentifiers(id, i));
// basic types:
case 'n': ++i; return DType.None; // ever used?
case 'v': ++i; return DType.Void;
case 'g': ++i; return DType.Byte;
case 'h': ++i; return DType.UByte;
case 's': ++i; return DType.Short;
case 't': ++i; return DType.UShort;
case 'i': ++i; return DType.Int;
case 'k': ++i; return DType.UInt;
case 'l': ++i; return DType.Long;
case 'm': ++i; return DType.ULong;
case 'f': ++i; return DType.Float;
case 'd': ++i; return DType.Double;
case 'e': ++i; return DType.Real;
// imaginary and complex:
case 'o': ++i; return DType.IFloat;
case 'p': ++i; return DType.IDouble;
case 'j': ++i; return DType.IReal;
case 'q': ++i; return DType.CFloat;
case 'r': ++i; return DType.CDouble;
case 'c': ++i; return DType.CReal;
// other types:
case 'b': ++i; return DType.Bit;
case 'a': ++i; return DType.Char;
case 'u': ++i; return DType.WChar;
case 'w': ++i; return DType.DChar;
case 'Z': throw new DTypeException(format("Z (return type) cannot be used as a type at position %d!", i));
// typeinfo, error, instance:
case '@': ++i; return null; // BUG: FIXME!!
default: throw new DTypeException(format("unknown type mangle character '%s' at position %d!", id[i], i));
}
}
public:
// Constructor doesn't do anything.
this() {
}
// Returns the symbol represented by the mangled string:
// right now, only class declarations and function declarations.
DSymbol demangle(char[] id) {
char[] name;
int i;
// Remove all leading underscores except one:
i = 0;
while (id[i] == '_') ++i;
if (i > 0) --i;
id = id[i .. length];
// D linkage function:
if (id[0] == '_') {
if (id[1] == 'D') {
if (id.length <= 2)
throw new DTypeException("mangled function identifier is too short!");
// is it main?
if ((id.length >= 6) && (id[2 .. 6] == "main")) {
DFunction dfunc = new DFunction();
// aww that's easy:
dfunc.name = "main";
dfunc.type = DType.Int;
dfunc.params.length = 1;
dfunc.params[0] = new DTypeArray(new DTypeArray(DType.Char));
return dfunc;
}
// Parse the name:
i = 2;
DFunction dfunc = new DFunction();
dfunc.name = extractidentifiers(id, i);
// function:
if (i >= id.length)
throw new DTypeException(format("expected F at position %d!", i));
if (id[i] == 'F') {
// extract all the parameters:
++i;
dfunc.params.length = 0;
while (i < id.length) {
if (id[i] == 'Z') break;
// Add the parameter:
dfunc.params.length = dfunc.params.length + 1;
dfunc.params[length - 1] = extracttypeinfo(id, i);
}
// extract the return type:
if ((i >= id.length) || (id[i] != 'Z'))
throw new DTypeException(format("Z expected at position %d!", i));
// skip the Z cuz we know it's a return type:
++i;
dfunc.type = extracttypeinfo(id, i);
version (error_extrachars) {
// check for extra characters:
if (i < id.length)
throw new DTypeException(format("%d extra characters at position %d", id.length - i, i));
}
// Return the DFunction as a DSymbol:
return dfunc;
} else {
// should always be a function if it has _D linkage!
throw new DTypeException(format("expected F at position %d!", i));
}
// Check the type:
} else if (id[1 .. 6] == "Class") {
i = 7;
return new DClass(extractidentifiers(id, i));
// Not sure what to do with these:
/+
} else if (id[1 .. 5] == "init") {
i = 6;
printf("init %.*s\n", extractidentifiers(id, i));
} else if (id[1 .. 5] == "vtbl") {
i = 6;
printf("vtbl %.*s\n", extractidentifiers(id, i));
} else if (id[1 .. 8] == "modctor") {
i = 9;
printf("ctor %.*s\n", extractidentifiers(id, i));
} else if (id[1 .. 8] == "moddtor") {
i = 9;
printf("dtor %.*s\n", extractidentifiers(id, i));
+/
} else if (id[1 .. 11] == "ModuleInfo") {
i = 12;
return new DModule(extractidentifiers(id, i));
}
return null;
}
// Got nothin' to return here:
return null;
}
}
// Simple test program:
int main(char[][] args) {
static char[][] testcases = [
// these were taken from phobos.lib:
"_D3std6stream4File5_ctorFT3std1c7windows7windows6HANDLEE8FileModeZC3std6stream4File",
"__Class_3std6socket9UdpSocket",
"_D3std6stream4File6handleFZT3std1c7windows7windows6HANDLE",
"_D3std6stream12BufferedFile6createFAaE8FileModeZv",
"_D3std5math24polyFeAeZe",
"_D3std3uri15decodeComponentFAaZAa",
"_D3std7windows8registry17Reg_CreateKeyExA_FT3std7windows8registry4HKEYAakE6REGSAMPvJT3std7windows8registry4HKEYJkZi",
"_D3std6string5ifindFAawZi",
"_D3std6stream12EndianStream4readFJqZv",
// these were taken from the compiled EXE of this module:
"_D8demangle18extractidentifiersFAaKiZAa",
"_D8demangle15extracttypeinfoFAaKiZAa",
"_Dmain"
];
// Create the symbol extractor:
DSymbolExtractor dse = new DSymbolExtractor();
printf("\n");
if (args.length <= 1) {
// Use it on each test case:
foreach (char[] test; testcases) {
DSymbol dsym = dse.demangle(test);
// Print out the demangled symbol:
if (!(dsym is null)) {
version (ansi_color)
printf("%.*s\n", dsym.toANSIString());
else
printf("%.*s\n", dsym.toString());
delete dsym;
}
}
} else {
// Use it on the argument:
DSymbol dsym = dse.demangle(args[1]);
// Print out the demangled symbol:
if (!(dsym is null)) {
version (ansi_color)
printf("%.*s\n", dsym.toANSIString());
else
printf("%.*s\n", dsym.toString());
delete dsym;
}
}
printf("\n");
return 0;
}
//
// Demangling algorithm:
//
// 1. check the prefix of the mangled name.
// a. if _D then D-linkage function
// b. if __Class_ then class definition
// c. if __init_ then init-table for class
// d. if __vtbl_ then inherited class/interface for class
// e. if __modctor_ then constructor for class
// f. if __moddtor_ then destructor for class
// g. if __ModuleInfo_ then module definition
// 2. To parse an identifier:
// 1. read digits until non-digit character
// 2. convert that collection of digits to integer
// 3. use integer as length to extract identifier
// 4. suffix identifier with .
// 5. repeat steps 1-4 until no initial digit character found.
// 3. To parse the parameter list of a function definition:
// 1. make sure function starts with '_D', has an identifier, and then an 'F'
// 2. check demangling type table function "extracttypeinfo" to appropriate action.
// 3. all lower-case letters are basic types
// 4. all upper-case letters are complex types (like arrays, structs, classes, etc)
// 5. upper-case letters are either followed by lower-case letters (basic types) or
// identifiers.
// 6. function definition ends with Z followed by a type for the return type.
//