| 699 | | { |
|---|
| 700 | | "minimal", /* Language name */ |
|---|
| 701 | | language_minimal, |
|---|
| | 699 | { |
|---|
| | 700 | "minimal", /* Language name */ |
|---|
| | 701 | language_minimal, |
|---|
| | 702 | NULL, |
|---|
| | 703 | range_check_off, |
|---|
| | 704 | type_check_off, |
|---|
| | 705 | case_sensitive_on, |
|---|
| | 706 | array_row_major, |
|---|
| | 707 | &exp_descriptor_standard, |
|---|
| | 708 | c_preprocess_and_parse, |
|---|
| | 709 | c_error, |
|---|
| | 710 | null_post_parser, |
|---|
| | 711 | c_printchar, /* Print a character constant */ |
|---|
| | 712 | c_printstr, /* Function to print string constant */ |
|---|
| | 713 | c_emit_char, /* Print a single char */ |
|---|
| | 714 | c_create_fundamental_type, /* Create fundamental type in this language */ |
|---|
| | 715 | c_print_type, /* Print a type using appropriate syntax */ |
|---|
| | 716 | c_val_print, /* Print a value using appropriate syntax */ |
|---|
| | 717 | c_value_print, /* Print a top-level value */ |
|---|
| | 718 | NULL, /* Language specific skip_trampoline */ |
|---|
| | 719 | NULL, /* value_of_this */ |
|---|
| | 720 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
|---|
| | 721 | basic_lookup_transparent_type,/* lookup_transparent_type */ |
|---|
| | 722 | NULL, /* Language specific symbol demangler */ |
|---|
| | 723 | NULL, /* Language specific class_name_from_physname */ |
|---|
| | 724 | c_op_print_tab, /* expression operators for printing */ |
|---|
| | 725 | 1, /* c-style arrays */ |
|---|
| | 726 | 0, /* String lower bound */ |
|---|
| | 727 | NULL, |
|---|
| | 728 | default_word_break_characters, |
|---|
| | 729 | c_language_arch_info, |
|---|
| | 730 | LANG_MAGIC |
|---|
| | 731 | }; |
|---|
| | 732 | |
|---|
| | 733 | |
|---|
| | 734 | /***************************** |
|---|
| | 735 | D Language stuff |
|---|
| | 736 | ******************************/ |
|---|
| | 737 | #include <string.h> |
|---|
| | 738 | #include <ctype.h> |
|---|
| | 739 | |
|---|
| | 740 | static int extractidentifiers(char** output, char** mangled) { |
|---|
| | 741 | int i = -1; |
|---|
| | 742 | while (isdigit(**mangled)) { |
|---|
| | 743 | i = strtol(*mangled, mangled, 10); |
|---|
| | 744 | if (strlen(*mangled) < i) |
|---|
| | 745 | return -1; |
|---|
| | 746 | memcpy(*output, *mangled, i); |
|---|
| | 747 | *mangled += i; |
|---|
| | 748 | *output += i + 1; |
|---|
| | 749 | (*output)[-1] = '.'; |
|---|
| | 750 | } |
|---|
| | 751 | if (**mangled == '\0' || i == -1) |
|---|
| | 752 | return -1; |
|---|
| | 753 | (*output)--; |
|---|
| | 754 | return 1; |
|---|
| | 755 | } |
|---|
| | 756 | |
|---|
| | 757 | static void append(char** dest, char* src) { |
|---|
| | 758 | int i = strlen(src); |
|---|
| | 759 | for(;i>0; i--) { |
|---|
| | 760 | *(*dest)++ = *src++; |
|---|
| | 761 | } |
|---|
| | 762 | } |
|---|
| | 763 | |
|---|
| | 764 | static int extracttypeinfo(char** dest, char** id) { |
|---|
| | 765 | if (**id == '\0') |
|---|
| | 766 | return -1; |
|---|
| | 767 | // Extract the type info: |
|---|
| | 768 | switch (*(*id)++) { |
|---|
| | 769 | // array, static array, dynamic array: |
|---|
| | 770 | case 'A': case 'G': case 'H': |
|---|
| | 771 | if (extracttypeinfo(dest, id) == -1) |
|---|
| | 772 | return -1; |
|---|
| | 773 | append(dest, "[]"); |
|---|
| | 774 | return 1; |
|---|
| | 775 | // pointer: |
|---|
| | 776 | case 'P': |
|---|
| | 777 | if (extracttypeinfo(dest, id) == -1) |
|---|
| | 778 | return -1; |
|---|
| | 779 | append(dest, "*"); |
|---|
| | 780 | return 1; |
|---|
| | 781 | // reference: |
|---|
| | 782 | case 'R': |
|---|
| | 783 | if (extracttypeinfo(dest, id) == -1) |
|---|
| | 784 | return -1; |
|---|
| | 785 | append(dest, "&"); |
|---|
| | 786 | return 1; |
|---|
| | 787 | // return value: |
|---|
| | 788 | case 'Z': |
|---|
| | 789 | return extracttypeinfo(dest, id); |
|---|
| | 790 | // out: |
|---|
| | 791 | case 'J': |
|---|
| | 792 | append(dest, "out "); |
|---|
| | 793 | return extracttypeinfo(dest, id); |
|---|
| | 794 | // inout: |
|---|
| | 795 | case 'K': |
|---|
| | 796 | append(dest, "inout "); |
|---|
| | 797 | return extracttypeinfo(dest, id); |
|---|
| | 798 | |
|---|
| | 799 | // enum: |
|---|
| | 800 | case 'E': case 'T': case 'D': case 'C': case 'S': case 'I': |
|---|
| | 801 | return extractidentifiers(dest, id); |
|---|
| | 802 | |
|---|
| | 803 | // basic types: |
|---|
| | 804 | case 'n': append(dest, "none"); return 1; // ever used? |
|---|
| | 805 | case 'v': append(dest, "void"); return 1; |
|---|
| | 806 | case 'g': append(dest, "byte"); return 1; |
|---|
| | 807 | case 'h': append(dest, "ubyte"); return 1; |
|---|
| | 808 | case 's': append(dest, "short"); return 1; |
|---|
| | 809 | case 't': append(dest, "ushort"); return 1; |
|---|
| | 810 | case 'i': append(dest, "int"); return 1; |
|---|
| | 811 | case 'k': append(dest, "uint"); return 1; |
|---|
| | 812 | case 'l': append(dest, "long"); return 1; |
|---|
| | 813 | case 'm': append(dest, "ulong"); return 1; |
|---|
| | 814 | case 'f': append(dest, "float"); return 1; |
|---|
| | 815 | case 'd': append(dest, "double"); return 1; |
|---|
| | 816 | case 'e': append(dest, "real"); return 1; |
|---|
| | 817 | |
|---|
| | 818 | // imaginary and complex: |
|---|
| | 819 | case 'o': append(dest, "ifloat"); return 1; |
|---|
| | 820 | case 'p': append(dest, "idouble"); return 1; |
|---|
| | 821 | case 'j': append(dest, "ireal"); return 1; |
|---|
| | 822 | case 'q': append(dest, "cfloat"); return 1; |
|---|
| | 823 | case 'r': append(dest, "cdouble"); return 1; |
|---|
| | 824 | case 'c': append(dest, "creal"); return 1; |
|---|
| | 825 | |
|---|
| | 826 | // other types: |
|---|
| | 827 | case 'b': append(dest, "bit"); return 1; |
|---|
| | 828 | case 'a': append(dest, "char"); return 1; |
|---|
| | 829 | case 'u': append(dest, "wchar"); return 1; |
|---|
| | 830 | case 'w': append(dest, "dchar"); return 1; |
|---|
| | 831 | |
|---|
| | 832 | // typeinfo, error, instance: |
|---|
| | 833 | case '@': return extractidentifiers(dest, id); // BUG: is this right? |
|---|
| | 834 | |
|---|
| | 835 | default: append(dest, "unknown"); return 1; |
|---|
| | 836 | } |
|---|
| | 837 | } |
|---|
| | 838 | |
|---|
| | 839 | char* d_demangle(char* mangled, int options) { |
|---|
| | 840 | char *output = malloc(strlen(mangled)+20), *orig = output; |
|---|
| | 841 | unsigned char isFunc = 0; |
|---|
| | 842 | return NULL; |
|---|
| | 843 | if (mangled == strstr(mangled, "_D")) { |
|---|
| | 844 | mangled += 2; |
|---|
| | 845 | isFunc = 1; |
|---|
| | 846 | } else if (mangled == strstr(mangled, "__Class_")) { |
|---|
| | 847 | mangled += 8; |
|---|
| | 848 | } else if (mangled == strstr(mangled, "__init_")) { |
|---|
| | 849 | mangled += 7; |
|---|
| | 850 | } else if (mangled == strstr(mangled, "__vtbl_")) { |
|---|
| | 851 | mangled += 7; |
|---|
| | 852 | } else if (mangled == strstr(mangled, "__modctor_")) { |
|---|
| | 853 | mangled += 10; |
|---|
| | 854 | } else if (mangled == strstr(mangled, "__moddtor_")) { |
|---|
| | 855 | mangled += 10; |
|---|
| | 856 | } else if (mangled == strstr(mangled, "__ModuleInfo_")) { |
|---|
| | 857 | mangled += 13; |
|---|
| | 858 | } else { |
|---|
| | 859 | free(orig); |
|---|
| | 860 | return NULL; |
|---|
| | 861 | } |
|---|
| | 862 | |
|---|
| | 863 | if (extractidentifiers(&output, &mangled) < 0) { |
|---|
| | 864 | free(orig); |
|---|
| | 865 | return NULL; |
|---|
| | 866 | } |
|---|
| | 867 | append(&output, "("); |
|---|
| | 868 | if (isFunc == 1 && *mangled == 'F') { |
|---|
| | 869 | mangled++; |
|---|
| | 870 | while (*mangled != '\0' && *mangled != 'Z') { |
|---|
| | 871 | if (isFunc == 1) { |
|---|
| | 872 | isFunc++; |
|---|
| | 873 | } else { |
|---|
| | 874 | append(&output, ", "); |
|---|
| | 875 | } |
|---|
| | 876 | if (extracttypeinfo(&output, &mangled) < 0) { |
|---|
| | 877 | free(orig); |
|---|
| | 878 | return NULL; |
|---|
| | 879 | } |
|---|
| | 880 | } |
|---|
| | 881 | } |
|---|
| | 882 | append(&output, ")"); |
|---|
| | 883 | |
|---|
| | 884 | //Doesn't display the return type, but wouldn't be too hard to do. |
|---|
| | 885 | |
|---|
| | 886 | *output = '\0'; |
|---|
| | 887 | output = strdup(orig); |
|---|
| | 888 | free(orig); |
|---|
| | 889 | return output; |
|---|
| | 890 | } |
|---|
| | 891 | |
|---|
| | 892 | char* d_sym_demangle(const struct general_symbol_info *gsymbol) { |
|---|
| | 893 | return d_demangle(gsymbol->name, 0); |
|---|
| | 894 | } |
|---|
| | 895 | |
|---|
| | 896 | const struct language_defn d_language_defn = |
|---|
| | 897 | { |
|---|
| | 898 | "d", /* Language name */ |
|---|
| | 899 | language_d, |
|---|