blob: 4f0ba1c4aa75d10ec26af3d3e656dc2b6921d218 [file] [log] [blame]
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001//===-------------------------- cxa_demangle.cpp --------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "cxa_demangle.h"
11
12#include <stdlib.h>
13#include <string.h>
14#include <ctype.h>
15#include <stdio.h>
16#include <new>
17#include <algorithm>
18#include <assert.h>
19
20
21#ifdef DEBUGGING
22
23#include <string>
24#include <typeinfo>
25
26#endif
27
28namespace __cxxabiv1
29{
30
31namespace __libcxxabi
32{
33
34#pragma GCC visibility push(hidden)
35
36class __node
37{
38 __node(const __node&);
39 __node& operator=(const __node&);
40public:
41 const char* __name_;
42 size_t __size_;
43 __node* __left_;
44 __node* __right_;
45 long double __value_;
46 long __cached_size_;
47public:
48 __node()
49 : __name_(0), __size_(0), __left_(0), __right_(0), __cached_size_(-1)
50 {}
51 virtual ~__node() {};
52
53 void reset_cached_size()
54 {
55 __cached_size_ = -1;
56 if (__left_)
57 __left_->reset_cached_size();
58 if (__right_)
59 __right_->reset_cached_size();
60 }
61
62 virtual size_t first_size() const {return 0;}
63 virtual size_t second_size() const {return 0;}
64 virtual size_t size() const
65 {
66 if (__cached_size_ == -1)
67 const_cast<long&>(__cached_size_) = first_size() + second_size();
68 return __cached_size_;
69 }
70 virtual char* first_demangled_name(char* buf) const {return buf;}
71 virtual char* second_demangled_name(char* buf) const {return buf;}
72 virtual char* get_demangled_name(char* buf) const
73 {
74 return second_demangled_name(first_demangled_name(buf));
75 }
76 virtual size_t base_size() const {return size();}
77 virtual char* get_base_name(char* buf) const
78 {
79 return get_demangled_name(buf);
80 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +000081
82 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +000083 {
84 return false;
85 }
86 virtual bool is_ctor_dtor_conv() const
87 {
88 return false;
89 }
90 virtual __node* base_name() const
91 {
92 return const_cast<__node*>(this);
93 }
94 virtual bool is_reference_or_pointer_to_function_or_array() const
95 {
96 return false;
97 }
98 virtual bool is_function() const
99 {
100 return false;
101 }
102 virtual bool is_cv_qualifer() const
103 {
104 return false;
105 }
106 virtual bool is_array() const
107 {
108 return false;
109 }
110
111 virtual bool fix_forward_references(__node**, __node**)
112 {
113 return true;
114 }
115 virtual __node* extract_cv(__node*&) const
116 {
117 return 0;
118 }
119 virtual size_t list_len() const
120 {
121 return 0;
122 }
123 virtual bool is_sub() const
124 {
125 return false;
126 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000127};
128
129#ifdef DEBUGGING
130
131void display(__node* x, int indent = 0)
132{
133 if (x)
134 {
135 for (int i = 0; i < 2*indent; ++i)
136 printf(" ");
137 std::string buf(x->size(), '\0');
Howard Hinnantab87dcf2011-12-15 20:02:15 +0000138 x->get_demangled_name(&buf.front());
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000139 printf("%s %s, %p\n", typeid(*x).name(), buf.c_str(), x);
140 display(x->__left_, indent+1);
141 display(x->__right_, indent+1);
142 }
143}
144
145#endif
146
147class __vtable
148 : public __node
149{
150 static const ptrdiff_t n = sizeof("vtable for ") - 1;
151public:
152 __vtable(__node* type)
153 {
154 __right_ = type;
155 }
156
157 virtual size_t first_size() const
158 {
159 if (__cached_size_ == -1)
160 const_cast<long&>(__cached_size_) = n + __right_->size();
161 return __cached_size_;
162 }
163 virtual char* first_demangled_name(char* buf) const
164 {
165 strncpy(buf, "vtable for ", n);
166 return __right_->get_demangled_name(buf+n);
167 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000168 virtual __node* base_name() const
169 {
170 return __right_->base_name();
171 }
172 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
173 {
174 return __right_->fix_forward_references(t_begin, t_end);
175 }
176};
177
178class __VTT
179 : public __node
180{
181 static const ptrdiff_t n = sizeof("VTT for ") - 1;
182public:
183 __VTT(__node* type)
184 {
185 __right_ = type;
186 }
187
188 virtual size_t first_size() const
189 {
190 if (__cached_size_ == -1)
191 const_cast<long&>(__cached_size_) = n + __right_->size();
192 return __cached_size_;
193 }
194 virtual char* first_demangled_name(char* buf) const
195 {
196 strncpy(buf, "VTT for ", n);
197 return __right_->get_demangled_name(buf+n);
198 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000199 virtual __node* base_name() const
200 {
201 return __right_->base_name();
202 }
203 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
204 {
205 return __right_->fix_forward_references(t_begin, t_end);
206 }
207};
208
Howard Hinnantf2700352011-12-09 20:07:56 +0000209class __construction_vtable
210 : public __node
211{
212 static const ptrdiff_t n = sizeof("construction vtable for ") - 1 + 4;
213public:
214 __construction_vtable(__node* left, __node* right)
215 {
216 __left_ = left;
217 __right_ = right;
218 }
219
220 virtual size_t first_size() const
221 {
222 if (__cached_size_ == -1)
223 const_cast<long&>(__cached_size_) = n + __left_->size()
224 + __right_->size();
225 return __cached_size_;
226 }
227 virtual char* first_demangled_name(char* buf) const
228 {
229 strncpy(buf, "construction vtable for ", n-4);
230 buf = __left_->get_demangled_name(buf+n-4);
231 *buf++ = '-';
232 *buf++ = 'i';
233 *buf++ = 'n';
234 *buf++ = '-';
235 return __right_->get_demangled_name(buf);
236 }
Howard Hinnantf2700352011-12-09 20:07:56 +0000237 virtual __node* base_name() const
238 {
239 return __right_->base_name();
240 }
241 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
242 {
243 bool r = true;
244 if (__left_)
245 r = __left_->fix_forward_references(t_begin, t_end);
246 return r && __right_->fix_forward_references(t_begin, t_end);
247 }
248};
249
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000250class __typeinfo
251 : public __node
252{
253 static const ptrdiff_t n = sizeof("typeinfo for ") - 1;
254public:
255 __typeinfo(__node* type)
256 {
257 __right_ = type;
258 }
259
260 virtual size_t first_size() const
261 {
262 if (__cached_size_ == -1)
263 const_cast<long&>(__cached_size_) = n + __right_->size();
264 return __cached_size_;
265 }
266 virtual char* first_demangled_name(char* buf) const
267 {
268 strncpy(buf, "typeinfo for ", n);
269 return __right_->get_demangled_name(buf+n);
270 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000271 virtual __node* base_name() const
272 {
273 return __right_->base_name();
274 }
275 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
276 {
277 return __right_->fix_forward_references(t_begin, t_end);
278 }
279};
280
281class __typeinfo_name
282 : public __node
283{
284 static const ptrdiff_t n = sizeof("typeinfo name for ") - 1;
285public:
286 __typeinfo_name(__node* type)
287 {
288 __right_ = type;
289 }
290
291 virtual size_t first_size() const
292 {
293 if (__cached_size_ == -1)
294 const_cast<long&>(__cached_size_) = n + __right_->size();
295 return __cached_size_;
296 }
297 virtual char* first_demangled_name(char* buf) const
298 {
299 strncpy(buf, "typeinfo name for ", n);
300 return __right_->get_demangled_name(buf+n);
301 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000302 virtual __node* base_name() const
303 {
304 return __right_->base_name();
305 }
306 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
307 {
308 return __right_->fix_forward_references(t_begin, t_end);
309 }
310};
311
312class __covariant_return_thunk
313 : public __node
314{
315 static const ptrdiff_t n = sizeof("covariant return thunk to ") - 1;
316public:
317 __covariant_return_thunk(__node* type)
318 {
319 __right_ = type;
320 }
321
322 virtual size_t first_size() const
323 {
324 if (__cached_size_ == -1)
325 const_cast<long&>(__cached_size_) = n + __right_->size();
326 return __cached_size_;
327 }
328 virtual char* first_demangled_name(char* buf) const
329 {
330 strncpy(buf, "covariant return thunk to ", n);
331 return __right_->get_demangled_name(buf+n);
332 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000333 virtual __node* base_name() const
334 {
335 return __right_->base_name();
336 }
337 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
338 {
339 return __right_->fix_forward_references(t_begin, t_end);
340 }
341};
342
343class __virtual_thunk
344 : public __node
345{
346 static const size_t n = sizeof("virtual thunk to ") - 1;
347public:
348 __virtual_thunk(__node* type)
349 {
350 __right_ = type;
351 }
352
353 virtual size_t first_size() const
354 {
355 if (__cached_size_ == -1)
356 const_cast<long&>(__cached_size_) = n + __right_->size();
357 return __cached_size_;
358 }
359 virtual char* first_demangled_name(char* buf) const
360 {
361 strncpy(buf, "virtual thunk to ", n);
362 return __right_->get_demangled_name(buf+n);
363 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000364 virtual __node* base_name() const
365 {
366 return __right_->base_name();
367 }
368 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
369 {
370 return __right_->fix_forward_references(t_begin, t_end);
371 }
372};
373
374class __non_virtual_thunk
375 : public __node
376{
377 static const size_t n = sizeof("non-virtual thunk to ") - 1;
378public:
379 __non_virtual_thunk(__node* type)
380 {
381 __right_ = type;
382 }
383
384 virtual size_t first_size() const
385 {
386 if (__cached_size_ == -1)
387 const_cast<long&>(__cached_size_) = n + __right_->size();
388 return __cached_size_;
389 }
390 virtual char* first_demangled_name(char* buf) const
391 {
392 strncpy(buf, "non-virtual thunk to ", n);
393 return __right_->get_demangled_name(buf+n);
394 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000395 virtual __node* base_name() const
396 {
397 return __right_->base_name();
398 }
399 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
400 {
401 return __right_->fix_forward_references(t_begin, t_end);
402 }
403};
404
405class __guard_variable
406 : public __node
407{
408 static const size_t n = sizeof("guard variable for ") - 1;
409public:
410 __guard_variable(__node* type)
411 {
412 __right_ = type;
413 }
414
415 virtual size_t first_size() const
416 {
417 if (__cached_size_ == -1)
418 const_cast<long&>(__cached_size_) = n + __right_->size();
419 return __cached_size_;
420 }
421 virtual char* first_demangled_name(char* buf) const
422 {
423 strncpy(buf, "guard variable for ", n);
424 return __right_->get_demangled_name(buf+n);
425 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000426 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
427 {
428 return __right_->fix_forward_references(t_begin, t_end);
429 }
430};
431
Howard Hinnantf2700352011-12-09 20:07:56 +0000432class __reference_temporary
433 : public __node
434{
435 static const size_t n = sizeof("reference temporary for ") - 1;
436public:
437 __reference_temporary(__node* type)
438 {
439 __right_ = type;
440 }
441
442 virtual size_t first_size() const
443 {
444 if (__cached_size_ == -1)
445 const_cast<long&>(__cached_size_) = n + __right_->size();
446 return __cached_size_;
447 }
448 virtual char* first_demangled_name(char* buf) const
449 {
450 strncpy(buf, "reference temporary for ", n);
451 return __right_->get_demangled_name(buf+n);
452 }
Howard Hinnantf2700352011-12-09 20:07:56 +0000453 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
454 {
455 return __right_->fix_forward_references(t_begin, t_end);
456 }
457};
458
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000459class __source_name
460 : public __node
461{
462public:
463 __source_name(const char* __name, unsigned __size)
464 {
465 __name_ = __name;
466 __size_ = __size;
467 }
468
469 virtual size_t first_size() const
470 {
471 if (__cached_size_ == -1)
472 {
473 if (__size_ >= 10 && strncmp(__name_, "_GLOBAL__N", 10) == 0)
474 const_cast<long&>(__cached_size_) = 21;
475 else
476 const_cast<long&>(__cached_size_) = __size_;
477 }
478 return __cached_size_;
479 }
480 virtual char* first_demangled_name(char* buf) const
481 {
482 if (__size_ >= 10 && strncmp(__name_, "_GLOBAL__N", 10) == 0)
483 return strncpy(buf, "(anonymous namespace)", 21) + 21;
484 return strncpy(buf, __name_, __size_) + __size_;
485 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000486};
487
488class __operator_new
489 : public __node
490{
491public:
492
493 virtual size_t first_size() const {return sizeof("operator new") - 1;}
494 virtual char* first_demangled_name(char* buf) const
495 {
496 return strncpy(buf, "operator new", sizeof("operator new") - 1) +
497 sizeof("operator new") - 1;
498 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000499};
500
501class __operator_new_array
502 : public __node
503{
504public:
505
506 virtual size_t first_size() const {return sizeof("operator new[]") - 1;}
507 virtual char* first_demangled_name(char* buf) const
508 {
509 return strncpy(buf, "operator new[]", sizeof("operator new[]") - 1) +
510 sizeof("operator new[]") - 1;
511 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000512};
513
514class __operator_delete
515 : public __node
516{
517public:
518
519 virtual size_t first_size() const {return sizeof("operator delete") - 1;}
520 virtual char* first_demangled_name(char* buf) const
521 {
522 return strncpy(buf, "operator delete", sizeof("operator delete") - 1) +
523 sizeof("operator delete") - 1;
524 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000525};
526
527class __operator_delete_array
528 : public __node
529{
530public:
531
532 virtual size_t first_size() const {return sizeof("operator delete[]") - 1;}
533 virtual char* first_demangled_name(char* buf) const
534 {
535 return strncpy(buf, "operator delete[]", sizeof("operator delete[]") - 1) +
536 sizeof("operator delete[]") - 1;
537 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000538};
539
540class __operator_logical_and
541 : public __node
542{
543public:
544
545 __operator_logical_and() {}
546 __operator_logical_and(__node* op1, __node* op2)
547 {
548 __left_ = op1;
549 __right_ = op2;
550 }
551 virtual size_t first_size() const
552 {
553 if (__cached_size_ == -1)
554 {
555 if (__left_)
556 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
557 else
558 const_cast<long&>(__cached_size_) = sizeof("operator&&") - 1;
559 }
560 return __cached_size_;
561 }
562 virtual char* first_demangled_name(char* buf) const
563 {
564 if (__left_)
565 {
566 *buf++ = '(';
567 buf = __left_->get_demangled_name(buf);
568 strncpy(buf, ") && (", 6);
569 buf += 6;
570 buf = __right_->get_demangled_name(buf);
571 *buf++ = ')';
572 }
573 else
574 {
575 strncpy(buf, "operator&&", sizeof("operator&&") - 1);
576 buf += sizeof("operator&&") - 1;
577 }
578 return buf;
579 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000580 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
581 {
582 bool r = true;
583 if (__left_)
584 r = r && __left_->fix_forward_references(t_begin, t_end);
585 if (__right_)
586 r = r && __right_->fix_forward_references(t_begin, t_end);
587 return r;
588 }
589};
590
591class __operator_addressof
592 : public __node
593{
594public:
595
596 __operator_addressof() {}
597 explicit __operator_addressof(__node* op)
598 {
599 __left_ = op;
600 }
601 virtual size_t first_size() const
602 {
603 if (__cached_size_ == -1)
604 {
605 if (__left_)
606 const_cast<long&>(__cached_size_) = 3+__left_->size();
607 else
608 const_cast<long&>(__cached_size_) = sizeof("operator&") - 1;
609 }
610 return __cached_size_;
611 }
612 virtual char* first_demangled_name(char* buf) const
613 {
614 if (__left_)
615 {
616 *buf++ = '&';
617 *buf++ = '(';
618 buf = __left_->get_demangled_name(buf);
619 *buf++ = ')';
620 }
621 else
622 {
623 strncpy(buf, "operator&", sizeof("operator&") - 1);
624 buf += sizeof("operator&") - 1;
625 }
626 return buf;
627 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000628 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
629 {
630 if (__left_)
631 return __left_->fix_forward_references(t_begin, t_end);
632 return true;
633 }
634};
635
636class __operator_bit_and
637 : public __node
638{
639public:
640
641 __operator_bit_and() {}
642 __operator_bit_and(__node* op1, __node* op2)
643 {
644 __left_ = op1;
645 __right_ = op2;
646 }
647 virtual size_t first_size() const
648 {
649 if (__cached_size_ == -1)
650 {
651 if (__left_)
652 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
653 else
654 const_cast<long&>(__cached_size_) = sizeof("operator&") - 1;
655 }
656 return __cached_size_;
657 }
658 virtual char* first_demangled_name(char* buf) const
659 {
660 if (__left_)
661 {
662 *buf++ = '(';
663 buf = __left_->get_demangled_name(buf);
664 strncpy(buf, ") & (", 5);
665 buf += 5;
666 buf = __right_->get_demangled_name(buf);
667 *buf++ = ')';
668 }
669 else
670 {
671 strncpy(buf, "operator&", sizeof("operator&") - 1);
672 buf += sizeof("operator&") - 1;
673 }
674 return buf;
675 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000676 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
677 {
678 bool r = true;
679 if (__left_)
680 r = r && __left_->fix_forward_references(t_begin, t_end);
681 if (__right_)
682 r = r && __right_->fix_forward_references(t_begin, t_end);
683 return r;
684 }
685};
686
687class __operator_and_equal
688 : public __node
689{
690public:
691
692 __operator_and_equal() {}
693 __operator_and_equal(__node* op1, __node* op2)
694 {
695 __left_ = op1;
696 __right_ = op2;
697 }
698 virtual size_t first_size() const
699 {
700 if (__cached_size_ == -1)
701 {
702 if (__left_)
703 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
704 else
705 const_cast<long&>(__cached_size_) = sizeof("operator&=") - 1;
706 }
707 return __cached_size_;
708 }
709 virtual char* first_demangled_name(char* buf) const
710 {
711 if (__left_)
712 {
713 *buf++ = '(';
714 buf = __left_->get_demangled_name(buf);
715 strncpy(buf, ") &= (", 6);
716 buf += 6;
717 buf = __right_->get_demangled_name(buf);
718 *buf++ = ')';
719 }
720 else
721 {
722 strncpy(buf, "operator&=", sizeof("operator&=") - 1);
723 buf += sizeof("operator&=") - 1;
724 }
725 return buf;
726 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000727 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
728 {
729 bool r = true;
730 if (__left_)
731 r = r && __left_->fix_forward_references(t_begin, t_end);
732 if (__right_)
733 r = r && __right_->fix_forward_references(t_begin, t_end);
734 return r;
735 }
736};
737
738class __operator_equal
739 : public __node
740{
741public:
742
743 __operator_equal() {}
744 __operator_equal(__node* op1, __node* op2)
745 {
746 __left_ = op1;
747 __right_ = op2;
748 }
749 virtual size_t first_size() const
750 {
751 if (__cached_size_ == -1)
752 {
753 if (__left_)
754 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
755 else
756 const_cast<long&>(__cached_size_) = sizeof("operator=") - 1;
757 }
758 return __cached_size_;
759 }
760 virtual char* first_demangled_name(char* buf) const
761 {
762 if (__left_)
763 {
764 *buf++ = '(';
765 buf = __left_->get_demangled_name(buf);
766 strncpy(buf, ") = (", 5);
767 buf += 5;
768 buf = __right_->get_demangled_name(buf);
769 *buf++ = ')';
770 }
771 else
772 {
773 strncpy(buf, "operator=", sizeof("operator=") - 1);
774 buf += sizeof("operator=") - 1;
775 }
776 return buf;
777 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000778 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
779 {
780 bool r = true;
781 if (__left_)
782 r = r && __left_->fix_forward_references(t_begin, t_end);
783 if (__right_)
784 r = r && __right_->fix_forward_references(t_begin, t_end);
785 return r;
786 }
787};
788
789class __operator_alignof_type
790 : public __node
791{
792public:
793
794 __operator_alignof_type() {}
795 __operator_alignof_type(__node* op)
796 {
797 __right_ = op;
798 }
799 virtual size_t first_size() const
800 {
801 if (__cached_size_ == -1)
802 {
803 if (__right_)
804 const_cast<long&>(__cached_size_) = __right_->size() + 10;
805 else
806 const_cast<long&>(__cached_size_) = sizeof("operator alignof") - 1;
807 }
808 return __cached_size_;
809 }
810 virtual char* first_demangled_name(char* buf) const
811 {
812 if (__right_)
813 {
814 strncpy(buf, "alignof (", 9);
815 buf += 9;
816 buf = __right_->get_demangled_name(buf);
817 *buf++ = ')';
818 }
819 else
820 {
821 strncpy(buf, "operator alignof", sizeof("operator alignof") - 1);
822 buf += sizeof("operator alignof") - 1;
823 }
824 return buf;
825 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000826 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
827 {
828 if (__right_)
829 return __right_->fix_forward_references(t_begin, t_end);
830 return true;
831 }
832};
833
834class __operator_alignof_expression
835 : public __node
836{
837public:
838
839 __operator_alignof_expression() {}
840 __operator_alignof_expression(__node* op)
841 {
842 __right_ = op;
843 }
844 virtual size_t first_size() const
845 {
846 if (__cached_size_ == -1)
847 {
848 if (__right_)
849 const_cast<long&>(__cached_size_) = __right_->size() + 10;
850 else
851 const_cast<long&>(__cached_size_) = sizeof("operator alignof") - 1;
852 }
853 return __cached_size_;
854 }
855 virtual char* first_demangled_name(char* buf) const
856 {
857 if (__right_)
858 {
859 strncpy(buf, "alignof (", 9);
860 buf += 9;
861 buf = __right_->get_demangled_name(buf);
862 *buf++ = ')';
863 }
864 else
865 {
866 strncpy(buf, "operator alignof", sizeof("operator alignof") - 1);
867 buf += sizeof("operator alignof") - 1;
868 }
869 return buf;
870 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000871 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
872 {
873 if (__right_)
874 return __right_->fix_forward_references(t_begin, t_end);
875 return true;
876 }
877};
878
879class __operator_paren
880 : public __node
881{
882public:
883
884 virtual size_t first_size() const {return sizeof("operator()") - 1;}
885 virtual char* first_demangled_name(char* buf) const
886 {
887 strncpy(buf, "operator()", sizeof("operator()") - 1);
888 return buf + sizeof("operator()") - 1;
889 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000890};
891
892class __operator_comma
893 : public __node
894{
895public:
896
897 __operator_comma() {}
898 __operator_comma(__node* op1, __node* op2)
899 {
900 __left_ = op1;
901 __right_ = op2;
902 }
903 virtual size_t first_size() const
904 {
905 if (__cached_size_ == -1)
906 {
907 if (__left_)
908 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
909 else
910 const_cast<long&>(__cached_size_) = sizeof("operator,") - 1;
911 }
912 return __cached_size_;
913 }
914 virtual char* first_demangled_name(char* buf) const
915 {
916 if (__left_)
917 {
918 *buf++ = '(';
919 buf = __left_->get_demangled_name(buf);
920 strncpy(buf, ") , (", 5);
921 buf += 5;
922 buf = __right_->get_demangled_name(buf);
923 *buf++ = ')';
924 }
925 else
926 {
927 strncpy(buf, "operator,", sizeof("operator,") - 1);
928 buf += sizeof("operator,") - 1;
929 }
930 return buf;
931 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000932 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
933 {
934 bool r = true;
935 if (__left_)
936 r = r && __left_->fix_forward_references(t_begin, t_end);
937 if (__right_)
938 r = r && __right_->fix_forward_references(t_begin, t_end);
939 return r;
940 }
941};
942
943class __operator_tilda
944 : public __node
945{
946public:
947
948 __operator_tilda() {}
949 explicit __operator_tilda(__node* op)
950 {
951 __left_ = op;
952 }
953 virtual size_t first_size() const
954 {
955 if (__cached_size_ == -1)
956 {
957 if (__left_)
958 const_cast<long&>(__cached_size_) = 3+__left_->size();
959 else
960 const_cast<long&>(__cached_size_) = sizeof("operator~") - 1;
961 }
962 return __cached_size_;
963 }
964 virtual char* first_demangled_name(char* buf) const
965 {
966 if (__left_)
967 {
968 *buf++ = '~';
969 *buf++ = '(';
970 buf = __left_->get_demangled_name(buf);
971 *buf++ = ')';
972 }
973 else
974 {
975 strncpy(buf, "operator~", sizeof("operator~") - 1);
976 buf += sizeof("operator~") - 1;
977 }
978 return buf;
979 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +0000980 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
981 {
982 if (__left_)
983 return __left_->fix_forward_references(t_begin, t_end);
984 return true;
985 }
986};
987
988class __operator_cast
989 : public __node
990{
991 static const size_t n = sizeof("operator ") - 1;
992public:
993
994 explicit __operator_cast(__node* type)
995 {
996 __right_ = type;
997 }
998 __operator_cast(__node* type, __node* arg)
999 {
1000 __size_ = 1;
1001 __right_ = type;
1002 __left_ = arg;
1003 }
1004 virtual size_t first_size() const
1005 {
1006 if (__cached_size_ == -1)
1007 {
1008 size_t off;
1009 if (__size_)
1010 {
1011 off = 4;
1012 off += __right_->size();
1013 if (__left_)
1014 off += __left_->size();
1015 }
1016 else
1017 off = n + __right_->size();;
1018 const_cast<long&>(__cached_size_) = off;
1019 }
1020 return __cached_size_;
1021 }
1022 virtual char* first_demangled_name(char* buf) const
1023 {
1024 if (__size_)
1025 {
1026 *buf++ = '(';
1027 buf = __right_->get_demangled_name(buf);
1028 *buf++ = ')';
1029 *buf++ = '(';
1030 if (__left_)
1031 buf = __left_->get_demangled_name(buf);
1032 *buf++ = ')';
1033 }
1034 else
1035 {
1036 strncpy(buf, "operator ", n);
1037 buf = __right_->get_demangled_name(buf+n);
1038 }
1039 return buf;
1040 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001041 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1042 {
1043 bool r = true;
1044 if (__left_)
1045 r = r && __left_->fix_forward_references(t_begin, t_end);
1046 r = r && __right_->fix_forward_references(t_begin, t_end);
1047 return r;
1048 }
1049 virtual bool is_ctor_dtor_conv() const
1050 {
1051 return true;
1052 }
1053};
1054
1055class __cast_literal
1056 : public __node
1057{
1058public:
1059
1060 __cast_literal(__node* type, const char* f, const char* l)
1061 {
1062 __left_ = type;
1063 __name_ = f;
1064 __size_ = l - f;
1065 }
1066 virtual size_t first_size() const
1067 {
1068 if (__cached_size_ == -1)
1069 const_cast<long&>(__cached_size_) = 2 + __left_->size() + __size_;
1070 return __cached_size_;
1071 }
1072 virtual char* first_demangled_name(char* buf) const
1073 {
1074 *buf++ = '(';
1075 buf = __left_->get_demangled_name(buf);
1076 *buf++ = ')';
1077 strncpy(buf, __name_, __size_);
1078 return buf + __size_;
1079 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001080 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1081 {
1082 return __left_->fix_forward_references(t_begin, t_end);
1083 }
1084};
1085
1086class __operator_dereference
1087 : public __node
1088{
1089public:
1090
1091 __operator_dereference() {}
1092 explicit __operator_dereference(__node* op)
1093 {
1094 __left_ = op;
1095 }
1096 virtual size_t first_size() const
1097 {
1098 if (__cached_size_ == -1)
1099 {
1100 if (__left_)
1101 const_cast<long&>(__cached_size_) = 3+__left_->size();
1102 else
1103 const_cast<long&>(__cached_size_) = sizeof("operator*") - 1;
1104 }
1105 return __cached_size_;
1106 }
1107 virtual char* first_demangled_name(char* buf) const
1108 {
1109 if (__left_)
1110 {
1111 *buf++ = '*';
1112 *buf++ = '(';
1113 buf = __left_->get_demangled_name(buf);
1114 *buf++ = ')';
1115 }
1116 else
1117 {
1118 strncpy(buf, "operator*", sizeof("operator*") - 1);
1119 buf += sizeof("operator*") - 1;
1120 }
1121 return buf;
1122 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001123 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1124 {
1125 if (__left_)
1126 return __left_->fix_forward_references(t_begin, t_end);
1127 return true;
1128 }
1129};
1130
1131class __operator_divide
1132 : public __node
1133{
1134public:
1135
1136 __operator_divide() {}
1137 __operator_divide(__node* op1, __node* op2)
1138 {
1139 __left_ = op1;
1140 __right_ = op2;
1141 }
1142 virtual size_t first_size() const
1143 {
1144 if (__cached_size_ == -1)
1145 {
1146 if (__left_)
1147 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
1148 else
1149 const_cast<long&>(__cached_size_) = sizeof("operator/") - 1;
1150 }
1151 return __cached_size_;
1152 }
1153 virtual char* first_demangled_name(char* buf) const
1154 {
1155 if (__left_)
1156 {
1157 *buf++ = '(';
1158 buf = __left_->get_demangled_name(buf);
1159 strncpy(buf, ") / (", 5);
1160 buf += 5;
1161 buf = __right_->get_demangled_name(buf);
1162 *buf++ = ')';
1163 }
1164 else
1165 {
1166 strncpy(buf, "operator/", sizeof("operator/") - 1);
1167 buf += sizeof("operator/") - 1;
1168 }
1169 return buf;
1170 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001171 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1172 {
1173 bool r = true;
1174 if (__left_)
1175 r = r && __left_->fix_forward_references(t_begin, t_end);
1176 if (__right_)
1177 r = r && __right_->fix_forward_references(t_begin, t_end);
1178 return r;
1179 }
1180};
1181
1182class __operator_divide_equal
1183 : public __node
1184{
1185public:
1186
1187 __operator_divide_equal() {}
1188 __operator_divide_equal(__node* op1, __node* op2)
1189 {
1190 __left_ = op1;
1191 __right_ = op2;
1192 }
1193 virtual size_t first_size() const
1194 {
1195 if (__cached_size_ == -1)
1196 {
1197 if (__left_)
1198 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1199 else
1200 const_cast<long&>(__cached_size_) = sizeof("operator/=") - 1;
1201 }
1202 return __cached_size_;
1203 }
1204 virtual char* first_demangled_name(char* buf) const
1205 {
1206 if (__left_)
1207 {
1208 *buf++ = '(';
1209 buf = __left_->get_demangled_name(buf);
1210 strncpy(buf, ") /= (", 6);
1211 buf += 6;
1212 buf = __right_->get_demangled_name(buf);
1213 *buf++ = ')';
1214 }
1215 else
1216 {
1217 strncpy(buf, "operator/=", sizeof("operator/=") - 1);
1218 buf += sizeof("operator/=") - 1;
1219 }
1220 return buf;
1221 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001222 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1223 {
1224 bool r = true;
1225 if (__left_)
1226 r = r && __left_->fix_forward_references(t_begin, t_end);
1227 if (__right_)
1228 r = r && __right_->fix_forward_references(t_begin, t_end);
1229 return r;
1230 }
1231};
1232
1233class __operator_xor
1234 : public __node
1235{
1236public:
1237
1238 __operator_xor() {}
1239 __operator_xor(__node* op1, __node* op2)
1240 {
1241 __left_ = op1;
1242 __right_ = op2;
1243 }
1244 virtual size_t first_size() const
1245 {
1246 if (__cached_size_ == -1)
1247 {
1248 if (__left_)
1249 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
1250 else
1251 const_cast<long&>(__cached_size_) = sizeof("operator^") - 1;
1252 }
1253 return __cached_size_;
1254 }
1255 virtual char* first_demangled_name(char* buf) const
1256 {
1257 if (__left_)
1258 {
1259 *buf++ = '(';
1260 buf = __left_->get_demangled_name(buf);
1261 strncpy(buf, ") ^ (", 5);
1262 buf += 5;
1263 buf = __right_->get_demangled_name(buf);
1264 *buf++ = ')';
1265 }
1266 else
1267 {
1268 strncpy(buf, "operator^", sizeof("operator^") - 1);
1269 buf += sizeof("operator^") - 1;
1270 }
1271 return buf;
1272 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001273 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1274 {
1275 bool r = true;
1276 if (__left_)
1277 r = r && __left_->fix_forward_references(t_begin, t_end);
1278 if (__right_)
1279 r = r && __right_->fix_forward_references(t_begin, t_end);
1280 return r;
1281 }
1282};
1283
1284class __operator_xor_equal
1285 : public __node
1286{
1287public:
1288
1289 __operator_xor_equal() {}
1290 __operator_xor_equal(__node* op1, __node* op2)
1291 {
1292 __left_ = op1;
1293 __right_ = op2;
1294 }
1295 virtual size_t first_size() const
1296 {
1297 if (__cached_size_ == -1)
1298 {
1299 if (__left_)
1300 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1301 else
1302 const_cast<long&>(__cached_size_) = sizeof("operator^=") - 1;
1303 }
1304 return __cached_size_;
1305 }
1306 virtual char* first_demangled_name(char* buf) const
1307 {
1308 if (__left_)
1309 {
1310 *buf++ = '('; // strncpy(buf, "(", 1);
1311 buf = __left_->get_demangled_name(buf);
1312 strncpy(buf, ") ^= (", 6);
1313 buf += 6;
1314 buf = __right_->get_demangled_name(buf);
1315 *buf++ = ')';
1316 }
1317 else
1318 {
1319 strncpy(buf, "operator^=", sizeof("operator^=") - 1);
1320 buf += sizeof("operator^=") - 1;
1321 }
1322 return buf;
1323 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001324 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1325 {
1326 bool r = true;
1327 if (__left_)
1328 r = r && __left_->fix_forward_references(t_begin, t_end);
1329 if (__right_)
1330 r = r && __right_->fix_forward_references(t_begin, t_end);
1331 return r;
1332 }
1333};
1334
1335class __operator_equality
1336 : public __node
1337{
1338public:
1339
1340 __operator_equality() {}
1341 __operator_equality(__node* op1, __node* op2)
1342 {
1343 __left_ = op1;
1344 __right_ = op2;
1345 }
1346 virtual size_t first_size() const
1347 {
1348 if (__cached_size_ == -1)
1349 {
1350 if (__left_)
1351 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1352 else
1353 const_cast<long&>(__cached_size_) = sizeof("operator==") - 1;
1354 }
1355 return __cached_size_;
1356 }
1357 virtual char* first_demangled_name(char* buf) const
1358 {
1359 if (__left_)
1360 {
1361 *buf++ = '(';
1362 buf = __left_->get_demangled_name(buf);
1363 strncpy(buf, ") == (", 6);
1364 buf += 6;
1365 buf = __right_->get_demangled_name(buf);
1366 *buf++ = ')';
1367 }
1368 else
1369 {
1370 strncpy(buf, "operator==", sizeof("operator==") - 1);
1371 buf += sizeof("operator==") - 1;
1372 }
1373 return buf;
1374 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001375 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1376 {
1377 bool r = true;
1378 if (__left_)
1379 r = r && __left_->fix_forward_references(t_begin, t_end);
1380 if (__right_)
1381 r = r && __right_->fix_forward_references(t_begin, t_end);
1382 return r;
1383 }
1384};
1385
1386class __operator_greater_equal
1387 : public __node
1388{
1389public:
1390
1391 __operator_greater_equal() {}
1392 __operator_greater_equal(__node* op1, __node* op2)
1393 {
1394 __left_ = op1;
1395 __right_ = op2;
1396 }
1397 virtual size_t first_size() const
1398 {
1399 if (__cached_size_ == -1)
1400 {
1401 if (__left_)
1402 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1403 else
1404 const_cast<long&>(__cached_size_) = sizeof("operator>=") - 1;
1405 }
1406 return __cached_size_;
1407 }
1408 virtual char* first_demangled_name(char* buf) const
1409 {
1410 if (__left_)
1411 {
1412 *buf++ = '(';
1413 buf = __left_->get_demangled_name(buf);
1414 strncpy(buf, ") >= (", 6);
1415 buf += 6;
1416 buf = __right_->get_demangled_name(buf);
1417 *buf++ = ')';
1418 }
1419 else
1420 {
1421 strncpy(buf, "operator>=", sizeof("operator>=") - 1);
1422 buf += sizeof("operator>=") - 1;
1423 }
1424 return buf;
1425 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001426 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1427 {
1428 bool r = true;
1429 if (__left_)
1430 r = r && __left_->fix_forward_references(t_begin, t_end);
1431 if (__right_)
1432 r = r && __right_->fix_forward_references(t_begin, t_end);
1433 return r;
1434 }
1435};
1436
1437class __operator_greater
1438 : public __node
1439{
1440public:
1441
1442 __operator_greater() {}
1443 __operator_greater(__node* op1, __node* op2)
1444 {
1445 __left_ = op1;
1446 __right_ = op2;
1447 }
1448 virtual size_t first_size() const
1449 {
1450 if (__cached_size_ == -1)
1451 {
1452 if (__left_)
1453 const_cast<long&>(__cached_size_) = __left_->size() + 9 + __right_->size();
1454 else
1455 const_cast<long&>(__cached_size_) = sizeof("operator>") - 1;
1456 }
1457 return __cached_size_;
1458 }
1459 virtual char* first_demangled_name(char* buf) const
1460 {
1461 if (__left_)
1462 {
1463 *buf++ = '(';
1464 *buf++ = '(';
1465 buf = __left_->get_demangled_name(buf);
1466 strncpy(buf, ") > (", 5);
1467 buf += 5;
1468 buf = __right_->get_demangled_name(buf);
1469 *buf++ = ')';
1470 *buf++ = ')';
1471 }
1472 else
1473 {
1474 strncpy(buf, "operator>", sizeof("operator>") - 1);
1475 buf += sizeof("operator>") - 1;
1476 }
1477 return buf;
1478 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001479 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1480 {
1481 bool r = true;
1482 if (__left_)
1483 r = r && __left_->fix_forward_references(t_begin, t_end);
1484 if (__right_)
1485 r = r && __right_->fix_forward_references(t_begin, t_end);
1486 return r;
1487 }
1488};
1489
1490class __operator_brackets
1491 : public __node
1492{
1493public:
1494
1495 virtual size_t first_size() const {return sizeof("operator[]") - 1;}
1496 virtual char* first_demangled_name(char* buf) const
1497 {
1498 strncpy(buf, "operator[]", sizeof("operator[]") - 1);
1499 return buf + sizeof("operator[]") - 1;
1500 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001501};
1502
1503class __operator_less_equal
1504 : public __node
1505{
1506public:
1507
1508 __operator_less_equal() {}
1509 __operator_less_equal(__node* op1, __node* op2)
1510 {
1511 __left_ = op1;
1512 __right_ = op2;
1513 }
1514 virtual size_t first_size() const
1515 {
1516 if (__cached_size_ == -1)
1517 {
1518 if (__left_)
1519 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1520 else
1521 const_cast<long&>(__cached_size_) = sizeof("operator<=") - 1;
1522 }
1523 return __cached_size_;
1524 }
1525 virtual char* first_demangled_name(char* buf) const
1526 {
1527 if (__left_)
1528 {
1529 *buf++ = '(';
1530 buf = __left_->get_demangled_name(buf);
1531 strncpy(buf, ") <= (", 6);
1532 buf += 6;
1533 buf = __right_->get_demangled_name(buf);
1534 *buf++ = ')';
1535 }
1536 else
1537 {
1538 strncpy(buf, "operator<=", sizeof("operator<=") - 1);
1539 buf += sizeof("operator<=") - 1;
1540 }
1541 return buf;
1542 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001543 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1544 {
1545 bool r = true;
1546 if (__left_)
1547 r = r && __left_->fix_forward_references(t_begin, t_end);
1548 if (__right_)
1549 r = r && __right_->fix_forward_references(t_begin, t_end);
1550 return r;
1551 }
1552};
1553
1554class __operator_less
1555 : public __node
1556{
1557public:
1558
1559 __operator_less() {}
1560 __operator_less(__node* op1, __node* op2)
1561 {
1562 __left_ = op1;
1563 __right_ = op2;
1564 }
1565 virtual size_t first_size() const
1566 {
1567 if (__cached_size_ == -1)
1568 {
1569 if (__left_)
1570 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
1571 else
1572 const_cast<long&>(__cached_size_) = sizeof("operator<") - 1;
1573 }
1574 return __cached_size_;
1575 }
1576 virtual char* first_demangled_name(char* buf) const
1577 {
1578 if (__left_)
1579 {
1580 *buf++ = '(';
1581 buf = __left_->get_demangled_name(buf);
1582 strncpy(buf, ") < (", 5);
1583 buf += 5;
1584 buf = __right_->get_demangled_name(buf);
1585 *buf++ = ')';
1586 }
1587 else
1588 {
1589 strncpy(buf, "operator<", sizeof("operator<") - 1);
1590 buf += sizeof("operator<") - 1;
1591 }
1592 return buf;
1593 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001594 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1595 {
1596 bool r = true;
1597 if (__left_)
1598 r = r && __left_->fix_forward_references(t_begin, t_end);
1599 if (__right_)
1600 r = r && __right_->fix_forward_references(t_begin, t_end);
1601 return r;
1602 }
1603};
1604
1605class __operator_left_shift
1606 : public __node
1607{
1608public:
1609
1610 __operator_left_shift() {}
1611 __operator_left_shift(__node* op1, __node* op2)
1612 {
1613 __left_ = op1;
1614 __right_ = op2;
1615 }
1616 virtual size_t first_size() const
1617 {
1618 if (__cached_size_ == -1)
1619 {
1620 if (__left_)
1621 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1622 else
1623 const_cast<long&>(__cached_size_) = sizeof("operator<<") - 1;
1624 }
1625 return __cached_size_;
1626 }
1627 virtual char* first_demangled_name(char* buf) const
1628 {
1629 if (__left_)
1630 {
1631 *buf++ = '(';
1632 buf = __left_->get_demangled_name(buf);
1633 strncpy(buf, ") << (", 6);
1634 buf += 6;
1635 buf = __right_->get_demangled_name(buf);
1636 *buf++ = ')';
1637 }
1638 else
1639 {
1640 strncpy(buf, "operator<<", sizeof("operator<<") - 1);
1641 buf += sizeof("operator<<") - 1;
1642 }
1643 return buf;
1644 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001645 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1646 {
1647 bool r = true;
1648 if (__left_)
1649 r = r && __left_->fix_forward_references(t_begin, t_end);
1650 if (__right_)
1651 r = r && __right_->fix_forward_references(t_begin, t_end);
1652 return r;
1653 }
1654};
1655
1656class __operator_left_shift_equal
1657 : public __node
1658{
1659public:
1660
1661 __operator_left_shift_equal() {}
1662 __operator_left_shift_equal(__node* op1, __node* op2)
1663 {
1664 __left_ = op1;
1665 __right_ = op2;
1666 }
1667 virtual size_t first_size() const
1668 {
1669 if (__cached_size_ == -1)
1670 {
1671 if (__left_)
1672 const_cast<long&>(__cached_size_) = __left_->size() + 9 + __right_->size();
1673 else
1674 const_cast<long&>(__cached_size_) = sizeof("operator<<=") - 1;
1675 }
1676 return __cached_size_;
1677 }
1678 virtual char* first_demangled_name(char* buf) const
1679 {
1680 if (__left_)
1681 {
1682 *buf++ = '(';
1683 buf = __left_->get_demangled_name(buf);
1684 strncpy(buf, ") <<= (", 7);
1685 buf += 7;
1686 buf = __right_->get_demangled_name(buf);
1687 *buf++ = ')';
1688 }
1689 else
1690 {
1691 strncpy(buf, "operator<<=", sizeof("operator<<=") - 1);
1692 buf += sizeof("operator<<=") - 1;
1693 }
1694 return buf;
1695 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001696 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1697 {
1698 bool r = true;
1699 if (__left_)
1700 r = r && __left_->fix_forward_references(t_begin, t_end);
1701 if (__right_)
1702 r = r && __right_->fix_forward_references(t_begin, t_end);
1703 return r;
1704 }
1705};
1706
1707class __operator_minus
1708 : public __node
1709{
1710public:
1711
1712 __operator_minus() {}
1713 __operator_minus(__node* op1, __node* op2)
1714 {
1715 __left_ = op1;
1716 __right_ = op2;
1717 }
1718 virtual size_t first_size() const
1719 {
1720 if (__cached_size_ == -1)
1721 {
1722 if (__left_)
1723 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
1724 else
1725 const_cast<long&>(__cached_size_) = sizeof("operator-") - 1;
1726 }
1727 return __cached_size_;
1728 }
1729 virtual char* first_demangled_name(char* buf) const
1730 {
1731 if (__left_)
1732 {
1733 *buf++ = '(';
1734 buf = __left_->get_demangled_name(buf);
1735 strncpy(buf, ") - (", 5);
1736 buf += 5;
1737 buf = __right_->get_demangled_name(buf);
1738 *buf++ = ')';
1739 }
1740 else
1741 {
1742 strncpy(buf, "operator-", sizeof("operator-") - 1);
1743 buf += sizeof("operator-") - 1;
1744 }
1745 return buf;
1746 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001747 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1748 {
1749 bool r = true;
1750 if (__left_)
1751 r = r && __left_->fix_forward_references(t_begin, t_end);
1752 if (__right_)
1753 r = r && __right_->fix_forward_references(t_begin, t_end);
1754 return r;
1755 }
1756};
1757
1758class __operator_minus_equal
1759 : public __node
1760{
1761public:
1762
1763 __operator_minus_equal() {}
1764 __operator_minus_equal(__node* op1, __node* op2)
1765 {
1766 __left_ = op1;
1767 __right_ = op2;
1768 }
1769 virtual size_t first_size() const
1770 {
1771 if (__cached_size_ == -1)
1772 {
1773 if (__left_)
1774 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1775 else
1776 const_cast<long&>(__cached_size_) = sizeof("operator-=") - 1;
1777 }
1778 return __cached_size_;
1779 }
1780 virtual char* first_demangled_name(char* buf) const
1781 {
1782 if (__left_)
1783 {
1784 *buf++ = '(';
1785 buf = __left_->get_demangled_name(buf);
1786 strncpy(buf, ") -= (", 6);
1787 buf += 6;
1788 buf = __right_->get_demangled_name(buf);
1789 *buf++ = ')';
1790 }
1791 else
1792 {
1793 strncpy(buf, "operator-=", sizeof("operator-=") - 1);
1794 buf += sizeof("operator-=") - 1;
1795 }
1796 return buf;
1797 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001798 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1799 {
1800 bool r = true;
1801 if (__left_)
1802 r = r && __left_->fix_forward_references(t_begin, t_end);
1803 if (__right_)
1804 r = r && __right_->fix_forward_references(t_begin, t_end);
1805 return r;
1806 }
1807};
1808
1809class __operator_times
1810 : public __node
1811{
1812public:
1813
1814 __operator_times() {}
1815 __operator_times(__node* op1, __node* op2)
1816 {
1817 __left_ = op1;
1818 __right_ = op2;
1819 }
1820 virtual size_t first_size() const
1821 {
1822 if (__cached_size_ == -1)
1823 {
1824 if (__left_)
1825 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
1826 else
1827 const_cast<long&>(__cached_size_) = sizeof("operator*") - 1;
1828 }
1829 return __cached_size_;
1830 }
1831 virtual char* first_demangled_name(char* buf) const
1832 {
1833 if (__left_)
1834 {
1835 *buf++ = '(';
1836 buf = __left_->get_demangled_name(buf);
1837 strncpy(buf, ") * (", 5);
1838 buf += 5;
1839 buf = __right_->get_demangled_name(buf);
1840 *buf++ = ')';
1841 }
1842 else
1843 {
1844 strncpy(buf, "operator*", sizeof("operator*") - 1);
1845 buf += sizeof("operator*") - 1;
1846 }
1847 return buf;
1848 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001849 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1850 {
1851 bool r = true;
1852 if (__left_)
1853 r = r && __left_->fix_forward_references(t_begin, t_end);
1854 if (__right_)
1855 r = r && __right_->fix_forward_references(t_begin, t_end);
1856 return r;
1857 }
1858};
1859
1860class __operator_times_equal
1861 : public __node
1862{
1863public:
1864
1865 __operator_times_equal() {}
1866 __operator_times_equal(__node* op1, __node* op2)
1867 {
1868 __left_ = op1;
1869 __right_ = op2;
1870 }
1871 virtual size_t first_size() const
1872 {
1873 if (__cached_size_ == -1)
1874 {
1875 if (__left_)
1876 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1877 else
1878 const_cast<long&>(__cached_size_) = sizeof("operator*=") - 1;
1879 }
1880 return __cached_size_;
1881 }
1882 virtual char* first_demangled_name(char* buf) const
1883 {
1884 if (__left_)
1885 {
1886 *buf++ = '(';
1887 buf = __left_->get_demangled_name(buf);
1888 strncpy(buf, ") *= (", 6);
1889 buf += 6;
1890 buf = __right_->get_demangled_name(buf);
1891 *buf++ = ')';
1892 }
1893 else
1894 {
1895 strncpy(buf, "operator*=", sizeof("operator*=") - 1);
1896 buf += sizeof("operator*=") - 1;
1897 }
1898 return buf;
1899 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001900 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1901 {
1902 bool r = true;
1903 if (__left_)
1904 r = r && __left_->fix_forward_references(t_begin, t_end);
1905 if (__right_)
1906 r = r && __right_->fix_forward_references(t_begin, t_end);
1907 return r;
1908 }
1909};
1910
1911class __operator_decrement
1912 : public __node
1913{
1914public:
1915
1916 __operator_decrement() {}
1917 explicit __operator_decrement(bool prefix, __node* op)
1918 {
1919 __size_ = prefix;
1920 __left_ = op;
1921 }
1922 virtual size_t first_size() const
1923 {
1924 if (__cached_size_ == -1)
1925 {
1926 if (__left_)
1927 const_cast<long&>(__cached_size_) = 4+__left_->size();
1928 else
1929 const_cast<long&>(__cached_size_) = sizeof("operator--") - 1;
1930 }
1931 return __cached_size_;
1932 }
1933 virtual char* first_demangled_name(char* buf) const
1934 {
1935 if (__left_)
1936 {
1937 if (__size_)
1938 {
1939 *buf++ = '-';
1940 *buf++ = '-';
1941 *buf++ = '(';
1942 }
1943 else
1944 *buf++ = '(';
1945 buf = __left_->get_demangled_name(buf);
1946 if (__size_)
1947 *buf++ = ')';
1948 else
1949 {
1950 *buf++ = ')';
1951 *buf++ = '-';
1952 *buf++ = '-';
1953 }
1954 }
1955 else
1956 {
1957 strncpy(buf, "operator--", sizeof("operator--") - 1);
1958 buf += sizeof("operator--") - 1;
1959 }
1960 return buf;
1961 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00001962 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
1963 {
1964 if (__left_)
1965 return __left_->fix_forward_references(t_begin, t_end);
1966 return true;
1967 }
1968};
1969
1970class __operator_not_equal
1971 : public __node
1972{
1973public:
1974
1975 __operator_not_equal() {}
1976 __operator_not_equal(__node* op1, __node* op2)
1977 {
1978 __left_ = op1;
1979 __right_ = op2;
1980 }
1981 virtual size_t first_size() const
1982 {
1983 if (__cached_size_ == -1)
1984 {
1985 if (__left_)
1986 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
1987 else
1988 const_cast<long&>(__cached_size_) = sizeof("operator!=") - 1;
1989 }
1990 return __cached_size_;
1991 }
1992 virtual char* first_demangled_name(char* buf) const
1993 {
1994 if (__left_)
1995 {
1996 *buf++ = '(';
1997 buf = __left_->get_demangled_name(buf);
1998 strncpy(buf, ") != (", 6);
1999 buf += 6;
2000 buf = __right_->get_demangled_name(buf);
2001 *buf++ = ')';
2002 }
2003 else
2004 {
2005 strncpy(buf, "operator!=", sizeof("operator!=") - 1);
2006 buf += sizeof("operator!=") - 1;
2007 }
2008 return buf;
2009 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002010 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2011 {
2012 bool r = true;
2013 if (__left_)
2014 r = r && __left_->fix_forward_references(t_begin, t_end);
2015 if (__right_)
2016 r = r && __right_->fix_forward_references(t_begin, t_end);
2017 return r;
2018 }
2019};
2020
2021class __operator_negate
2022 : public __node
2023{
2024public:
2025
2026 __operator_negate() {}
2027 explicit __operator_negate(__node* op)
2028 {
2029 __left_ = op;
2030 }
2031 virtual size_t first_size() const
2032 {
2033 if (__cached_size_ == -1)
2034 {
2035 if (__left_)
2036 const_cast<long&>(__cached_size_) = 3+__left_->size();
2037 else
2038 const_cast<long&>(__cached_size_) = sizeof("operator-") - 1;
2039 }
2040 return __cached_size_;
2041 }
2042 virtual char* first_demangled_name(char* buf) const
2043 {
2044 if (__left_)
2045 {
2046 *buf++ = '-';
2047 *buf++ = '(';
2048 buf = __left_->get_demangled_name(buf);
2049 *buf++ = ')';
2050 }
2051 else
2052 {
2053 strncpy(buf, "operator-", sizeof("operator-") - 1);
2054 buf += sizeof("operator-") - 1;
2055 }
2056 return buf;
2057 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002058 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2059 {
2060 if (__left_)
2061 return __left_->fix_forward_references(t_begin, t_end);
2062 return true;
2063 }
2064};
2065
2066class __operator_logical_not
2067 : public __node
2068{
2069public:
2070
2071 __operator_logical_not() {}
2072 explicit __operator_logical_not(__node* op)
2073 {
2074 __left_ = op;
2075 }
2076 virtual size_t first_size() const
2077 {
2078 if (__cached_size_ == -1)
2079 {
2080 if (__left_)
2081 const_cast<long&>(__cached_size_) = 3+__left_->size();
2082 else
2083 const_cast<long&>(__cached_size_) = sizeof("operator!") - 1;
2084 }
2085 return __cached_size_;
2086 }
2087 virtual char* first_demangled_name(char* buf) const
2088 {
2089 if (__left_)
2090 {
2091 *buf++ = '!';
2092 *buf++ = '(';
2093 buf = __left_->get_demangled_name(buf);
2094 *buf++ = ')';
2095 }
2096 else
2097 {
2098 strncpy(buf, "operator!", sizeof("operator!") - 1);
2099 buf += sizeof("operator!") - 1;
2100 }
2101 return buf;
2102 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002103 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2104 {
2105 if (__left_)
2106 return __left_->fix_forward_references(t_begin, t_end);
2107 return true;
2108 }
2109};
2110
2111class __operator_logical_or
2112 : public __node
2113{
2114public:
2115
2116 __operator_logical_or() {}
2117 __operator_logical_or(__node* op1, __node* op2)
2118 {
2119 __left_ = op1;
2120 __right_ = op2;
2121 }
2122 virtual size_t first_size() const
2123 {
2124 if (__cached_size_ == -1)
2125 {
2126 if (__left_)
2127 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
2128 else
2129 const_cast<long&>(__cached_size_) = sizeof("operator||") - 1;
2130 }
2131 return __cached_size_;
2132 }
2133 virtual char* first_demangled_name(char* buf) const
2134 {
2135 if (__left_)
2136 {
2137 *buf++ = '(';
2138 buf = __left_->get_demangled_name(buf);
2139 strncpy(buf, ") || (", 6);
2140 buf += 6;
2141 buf = __right_->get_demangled_name(buf);
2142 *buf++ = ')';
2143 }
2144 else
2145 {
2146 strncpy(buf, "operator||", sizeof("operator||") - 1);
2147 buf += sizeof("operator||") - 1;
2148 }
2149 return buf;
2150 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002151 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2152 {
2153 bool r = true;
2154 if (__left_)
2155 r = r && __left_->fix_forward_references(t_begin, t_end);
2156 if (__right_)
2157 r = r && __right_->fix_forward_references(t_begin, t_end);
2158 return r;
2159 }
2160};
2161
2162class __operator_bit_or
2163 : public __node
2164{
2165public:
2166
2167 __operator_bit_or() {}
2168 __operator_bit_or(__node* op1, __node* op2)
2169 {
2170 __left_ = op1;
2171 __right_ = op2;
2172 }
2173 virtual size_t first_size() const
2174 {
2175 if (__cached_size_ == -1)
2176 {
2177 if (__left_)
2178 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
2179 else
2180 const_cast<long&>(__cached_size_) = sizeof("operator|") - 1;
2181 }
2182 return __cached_size_;
2183 }
2184 virtual char* first_demangled_name(char* buf) const
2185 {
2186 if (__left_)
2187 {
2188 *buf++ = '(';
2189 buf = __left_->get_demangled_name(buf);
2190 strncpy(buf, ") | (", 5);
2191 buf += 5;
2192 buf = __right_->get_demangled_name(buf);
2193 *buf++ = ')';
2194 }
2195 else
2196 {
2197 strncpy(buf, "operator|", sizeof("operator|") - 1);
2198 buf += sizeof("operator|") - 1;
2199 }
2200 return buf;
2201 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002202 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2203 {
2204 bool r = true;
2205 if (__left_)
2206 r = r && __left_->fix_forward_references(t_begin, t_end);
2207 if (__right_)
2208 r = r && __right_->fix_forward_references(t_begin, t_end);
2209 return r;
2210 }
2211};
2212
2213class __operator_or_equal
2214 : public __node
2215{
2216public:
2217
2218 __operator_or_equal() {}
2219 __operator_or_equal(__node* op1, __node* op2)
2220 {
2221 __left_ = op1;
2222 __right_ = op2;
2223 }
2224 virtual size_t first_size() const
2225 {
2226 if (__cached_size_ == -1)
2227 {
2228 if (__left_)
2229 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
2230 else
2231 const_cast<long&>(__cached_size_) = sizeof("operator|=") - 1;
2232 }
2233 return __cached_size_;
2234 }
2235 virtual char* first_demangled_name(char* buf) const
2236 {
2237 if (__left_)
2238 {
2239 *buf++ = '(';
2240 buf = __left_->get_demangled_name(buf);
2241 strncpy(buf, ") |= (", 6);
2242 buf += 6;
2243 buf = __right_->get_demangled_name(buf);
2244 *buf++ = ')';
2245 }
2246 else
2247 {
2248 strncpy(buf, "operator|=", sizeof("operator|=") - 1);
2249 buf += sizeof("operator|=") - 1;
2250 }
2251 return buf;
2252 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002253 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2254 {
2255 bool r = true;
2256 if (__left_)
2257 r = r && __left_->fix_forward_references(t_begin, t_end);
2258 if (__right_)
2259 r = r && __right_->fix_forward_references(t_begin, t_end);
2260 return r;
2261 }
2262};
2263
2264class __operator_pointer_to_member
2265 : public __node
2266{
2267public:
2268
2269 __operator_pointer_to_member() {}
2270 __operator_pointer_to_member(__node* op1, __node* op2)
2271 {
2272 __left_ = op1;
2273 __right_ = op2;
2274 }
2275 virtual size_t first_size() const
2276 {
2277 if (__cached_size_ == -1)
2278 {
2279 if (__left_)
2280 const_cast<long&>(__cached_size_) = __left_->size() + 9 + __right_->size();
2281 else
2282 const_cast<long&>(__cached_size_) = sizeof("operator->*") - 1;
2283 }
2284 return __cached_size_;
2285 }
2286 virtual char* first_demangled_name(char* buf) const
2287 {
2288 if (__left_)
2289 {
2290 *buf++ = '(';
2291 buf = __left_->get_demangled_name(buf);
2292 strncpy(buf, ") ->* (", 7);
2293 buf += 7;
2294 buf = __right_->get_demangled_name(buf);
2295 *buf++ = ')';
2296 }
2297 else
2298 {
2299 strncpy(buf, "operator->*", sizeof("operator->*") - 1);
2300 buf += sizeof("operator->*") - 1;
2301 }
2302 return buf;
2303 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002304 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2305 {
2306 bool r = true;
2307 if (__left_)
2308 r = r && __left_->fix_forward_references(t_begin, t_end);
2309 if (__right_)
2310 r = r && __right_->fix_forward_references(t_begin, t_end);
2311 return r;
2312 }
2313};
2314
2315class __operator_plus
2316 : public __node
2317{
2318public:
2319
2320 __operator_plus() {}
2321 __operator_plus(__node* op1, __node* op2)
2322 {
2323 __left_ = op1;
2324 __right_ = op2;
2325 }
2326 virtual size_t first_size() const
2327 {
2328 if (__cached_size_ == -1)
2329 {
2330 if (__left_)
2331 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
2332 else
2333 const_cast<long&>(__cached_size_) = sizeof("operator+") - 1;
2334 }
2335 return __cached_size_;
2336 }
2337 virtual char* first_demangled_name(char* buf) const
2338 {
2339 if (__left_)
2340 {
2341 *buf++ = '(';
2342 buf = __left_->get_demangled_name(buf);
2343 strncpy(buf, ") + (", 5);
2344 buf += 5;
2345 buf = __right_->get_demangled_name(buf);
2346 *buf++ = ')';
2347 }
2348 else
2349 {
2350 strncpy(buf, "operator+", sizeof("operator+") - 1);
2351 buf += sizeof("operator+") - 1;
2352 }
2353 return buf;
2354 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002355 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2356 {
2357 bool r = true;
2358 if (__left_)
2359 r = r && __left_->fix_forward_references(t_begin, t_end);
2360 if (__right_)
2361 r = r && __right_->fix_forward_references(t_begin, t_end);
2362 return r;
2363 }
2364};
2365
2366class __operator_plus_equal
2367 : public __node
2368{
2369public:
2370
2371 __operator_plus_equal() {}
2372 __operator_plus_equal(__node* op1, __node* op2)
2373 {
2374 __left_ = op1;
2375 __right_ = op2;
2376 }
2377 virtual size_t first_size() const
2378 {
2379 if (__cached_size_ == -1)
2380 {
2381 if (__left_)
2382 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
2383 else
2384 const_cast<long&>(__cached_size_) = sizeof("operator+=") - 1;
2385 }
2386 return __cached_size_;
2387 }
2388 virtual char* first_demangled_name(char* buf) const
2389 {
2390 if (__left_)
2391 {
2392 *buf++ = '(';
2393 buf = __left_->get_demangled_name(buf);
2394 strncpy(buf, ") += (", 6);
2395 buf += 6;
2396 buf = __right_->get_demangled_name(buf);
2397 *buf++ = ')';
2398 }
2399 else
2400 {
2401 strncpy(buf, "operator+=", sizeof("operator+=") - 1);
2402 buf += sizeof("operator+=") - 1;
2403 }
2404 return buf;
2405 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002406 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2407 {
2408 bool r = true;
2409 if (__left_)
2410 r = r && __left_->fix_forward_references(t_begin, t_end);
2411 if (__right_)
2412 r = r && __right_->fix_forward_references(t_begin, t_end);
2413 return r;
2414 }
2415};
2416
2417class __operator_increment
2418 : public __node
2419{
2420public:
2421
2422 __operator_increment() {}
2423 explicit __operator_increment(bool prefix, __node* op)
2424 {
2425 __size_ = prefix;
2426 __left_ = op;
2427 }
2428 virtual size_t first_size() const
2429 {
2430 if (__cached_size_ == -1)
2431 {
2432 if (__left_)
2433 const_cast<long&>(__cached_size_) = 4+__left_->size();
2434 else
2435 const_cast<long&>(__cached_size_) = sizeof("operator++") - 1;
2436 }
2437 return __cached_size_;
2438 }
2439 virtual char* first_demangled_name(char* buf) const
2440 {
2441 if (__left_)
2442 {
2443 if (__size_)
2444 {
2445 *buf++ = '+';
2446 *buf++ = '+';
2447 *buf++ = '(';
2448 }
2449 else
2450 *buf++ = '(';
2451 buf = __left_->get_demangled_name(buf);
2452 if (__size_)
2453 *buf++ = ')';
2454 else
2455 {
2456 *buf++ = ')';
2457 *buf++ = '+';
2458 *buf++ = '+';
2459 }
2460 }
2461 else
2462 {
2463 strncpy(buf, "operator++", sizeof("operator++") - 1);
2464 buf += sizeof("operator++") - 1;
2465 }
2466 return buf;
2467 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002468 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2469 {
2470 if (__left_)
2471 return __left_->fix_forward_references(t_begin, t_end);
2472 return true;
2473 }
2474};
2475
2476class __operator_unary_plus
2477 : public __node
2478{
2479public:
2480
2481 __operator_unary_plus() {}
2482 explicit __operator_unary_plus(__node* op)
2483 {
2484 __left_ = op;
2485 }
2486 virtual size_t first_size() const
2487 {
2488 if (__cached_size_ == -1)
2489 {
2490 if (__left_)
2491 const_cast<long&>(__cached_size_) = 3+__left_->size();
2492 else
2493 const_cast<long&>(__cached_size_) = sizeof("operator+") - 1;
2494 }
2495 return __cached_size_;
2496 }
2497 virtual char* first_demangled_name(char* buf) const
2498 {
2499 if (__left_)
2500 {
2501 *buf++ = '+';
2502 *buf++ = '(';
2503 buf = __left_->get_demangled_name(buf);
2504 *buf++ = ')';
2505 }
2506 else
2507 {
2508 strncpy(buf, "operator+", sizeof("operator+") - 1);
2509 buf += sizeof("operator+") - 1;
2510 }
2511 return buf;
2512 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002513 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2514 {
2515 if (__left_)
2516 return __left_->fix_forward_references(t_begin, t_end);
2517 return true;
2518 }
2519};
2520
2521class __operator_arrow
2522 : public __node
2523{
2524public:
2525
2526 __operator_arrow() {}
2527 __operator_arrow(__node* op1, __node* op2)
2528 {
2529 __left_ = op1;
2530 __right_ = op2;
2531 }
2532 virtual size_t first_size() const
2533 {
2534 if (__cached_size_ == -1)
2535 {
2536 if (__left_)
2537 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
2538 else
2539 const_cast<long&>(__cached_size_) = sizeof("operator->") - 1;
2540 }
2541 return __cached_size_;
2542 }
2543 virtual char* first_demangled_name(char* buf) const
2544 {
2545 if (__left_)
2546 {
2547 *buf++ = '(';
2548 buf = __left_->get_demangled_name(buf);
2549 strncpy(buf, ") -> (", 6);
2550 buf += 6;
2551 buf = __right_->get_demangled_name(buf);
2552 *buf++ = ')';
2553 }
2554 else
2555 {
2556 strncpy(buf, "operator->", sizeof("operator->") - 1);
2557 buf += sizeof("operator->") - 1;
2558 }
2559 return buf;
2560 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002561 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2562 {
2563 bool r = true;
2564 if (__left_)
2565 r = r && __left_->fix_forward_references(t_begin, t_end);
2566 if (__right_)
2567 r = r && __right_->fix_forward_references(t_begin, t_end);
2568 return r;
2569 }
2570};
2571
2572class __operator_conditional
2573 : public __node
2574{
2575public:
2576
2577 __operator_conditional() {}
2578 __operator_conditional(__node* op1, __node* op2, __node* op3)
2579 {
2580 __name_ = (const char*)op1;
2581 __left_ = op2;
2582 __right_ = op3;
2583 }
2584 virtual size_t first_size() const
2585 {
2586 if (__cached_size_ == -1)
2587 {
2588 if (__left_)
2589 {
2590 __node* op1 = (__node*)__name_;
2591 const_cast<long&>(__cached_size_) = op1->size() + __left_->size() + 12 + __right_->size();
2592 }
2593 else
2594 const_cast<long&>(__cached_size_) = sizeof("operator?") - 1;
2595 }
2596 return __cached_size_;
2597 }
2598 virtual char* first_demangled_name(char* buf) const
2599 {
2600 if (__left_)
2601 {
2602 __node* op1 = (__node*)__name_;
2603 *buf++ = '(';
2604 buf = op1->get_demangled_name(buf);
2605 strncpy(buf, ") ? (", 5);
2606 buf += 5;
2607 buf = __left_->get_demangled_name(buf);
2608 strncpy(buf, ") : (", 5);
2609 buf += 5;
2610 buf = __right_->get_demangled_name(buf);
2611 *buf++ = ')';
2612 }
2613 else
2614 {
2615 strncpy(buf, "operator?", sizeof("operator?") - 1);
2616 buf += sizeof("operator?") - 1;
2617 }
2618 return buf;
2619 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002620 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2621 {
2622 bool r = true;
2623 if (__name_)
2624 r = r && ((__node*)__name_)->fix_forward_references(t_begin, t_end);
2625 if (__left_)
2626 r = r && __left_->fix_forward_references(t_begin, t_end);
2627 if (__right_)
2628 r = r && __right_->fix_forward_references(t_begin, t_end);
2629 return r;
2630 }
2631};
2632
2633class __operator_mod
2634 : public __node
2635{
2636public:
2637
2638 __operator_mod() {}
2639 __operator_mod(__node* op1, __node* op2)
2640 {
2641 __left_ = op1;
2642 __right_ = op2;
2643 }
2644 virtual size_t first_size() const
2645 {
2646 if (__cached_size_ == -1)
2647 {
2648 if (__left_)
2649 const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size();
2650 else
2651 const_cast<long&>(__cached_size_) = sizeof("operator%") - 1;
2652 }
2653 return __cached_size_;
2654 }
2655 virtual char* first_demangled_name(char* buf) const
2656 {
2657 if (__left_)
2658 {
2659 *buf++ = '(';
2660 buf = __left_->get_demangled_name(buf);
2661 strncpy(buf, ") % (", 5);
2662 buf += 5;
2663 buf = __right_->get_demangled_name(buf);
2664 *buf++ = ')';
2665 }
2666 else
2667 {
2668 strncpy(buf, "operator%", sizeof("operator%") - 1);
2669 buf += sizeof("operator%") - 1;
2670 }
2671 return buf;
2672 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002673 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2674 {
2675 bool r = true;
2676 if (__left_)
2677 r = r && __left_->fix_forward_references(t_begin, t_end);
2678 if (__right_)
2679 r = r && __right_->fix_forward_references(t_begin, t_end);
2680 return r;
2681 }
2682};
2683
2684class __operator_mod_equal
2685 : public __node
2686{
2687public:
2688
2689 __operator_mod_equal() {}
2690 __operator_mod_equal(__node* op1, __node* op2)
2691 {
2692 __left_ = op1;
2693 __right_ = op2;
2694 }
2695 virtual size_t first_size() const
2696 {
2697 if (__cached_size_ == -1)
2698 {
2699 if (__left_)
2700 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
2701 else
2702 const_cast<long&>(__cached_size_) = sizeof("operator%=") - 1;
2703 }
2704 return __cached_size_;
2705 }
2706 virtual char* first_demangled_name(char* buf) const
2707 {
2708 if (__left_)
2709 {
2710 *buf++ = '(';
2711 buf = __left_->get_demangled_name(buf);
2712 strncpy(buf, ") %= (", 6);
2713 buf += 6;
2714 buf = __right_->get_demangled_name(buf);
2715 *buf++ = ')';
2716 }
2717 else
2718 {
2719 strncpy(buf, "operator%=", sizeof("operator%=") - 1);
2720 buf += sizeof("operator%=") - 1;
2721 }
2722 return buf;
2723 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002724 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2725 {
2726 bool r = true;
2727 if (__left_)
2728 r = r && __left_->fix_forward_references(t_begin, t_end);
2729 if (__right_)
2730 r = r && __right_->fix_forward_references(t_begin, t_end);
2731 return r;
2732 }
2733};
2734
2735class __operator_right_shift
2736 : public __node
2737{
2738public:
2739
2740 __operator_right_shift() {}
2741 __operator_right_shift(__node* op1, __node* op2)
2742 {
2743 __left_ = op1;
2744 __right_ = op2;
2745 }
2746 virtual size_t first_size() const
2747 {
2748 if (__cached_size_ == -1)
2749 {
2750 if (__left_)
2751 const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size();
2752 else
2753 const_cast<long&>(__cached_size_) = sizeof("operator>>") - 1;
2754 }
2755 return __cached_size_;
2756 }
2757 virtual char* first_demangled_name(char* buf) const
2758 {
2759 if (__left_)
2760 {
2761 *buf++ = '(';
2762 buf = __left_->get_demangled_name(buf);
2763 strncpy(buf, ") >> (", 6);
2764 buf += 6;
2765 buf = __right_->get_demangled_name(buf);
2766 *buf++ = ')';
2767 }
2768 else
2769 {
2770 strncpy(buf, "operator>>", sizeof("operator>>") - 1);
2771 buf += sizeof("operator>>") - 1;
2772 }
2773 return buf;
2774 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002775 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2776 {
2777 bool r = true;
2778 if (__left_)
2779 r = r && __left_->fix_forward_references(t_begin, t_end);
2780 if (__right_)
2781 r = r && __right_->fix_forward_references(t_begin, t_end);
2782 return r;
2783 }
2784};
2785
2786class __operator_right_shift_equal
2787 : public __node
2788{
2789public:
2790
2791 __operator_right_shift_equal() {}
2792 __operator_right_shift_equal(__node* op1, __node* op2)
2793 {
2794 __left_ = op1;
2795 __right_ = op2;
2796 }
2797 virtual size_t first_size() const
2798 {
2799 if (__cached_size_ == -1)
2800 {
2801 if (__left_)
2802 const_cast<long&>(__cached_size_) = __left_->size() + 9 + __right_->size();
2803 else
2804 const_cast<long&>(__cached_size_) = sizeof("operator>>=") - 1;
2805 }
2806 return __cached_size_;
2807 }
2808 virtual char* first_demangled_name(char* buf) const
2809 {
2810 if (__left_)
2811 {
2812 *buf++ = '(';
2813 buf = __left_->get_demangled_name(buf);
2814 strncpy(buf, ") >>= (", 7);
2815 buf += 7;
2816 buf = __right_->get_demangled_name(buf);
2817 *buf++ = ')';
2818 }
2819 else
2820 {
2821 strncpy(buf, "operator>>=", sizeof("operator>>=") - 1);
2822 buf += sizeof("operator>>=") - 1;
2823 }
2824 return buf;
2825 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002826 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2827 {
2828 bool r = true;
2829 if (__left_)
2830 r = r && __left_->fix_forward_references(t_begin, t_end);
2831 if (__right_)
2832 r = r && __right_->fix_forward_references(t_begin, t_end);
2833 return r;
2834 }
2835};
2836
2837class __operator_sizeof_type
2838 : public __node
2839{
2840public:
2841
2842 __operator_sizeof_type() {}
2843 __operator_sizeof_type(__node* op)
2844 {
2845 __right_ = op;
2846 }
2847 virtual size_t first_size() const
2848 {
2849 if (__cached_size_ == -1)
2850 {
2851 if (__right_)
2852 const_cast<long&>(__cached_size_) = __right_->size() + 9;
2853 else
2854 const_cast<long&>(__cached_size_) = sizeof("operator sizeof") - 1;
2855 }
2856 return __cached_size_;
2857 }
2858 virtual char* first_demangled_name(char* buf) const
2859 {
2860 if (__right_)
2861 {
2862 strncpy(buf, "sizeof (", 8);
2863 buf += 8;
2864 buf = __right_->get_demangled_name(buf);
2865 *buf++ = ')';
2866 }
2867 else
2868 {
2869 strncpy(buf, "operator sizeof", sizeof("operator sizeof") - 1);
2870 buf += sizeof("operator sizeof") - 1;
2871 }
2872 return buf;
2873 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002874 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2875 {
2876 if (__right_)
2877 return __right_->fix_forward_references(t_begin, t_end);
2878 return true;
2879 }
2880};
2881
2882class __operator_sizeof_expression
2883 : public __node
2884{
2885public:
2886
2887 __operator_sizeof_expression() {}
2888 __operator_sizeof_expression(__node* op)
2889 {
2890 __right_ = op;
2891 }
2892 virtual size_t first_size() const
2893 {
2894 if (__cached_size_ == -1)
2895 {
2896 if (__right_)
2897 const_cast<long&>(__cached_size_) = __right_->size() + 9;
2898 else
2899 const_cast<long&>(__cached_size_) = sizeof("operator sizeof") - 1;
2900 }
2901 return __cached_size_;
2902 }
2903 virtual char* first_demangled_name(char* buf) const
2904 {
2905 if (__right_)
2906 {
2907 strncpy(buf, "sizeof (", 8);
2908 buf += 8;
2909 buf = __right_->get_demangled_name(buf);
2910 *buf++ = ')';
2911 }
2912 else
2913 {
2914 strncpy(buf, "operator sizeof", sizeof("operator sizeof") - 1);
2915 buf += sizeof("operator sizeof") - 1;
2916 }
2917 return buf;
2918 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002919 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2920 {
2921 if (__right_)
2922 return __right_->fix_forward_references(t_begin, t_end);
2923 return true;
2924 }
2925};
2926
2927class __typeid
2928 : public __node
2929{
2930public:
2931
2932 __typeid(__node* op)
2933 {
2934 __right_ = op;
2935 }
2936 virtual size_t first_size() const
2937 {
2938 if (__cached_size_ == -1)
2939 const_cast<long&>(__cached_size_) = __right_->size() + 8;
2940 return __cached_size_;
2941 }
2942 virtual char* first_demangled_name(char* buf) const
2943 {
2944 strncpy(buf, "typeid(", 7);
2945 buf += 7;
2946 buf = __right_->get_demangled_name(buf);
2947 *buf++ = ')';
2948 return buf;
2949 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002950 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2951 {
2952 return __right_->fix_forward_references(t_begin, t_end);
2953 }
2954};
2955
2956class __throw
2957 : public __node
2958{
2959public:
2960
2961 __throw(__node* op)
2962 {
2963 __right_ = op;
2964 }
2965 virtual size_t first_size() const
2966 {
2967 if (__cached_size_ == -1)
2968 const_cast<long&>(__cached_size_) = __right_->size() + 6;
2969 return __cached_size_;
2970 }
2971 virtual char* first_demangled_name(char* buf) const
2972 {
2973 strncpy(buf, "throw ", 6);
2974 return __right_->get_demangled_name(buf+6);
2975 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002976 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
2977 {
2978 return __right_->fix_forward_references(t_begin, t_end);
2979 }
2980};
2981
2982class __rethrow
2983 : public __node
2984{
2985 static const ptrdiff_t n = sizeof("throw") - 1;
2986public:
2987
2988 virtual size_t first_size() const {return n;}
2989 virtual char* first_demangled_name(char* buf) const
2990 {
2991 strncpy(buf, "throw", n);
2992 return buf+n;
2993 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00002994};
2995
2996class __operator_sizeof_param_pack
2997 : public __node
2998{
2999public:
3000
3001 __operator_sizeof_param_pack(__node* op)
3002 {
3003 __right_ = op;
3004 }
3005 virtual size_t first_size() const
3006 {
3007 if (__cached_size_ == -1)
3008 const_cast<long&>(__cached_size_) = __right_->size() + 11;
3009 return __cached_size_;
3010 }
3011 virtual char* first_demangled_name(char* buf) const
3012 {
3013 strncpy(buf, "sizeof...(", 10);
3014 buf += 10;
3015 buf = __right_->get_demangled_name(buf);
3016 *buf++ = ')';
3017 return buf;
3018 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003019 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3020 {
3021 return __right_->fix_forward_references(t_begin, t_end);
3022 }
3023};
3024
3025class __const_cast
3026 : public __node
3027{
3028public:
3029
3030 __const_cast(__node* op1, __node* op2)
3031 {
3032 __left_ = op1;
3033 __right_ = op2;
3034 }
3035 virtual size_t first_size() const
3036 {
3037 if (__cached_size_ == -1)
3038 const_cast<long&>(__cached_size_) = __left_->size() + 14 + __right_->size();
3039 return __cached_size_;
3040 }
3041 virtual char* first_demangled_name(char* buf) const
3042 {
3043 strncpy(buf, "const_cast<", 11);
3044 buf += 11;
3045 buf = __left_->get_demangled_name(buf);
3046 *buf++ = '>';
3047 *buf++ = '(';
3048 buf = __right_->get_demangled_name(buf);
3049 *buf++ = ')';
3050 return buf;
3051 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003052 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3053 {
3054 return __left_->fix_forward_references(t_begin, t_end) &&
3055 __right_->fix_forward_references(t_begin, t_end);
3056 }
3057};
3058
3059class __dynamic_cast
3060 : public __node
3061{
3062public:
3063
3064 __dynamic_cast(__node* op1, __node* op2)
3065 {
3066 __left_ = op1;
3067 __right_ = op2;
3068 }
3069 virtual size_t first_size() const
3070 {
3071 if (__cached_size_ == -1)
3072 const_cast<long&>(__cached_size_) = __left_->size() + 16 + __right_->size();
3073 return __cached_size_;
3074 }
3075 virtual char* first_demangled_name(char* buf) const
3076 {
3077 strncpy(buf, "dynamic_cast<", 13);
3078 buf += 13;
3079 buf = __left_->get_demangled_name(buf);
3080 *buf++ = '>';
3081 *buf++ = '(';
3082 buf = __right_->get_demangled_name(buf);
3083 *buf++ = ')';
3084 return buf;
3085 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003086 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3087 {
3088 return __left_->fix_forward_references(t_begin, t_end) &&
3089 __right_->fix_forward_references(t_begin, t_end);
3090 }
3091};
3092
3093class __reinterpret_cast
3094 : public __node
3095{
3096public:
3097
3098 __reinterpret_cast(__node* op1, __node* op2)
3099 {
3100 __left_ = op1;
3101 __right_ = op2;
3102 }
3103 virtual size_t first_size() const
3104 {
3105 if (__cached_size_ == -1)
3106 const_cast<long&>(__cached_size_) = __left_->size() + 20 + __right_->size();
3107 return __cached_size_;
3108 }
3109 virtual char* first_demangled_name(char* buf) const
3110 {
3111 strncpy(buf, "reinterpret_cast<", 17);
3112 buf += 17;
3113 buf = __left_->get_demangled_name(buf);
3114 *buf++ = '>';
3115 *buf++ = '(';
3116 buf = __right_->get_demangled_name(buf);
3117 *buf++ = ')';
3118 return buf;
3119 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003120 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3121 {
3122 return __left_->fix_forward_references(t_begin, t_end) &&
3123 __right_->fix_forward_references(t_begin, t_end);
3124 }
3125};
3126
3127class __static_cast
3128 : public __node
3129{
3130public:
3131
3132 __static_cast(__node* op1, __node* op2)
3133 {
3134 __left_ = op1;
3135 __right_ = op2;
3136 }
3137 virtual size_t first_size() const
3138 {
3139 if (__cached_size_ == -1)
3140 const_cast<long&>(__cached_size_) = __left_->size() + 15 + __right_->size();
3141 return __cached_size_;
3142 }
3143 virtual char* first_demangled_name(char* buf) const
3144 {
3145 strncpy(buf, "static_cast<", 12);
3146 buf += 12;
3147 buf = __left_->get_demangled_name(buf);
3148 *buf++ = '>';
3149 *buf++ = '(';
3150 buf = __right_->get_demangled_name(buf);
3151 *buf++ = ')';
3152 return buf;
3153 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003154 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3155 {
3156 return __left_->fix_forward_references(t_begin, t_end) &&
3157 __right_->fix_forward_references(t_begin, t_end);
3158 }
3159};
3160
3161class __call_expr
3162 : public __node
3163{
3164public:
3165
3166 __call_expr(__node* op1, __node* op2)
3167 {
3168 __left_ = op1;
3169 __right_ = op2;
3170 }
3171 virtual size_t first_size() const
3172 {
3173 if (__cached_size_ == -1)
3174 {
3175 size_t off = __left_->size() + 2;
3176 if (__right_)
3177 off += __right_->size();
3178 const_cast<long&>(__cached_size_) = off;
3179 }
3180 return __cached_size_;
3181 }
3182 virtual char* first_demangled_name(char* buf) const
3183 {
3184 buf = __left_->get_demangled_name(buf);
3185 *buf++ = '(';
3186 if (__right_)
3187 buf = __right_->get_demangled_name(buf);
3188 *buf++ = ')';
3189 return buf;
3190 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003191 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3192 {
3193 bool r = __left_->fix_forward_references(t_begin, t_end);
3194 if (__right_)
3195 r = r && __right_->fix_forward_references(t_begin, t_end);
3196 return r;
3197 }
3198};
3199
3200class __delete_array_expr
3201 : public __node
3202{
3203public:
3204
3205 __delete_array_expr(bool global, __node* op)
3206 {
3207 __size_ = global;
3208 __right_ = op;
3209 }
3210 virtual size_t first_size() const
3211 {
3212 if (__cached_size_ == -1)
3213 const_cast<long&>(__cached_size_) = (__size_ ? 2 : 0) + 9 + __right_->size();
3214 return __cached_size_;
3215 }
3216 virtual char* first_demangled_name(char* buf) const
3217 {
3218 if (__size_)
3219 {
3220 *buf++ = ':';
3221 *buf++ = ':';
3222 }
3223 strncpy(buf, "delete[] ", 9);
3224 return __right_->get_demangled_name(buf+9);
3225 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003226 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3227 {
3228 return __right_->fix_forward_references(t_begin, t_end);
3229 }
3230};
3231
3232class __delete_expr
3233 : public __node
3234{
3235public:
3236
3237 __delete_expr(bool global, __node* op)
3238 {
3239 __size_ = global;
3240 __right_ = op;
3241 }
3242 virtual size_t first_size() const
3243 {
3244 if (__cached_size_ == -1)
3245 const_cast<long&>(__cached_size_) = (__size_ ? 2 : 0) + 7 + __right_->size();
3246 return __cached_size_;
3247 }
3248 virtual char* first_demangled_name(char* buf) const
3249 {
3250 if (__size_)
3251 {
3252 *buf++ = ':';
3253 *buf++ = ':';
3254 }
3255 strncpy(buf, "delete ", 7);
3256 return __right_->get_demangled_name(buf+7);
3257 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003258 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3259 {
3260 return __right_->fix_forward_references(t_begin, t_end);
3261 }
3262};
3263
3264class __new_expr
3265 : public __node
3266{
3267public:
3268
3269 __new_expr(bool global, bool is_array, bool has_init,
3270 __node* expr, __node* type, __node* init)
3271 {
3272 __size_ = (unsigned)global |
3273 ((unsigned)is_array << 1) |
3274 ((unsigned)has_init << 2);
3275 __left_ = expr;
3276 __name_ = (const char*)type;
3277 __right_ = init;
3278 }
3279 virtual size_t first_size() const
3280 {
3281 if (__cached_size_ == -1)
3282 {
3283 size_t off = 4;
3284 if (__size_ & 1)
3285 off += 2;
3286 if (__size_ & 2)
3287 off += 2;
3288 if (__left_)
3289 {
3290 off += 2;
3291 off += __left_->size();
3292 }
3293 __node* type = (__node*)__name_;
3294 off += type->size();
3295 if (__size_ & 4)
3296 {
3297 off += 2;
3298 if (__right_)
3299 off += __right_->size();
3300 }
3301 const_cast<long&>(__cached_size_) = off;
3302 }
3303 return __cached_size_;
3304 }
3305 virtual char* first_demangled_name(char* buf) const
3306 {
3307 if (__size_ & 1)
3308 {
3309 *buf++ = ':';
3310 *buf++ = ':';
3311 }
3312 *buf++ = 'n';
3313 *buf++ = 'e';
3314 *buf++ = 'w';
3315 if (__size_ & 2)
3316 {
3317 *buf++ = '[';
3318 *buf++ = ']';
3319 }
3320 if (__left_)
3321 {
3322 *buf++ = '(';
3323 buf = __left_->get_demangled_name(buf);
3324 *buf++ = ')';
3325 }
3326 *buf++ = ' ';
3327 __node* type = (__node*)__name_;
3328 buf = type->get_demangled_name(buf);
3329 if (__size_ & 4)
3330 {
3331 *buf++ = '(';
3332 if (__right_)
3333 buf = __right_->get_demangled_name(buf);
3334 *buf++ = ')';
3335 }
3336 return buf;
3337 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003338 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3339 {
3340 __node* type = (__node*)__name_;
3341 bool r = type->fix_forward_references(t_begin, t_end);
3342 if (__left_)
3343 r = r && __left_->fix_forward_references(t_begin, t_end);;
3344 if (__right_)
3345 r = r && __right_->fix_forward_references(t_begin, t_end);;
3346 return r;
3347 }
3348};
3349
3350class __dot_star_expr
3351 : public __node
3352{
3353public:
3354
3355 __dot_star_expr(__node* op1, __node* op2)
3356 {
3357 __left_ = op1;
3358 __right_ = op2;
3359 }
3360 virtual size_t first_size() const
3361 {
3362 if (__cached_size_ == -1)
3363 const_cast<long&>(__cached_size_) = __left_->size() + 2 + __right_->size();
3364 return __cached_size_;
3365 }
3366 virtual char* first_demangled_name(char* buf) const
3367 {
3368 buf = __left_->get_demangled_name(buf);
3369 *buf++ = '.';
3370 *buf++ = '*';
3371 return __right_->get_demangled_name(buf);
3372 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003373 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3374 {
3375 return __left_->fix_forward_references(t_begin, t_end) &&
3376 __right_->fix_forward_references(t_begin, t_end);
3377 }
3378};
3379
3380class __dot_expr
3381 : public __node
3382{
3383public:
3384
3385 __dot_expr(__node* op1, __node* op2)
3386 {
3387 __left_ = op1;
3388 __right_ = op2;
3389 }
3390 virtual size_t first_size() const
3391 {
3392 if (__cached_size_ == -1)
3393 const_cast<long&>(__cached_size_) = __left_->size() + 1 + __right_->size();
3394 return __cached_size_;
3395 }
3396 virtual char* first_demangled_name(char* buf) const
3397 {
3398 buf = __left_->get_demangled_name(buf);
3399 *buf++ = '.';
3400 return __right_->get_demangled_name(buf);
3401 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003402 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3403 {
3404 return __left_->fix_forward_references(t_begin, t_end) &&
3405 __right_->fix_forward_references(t_begin, t_end);
3406 }
3407};
3408
3409class __arrow_expr
3410 : public __node
3411{
3412public:
3413
3414 __arrow_expr(__node* op1, __node* op2)
3415 {
3416 __left_ = op1;
3417 __right_ = op2;
3418 }
3419 virtual size_t first_size() const
3420 {
3421 if (__cached_size_ == -1)
3422 const_cast<long&>(__cached_size_) = __left_->size() + 2 + __right_->size();
3423 return __cached_size_;
3424 }
3425 virtual char* first_demangled_name(char* buf) const
3426 {
3427 buf = __left_->get_demangled_name(buf);
3428 *buf++ = '-';
3429 *buf++ = '>';
3430 return __right_->get_demangled_name(buf);
3431 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003432 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3433 {
3434 return __left_->fix_forward_references(t_begin, t_end) &&
3435 __right_->fix_forward_references(t_begin, t_end);
3436 }
3437};
3438
3439class __std_qualified_name
3440 : public __node
3441{
3442 static const ptrdiff_t n = sizeof("std") - 1;
3443public:
3444
3445 __std_qualified_name()
3446 {
3447 }
3448 virtual size_t first_size() const
3449 {
3450 return n;
3451 }
3452
3453 virtual char* first_demangled_name(char* buf) const
3454 {
3455 *buf++ = 's';
3456 *buf++ = 't';
3457 *buf++ = 'd';
3458 return buf;
3459 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003460};
3461
3462class __sub_allocator
3463 : public __node
3464{
3465 static const ptrdiff_t n = sizeof("std::allocator") - 1;
3466public:
3467
3468 virtual size_t first_size() const
3469 {
3470 return n;
3471 }
3472 virtual char* first_demangled_name(char* buf) const
3473 {
3474 strncpy(buf, "std::allocator", n);
3475 return buf + n;
3476 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003477};
3478
3479class __sub_basic_string
3480 : public __node
3481{
3482 static const ptrdiff_t n = sizeof("std::basic_string") - 1;
3483public:
3484
3485 virtual size_t first_size() const
3486 {
3487 return n;
3488 }
3489 virtual char* first_demangled_name(char* buf) const
3490 {
3491 strncpy(buf, "std::basic_string", n);
3492 return buf + n;
3493 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003494};
3495
3496class __sub_string
3497 : public __node
3498{
3499 static const size_t n = sizeof("std::string") - 1;
3500 static const size_t ne = sizeof("std::basic_string<char, std::char_traits<char>, std::allocator<char> >") - 1;
3501public:
3502
3503 virtual size_t first_size() const
3504 {
3505 if (__size_)
3506 return ne;
3507 return n;
3508 }
3509 virtual char* first_demangled_name(char* buf) const
3510 {
3511 if (__size_)
3512 {
3513 strncpy(buf, "std::basic_string<char, std::char_traits<char>, std::allocator<char> >", ne);
3514 buf += ne;
3515 }
3516 else
3517 {
3518 strncpy(buf, "std::string", n);
3519 buf += n;
3520 }
3521 return buf;
3522 }
3523
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003524 virtual size_t base_size() const
3525 {
3526 return 12;
3527 }
3528 virtual char* get_base_name(char* buf) const
3529 {
3530 strncpy(buf, "basic_string", 12);
3531 return buf + 12;
3532 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003533
3534 virtual __node* base_name() const
3535 {
3536 const_cast<size_t&>(__size_) = true;
3537 return const_cast<__node*>(static_cast<const __node*>(this));
3538 }
3539};
3540
3541class __sub_istream
3542 : public __node
3543{
3544 static const ptrdiff_t n = sizeof("std::istream") - 1;
3545public:
3546
3547 virtual size_t first_size() const {return n;}
3548 virtual char* first_demangled_name(char* buf) const
3549 {
3550 strncpy(buf, "std::istream", n);
3551 return buf + n;
3552 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003553};
3554
3555class __sub_ostream
3556 : public __node
3557{
3558 static const ptrdiff_t n = sizeof("std::ostream") - 1;
3559public:
3560
3561 virtual size_t first_size() const {return n;}
3562 virtual char* first_demangled_name(char* buf) const
3563 {
3564 strncpy(buf, "std::ostream", n);
3565 return buf + n;
3566 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003567};
3568
3569class __sub_iostream
3570 : public __node
3571{
3572 static const ptrdiff_t n = sizeof("std::iostream") - 1;
3573public:
3574
3575 virtual size_t first_size() const {return n;}
3576 virtual char* first_demangled_name(char* buf) const
3577 {
3578 strncpy(buf, "std::iostream", n);
3579 return buf + n;
3580 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003581};
3582
3583class __sub
3584 : public __node
3585{
3586public:
3587
3588 explicit __sub(__node* arg)
3589 {
3590 __left_ = arg;
3591 }
3592 explicit __sub(size_t arg)
3593 {
3594 __size_ = arg;
3595 }
3596 virtual size_t first_size() const
3597 {
3598 return __left_->first_size();
3599 }
3600 virtual char* first_demangled_name(char* buf) const
3601 {
3602 return __left_->first_demangled_name(buf);
3603 }
3604 virtual size_t second_size() const
3605 {
3606 return __left_->second_size();
3607 }
3608 virtual char* second_demangled_name(char* buf) const
3609 {
3610 return __left_->second_demangled_name(buf);
3611 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003612 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003613 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003614 return __left_->ends_with_template(parsing);
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003615 }
3616 virtual __node* base_name() const
3617 {
3618 return __left_->base_name();
3619 }
3620 virtual bool is_reference_or_pointer_to_function_or_array() const
3621 {
3622 return __left_->is_reference_or_pointer_to_function_or_array();
3623 }
3624 virtual bool is_function() const
3625 {
3626 return __left_->is_function();
3627 }
3628 virtual bool is_cv_qualifer() const
3629 {
3630 return __left_->is_cv_qualifer();
3631 }
3632 virtual bool is_ctor_dtor_conv() const
3633 {
3634 return __left_->is_ctor_dtor_conv();
3635 }
3636 virtual bool is_array() const
3637 {
3638 return __left_->is_array();
3639 }
3640 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3641 {
3642 if (__left_ == 0)
3643 {
3644 if (__size_ < t_end - t_begin)
3645 {
3646 __left_ = t_begin[__size_];
3647 __size_ = 0;
3648 }
3649 else
3650 return false;
3651 }
3652 return true;
3653 }
3654 virtual size_t list_len() const
3655 {
3656 return __left_->list_len();
3657 }
3658 virtual bool is_sub() const
3659 {
3660 return true;
3661 }
3662};
3663
3664class __unscoped_template_name
3665 : public __node
3666{
3667public:
3668 __unscoped_template_name(__node* name, __node* args)
3669 {__left_ = name; __right_ = args;}
3670
3671 virtual size_t first_size() const
3672 {
3673 if (__cached_size_ == -1)
3674 const_cast<long&>(__cached_size_) = __left_->size() + __right_->size();
3675 return __cached_size_;
3676 }
3677 virtual char* first_demangled_name(char* buf) const
3678 {
3679 buf = __left_->get_demangled_name(buf);
3680 return __right_->get_demangled_name(buf);
3681 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003682 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003683 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003684 return __right_->ends_with_template(parsing);
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003685 }
3686 virtual __node* base_name() const
3687 {
3688 return __left_->base_name();
3689 }
3690 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3691 {
3692 return __left_->fix_forward_references(t_begin, t_end) &&
3693 __right_->fix_forward_references(t_begin, t_end);
3694 }
3695};
3696
3697// length == 0: __left_ == NULL
3698// length == 1: __left_ != NULL, __right_ == NULL
3699// length > 1: __left_ != NULL, __right_ != NULL
3700class __list
3701 : public __node
3702{
3703public:
3704 explicit __list(__node* type)
3705 {__left_ = type;}
3706
3707 virtual size_t first_size() const
3708 {
3709 if (__cached_size_ == -1)
3710 {
3711 if (__left_ == NULL)
3712 const_cast<long&>(__cached_size_) = 0;
3713 else if (__right_ == NULL)
3714 const_cast<long&>(__cached_size_) = __left_->size();
3715 else
3716 {
3717 size_t off = __right_->size();
3718 if (off > 0)
3719 off += 2;
3720 const_cast<long&>(__cached_size_) = __left_->size() + off;
3721 }
3722 }
3723 return __cached_size_;
3724 }
3725 virtual char* first_demangled_name(char* buf) const
3726 {
3727 if (__left_ != NULL)
3728 {
3729 char* t = __left_->get_demangled_name(buf + (__size_ ? 2 : 0));
3730 if (__size_ == 0)
3731 buf = t;
3732 else if (t != buf+2)
3733 {
3734 *buf++ = ',';
3735 *buf++ = ' ';
3736 buf = t;
3737 }
3738 if (__right_)
3739 buf = __right_->get_demangled_name(buf);
3740 }
3741 return buf;
3742 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003743 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003744 {
3745 if (__right_ != NULL)
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003746 return __right_->ends_with_template(parsing);
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003747 if (__left_ != NULL)
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003748 return __left_->ends_with_template(parsing);
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003749 return false;
3750 }
3751 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3752 {
3753 bool r = true;
3754 if (__left_)
3755 r = r && __left_->fix_forward_references(t_begin, t_end);
3756 if (__right_)
3757 r = r && __right_->fix_forward_references(t_begin, t_end);
3758 return r;
3759 }
3760 virtual size_t list_len() const
3761 {
3762 if (!__left_)
3763 return 0;
3764 if (!__right_)
3765 return 1;
3766 return 1 + __right_->list_len();
3767 }
3768};
3769
3770class __template_args
3771 : public __node
3772{
3773public:
3774 __template_args(__node* name, __node* list)
3775 {
3776 __left_ = name;
3777 __right_ = list;
3778 }
3779
3780 virtual size_t first_size() const
3781 {
3782 if (__cached_size_ == -1)
3783 {
3784 size_t off = 2;
3785 if (__right_)
3786 {
3787 if (__right_->ends_with_template())
3788 ++off;
3789 off += __right_->size();
3790 }
3791 const_cast<long&>(__cached_size_) = __left_->size() + off;
3792 }
3793 return __cached_size_;
3794 }
3795 virtual char* first_demangled_name(char* buf) const
3796 {
3797 buf = __left_->get_demangled_name(buf);
3798 *buf++ = '<';
3799 if (__right_)
3800 {
3801 buf = __right_->get_demangled_name(buf);
3802 if (buf[-1] == '>')
3803 *buf++ = ' ';
3804 }
3805 *buf++ = '>';
3806 return buf;
3807 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003808 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003809 {
3810 return true;
3811 }
3812 virtual __node* base_name() const
3813 {
3814 return __left_->base_name();
3815 }
3816 virtual bool is_ctor_dtor_conv() const
3817 {
3818 return __left_->is_ctor_dtor_conv();
3819 }
3820 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3821 {
3822 bool r = __left_->fix_forward_references(t_begin, t_end);
3823 if (__right_)
3824 r = r && __right_->fix_forward_references(t_begin, t_end);
3825 return r;
3826 }
3827};
3828
3829class __function_args
3830 : public __node
3831{
3832public:
3833 __function_args(__node* list)
3834 {__right_ = list;}
3835
3836 virtual size_t first_size() const
3837 {
3838 if (__cached_size_ == -1)
3839 const_cast<long&>(__cached_size_) = 2 + __right_->size();
3840 return __cached_size_;
3841 }
3842 virtual char* first_demangled_name(char* buf) const
3843 {
3844 *buf++ = '(';
3845 buf = __right_->get_demangled_name(buf);
3846 *buf++ = ')';
3847 return buf;
3848 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003849 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
3850 {
3851 return __right_->fix_forward_references(t_begin, t_end);
3852 }
3853};
3854
3855class __cv_qualifiers
3856 : public __node
3857{
3858public:
3859 __cv_qualifiers(size_t cv, __node* type)
3860 {
3861 __left_ = type;
3862 __size_ = __left_->is_function() ? cv << 5 : cv;
3863 }
3864
3865 virtual size_t first_size() const
3866 {
3867 size_t s = __left_->first_size();
3868 if (__size_ & 4)
3869 s += sizeof(" restrict")-1;
3870 if (__size_ & 2)
3871 s += sizeof(" volatile")-1;
3872 if (__size_ & 1)
3873 s += sizeof(" const")-1;
3874 if (__size_ & 8)
3875 s += sizeof(" &")-1;
3876 if (__size_ & 16)
3877 s += sizeof(" &&")-1;
3878 return s;
3879 }
3880 virtual char* first_demangled_name(char* buf) const
3881 {
3882 buf = __left_->first_demangled_name(buf);
3883 if (__size_ & 1)
3884 {
3885 const size_t n = sizeof(" const")-1;
3886 strncpy(buf, " const", n);
3887 buf += n;
3888 }
3889 if (__size_ & 2)
3890 {
3891 const size_t n = sizeof(" volatile")-1;
3892 strncpy(buf, " volatile", n);
3893 buf += n;
3894 }
3895 if (__size_ & 4)
3896 {
3897 const size_t n = sizeof(" restrict")-1;
3898 strncpy(buf, " restrict", n);
3899 buf += n;
3900 }
3901 if (__size_ & 8)
3902 {
3903 *buf++ = ' ';
3904 *buf++ = '&';
3905 }
3906 if (__size_ & 16)
3907 {
3908 *buf++ = ' ';
3909 *buf++ = '&';
3910 *buf++ = '&';
3911 }
3912 return buf;
3913 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003914 virtual size_t second_size() const
3915 {
3916 size_t s = __left_->second_size();
3917 if (__size_ & 128)
3918 s += sizeof(" restrict")-1;
3919 if (__size_ & 64)
3920 s += sizeof(" volatile")-1;
3921 if (__size_ & 32)
3922 s += sizeof(" const")-1;
3923 if (__size_ & 256)
3924 s += sizeof(" &")-1;
3925 if (__size_ & 512)
3926 s += sizeof(" &&")-1;
3927 return s;
3928 }
3929 virtual char* second_demangled_name(char* buf) const
3930 {
3931 buf = __left_->second_demangled_name(buf);
3932 if (__size_ & 32)
3933 {
3934 const size_t n = sizeof(" const")-1;
3935 strncpy(buf, " const", n);
3936 buf += n;
3937 }
3938 if (__size_ & 64)
3939 {
3940 const size_t n = sizeof(" volatile")-1;
3941 strncpy(buf, " volatile", n);
3942 buf += n;
3943 }
3944 if (__size_ & 128)
3945 {
3946 const size_t n = sizeof(" restrict")-1;
3947 strncpy(buf, " restrict", n);
3948 buf += n;
3949 }
3950 if (__size_ & 256)
3951 {
3952 *buf++ = ' ';
3953 *buf++ = '&';
3954 }
3955 if (__size_ & 512)
3956 {
3957 *buf++ = ' ';
3958 *buf++ = '&';
3959 *buf++ = '&';
3960 }
3961 return buf;
3962 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003963 virtual __node* base_name() const
3964 {
3965 return __left_->base_name();
3966 }
3967 virtual bool is_reference_or_pointer_to_function_or_array() const
3968 {
3969 return __left_->is_reference_or_pointer_to_function_or_array();
3970 }
3971 virtual bool is_function() const
3972 {
3973 return __left_->is_function();
3974 }
3975 virtual bool is_cv_qualifer() const
3976 {
3977 return true;
3978 }
3979 virtual __node* extract_cv(__node*& rt) const
3980 {
3981 if (rt == this)
3982 {
3983 rt = __left_;
3984 return const_cast<__node*>(static_cast<const __node*>(this));
3985 }
3986 return 0;
3987 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003988 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003989 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00003990 if (parsing)
3991 return __left_->ends_with_template(parsing);
3992 return false;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00003993 }
3994 virtual bool is_ctor_dtor_conv() const
3995 {
3996 return __left_->is_ctor_dtor_conv();
3997 }
3998 virtual bool is_array() const
3999 {
4000 return __left_->is_array();
4001 }
4002 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4003 {
4004 return __left_->fix_forward_references(t_begin, t_end);
4005 }
4006 virtual size_t list_len() const
4007 {
4008 return __left_->list_len();
4009 }
4010};
4011
4012class __extended_qualifier
4013 : public __node
4014{
4015public:
4016 __extended_qualifier(__node* name, __node* type)
4017 {
4018 __left_ = type;
4019 __right_ = name;
4020 __size_ = __left_->is_function() ? 1 : 0;
4021 }
4022
4023 virtual size_t first_size() const
4024 {
4025 size_t s = __left_->first_size();
4026 if (__size_ == 0)
4027 s += __right_->size() + 1;
4028 return s;
4029 }
4030 virtual char* first_demangled_name(char* buf) const
4031 {
4032 buf = __left_->first_demangled_name(buf);
4033 if (__size_ == 0)
4034 {
4035 *buf++ = ' ';
4036 buf = __right_->get_demangled_name(buf);
4037 }
4038 return buf;
4039 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004040 virtual size_t second_size() const
4041 {
4042 size_t s = __left_->second_size();
4043 if (__size_ == 1)
4044 s += __right_->size() + 1;
4045 return s;
4046 }
4047 virtual char* second_demangled_name(char* buf) const
4048 {
4049 buf = __left_->second_demangled_name(buf);
4050 if (__size_ == 1)
4051 {
4052 *buf++ = ' ';
4053 buf = __right_->get_demangled_name(buf);
4054 }
4055 return buf;
4056 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004057 virtual __node* base_name() const
4058 {
4059 return __left_->base_name();
4060 }
4061 virtual bool is_reference_or_pointer_to_function_or_array() const
4062 {
4063 return __left_->is_reference_or_pointer_to_function_or_array();
4064 }
4065 virtual bool is_function() const
4066 {
4067 return __left_->is_function();
4068 }
4069 virtual bool is_cv_qualifer() const
4070 {
4071 return true;
4072 }
4073 virtual __node* extract_cv(__node*& rt) const
4074 {
4075 if (rt == this)
4076 {
4077 rt = __left_;
4078 return const_cast<__node*>(static_cast<const __node*>(this));
4079 }
4080 return 0;
4081 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +00004082 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004083 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00004084 return __left_->ends_with_template(parsing);
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004085 }
4086 virtual bool is_ctor_dtor_conv() const
4087 {
4088 return __left_->is_ctor_dtor_conv();
4089 }
4090 virtual bool is_array() const
4091 {
4092 return __left_->is_array();
4093 }
4094 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4095 {
4096 return __left_->fix_forward_references(t_begin, t_end);
4097 }
4098 virtual size_t list_len() const
4099 {
4100 return __left_->list_len();
4101 }
4102};
4103
4104class __function
4105 : public __node
4106{
4107public:
4108
4109 __function(__node* name, __node* signature, size_t ret_goes_first = true)
4110 {
4111 __size_ = ret_goes_first;
4112 __left_ = name;
4113 __right_ = signature;
4114 }
4115
4116 virtual size_t first_size() const
4117 {
4118 size_t off = 0;
4119 if (__size_)
4120 {
4121 off = __right_->first_size();
4122 if (off > 0 && (__left_ == NULL ||
4123 !__right_->__left_->is_reference_or_pointer_to_function_or_array()))
4124 ++off;
4125 }
4126 else
4127 off = 5;
4128 if (__left_)
4129 off += __left_->first_size();
4130 else
4131 ++off;
4132 return off;
4133 }
4134
4135 virtual size_t second_size() const
4136 {
4137 size_t off = 0;
4138 if (__left_ == NULL)
4139 off = 1;
4140 off += __right_->second_size();
4141 if (!__size_)
4142 {
4143 off += 2;
4144 off += __right_->first_size();
4145 }
4146 return off;
4147 }
4148
4149 virtual char* first_demangled_name(char* buf) const
4150 {
4151 if (__size_)
4152 {
4153 const char* t = buf;
4154 buf = __right_->first_demangled_name(buf);
4155 if (buf != t && (__left_ == NULL ||
4156 !__right_->__left_->is_reference_or_pointer_to_function_or_array()))
4157 *buf++ = ' ';
4158 }
4159 else
4160 {
4161 strncpy(buf, "auto ", 5);
4162 buf += 5;
4163 }
4164 if (__left_)
4165 buf = __left_->first_demangled_name(buf);
4166 else
4167 *buf++ = '(';
4168 return buf;
4169 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004170 virtual char* second_demangled_name(char* buf) const
4171 {
4172 if (__left_ == NULL)
4173 *buf++ = ')';
4174 buf = __right_->second_demangled_name(buf);
4175 if (!__size_)
4176 {
4177 *buf++ = '-';
4178 *buf++ = '>';
4179 buf = __right_->first_demangled_name(buf);
4180 }
4181 return buf;
4182 }
Howard Hinnant89df8ad2011-08-12 17:33:10 +00004183 virtual char* get_demangled_name(char* buf) const
4184 {
4185 if (__size_)
4186 {
4187 const char* t = buf;
4188 buf = __right_->first_demangled_name(buf);
4189 if (buf != t && (__left_ == NULL ||
4190 !__right_->__left_->is_reference_or_pointer_to_function_or_array()))
4191 *buf++ = ' ';
4192 }
4193 else
4194 {
4195 strncpy(buf, "auto ", 5);
4196 buf += 5;
4197 }
4198 if (__left_)
4199 buf = __left_->first_demangled_name(buf);
4200 buf = __right_->second_demangled_name(buf);
4201 if (!__size_)
4202 {
4203 *buf++ = '-';
4204 *buf++ = '>';
4205 buf = __right_->first_demangled_name(buf);
4206 }
4207 return buf;
4208 }
4209
4210 virtual size_t size() const
4211 {
4212 if (__cached_size_ == -1)
4213 {
4214 size_t off = 0;
4215 if (__size_)
4216 {
4217 off = __right_->first_size();
4218 if (off > 0 && (__left_ == NULL ||
4219 !__right_->__left_->is_reference_or_pointer_to_function_or_array()))
4220 ++off;
4221 }
4222 else
4223 off = 5;
4224 if (__left_)
4225 off += __left_->first_size();
4226 off += __right_->second_size();
4227 if (!__size_)
4228 {
4229 off += 2;
4230 off += __right_->first_size();
4231 }
4232 const_cast<long&>(__cached_size_) = off;
4233 }
4234 return __cached_size_;
4235 }
4236
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004237 virtual bool is_function() const
4238 {
4239 return true;
4240 }
4241 virtual bool is_ctor_dtor_conv() const
4242 {
4243 return __left_->is_ctor_dtor_conv();
4244 }
4245 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4246 {
4247 bool r = true;
4248 if (__left_)
4249 r = r && __left_->fix_forward_references(t_begin, t_end);
4250 r = r && __right_->fix_forward_references(t_begin, t_end);
4251 return r;
4252 }
4253};
4254
4255class __function_signature
4256 : public __node
4257{
4258public:
4259 __function_signature(__node* ret, __node* args)
4260 {
4261 __left_ = ret;
4262 __right_ = args;
4263 }
4264 virtual size_t first_size() const
4265 {
4266 return __left_ ? __left_->first_size() : 0;
4267 }
4268
4269 virtual size_t second_size() const
4270 {
4271 return 2 + (__right_ ? __right_->size() : 0)
4272 + (__left_ ? __left_->second_size() : 0);
4273 }
4274
4275 virtual char* first_demangled_name(char* buf) const
4276 {
4277 if (__left_)
4278 buf = __left_->first_demangled_name(buf);
4279 return buf;
4280 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004281
4282 virtual char* second_demangled_name(char* buf) const
4283 {
4284 *buf++ = '(';
4285 if (__right_)
4286 buf = __right_->get_demangled_name(buf);
4287 *buf++ = ')';
4288 if (__left_)
4289 buf = __left_->second_demangled_name(buf);
4290 return buf;
4291 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004292 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4293 {
4294 bool r = true;
4295 if (__left_)
4296 r = r && __left_->fix_forward_references(t_begin, t_end);
4297 if (__right_)
4298 r = r && __right_->fix_forward_references(t_begin, t_end);
4299 return r;
4300 }
4301};
4302
4303class __pointer_to
4304 : public __node
4305{
4306public:
4307
4308 explicit __pointer_to(__node* type)
4309 {
4310 __left_ = type;
4311 }
4312 virtual size_t first_size() const
4313 {
4314 return __left_->first_size() + (__left_->is_array() ? 3 : 1);
4315 }
4316 virtual size_t second_size() const
4317 {
4318 return __left_->second_size() + (__left_->is_array() ? 1 : 0);
4319 }
4320 virtual char* first_demangled_name(char* buf) const
4321 {
4322 buf = __left_->first_demangled_name(buf);
4323 if (__left_->is_array())
4324 {
4325 *buf++ = ' ';
4326 *buf++ = '(';
4327 *buf++ = '*';
4328 }
4329 else
4330 *buf++ = '*';
4331 return buf;
4332 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004333 virtual char* second_demangled_name(char* buf) const
4334 {
4335 if (__left_->is_array())
4336 *buf++ = ')';
4337 return __left_->second_demangled_name(buf);
4338 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004339 virtual __node* base_name() const
4340 {
4341 return __left_->base_name();
4342 }
4343 virtual bool is_reference_or_pointer_to_function_or_array() const
4344 {
4345 return __left_->is_function() ||
4346 __left_->is_reference_or_pointer_to_function_or_array();
4347 }
4348 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4349 {
4350 return __left_->fix_forward_references(t_begin, t_end);
4351 }
4352 virtual size_t list_len() const
4353 {
4354 return __left_->list_len();
4355 }
4356};
4357
4358class __lvalue_reference_to
4359 : public __node
4360{
4361public:
4362
4363 explicit __lvalue_reference_to(__node* type)
4364 {
4365 __left_ = type;
4366 }
4367 virtual size_t first_size() const
4368 {
4369 return __left_->first_size() + (__left_->is_array() ? 3 : 1);
4370 }
4371 virtual size_t second_size() const
4372 {
4373 return __left_->second_size() + (__left_->is_array() ? 1 : 0);
4374 }
4375 virtual char* first_demangled_name(char* buf) const
4376 {
4377 buf = __left_->first_demangled_name(buf);
4378 if (__left_->is_array())
4379 {
4380 *buf++ = ' ';
4381 *buf++ = '(';
4382 *buf++ = '&';
4383 }
4384 else
4385 *buf++ = '&';
4386 return buf;
4387 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004388 virtual char* second_demangled_name(char* buf) const
4389 {
4390 if (__left_->is_array())
4391 *buf++ = ')';
4392 return __left_->second_demangled_name(buf);
4393 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004394 virtual __node* base_name() const
4395 {
4396 return __left_->base_name();
4397 }
4398 virtual bool is_reference_or_pointer_to_function_or_array() const
4399 {
4400 return __left_->is_function();
4401 }
4402 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4403 {
4404 return __left_->fix_forward_references(t_begin, t_end);
4405 }
4406 virtual size_t list_len() const
4407 {
4408 return __left_->list_len();
4409 }
4410};
4411
4412class __rvalue_reference_to
4413 : public __node
4414{
4415public:
4416
4417 explicit __rvalue_reference_to(__node* type)
4418 {
4419 __left_ = type;
4420 }
4421 virtual size_t first_size() const
4422 {
4423 return __left_->first_size() + (__left_->is_array() ? 4 : 2);
4424 }
4425 virtual size_t second_size() const
4426 {
4427 return __left_->second_size() + (__left_->is_array() ? 1 : 0);
4428 }
4429 virtual char* first_demangled_name(char* buf) const
4430 {
4431 buf = __left_->first_demangled_name(buf);
4432 if (__left_->is_array())
4433 {
4434 strncpy(buf, " (&&", 4);
4435 buf += 4;
4436 }
4437 else
4438 {
4439 *buf++ = '&';
4440 *buf++ = '&';
4441 }
4442 return buf;
4443 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004444 virtual char* second_demangled_name(char* buf) const
4445 {
4446 if (__left_->is_array())
4447 *buf++ = ')';
4448 return __left_->second_demangled_name(buf);
4449 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004450 virtual __node* base_name() const
4451 {
4452 return __left_->base_name();
4453 }
4454 virtual bool is_reference_or_pointer_to_function_or_array() const
4455 {
4456 return __left_->is_function();
4457 }
4458 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4459 {
4460 return __left_->fix_forward_references(t_begin, t_end);
4461 }
4462 virtual size_t list_len() const
4463 {
4464 return __left_->list_len();
4465 }
4466};
4467
4468class __d_complex
4469 : public __node
4470{
4471 static const size_t n = sizeof(" complex") - 1;
4472public:
4473
4474 explicit __d_complex(__node* type)
4475 {
4476 __left_ = type;
4477 }
4478 virtual size_t first_size() const
4479 {
4480 if (__cached_size_ == -1)
4481 const_cast<long&>(__cached_size_) = n + __left_->size();
4482 return __cached_size_;
4483 }
4484 virtual char* first_demangled_name(char* buf) const
4485 {
4486 buf = __left_->get_demangled_name(buf);
4487 strncpy(buf, " complex", n);
4488 return buf + n;
4489 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004490 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4491 {
4492 return __left_->fix_forward_references(t_begin, t_end);
4493 }
4494};
4495
4496class __imaginary
4497 : public __node
4498{
4499 static const size_t n = sizeof(" imaginary") - 1;
4500public:
4501
4502 explicit __imaginary(__node* type)
4503 {
4504 __left_ = type;
4505 }
4506 virtual size_t first_size() const
4507 {
4508 if (__cached_size_ == -1)
4509 const_cast<long&>(__cached_size_) = n + __left_->size();
4510 return __cached_size_;
4511 }
4512 virtual char* first_demangled_name(char* buf) const
4513 {
4514 buf = __left_->get_demangled_name(buf);
4515 strncpy(buf, " imaginary", n);
4516 return buf + n;
4517 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004518 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4519 {
4520 return __left_->fix_forward_references(t_begin, t_end);
4521 }
4522};
4523
4524class __pack_expansion
4525 : public __node
4526{
4527public:
4528
4529 explicit __pack_expansion(__node* type)
4530 {
4531 __left_ = type;
4532 }
4533 virtual size_t first_size() const
4534 {
4535 if (__cached_size_ == -1)
4536 {
4537 size_t len = __left_->list_len();
4538 size_t off = 0;
4539 if (len != 0)
4540 {
4541 if (__left_->is_sub() || len == 1)
4542 off = __left_->size();
4543 else
4544 {
4545 __node* top = __left_;
4546 __node* bottom = top;
4547 while (!bottom->__left_->is_sub())
4548 bottom = bottom->__left_;
4549 __node* sub = bottom->__left_;
4550 __node* i = sub->__left_;
4551 bool first = true;
4552 top->reset_cached_size();
4553 while (i)
4554 {
4555 if (!first)
4556 off += 2;
4557 bottom->__left_ = i->__left_;
4558 off += top->size();
4559 top->reset_cached_size();
4560 i = i->__right_;
4561 first = false;
4562 }
4563 bottom->__left_ = sub;
4564 }
4565 }
4566 const_cast<long&>(__cached_size_) = off;
4567 }
4568 return __cached_size_;
4569 }
4570 virtual char* first_demangled_name(char* buf) const
4571 {
4572 size_t len = __left_->list_len();
4573 if (len != 0)
4574 {
4575 if (__left_->is_sub() || len == 1)
4576 buf = __left_->get_demangled_name(buf);
4577 else
4578 {
4579 __node* top = __left_;
4580 __node* bottom = top;
4581 while (!bottom->__left_->is_sub())
4582 bottom = bottom->__left_;
4583 __node* sub = bottom->__left_;
4584 __node* i = sub->__left_;
4585 bool first = true;
4586 top->reset_cached_size();
4587 while (i)
4588 {
4589 if (!first)
4590 {
4591 *buf++ = ',';
4592 *buf++ = ' ';
4593 }
4594 bottom->__left_ = i->__left_;
4595 buf = top->get_demangled_name(buf);
4596 top->reset_cached_size();
4597 i = i->__right_;
4598 first = false;
4599 }
4600 bottom->__left_ = sub;
4601 }
4602 }
4603 return buf;
4604 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004605 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
4606 {
4607 return __left_->fix_forward_references(t_begin, t_end);
4608 }
4609};
4610
4611class __void
4612 : public __node
4613{
4614 static const size_t n = sizeof("void") - 1;
4615public:
4616
4617 virtual size_t first_size() const {return n;}
4618 virtual char* first_demangled_name(char* buf) const
4619 {
4620 strncpy(buf, "void", n);
4621 return buf + n;
4622 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004623};
4624
4625class __wchar_t
4626 : public __node
4627{
4628 static const size_t n = sizeof("wchar_t") - 1;
4629public:
4630
4631 virtual size_t first_size() const {return n;}
4632 virtual char* first_demangled_name(char* buf) const
4633 {
4634 strncpy(buf, "wchar_t", n);
4635 return buf + n;
4636 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004637};
4638
4639class __wchar_t_literal
4640 : public __node
4641{
4642public:
4643 explicit __wchar_t_literal(const char* __first, const char* __last)
4644 {
4645 __name_ = __first;
4646 __size_ = __last - __first;
4647 }
4648
4649 virtual size_t first_size() const
4650 {
4651 return __size_+9;
4652 }
4653 virtual char* first_demangled_name(char* buf) const
4654 {
4655 strncpy(buf, "(wchar_t)", 9);
4656 buf += 9;
4657 strncpy(buf, __name_, __size_);
4658 return buf + __size_;
4659 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004660};
4661
4662class __bool
4663 : public __node
4664{
4665 static const size_t n = sizeof("bool") - 1;
4666public:
4667
4668 virtual size_t first_size() const {return n;}
4669 virtual char* first_demangled_name(char* buf) const
4670 {
4671 strncpy(buf, "bool", n);
4672 return buf + n;
4673 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004674};
4675
4676class __bool_literal
4677 : public __node
4678{
4679public:
4680 explicit __bool_literal(const char* __name, unsigned __size)
4681 {
4682 __name_ = __name;
4683 __size_ = __size;
4684 }
4685
4686 virtual size_t first_size() const
4687 {
4688 return __size_;
4689 }
4690 virtual char* first_demangled_name(char* buf) const
4691 {
4692 strncpy(buf, __name_, __size_);
4693 return buf + __size_;
4694 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004695};
4696
4697class __char
4698 : public __node
4699{
4700 static const size_t n = sizeof("char") - 1;
4701public:
4702
4703 virtual size_t first_size() const {return n;}
4704 virtual char* first_demangled_name(char* buf) const
4705 {
4706 strncpy(buf, "char", n);
4707 return buf + n;
4708 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004709};
4710
4711class __char_literal
4712 : public __node
4713{
4714public:
4715 explicit __char_literal(const char* __first, const char* __last)
4716 {
4717 __name_ = __first;
4718 __size_ = __last - __first;
4719 }
4720
4721 virtual size_t first_size() const
4722 {
4723 return __size_+6;
4724 }
4725 virtual char* first_demangled_name(char* buf) const
4726 {
4727 strncpy(buf, "(char)", 6);
4728 buf += 6;
4729 if (*__name_ == 'n')
4730 {
4731 *buf++ = '-'; // strncpy(buf+6, "-", 1);
4732 strncpy(buf, __name_+1, __size_-1);
4733 buf += __size_ - 1;
4734 }
4735 else
4736 {
4737 strncpy(buf, __name_, __size_);
4738 buf += __size_;
4739 }
4740 return buf;
4741 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004742};
4743
4744class __signed_char
4745 : public __node
4746{
4747 static const size_t n = sizeof("signed char") - 1;
4748public:
4749
4750 virtual size_t first_size() const {return n;}
4751 virtual char* first_demangled_name(char* buf) const
4752 {
4753 strncpy(buf, "signed char", n);
4754 return buf + n;
4755 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004756};
4757
4758class __signed_char_literal
4759 : public __node
4760{
4761public:
4762 explicit __signed_char_literal(const char* __first, const char* __last)
4763 {
4764 __name_ = __first;
4765 __size_ = __last - __first;
4766 }
4767
4768 virtual size_t first_size() const
4769 {
4770 return __size_+13;
4771 }
4772 virtual char* first_demangled_name(char* buf) const
4773 {
4774 strncpy(buf, "(signed char)", 13);
4775 buf += 13;
4776 if (*__name_ == 'n')
4777 {
4778 *buf++ = '-';
4779 strncpy(buf, __name_+1, __size_-1);
4780 buf += __size_ - 1;
4781 }
4782 else
4783 {
4784 strncpy(buf, __name_, __size_);
4785 buf += __size_;
4786 }
4787 return buf;
4788 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004789};
4790
4791class __unsigned_char
4792 : public __node
4793{
4794 static const size_t n = sizeof("unsigned char") - 1;
4795public:
4796
4797 virtual size_t first_size() const {return n;}
4798 virtual char* first_demangled_name(char* buf) const
4799 {
4800 strncpy(buf, "unsigned char", n);
4801 return buf + n;
4802 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004803};
4804
4805class __unsigned_char_literal
4806 : public __node
4807{
4808public:
4809 explicit __unsigned_char_literal(const char* __first, const char* __last)
4810 {
4811 __name_ = __first;
4812 __size_ = __last - __first;
4813 }
4814
4815 virtual size_t first_size() const
4816 {
4817 return __size_+15;
4818 }
4819 virtual char* first_demangled_name(char* buf) const
4820 {
4821 strncpy(buf, "(unsigned char)", 15);
4822 buf += 15;
4823 strncpy(buf, __name_, __size_);
4824 return buf + __size_;
4825 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004826};
4827
4828class __short
4829 : public __node
4830{
4831 static const size_t n = sizeof("short") - 1;
4832public:
4833
4834 virtual size_t first_size() const {return n;}
4835 virtual char* first_demangled_name(char* buf) const
4836 {
4837 strncpy(buf, "short", n);
4838 return buf + n;
4839 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004840};
4841
4842class __short_literal
4843 : public __node
4844{
4845public:
4846 explicit __short_literal(const char* __first, const char* __last)
4847 {
4848 __name_ = __first;
4849 __size_ = __last - __first;
4850 }
4851
4852 virtual size_t first_size() const
4853 {
4854 return __size_+7;
4855 }
4856 virtual char* first_demangled_name(char* buf) const
4857 {
4858 strncpy(buf, "(short)", 7);
4859 buf += 7;
4860 if (*__name_ == 'n')
4861 {
4862 *buf++ = '-';
4863 strncpy(buf, __name_+1, __size_-1);
4864 buf += __size_ - 1;
4865 }
4866 else
4867 {
4868 strncpy(buf, __name_, __size_);
4869 buf += __size_;
4870 }
4871 return buf;
4872 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004873};
4874
4875class __unsigned_short
4876 : public __node
4877{
4878 static const size_t n = sizeof("unsigned short") - 1;
4879public:
4880
4881 virtual size_t first_size() const {return n;}
4882 virtual char* first_demangled_name(char* buf) const
4883 {
4884 strncpy(buf, "unsigned short", n);
4885 return buf + n;
4886 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004887};
4888
4889class __unsigned_short_literal
4890 : public __node
4891{
4892public:
4893 explicit __unsigned_short_literal(const char* __first, const char* __last)
4894 {
4895 __name_ = __first;
4896 __size_ = __last - __first;
4897 }
4898
4899 virtual size_t first_size() const
4900 {
4901 return __size_+16;
4902 }
4903 virtual char* first_demangled_name(char* buf) const
4904 {
4905 strncpy(buf, "(unsigned short)", 16);
4906 buf += 16;
4907 strncpy(buf, __name_, __size_);
4908 return buf + __size_;
4909 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004910};
4911
4912class __int
4913 : public __node
4914{
4915 static const size_t n = sizeof("int") - 1;
4916public:
4917
4918 virtual size_t first_size() const {return n;}
4919 virtual char* first_demangled_name(char* buf) const
4920 {
4921 *buf++ = 'i';
4922 *buf++ = 'n';
4923 *buf++ = 't';
4924 return buf;
4925 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004926};
4927
4928class __int_literal
4929 : public __node
4930{
4931public:
4932 explicit __int_literal(const char* __first, const char* __last)
4933 {
4934 __name_ = __first;
4935 __size_ = __last - __first;
4936 }
4937
4938 virtual size_t first_size() const
4939 {
4940 return __size_;
4941 }
4942 virtual char* first_demangled_name(char* buf) const
4943 {
4944 if (*__name_ == 'n')
4945 {
4946 *buf++ = '-';
4947 strncpy(buf, __name_+1, __size_-1);
4948 buf += __size_ - 1;
4949 }
4950 else
4951 {
4952 strncpy(buf, __name_, __size_);
4953 buf += __size_;
4954 }
4955 return buf;
4956 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004957};
4958
4959class __unsigned_int
4960 : public __node
4961{
4962 static const size_t n = sizeof("unsigned int") - 1;
4963public:
4964
4965 virtual size_t first_size() const {return n;}
4966 virtual char* first_demangled_name(char* buf) const
4967 {
4968 strncpy(buf, "unsigned int", n);
4969 return buf + n;
4970 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004971};
4972
4973class __unsigned_int_literal
4974 : public __node
4975{
4976public:
4977 explicit __unsigned_int_literal(const char* __first, const char* __last)
4978 {
4979 __name_ = __first;
4980 __size_ = __last - __first;
4981 }
4982
4983 virtual size_t first_size() const
4984 {
4985 return __size_+1;
4986 }
4987 virtual char* first_demangled_name(char* buf) const
4988 {
4989 strncpy(buf, __name_, __size_);
4990 buf += __size_;
4991 *buf++ = 'u';
4992 return buf;
4993 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00004994};
4995
4996class __long
4997 : public __node
4998{
4999 static const size_t n = sizeof("long") - 1;
5000public:
5001
5002 virtual size_t first_size() const {return n;}
5003 virtual char* first_demangled_name(char* buf) const
5004 {
5005 strncpy(buf, "long", n);
5006 return buf + n;
5007 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005008};
5009
5010class __long_literal
5011 : public __node
5012{
5013public:
5014 explicit __long_literal(const char* __first, const char* __last)
5015 {
5016 __name_ = __first;
5017 __size_ = __last - __first;
5018 }
5019
5020 virtual size_t first_size() const
5021 {
5022 return __size_+1;
5023 }
5024 virtual char* first_demangled_name(char* buf) const
5025 {
5026 if (*__name_ == 'n')
5027 {
5028 *buf++ = '-'; // strncpy(buf, "-", 1);
5029 strncpy(buf, __name_+1, __size_-1);
5030 buf += __size_ - 1;
5031 }
5032 else
5033 {
5034 strncpy(buf, __name_, __size_);
5035 buf += __size_;
5036 }
5037 *buf++ = 'l';
5038 return buf;
5039 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005040};
5041
5042class __unsigned_long
5043 : public __node
5044{
5045 static const size_t n = sizeof("unsigned long") - 1;
5046public:
5047
5048 virtual size_t first_size() const {return n;}
5049 virtual char* first_demangled_name(char* buf) const
5050 {
5051 strncpy(buf, "unsigned long", n);
5052 return buf + n;
5053 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005054};
5055
5056class __unsigned_long_literal
5057 : public __node
5058{
5059public:
5060 explicit __unsigned_long_literal(const char* __first, const char* __last)
5061 {
5062 __name_ = __first;
5063 __size_ = __last - __first;
5064 }
5065
5066 virtual size_t first_size() const
5067 {
5068 return __size_+2;
5069 }
5070 virtual char* first_demangled_name(char* buf) const
5071 {
5072 strncpy(buf, __name_, __size_);
5073 buf += __size_;
5074 *buf++ = 'u';
5075 *buf++ = 'l';
5076 return buf;
5077 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005078};
5079
5080class __long_long
5081 : public __node
5082{
5083 static const size_t n = sizeof("long long") - 1;
5084public:
5085
5086 virtual size_t first_size() const {return n;}
5087 virtual char* first_demangled_name(char* buf) const
5088 {
5089 strncpy(buf, "long long", n);
5090 return buf + n;
5091 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005092};
5093
5094class __long_long_literal
5095 : public __node
5096{
5097public:
5098 explicit __long_long_literal(const char* __first, const char* __last)
5099 {
5100 __name_ = __first;
5101 __size_ = __last - __first;
5102 }
5103
5104 virtual size_t first_size() const
5105 {
5106 return __size_+2;
5107 }
5108 virtual char* first_demangled_name(char* buf) const
5109 {
5110 if (*__name_ == 'n')
5111 {
5112 *buf++ = '-';
5113 strncpy(buf, __name_+1, __size_-1);
5114 buf += __size_ - 1;
5115 }
5116 else
5117 {
5118 strncpy(buf, __name_, __size_);
5119 buf += __size_;
5120 }
5121 *buf++ = 'l';
5122 *buf++ = 'l';
5123 return buf;
5124 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005125};
5126
5127class __unsigned_long_long
5128 : public __node
5129{
5130 static const size_t n = sizeof("unsigned long long") - 1;
5131public:
5132
5133 virtual size_t first_size() const {return n;}
5134 virtual char* first_demangled_name(char* buf) const
5135 {
5136 strncpy(buf, "unsigned long long", n);
5137 return buf + n;
5138 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005139};
5140
5141class __unsigned_long_long_literal
5142 : public __node
5143{
5144public:
5145 explicit __unsigned_long_long_literal(const char* __first, const char* __last)
5146 {
5147 __name_ = __first;
5148 __size_ = __last - __first;
5149 }
5150
5151 virtual size_t first_size() const
5152 {
5153 return __size_+3;
5154 }
5155 virtual char* first_demangled_name(char* buf) const
5156 {
5157 strncpy(buf, __name_, __size_);
5158 buf += __size_;
5159 *buf++ = 'u';
5160 *buf++ = 'l';
5161 *buf++ = 'l';
5162 return buf;
5163 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005164};
5165
5166class __int128
5167 : public __node
5168{
5169 static const size_t n = sizeof("__int128") - 1;
5170public:
5171
5172 virtual size_t first_size() const {return n;}
5173 virtual char* first_demangled_name(char* buf) const
5174 {
5175 strncpy(buf, "__int128", n);
5176 return buf + n;
5177 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005178};
5179
5180class __int128_literal
5181 : public __node
5182{
5183public:
5184 explicit __int128_literal(const char* __first, const char* __last)
5185 {
5186 __name_ = __first;
5187 __size_ = __last - __first;
5188 }
5189
5190 virtual size_t first_size() const
5191 {
5192 return __size_+10;
5193 }
5194 virtual char* first_demangled_name(char* buf) const
5195 {
5196 strncpy(buf, "(__int128)", 10);
5197 buf += 10;
5198 if (*__name_ == 'n')
5199 {
5200 *buf++ = '-';
5201 strncpy(buf, __name_+1, __size_-1);
5202 buf += __size_ - 1;
5203 }
5204 else
5205 {
5206 strncpy(buf, __name_, __size_);
5207 buf += __size_;
5208 }
5209 return buf;
5210 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005211};
5212
5213class __unsigned_int128
5214 : public __node
5215{
5216 static const size_t n = sizeof("unsigned __int128") - 1;
5217public:
5218
5219 virtual size_t first_size() const {return n;}
5220 virtual char* first_demangled_name(char* buf) const
5221 {
5222 strncpy(buf, "unsigned __int128", n);
5223 return buf + n;
5224 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005225};
5226
5227class __unsigned_int128_literal
5228 : public __node
5229{
5230public:
5231 explicit __unsigned_int128_literal(const char* __first, const char* __last)
5232 {
5233 __name_ = __first;
5234 __size_ = __last - __first;
5235 }
5236
5237 virtual size_t first_size() const
5238 {
5239 return __size_+19;
5240 }
5241 virtual char* first_demangled_name(char* buf) const
5242 {
5243 strncpy(buf, "(unsigned __int128)", 19);
5244 buf += 19;
5245 strncpy(buf, __name_, __size_);
5246 return buf + __size_;
5247 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005248};
5249
5250class __float_literal
5251 : public __node
5252{
5253public:
5254 explicit __float_literal(float value)
5255 {
5256 __value_ = value;
5257 }
5258
5259 virtual size_t first_size() const
5260 {
5261 if (__cached_size_ == -1)
5262 {
5263 char num[20] = {0};
5264 float v = static_cast<float>(__value_);
5265 const_cast<long&>(__cached_size_) = sprintf(num, "%a", v)+1;
5266 }
5267 return __cached_size_;
5268 }
5269 virtual char* first_demangled_name(char* buf) const
5270 {
5271 char num[20] = {0};
5272 float v = static_cast<float>(__value_);
5273 int n = sprintf(num, "%a", v);
5274 strncpy(buf, num, n);
5275 buf += n;
5276 *buf++ = 'f';
5277 return buf;
5278 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005279};
5280
5281class __float
5282 : public __node
5283{
5284 static const size_t n = sizeof("float") - 1;
5285public:
5286
5287 virtual size_t first_size() const {return n;}
5288 virtual char* first_demangled_name(char* buf) const
5289 {
5290 strncpy(buf, "float", n);
5291 return buf + n;
5292 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005293};
5294
5295class __double_literal
5296 : public __node
5297{
5298public:
5299 explicit __double_literal(double value)
5300 {
5301 __value_ = value;
5302 }
5303
5304 virtual size_t first_size() const
5305 {
5306 if (__cached_size_ == -1)
5307 {
5308 char num[30] = {0};
5309 double v = static_cast<double>(__value_);
5310 const_cast<long&>(__cached_size_) = sprintf(num, "%a", v);
5311 }
5312 return __cached_size_;
5313 }
5314 virtual char* first_demangled_name(char* buf) const
5315 {
5316 char num[30] = {0};
5317 double v = static_cast<double>(__value_);
5318 int n = sprintf(num, "%a", v);
5319 strncpy(buf, num, n);
5320 return buf + n;
5321 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005322};
5323
5324class __double
5325 : public __node
5326{
5327 static const size_t n = sizeof("double") - 1;
5328public:
5329
5330 virtual size_t first_size() const {return n;}
5331 virtual char* first_demangled_name(char* buf) const
5332 {
5333 strncpy(buf, "double", n);
5334 return buf + n;
5335 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005336};
5337
5338class __long_double
5339 : public __node
5340{
5341 static const size_t n = sizeof("long double") - 1;
5342public:
5343
5344 virtual size_t first_size() const {return n;}
5345 virtual char* first_demangled_name(char* buf) const
5346 {
5347 strncpy(buf, "long double", n);
5348 return buf + n;
5349 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005350};
5351
5352class __float128
5353 : public __node
5354{
5355 static const size_t n = sizeof("__float128") - 1;
5356public:
5357
5358 virtual size_t first_size() const {return n;}
5359 virtual char* first_demangled_name(char* buf) const
5360 {
5361 strncpy(buf, "__float128", n);
5362 return buf + n;
5363 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005364};
5365
5366class __ellipsis
5367 : public __node
5368{
5369 static const size_t n = sizeof("...") - 1;
5370public:
5371
5372 virtual size_t first_size() const {return n;}
5373 virtual char* first_demangled_name(char* buf) const
5374 {
5375 *buf++ = '.';
5376 *buf++ = '.';
5377 *buf++ = '.';
5378 return buf;
5379 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005380};
5381
5382class __decimal64
5383 : public __node
5384{
5385 static const size_t n = sizeof("decimal64") - 1;
5386public:
5387
5388 virtual size_t first_size() const {return n;}
5389 virtual char* first_demangled_name(char* buf) const
5390 {
5391 strncpy(buf, "decimal64", n);
5392 return buf + n;
5393 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005394};
5395
5396class __decimal128
5397 : public __node
5398{
5399 static const size_t n = sizeof("decimal128") - 1;
5400public:
5401
5402 virtual size_t first_size() const {return n;}
5403 virtual char* first_demangled_name(char* buf) const
5404 {
5405 strncpy(buf, "decimal128", n);
5406 return buf + n;
5407 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005408};
5409
5410class __decimal32
5411 : public __node
5412{
5413 static const size_t n = sizeof("decimal32") - 1;
5414public:
5415
5416 virtual size_t first_size() const {return n;}
5417 virtual char* first_demangled_name(char* buf) const
5418 {
5419 strncpy(buf, "decimal32", n);
5420 return buf + n;
5421 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005422};
5423
5424class __decimal16
5425 : public __node
5426{
5427 static const size_t n = sizeof("decimal16") - 1;
5428public:
5429
5430 virtual size_t first_size() const {return n;}
5431 virtual char* first_demangled_name(char* buf) const
5432 {
5433 strncpy(buf, "decimal16", n);
5434 return buf + n;
5435 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005436};
5437
5438class __d_char32_t
5439 : public __node
5440{
5441 static const size_t n = sizeof("char32_t") - 1;
5442public:
5443
5444 virtual size_t first_size() const {return n;}
5445 virtual char* first_demangled_name(char* buf) const
5446 {
5447 strncpy(buf, "char32_t", n);
5448 return buf + n;
5449 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005450};
5451
5452class __d_char16_t
5453 : public __node
5454{
5455 static const size_t n = sizeof("char16_t") - 1;
5456public:
5457
5458 virtual size_t first_size() const {return n;}
5459 virtual char* first_demangled_name(char* buf) const
5460 {
5461 strncpy(buf, "char16_t", n);
5462 return buf + n;
5463 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005464};
5465
5466class __auto
5467 : public __node
5468{
5469 static const size_t n = sizeof("auto") - 1;
5470public:
5471
5472 virtual size_t first_size() const {return n;}
5473 virtual char* first_demangled_name(char* buf) const
5474 {
5475 strncpy(buf, "auto", n);
5476 return buf + n;
5477 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005478};
5479
5480class __nullptr_t
5481 : public __node
5482{
5483 static const size_t n = sizeof("std::nullptr_t") - 1;
5484public:
5485
5486 virtual size_t first_size() const {return n;}
5487 virtual char* first_demangled_name(char* buf) const
5488 {
5489 strncpy(buf, "std::nullptr_t", n);
5490 return buf + n;
5491 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005492};
5493
5494class __array
5495 : public __node
5496{
5497public:
5498
5499 explicit __array(__node* type)
5500 {
5501 __left_ = type;
5502 }
5503
5504 __array(__node* type, size_t dim)
5505 {
5506 __left_ = type;
5507 __size_ = dim;
5508 }
5509
5510 __array(__node* type, __node* dim)
5511 {
5512 __left_ = type;
5513 __right_ = dim;
5514 }
5515
5516 virtual size_t size() const
5517 {
5518 if (__cached_size_ == -1)
5519 {
5520 size_t r = __left_->size() + 3;
5521 if (__right_ != 0)
5522 r += __right_->size();
5523 else if (__size_ != 0)
5524 r += snprintf(0, 0, "%ld", __size_);
5525 const_cast<long&>(__cached_size_) = r;
5526 }
5527 return __cached_size_;
5528 }
5529
5530 virtual char* get_demangled_name(char* buf) const
5531 {
5532 buf = __left_->get_demangled_name(buf);
5533 *buf++ = ' ';
5534 *buf++ = '[';
5535 if (__right_ != 0)
5536 buf = __right_->get_demangled_name(buf);
5537 else if (__size_ != 0)
5538 {
5539 size_t rs = sprintf(buf, "%ld", __size_);
5540 buf += rs;
5541 }
5542 *buf++ = ']';
5543 return buf;
5544 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005545
5546 virtual size_t first_size() const
5547 {
5548 return __left_->first_size();
5549 }
5550
5551 virtual char* first_demangled_name(char* buf) const
5552 {
5553 return __left_->first_demangled_name(buf);
5554 }
5555
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005556 virtual size_t second_size() const
5557 {
5558 size_t r = 2 + __left_->second_size();
5559 if (!__left_->is_array())
5560 ++r;
5561 if (__right_ != 0)
5562 r += __right_->size();
5563 else if (__size_ != 0)
5564 r += snprintf(0, 0, "%ld", __size_);
5565 return r;
5566 }
5567
5568 virtual char* second_demangled_name(char* buf) const
5569 {
5570 *buf++ = ' ';
5571 *buf++ = '[';
5572 if (__right_ != 0)
5573 buf = __right_->get_demangled_name(buf);
5574 else if (__size_ != 0)
5575 {
5576 size_t off = sprintf(buf, "%ld", __size_);
5577 buf += off;
5578 }
5579 char* t = buf;
5580 buf = __left_->second_demangled_name(buf);
5581 *t = ']';
5582 if (buf == t)
5583 ++buf;
5584 return buf;
5585 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005586 virtual bool is_array() const
5587 {
5588 return true;
5589 }
5590 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5591 {
5592 bool r = __left_->fix_forward_references(t_begin, t_end);
5593 if (__right_)
5594 r = r && __right_->fix_forward_references(t_begin, t_end);
5595 return r;
5596 }
5597};
5598
5599class __pointer_to_member_type
5600 : public __node
5601{
5602public:
5603
5604 __pointer_to_member_type(__node* class_type, __node* member_type)
5605 {
5606 __left_ = class_type;
5607 __right_ = member_type;
5608 }
5609
5610 virtual size_t first_size() const
5611 {
5612 if (__cached_size_ == -1)
Howard Hinnant5ee51a72011-12-13 01:23:16 +00005613 const_cast<long&>(__cached_size_) = __left_->size() + 3
5614 + __right_->first_size()
5615 + __right_->second_size();
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005616 return __cached_size_;
5617 }
5618 virtual char* first_demangled_name(char* buf) const
5619 {
5620 buf = __right_->first_demangled_name(buf);
5621 buf = __left_->get_demangled_name(buf);
5622 *buf++ = ':';
5623 *buf++ = ':';
5624 *buf++ = '*';
5625 return __right_->second_demangled_name(buf);
5626 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005627 virtual __node* base_name() const
5628 {
5629 return __left_->base_name();
5630 }
5631 virtual bool is_reference_or_pointer_to_function_or_array() const
5632 {
5633 return __right_->is_function();
5634 }
5635 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5636 {
5637 return __left_->fix_forward_references(t_begin, t_end) &&
5638 __right_->fix_forward_references(t_begin, t_end);
5639 }
5640};
5641
5642class __decltype_node
5643 : public __node
5644{
5645public:
5646
5647 explicit __decltype_node(__node* expr)
5648 {
5649 __right_ = expr;
5650 }
5651
5652 virtual size_t first_size() const
5653 {
5654 if (__cached_size_ == -1)
5655 const_cast<long&>(__cached_size_) = 10 + __right_->size();
5656 return __cached_size_;
5657 }
5658
5659 virtual char* first_demangled_name(char* buf) const
5660 {
5661 strncpy(buf, "decltype(", 9);
5662 buf += 9;
5663 buf = __right_->get_demangled_name(buf);
5664 *buf++ = ')';
5665 return buf;
5666 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005667 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5668 {
5669 return __right_->fix_forward_references(t_begin, t_end);
5670 }
5671};
5672
5673class __nested_delimeter
5674 : public __node
5675{
5676public:
5677
5678 explicit __nested_delimeter(__node* prev, __node* arg)
5679 {
5680 __left_ = prev;
5681 __right_ = arg;
5682 }
5683
5684 virtual size_t first_size() const
5685 {
5686 if (__cached_size_ == -1)
5687 const_cast<long&>(__cached_size_) = __left_->size() + __right_->size() + 2;
5688 return __cached_size_;
5689 }
5690
5691 virtual char* first_demangled_name(char* buf) const
5692 {
5693 buf = __left_->get_demangled_name(buf);
5694 *buf++ = ':';
5695 *buf++ = ':';
5696 return __right_->get_demangled_name(buf);
5697 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005698
Howard Hinnantab87dcf2011-12-15 20:02:15 +00005699 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005700 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00005701 return __right_->ends_with_template(parsing);
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005702 }
5703 virtual __node* base_name() const
5704 {
5705 return __right_->base_name();
5706 }
5707 virtual bool is_ctor_dtor_conv() const
5708 {
5709 return __right_->is_ctor_dtor_conv();
5710 }
5711 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5712 {
5713 return __left_->fix_forward_references(t_begin, t_end) &&
5714 __right_->fix_forward_references(t_begin, t_end);
5715 }
5716 virtual __node* extract_cv(__node*& rt) const
5717 {
5718 return __right_->extract_cv(const_cast<__node*&>(__right_));
5719 }
5720};
5721
5722class __unresolved_name
5723 : public __node
5724{
5725public:
5726
5727 __unresolved_name(__node* prev, __node* arg)
5728 {
5729 __left_ = prev;
5730 __right_ = arg;
5731 }
5732
5733 __unresolved_name(bool global, __node* prev, __node* arg)
5734 {
5735 __size_ = global;
5736 __left_ = prev;
5737 __right_ = arg;
5738 }
5739
5740 virtual size_t first_size() const
5741 {
5742 if (__cached_size_ == -1)
5743 const_cast<long&>(__cached_size_) = (__left_ ? __left_->size() + 2 : 0) +
5744 __right_->size() + __size_ * 2;
5745 return __cached_size_;
5746 }
5747
5748 virtual char* first_demangled_name(char* buf) const
5749 {
5750 if (__size_)
5751 {
5752 *buf++ = ':';
5753 *buf++ = ':';
5754 }
5755 if (__left_)
5756 {
5757 buf = __left_->get_demangled_name(buf);
5758 *buf++ = ':';
5759 *buf++ = ':';
5760 }
5761 return __right_->get_demangled_name(buf);
5762 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005763
Howard Hinnantab87dcf2011-12-15 20:02:15 +00005764 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005765 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00005766 return __right_->ends_with_template(parsing);
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005767 }
5768 virtual __node* base_name() const
5769 {
5770 return __right_->base_name();
5771 }
5772 virtual bool is_ctor_dtor_conv() const
5773 {
5774 return __right_->is_ctor_dtor_conv();
5775 }
5776 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5777 {
5778 bool r = true;
5779 if (__left_)
5780 r = __left_->fix_forward_references(t_begin, t_end);
5781 return r && __right_->fix_forward_references(t_begin, t_end);
5782 }
5783 virtual __node* extract_cv(__node*& rt) const
5784 {
5785 return __right_->extract_cv(const_cast<__node*&>(__right_));
5786 }
5787};
5788
5789class __string_literal
5790 : public __node
5791{
5792public:
5793
5794 virtual size_t first_size() const
5795 {
5796 return 14;
5797 }
5798
5799 virtual char* first_demangled_name(char* buf) const
5800 {
5801 strncpy(buf, "string literal", 14);
5802 return buf + 14;
5803 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005804};
5805
5806class __constructor
5807 : public __node
5808{
5809public:
5810
5811 explicit __constructor(__node* name)
5812 {
5813 __right_ = name;
5814 }
5815
5816 virtual size_t first_size() const
5817 {
5818 if (__cached_size_ == -1)
5819 const_cast<long&>(__cached_size_) = __right_->base_size();
5820 return __cached_size_;
5821 }
5822
5823 virtual char* first_demangled_name(char* buf) const
5824 {
5825 return __right_->get_base_name(buf);
5826 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005827 virtual __node* base_name() const
5828 {
5829 return __right_->base_name();
5830 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +00005831 virtual bool ends_with_template(bool parsing = false) const
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005832 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00005833 return __right_->ends_with_template(parsing);
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005834 }
5835 virtual bool is_ctor_dtor_conv() const
5836 {
5837 return true;
5838 }
5839 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5840 {
5841 return __right_->fix_forward_references(t_begin, t_end);
5842 }
5843};
5844
5845class __destructor
5846 : public __node
5847{
5848public:
5849
5850 explicit __destructor(__node* name)
5851 {
5852 __right_ = name;
5853 }
5854
5855 virtual size_t first_size() const
5856 {
5857 if (__cached_size_ == -1)
5858 const_cast<long&>(__cached_size_) = __right_->base_size() + 1;
5859 return __cached_size_;
5860 }
5861
5862 virtual char* first_demangled_name(char* buf) const
5863 {
5864 *buf++ = '~';
5865 return __right_->get_base_name(buf);
5866 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005867 virtual __node* base_name() const
5868 {
5869 return __right_->base_name();
5870 }
5871 virtual bool is_ctor_dtor_conv() const
5872 {
5873 return true;
5874 }
5875 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5876 {
5877 return __right_->fix_forward_references(t_begin, t_end);
5878 }
5879};
5880
5881class __dot_suffix
5882 : public __node
5883{
5884public:
5885 __dot_suffix(__node* name, const char* suffix, unsigned sz)
5886 {
5887 __left_ = name;
5888 __name_ = suffix;
5889 __size_ = sz;
5890 }
5891
5892 virtual size_t first_size() const
5893 {
5894 if (__cached_size_ == -1)
5895 {
5896 size_t off = __left_->size();
5897 off += __size_ + 3;
5898 const_cast<long&>(__cached_size_) = off;
5899 }
5900 return __cached_size_;
5901 }
5902 virtual char* first_demangled_name(char* buf) const
5903 {
5904 buf = __left_->get_demangled_name(buf);
5905 *buf++ = ' ';
5906 *buf++ = '(';
5907 strncpy(buf, __name_, __size_);
5908 buf += __size_;
5909 *buf++ = ')';
5910 return buf;
5911 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005912 virtual __node* base_name() const
5913 {
5914 return __left_->base_name();
5915 }
5916 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5917 {
5918 return __left_->fix_forward_references(t_begin, t_end);
5919 }
5920};
5921
Howard Hinnantab87dcf2011-12-15 20:02:15 +00005922class __vector_type
5923 : public __node
5924{
5925public:
5926 __vector_type(__node* type, const char* num, size_t sz)
5927 {
5928 __left_ = type;
5929 __name_ = num;
5930 __size_ = sz;
5931 }
5932
5933 __vector_type(__node* type, __node* num)
5934 {
5935 __left_ = type;
5936 __right_ = num;
5937 }
5938
5939 virtual size_t first_size() const
5940 {
5941 if (__cached_size_ == -1)
5942 {
5943 size_t off = 5;
5944 if (__left_)
5945 off = __left_->size();
5946 off += 9;
5947 if (__right_)
5948 off += __right_->size();
5949 else if (__size_ > 0)
5950 off += __size_;
5951 const_cast<long&>(__cached_size_) = off;
5952 }
5953 return __cached_size_;
5954 }
5955 virtual char* first_demangled_name(char* buf) const
5956 {
5957 if (__left_)
5958 buf = __left_->get_demangled_name(buf);
5959 else
5960 {
5961 strncpy(buf, "pixel", 5);
5962 buf += 5;
5963 }
5964 strncpy(buf, " vector[", 8);
5965 buf += 8;
5966 if (__right_)
5967 buf = __right_->get_demangled_name(buf);
5968 else if (__size_ > 0)
5969 {
5970 strncpy(buf, __name_, __size_);
5971 buf += __size_;
5972 }
5973 *buf++ = ']';
5974 return buf;
5975 }
5976 virtual __node* base_name() const
5977 {
5978 if (__left_)
5979 return __left_->base_name();
5980 return __left_;
5981 }
5982 virtual bool fix_forward_references(__node** t_begin, __node** t_end)
5983 {
5984 bool r = true;
5985 if (__left_)
5986 r = __left_->fix_forward_references(t_begin, t_end);
5987 if (__right_)
5988 r = r && __right_->fix_forward_references(t_begin, t_end);
5989 return r;
5990 }
5991};
5992
Howard Hinnantd213ffd2011-05-05 15:27:28 +00005993
5994enum {invalid_args = -3, invalid_mangled_name, memory_alloc_failure, success,
5995 not_yet_implemented};
5996
5997__demangle_tree::__demangle_tree(const char* mangled_name, char* buf, size_t bs)
5998 : __mangled_name_begin_(0), __mangled_name_end_(0),
5999 __status_(invalid_mangled_name), __root_(0),
6000 __node_begin_(0), __node_end_(0), __node_cap_(0),
6001 __sub_begin_(0), __sub_end_(0), __sub_cap_(0),
6002 __t_begin_(0), __t_end_(0), __t_cap_(0),
6003 __tag_templates_(true),
6004 __fix_forward_references_(false)
6005{
6006 size_t n = strlen(mangled_name);
6007 size_t ms = n + 2*n*sizeof(__node) + 2*n*sizeof(__node*);
6008 char* m;
6009 if (ms <= bs)
6010 {
6011 m = buf;
6012 __owns_buf_ = false;
6013 }
6014 else
6015 {
6016 m = static_cast<char*>(malloc(ms));
6017 __owns_buf_ = true;
6018 }
6019 if (m == NULL)
6020 {
6021 __status_ = memory_alloc_failure;
6022 return;
6023 }
6024 __node_begin_ = __node_end_ = (__node*)(m);
6025 __node_cap_ = __node_begin_ + 2*n;
6026 __sub_begin_ = __sub_end_ = (__node**)(__node_cap_);
6027 __sub_cap_ = __sub_begin_ + n;
6028 __t_begin_ = __t_end_ = (__node**)(__sub_cap_);
6029 __t_cap_ = __t_begin_ + n;
6030 __mangled_name_begin_ = (const char*)(__t_cap_);
6031 __mangled_name_end_ = __mangled_name_begin_ + n;
6032 strncpy(const_cast<char*>(__mangled_name_begin_), mangled_name, n);
6033}
6034
6035__demangle_tree::~__demangle_tree()
6036{
6037 if (__owns_buf_)
6038 free(__node_begin_);
6039}
6040
6041__demangle_tree::__demangle_tree(__demangle_tree& t)
6042 : __mangled_name_begin_(t.__mangled_name_begin_),
6043 __mangled_name_end_(t.__mangled_name_end_),
6044 __status_(t.__status_), __root_(t.__root_),
6045 __node_begin_(t.__node_begin_), __node_end_(t.__node_end_),
6046 __node_cap_(t.__node_cap_),
6047 __sub_begin_(t.__sub_begin_), __sub_end_(t.__sub_end_),
6048 __sub_cap_(t.__sub_cap_),
6049 __t_begin_(t.__t_begin_), __t_end_(t.__t_end_),
6050 __t_cap_(t.__t_cap_),
6051 __tag_templates_(t.__tag_templates_),
6052 __fix_forward_references_(t.__fix_forward_references_),
6053 __owns_buf_(t.__owns_buf_)
6054{
6055 t.__mangled_name_begin_ = 0;
6056 t.__mangled_name_end_ = 0;
6057 t.__status_ = invalid_mangled_name;
6058 t.__root_ = 0;
6059 t.__node_begin_ = t.__node_end_ = t.__node_cap_ = 0;
6060 t.__sub_begin_ = t.__sub_end_ = t.__sub_cap_ = 0;
6061 t.__t_begin_ = t.__t_end_ = t.__t_cap_ = 0;
6062 t.__owns_buf_ = false;
6063}
6064
6065__demangle_tree::__demangle_tree(__demangle_tree_rv rv)
6066 : __mangled_name_begin_(rv.ptr_->__mangled_name_begin_),
6067 __mangled_name_end_(rv.ptr_->__mangled_name_end_),
6068 __status_(rv.ptr_->__status_), __root_(rv.ptr_->__root_),
6069 __node_begin_(rv.ptr_->__node_begin_), __node_end_(rv.ptr_->__node_end_),
6070 __node_cap_(rv.ptr_->__node_cap_),
6071 __sub_begin_(rv.ptr_->__sub_begin_), __sub_end_(rv.ptr_->__sub_end_),
6072 __sub_cap_(rv.ptr_->__sub_cap_),
6073 __t_begin_(rv.ptr_->__t_begin_), __t_end_(rv.ptr_->__t_end_),
6074 __t_cap_(rv.ptr_->__t_cap_),
6075 __tag_templates_(rv.ptr_->__tag_templates_),
6076 __fix_forward_references_(rv.ptr_->__fix_forward_references_),
6077 __owns_buf_(rv.ptr_->__owns_buf_)
6078{
6079 rv.ptr_->__mangled_name_begin_ = 0;
6080 rv.ptr_->__mangled_name_end_ = 0;
6081 rv.ptr_->__status_ = invalid_mangled_name;
6082 rv.ptr_->__root_ = 0;
6083 rv.ptr_->__node_begin_ = rv.ptr_->__node_end_ = rv.ptr_->__node_cap_ = 0;
6084 rv.ptr_->__sub_begin_ = rv.ptr_->__sub_end_ = rv.ptr_->__sub_cap_ = 0;
6085 rv.ptr_->__t_begin_ = rv.ptr_->__t_end_ = rv.ptr_->__t_cap_ = 0;
6086 rv.ptr_->__owns_buf_ = false;
6087}
6088
6089int
6090__demangle_tree::__status() const
6091{
6092 return __status_;
6093}
6094
6095size_t
6096__demangle_tree::size() const
6097{
6098 return __status_ == success ? __root_->size() : 0;
6099}
6100
6101char*
6102__demangle_tree::__get_demangled_name(char* buf) const
6103{
6104 if (__status_ == success)
6105 return __root_->get_demangled_name(buf);
6106 return 0;
6107}
6108
6109template <class _Tp>
6110bool
6111__demangle_tree::__make()
6112{
6113 if (__node_end_ < __node_cap_)
6114 {
6115 ::new (__node_end_) _Tp();
6116 __root_ = __node_end_;
6117 ++__node_end_;
6118 return true;
6119 }
6120 __status_ = memory_alloc_failure;
6121 return false;
6122}
6123
6124template <class _Tp, class _A0>
6125bool
6126__demangle_tree::__make(_A0 __a0)
6127{
6128 if (__node_end_ < __node_cap_)
6129 {
6130 ::new (__node_end_) _Tp(__a0);
6131 __root_ = __node_end_;
6132 ++__node_end_;
6133 return true;
6134 }
6135 __status_ = memory_alloc_failure;
6136 return false;
6137}
6138
6139template <class _Tp, class _A0, class _A1>
6140bool
6141__demangle_tree::__make(_A0 __a0, _A1 __a1)
6142{
6143 if (__node_end_ < __node_cap_)
6144 {
6145 ::new (__node_end_) _Tp(__a0, __a1);
6146 __root_ = __node_end_;
6147 ++__node_end_;
6148 return true;
6149 }
6150 __status_ = memory_alloc_failure;
6151 return false;
6152}
6153
6154template <class _Tp, class _A0, class _A1, class _A2>
6155bool
6156__demangle_tree::__make(_A0 __a0, _A1 __a1, _A2 __a2)
6157{
6158 if (__node_end_ < __node_cap_)
6159 {
6160 ::new (__node_end_) _Tp(__a0, __a1, __a2);
6161 __root_ = __node_end_;
6162 ++__node_end_;
6163 return true;
6164 }
6165 __status_ = memory_alloc_failure;
6166 return false;
6167}
6168
6169template <class _Tp, class _A0, class _A1, class _A2, class _A3>
6170bool
6171__demangle_tree::__make(_A0 __a0, _A1 __a1, _A2 __a2, _A3 __a3)
6172{
6173 if (__node_end_ < __node_cap_)
6174 {
6175 ::new (__node_end_) _Tp(__a0, __a1, __a2, __a3);
6176 __root_ = __node_end_;
6177 ++__node_end_;
6178 return true;
6179 }
6180 __status_ = memory_alloc_failure;
6181 return false;
6182}
6183
6184template <class _Tp, class _A0, class _A1, class _A2, class _A3, class _A4>
6185bool
6186__demangle_tree::__make(_A0 __a0, _A1 __a1, _A2 __a2, _A3 __a3, _A4 __a4)
6187{
6188 if (__node_end_ < __node_cap_)
6189 {
6190 ::new (__node_end_) _Tp(__a0, __a1, __a2, __a3, __a4);
6191 __root_ = __node_end_;
6192 ++__node_end_;
6193 return true;
6194 }
6195 __status_ = memory_alloc_failure;
6196 return false;
6197}
6198
6199template <class _Tp, class _A0, class _A1, class _A2, class _A3, class _A4,
6200 class _A5>
6201bool
6202__demangle_tree::__make(_A0 __a0, _A1 __a1, _A2 __a2, _A3 __a3, _A4 __a4,
6203 _A5 __a5)
6204{
6205 if (__node_end_ < __node_cap_)
6206 {
6207 ::new (__node_end_) _Tp(__a0, __a1, __a2, __a3, __a4, __a5);
6208 __root_ = __node_end_;
6209 ++__node_end_;
6210 return true;
6211 }
6212 __status_ = memory_alloc_failure;
6213 return false;
6214}
6215
6216// <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const
6217// [R | O] # & or &&
6218
6219const char*
6220__demangle_tree::__parse_cv_qualifiers(const char* first, const char* last,
6221 unsigned& cv, bool look_for_ref_quals)
6222{
6223 if (look_for_ref_quals)
6224 {
6225 for (; first != last; ++first)
6226 {
6227 switch (*first)
6228 {
6229 case 'r':
6230 cv |= 4;
6231 break;
6232 case 'V':
6233 cv |= 2;
6234 break;
6235 case 'K':
6236 cv |= 1;
6237 break;
6238 case 'R':
6239 cv |= 8;
6240 break;
6241 case 'O':
6242 cv |= 16;
6243 break;
6244 default:
6245 return first;
6246 }
6247 }
6248 }
6249 else
6250 {
6251 for (; first != last; ++first)
6252 {
6253 switch (*first)
6254 {
6255 case 'r':
6256 cv |= 4;
6257 break;
6258 case 'V':
6259 cv |= 2;
6260 break;
6261 case 'K':
6262 cv |= 1;
6263 break;
6264 default:
6265 return first;
6266 }
6267 }
6268 }
6269 return first;
6270}
6271
6272// <builtin-type> ::= v # void
6273// ::= w # wchar_t
6274// ::= b # bool
6275// ::= c # char
6276// ::= a # signed char
6277// ::= h # unsigned char
6278// ::= s # short
6279// ::= t # unsigned short
6280// ::= i # int
6281// ::= j # unsigned int
6282// ::= l # long
6283// ::= m # unsigned long
6284// ::= x # long long, __int64
6285// ::= y # unsigned long long, __int64
6286// ::= n # __int128
6287// ::= o # unsigned __int128
6288// ::= f # float
6289// ::= d # double
6290// ::= e # long double, __float80
6291// ::= g # __float128
6292// ::= z # ellipsis
6293// ::= Dd # IEEE 754r decimal floating point (64 bits)
6294// ::= De # IEEE 754r decimal floating point (128 bits)
6295// ::= Df # IEEE 754r decimal floating point (32 bits)
6296// ::= Dh # IEEE 754r half-precision floating point (16 bits)
6297// ::= Di # char32_t
6298// ::= Ds # char16_t
6299// ::= Da # auto (in dependent new-expressions)
6300// ::= Dn # std::nullptr_t (i.e., decltype(nullptr))
6301// ::= u <source-name> # vendor extended type
6302
6303const char*
6304__demangle_tree::__parse_builtin_type(const char* first, const char* last)
6305{
6306 if (first != last)
6307 {
6308 switch (*first)
6309 {
6310 case 'v':
6311 if (__make<__void>())
6312 ++first;
6313 break;
6314 case 'w':
6315 if (__make<__wchar_t>())
6316 ++first;
6317 break;
6318 case 'b':
6319 if (__make<__bool>())
6320 ++first;
6321 break;
6322 case 'c':
6323 if (__make<__char>())
6324 ++first;
6325 break;
6326 case 'a':
6327 if (__make<__signed_char>())
6328 ++first;
6329 break;
6330 case 'h':
6331 if (__make<__unsigned_char>())
6332 ++first;
6333 break;
6334 case 's':
6335 if (__make<__short>())
6336 ++first;
6337 break;
6338 case 't':
6339 if (__make<__unsigned_short>())
6340 ++first;
6341 break;
6342 case 'i':
6343 if (__make<__int>())
6344 ++first;
6345 break;
6346 case 'j':
6347 if (__make<__unsigned_int>())
6348 ++first;
6349 break;
6350 case 'l':
6351 if (__make<__long>())
6352 ++first;
6353 break;
6354 case 'm':
6355 if (__make<__unsigned_long>())
6356 ++first;
6357 break;
6358 case 'x':
6359 if (__make<__long_long>())
6360 ++first;
6361 break;
6362 case 'y':
6363 if (__make<__unsigned_long_long>())
6364 ++first;
6365 break;
6366 case 'n':
6367 if (__make<__int128>())
6368 ++first;
6369 break;
6370 case 'o':
6371 if (__make<__unsigned_int128>())
6372 ++first;
6373 break;
6374 case 'f':
6375 if (__make<__float>())
6376 ++first;
6377 break;
6378 case 'd':
6379 if (__make<__double>())
6380 ++first;
6381 break;
6382 case 'e':
6383 if (__make<__long_double>())
6384 ++first;
6385 break;
6386 case 'g':
6387 if (__make<__float128>())
6388 ++first;
6389 break;
6390 case 'z':
6391 if (__make<__ellipsis>())
6392 ++first;
6393 break;
6394 case 'D':
6395 if (first+1 != last)
6396 {
6397 switch (first[1])
6398 {
6399 case 'd':
6400 if (__make<__decimal64>())
6401 first += 2;
6402 break;
6403 case 'e':
6404 if (__make<__decimal128>())
6405 first += 2;
6406 break;
6407 case 'f':
6408 if (__make<__decimal32>())
6409 first += 2;
6410 break;
6411 case 'h':
6412 if (__make<__decimal16>())
6413 first += 2;
6414 break;
6415 case 'i':
6416 if (__make<__d_char32_t>())
6417 first += 2;
6418 break;
6419 case 's':
6420 if (__make<__d_char16_t>())
6421 first += 2;
6422 break;
6423 case 'a':
6424 if (__make<__auto>())
6425 first += 2;
6426 break;
6427 case 'n':
6428 if (__make<__nullptr_t>())
6429 first += 2;
6430 break;
6431 }
6432 }
6433 break;
6434 }
6435 }
6436 return first;
6437}
6438
6439// <bare-function-type> ::= <signature type>+
6440// # types are possible return type, then parameter types
6441
6442const char*
6443__demangle_tree::__parse_bare_function_type(const char* first, const char* last)
6444{
6445 if (first != last)
6446 {
6447 __tag_templates_ = false;
6448 const char* t = __parse_type(first, last);
6449 if (t != first && __make<__list>(__root_))
6450 {
6451 const char* t0 = t;
6452 __node* head = __root_;
6453 __node* prev = head;
6454 while (true)
6455 {
6456 t = __parse_type(t0, last);
6457 if (t != t0)
6458 {
6459 if (__make<__list>(__root_))
6460 {
6461 t0 = t;
6462 prev->__right_ = __root_;
6463 __root_->__size_ = prev->__size_ + 1;
6464 prev = __root_;
6465 }
6466 else
6467 break;
6468 }
6469 else
6470 {
6471 first = t;
6472 __root_ = head;
6473 break;
6474 }
6475 }
6476 }
6477 __tag_templates_ = true;
6478 }
6479 return first;
6480}
6481
6482// <function-type> ::= F [Y] <bare-function-type> E
6483
6484const char*
6485__demangle_tree::__parse_function_type(const char* first, const char* last)
6486{
6487 if (first != last && *first == 'F')
6488 {
6489 const char* t = first+1;
6490 if (t != last)
6491 {
6492 bool externC = false;
6493 if (*t == 'Y')
6494 {
6495 externC = true;
6496 if (++t == last)
6497 return first;
6498 }
6499 const char* t1 = __parse_type(t, last);
6500 if (t1 != t)
6501 {
6502 __node* ret = __root_;
6503 t = t1;
6504 t1 = __parse_bare_function_type(t, last);
6505 if (t1 != t && t1 != last && *t1 == 'E')
6506 {
6507 if (dynamic_cast<__void*>(__root_->__left_) != NULL)
6508 __root_->__left_ = NULL;
6509 if (__make<__function_signature>(ret, __root_))
6510 {
6511 if (__make<__function>((__node*)0, __root_))
6512 first = t1+1;
6513 }
6514 }
6515 }
6516 }
6517 }
6518 return first;
6519}
6520
6521const char*
6522__demangle_tree::__parse_hex_number(const char* first, const char* last, unsigned long long& n)
6523{
6524 const char* t = first;
6525 for (; t != last && isxdigit(*t); ++t)
6526 {
6527 if (t == first)
6528 n = 0;
6529 if (isdigit(*t))
6530 n = n * 16 + *t - '0';
6531 else if (isupper(*t))
6532 n = n * 16 + *t - 'A' + 10;
6533 else
6534 n = n * 16 + *t - 'a' + 10;
6535 }
6536 first = t;
6537 return first;
6538}
6539
6540// <expr-primary> ::= L <type> <value number> E # integer literal
6541// ::= L <type> <value float> E # floating literal
6542// ::= L <string type> E # string literal
6543// ::= L <nullptr type> E # nullptr literal (i.e., "LDnE")
6544// ::= L <type> <real-part float> _ <imag-part float> E # complex floating point literal (C 2000)
6545// ::= L <mangled-name> E # external name
6546
6547const char*
6548__demangle_tree::__parse_expr_primary(const char* first, const char* last)
6549{
6550 if (last - first >= 4 && *first == 'L')
6551 {
6552 switch (first[1])
6553 {
6554 case 'w':
6555 {
6556 const char* t = __parse_number(first+2, last);
6557 if (t != first+2 && t != last && *t == 'E')
6558 {
6559 if (__make<__wchar_t_literal>(first+2, t))
6560 first = t+1;
6561 }
6562 }
6563 break;
6564 case 'b':
6565 if (first[3] == 'E')
6566 {
6567 switch (first[2])
6568 {
6569 case '0':
6570 if (__make<__bool_literal>("false", 5))
6571 first += 4;
6572 break;
6573 case '1':
6574 if (__make<__bool_literal>("true", 4))
6575 first += 4;
6576 break;
6577 }
6578 }
6579 break;
6580 case 'c':
6581 {
6582 const char* t = __parse_number(first+2, last);
6583 if (t != first+2 && t != last && *t == 'E')
6584 {
6585 if (__make<__char_literal>(first+2, t))
6586 first = t+1;
6587 }
6588 }
6589 break;
6590 case 'a':
6591 {
6592 const char* t = __parse_number(first+2, last);
6593 if (t != first+2 && t != last && *t == 'E')
6594 {
6595 if (__make<__signed_char_literal>(first+2, t))
6596 first = t+1;
6597 }
6598 }
6599 break;
6600 case 'h':
6601 {
6602 const char* t = __parse_number(first+2, last);
6603 if (t != first+2 && t != last && *t == 'E')
6604 {
6605 if (__make<__unsigned_char_literal>(first+2, t))
6606 first = t+1;
6607 }
6608 }
6609 break;
6610 case 's':
6611 {
6612 const char* t = __parse_number(first+2, last);
6613 if (t != first+2 && t != last && *t == 'E')
6614 {
6615 if (__make<__short_literal>(first+2, t))
6616 first = t+1;
6617 }
6618 }
6619 break;
6620 case 't':
6621 {
6622 const char* t = __parse_number(first+2, last);
6623 if (t != first+2 && t != last && *t == 'E')
6624 {
6625 if (__make<__unsigned_short_literal>(first+2, t))
6626 first = t+1;
6627 }
6628 }
6629 break;
6630 case 'i':
6631 {
6632 const char* t = __parse_number(first+2, last);
6633 if (t != first+2 && t != last && *t == 'E')
6634 {
6635 if (__make<__int_literal>(first+2, t))
6636 first = t+1;
6637 }
6638 }
6639 break;
6640 case 'j':
6641 {
6642 const char* t = __parse_number(first+2, last);
6643 if (t != first+2 && t != last && *t == 'E')
6644 {
6645 if (__make<__unsigned_int_literal>(first+2, t))
6646 first = t+1;
6647 }
6648 }
6649 break;
6650 case 'l':
6651 {
6652 const char* t = __parse_number(first+2, last);
6653 if (t != first+2 && t != last && *t == 'E')
6654 {
6655 if (__make<__long_literal>(first+2, t))
6656 first = t+1;
6657 }
6658 }
6659 break;
6660 case 'm':
6661 {
6662 const char* t = __parse_number(first+2, last);
6663 if (t != first+2 && t != last && *t == 'E')
6664 {
6665 if (__make<__unsigned_long_literal>(first+2, t))
6666 first = t+1;
6667 }
6668 }
6669 break;
6670 case 'x':
6671 {
6672 const char* t = __parse_number(first+2, last);
6673 if (t != first+2 && t != last && *t == 'E')
6674 {
6675 if (__make<__long_long_literal>(first+2, t))
6676 first = t+1;
6677 }
6678 }
6679 break;
6680 case 'y':
6681 {
6682 const char* t = __parse_number(first+2, last);
6683 if (t != first+2 && t != last && *t == 'E')
6684 {
6685 if (__make<__unsigned_long_long_literal>(first+2, t))
6686 first = t+1;
6687 }
6688 }
6689 break;
6690 case 'n':
6691 {
6692 const char* t = __parse_number(first+2, last);
6693 if (t != first+2 && t != last && *t == 'E')
6694 {
6695 if (__make<__int128_literal>(first+2, t))
6696 first = t+1;
6697 }
6698 }
6699 break;
6700 case 'o':
6701 {
6702 const char* t = __parse_number(first+2, last);
6703 if (t != first+2 && t != last && *t == 'E')
6704 {
6705 if (__make<__unsigned_int128_literal>(first+2, t))
6706 first = t+1;
6707 }
6708 }
6709 break;
6710 case 'f':
6711 {
6712 if (last - (first+2) <= 8)
6713 return first;
6714 unsigned long long j;
6715 const char* t = __parse_hex_number(first+2, first+10, j);
6716 if (t != first+2 && t != last && *t == 'E')
6717 {
6718 unsigned i = static_cast<unsigned>(j);
6719 float value = *(float*)&i;
6720 if (__make<__float_literal>(value))
6721 first = t+1;
6722 }
6723 }
6724 break;
6725 case 'd':
6726 {
6727 if (last - (first+2) <= 16)
6728 return first;
6729 unsigned long long j;
6730 const char* t = __parse_hex_number(first+2, first+18, j);
6731 if (t != first+2 && t != last && *t == 'E')
6732 {
6733 double value = *(double*)&j;
6734 if (__make<__double_literal>(value))
6735 first = t+1;
6736 }
6737 }
6738 break;
6739 case 'e':
6740 break;
6741 case '_':
6742 if (first[2] == 'Z')
6743 {
6744 const char* t = __parse_encoding(first+3, last);
6745 if (t != first+3 && t != last && *t == 'E')
6746 first = t+1;
6747 }
6748 break;
6749 default:
6750 {
6751 // might be named type
6752 const char* t = __parse_type(first+1, last);
6753 if (t != first+1 && t != last)
6754 {
6755 if (*t != 'E')
6756 {
6757 const char* n = t;
6758 for (; n != last && isdigit(*n); ++n)
6759 ;
6760 if (n != t && n != last && *n == 'E')
6761 {
6762 if (__make<__cast_literal>(__root_, t, n))
6763 {
6764 first = n+1;
6765 break;
6766 }
6767 }
6768 }
6769 else
6770 {
6771 first = t+1;
6772 break;
6773 }
6774 }
6775 }
Howard Hinnantab87dcf2011-12-15 20:02:15 +00006776// assert(!"case in __parse_expr_primary not implemented");
6777 __status_ = not_yet_implemented;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00006778 }
6779 }
6780 return first;
6781}
6782
Howard Hinnantab87dcf2011-12-15 20:02:15 +00006783// <unnamed-type-name> ::= Ut [ <nonnegative number> ] _
6784// ::= <closure-type-name>
6785//
6786// <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _
6787//
6788// <lambda-sig> ::= <parameter type>+ # Parameter types or "v" if the lambda has no parameters
6789
Howard Hinnantd213ffd2011-05-05 15:27:28 +00006790const char*
6791__demangle_tree::__parse_unnamed_type_name(const char* first, const char* last)
6792{
Howard Hinnantab87dcf2011-12-15 20:02:15 +00006793 if (last - first > 2 && first[0] == 'U')
Howard Hinnantd213ffd2011-05-05 15:27:28 +00006794 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00006795 switch (first[1])
6796 {
6797 case 't':
6798 case 'l':
6799 first += 2;
6800 __status_ = not_yet_implemented;
6801 break;
6802 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00006803 }
6804 return first;
6805}
6806
6807// <ctor-dtor-name> ::= C1 # complete object constructor
6808// ::= C2 # base object constructor
6809// ::= C3 # complete object allocating constructor
6810// ::= D0 # deleting destructor
6811// ::= D1 # complete object destructor
6812// ::= D2 # base object destructor
6813
6814const char*
6815__demangle_tree::__parse_ctor_dtor_name(const char* first, const char* last)
6816{
6817 if (last-first >= 2)
6818 {
6819 switch (first[0])
6820 {
6821 case 'C':
6822 switch (first[1])
6823 {
6824 case '1':
6825 case '2':
6826 case '3':
6827 if (__make<__constructor>(__root_->base_name()))
6828 first += 2;
6829 break;
6830 }
6831 break;
6832 case 'D':
6833 switch (first[1])
6834 {
6835 case '0':
6836 case '1':
6837 case '2':
6838 if (__make<__destructor>(__root_->base_name()))
6839 first += 2;
6840 break;
6841 }
6842 break;
6843 }
6844 }
6845 return first;
6846}
6847
6848const char*
6849__demangle_tree::__parse_unscoped_template_name(const char* first, const char* last)
6850{
Howard Hinnantab87dcf2011-12-15 20:02:15 +00006851// assert(!"__parse_unscoped_template_name not implemented");
6852 __status_ = not_yet_implemented;
6853 return first;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00006854}
6855
6856// <discriminator> := _ <non-negative number> # when number < 10
6857// := __ <non-negative number> _ # when number >= 10
6858// extension := decimal-digit+
6859
6860const char*
6861__demangle_tree::__parse_discriminator(const char* first, const char* last)
6862{
6863 // parse but ignore discriminator
6864 if (first != last)
6865 {
6866 if (*first == '_')
6867 {
6868 const char* t1 = first+1;
6869 if (t1 != last)
6870 {
6871 if (isdigit(*t1))
6872 first = t1+1;
6873 else if (*t1 == '_')
6874 {
6875 for (++t1; t1 != last && isdigit(*t1); ++t1)
6876 ;
6877 if (t1 != last && *t1 == '_')
6878 first = t1 + 1;
6879 }
6880 }
6881 }
6882 else if (isdigit(*first))
6883 {
6884 const char* t1 = first+1;
6885 for (; t1 != last && isdigit(*t1); ++t1)
6886 ;
6887 first = t1;
6888 }
6889 }
6890 return first;
6891}
6892
6893// <local-name> := Z <function encoding> E <entity name> [<discriminator>]
6894// := Z <function encoding> E s [<discriminator>]
6895// := Z <function encoding> Ed [ <parameter number> ] _ <entity name>
6896
6897const char*
6898__demangle_tree::__parse_local_name(const char* first, const char* last)
6899{
6900 if (first != last && *first == 'Z')
6901 {
6902 const char* t = __parse_encoding(first+1, last);
6903 if (t != first+1 && t != last && *t == 'E' && ++t != last)
6904 {
6905 __node* encoding = __root_;
6906 switch (*t)
6907 {
6908 case 's':
6909 {
6910 const char*t1 = __parse_discriminator(t+1, last);
6911 if (__make<__string_literal>())
6912 {
6913 if (__make<__nested_delimeter>(encoding, __root_))
6914 first = t1;
6915 }
6916 }
6917 break;
6918 case 'd':
Howard Hinnantab87dcf2011-12-15 20:02:15 +00006919// assert(!"__parse_local_name d not implemented");
6920 __status_ = not_yet_implemented;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00006921 break;
6922 default:
6923 {
6924 const char*t1 = __parse_name(t, last);
6925 if (t1 != t)
6926 {
6927 // parse but ignore discriminator
6928 t1 = __parse_discriminator(t1, last);
6929 if (__make<__nested_delimeter>(encoding, __root_))
6930 first = t1;
6931 }
6932 }
6933 break;
6934 }
6935 }
6936 }
6937 return first;
6938}
6939
6940// <destructor-name> ::= <unresolved-type> # e.g., ~T or ~decltype(f())
6941// ::= <simple-id> # e.g., ~A<2*N>
6942
6943const char*
6944__demangle_tree::__parse_destructor_name(const char* first, const char* last)
6945{
6946 if (first != last)
6947 {
6948 const char* t = __parse_unresolved_type(first, last);
6949 if (t == first)
6950 t = __parse_simple_id(first, last);
6951 if (t != first && __make<__destructor>(__root_))
6952 first = t;
6953 }
6954 return first;
6955}
6956
6957// <simple-id> ::= <source-name> [ <template-args> ]
6958
6959const char*
6960__demangle_tree::__parse_simple_id(const char* first, const char* last)
6961{
6962 if (first != last)
6963 {
6964 const char* t = __parse_source_name(first, last);
6965 if (t != first)
6966 first = __parse_template_args(t, last);
6967 else
6968 first = t;
6969 }
6970 return first;
6971}
6972
6973// <base-unresolved-name> ::= <simple-id> # unresolved name
6974// extension ::= <operator-name> # unresolved operator-function-id
6975// extension ::= <operator-name> <template-args> # unresolved operator template-id
6976// ::= on <operator-name> # unresolved operator-function-id
6977// ::= on <operator-name> <template-args> # unresolved operator template-id
6978// ::= dn <destructor-name> # destructor or pseudo-destructor;
6979// # e.g. ~X or ~X<N-1>
6980
6981const char*
6982__demangle_tree::__parse_base_unresolved_name(const char* first, const char* last)
6983{
6984 if (last - first >= 2)
6985 {
6986 if ((first[0] == 'o' || first[0] == 'd') && first[1] == 'n')
6987 {
6988 if (first[0] == 'o')
6989 {
6990 const char* t = __parse_operator_name(first+2, last);
6991 if (t != first+2)
6992 first = __parse_template_args(t, last);
6993 else
6994 first = t;
6995 }
6996 else
6997 {
6998 const char* t = __parse_destructor_name(first+2, last);
6999 if (t != first+2)
7000 first = t;
7001 }
7002 }
7003 else
7004 {
7005 const char* t = __parse_simple_id(first, last);
7006 if (t == first)
7007 {
7008 t = __parse_operator_name(first, last);
7009 if (t != first)
7010 t = __parse_template_args(t, last);
7011 }
7012 if (t != first)
7013 first = t;
7014 }
7015 }
7016 return first;
7017}
7018
7019// <unresolved-type> ::= <template-param>
7020// ::= <decltype>
7021// ::= <substitution>
7022
7023const char*
7024__demangle_tree::__parse_unresolved_type(const char* first, const char* last)
7025{
7026 if (first != last)
7027 {
7028 const char* t;
7029 switch (*first)
7030 {
7031 case 'T':
7032 t = __parse_template_param(first, last);
7033 if (t != first)
7034 {
7035 if (__sub_end_ == __sub_cap_)
7036 __status_ = memory_alloc_failure;
7037 else
7038 {
7039 *__sub_end_++ = __root_;
7040 first = t;
7041 }
7042 }
7043 break;
7044 case 'D':
7045 t = __parse_decltype(first, last);
7046 if (t != first)
7047 {
7048 if (__sub_end_ == __sub_cap_)
7049 __status_ = memory_alloc_failure;
7050 else
7051 {
7052 *__sub_end_++ = __root_;
7053 first = t;
7054 }
7055 }
7056 break;
7057 case 'S':
7058 t = __parse_substitution(first, last);
7059 if (t != first)
7060 first = t;
7061 break;
7062 }
7063 }
7064 return first;
7065}
7066
Howard Hinnant889b02d2011-06-22 19:27:39 +00007067// <unresolved-qualifier-level> ::= <source-name> [ <template-args> ]
7068
7069const char*
7070__demangle_tree::__parse_unresolved_qualifier_level(const char* first, const char* last)
7071{
7072 if (first != last)
7073 {
7074 const char* t = __parse_source_name(first, last);
7075 if (t != first)
7076 first = __parse_template_args(t, last);
7077 }
7078 return first;
7079}
7080
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007081// <unresolved-name>
Howard Hinnant889b02d2011-06-22 19:27:39 +00007082// extension ::= srN <unresolved-type> [<template-args>] <unresolved-qualifier-level>* E <base-unresolved-name>
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007083// ::= [gs] <base-unresolved-name> # x or (with "gs") ::x
7084// ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name>
7085// # A::x, N::y, A<T>::z; "gs" means leading "::"
Howard Hinnant889b02d2011-06-22 19:27:39 +00007086// ::= sr <unresolved-type> <base-unresolved-name> # T::x / decltype(p)::x
7087// # T::N::x /decltype(p)::N::x
7088// (ignored) ::= srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name>
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007089
7090const char*
7091__demangle_tree::__parse_unresolved_name(const char* first, const char* last)
7092{
7093 if (last - first > 2)
7094 {
Howard Hinnant889b02d2011-06-22 19:27:39 +00007095 const char* t = first;
7096 bool global = false;
7097 if (t[0] == 'g' && t[1] == 's')
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007098 {
Howard Hinnant889b02d2011-06-22 19:27:39 +00007099 global = true;
7100 t += 2;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007101 }
Howard Hinnant889b02d2011-06-22 19:27:39 +00007102 const char* t2 = __parse_base_unresolved_name(t, last);
7103 if (t2 != t)
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007104 {
Howard Hinnant889b02d2011-06-22 19:27:39 +00007105 if (__make<__unresolved_name>(global, (__node*)0, __root_))
7106 first = t2;
7107 }
7108 else if (last - t > 2 && t[0] == 's' && t[1] == 'r')
7109 {
7110 if (!global && t[2] == 'N')
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007111 {
Howard Hinnant889b02d2011-06-22 19:27:39 +00007112 t2 = __parse_unresolved_type(t+3, last);
7113 if (t2 != t+3 && t2 != last)
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007114 {
Howard Hinnant889b02d2011-06-22 19:27:39 +00007115 t = __parse_template_args(t2, last);
7116 if (t == last)
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007117 return first;
Howard Hinnant889b02d2011-06-22 19:27:39 +00007118 __node* name = __root_;
7119 while (*t != 'E')
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007120 {
Howard Hinnant889b02d2011-06-22 19:27:39 +00007121 t2 = __parse_unresolved_qualifier_level(t, last);
7122 if (t2 == t || t2 == last)
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007123 return first;
7124 if (!__make<__nested_delimeter>(name, __root_))
7125 return first;
7126 name = __root_;
Howard Hinnant889b02d2011-06-22 19:27:39 +00007127 t = t2;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007128 }
Howard Hinnant889b02d2011-06-22 19:27:39 +00007129 t2 = __parse_base_unresolved_name(++t, last);
7130 if (t2 != t && __make<__unresolved_name>(false, name, __root_))
7131 first = t2;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007132 }
Howard Hinnant889b02d2011-06-22 19:27:39 +00007133 }
7134 else
7135 {
7136 if (!global)
7137 {
7138 t2 = __parse_unresolved_type(t+2, last);
7139 if (t2 != t+2)
7140 {
7141 t = t2;
7142 __node* name = __root_;
7143 t2 = __parse_base_unresolved_name(t, last);
7144 if (t2 != t && __make<__unresolved_name>(false, name, __root_))
7145 return t2;
7146 return first;
7147 }
7148 }
7149 t2 = __parse_unresolved_qualifier_level(t+2, last);
7150 if (t2 != t+2 && t2 != last)
7151 {
7152 __node* name = __root_;
7153 t = t2;
7154 while (*t != 'E')
7155 {
7156 t2 = __parse_unresolved_qualifier_level(t, last);
7157 if (t2 == t || t2 == last)
7158 return first;
7159 if (!__make<__nested_delimeter>(name, __root_))
7160 return first;
7161 name = __root_;
7162 t = t2;
7163 }
7164 t2 = __parse_base_unresolved_name(++t, last);
7165 if (t2 != t && __make<__unresolved_name>(global, name, __root_))
7166 first = t2;
7167 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007168 }
7169 }
7170 }
7171 return first;
7172}
7173
7174// <function-param> ::= fp <top-level CV-qualifiers> _ # L == 0, first parameter
7175// ::= fp <top-level CV-qualifiers> <parameter-2 non-negative number> _ # L == 0, second and later parameters
7176// ::= fL <L-1 non-negative number> p <top-level CV-qualifiers> _ # L > 0, first parameter
7177// ::= fL <L-1 non-negative number> p <top-level CV-qualifiers>
7178
7179const char*
7180__demangle_tree::__parse_function_param(const char* first, const char* last)
7181{
7182 if (last - first >= 3 && *first == 'f')
7183 {
7184 if (first[1] == 'p')
7185 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00007186// assert(!"__parse_function_param not implemented");
7187 __status_ = not_yet_implemented;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007188 }
7189 else if (first[1] == 'L')
7190 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +00007191// assert(!"__parse_function_param not implemented");
7192 __status_ = not_yet_implemented;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00007193 }
7194 }
7195 return first;
7196}
7197
7198// at <type> # alignof (a type)
7199
7200const char*
7201__demangle_tree::__parse_alignof_expr(const char* first, const char* last)
7202{
7203 if (last - first >= 3 && first[0] == 'a' && first[1] == 't')
7204 {
7205 const char* t = __parse_type(first+2, last);
7206 if (t != first+2)
7207 {
7208 if (__make<__operator_alignof_expression>(__root_))
7209 first = t;
7210 }
7211 }
7212 return first;
7213}
7214
7215// cc <type> <expression> # const_cast<type> (expression)
7216
7217const char*
7218__demangle_tree::__parse_const_cast_expr(const char* first, const char* last)
7219{
7220 if (last - first >= 3 && first[0] == 'c' && first[1] == 'c')
7221 {
7222 const char* t = __parse_type(first+2, last);
7223 if (t != first+2)
7224 {
7225 __node* type = __root_;
7226 const char* t1 = __parse_expression(t, last);
7227 if (t1 != t)
7228 {
7229 if (__make<__const_cast>(type, __root_))
7230 first = t1;
7231 }
7232 }
7233 }
7234 return first;
7235}
7236
7237// cl <expression>+ E # call
7238
7239const char*
7240__demangle_tree::__parse_call_expr(const char* first, const char* last)
7241{
7242 if (last - first >= 4 && first[0] == 'c' && first[1] == 'l')
7243 {
7244 const char* t = __parse_expression(first+2, last);
7245 if (t != first+2)
7246 {
7247 if (t == last)
7248 return first;
7249 __node* name = __root_;
7250 __node* args = 0;
7251 __node* prev = 0;
7252 while (*t != 'E')
7253 {
7254 const char* t1 = __parse_expression(t, last);
7255 if (t1 == t || t1 == last)
7256 return first;
7257 if (!__make<__list>(__root_))
7258 return first;
7259 if (args == 0)
7260 args = __root_;
7261 if (prev)
7262 {
7263 prev->__right_ = __root_;
7264 __root_->__size_ = prev->__size_ + 1;
7265 }
7266 prev = __root_;
7267 t = t1;
7268 }
7269 ++t;
7270 if (__make<__call_expr>(name, args))
7271 first = t;
7272 }
7273 }
7274 return first;
7275}
7276
7277// cv <type> <expression> # conversion with one argument
7278// cv <type> _ <expression>* E # conversion with a different number of arguments
7279
7280const char*
7281__demangle_tree::__parse_conversion_expr(const char* first, const char* last)
7282{
7283 if (last - first >= 3 && first[0] == 'c' && first[1] == 'v')
7284 {
7285 const char* t = __parse_type(first+2, last);
7286 if (t != first+2 && t != last)
7287 {
7288 __node* type = __root_;
7289 __node* args = 0;
7290 if (*t != '_')
7291 {
7292 const char* t1 = __parse_expression(t, last);
7293 if (t1 == t)
7294 return first;
7295 args = __root_;
7296 t = t1;
7297 }
7298 else
7299 {
7300 ++t;
7301 if (t == last)
7302 return first;
7303 __node* prev = 0;
7304 while (*t != 'E')
7305 {
7306 const char* t1 = __parse_expression(t, last);
7307 if (t1 == t || t1 == last)
7308 return first;
7309 if (!__make<__list>(__root_))
7310 return first;
7311 if (args == 0)
7312 args = __root_;
7313 if (prev)
7314 {
7315 prev->__right_ = __root_;
7316 __root_->__size_ = prev->__size_ + 1;
7317 }
7318 prev = __root_;
7319 t = t1;
7320 }
7321 ++t;
7322 }
7323 if (__make<__operator_cast>(type, args))
7324 first = t;
7325 }
7326 }
7327 return first;
7328}
7329
7330// [gs] da <expression> # delete[] expression
7331
7332const char*
7333__demangle_tree::__parse_delete_array_expr(const char* first, const char* last)
7334{
7335 if (last - first >= 4)
7336 {
7337 const char* t = first;
7338 bool parsed_gs = false;
7339 if (t[0] == 'g' && t[1] == 's')
7340 {
7341 t += 2;
7342 parsed_gs = true;
7343 }
7344 if (t[0] == 'd' && t[1] == 'a')
7345 {
7346 t += 2;
7347 const char* t1 = __parse_expression(t, last);
7348 if (t1 != t)
7349 {
7350 if (__make<__delete_array_expr>(parsed_gs, __root_))
7351 first = t1;
7352 }
7353 }
7354 }
7355 return first;
7356}
7357
7358// dc <type> <expression> # dynamic_cast<type> (expression)
7359
7360const char*
7361__demangle_tree::__parse_dynamic_cast_expr(const char* first, const char* last)
7362{
7363 if (last - first >= 3 && first[0] == 'd' && first[1] == 'c')
7364 {
7365 const char* t = __parse_type(first+2, last);
7366 if (t != first+2)
7367 {
7368 __node* type = __root_;
7369 const char* t1 = __parse_expression(t, last);
7370 if (t1 != t)
7371 {
7372 if (__make<__dynamic_cast>(type, __root_))
7373 first = t1;
7374 }
7375 }
7376 }
7377 return first;
7378}
7379
7380// [gs] dl <expression> # delete expression
7381
7382const char*
7383__demangle_tree::__parse_delete_expr(const char* first, const char* last)
7384{
7385 if (last - first >= 4)
7386 {
7387 const char* t = first;
7388 bool parsed_gs = false;
7389 if (t[0] == 'g' && t[1] == 's')
7390 {
7391 t += 2;
7392 parsed_gs = true;
7393 }
7394 if (t[0] == 'd' && t[1] == 'l')
7395 {
7396 t += 2;
7397 const char* t1 = __parse_expression(t, last);
7398 if (t1 != t)
7399 {
7400 if (__make<__delete_expr>(parsed_gs, __root_))
7401 first = t1;
7402 }
7403 }
7404 }
7405 return first;
7406}
7407
7408// ds <expression> <expression> # expr.*expr
7409
7410const char*
7411__demangle_tree::__parse_dot_star_expr(const char* first, const char* last)
7412{
7413 if (last - first >= 3 && first[0] == 'd' && first[1] == 's')
7414 {
7415 const char* t = __parse_expression(first+2, last);
7416 if (t != first+2)
7417 {
7418 __node* expr = __root_;
7419 const char* t1 = __parse_expression(t, last);
7420 if (t1 != t)
7421 {
7422 if (__make<__dot_star_expr>(expr, __root_))
7423 first = t1;
7424 }
7425 }
7426 }
7427 return first;
7428}
7429
7430// dt <expression> <unresolved-name> # expr.name
7431
7432const char*
7433__demangle_tree::__parse_dot_expr(const char* first, const char* last)
7434{
7435 if (last - first >= 3 && first[0] == 'd' && first[1] == 't')
7436 {
7437 const char* t = __parse_expression(first+2, last);
7438 if (t != first+2)
7439 {
7440 __node* expr = __root_;
7441 const char* t1 = __parse_unresolved_name(t, last);
7442 if (t1 != t)
7443 {
7444 if (__make<__dot_expr>(expr, __root_))
7445 first = t1;
7446 }
7447 }
7448 }
7449 return first;
7450}
7451
7452// mm_ <expression> # prefix --
7453
7454const char*
7455__demangle_tree::__parse_decrement_expr(const char* first, const char* last)
7456{
7457 if (last - first > 3 && first[0] == 'm' && first[1] == 'm' && first[2] == '_')
7458 {
7459 const char* t = __parse_expression(first+3, last);
7460 if (t != first+3)
7461 {
7462 if (__make<__operator_decrement>(true, __root_))
7463 first = t;
7464 }
7465 }
7466 return first;
7467}
7468
7469// pp_ <expression> # prefix ++
7470
7471const char*
7472__demangle_tree::__parse_increment_expr(const char* first, const char* last)
7473{
7474 if (last - first > 3 && first[0] == 'p' && first[1] == 'p' && first[2] == '_')
7475 {
7476 const char* t = __parse_expression(first+3, last);
7477 if (t != first+3)
7478 {
7479 if (__make<__operator_increment>(true, __root_))
7480 first = t;
7481 }
7482 }
7483 return first;
7484}
7485
7486// [gs] nw <expression>* _ <type> E # new (expr-list) type
7487// [gs] nw <expression>* _ <type> <initializer> # new (expr-list) type (init)
7488// [gs] na <expression>* _ <type> E # new[] (expr-list) type
7489// [gs] na <expression>* _ <type> <initializer> # new[] (expr-list) type (init)
7490// <initializer> ::= pi <expression>* E # parenthesized initialization
7491
7492const char*
7493__demangle_tree::__parse_new_expr(const char* first, const char* last)
7494{
7495 if (last - first >= 4)
7496 {
7497 const char* t = first;
7498 bool parsed_gs = false;
7499 if (t[0] == 'g' && t[1] == 's')
7500 {
7501 t += 2;
7502 parsed_gs = true;
7503 }
7504 if (t[0] == 'n' && (t[1] == 'w' || t[1] == 'a'))
7505 {
7506 bool is_array = t[1] == 'a';
7507 t += 2;
7508 if (t == last)
7509 return first;
7510 __node* expr = 0;
7511 __node* prev = 0;
7512 while (*t != '_')
7513 {
7514 const char* t1 = __parse_expression(t, last);
7515 if (t1 == t || t1 == last)
7516 return first;
7517 if (!__make<__list>(__root_))
7518 return first;
7519 if (expr == 0)
7520 expr = __root_;
7521 if (prev)
7522 {
7523 prev->__right_ = __root_;
7524 __root_->__size_ = prev->__size_ + 1;
7525 }
7526 prev = __root_;
7527 t = t1;
7528 }
7529 ++t;
7530 const char* t1 = __parse_type(t, last);
7531 if (t1 == t || t1 == last)
7532 return first;
7533 t = t1;
7534 __node* type = __root_;
7535 __node* init = 0;
7536 prev = 0;
7537 bool has_init = false;
7538 if (last - t >= 3 && t[0] == 'p' && t[1] == 'i')
7539 {
7540 t += 2;
7541 has_init = true;
7542 while (*t != 'E')
7543 {
7544 t1 = __parse_expression(t, last);
7545 if (t1 == t || t1 == last)
7546 return first;
7547 if (!__make<__list>(__root_))
7548 return first;
7549 if (init == 0)
7550 init = __root_;
7551 if (prev)
7552 {
7553 prev->__right_ = __root_;
7554 __root_->__size_ = prev->__size_ + 1;
7555 }
7556 prev = __root_;
7557 t = t1;
7558 }
7559 }
7560 if (*t != 'E')
7561 return first;
7562 if (__make<__new_expr>(parsed_gs, is_array, has_init,
7563 expr, type, init))
7564 first = t;
7565 }
7566 }
7567 return first;
7568}
7569
7570// pt <expression> <unresolved-name> # expr->name
7571
7572const char*
7573__demangle_tree::__parse_arrow_expr(const char* first, const char* last)
7574{
7575 if (last - first >= 3 && first[0] == 'p' && first[1] == 't')
7576 {
7577 const char* t = __parse_expression(first+2, last);
7578 if (t != first+2)
7579 {
7580 __node* expr = __root_;
7581 const char* t1 = __parse_unresolved_name(t, last);
7582 if (t1 != t)
7583 {
7584 if (__make<__arrow_expr>(expr, __root_))
7585 first = t1;
7586 }
7587 }
7588 }
7589 return first;
7590}
7591
7592// rc <type> <expression> # reinterpret_cast<type> (expression)
7593
7594const char*
7595__demangle_tree::__parse_reinterpret_cast_expr(const char* first, const char* last)
7596{
7597 if (last - first >= 3 && first[0] == 'r' && first[1] == 'c')
7598 {
7599 const char* t = __parse_type(first+2, last);
7600 if (t != first+2)
7601 {
7602 __node* type = __root_;
7603 const char* t1 = __parse_expression(t, last);
7604 if (t1 != t)
7605 {
7606 if (__make<__reinterpret_cast>(type, __root_))
7607 first = t1;
7608 }
7609 }
7610 }
7611 return first;
7612}
7613
7614// sc <type> <expression> # static_cast<type> (expression)
7615
7616const char*
7617__demangle_tree::__parse_static_cast_expr(const char* first, const char* last)
7618{
7619 if (last - first >= 3 && first[0] == 's' && first[1] == 'c')
7620 {
7621 const char* t = __parse_type(first+2, last);
7622 if (t != first+2)
7623 {
7624 __node* type = __root_;
7625 const char* t1 = __parse_expression(t, last);
7626 if (t1 != t)
7627 {
7628 if (__make<__static_cast>(type, __root_))
7629 first = t1;
7630 }
7631 }
7632 }
7633 return first;
7634}
7635
7636// st <type> # sizeof (a type)
7637
7638const char*
7639__demangle_tree::__parse_sizeof_type_expr(const char* first, const char* last)
7640{
7641 if (last - first >= 3 && first[0] == 's' && first[1] == 't')
7642 {
7643 const char* t = __parse_type(first+2, last);
7644 if (t != first+2)
7645 {
7646 if (__make<__operator_sizeof_expression>(__root_))
7647 first = t;
7648 }
7649 }
7650 return first;
7651}
7652
7653// sZ <template-param> # size of a parameter pack
7654
7655const char*
7656__demangle_tree::__parse_sizeof_param_pack_expr(const char* first, const char* last)
7657{
7658 if (last - first >= 3 && first[0] == 's' && first[1] == 'Z' && first[2] == 'T')
7659 {
7660 const char* t = __parse_template_param(first+2, last);
7661 if (t != first+2)
7662 {
7663 if (__make<__operator_sizeof_param_pack>(__root_))
7664 first = t;
7665 }
7666 }
7667 return first;
7668}
7669
7670// sZ <function-param> # size of a function parameter pack
7671
7672const char*
7673__demangle_tree::__parse_sizeof_function_param_pack_expr(const char* first, const char* last)
7674{
7675 if (last - first >= 3 && first[0] == 's' && first[1] == 'Z' && first[2] == 'f')
7676 {
7677 const char* t = __parse_function_param(first+2, last);
7678 if (t != first+2)
7679 {
7680 if (__make<__operator_sizeof_param_pack>(__root_))
7681 first = t;
7682 }
7683 }
7684 return first;
7685}
7686
7687// sp <expression> # pack expansion
7688
7689const char*
7690__demangle_tree::__parse_pack_expansion(const char* first, const char* last)
7691{
7692 if (last - first >= 3 && first[0] == 's' && first[1] == 'p')
7693 {
7694 const char* t = __parse_expression(first+2, last);
7695 if (t != first+2)
7696 {
7697 if (__make<__pack_expansion>(__root_))
7698 first = t;
7699 }
7700 }
7701 return first;
7702}
7703
7704// te <expression> # typeid (expression)
7705// ti <type> # typeid (type)
7706
7707const char*
7708__demangle_tree::__parse_typeid_expr(const char* first, const char* last)
7709{
7710 if (last - first >= 3 && first[0] == 't' && (first[1] == 'e' || first[1] == 'i'))
7711 {
7712 const char* t;
7713 if (first[1] == 'e')
7714 t = __parse_expression(first+2, last);
7715 else
7716 t = __parse_type(first+2, last);
7717 if (t != first+2)
7718 {
7719 if (__make<__typeid>(__root_))
7720 first = t;
7721 }
7722 }
7723 return first;
7724}
7725
7726// tw <expression> # throw expression
7727
7728const char*
7729__demangle_tree::__parse_throw_expr(const char* first, const char* last)
7730{
7731 if (last - first >= 3 && first[0] == 't' && first[1] == 'w')
7732 {
7733 const char* t = __parse_expression(first+2, last);
7734 if (t != first+2)
7735 {
7736 if (__make<__throw>(__root_))
7737 first = t;
7738 }
7739 }
7740 return first;
7741}
7742
7743// <expression> ::= <unary operator-name> <expression>
7744// ::= <binary operator-name> <expression> <expression>
7745// ::= <ternary operator-name> <expression> <expression> <expression>
7746// ::= cl <expression>+ E # call
7747// ::= cv <type> <expression> # conversion with one argument
7748// ::= cv <type> _ <expression>* E # conversion with a different number of arguments
7749// ::= [gs] nw <expression>* _ <type> E # new (expr-list) type
7750// ::= [gs] nw <expression>* _ <type> <initializer> # new (expr-list) type (init)
7751// ::= [gs] na <expression>* _ <type> E # new[] (expr-list) type
7752// ::= [gs] na <expression>* _ <type> <initializer> # new[] (expr-list) type (init)
7753// ::= [gs] dl <expression> # delete expression
7754// ::= [gs] da <expression> # delete[] expression
7755// ::= pp_ <expression> # prefix ++
7756// ::= mm_ <expression> # prefix --
7757// ::= ti <type> # typeid (type)
7758// ::= te <expression> # typeid (expression)
7759// ::= dc <type> <expression> # dynamic_cast<type> (expression)
7760// ::= sc <type> <expression> # static_cast<type> (expression)
7761// ::= cc <type> <expression> # const_cast<type> (expression)
7762// ::= rc <type> <expression> # reinterpret_cast<type> (expression)
7763// ::= st <type> # sizeof (a type)
7764// ::= at <type> # alignof (a type)
7765// ::= <template-param>
7766// ::= <function-param>
7767// ::= dt <expression> <unresolved-name> # expr.name
7768// ::= pt <expression> <unresolved-name> # expr->name
7769// ::= ds <expression> <expression> # expr.*expr
7770// ::= sZ <template-param> # size of a parameter pack
7771// ::= sZ <function-param> # size of a function parameter pack
7772// ::= sp <expression> # pack expansion
7773// ::= tw <expression> # throw expression
7774// ::= tr # throw with no operand (rethrow)
7775// ::= <unresolved-name> # f(p), N::f(p), ::f(p),
7776// # freestanding dependent name (e.g., T::x),
7777// # objectless nonstatic member reference
7778// ::= <expr-primary>
7779
7780const char*
7781__demangle_tree::__parse_expression(const char* first, const char* last)
7782{
7783 if (last - first >= 2)
7784 {
7785 const char* t = first;
7786 bool parsed_gs = false;
7787 if (last - first >= 4 && t[0] == 'g' && t[1] == 's')
7788 {
7789 t += 2;
7790 parsed_gs = true;
7791 }
7792 switch (*t)
7793 {
7794 case 'L':
7795 t = __parse_expr_primary(first, last);
7796 break;
7797 case 'T':
7798 t = __parse_template_param(first, last);
7799 break;
7800 case 'f':
7801 t = __parse_function_param(first, last);
7802 break;
7803 case 'a':
7804 if (t[1] == 't')
7805 t = __parse_alignof_expr(first, last);
7806 break;
7807 case 'c':
7808 switch (t[1])
7809 {
7810 case 'c':
7811 t = __parse_const_cast_expr(first, last);
7812 break;
7813 case 'l':
7814 t = __parse_call_expr(first, last);
7815 break;
7816 case 'v':
7817 t = __parse_conversion_expr(first, last);
7818 break;
7819 }
7820 break;
7821 case 'd':
7822 switch (t[1])
7823 {
7824 case 'a':
7825 t = __parse_delete_array_expr(first, last);
7826 break;
7827 case 'c':
7828 t = __parse_dynamic_cast_expr(first, last);
7829 break;
7830 case 'l':
7831 t = __parse_delete_expr(first, last);
7832 break;
7833 case 's':
7834 t = __parse_dot_star_expr(first, last);
7835 break;
7836 case 't':
7837 t = __parse_dot_expr(first, last);
7838 break;
7839 }
7840 break;
7841 case 'm':
7842 t = __parse_decrement_expr(first, last);
7843 break;
7844 case 'n':
7845 switch (t[1])
7846 {
7847 case 'a':
7848 case 'w':
7849 t = __parse_new_expr(first, last);
7850 break;
7851 }
7852 break;
7853 case 'p':
7854 switch (t[1])
7855 {
7856 case 'p':
7857 t = __parse_increment_expr(first, last);
7858 break;
7859 case 't':
7860 t = __parse_arrow_expr(first, last);
7861 break;
7862 }
7863 break;
7864 case 'r':
7865 t = __parse_reinterpret_cast_expr(first, last);
7866 break;
7867 case 's':
7868 switch (t[1])
7869 {
7870 case 'c':
7871 t = __parse_static_cast_expr(first, last);
7872 break;
7873 case 'p':
7874 t = __parse_pack_expansion(first, last);
7875 break;
7876 case 't':
7877 t = __parse_sizeof_type_expr(first, last);
7878 break;
7879 case 'Z':
7880 if (last - t >= 3)
7881 {
7882 switch (t[2])
7883 {
7884 case 'T':
7885 t = __parse_sizeof_param_pack_expr(first, last);
7886 break;
7887 case 'f':
7888 t = __parse_sizeof_function_param_pack_expr(first, last);
7889 break;
7890 }
7891 }
7892 break;
7893 }
7894 break;
7895 case 't':
7896 switch (t[1])
7897 {
7898 case 'e':
7899 case 'i':
7900 t = __parse_typeid_expr(first, last);
7901 break;
7902 case 'r':
7903 if (__make<__rethrow>())
7904 t = first +2;
7905 break;
7906 case 'w':
7907 t = __parse_throw_expr(first, last);
7908 break;
7909 }
7910 break;
7911 }
7912 if ((!parsed_gs && t == first) || (parsed_gs && t == first+2))
7913 {
7914 int op;
7915 t = __parse_operator_name(first, last, &op);
7916 if (t == first)
7917 first = __parse_unresolved_name(first, last);
7918 else
7919 first = t;
7920 }
7921 else
7922 first = t;
7923 }
7924 return first;
7925}
7926
7927// <array-type> ::= A <positive dimension number> _ <element type>
7928// ::= A [<dimension expression>] _ <element type>
7929
7930const char*
7931__demangle_tree::__parse_array_type(const char* first, const char* last)
7932{
7933 if (first != last && *first == 'A' && first+1 != last)
7934 {
7935 if (first[1] == '_')
7936 {
7937 const char* t = __parse_type(first+2, last);
7938 if (t != first+2)
7939 {
7940 if (__make<__array>(__root_))
7941 first = t;
7942 }
7943 }
7944 else if ('1' <= first[1] && first[1] <= '9')
7945 {
7946 size_t dim = first[1] - '0';
7947 const char* t = first+2;
7948 for (; t != last && isdigit(*t); ++t)
7949 dim = dim * 10 + *t - '0';
7950 if (t != last && *t == '_')
7951 {
7952 const char* t2 = __parse_type(t+1, last);
7953 if (t2 != t+1)
7954 {
7955 if (__make<__array>(__root_, dim))
7956 first = t2;
7957 }
7958 }
7959 }
7960 else
7961 {
7962 const char* t = __parse_expression(first+1, last);
7963 if (t != first+1 && t != last && *t == '_')
7964 {
7965 __node* dim = __root_;
7966 const char* t2 = __parse_type(++t, last);
7967 if (t2 != t)
7968 {
7969 if (__make<__array>(__root_, dim))
7970 first = t2;
7971 }
7972 }
7973 }
7974 }
7975 return first;
7976}
7977
7978// <class-enum-type> ::= <name>
7979
7980const char*
7981__demangle_tree::__parse_class_enum_type(const char* first, const char* last)
7982{
7983 return __parse_name(first, last);
7984}
7985
7986// <pointer-to-member-type> ::= M <class type> <member type>
7987
7988const char*
7989__demangle_tree::__parse_pointer_to_member_type(const char* first, const char* last)
7990{
7991 if (first != last && *first == 'M')
7992 {
7993 const char* t = __parse_type(first+1, last);
7994 if (t != first+1)
7995 {
7996 __node* class_type = __root_;
7997 const char* t2 = __parse_type(t, last, true, true);
7998 if (t2 != t)
7999 {
8000 if (__make<__pointer_to_member_type>(class_type, __root_))
8001 first = t2;
8002 }
8003 }
8004 }
8005 return first;
8006}
8007
8008// <decltype> ::= Dt <expression> E # decltype of an id-expression or class member access (C++0x)
8009// ::= DT <expression> E # decltype of an expression (C++0x)
8010
8011const char*
8012__demangle_tree::__parse_decltype(const char* first, const char* last)
8013{
8014 if (last - first >= 4 && first[0] == 'D')
8015 {
8016 switch (first[1])
8017 {
8018 case 't':
8019 case 'T':
8020 {
8021 const char* t = __parse_expression(first+2, last);
8022 if (t != first+2 && t != last && *t == 'E')
8023 {
8024 if (__make<__decltype_node>(__root_))
8025 first = t+1;
8026 }
8027 }
8028 break;
8029 }
8030 }
8031 return first;
8032}
8033
8034// <template-param> ::= T_ # first template parameter
8035// ::= T <parameter-2 non-negative number> _
8036
8037const char*
8038__demangle_tree::__parse_template_param(const char* first, const char* last)
8039{
8040 if (last - first >= 2)
8041 {
8042 if (*first == 'T')
8043 {
8044 if (first[1] == '_')
8045 {
8046 if (__t_begin_ != __t_end_)
8047 {
8048 if (__make<__sub>(*__t_begin_))
8049 first += 2;
8050 }
8051 else
8052 {
8053 if (__make<__sub>(size_t(0)))
8054 {
8055 first += 2;
8056 __fix_forward_references_ = true;
8057 }
8058 }
8059 }
8060 else if (isdigit(first[1]))
8061 {
8062 const char* t = first+1;
8063 size_t sub = *t - '0';
8064 for (++t; t != last && isdigit(*t); ++t)
8065 {
8066 sub *= 10;
8067 sub += *t - '0';
8068 }
8069 if (t == last || *t != '_')
8070 return first;
8071 ++sub;
8072 if (sub < __t_end_ - __t_begin_)
8073 {
8074 if (__make<__sub>(__t_begin_[sub]))
8075 first = t+1;
8076 }
8077 else
8078 {
8079 if (__make<__sub>(sub))
8080 {
8081 first = t+1;
8082 __fix_forward_references_ = true;
8083 }
8084 }
8085 }
8086 }
8087 }
8088 return first;
8089}
8090
Howard Hinnantab87dcf2011-12-15 20:02:15 +00008091// extension:
8092// <vector-type> ::= Dv <positive dimension number> _
8093// <extended element type>
8094// ::= Dv [<dimension expression>] _ <element type>
8095// <extended element type> ::= <element type>
8096// ::= p # AltiVec vector pixel
8097
8098const char*
8099__demangle_tree::__parse_vector_type(const char* first, const char* last)
8100{
8101 if (last - first > 3 && first[0] == 'D' && first[1] == 'v')
8102 {
8103 if ('1' <= first[2] && first[2] <= '9')
8104 {
8105 const char* t = first+3;
8106 while (*t != '_')
8107 {
8108 if (!isdigit(*t) || ++t == last)
8109 return first;
8110 }
8111 const char* num = first + 2;
8112 size_t sz = t - num;
8113 if (++t != last)
8114 {
8115 if (*t != 'p')
8116 {
8117 const char* t1 = __parse_type(t, last);
8118 if (t1 != t)
8119 {
8120 if (__make<__vector_type>(__root_, num, sz))
8121 first = t1;
8122 }
8123 }
8124 else
8125 {
8126 ++t;
8127 if (__make<__vector_type>((__node*)0, num, sz))
8128 first = t;
8129 }
8130 }
8131 }
8132 else
8133 {
8134 __node* num = 0;
8135 const char* t1 = first+2;
8136 if (*t1 != '_')
8137 {
8138 const char* t = __parse_expression(t1, last);
8139 if (t != t1)
8140 num = __root_;
8141 t1 = t;
8142 }
8143 if (t1 != last && *t1 == '_' && ++t1 != last)
8144 {
8145 const char* t = __parse_type(t1, last);
8146 if (t != t1)
8147 {
8148 if (__make<__vector_type>(__root_, num))
8149 first = t;
8150 }
8151 }
8152 }
8153 }
8154 return first;
8155}
8156
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008157// <type> ::= <builtin-type>
8158// ::= <function-type>
8159// ::= <class-enum-type>
8160// ::= <array-type>
8161// ::= <pointer-to-member-type>
8162// ::= <template-param>
8163// ::= <template-template-param> <template-args>
8164// ::= <decltype>
8165// ::= <substitution>
8166// ::= <CV-qualifiers> <type>
8167// ::= P <type> # pointer-to
8168// ::= R <type> # reference-to
8169// ::= O <type> # rvalue reference-to (C++0x)
8170// ::= C <type> # complex pair (C 2000)
8171// ::= G <type> # imaginary (C 2000)
8172// ::= Dp <type> # pack expansion (C++0x)
8173// ::= U <source-name> <type> # vendor extended type qualifier
Howard Hinnantab87dcf2011-12-15 20:02:15 +00008174// extension := <vector-type> # <vector-type> starts with Dv
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008175
8176const char*
8177__demangle_tree::__parse_type(const char* first, const char* last,
8178 bool try_to_parse_template_args,
8179 bool look_for_ref_quals)
8180{
8181 unsigned cv = 0;
8182 const char* t = __parse_cv_qualifiers(first, last, cv, look_for_ref_quals);
8183 if (t != first)
8184 {
8185 const char* t2 = __parse_type(t, last, try_to_parse_template_args);
8186 if (t2 != t)
8187 {
8188 if (__make<__cv_qualifiers>(cv, __root_))
8189 {
8190 if (__sub_end_ == __sub_cap_)
8191 __status_ = memory_alloc_failure;
8192 else
8193 {
8194 *__sub_end_++ = __root_;
8195 first = t2;
8196 }
8197 }
8198 }
8199 return first;
8200 }
8201 if (first != last)
8202 {
8203 switch (*first)
8204 {
8205 case 'A':
8206 t = __parse_array_type(first, last);
8207 if (t != first)
8208 {
8209 if (__sub_end_ == __sub_cap_)
8210 __status_ = memory_alloc_failure;
8211 else
8212 {
8213 *__sub_end_++ = __root_;
8214 first = t;
8215 }
8216 }
8217 break;
8218 case 'C':
8219 t = __parse_type(first+1, last, try_to_parse_template_args);
8220 if (t != first+1)
8221 {
8222 if (__make<__d_complex>(__root_))
8223 {
8224 if (__sub_end_ == __sub_cap_)
8225 __status_ = memory_alloc_failure;
8226 else
8227 {
8228 *__sub_end_++ = __root_;
8229 first = t;
8230 }
8231 }
8232 return first;
8233 }
8234 break;
8235 case 'F':
8236 t = __parse_function_type(first, last);
8237 if (t != first)
8238 {
8239 if (__sub_end_ == __sub_cap_)
8240 __status_ = memory_alloc_failure;
8241 else
8242 {
8243 *__sub_end_++ = __root_;
8244 first = t;
8245 }
8246 }
8247 break;
8248 case 'G':
8249 t = __parse_type(first+1, last, try_to_parse_template_args);
8250 if (t != first+1)
8251 {
8252 if (__make<__imaginary>(__root_))
8253 {
8254 if (__sub_end_ == __sub_cap_)
8255 __status_ = memory_alloc_failure;
8256 else
8257 {
8258 *__sub_end_++ = __root_;
8259 first = t;
8260 }
8261 }
8262 return first;
8263 }
8264 break;
8265 case 'M':
8266 t = __parse_pointer_to_member_type(first, last);
8267 if (t != first)
8268 {
8269 if (__sub_end_ == __sub_cap_)
8270 __status_ = memory_alloc_failure;
8271 else
8272 {
8273 *__sub_end_++ = __root_;
8274 first = t;
8275 }
8276 }
8277 break;
8278 case 'O':
8279 t = __parse_type(first+1, last, try_to_parse_template_args);
8280 if (t != first+1)
8281 {
8282 if (__make<__rvalue_reference_to>(__root_))
8283 {
8284 if (__sub_end_ == __sub_cap_)
8285 __status_ = memory_alloc_failure;
8286 else
8287 {
8288 *__sub_end_++ = __root_;
8289 first = t;
8290 }
8291 }
8292 return first;
8293 }
8294 break;
8295 case 'P':
8296 t = __parse_type(first+1, last, try_to_parse_template_args);
8297 if (t != first+1)
8298 {
8299 if (__make<__pointer_to>(__root_))
8300 {
8301 if (__sub_end_ == __sub_cap_)
8302 __status_ = memory_alloc_failure;
8303 else
8304 {
8305 *__sub_end_++ = __root_;
8306 first = t;
8307 }
8308 }
8309 return first;
8310 }
8311 break;
8312 case 'R':
8313 t = __parse_type(first+1, last, try_to_parse_template_args);
8314 if (t != first+1)
8315 {
8316 if (__make<__lvalue_reference_to>(__root_))
8317 {
8318 if (__sub_end_ == __sub_cap_)
8319 __status_ = memory_alloc_failure;
8320 else
8321 {
8322 *__sub_end_++ = __root_;
8323 first = t;
8324 }
8325 }
8326 return first;
8327 }
8328 break;
8329 case 'T':
8330 t = __parse_template_param(first, last);
8331 if (t != first)
8332 {
8333 if (__sub_end_ == __sub_cap_)
8334 __status_ = memory_alloc_failure;
8335 else
8336 {
8337 *__sub_end_++ = __root_;
8338 if (try_to_parse_template_args)
8339 {
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008340 const char* t2 = __parse_template_args(t, last);
8341 if (t2 != t)
8342 {
8343 if (__sub_end_ < __sub_cap_)
8344 {
8345 *__sub_end_++ = __root_;
8346 first = t2;
8347 }
8348 else
8349 __status_ = memory_alloc_failure;
8350 }
8351 else
8352 {
8353 first = t;
8354 }
8355 }
8356 else
8357 {
8358 first = t;
8359 }
8360 }
8361 }
8362 break;
8363 case 'U':
8364 if (first+1 != last)
8365 {
8366 t = __parse_source_name(first+1, last);
8367 if (t != first+1)
8368 {
8369 __node* name = __root_;
8370 const char* t2 = __parse_type(t, last, try_to_parse_template_args);
8371 if (t2 != t)
8372 {
8373 if (__make<__extended_qualifier>(name, __root_))
8374 {
8375 if (__sub_end_ == __sub_cap_)
8376 __status_ = memory_alloc_failure;
8377 else
8378 {
8379 *__sub_end_++ = __root_;
8380 first = t2;
8381 }
8382 }
8383 return first;
8384 }
8385 }
8386 }
8387 break;
8388 case 'S':
8389 if (first+1 != last && first[1] == 't')
8390 {
8391 t = __parse_class_enum_type(first, last);
8392 if (t != first)
8393 {
8394 if (__sub_end_ == __sub_cap_)
8395 __status_ = memory_alloc_failure;
8396 else
8397 {
8398 *__sub_end_++ = __root_;
8399 first = t;
8400 }
8401 }
8402 }
8403 else
8404 {
8405 t = __parse_substitution(first, last);
8406 if (t != first)
8407 {
8408 first = t;
8409 // Parsed a substitution. If the substitution is a
8410 // <template-param> it might be followed by <template-args>.
8411 t = __parse_template_args(first, last);
8412 if (t != first)
8413 {
8414 // Need to create substitution for <template-template-param> <template-args>
8415 if (__sub_end_ == __sub_cap_)
8416 __status_ = memory_alloc_failure;
8417 else
8418 {
8419 *__sub_end_++ = __root_;
8420 first = t;
8421 }
8422 }
8423 }
8424 }
8425 break;
8426 case 'D':
8427 if (first+1 != last)
8428 {
8429 switch (first[1])
8430 {
8431 case 'p':
8432 t = __parse_type(first+2, last, try_to_parse_template_args);
8433 if (t != first+1)
8434 {
8435 if (__make<__pack_expansion>(__root_))
8436 {
8437 if (__sub_end_ == __sub_cap_)
8438 __status_ = memory_alloc_failure;
8439 else
8440 {
8441 *__sub_end_++ = __root_;
8442 first = t;
8443 }
8444 }
8445 return first;
8446 }
8447 break;
8448 case 't':
8449 case 'T':
8450 t = __parse_decltype(first, last);
8451 if (t != first)
8452 {
8453 if (__sub_end_ == __sub_cap_)
8454 __status_ = memory_alloc_failure;
8455 else
8456 {
8457 *__sub_end_++ = __root_;
8458 first = t;
8459 }
8460 return first;
8461 }
8462 break;
Howard Hinnantab87dcf2011-12-15 20:02:15 +00008463 case 'v':
8464 t = __parse_vector_type(first, last);
8465 if (t != first)
8466 {
8467 if (__sub_end_ == __sub_cap_)
8468 __status_ = memory_alloc_failure;
8469 else
8470 {
8471 *__sub_end_++ = __root_;
8472 first = t;
8473 }
8474 return first;
8475 }
8476 break;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008477 }
8478 }
8479 // drop through
8480 default:
8481 // must check for builtin-types before class-enum-types to avoid
8482 // ambiguities with operator-names
8483 t = __parse_builtin_type(first, last);
8484 if (t != first)
8485 {
8486 first = t;
8487 }
8488 else
8489 {
8490 t = __parse_class_enum_type(first, last);
8491 if (t != first)
8492 {
8493 if (__sub_end_ == __sub_cap_)
8494 __status_ = memory_alloc_failure;
8495 else
8496 {
8497 *__sub_end_++ = __root_;
8498 first = t;
8499 }
8500 }
8501 }
8502 break;
8503 }
8504 }
8505 return first;
8506}
8507
8508// <number> ::= [n] <non-negative decimal integer>
8509
8510const char*
8511__demangle_tree::__parse_number(const char* first, const char* last)
8512{
8513 if (first != last)
8514 {
8515 const char* t = first;
8516 if (*t == 'n')
8517 ++t;
8518 if (t != last)
8519 {
8520 if (*t == '0')
8521 {
8522 first = t+1;
8523 }
8524 else if ('1' <= *t && *t <= '9')
8525 {
8526 first = t+1;
8527 while (first != last && isdigit(*first))
8528 ++first;
8529 }
8530 }
8531 }
8532 return first;
8533}
8534
8535// <call-offset> ::= h <nv-offset> _
8536// ::= v <v-offset> _
8537//
8538// <nv-offset> ::= <offset number>
8539// # non-virtual base override
8540//
8541// <v-offset> ::= <offset number> _ <virtual offset number>
8542// # virtual base override, with vcall offset
8543
8544const char*
8545__demangle_tree::__parse_call_offset(const char* first, const char* last)
8546{
8547 if (first != last)
8548 {
8549 switch (*first)
8550 {
8551 case 'h':
8552 {
8553 const char* t = __parse_number(first + 1, last);
8554 if (t != first + 1 && t != last && *t == '_')
8555 first = t + 1;
8556 }
8557 break;
8558 case 'v':
8559 {
8560 const char* t = __parse_number(first + 1, last);
8561 if (t != first + 1 && t != last && *t == '_')
8562 {
8563 const char* t2 = __parse_number(++t, last);
8564 if (t2 != t && t2 != last && *t2 == '_')
8565 first = t2 + 1;
8566 }
8567 }
8568 break;
8569 }
8570 }
8571 return first;
8572}
8573
8574// <special-name> ::= TV <type> # virtual table
8575// ::= TT <type> # VTT structure (construction vtable index)
8576// ::= TI <type> # typeinfo structure
8577// ::= TS <type> # typeinfo name (null-terminated byte string)
8578// ::= Tc <call-offset> <call-offset> <base encoding>
8579// # base is the nominal target function of thunk
8580// # first call-offset is 'this' adjustment
8581// # second call-offset is result adjustment
8582// ::= T <call-offset> <base encoding>
8583// # base is the nominal target function of thunk
8584// ::= GV <object name> # Guard variable for one-time initialization
8585// # No <type>
Howard Hinnantf2700352011-12-09 20:07:56 +00008586// extension ::= TC <first type> <number> _ <second type> # construction vtable for second-in-first
8587// extension ::= GR <object name> # reference temporary for object
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008588
8589const char*
8590__demangle_tree::__parse_special_name(const char* first, const char* last)
8591{
8592 if (last - first > 2)
8593 {
8594 const char* t;
8595 switch (*first)
8596 {
8597 case 'T':
8598 switch (first[1])
8599 {
8600 case 'V':
8601 // TV <type> # virtual table
8602 t = __parse_type(first+2, last);
8603 if (t != first+2 && __make<__vtable>(__root_))
8604 first = t;
8605 break;
8606 case 'T':
8607 // TT <type> # VTT structure (construction vtable index)
8608 t = __parse_type(first+2, last);
8609 if (t != first+2 && __make<__VTT>(__root_))
8610 first = t;
8611 break;
8612 case 'I':
8613 // TI <type> # typeinfo structure
8614 t = __parse_type(first+2, last);
8615 if (t != first+2 && __make<__typeinfo>(__root_))
8616 first = t;
8617 break;
8618 case 'S':
8619 // TS <type> # typeinfo name (null-terminated byte string)
8620 t = __parse_type(first+2, last);
8621 if (t != first+2 && __make<__typeinfo_name>(__root_))
8622 first = t;
8623 break;
8624 case 'c':
8625 // Tc <call-offset> <call-offset> <base encoding>
8626 {
8627 const char* t0 = __parse_call_offset(first+2, last);
8628 if (t0 == first+2)
8629 break;
8630 const char* t1 = __parse_call_offset(t0, last);
8631 if (t1 == t0)
8632 break;
8633 t = __parse_encoding(t1, last);
8634 if (t != t1 && __make<__covariant_return_thunk>(__root_))
8635 first = t;
8636 }
8637 break;
Howard Hinnantf2700352011-12-09 20:07:56 +00008638 case 'C':
8639 // extension ::= TC <first type> <number> _ <second type> # construction vtable for second-in-first
8640 t = __parse_type(first+2, last);
8641 if (t != first+2)
8642 {
8643 __node* op1 = __root_;
8644 const char* t0 = __parse_number(t, last);
8645 if (t0 != t && t0 != last && *t0 == '_')
8646 {
8647 const char* t1 = __parse_type(++t0, last);
8648 if (t1 != t0)
8649 {
8650 if (__make<__construction_vtable>(__root_, op1))
8651 first = t1;
8652 }
8653 }
8654 }
8655 break;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008656 default:
8657 // T <call-offset> <base encoding>
8658 {
8659 const char* t0 = __parse_call_offset(first+1, last);
8660 if (t0 == first+1)
8661 break;
8662 t = __parse_encoding(t0, last);
8663 if (t != t0)
8664 {
8665 if (first[2] == 'v')
8666 {
8667 if (__make<__virtual_thunk>(__root_))
8668 first = t;
8669 }
8670 else
8671 {
8672 if (__make<__non_virtual_thunk>(__root_))
8673 first = t;
8674 }
8675 }
8676 }
8677 break;
8678 }
8679 break;
8680 case 'G':
Howard Hinnantf2700352011-12-09 20:07:56 +00008681 switch (first[1])
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008682 {
Howard Hinnantf2700352011-12-09 20:07:56 +00008683 case 'V':
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008684 // GV <object name> # Guard variable for one-time initialization
8685 t = __parse_name(first+2, last);
8686 if (t != first+2 && __make<__guard_variable>(__root_))
8687 first = t;
Howard Hinnantf2700352011-12-09 20:07:56 +00008688 break;
8689 case 'R':
8690 // extension ::= GR <object name> # reference temporary for object
8691 t = __parse_name(first+2, last);
8692 if (t != first+2 && __make<__reference_temporary>(__root_))
8693 first = t;
8694 break;
Howard Hinnantd213ffd2011-05-05 15:27:28 +00008695 }
8696 break;
8697 }
8698 }
8699 return first;
8700}
8701
8702// <operator-name>
8703// ::= aa # &&
8704// ::= ad # & (unary)
8705// ::= an # &
8706// ::= aN # &=
8707// ::= aS # =
8708// ::= at # alignof (a type)
8709// ::= az # alignof (an expression)
8710// ::= cl # ()
8711// ::= cm # ,
8712// ::= co # ~
8713// ::= cv <type> # (cast)
8714// ::= da # delete[]
8715// ::= de # * (unary)
8716// ::= dl # delete
8717// ::= dv # /
8718// ::= dV # /=
8719// ::= eo # ^
8720// ::= eO # ^=
8721// ::= eq # ==
8722// ::= ge # >=
8723// ::= gt # >
8724// ::= ix # []
8725// ::= le # <=
8726// ::= ls # <<
8727// ::= lS # <<=
8728// ::= lt # <
8729// ::= mi # -
8730// ::= mI # -=
8731// ::= ml # *
8732// ::= mL # *=
8733// ::= mm # -- (postfix in <expression> context)
8734// ::= na # new[]
8735// ::= ne # !=
8736// ::= ng # - (unary)
8737// ::= nt # !
8738// ::= nw # new
8739// ::= oo # ||
8740// ::= or # |
8741// ::= oR # |=
8742// ::= pm # ->*
8743// ::= pl # +
8744// ::= pL # +=
8745// ::= pp # ++ (postfix in <expression> context)
8746// ::= ps # + (unary)
8747// ::= pt # ->
8748// ::= qu # ?
8749// ::= rm # %
8750// ::= rM # %=
8751// ::= rs # >>
8752// ::= rS # >>=
8753// ::= st # sizeof (a type)
8754// ::= sz # sizeof (an expression)
8755// ::= v <digit> <source-name> # vendor extended operator
8756
8757const char*
8758__demangle_tree::__parse_operator_name(const char* first, const char* last, int* type)
8759{
8760 if (last - first >= 2)
8761 {
8762 switch (*first)
8763 {
8764 case 'a':
8765 switch (first[1])
8766 {
8767 case 'a':
8768 // &&
8769 if (type)
8770 {
8771 const char* t = __parse_expression(first+2, last);
8772 if (t != first+2)
8773 {
8774 __node* op1 = __root_;
8775 const char* t2 = __parse_expression(t, last);
8776 if (t != t2)
8777 {
8778 if (__make<__operator_logical_and>(op1, __root_))
8779 {
8780 *type = 2;
8781 first = t2;
8782 }
8783 }
8784 }
8785 }
8786 else
8787 {
8788 if (__make<__operator_logical_and>())
8789 first += 2;
8790 }
8791 break;
8792 case 'd':
8793 // & (unary)
8794 if (type)
8795 {
8796 const char* t = __parse_expression(first+2, last);
8797 if (t != first+2)
8798 {
8799 if (__make<__operator_addressof>(__root_))
8800 {
8801 *type = 1;
8802 first = t;
8803 }
8804 }
8805 }
8806 else
8807 {
8808 if (__make<__operator_addressof>())
8809 first += 2;
8810 }
8811 break;
8812 case 'n':
8813 // &
8814 if (type)
8815 {
8816 const char* t = __parse_expression(first+2, last);
8817 if (t != first+2)
8818 {
8819 __node* op1 = __root_;
8820 const char* t2 = __parse_expression(t, last);
8821 if (t != t2)
8822 {
8823 if (__make<__operator_bit_and>(op1, __root_))
8824 {
8825 *type = 2;
8826 first = t2;
8827 }
8828 }
8829 }
8830 }
8831 else
8832 {
8833 if (__make<__operator_bit_and>())
8834 first += 2;
8835 }
8836 break;
8837 case 'N':
8838 // &=
8839 if (type)
8840 {
8841 const char* t = __parse_expression(first+2, last);
8842 if (t != first+2)
8843 {
8844 __node* op1 = __root_;
8845 const char* t2 = __parse_expression(t, last);
8846 if (t != t2)
8847 {
8848 if (__make<__operator_and_equal>(op1, __root_))
8849 {
8850 *type = 2;
8851 first = t2;
8852 }
8853 }
8854 }
8855 }
8856 else
8857 {
8858 if (__make<__operator_and_equal>())
8859 first += 2;
8860 }
8861 break;
8862 case 'S':
8863 // =
8864 if (type)
8865 {
8866 const char* t = __parse_expression(first+2, last);
8867 if (t != first+2)
8868 {
8869 __node* op1 = __root_;
8870 const char* t2 = __parse_expression(t, last);
8871 if (t != t2)
8872 {
8873 if (__make<__operator_equal>(op1, __root_))
8874 {
8875 *type = 2;
8876 first = t2;
8877 }
8878 }
8879 }
8880 }
8881 else
8882 {
8883 if (__make<__operator_equal>())
8884 first += 2;
8885 }
8886 break;
8887 case 't':
8888 // alignof (a type)
8889 if (type)
8890 {
8891 const char* t = __parse_expression(first+2, last);
8892 if (t != first+2)
8893 {
8894 if (__make<__operator_alignof_type>(__root_))
8895 {
8896 *type = -1;
8897 first = t;
8898 }
8899 }
8900 }
8901 else
8902 {
8903 if (__make<__operator_alignof_type>())
8904 first += 2;
8905 }
8906 break;
8907 case 'z':
8908 // alignof (an expression)
8909 if (type)
8910 {
8911 const char* t = __parse_expression(first+2, last);
8912 if (t != first+2)
8913 {
8914 if (__make<__operator_alignof_expression>(__root_))
8915 {
8916 *type = -1;
8917 first = t;
8918 }
8919 }
8920 }
8921 else
8922 {
8923 if (__make<__operator_alignof_expression>())
8924 first += 2;
8925 }
8926 break;
8927 }
8928 break;
8929 case 'c':
8930 switch (first[1])
8931 {
8932 case 'l':
8933 // ()
8934 if (__make<__operator_paren>())
8935 {
8936 first += 2;
8937 if (type)
8938 *type = -1;
8939 }
8940 break;
8941 case 'm':
8942 // ,
8943 if (type)
8944 {
8945 const char* t = __parse_expression(first+2, last);
8946 if (t != first+2)
8947 {
8948 __node* op1 = __root_;
8949 const char* t2 = __parse_expression(t, last);
8950 if (t != t2)
8951 {
8952 if (__make<__operator_comma>(op1, __root_))
8953 {
8954 *type = 2;
8955 first = t2;
8956 }
8957 }
8958 }
8959 }
8960 else
8961 {
8962 if (__make<__operator_comma>())
8963 first += 2;
8964 }
8965 break;
8966 case 'o':
8967 // ~
8968 if (type)
8969 {
8970 const char* t = __parse_expression(first+2, last);
8971 if (t != first+2)
8972 {
8973 if (__make<__operator_tilda>(__root_))
8974 {
8975 *type = 1;
8976 first = t;
8977 }
8978 }
8979 }
8980 else
8981 {
8982 if (__make<__operator_tilda>())
8983 first += 2;
8984 }
8985 break;
8986 case 'v':
8987 // cast <type>
8988 {
8989 const char* t = __parse_type(first+2, last, false);
8990 if (t != first+2)
8991 {
8992 __node* cast_type = __root_;
8993 if (type)
8994 {
8995 const char* t2 = __parse_expression(t, last);
8996 if (t2 != t)
8997 {
8998 if (__make<__operator_cast>(cast_type, __root_))
8999 {
9000 *type = -1;
9001 first = t2;
9002 }
9003 }
9004 }
9005 else
9006 {
9007 if (__make<__operator_cast>(cast_type))
9008 first = t;
9009 }
9010 }
9011 }
9012 break;
9013 }
9014 break;
9015 case 'd':
9016 switch (first[1])
9017 {
9018 case 'a':
9019 // delete[]
9020 if (__make<__operator_delete_array>())
9021 {
9022 first += 2;
9023 if (type)
9024 *type = -1;
9025 }
9026 break;
9027 case 'e':
9028 // * (unary)
9029 if (type)
9030 {
9031 const char* t = __parse_expression(first+2, last);
9032 if (t != first+2)
9033 {
9034 if (__make<__operator_dereference>(__root_))
9035 {
9036 *type = 1;
9037 first = t;
9038 }
9039 }
9040 }
9041 else
9042 {
9043 if (__make<__operator_dereference>())
9044 first += 2;
9045 }
9046 break;
9047 case 'l':
9048 // delete
9049 if (__make<__operator_delete>())
9050 {
9051 first += 2;
9052 if (type)
9053 *type = -1;
9054 }
9055 break;
9056 case 'v':
9057 // /
9058 if (type)
9059 {
9060 const char* t = __parse_expression(first+2, last);
9061 if (t != first+2)
9062 {
9063 __node* op1 = __root_;
9064 const char* t2 = __parse_expression(t, last);
9065 if (t != t2)
9066 {
9067 if (__make<__operator_divide>(op1, __root_))
9068 {
9069 *type = 2;
9070 first = t2;
9071 }
9072 }
9073 }
9074 }
9075 else
9076 {
9077 if (__make<__operator_divide>())
9078 first += 2;
9079 }
9080 break;
9081 case 'V':
9082 // /=
9083 if (type)
9084 {
9085 const char* t = __parse_expression(first+2, last);
9086 if (t != first+2)
9087 {
9088 __node* op1 = __root_;
9089 const char* t2 = __parse_expression(t, last);
9090 if (t != t2)
9091 {
9092 if (__make<__operator_divide_equal>(op1, __root_))
9093 {
9094 *type = 2;
9095 first = t2;
9096 }
9097 }
9098 }
9099 }
9100 else
9101 {
9102 if (__make<__operator_divide_equal>())
9103 first += 2;
9104 }
9105 break;
9106 }
9107 break;
9108 case 'e':
9109 switch (first[1])
9110 {
9111 case 'o':
9112 // ^
9113 if (type)
9114 {
9115 const char* t = __parse_expression(first+2, last);
9116 if (t != first+2)
9117 {
9118 __node* op1 = __root_;
9119 const char* t2 = __parse_expression(t, last);
9120 if (t != t2)
9121 {
9122 if (__make<__operator_xor>(op1, __root_))
9123 {
9124 *type = 2;
9125 first = t2;
9126 }
9127 }
9128 }
9129 }
9130 else
9131 {
9132 if (__make<__operator_xor>())
9133 first += 2;
9134 }
9135 break;
9136 case 'O':
9137 // ^=
9138 if (type)
9139 {
9140 const char* t = __parse_expression(first+2, last);
9141 if (t != first+2)
9142 {
9143 __node* op1 = __root_;
9144 const char* t2 = __parse_expression(t, last);
9145 if (t != t2)
9146 {
9147 if (__make<__operator_xor_equal>(op1, __root_))
9148 {
9149 *type = 2;
9150 first = t2;
9151 }
9152 }
9153 }
9154 }
9155 else
9156 {
9157 if (__make<__operator_xor_equal>())
9158 first += 2;
9159 }
9160 break;
9161 case 'q':
9162 // ==
9163 if (type)
9164 {
9165 const char* t = __parse_expression(first+2, last);
9166 if (t != first+2)
9167 {
9168 __node* op1 = __root_;
9169 const char* t2 = __parse_expression(t, last);
9170 if (t != t2)
9171 {
9172 if (__make<__operator_equality>(op1, __root_))
9173 {
9174 *type = 2;
9175 first = t2;
9176 }
9177 }
9178 }
9179 }
9180 else
9181 {
9182 if (__make<__operator_equality>())
9183 first += 2;
9184 }
9185 break;
9186 }
9187 break;
9188 case 'g':
9189 switch (first[1])
9190 {
9191 case 'e':
9192 // >=
9193 if (type)
9194 {
9195 const char* t = __parse_expression(first+2, last);
9196 if (t != first+2)
9197 {
9198 __node* op1 = __root_;
9199 const char* t2 = __parse_expression(t, last);
9200 if (t != t2)
9201 {
9202 if (__make<__operator_greater_equal>(op1, __root_))
9203 {
9204 *type = 2;
9205 first = t2;
9206 }
9207 }
9208 }
9209 }
9210 else
9211 {
9212 if (__make<__operator_greater_equal>())
9213 first += 2;
9214 }
9215 break;
9216 case 't':
9217 // >
9218 if (type)
9219 {
9220 const char* t = __parse_expression(first+2, last);
9221 if (t != first+2)
9222 {
9223 __node* op1 = __root_;
9224 const char* t2 = __parse_expression(t, last);
9225 if (t != t2)
9226 {
9227 if (__make<__operator_greater>(op1, __root_))
9228 {
9229 *type = 2;
9230 first = t2;
9231 }
9232 }
9233 }
9234 }
9235 else
9236 {
9237 if (__make<__operator_greater>())
9238 first += 2;
9239 }
9240 break;
9241 }
9242 break;
9243 case 'i':
9244 // []
9245 if (first[1] == 'x' && __make<__operator_brackets>())
9246 {
9247 first += 2;
9248 if (type)
9249 *type = -1;
9250 }
9251 break;
9252 case 'l':
9253 switch (first[1])
9254 {
9255 case 'e':
9256 // <=
9257 if (type)
9258 {
9259 const char* t = __parse_expression(first+2, last);
9260 if (t != first+2)
9261 {
9262 __node* op1 = __root_;
9263 const char* t2 = __parse_expression(t, last);
9264 if (t != t2)
9265 {
9266 if (__make<__operator_less_equal>(op1, __root_))
9267 {
9268 *type = 2;
9269 first = t2;
9270 }
9271 }
9272 }
9273 }
9274 else
9275 {
9276 if (__make<__operator_less_equal>())
9277 first += 2;
9278 }
9279 break;
9280 case 's':
9281 // <<
9282 if (type)
9283 {
9284 const char* t = __parse_expression(first+2, last);
9285 if (t != first+2)
9286 {
9287 __node* op1 = __root_;
9288 const char* t2 = __parse_expression(t, last);
9289 if (t != t2)
9290 {
9291 if (__make<__operator_left_shift>(op1, __root_))
9292 {
9293 *type = 2;
9294 first = t2;
9295 }
9296 }
9297 }
9298 }
9299 else
9300 {
9301 if (__make<__operator_left_shift>())
9302 first += 2;
9303 }
9304 break;
9305 case 'S':
9306 // <<=
9307 if (type)
9308 {
9309 const char* t = __parse_expression(first+2, last);
9310 if (t != first+2)
9311 {
9312 __node* op1 = __root_;
9313 const char* t2 = __parse_expression(t, last);
9314 if (t != t2)
9315 {
9316 if (__make<__operator_left_shift_equal>(op1, __root_))
9317 {
9318 *type = 2;
9319 first = t2;
9320 }
9321 }
9322 }
9323 }
9324 else
9325 {
9326 if (__make<__operator_left_shift_equal>())
9327 first += 2;
9328 }
9329 break;
9330 case 't':
9331 // <
9332 if (type)
9333 {
9334 const char* t = __parse_expression(first+2, last);
9335 if (t != first+2)
9336 {
9337 __node* op1 = __root_;
9338 const char* t2 = __parse_expression(t, last);
9339 if (t != t2)
9340 {
9341 if (__make<__operator_less>(op1, __root_))
9342 {
9343 *type = 2;
9344 first = t2;
9345 }
9346 }
9347 }
9348 }
9349 else
9350 {
9351 if (__make<__operator_less>())
9352 first += 2;
9353 }
9354 break;
9355 }
9356 break;
9357 case 'm':
9358 switch (first[1])
9359 {
9360 case 'i':
9361 // -
9362 if (type)
9363 {
9364 const char* t = __parse_expression(first+2, last);
9365 if (t != first+2)
9366 {
9367 __node* op1 = __root_;
9368 const char* t2 = __parse_expression(t, last);
9369 if (t != t2)
9370 {
9371 if (__make<__operator_minus>(op1, __root_))
9372 {
9373 *type = 2;
9374 first = t2;
9375 }
9376 }
9377 }
9378 }
9379 else
9380 {
9381 if (__make<__operator_minus>())
9382 first += 2;
9383 }
9384 break;
9385 case 'I':
9386 // -=
9387 if (type)
9388 {
9389 const char* t = __parse_expression(first+2, last);
9390 if (t != first+2)
9391 {
9392 __node* op1 = __root_;
9393 const char* t2 = __parse_expression(t, last);
9394 if (t != t2)
9395 {
9396 if (__make<__operator_minus_equal>(op1, __root_))
9397 {
9398 *type = 2;
9399 first = t2;
9400 }
9401 }
9402 }
9403 }
9404 else
9405 {
9406 if (__make<__operator_minus_equal>())
9407 first += 2;
9408 }
9409 break;
9410 case 'l':
9411 // *
9412 if (type)
9413 {
9414 const char* t = __parse_expression(first+2, last);
9415 if (t != first+2)
9416 {
9417 __node* op1 = __root_;
9418 const char* t2 = __parse_expression(t, last);
9419 if (t != t2)
9420 {
9421 if (__make<__operator_times>(op1, __root_))
9422 {
9423 *type = 2;
9424 first = t2;
9425 }
9426 }
9427 }
9428 }
9429 else
9430 {
9431 if (__make<__operator_times>())
9432 first += 2;
9433 }
9434 break;
9435 case 'L':
9436 // *=
9437 if (type)
9438 {
9439 const char* t = __parse_expression(first+2, last);
9440 if (t != first+2)
9441 {
9442 __node* op1 = __root_;
9443 const char* t2 = __parse_expression(t, last);
9444 if (t != t2)
9445 {
9446 if (__make<__operator_times_equal>(op1, __root_))
9447 {
9448 *type = 2;
9449 first = t2;
9450 }
9451 }
9452 }
9453 }
9454 else
9455 {
9456 if (__make<__operator_times_equal>())
9457 first += 2;
9458 }
9459 break;
9460 case 'm':
9461 // -- (postfix in <expression> context)
9462 if (type)
9463 {
9464 const char* t = __parse_expression(first+2, last);
9465 if (t != first+2)
9466 {
9467 if (__make<__operator_decrement>(false, __root_))
9468 {
9469 *type = 1;
9470 first = t;
9471 }
9472 }
9473 }
9474 else
9475 {
9476 if (__make<__operator_decrement>())
9477 first += 2;
9478 }
9479 break;
9480 }
9481 break;
9482 case 'n':
9483 switch (first[1])
9484 {
9485 case 'a':
9486 // new[]
9487 if (__make<__operator_new_array>())
9488 {
9489 first += 2;
9490 if (type)
9491 *type = -1;
9492 }
9493 break;
9494 case 'e':
9495 // !=
9496 if (type)
9497 {
9498 const char* t = __parse_expression(first+2, last);
9499 if (t != first+2)
9500 {
9501 __node* op1 = __root_;
9502 const char* t2 = __parse_expression(t, last);
9503 if (t != t2)
9504 {
9505 if (__make<__operator_not_equal>(op1, __root_))
9506 {
9507 *type = 2;
9508 first = t2;
9509 }
9510 }
9511 }
9512 }
9513 else
9514 {
9515 if (__make<__operator_not_equal>())
9516 first += 2;
9517 }
9518 break;
9519 case 'g':
9520 // - (unary)
9521 if (type)
9522 {
9523 const char* t = __parse_expression(first+2, last);
9524 if (t != first+2)
9525 {
9526 if (__make<__operator_negate>(__root_))
9527 {
9528 *type = 1;
9529 first = t;
9530 }
9531 }
9532 }
9533 else
9534 {
9535 if (__make<__operator_negate>())
9536 first += 2;
9537 }
9538 break;
9539 case 't':
9540 // !
9541 if (type)
9542 {
9543 const char* t = __parse_expression(first+2, last);
9544 if (t != first+2)
9545 {
9546 if (__make<__operator_logical_not>(__root_))
9547 {
9548 *type = 1;
9549 first = t;
9550 }
9551 }
9552 }
9553 else
9554 {
9555 if (__make<__operator_logical_not>())
9556 first += 2;
9557 }
9558 break;
9559 case 'w':
9560 // new
9561 if (__make<__operator_new>())
9562 {
9563 first += 2;
9564 if (type)
9565 *type = -1;
9566 }
9567 break;
9568 }
9569 break;
9570 case 'o':
9571 switch (first[1])
9572 {
9573 case 'o':
9574 // ||
9575 if (type)
9576 {
9577 const char* t = __parse_expression(first+2, last);
9578 if (t != first+2)
9579 {
9580 __node* op1 = __root_;
9581 const char* t2 = __parse_expression(t, last);
9582 if (t != t2)
9583 {
9584 if (__make<__operator_logical_or>(op1, __root_))
9585 {
9586 *type = 2;
9587 first = t2;
9588 }
9589 }
9590 }
9591 }
9592 else
9593 {
9594 if (__make<__operator_logical_or>())
9595 first += 2;
9596 }
9597 break;
9598 case 'r':
9599 // |
9600 if (type)
9601 {
9602 const char* t = __parse_expression(first+2, last);
9603 if (t != first+2)
9604 {
9605 __node* op1 = __root_;
9606 const char* t2 = __parse_expression(t, last);
9607 if (t != t2)
9608 {
9609 if (__make<__operator_bit_or>(op1, __root_))
9610 {
9611 *type = 2;
9612 first = t2;
9613 }
9614 }
9615 }
9616 }
9617 else
9618 {
9619 if (__make<__operator_bit_or>())
9620 first += 2;
9621 }
9622 break;
9623 case 'R':
9624 // |=
9625 if (type)
9626 {
9627 const char* t = __parse_expression(first+2, last);
9628 if (t != first+2)
9629 {
9630 __node* op1 = __root_;
9631 const char* t2 = __parse_expression(t, last);
9632 if (t != t2)
9633 {
9634 if (__make<__operator_or_equal>(op1, __root_))
9635 {
9636 *type = 2;
9637 first = t2;
9638 }
9639 }
9640 }
9641 }
9642 else
9643 {
9644 if (__make<__operator_or_equal>())
9645 first += 2;
9646 }
9647 break;
9648 }
9649 break;
9650 case 'p':
9651 switch (first[1])
9652 {
9653 case 'm':
9654 // ->*
9655 if (type)
9656 {
9657 const char* t = __parse_expression(first+2, last);
9658 if (t != first+2)
9659 {
9660 __node* op1 = __root_;
9661 const char* t2 = __parse_expression(t, last);
9662 if (t != t2)
9663 {
9664 if (__make<__operator_pointer_to_member>(op1, __root_))
9665 {
9666 *type = 2;
9667 first = t2;
9668 }
9669 }
9670 }
9671 }
9672 else
9673 {
9674 if (__make<__operator_pointer_to_member>())
9675 first += 2;
9676 }
9677 break;
9678 case 'l':
9679 // +
9680 if (type)
9681 {
9682 const char* t = __parse_expression(first+2, last);
9683 if (t != first+2)
9684 {
9685 __node* op1 = __root_;
9686 const char* t2 = __parse_expression(t, last);
9687 if (t != t2)
9688 {
9689 if (__make<__operator_plus>(op1, __root_))
9690 {
9691 *type = 2;
9692 first = t2;
9693 }
9694 }
9695 }
9696 }
9697 else
9698 {
9699 if (__make<__operator_plus>())
9700 first += 2;
9701 }
9702 break;
9703 case 'L':
9704 // +=
9705 if (type)
9706 {
9707 const char* t = __parse_expression(first+2, last);
9708 if (t != first+2)
9709 {
9710 __node* op1 = __root_;
9711 const char* t2 = __parse_expression(t, last);
9712 if (t != t2)
9713 {
9714 if (__make<__operator_plus_equal>(op1, __root_))
9715 {
9716 *type = 2;
9717 first = t2;
9718 }
9719 }
9720 }
9721 }
9722 else
9723 {
9724 if (__make<__operator_plus_equal>())
9725 first += 2;
9726 }
9727 break;
9728 case 'p':
9729 // ++ (postfix in <expression> context)
9730 if (type)
9731 {
9732 const char* t = __parse_expression(first+2, last);
9733 if (t != first+2)
9734 {
9735 if (__make<__operator_increment>(false, __root_))
9736 {
9737 *type = 1;
9738 first = t;
9739 }
9740 }
9741 }
9742 else
9743 {
9744 if (__make<__operator_increment>())
9745 first += 2;
9746 }
9747 break;
9748 case 's':
9749 // + (unary)
9750 if (type)
9751 {
9752 const char* t = __parse_expression(first+2, last);
9753 if (t != first+2)
9754 {
9755 if (__make<__operator_unary_plus>(__root_))
9756 {
9757 *type = 1;
9758 first = t;
9759 }
9760 }
9761 }
9762 else
9763 {
9764 if (__make<__operator_unary_plus>())
9765 first += 2;
9766 }
9767 break;
9768 case 't':
9769 // ->
9770 if (type)
9771 {
9772 const char* t = __parse_expression(first+2, last);
9773 if (t != first+2)
9774 {
9775 __node* op1 = __root_;
9776 const char* t2 = __parse_expression(t, last);
9777 if (t != t2)
9778 {
9779 if (__make<__operator_arrow>(op1, __root_))
9780 {
9781 *type = 2;
9782 first = t2;
9783 }
9784 }
9785 }
9786 }
9787 else
9788 {
9789 if (__make<__operator_arrow>())
9790 first += 2;
9791 }
9792 break;
9793 }
9794 break;
9795 case 'q':
9796 // ?
9797 if (first[1] == 'u')
9798 {
9799 if (type)
9800 {
9801 const char* t = __parse_expression(first+2, last);
9802 if (t != first+2)
9803 {
9804 __node* op1 = __root_;
9805 const char* t2 = __parse_expression(t, last);
9806 if (t != t2)
9807 {
9808 __node* op2 = __root_;
9809 const char* t3 = __parse_expression(t2, last);
9810 if (t3 != t2)
9811 {
9812 if (__make<__operator_conditional>(op1, op2, __root_))
9813 {
9814 *type = 3;
9815 first = t3;
9816 }
9817 }
9818 }
9819 }
9820 }
9821 else
9822 {
9823 if (__make<__operator_conditional>())
9824 first += 2;
9825 }
9826 }
9827 break;
9828 case 'r':
9829 switch (first[1])
9830 {
9831 case 'm':
9832 // %
9833 if (type)
9834 {
9835 const char* t = __parse_expression(first+2, last);
9836 if (t != first+2)
9837 {
9838 __node* op1 = __root_;
9839 const char* t2 = __parse_expression(t, last);
9840 if (t != t2)
9841 {
9842 if (__make<__operator_mod>(op1, __root_))
9843 {
9844 *type = 2;
9845 first = t2;
9846 }
9847 }
9848 }
9849 }
9850 else
9851 {
9852 if (__make<__operator_mod>())
9853 first += 2;
9854 }
9855 break;
9856 case 'M':
9857 // %=
9858 if (type)
9859 {
9860 const char* t = __parse_expression(first+2, last);
9861 if (t != first+2)
9862 {
9863 __node* op1 = __root_;
9864 const char* t2 = __parse_expression(t, last);
9865 if (t != t2)
9866 {
9867 if (__make<__operator_mod_equal>(op1, __root_))
9868 {
9869 *type = 2;
9870 first = t2;
9871 }
9872 }
9873 }
9874 }
9875 else
9876 {
9877 if (__make<__operator_mod_equal>())
9878 first += 2;
9879 }
9880 break;
9881 case 's':
9882 // >>
9883 if (type)
9884 {
9885 const char* t = __parse_expression(first+2, last);
9886 if (t != first+2)
9887 {
9888 __node* op1 = __root_;
9889 const char* t2 = __parse_expression(t, last);
9890 if (t != t2)
9891 {
9892 if (__make<__operator_right_shift>(op1, __root_))
9893 {
9894 *type = 2;
9895 first = t2;
9896 }
9897 }
9898 }
9899 }
9900 else
9901 {
9902 if (__make<__operator_right_shift>())
9903 first += 2;
9904 }
9905 break;
9906 case 'S':
9907 // >>=
9908 if (type)
9909 {
9910 const char* t = __parse_expression(first+2, last);
9911 if (t != first+2)
9912 {
9913 __node* op1 = __root_;
9914 const char* t2 = __parse_expression(t, last);
9915 if (t != t2)
9916 {
9917 if (__make<__operator_right_shift_equal>(op1, __root_))
9918 {
9919 *type = 2;
9920 first = t2;
9921 }
9922 }
9923 }
9924 }
9925 else
9926 {
9927 if (__make<__operator_right_shift_equal>())
9928 first += 2;
9929 }
9930 break;
9931 }
9932 break;
9933 case 's':
9934 switch (first[1])
9935 {
9936 case 't':
9937 // sizeof (a type)
9938 if (type)
9939 {
9940 const char* t = __parse_expression(first+2, last);
9941 if (t != first+2)
9942 {
9943 if (__make<__operator_sizeof_type>(__root_))
9944 {
9945 *type = -1;
9946 first = t;
9947 }
9948 }
9949 }
9950 else
9951 {
9952 if (__make<__operator_sizeof_type>())
9953 first += 2;
9954 }
9955 break;
9956 case 'z':
9957 // sizeof (an expression)
9958 if (type)
9959 {
9960 const char* t = __parse_expression(first+2, last);
9961 if (t != first+2)
9962 {
9963 if (__make<__operator_sizeof_expression>(__root_))
9964 {
9965 *type = -1;
9966 first = t;
9967 }
9968 }
9969 }
9970 else
9971 {
9972 if (__make<__operator_sizeof_expression>())
9973 first += 2;
9974 }
9975 break;
9976 }
9977 break;
9978 }
9979 }
9980 return first;
9981}
9982
9983// <source-name> ::= <positive length number> <identifier>
9984
9985const char*
9986__demangle_tree::__parse_source_name(const char* first, const char* last)
9987{
9988 if (first != last)
9989 {
9990 char c = *first;
9991 if ('1' <= c && c <= '9' && first+1 != last)
9992 {
9993 const char* t = first+1;
9994 size_t n = c - '0';
9995 for (c = *t; '0' <= c && c <= '9'; c = *t)
9996 {
9997 n = n * 10 + c - '0';
9998 if (++t == last)
9999 return first;
10000 }
10001 if (last - t >= n && __make<__source_name>(t, n))
10002 first = t + n;
10003 }
10004 }
10005 return first;
10006}
10007
10008// <unqualified-name> ::= <operator-name>
10009// ::= <ctor-dtor-name>
10010// ::= <source-name>
10011// ::= <unnamed-type-name>
10012
10013const char*
10014__demangle_tree::__parse_unqualified_name(const char* first, const char* last)
10015{
10016 const char* t = __parse_source_name(first, last);
10017 if (t == first)
10018 {
10019 t = __parse_ctor_dtor_name(first, last);
10020 if (t == first)
10021 {
10022 t = __parse_operator_name(first, last);
10023 if (t == first)
10024 first = __parse_unnamed_type_name(first, last);
10025 else
10026 first = t;
10027 }
10028 else
10029 first = t;
10030 }
10031 else
10032 first = t;
10033 return first;
10034}
10035
10036// <unscoped-name> ::= <unqualified-name>
10037// ::= St <unqualified-name> # ::std::
10038// extension ::= StL<unqualified-name>
10039
10040const char*
10041__demangle_tree::__parse_unscoped_name(const char* first, const char* last)
10042{
10043 if (last - first >= 2)
10044 {
10045 const char* t0 = first;
10046 if (first[0] == 'S' && first[1] == 't')
10047 {
10048 t0 += 2;
10049 if (t0 != last && *t0 == 'L')
10050 ++t0;
10051 }
10052 const char* t1 = __parse_unqualified_name(t0, last);
10053 if (t1 != t0)
10054 {
10055 if (t0 != first)
10056 {
10057 __node* name = __root_;
10058 if (__make<__std_qualified_name>())
10059 {
10060 if (__make<__nested_delimeter>(__root_, name))
10061 first = t1;
10062 }
10063 }
10064 else
10065 first = t1;
10066 }
10067 }
10068 return first;
10069}
10070
10071// <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
10072// ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
10073//
10074// <prefix> ::= <prefix> <unqualified-name>
10075// ::= <template-prefix> <template-args>
10076// ::= <template-param>
10077// ::= <decltype>
10078// ::= # empty
10079// ::= <substitution>
10080// ::= <prefix> <data-member-prefix>
10081// extension ::= L
10082//
10083// <template-prefix> ::= <prefix> <template unqualified-name>
10084// ::= <template-param>
10085// ::= <substitution>
10086
10087const char*
10088__demangle_tree::__parse_nested_name(const char* first, const char* last)
10089{
10090 if (first != last && *first == 'N')
10091 {
10092 unsigned cv = 0;
10093 const char* t0 = __parse_cv_qualifiers(first+1, last, cv, true);
10094 __node* prev = NULL;
10095 if (last - t0 >= 2 && t0[0] == 'S' && t0[1] == 't')
10096 {
10097 t0 += 2;
10098 if (!__make<__std_qualified_name>())
10099 return first;
10100 prev = __root_;
10101 }
10102 while (t0 != last)
10103 {
10104 bool can_sub = true;
10105 bool make_nested = true;
10106 const char* t1;
10107 switch (*t0)
10108 {
10109 case '1':
10110 case '2':
10111 case '3':
10112 case '4':
10113 case '5':
10114 case '6':
10115 case '7':
10116 case '8':
10117 case '9':
10118 t1 = __parse_source_name(t0, last);
10119 if (t1 == t0 || t1 == last)
10120 return first;
10121 if (*t1 == 'M')
10122 {
10123 // This is a data-member-prefix
10124 ++t1;
10125 }
10126 else if (*t1 == 'I')
10127 {
10128 // has following <template-args>
10129 if (prev)
10130 {
10131 if (!__make<__nested_delimeter>(prev, __root_))
10132 return first;
10133 make_nested = false;
10134 }
10135 if (__sub_end_ == __sub_cap_)
10136 {
10137 __status_ = memory_alloc_failure;
10138 return first;
10139 }
10140 else
10141 *__sub_end_++ = __root_;
10142 const char* t2 = __parse_template_args(t1, last);
10143 if (t2 == t1)
10144 return first;
10145 t1 = t2;
10146 }
10147 break;
10148 case 'D':
10149 if (t0+1 != last && (t0[1] == 't' || t0[1] == 'T'))
10150 {
10151 t1 = __parse_decltype(t0, last);
10152 break;
10153 }
10154 // check for Dt, DT here, else drop through
10155 case 'C':
10156 t1 = __parse_ctor_dtor_name(t0, last);
10157 if (t1 == t0 || t1 == last)
10158 return first;
10159 if (*t1 == 'I')
10160 {
10161 // has following <template-args>
10162 if (prev)
10163 {
10164 if (!__make<__nested_delimeter>(prev, __root_))
10165 return first;
10166 make_nested = false;
10167 }
10168 if (__sub_end_ == __sub_cap_)
10169 {
10170 __status_ = memory_alloc_failure;
10171 return first;
10172 }
10173 else
10174 *__sub_end_++ = __root_;
10175 const char* t2 = __parse_template_args(t1, last);
10176 if (t2 == t1)
10177 return first;
10178 t1 = t2;
10179 }
10180 break;
10181 case 'U':
10182 assert(!"__parse_nested_name U");
10183 // could have following <template-args>
10184 break;
10185 case 'T':
10186 t1 = __parse_template_param(t0, last);
10187 if (t1 == t0 || t1 == last)
10188 return first;
10189 if (*t1 == 'I')
10190 {
10191 // has following <template-args>
10192 if (prev)
10193 {
10194 if (!__make<__nested_delimeter>(prev, __root_))
10195 return first;
10196 make_nested = false;
10197 }
10198 if (__sub_end_ == __sub_cap_)
10199 {
10200 __status_ = memory_alloc_failure;
10201 return first;
10202 }
10203 else
10204 *__sub_end_++ = __root_;
10205 const char* t2 = __parse_template_args(t1, last);
10206 if (t2 == t1)
10207 return first;
10208 t1 = t2;
10209 }
10210 break;
10211 case 'S':
10212 t1 = __parse_substitution(t0, last);
10213 if (t1 == t0 || t1 == last)
10214 return first;
10215 if (*t1 == 'I')
10216 {
10217 const char* t2 = __parse_template_args(t1, last);
10218 if (t2 == t1)
10219 return first;
10220 t1 = t2;
10221 }
10222 else
10223 can_sub = false;
10224 break;
10225 case 'L':
10226 // extension: ignore L here
10227 ++t0;
10228 continue;
10229 default:
10230 t1 = __parse_operator_name(t0, last);
10231 if (t1 == t0 || t1 == last)
10232 return first;
10233 if (*t1 == 'I')
10234 {
10235 // has following <template-args>
10236 if (prev)
10237 {
10238 if (!__make<__nested_delimeter>(prev, __root_))
10239 return first;
10240 make_nested = false;
10241 }
10242 if (__sub_end_ == __sub_cap_)
10243 {
10244 __status_ = memory_alloc_failure;
10245 return first;
10246 }
10247 else
10248 *__sub_end_++ = __root_;
10249 const char* t2 = __parse_template_args(t1, last);
10250 if (t2 == t1)
10251 return first;
10252 t1 = t2;
10253 }
10254 break;
10255 }
10256 if (t1 == t0 || t1 == last)
10257 return first;
10258 if (prev && make_nested)
10259 {
10260 if (!__make<__nested_delimeter>(prev, __root_))
10261 return first;
10262 can_sub = true;
10263 }
10264 if (can_sub && *t1 != 'E')
10265 {
10266 if (__sub_end_ == __sub_cap_)
10267 {
10268 __status_ = memory_alloc_failure;
10269 return first;
10270 }
10271 else
10272 *__sub_end_++ = __root_;
10273 }
10274 if (*t1 == 'E')
10275 {
10276 if (cv != 0)
10277 {
10278 if (!__make<__cv_qualifiers>(cv, __root_))
10279 return first;
10280 }
10281 first = t1+1;
10282 break;
10283 }
10284 prev = __root_;
10285 t0 = t1;
10286 }
10287 }
10288 return first;
10289}
10290
10291// <template-arg> ::= <type> # type or template
10292// ::= X <expression> E # expression
10293// ::= <expr-primary> # simple expressions
10294// ::= J <template-arg>* E # argument pack
10295// ::= LZ <encoding> E # extension
10296
10297const char*
10298__demangle_tree::__parse_template_arg(const char* first, const char* last)
10299{
10300 if (first != last)
10301 {
10302 const char* t;
10303 switch (*first)
10304 {
10305 case 'X':
10306 t = __parse_expression(first+1, last);
10307 if (t != first+1)
10308 {
10309 if (t != last && *t == 'E')
10310 first = t+1;
10311 }
10312 break;
10313 case 'J':
10314 t = first+1;
10315 if (t == last)
10316 return first;
10317 if (*t == 'E')
10318 {
10319 if (__make<__list>((__node*)0))
10320 first = t+1;
10321 }
10322 else
10323 {
10324 __node* list = NULL;
10325 __node* prev = NULL;
10326 do
10327 {
10328 const char* t2 = __parse_template_arg(t, last);
10329 if (t2 == t || !__make<__list>(__root_))
10330 return first;
10331 if (list == 0)
10332 list = __root_;
10333 if (prev)
10334 {
10335 prev->__right_ = __root_;
10336 __root_->__size_ = prev->__size_ + 1;
10337 }
10338 prev = __root_;
10339 t = t2;
10340 } while (t != last && *t != 'E');
10341 first = t+1;
10342 __root_ = list;
10343 }
10344 break;
10345 case 'L':
10346 // <expr-primary> or LZ <encoding> E
10347 if (first+1 != last && first[1] == 'Z')
10348 {
10349 t = __parse_encoding(first+2, last);
10350 if (t != first+2 && t != last && *t == 'E')
10351 first = t+1;
10352 }
10353 else
10354 first = __parse_expr_primary(first, last);
10355 break;
10356 default:
10357 // <type>
10358 first = __parse_type(first, last);
10359 break;
10360 }
10361 }
10362 return first;
10363}
10364
10365// <template-args> ::= I <template-arg>* E
10366// extension, the abi says <template-arg>+
10367
10368const char*
10369__demangle_tree::__parse_template_args(const char* first, const char* last)
10370{
10371 if (last - first >= 2 && *first == 'I')
10372 {
10373 __node* args = NULL;
10374 __node* prev = NULL;
10375 __node* name = __root_;
Howard Hinnantab87dcf2011-12-15 20:02:15 +000010376 if (__tag_templates_)
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010377 __t_end_ = __t_begin_;
10378 const char* t = first+1;
10379 while (*t != 'E')
10380 {
Howard Hinnantab87dcf2011-12-15 20:02:15 +000010381 bool prev_tag_templates = __tag_templates_;
10382 __node** prev_t_begin = __t_begin_;
10383 __node** prev_t_end = __t_end_;
10384 if (__tag_templates_)
10385 __t_begin_ = __t_end_;
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010386 const char* t2 = __parse_template_arg(t, last);
Howard Hinnantab87dcf2011-12-15 20:02:15 +000010387 if (prev_tag_templates)
10388 {
10389 __tag_templates_ = prev_tag_templates;
10390 __t_begin_ = prev_t_begin;
10391 __t_end_ = prev_t_end;
10392 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010393 if (t2 == t || t2 == last)
10394 break;
10395 if (!__make<__list>(__root_))
10396 return first;
10397 if (args == 0)
10398 args = __root_;
10399 if (prev)
10400 {
10401 prev->__right_ = __root_;
10402 __root_->__size_ = prev->__size_ + 1;
10403 }
10404 prev = __root_;
Howard Hinnantab87dcf2011-12-15 20:02:15 +000010405 if (__tag_templates_)
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010406 {
10407 if (__t_end_ == __t_cap_)
10408 {
10409 __status_ = memory_alloc_failure;
10410 return first;
10411 }
10412 if (__root_->__left_)
10413 *__t_end_++ = __root_->__left_;
10414 else
10415 *__t_end_++ = __root_;
10416 }
10417 t = t2;
10418 }
10419 if (t != last && *t == 'E')
10420 {
10421 if (__make<__template_args>(name, args))
10422 first = t+1;
10423 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010424 }
10425 return first;
10426}
10427
10428// <substitution> ::= S <seq-id> _
10429// ::= S_
10430// <substitution> ::= Sa # ::std::allocator
10431// <substitution> ::= Sb # ::std::basic_string
10432// <substitution> ::= Ss # ::std::basic_string < char,
10433// ::std::char_traits<char>,
10434// ::std::allocator<char> >
10435// <substitution> ::= Si # ::std::basic_istream<char, std::char_traits<char> >
10436// <substitution> ::= So # ::std::basic_ostream<char, std::char_traits<char> >
10437// <substitution> ::= Sd # ::std::basic_iostream<char, std::char_traits<char> >
10438
10439const char*
10440__demangle_tree::__parse_substitution(const char* first, const char* last)
10441{
10442 if (last - first >= 2)
10443 {
10444 if (*first == 'S')
10445 {
10446 switch (first[1])
10447 {
10448 case 'a':
10449 if (__make<__sub_allocator>())
10450 first += 2;
10451 break;
10452 case 'b':
10453 if (__make<__sub_basic_string>())
10454 first += 2;
10455 break;
10456 case 's':
10457 if (__make<__sub_string>())
10458 first += 2;
10459 break;
10460 case 'i':
10461 if (__make<__sub_istream>())
10462 first += 2;
10463 break;
10464 case 'o':
10465 if (__make<__sub_ostream>())
10466 first += 2;
10467 break;
10468 case 'd':
10469 if (__make<__sub_iostream>())
10470 first += 2;
10471 break;
10472 case '_':
10473 if (__sub_begin_ != __sub_end_)
10474 {
10475 if (__make<__sub>(*__sub_begin_))
10476 first += 2;
10477 }
10478 break;
10479 default:
10480 if (isdigit(first[1]) || isupper(first[1]))
10481 {
10482 size_t sub = 0;
10483 const char* t = first+1;
10484 if (isdigit(*t))
10485 sub = *t - '0';
10486 else
10487 sub = *t - 'A' + 10;
10488 for (++t; t != last && (isdigit(*t) || isupper(*t)); ++t)
10489 {
10490 sub *= 36;
10491 if (isdigit(*t))
10492 sub += *t - '0';
10493 else
10494 sub += *t - 'A' + 10;
10495 }
10496 if (t == last || *t != '_')
10497 return first;
10498 ++sub;
10499 if (sub < __sub_end_ - __sub_begin_)
10500 {
10501 if (__make<__sub>(__sub_begin_[sub]))
10502 first = t+1;
10503 }
10504 }
10505 break;
10506 }
10507 }
10508 }
10509 return first;
10510}
10511
10512// <name> ::= <nested-name>
10513// ::= <local-name> # See Scope Encoding below
10514// ::= <unscoped-template-name> <template-args>
10515// ::= <unscoped-name>
10516
10517const char*
10518__demangle_tree::__parse_name(const char* first, const char* last)
10519{
10520 if (first != last)
10521 {
10522 const char* t0 = first;
10523 // extension: ignore L here
10524 if (*t0 == 'L')
10525 ++t0;
10526 const char* t = __parse_nested_name(t0, last);
10527 if (t == t0)
10528 {
10529 t = __parse_local_name(t0, last);
10530 if (t == t0)
10531 {
10532 // not <nested-name> nor <local-name>
10533 // Try to parse <unscoped-template-name> <template-args> or
10534 // <unscoped-name> which are nearly ambiguous.
10535 // This logic occurs nowhere else.
10536 if (last - t0 >= 2)
10537 {
10538 if (t0[0] == 'S' && (t0[1] == '_' ||
10539 isdigit(t0[1]) ||
10540 isupper(t0[1]) ||
10541 t0[1] == 'a' ||
10542 t0[1] == 'b'))
10543 {
10544 t = __parse_substitution(t0, last);
10545 if (t != t0)
10546 {
10547 const char* t2 = __parse_template_args(t, last);
10548 if (t2 != t)
10549 first = t2;
10550 }
10551 }
10552 else // Not a substitution, except maybe St
10553 {
10554 t = __parse_unscoped_name(t0, last);
10555 if (t != t0)
10556 {
10557 // unscoped-name might be <unscoped-template-name>
10558 if (t != last && *t == 'I')
10559 {
10560 if (__sub_end_ == __sub_cap_)
10561 {
10562 __status_ = memory_alloc_failure;
10563 return first;
10564 }
10565 *__sub_end_++ = __root_;
10566 const char* t2 = __parse_template_args(t, last);
10567 if (t2 != t)
10568 first = t2;
10569 }
10570 else
10571 {
10572 // <unscoped-name>
10573 first = t;
10574 }
10575 }
10576 }
10577 }
10578 }
10579 else
10580 first = t;
10581 }
10582 else
10583 first = t;
10584 }
10585 return first;
10586}
10587
10588// extension
10589// <dot-suffix> := .<anything and everything>
10590
10591const char*
10592__demangle_tree::__parse_dot_suffix(const char* first, const char* last)
10593{
10594 if (first != last && *first == '.')
10595 {
10596 if (__make<__dot_suffix>(__root_, first, last-first))
10597 first = last;
10598 }
10599 return first;
10600}
10601
10602// <encoding> ::= <function name> <bare-function-type>
10603// ::= <data name>
10604// ::= <special-name>
10605
10606const char*
10607__demangle_tree::__parse_encoding(const char* first, const char* last)
10608{
10609 const char* t = __parse_name(first, last);
10610 if (t != first)
10611 {
Howard Hinnant889b02d2011-06-22 19:27:39 +000010612 if (t != last && *t != 'E' && *t != '.')
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010613 {
10614 __node* name = __root_;
Howard Hinnantab87dcf2011-12-15 20:02:15 +000010615 bool has_return = name->ends_with_template(true) &&
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010616 !name->is_ctor_dtor_conv();
10617 __node* ret = NULL;
10618 const char* t2;
10619 __tag_templates_ = false;
10620 if (has_return)
10621 {
10622 t2 = __parse_type(t, last);
10623 if (t2 != t)
10624 {
10625 ret = __root_;
10626 t = t2;
10627 }
10628 else
10629 return first;
10630 }
10631 t2 = __parse_bare_function_type(t, last);
10632 if (t2 != t)
10633 {
10634 if (dynamic_cast<__void*>(__root_->__left_) != NULL)
10635 __root_->__left_ = NULL;
10636 if (__make<__function_signature>(ret, __root_))
10637 {
10638 __node* cv = name->extract_cv(name);
10639 if (__make<__function>(name, __root_))
10640 {
10641 if (cv)
10642 {
10643 cv->__left_ = __root_;
10644 cv->__size_ <<= 5;
10645 __root_ = cv;
10646 }
10647 first = t2;
10648 }
10649 }
10650 }
10651 __tag_templates_ = true;
10652 }
10653 else
10654 first = t;
10655 }
10656 else
10657 first = __parse_special_name(first, last);
10658 return first;
10659}
10660
10661// <mangled-name> ::= _Z<encoding>
10662// ::= <type>
10663
10664void
10665__demangle_tree::__parse()
10666{
10667 if (__mangled_name_begin_ == __mangled_name_end_)
10668 {
10669 __status_ = invalid_mangled_name;
10670 return;
10671 }
10672 const char* t = NULL;
10673 if (__mangled_name_end_ - __mangled_name_begin_ >= 2 &&
10674 __mangled_name_begin_[0] == '_' &&
10675 __mangled_name_begin_[1] == 'Z')
10676 {
10677 t = __parse_encoding(__mangled_name_begin_+2, __mangled_name_end_);
10678 if (t != __mangled_name_begin_+2 && t != __mangled_name_end_ && *t == '.')
10679 t = __parse_dot_suffix(t, __mangled_name_end_);
10680 }
10681 else
10682 t = __parse_type(__mangled_name_begin_, __mangled_name_end_);
10683 if (t == __mangled_name_end_ && __root_)
10684 {
10685 if (__fix_forward_references_)
10686 {
10687 if (__root_->fix_forward_references(__t_begin_, __t_end_))
10688 __status_ = success;
10689 }
10690 else
10691 __status_ = success;
10692 }
10693}
10694
10695#pragma GCC visibility pop
10696#pragma GCC visibility push(default)
10697
10698__demangle_tree
10699__demangle(const char* mangled_name, char* buf, size_t bs)
10700{
10701 __demangle_tree t(mangled_name, buf, bs);
10702 if (t.__status() == invalid_mangled_name)
10703 t.__parse();
10704 return t;
10705}
10706
10707__demangle_tree
10708__demangle(const char* mangled_name)
10709{
10710 return __demangle(mangled_name, 0, 0);
10711}
10712
10713char*
10714__demangle(__demangle_tree dmg_tree, char* buf, size_t* n, int* status)
10715{
10716 if (dmg_tree.__status() != success)
10717 {
10718 if (status)
10719 *status = dmg_tree.__status();
10720 return NULL;
10721 }
10722#ifdef DEBUGGING
10723display(dmg_tree.__root_);
10724printf("\n");
10725#endif
10726 const size_t bs = buf == NULL ? 0 : *n;
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010727 ptrdiff_t sm = dmg_tree.__mangled_name_end_ - dmg_tree.__mangled_name_begin_;
Howard Hinnantf2888962011-12-01 00:08:59 +000010728 ptrdiff_t est = sm + 60 * (
10729 (dmg_tree.__node_end_ - dmg_tree.__node_begin_) +
10730 (dmg_tree.__sub_end_ - dmg_tree.__sub_begin_) +
10731 (dmg_tree.__t_end_ - dmg_tree.__t_begin_));
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010732 const unsigned N = 4096;
10733 char tmp[N];
10734 ptrdiff_t s;
10735 if (est <= bs)
10736 {
10737 char* e = dmg_tree.__get_demangled_name(buf);
10738 *e++ = '\0';
10739 s = e - buf;
10740 }
10741 else if (est <= N)
10742 {
10743 char* e = dmg_tree.__get_demangled_name(tmp);
10744 *e++ = '\0';
10745 s = e - tmp;
10746 }
10747 else
10748 s = dmg_tree.size() + 1;
10749 if (s > bs)
10750 {
10751 buf = static_cast<char*>(realloc(buf, s));
10752 if (buf == NULL)
10753 {
10754 if (status)
10755 *status = memory_alloc_failure;
10756 return NULL;
10757 }
10758 if (n)
10759 *n = s;
10760 }
10761 if (est > bs)
10762 {
10763 if (est <= N)
10764 strncpy(buf, tmp, s);
10765 else
10766 *dmg_tree.__get_demangled_name(buf) = '\0';
10767 }
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010768 if (status)
10769 *status = success;
10770 return buf;
10771}
10772
10773} // __libcxxabi
10774
10775extern "C"
10776{
10777
10778char*
10779__cxa_demangle(const char* mangled_name, char* buf, size_t* n, int* status)
10780{
10781 if (mangled_name == NULL || (buf != NULL && n == NULL))
10782 {
10783 if (status)
10784 *status = __libcxxabi::invalid_args;
10785 return NULL;
10786 }
10787 const size_t bs = 64 * 1024;
Howard Hinnant8ffc8452011-11-28 21:03:21 +000010788 __attribute((aligned(16))) char static_buf[bs];
Howard Hinnantd213ffd2011-05-05 15:27:28 +000010789
10790 buf = __libcxxabi::__demangle(__libcxxabi::__demangle(mangled_name,
10791 static_buf, bs),
10792 buf, n, status);
10793 return buf;
10794}
10795
10796} // extern "C"
10797
10798} // abi