00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 static char *source_file = __FILE__;
00076 #ifdef _KEEP_RCS_ID
00077 static char *rcs_id = "$Source: kg++fe/SCCS/s.wfe_dst.cxx $ $Revision: 1.71 $";
00078 #endif
00079
00080 #include <values.h>
00081
00082 #include "defs.h"
00083 #include "glob.h"
00084 #include "config.h"
00085 #include "dwarf_DST_producer.h"
00086 #include "dwarf_DST_dump.h"
00087 #include "file_util.h"
00088 #include "srcpos.h"
00089 #include "symtab.h"
00090 extern "C" {
00091 #include "gnu_config.h"
00092 }
00093 #ifdef KEY // get HW_WIDE_INT for flags.h
00094 #include "gnu/hwint.h"
00095 #endif
00096 extern "C" {
00097 #include "gnu/flags.h"
00098 #include "gnu/system.h"
00099 #include "gnu/tree.h"
00100 #include "cp-tree.h"
00101 }
00102 #include "wfe_misc.h"
00103 #include "wfe_dst.h"
00104 #include "wfe_expr.h"
00105 #include "tree_symtab.h"
00106
00107 #include <sys/types.h>
00108 #include <sys/stat.h>
00109 #include <sys/param.h>
00110 #include <unistd.h>
00111 #include <string>
00112 #include <vector>
00113 #include <map>
00114 #ifdef KEY
00115 #include "stamp.h"
00116 #include "demangle.h"
00117 extern "C" char *cplus_demangle (const char *, int);
00118 #endif
00119
00120 extern const char *dump_base_name ;
00121
00122 extern FILE *tree_dump_file;
00123
00124 static BOOL dst_initialized = FALSE;
00125
00126 #define MAX_CWD_CHARS (256 - (MAXHOSTNAMELEN+1))
00127 static char cwd_buffer[MAX_CWD_CHARS+MAXHOSTNAMELEN+1];
00128 static char *current_working_dir = &cwd_buffer[0];
00129 static char *current_host_dir = &cwd_buffer[0];
00130
00131
00132
00133
00134
00135 static DST_INFO_IDX comp_unit_idx = DST_INVALID_INIT;
00136
00137 static void DST_enter_file (char *, UINT);
00138
00139 static UINT last_dir_num = 0;
00140 static UINT current_dir = 1;
00141 static UINT last_file_num = 0;
00142 UINT current_file = 1;
00143
00144 static DST_INFO_IDX DST_Create_var(ST *var_st, tree decl);
00145 static DST_INFO_IDX DST_Create_Parmvar(ST *var_st, tree decl);
00146 static DST_INFO_IDX DST_Create_type(ST *typ_decl, tree decl);
00147 static void DST_enter_param_vars(tree fndecl,DST_INFO_IDX parent,tree parameter_list,int is_abstract_root, int is_declaration_only);
00148
00149
00150
00151
00152 static std::vector< std::pair< char *, UINT > > dir_dst_list;
00153 typedef std::map< std::string, DST_INFO_IDX > DST_Type_Map;
00154 static DST_Type_Map basetypes;
00155
00156 #ifdef KEY
00157
00158
00159 static inline BOOL is_typedef (tree type_tree)
00160 {
00161 tree tname = TYPE_NAME (type_tree);
00162 return (tname && TREE_CODE (tname) == TYPE_DECL &&
00163 DECL_ORIGINAL_TYPE (tname));
00164 }
00165 #endif
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 static DST_INFO_IDX
00190 DST_get_context(tree intree)
00191 {
00192 tree ltree = intree;
00193 DST_INFO_IDX l_dst_idx = DST_INVALID_INIT;
00194
00195
00196 while(ltree ) {
00197
00198 switch(TREE_CODE(ltree)) {
00199 case BLOCK:
00200
00201
00202
00203 DevWarn("Unhandled BLOCK scope of decl/var");
00204 return comp_unit_idx;
00205
00206
00207 case FUNCTION_DECL:
00208 l_dst_idx = DECL_DST_IDX(ltree);
00209 if(DST_IS_NULL(l_dst_idx)) {
00210 DevWarn("forward reference to subprogram! assuming global context\n");
00211 return comp_unit_idx;
00212 }
00213 return l_dst_idx;
00214
00215 case RECORD_TYPE:
00216 case UNION_TYPE:
00217 case QUAL_UNION_TYPE:
00218 ltree = TYPE_CONTEXT(ltree);
00219 continue;
00220
00221 case FUNCTION_TYPE:
00222 DevWarn("Unhandled FUNCTION_TYPE scope of decl/var/type");
00223 return comp_unit_idx;
00224 case REFERENCE_TYPE:
00225
00226 return comp_unit_idx;
00227 case NAMESPACE_DECL:
00228
00229 ltree = DECL_CONTEXT(ltree);
00230 continue;
00231 default:
00232 DevWarn("Unhandled scope of tree code %d",
00233 TREE_CODE(ltree));
00234
00235
00236 if(TREE_CODE_CLASS(TREE_CODE(ltree)) == 'd') {
00237 ltree = DECL_CONTEXT(ltree);
00238
00239 continue;
00240 } else if (TREE_CODE_CLASS(TREE_CODE(ltree)) == 't') {
00241 ltree = TYPE_CONTEXT(ltree);
00242
00243 continue;
00244 }
00245
00246
00247
00248 return comp_unit_idx;
00249 }
00250
00251 }
00252
00253 return comp_unit_idx;
00254 }
00255
00256
00257
00258
00259 static UINT
00260 Get_Dir_Dst_Info (char *name)
00261 {
00262 #ifdef TARG_SL
00263
00264 if (name == NULL) return 0;
00265 #endif
00266 std::vector< std::pair < char*, UINT > >::iterator found;
00267
00268 for (found = dir_dst_list.begin();
00269 found != dir_dst_list.end();
00270 ++found)
00271 {
00272 if (strcmp ((*found).first, name) == 0) {
00273 return (*found).second;
00274 }
00275 }
00276
00277 #ifdef KEY
00278
00279
00280 char *new_name = (char *)malloc((strlen(name)+1)*sizeof(char));
00281 strcpy(new_name, name);
00282 name = new_name;
00283 #endif
00284 dir_dst_list.push_back (std::make_pair (name, ++last_dir_num));
00285 DST_mk_include_dir (name);
00286 return last_dir_num;
00287 }
00288
00289 static std::vector< std::pair< char *, UINT > > file_dst_list;
00290
00291
00292
00293 static UINT
00294 Get_File_Dst_Info (char *name, UINT dir)
00295 {
00296 #ifdef KEY
00297 if (name[0] == '\0')
00298 return last_file_num;
00299 #endif
00300 std::vector< std::pair < char*, UINT > >::iterator found;
00301
00302 for (found = file_dst_list.begin();
00303 found != file_dst_list.end();
00304 ++found)
00305 {
00306 if (strcmp ((*found).first, name) == 0) {
00307 return (*found).second;
00308 }
00309 }
00310
00311 #ifdef KEY
00312
00313
00314 char *new_name = (char *)malloc((strlen(name)+1)*sizeof(char));
00315 strcpy(new_name, name);
00316 name = new_name;
00317 #endif
00318 file_dst_list.push_back (std::make_pair (name, ++last_file_num));
00319 DST_enter_file (name, dir);
00320 return last_file_num;
00321 }
00322
00323
00324
00325 static char *
00326 drop_path (char *s)
00327 {
00328 char *tail;
00329 tail = strrchr (s, '/');
00330 if (tail == NULL) {
00331 return s;
00332 } else {
00333 tail++;
00334 return tail;
00335 }
00336 }
00337
00338 static void
00339 DST_enter_file (char *file_name, UINT dir)
00340 {
00341 UINT64 file_size = 0;
00342 UINT64 fmod_time = 0;
00343 struct stat fstat;
00344 if (stat(file_name, &fstat) == 0) {
00345
00346 file_size = (UINT64)fstat.st_size;
00347 fmod_time = (UINT64)fstat.st_mtime;
00348 }
00349 DST_mk_file_name(
00350 file_name,
00351 dir,
00352 file_size,
00353 fmod_time);
00354 }
00355
00356
00357
00358
00359
00360
00361
00362 static char *
00363 DST_get_command_line_options(INT32 num_copts,
00364 char *copts[])
00365 {
00366 INT32 i,
00367 strlength = 0;
00368 INT32 num_opts = 0;
00369 char **selected_opt;
00370 INT32 *opt_size;
00371 char *rtrn, *cp;
00372 char ch;
00373 INT32 record_option;
00374
00375 selected_opt = (char **)malloc(sizeof(char*) * num_copts);
00376 opt_size = (INT32 *)malloc(sizeof(INT32) * num_copts);
00377
00378 for (i = 1; i <= num_copts; i++)
00379 {
00380 if (copts[i] != NULL && copts[i][0] == '-')
00381 {
00382 ch = copts[i][1];
00383 if (Debug_Level <= 0)
00384
00385 record_option = (ch == 'g' ||
00386 ch == 'O');
00387 else
00388
00389 record_option = (ch == 'D' ||
00390 ch == 'g' ||
00391 ch == 'I' ||
00392 ch == 'O' ||
00393 ch == 'U');
00394 if (record_option)
00395 {
00396 opt_size[num_opts] = strlen(copts[i]) + 1;
00397 selected_opt[num_opts] = copts[i];
00398 strlength += opt_size[num_opts];
00399 num_opts += 1;
00400 }
00401 }
00402 }
00403
00404 if (strlength == 0)
00405 {
00406 rtrn = (char *)calloc(1, 1);
00407 }
00408 else
00409 {
00410 rtrn = (char *)malloc(strlength);
00411 cp = rtrn;
00412
00413
00414 for (i = 0; i < num_opts; i++)
00415 if (opt_size[i] > 0)
00416 {
00417 cp = strcpy(cp, selected_opt[i]) + opt_size[i];
00418 cp[-1] = ' ';
00419 }
00420 cp[-1] = '\0';
00421 }
00422
00423 free(selected_opt);
00424 free(opt_size);
00425 return rtrn;
00426 }
00427
00428 static char *
00429 Get_Name (tree node)
00430 {
00431 static char buf[64];
00432
00433
00434 if (node == NULL) {
00435 buf[0] = 0;
00436 return buf;
00437 }
00438 char *name = buf;
00439 buf[0] = 0;
00440
00441 #define DANAME(d) ((TREE_CODE_CLASS(TREE_CODE(d)) =='d')? \
00442 ((DECL_NAME(d))?IDENTIFIER_POINTER(DECL_NAME(d)):"?"):\
00443 "?2")
00444
00445
00446 int tc_class = (int)TREE_CODE_CLASS(TREE_CODE(node));
00447
00448 if (tc_class == 'd')
00449 {
00450 if (DECL_NAME (node)) {
00451 name = IDENTIFIER_POINTER (DECL_NAME (node));
00452 }
00453 }
00454 else if (tc_class == 't')
00455 {
00456 if (TYPE_NAME (node))
00457 {
00458 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
00459 name = IDENTIFIER_POINTER (TYPE_NAME (node));
00460 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
00461 && DECL_NAME (TYPE_NAME (node)))
00462 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
00463
00464 }
00465 } else {
00466 }
00467 return name;
00468 }
00469
00470
00471
00472
00473
00474
00475
00476 static void
00477 DST_enter_static_data_mem(tree parent_tree,
00478 DST_INFO_IDX parent_idx,
00479 TY_IDX parent_ty_idx,
00480 tree field)
00481 {
00482
00483 int isbit = 0;
00484 DST_INFO_IDX field_idx = DST_INVALID_INIT;
00485
00486 char * linkage_name =
00487 IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME (field));
00488 char * mem_name = Get_Name(field);
00489
00490
00491 tree ftype = TREE_TYPE(field);
00492
00493
00494
00495 ST * st = 0;
00496 ST_IDX base = ST_IDX_ZERO;
00497
00498
00499 DST_INFO_IDX fidx = Create_DST_type_For_Tree(ftype,base,parent_ty_idx);
00500
00501 USRCPOS src;
00502
00503
00504
00505
00506 #ifdef KEY
00507 USRCPOS_srcpos(src) = Get_Srcpos();
00508 #else
00509 USRCPOS_clear(src);
00510 #endif // KEY
00511
00512
00513 field_idx = DST_mk_variable(
00514 src,
00515 mem_name,
00516 fidx,
00517 0,
00518 base,
00519 DST_INVALID_IDX,
00520 TRUE,
00521 FALSE,
00522 FALSE,
00523 FALSE );
00524
00525 DECL_DST_FIELD_IDX(field) = field_idx;
00526 #ifdef KEY
00527
00528 if (mem_name != NULL && *mem_name != '\0')
00529 #endif
00530 DST_append_child(parent_idx,field_idx);
00531
00532 DST_INFO_IDX varidx = DECL_DST_IDX(field);
00533 DECL_DST_SPECIFICATION_IDX(field) = field_idx;
00534
00535 #ifdef KEY
00536 if(mem_name && linkage_name && strcmp(mem_name, linkage_name)) {
00537 DST_add_linkage_name_to_variable(field_idx, linkage_name);
00538 }
00539 #else
00540
00541
00542
00543
00544 #endif
00545 DECL_DST_SPECIFICATION_IDX(field) = field_idx;
00546
00547 return ;
00548 }
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560 #ifndef KEY
00561 static void
00562 #else
00563 void
00564 #endif
00565 DST_enter_member_function( tree parent_tree,
00566 DST_INFO_IDX parent_idx,
00567 TY_IDX parent_ty_idx,
00568 tree fndecl)
00569 {
00570 USRCPOS src;
00571 USRCPOS_srcpos(src) = Get_Srcpos();
00572 DST_INFO_IDX dst = DST_INVALID_INIT;
00573 DST_INFO_IDX ret_dst = DST_INVALID_IDX;
00574
00575 DST_INFO_IDX current_scope_idx = parent_idx;
00576
00577
00578
00579 #ifndef KEY
00580 tree resdecl = DECL_RESULT(fndecl);
00581 tree restype = 0;
00582 if( resdecl) {
00583 restype = TREE_TYPE(resdecl);
00584 }
00585 #else
00586
00587
00588 tree restype = 0;
00589 if (TREE_TYPE(fndecl))
00590 restype = TREE_TYPE(TREE_TYPE(fndecl));
00591 #endif
00592 if(restype) {
00593 TY_IDX itx = Get_TY(restype);
00594 ret_dst = TYPE_DST_IDX(restype);
00595 }
00596
00597 BOOL is_prototyped = TRUE;
00598
00599 #ifdef KEY
00600
00601 char *basename = IDENTIFIER_POINTER (DECL_NAME (fndecl));
00602 #else
00603 char * basename =
00604 IDENTIFIER_OPNAME_P(DECL_NAME(fndecl))? 0 :
00605 IDENTIFIER_POINTER (DECL_NAME (fndecl));
00606 #endif
00607 char * linkage_name =
00608 IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME (fndecl));
00609 #ifdef KEY
00610
00611 if (IDENTIFIER_OPNAME_P (DECL_NAME(fndecl)) &&
00612 IDENTIFIER_TYPENAME_P (DECL_NAME(fndecl))) {
00613 basename = cplus_demangle(linkage_name, DMGL_PARAMS | DMGL_ANSI |
00614 DMGL_TYPES);
00615 if (basename) {
00616 basename = strstr(basename, "operator ");
00617 FmtAssert(basename, ("NYI"));
00618 } else {
00619
00620
00621
00622
00623
00624
00625
00626
00627 DevWarn(
00628 "encountered a mangled name that can not be demangled using c++filt");
00629 basename = IDENTIFIER_POINTER (DECL_NAME (fndecl));
00630 }
00631 }
00632 #endif
00633
00634
00635 tree ftype = TREE_TYPE(fndecl);
00636
00637 int is_abstract_root = 0;
00638
00639
00640
00641 TY_IDX base = Get_TY(ftype);
00642
00643
00644 BOOL is_external = TRUE;
00645 DST_virtuality virtuality =
00646 DECL_PURE_VIRTUAL_P(fndecl)?
00647 DW_VIRTUALITY_pure_virtual
00648 : DECL_VIRTUAL_P(fndecl)?
00649 DW_VIRTUALITY_virtual : DW_VIRTUALITY_none;
00650
00651
00652 DST_inline inlin = 0;
00653
00654
00655
00656
00657
00658 DST_vtable_elem_location vtable_elem_location = 0;
00659
00660 dst = DST_mk_subprogram(
00661 src,
00662 basename,
00663 ret_dst,
00664 DST_INVALID_IDX,
00665 0,
00666 inlin,
00667 virtuality,
00668 vtable_elem_location,
00669
00670
00671 TRUE,
00672 is_prototyped,
00673 #ifdef KEY
00674 DECL_ARTIFICIAL (fndecl),
00675 #endif
00676 is_external );
00677
00678
00679 DST_RESET_assoc_fe (DST_INFO_flag(DST_INFO_IDX_TO_PTR(dst)));
00680
00681 DST_append_child (current_scope_idx, dst);
00682
00683
00684
00685 DECL_DST_FIELD_IDX(fndecl) = dst;
00686
00687
00688
00689
00690 if(is_prototyped) {
00691 tree parms = DECL_ARGUMENTS(fndecl);
00692 if(!parms) {
00693
00694 } else {
00695
00696 DST_enter_param_vars(fndecl,
00697 dst,
00698 parms,
00699 is_abstract_root,
00700 1);
00701 }
00702
00703 }
00704 if(basename && linkage_name && strcmp(basename, linkage_name)) {
00705 DST_add_linkage_name_to_subprogram(dst, linkage_name);
00706 }
00707 DECL_DST_SPECIFICATION_IDX(fndecl) = dst;
00708 }
00709
00710
00711 static void
00712 DST_enter_normal_field(tree parent_tree,
00713 DST_INFO_IDX parent_idx,
00714 TY_IDX parent_ty_idx,
00715 tree field)
00716 {
00717 char isbit = 0;
00718 if ( ! DECL_BIT_FIELD(field)
00719 && Get_Integer_Value(DECL_SIZE(field)) > 0
00720 && Get_Integer_Value(DECL_SIZE(field))
00721 != (TY_size(Get_TY(TREE_TYPE(field)))
00722 * BITSPERBYTE) )
00723 {
00724
00725
00726
00727
00728
00729
00730
00731
00733
00734
00735 isbit = 1;
00736 }
00737 if (DECL_BIT_FIELD(field)) {
00738 isbit = 1;
00739 }
00740 DST_INFO_IDX field_idx = DST_INVALID_INIT;
00741 char *field_name = Get_Name((field));
00742
00743 #ifdef KEY
00744
00745 if ((field_name == NULL || field_name[0] == '\0' ) &&
00746
00747 TREE_CODE(TREE_TYPE(field)) != UNION_TYPE) {
00748 return ;
00749 }
00750 #endif
00751
00752 tree ftype = TREE_TYPE(field);
00753
00754
00755 TY_IDX base = Get_TY(ftype);
00756
00757 DST_INFO_IDX fidx = Create_DST_type_For_Tree(ftype,base,parent_ty_idx);
00758
00759 USRCPOS src;
00760
00761
00762
00763
00764 #ifdef KEY
00765 USRCPOS_srcpos(src) = Get_Srcpos();
00766 #else
00767 USRCPOS_clear(src);
00768 #endif // KEY
00769
00770 INT bitoff = Get_Integer_Value(DECL_FIELD_BIT_OFFSET(field));
00771 #ifndef KEY
00772 INT fld_offset_bytes = bitoff / BITSPERBYTE;
00773 #else
00774
00775 INT fld_offset_bytes = Get_Integer_Value(DECL_FIELD_OFFSET(field)) +
00776 bitoff / BITSPERBYTE;
00777 #endif
00778 tree type_size = TYPE_SIZE(ftype);
00779 UINT align = TYPE_ALIGN(ftype)/BITSPERBYTE;
00780 INT tsize;
00781 if (type_size == NULL) {
00782
00783 Fail_FmtAssertion("DST_enter_normal_field: type_size NULL ");
00784 tsize = 0;
00785 }
00786 else {
00787 if (TREE_CODE(type_size) != INTEGER_CST) {
00788 if (TREE_CODE(type_size) == ARRAY_TYPE)
00789 Fail_FmtAssertion ("Encountered VLA at line %d", lineno);
00790 else
00791 Fail_FmtAssertion ("VLA at line %d not currently implemented",
00792 lineno);
00793 tsize = 0;
00794 }
00795 else
00796 tsize = Get_Integer_Value(type_size) / BITSPERBYTE;
00797 }
00798
00799 if(isbit == 0) {
00800
00801 #ifndef KEY
00802 field_idx = DST_mk_member(
00803 src,
00804 field_name,
00805 fidx,
00806 fld_offset_bytes,
00807 0,
00808 0,
00809 0,
00810 FALSE,
00811 FALSE,
00812 FALSE,
00813 FALSE);
00814 #else
00815 int accessibility;
00816 if (TREE_VIA_PRIVATE(field))
00817 accessibility = DW_ACCESS_private;
00818 else if (TREE_VIA_PROTECTED(field))
00819 accessibility = DW_ACCESS_protected;
00820 else if (TREE_VIA_PUBLIC(field))
00821 accessibility = DW_ACCESS_public;
00822 else
00823 accessibility = 0;
00824 field_idx = DST_mk_member(
00825 src,
00826 field_name,
00827 fidx,
00828 fld_offset_bytes,
00829 0,
00830 0,
00831 0,
00832 FALSE,
00833 FALSE,
00834 FALSE,
00835 FALSE,
00836 accessibility);
00837 #endif
00838
00839 } else {
00840 if(tsize == 0) {
00841 Fail_FmtAssertion("bit field type size 0!");
00842 return;
00843 }
00844 UINT container_off = fld_offset_bytes - (fld_offset_bytes%align);
00845
00846
00847
00848
00849
00850 #ifndef KEY
00851 UINT into_cont_off = bitoff - (container_off*BITSPERBYTE);
00852 #else
00853 UINT into_cont_off = bitoff - ((container_off%16)*BITSPERBYTE);
00854
00855
00856
00857
00858 if (!BYTES_BIG_ENDIAN) {
00859 into_cont_off = tsize*BITSPERBYTE - into_cont_off;
00860 into_cont_off -= Get_Integer_Value(DECL_SIZE(field));
00861 }
00862 #endif
00863
00864 #ifndef KEY
00865 field_idx = DST_mk_member(
00866 src,
00867 field_name,
00868 fidx ,
00869 fld_offset_bytes,
00870 tsize,
00871 into_cont_off,
00872
00873
00874 Get_Integer_Value(DECL_SIZE(field)),
00875 TRUE,
00876 FALSE,
00877 FALSE,
00878 FALSE);
00879 #else
00880 int accessibility;
00881 if (TREE_VIA_PRIVATE(field))
00882 accessibility = DW_ACCESS_private;
00883 else if (TREE_VIA_PROTECTED(field))
00884 accessibility = DW_ACCESS_protected;
00885 else if (TREE_VIA_PUBLIC(field))
00886 accessibility = DW_ACCESS_public;
00887 else
00888 accessibility = 0;
00889 field_idx = DST_mk_member(
00890 src,
00891 field_name,
00892 fidx ,
00893 container_off,
00894 tsize,
00895 into_cont_off,
00896
00897
00898 Get_Integer_Value(DECL_SIZE(field)),
00899 TRUE,
00900 FALSE,
00901 FALSE,
00902 FALSE,
00903 accessibility);
00904 #endif
00905 }
00906 DST_append_child(parent_idx,field_idx);
00907
00908
00909
00910 return ;
00911 }
00912 static void
00913 DST_enter_struct_union_members(tree parent_tree,
00914 DST_INFO_IDX parent_idx )
00915 {
00916 DST_INFO_IDX dst_idx = DST_INVALID_INIT;
00917
00918 TY_IDX parent_ty_idx = Get_TY(parent_tree);
00919
00920
00921
00922
00923
00924
00925 tree field = TREE_PURPOSE(parent_tree);
00926
00927
00928
00929
00930 for( ; field ; field = TREE_CHAIN(field) )
00931 {
00932 if(TREE_CODE(field) == FIELD_DECL) {
00933 DST_enter_normal_field( parent_tree,parent_idx,
00934 parent_ty_idx,field);
00935 } else if(TREE_CODE(field) == VAR_DECL) {
00936
00937
00938 DST_enter_static_data_mem( parent_tree,parent_idx,
00939 parent_ty_idx,field);
00940 } else if (TREE_CODE(field) == FUNCTION_DECL) {
00941
00942 DevWarn("Impossible FUNCTION DECL member of class!\n");
00943 } else {
00944
00945
00946 }
00947 }
00948
00949 #ifdef KEY
00950
00951
00952
00953
00954
00955 FmtAssert (TREE_CODE(parent_tree) == RECORD_TYPE || TREE_CODE(parent_tree) == UNION_TYPE,
00956 ("Unexpected code for parent_tree %x\n.", TREE_CODE(parent_tree)));
00957 #ifdef PATHSCALE_MERGE
00958 tree context = TYPE_CONTEXT(parent_tree);
00959 #else
00960 tree context = TYPE_NAME(parent_tree);
00961 #endif
00962 if (context == NULL ||
00963 TREE_CODE(context) != TYPE_DECL ||
00964 !DECL_CONTEXT(context) ||
00965 TREE_CODE(DECL_CONTEXT(context)) != NAMESPACE_DECL ||
00966 !DECL_NAMESPACE_STD_P(DECL_CONTEXT(context)))
00967 return;
00968 #endif
00969
00970 tree methods = TYPE_METHODS(parent_tree);
00971 for ( ; methods != NULL_TREE; methods = TREE_CHAIN(methods)) {
00972 if(TREE_CODE(methods) == FUNCTION_DECL ) {
00973
00974
00975
00976 #ifndef KEY
00977 if ( DECL_ARTIFICIAL(methods)) {
00978 #else
00979 if (IDENTIFIER_CTOR_OR_DTOR_P(methods->decl.name)) {
00980 #endif
00981
00982
00983 continue;
00984 } else {
00985
00986 DST_enter_member_function( parent_tree,parent_idx,
00987 parent_ty_idx,methods);
00988 }
00989 }
00990 }
00991
00992 return;
00993 }
00994
00995
00996
00997
00998 static DST_INFO_IDX
00999 DST_enter_struct_union(tree type_tree, TY_IDX ttidx , TY_IDX idx,
01000 INT tsize)
01001 {
01002 #ifdef KEY
01003
01004 type_tree = TYPE_MAIN_VARIANT(type_tree);
01005 #endif
01006
01007 DST_INFO_IDX dst_idx = TYPE_DST_IDX(type_tree);
01008
01009 DST_INFO_IDX current_scope_idx;
01010
01011 #ifdef KEY
01012
01013
01014
01015 if (TYPE_CONTEXT(type_tree) &&
01016 (TREE_CODE(type_tree) == RECORD_TYPE ||
01017 TREE_CODE(type_tree) == UNION_TYPE) &&
01018 (TREE_CODE(TYPE_CONTEXT(type_tree)) == RECORD_TYPE ||
01019 TREE_CODE(TYPE_CONTEXT(type_tree)) == UNION_TYPE)) {
01020 tree type_context = TYPE_CONTEXT(type_tree);
01021 current_scope_idx = TYPE_DST_IDX(type_context);
01022 if (DST_IS_NULL(current_scope_idx)) {
01023
01024
01025 Create_DST_type_For_Tree(type_context, TYPE_TY_IDX(type_context),
01026 TY_IDX_ZERO);
01027 current_scope_idx = TYPE_DST_IDX(type_context);
01028 }
01029 Is_True(!DST_IS_NULL(current_scope_idx),
01030 ("DST_enter_struct_union: invalid current scope index\n"));
01031 } else
01032 #endif
01033 current_scope_idx =
01034 DST_get_context(TYPE_CONTEXT(type_tree));
01035
01036 if(DST_IS_NULL(dst_idx)) {
01037
01038
01039
01040
01041
01042
01043
01044 USRCPOS src;
01045
01046
01047
01048
01049 #ifdef KEY
01050 USRCPOS_srcpos(src) = Get_Srcpos();
01051 #else
01052 USRCPOS_clear(src);
01053 #endif // KEY
01054
01055 char *name = Get_Name(type_tree);
01056
01057 #ifdef KEY
01058
01059 if (name == NULL || name[0] == '\0') {
01060 return dst_idx ;
01061 }
01062 #endif
01063
01064 if(TREE_CODE(type_tree) == RECORD_TYPE) {
01065 dst_idx = DST_mk_structure_type(src,
01066 name ,
01067 tsize,
01068 DST_INVALID_IDX,
01069 TREE_PURPOSE(type_tree)== 0
01070 );
01071 } else if (TREE_CODE(type_tree) == UNION_TYPE) {
01072 dst_idx = DST_mk_union_type(src,
01073 name ,
01074 tsize,
01075 DST_INVALID_IDX,
01076 TREE_PURPOSE(type_tree)== 0
01077 );
01078 } else {
01079
01080
01081 return dst_idx;
01082 }
01083 DST_append_child(current_scope_idx,dst_idx);
01084
01085
01086
01087 TYPE_DST_IDX(type_tree) = dst_idx;
01088
01089
01090
01091 INT32 offset = 0;
01092 INT32 anonymous_fields = 0;
01093 if (TYPE_BINFO(type_tree) &&
01094 BINFO_BASETYPES(TYPE_BINFO(type_tree))) {
01095 tree basetypes = BINFO_BASETYPES(TYPE_BINFO(type_tree));
01096 INT32 i;
01097 for (i = 0; i < TREE_VEC_LENGTH(basetypes); ++i) {
01098 tree binfo = TREE_VEC_ELT(basetypes, i);
01099 tree basetype = BINFO_TYPE(binfo);
01100
01101 int virtuality = DW_VIRTUALITY_none;
01102 if(TREE_VIA_VIRTUAL(binfo)) {
01103
01104
01105 virtuality = DW_VIRTUALITY_virtual;
01106 }
01107 #ifdef KEY
01108
01109
01110 int accessibility = DW_ACCESS_private;
01111 if (TREE_VIA_PUBLIC(binfo))
01112 accessibility = DW_ACCESS_public;
01113 else if (TREE_VIA_PROTECTED(binfo))
01114 accessibility = DW_ACCESS_protected;
01115 #endif
01116 offset = Roundup (offset,
01117 TYPE_ALIGN(basetype) / BITSPERBYTE);
01118
01119 TY_IDX itx = TYPE_TY_IDX(basetype);
01120 DST_INFO_IDX bcidx =
01121 Create_DST_type_For_Tree (basetype,itx, idx);
01122
01123 #ifndef KEY
01124
01125
01126 DST_INFO_IDX inhx =
01127 DST_mk_inheritance(src,
01128 bcidx,
01129 virtuality,
01130 offset);
01131 #else
01132 DST_INFO_IDX inhx =
01133 DST_mk_inheritance(src,
01134 bcidx,
01135 virtuality,
01136
01137 virtuality ?
01138 -(tree_low_cst(BINFO_VPTR_FIELD(binfo),0)):
01139 offset,
01140 accessibility);
01141 #endif
01142
01143 DST_append_child(dst_idx,inhx);
01144
01145
01146
01147 #ifdef KEY
01148 if (!is_empty_base_class(basetype) &&
01149 #else
01150 if (!is_empty_base_class(basetype) ||
01151 #endif
01152 !TREE_VIA_VIRTUAL(binfo)) {
01153
01154
01155 offset += Type_Size_Without_Vbases (basetype);
01156 }
01157
01158 }
01159 }
01160
01161
01162
01163 DST_enter_struct_union_members(type_tree,dst_idx);
01164
01165 }
01166
01167 return dst_idx;
01168 }
01169
01170
01171
01172
01173 static DST_INFO_IDX
01174 DST_enter_enum(tree type_tree, TY_IDX ttidx , TY_IDX idx,
01175 INT tsize)
01176 {
01177 DST_INFO_IDX dst_idx =
01178 TYPE_DST_IDX(type_tree);
01179
01180 if(TREE_CODE_CLASS(TREE_CODE(type_tree)) != 't') {
01181 DevWarn("DST_enter_enum input not 't' but %c",
01182 TREE_CODE_CLASS(TREE_CODE(type_tree)));
01183 }
01184 DST_INFO_IDX current_scope_idx =
01185 DST_get_context(TYPE_CONTEXT(type_tree));
01186
01187
01188 if(DST_IS_NULL(dst_idx)) {
01189 DST_INFO_IDX t_dst_idx = DST_INVALID_INIT;
01190 USRCPOS src;
01191
01192
01193
01194
01195 #ifdef KEY
01196 USRCPOS_srcpos(src) = Get_Srcpos();
01197 #else
01198 USRCPOS_clear(src);
01199 #endif // KEY
01200 char *name1 = Get_Name(type_tree);
01201 tree enum_entry = TYPE_VALUES(type_tree);
01202 DST_size_t e_tsize = tsize;
01203 t_dst_idx = DST_mk_enumeration_type( src,
01204 name1,
01205 e_tsize,
01206 DST_INVALID_IDX,
01207 (enum_entry==NULL_TREE));
01208
01209 DST_append_child(current_scope_idx,t_dst_idx);
01210
01211 TYPE_DST_IDX(type_tree) = t_dst_idx;
01212
01213
01214 DST_CONST_VALUE enumerator;
01215 if(tsize == 8) {
01216 DST_CONST_VALUE_form(enumerator) = DST_FORM_DATA8;
01217 } else if (tsize == 4) {
01218 DST_CONST_VALUE_form(enumerator) = DST_FORM_DATA4;
01219 } else {
01220
01221 DST_CONST_VALUE_form(enumerator) = DST_FORM_DATA4;
01222 DevWarn("Unexpected type size %d in enumerator",
01223 (int)tsize);
01224 }
01225
01226 for( ; enum_entry; enum_entry = TREE_CHAIN(enum_entry) ) {
01227 USRCPOS src;
01228
01229
01230
01231
01232 #ifdef KEY
01233 USRCPOS_srcpos(src) = Get_Srcpos();
01234 #else
01235 USRCPOS_clear(src);
01236 #endif // KEY
01237 char *name2 =
01238 IDENTIFIER_POINTER(TREE_PURPOSE(enum_entry));
01239
01240 if (tsize == 8) {
01241 DST_CONST_VALUE_form_data8(enumerator) =
01242 Get_Integer_Value(TREE_VALUE(enum_entry));
01243 } else {
01244 DST_CONST_VALUE_form_data4(enumerator) =
01245 Get_Integer_Value(TREE_VALUE(enum_entry));
01246 }
01247
01248 DST_INFO_IDX ed = DST_mk_enumerator(src,
01249 name2,
01250 enumerator);
01251 DST_append_child(t_dst_idx,ed);
01252
01253 }
01254
01255
01256 #ifdef KEY
01257
01258
01259 dst_idx = t_dst_idx;
01260 #endif
01261 }
01262 return dst_idx;
01263 }
01264
01265
01266 #ifdef KEY
01267 typedef struct type_trans {
01268 DST_size_t size;
01269 char *name;
01270 DST_ATE_encoding encoding;
01271 } type_trans;
01272
01273 static DST_INFO_IDX base_types[MTYPE_LAST+5] =
01274 {
01275 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
01276 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
01277 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
01278 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
01279 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
01280 DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,DST_INVALID_INIT,
01281 DST_INVALID_INIT
01282 } ;
01283
01284 static type_trans ate_types[] = {
01285 1, "BAD", 0,
01286 1, "LOGICAL_1", DW_ATE_boolean,
01287 1, "INTEGER_1", DW_ATE_signed,
01288 2, "INTEGER_2", DW_ATE_signed,
01289 4, "INTEGER_4", DW_ATE_signed,
01290 8, "INTEGER_8", DW_ATE_signed,
01291 1, "INTEGER*1", DW_ATE_unsigned,
01292 2, "INTEGER*2", DW_ATE_unsigned,
01293 4, "INTEGER*4", DW_ATE_unsigned,
01294 8, "INTEGER*8", DW_ATE_unsigned,
01295 4, "REAL_4", DW_ATE_float,
01296 8, "REAL_8", DW_ATE_float,
01297 16,"REAL_10", DW_ATE_float,
01298 16,"REAL_16", DW_ATE_float,
01299 1 ,"CHAR" , DW_ATE_signed_char,
01300 16,"REAL_16", DW_ATE_float,
01301 1, "UNK", DW_ATE_unsigned_char,
01302 8, "COMPLEX_4", DW_ATE_complex_float,
01303 16,"COMPLEX_8", DW_ATE_complex_float,
01304 32,"COMPLEX_16",DW_ATE_complex_float,
01305 1, "VOID", 0,
01306 1, "UNK", 0,
01307 4, "ADDRESS_4", DW_ATE_unsigned,
01308 8, "ADDRESS_8", DW_ATE_unsigned,
01309 32,"COMPLEX_16",DW_ATE_complex_float,
01310 } ;
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322 static DST_INFO_IDX
01323 DST_create_basetype (TY_IDX ty)
01324 {
01325 TYPE_ID bt ;
01326 DST_INFO_IDX i ;
01327
01328 bt = TY_mtype(ty);
01329
01330 if (bt == MTYPE_V) return(DST_INVALID_IDX);
01331
01332 if (TY_is_logical(Ty_Table[ty]))
01333 bt = bt -MTYPE_I1 + MTYPE_V + 1 ;
01334
01335 if (!DST_IS_NULL(base_types[bt]))
01336 return base_types[bt];
01337
01338 i = DST_mk_basetype(ate_types[bt].name,
01339 ate_types[bt].encoding,
01340 ate_types[bt].size);
01341
01342 base_types[bt] = i;
01343 DST_append_child(comp_unit_idx,i);
01344 return i;
01345 }
01346
01347
01348
01349 static DST_INFO_IDX
01350 DST_enter_subrange_type (ARB_HANDLE ar)
01351 {
01352 DST_INFO_IDX i ;
01353 DST_cval_ref lb,ub;
01354 DST_flag const_lb,const_ub ;
01355 BOOL extent = FALSE ;
01356 USRCPOS src;
01357 USRCPOS_clear(src);
01358 DST_INFO_IDX type;
01359
01360 const_lb = ARB_const_lbnd(ar) ;
01361 const_ub = ARB_const_ubnd(ar) ;
01362
01363
01364 if (const_lb)
01365 lb.cval = ARB_lbnd_val(ar) ;
01366 else {
01367 ST* var_st = &St_Table[ARB_lbnd_var(ar)];
01368 type = DST_create_basetype(ST_type(var_st));
01369 lb.ref = DST_mk_variable(
01370 src,
01371 ST_name(var_st),
01372 type,
01373 0,
01374 ST_st_idx(var_st),
01375 DST_INVALID_IDX,
01376 FALSE,
01377 ST_sclass(var_st) == SCLASS_AUTO,
01378 FALSE,
01379 FALSE );
01380 #ifdef KEY
01381
01382 if (ST_name(var_st) != NULL && *ST_name(var_st) != '\0')
01383 #endif
01384 DST_append_child(comp_unit_idx,lb.ref);
01385 }
01386
01387 if (const_ub)
01388 ub.cval = ARB_ubnd_val(ar) ;
01389 else {
01390 ST* var_st = &St_Table[ARB_ubnd_var(ar)];
01391 type = DST_create_basetype(ST_type(var_st));
01392 ub.ref = DST_mk_variable(
01393 src,
01394 ST_name(var_st),
01395 type,
01396 0,
01397 ST_st_idx(var_st),
01398 DST_INVALID_IDX,
01399 FALSE,
01400 ST_sclass(var_st) == SCLASS_AUTO,
01401 FALSE,
01402 FALSE );
01403 #ifdef KEY
01404
01405 if (ST_name(var_st) != NULL && *ST_name(var_st) != '\0')
01406 #endif
01407 DST_append_child(comp_unit_idx,ub.ref);
01408 }
01409
01410 i = DST_mk_subrange_type(const_lb,
01411 lb,
01412 const_ub,
01413 ub);
01414
01415 if (extent)
01416 DST_SET_count(DST_INFO_flag(DST_INFO_IDX_TO_PTR(i))) ;
01417
01418 return i;
01419 }
01420
01421 #endif
01422
01423
01424 static DST_INFO_IDX
01425 DST_enter_array_type(tree type_tree, TY_IDX ttidx , TY_IDX idx,INT tsize)
01426 {
01427 DST_INFO_IDX dst_idx = TYPE_DST_IDX(type_tree);
01428
01429 if(TREE_CODE_CLASS(TREE_CODE(type_tree)) != 't') {
01430 DevWarn("DST_enter_array_type input not 't' but %c",
01431 TREE_CODE_CLASS(TREE_CODE(type_tree)));
01432 }
01433
01434 if(DST_IS_NULL(dst_idx)) {
01435
01436 USRCPOS src;
01437
01438
01439
01440
01441 #ifdef KEY
01442 USRCPOS_srcpos(src) = Get_Srcpos();
01443 #else
01444 USRCPOS_clear(src);
01445 #endif // KEY
01446
01447
01448
01449 tree elt_tree = TREE_TYPE(type_tree);
01450 TY_IDX itx = TYPE_TY_IDX(elt_tree);
01451
01452
01453 DST_INFO_IDX inner_dst =
01454 Create_DST_type_For_Tree (elt_tree,itx, idx);
01455
01456 #ifndef KEY
01457 dst_idx = DST_mk_array_type( src,
01458 0,
01459
01460 inner_dst,
01461 tsize,
01462 DST_INVALID_IDX,
01463 (tsize == 0));
01464 #else
01465
01466
01467
01468 dst_idx = DST_mk_array_type( src,
01469 0,
01470
01471 inner_dst,
01472 0,
01473 DST_INVALID_IDX,
01474 TRUE);
01475 TY& tt = Ty_Table[ttidx];
01476 ARB_HANDLE arb = TY_arb(ttidx);
01477 DST_INFO_IDX d;
01478 if ( TY_kind (tt) != KIND_INVALID ) {
01479 for (INT index = TY_AR_ndims(ttidx) - 1; index >= 0; index--) {
01480
01481
01482 if (!ARB_ubnd_var(arb[index]))
01483 break;
01484
01485 if (!ARB_const_ubnd(arb[index])) {
01486 ST* var_st = &St_Table[ARB_ubnd_var(arb[index])];
01487 if (ST_sclass(var_st) == SCLASS_AUTO)
01488 break;
01489 }
01490 d = DST_enter_subrange_type(arb[index]);
01491 DST_append_child(dst_idx,d);
01492 }
01493 }
01494 #endif
01495 DST_append_child(comp_unit_idx,dst_idx);
01496
01497 TYPE_DST_IDX(type_tree) = dst_idx;
01498 }
01499 return dst_idx;
01500 }
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513 static DST_INFO_IDX
01514 DST_construct_pointer_to_member(tree type_tree)
01515 {
01516 tree ttree = TREE_TYPE(type_tree);
01517 FmtAssert(TREE_CODE(type_tree) == POINTER_TYPE
01518 && TREE_CODE(ttree) == OFFSET_TYPE,
01519 ("DST_construct_pointer_to_member:"
01520 "invalid incoming arguments "));
01521 USRCPOS src;
01522
01523
01524
01525
01526 DST_INFO_IDX error_idx = DST_INVALID_INIT;
01527
01528
01529 #ifdef KEY
01530 USRCPOS_srcpos(src) = Get_Srcpos();
01531 #else
01532 USRCPOS_clear(src);
01533 #endif // KEY
01534
01535 char *name1 = 0;
01536 if(DECL_ORIGINAL_TYPE(type_tree)== 0) {
01537
01538 name1 = Get_Name(TREE_TYPE(type_tree));
01539 } else {
01540
01541 name1 = Get_Name(DECL_ORIGINAL_TYPE(type_tree));
01542 }
01543
01544
01545 tree member_type = TREE_TYPE(ttree);
01546 if( TREE_CODE(member_type) == ERROR_MARK) {
01547 return error_idx;
01548 }
01549 if(TREE_CODE_CLASS(TREE_CODE(ttree)) != 't') {
01550 DevWarn("Unexpected tree shape1: pointer_to_member %c\n",
01551 TREE_CODE_CLASS(TREE_CODE(ttree)));
01552 }
01553 TY_IDX midx = Get_TY(member_type);
01554 TYPE_TY_IDX(member_type) = midx;
01555 TY_IDX orig_idx = 0;
01556
01557 DST_INFO_IDX mdst =
01558 Create_DST_type_For_Tree(member_type,
01559 midx,
01560 orig_idx);
01561 TYPE_DST_IDX(type_tree) = mdst;
01562
01563
01564 tree base_type = TYPE_OFFSET_BASETYPE(ttree);
01565 if( TREE_CODE(base_type) == ERROR_MARK) {
01566 return error_idx;
01567 }
01568 if(TREE_CODE_CLASS(TREE_CODE(base_type)) != 't') {
01569 DevWarn("Unexpected tree shape2: pointer_to_member %c\n",
01570 TREE_CODE_CLASS(TREE_CODE(base_type)));
01571 }
01572 TY_IDX container_idx = Get_TY(base_type);
01573
01574
01575 DST_INFO_IDX container_dst = Create_DST_type_For_Tree(
01576 base_type,
01577 container_idx,
01578 orig_idx);
01579 TYPE_DST_IDX(type_tree) = container_dst;
01580
01581
01582 DST_INFO_IDX lidx =
01583 DST_mk_ptr_to_member_type(src,
01584 name1,
01585 mdst ,
01586 container_dst);
01587 return lidx;
01588
01589 }
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607 DST_INFO_IDX
01608 Create_DST_type_For_Tree (tree type_tree, TY_IDX ttidx , TY_IDX idx, bool ignoreconst, bool ignorevolatile)
01609 {
01610
01611 DST_INFO_IDX dst_idx = DST_INVALID_INIT;
01612
01613 if(TREE_CODE_CLASS(TREE_CODE(type_tree)) != 't') {
01614 DevWarn("Create_DST_type_For_Tree input not 't' but %c",
01615 TREE_CODE_CLASS(TREE_CODE(type_tree)));
01616 return dst_idx;
01617
01618 }
01619
01620
01621
01622
01623 if (TYPE_NAME(type_tree)) {
01624
01625 if( idx == 0 &&
01626 (TREE_CODE(type_tree) == RECORD_TYPE ||
01627 TREE_CODE(type_tree) == UNION_TYPE) &&
01628 TREE_CODE(TYPE_NAME(type_tree)) == TYPE_DECL &&
01629 TYPE_MAIN_VARIANT(type_tree) != type_tree) {
01630 idx = Get_TY (TYPE_MAIN_VARIANT(type_tree));
01631
01632 #ifndef KEY
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648 return dst_idx;
01649 #endif
01650 } else {
01651
01652 }
01653 }
01654 DST_INFO_IDX current_scope_idx = comp_unit_idx;
01655 if(TYPE_CONTEXT(type_tree)) {
01656 current_scope_idx = DST_get_context(TYPE_CONTEXT(type_tree));
01657 }
01658
01659 char *name1 = Get_Name(type_tree);
01660
01661 TYPE_ID mtype;
01662 INT tsize;
01663 BOOL variable_size = FALSE;
01664 tree type_size = TYPE_SIZE(type_tree);
01665 UINT align = TYPE_ALIGN(type_tree) / BITSPERBYTE;
01666 if (type_size == NULL) {
01667
01668
01669 FmtAssert( TREE_CODE(type_tree) == ARRAY_TYPE
01670 || TREE_CODE(type_tree) == UNION_TYPE
01671 || TREE_CODE(type_tree) == RECORD_TYPE
01672 || TREE_CODE(type_tree) == ENUMERAL_TYPE
01673 || TREE_CODE(type_tree) == VOID_TYPE
01674 || TREE_CODE(type_tree) == LANG_TYPE,
01675 ("Create_DST_type_For_Tree: type_size NULL for non ARRAY/RECORD"));
01676 tsize = 0;
01677 }
01678 else {
01679 if (TREE_CODE(type_size) != INTEGER_CST) {
01680 if (TREE_CODE(type_tree) == ARRAY_TYPE)
01681 DevWarn ("Encountered VLA at line %d", lineno);
01682 else
01683 Fail_FmtAssertion ("VLA at line %d not currently implemented", lineno);
01684 variable_size = TRUE;
01685 tsize = 0;
01686 }
01687 else
01688 tsize = Get_Integer_Value(type_size) / BITSPERBYTE;
01689 }
01690
01691
01692 if (!ignoreconst && TYPE_READONLY (type_tree)) {
01693 dst_idx = TYPE_DST_IDX(type_tree);
01694 if(DST_IS_NULL(dst_idx)) {
01695 TY_IDX itx = TYPE_TY_IDX(type_tree);
01696 DST_INFO_IDX unqual_dst = Create_DST_type_For_Tree (type_tree,itx, idx, true, false);
01697 dst_idx = DST_mk_const_type (unqual_dst) ;
01698 DST_append_child(current_scope_idx,dst_idx);
01699 TYPE_DST_IDX(type_tree) = dst_idx;
01700 }
01701 return dst_idx ;
01702 }
01703 if (!ignorevolatile && TYPE_VOLATILE (type_tree)) {
01704 dst_idx = TYPE_DST_IDX(type_tree);
01705 if(DST_IS_NULL(dst_idx)) {
01706 TY_IDX itx = TYPE_TY_IDX(type_tree);
01707 DST_INFO_IDX unqual_dst = Create_DST_type_For_Tree (type_tree,itx, idx, true, true);
01708 dst_idx = DST_mk_volatile_type (unqual_dst) ;
01709 DST_append_child(current_scope_idx,dst_idx);
01710 TYPE_DST_IDX(type_tree) = dst_idx;
01711 }
01712 return dst_idx ;
01713 }
01714
01715 int encoding = 0;
01716 switch (TREE_CODE(type_tree)) {
01717 case VOID_TYPE:
01718 case LANG_TYPE:
01719
01720 break;
01721 case BOOLEAN_TYPE:
01722 {
01723 encoding = DW_ATE_boolean;
01724 goto common_basetypes;
01725 }
01726 case INTEGER_TYPE:
01727 {
01728
01729 #ifdef KEY
01730
01731
01732
01733
01734
01735
01736 if (tsize == 1 &&
01737 (strcmp(name1, "char") == 0 ||
01738 strcmp(name1, "unsigned char") == 0)) {
01739 if (TREE_UNSIGNED(type_tree)) {
01740 encoding = DW_ATE_unsigned_char;
01741 } else {
01742 encoding = DW_ATE_signed_char;
01743 }
01744 goto common_basetypes;
01745 }
01746 #endif
01747 if (TREE_UNSIGNED(type_tree)) {
01748 encoding = DW_ATE_unsigned;
01749 } else {
01750 encoding = DW_ATE_signed;
01751 }
01752 goto common_basetypes;
01753 }
01754 case CHAR_TYPE:
01755 {
01756
01757 if (TREE_UNSIGNED(type_tree)) {
01758 encoding = DW_ATE_unsigned_char;
01759 } else {
01760 encoding = DW_ATE_signed_char;
01761 }
01762 goto common_basetypes;
01763 }
01764 case ENUMERAL_TYPE:
01765 {
01766 #ifdef KEY
01767
01768 if (is_typedef (type_tree))
01769 dst_idx = DST_Create_type ((ST*)NULL, TYPE_NAME (type_tree));
01770 else
01771 #endif
01772 dst_idx = DST_enter_enum(type_tree,ttidx,idx,
01773 tsize);
01774
01775 }
01776 break;
01777 case REAL_TYPE:
01778 {
01779
01780 encoding = DW_ATE_float;
01781 goto common_basetypes;
01782 }
01783 case COMPLEX_TYPE:
01784
01785 encoding = DW_ATE_complex_float;
01786
01787 common_basetypes:
01788 {
01789 FmtAssert(name1 != 0,
01790 ("name of base type empty, cannot make DST entry!"));
01791
01792 std::string names(name1);
01793 DST_Type_Map::iterator p =
01794 basetypes.find(names);
01795 if(p != basetypes.end()) {
01796 DST_INFO_IDX t = (*p).second;
01797 return t;
01798 } else {
01799 #ifdef KEY
01800
01801 if (is_typedef (type_tree))
01802 dst_idx = DST_Create_type ((ST*)NULL,
01803 TYPE_NAME (type_tree));
01804 else
01805 #endif
01806 {
01807 dst_idx = DST_mk_basetype(
01808 name1,encoding,tsize);
01809 basetypes[names] = dst_idx;
01810 DST_append_child(comp_unit_idx,dst_idx);
01811 }
01812 }
01813
01814 }
01815
01816 break;
01817 case REFERENCE_TYPE:
01818 {
01819 dst_idx = TYPE_DST_IDX(type_tree);
01820 if(DST_IS_NULL(dst_idx)) {
01821
01822 tree ttree = TREE_TYPE(type_tree);
01823 TY_IDX itx = TYPE_TY_IDX(ttree);
01824 DST_INFO_IDX inner_dst =
01825 Create_DST_type_For_Tree (ttree,itx, idx);
01826
01827
01828
01829 dst_idx = DST_mk_reference_type(
01830 inner_dst,
01831 DW_ADDR_none,
01832 tsize);
01833
01834 DST_append_child(current_scope_idx,dst_idx);
01835
01836 TYPE_DST_IDX(type_tree) = dst_idx;
01837 }
01838 }
01839 break;
01840 case POINTER_TYPE:
01841 #ifdef KEY
01842
01843 if (is_typedef (type_tree))
01844 dst_idx = DST_Create_type ((ST*)NULL, TYPE_NAME (type_tree));
01845 else
01846 #endif
01847 {
01848 dst_idx = TYPE_DST_IDX(type_tree);
01849 if(DST_IS_NULL(dst_idx)) {
01850
01851 tree ttree = TREE_TYPE(type_tree);
01852 if(TREE_CODE(ttree) == OFFSET_TYPE) {
01853 dst_idx = DST_construct_pointer_to_member(type_tree);
01854 } else {
01855
01856 TY_IDX itx = TYPE_TY_IDX(ttree);
01857 DST_INFO_IDX inner_dst =
01858 Create_DST_type_For_Tree (ttree,itx, idx);
01859
01860
01861
01862
01863 dst_idx = DST_mk_pointer_type(
01864 inner_dst,
01865 DW_ADDR_none,
01866 tsize);
01867 }
01868
01869 DST_append_child(current_scope_idx,dst_idx);
01870
01871 TYPE_DST_IDX(type_tree) = dst_idx;
01872 }
01873 }
01874 break;
01875 case OFFSET_TYPE:
01876
01877
01878 break;
01879
01880 case ARRAY_TYPE:
01881
01882 {
01883 dst_idx = DST_enter_array_type(type_tree,
01884 ttidx, idx, tsize);
01885 }
01886 break;
01887 case RECORD_TYPE:
01888 case UNION_TYPE:
01889 {
01890 #ifdef KEY
01891
01892 if (is_typedef (type_tree))
01893 dst_idx = DST_Create_type ((ST*)NULL, TYPE_NAME (type_tree));
01894 else
01895 #endif
01896 dst_idx = DST_enter_struct_union(type_tree,ttidx,idx,
01897 tsize);
01898 }
01899 break;
01900 case METHOD_TYPE:
01901 {
01902
01903 }
01904 break;
01905
01906 case FUNCTION_TYPE:
01907 {
01908 #if 0
01909 tree arg;
01910 INT32 num_args;
01911 TY &ty = New_TY (idx);
01912 TY_Init (ty, 0, KIND_FUNCTION, MTYPE_UNKNOWN, NULL);
01913 Set_TY_align (idx, 1);
01914 TY_IDX ret_ty_idx;
01915 TY_IDX arg_ty_idx;
01916 TYLIST tylist_idx;
01917
01918
01919
01920
01921
01922 ret_ty_idx = Get_TY(TREE_TYPE(type_tree));
01923 for (arg = TYPE_ARG_TYPES(type_tree);
01924 arg;
01925 arg = TREE_CHAIN(arg))
01926 arg_ty_idx = Get_TY(TREE_VALUE(arg));
01927
01928
01929
01930 if (!WFE_Keep_Zero_Length_Structs &&
01931 TY_mtype (ret_ty_idx) == MTYPE_M &&
01932 TY_size (ret_ty_idx) == 0) {
01933
01934 DevWarn ("function returning zero length struct at line %d", lineno);
01935 ret_ty_idx = Be_Type_Tbl (MTYPE_V);
01936 }
01937
01938 Set_TYLIST_type (New_TYLIST (tylist_idx), ret_ty_idx);
01939 Set_TY_tylist (ty, tylist_idx);
01940 for (num_args = 0, arg = TYPE_ARG_TYPES(type_tree);
01941 arg;
01942 num_args++, arg = TREE_CHAIN(arg))
01943 {
01944 arg_ty_idx = Get_TY(TREE_VALUE(arg));
01945 if (!WFE_Keep_Zero_Length_Structs &&
01946 TY_mtype (arg_ty_idx) == MTYPE_M &&
01947 TY_size (arg_ty_idx) == 0) {
01948
01949 DevWarn ("zero length struct encountered in function prototype at line %d", lineno);
01950 }
01951 else
01952 Set_TYLIST_type (New_TYLIST (tylist_idx), arg_ty_idx);
01953 }
01954 if (num_args)
01955 {
01956 Set_TY_has_prototype(idx);
01957 if (arg_ty_idx != Be_Type_Tbl(MTYPE_V))
01958 {
01959 Set_TYLIST_type (New_TYLIST (tylist_idx), 0);
01960 Set_TY_is_varargs(idx);
01961 }
01962 else
01963 Set_TYLIST_type (Tylist_Table [tylist_idx], 0);
01964 }
01965 else
01966 Set_TYLIST_type (New_TYLIST (tylist_idx), 0);
01967 #endif
01968 }
01969 break;
01970 #ifdef TARG_X8664
01971 case VECTOR_TYPE:
01972 {
01973
01974
01975 type_tree = TREE_TYPE (TYPE_FIELDS
01976 (TYPE_DEBUG_REPRESENTATION_TYPE (type_tree)));
01977 ttidx = Get_TY (type_tree);
01978 dst_idx = DST_enter_array_type(type_tree, ttidx, idx, tsize);
01979 DST_SET_GNU_vector(DST_INFO_flag(DST_INFO_IDX_TO_PTR(dst_idx)));
01980 }
01981 break;
01982 #endif // TARG_X8664
01983 default:
01984
01985 FmtAssert(FALSE, ("Create_DST_type_For_Tree: unexpected tree_type"));
01986 }
01987
01988
01989
01990
01991
01992
01993
01994
01995 return dst_idx;
01996 }
01997
01998 extern DST_INFO_IDX
01999 Create_DST_decl_For_Tree(
02000 tree decl, ST* var_st)
02001 {
02002
02003
02004
02005 DST_INFO_IDX cur_idx = DECL_DST_IDX(decl);
02006 if(!DST_IS_NULL(cur_idx)) {
02007
02008
02009 return cur_idx;
02010 }
02011
02012 DST_INFO_IDX dst_idx = DST_INVALID_INIT;
02013
02014
02015
02016 if (DECL_IGNORED_P(decl)) {
02017 return cur_idx;
02018 }
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031 if (TREE_CODE(decl) == VAR_DECL &&
02032 DECL_EXTERNAL(decl) && !DECL_COMMON(decl)) {
02033 return cur_idx;
02034 }
02035
02036 #ifndef KEY
02037
02038
02039 if (TREE_CODE(decl) == VAR_DECL && (!TREE_STATIC(decl)
02040 && !DECL_COMMON(decl))) {
02041 return cur_idx ;
02042 }
02043 #endif // !KEY
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053 int tcode = TREE_CODE(decl);
02054 switch(tcode) {
02055 case VAR_DECL: {
02056
02057 dst_idx = DST_Create_var(var_st,decl);
02058 }
02059 break;
02060 case TYPE_DECL: {
02061
02062 dst_idx = DST_Create_type(var_st,decl);
02063 }
02064 break;
02065 case PARM_DECL: {
02066
02067 dst_idx = DST_Create_Parmvar(var_st,decl);
02068 }
02069 break;
02070 default: {
02071 }
02072 break;
02073 }
02074 return dst_idx;
02075 }
02076
02077
02078
02079 static DST_INFO_IDX
02080 DST_Create_type(ST *typ_decl, tree decl)
02081 {
02082 USRCPOS src;
02083
02084
02085
02086
02087
02088
02089 #ifdef KEY
02090 USRCPOS_srcpos(src) = Get_Srcpos();
02091 #else
02092 USRCPOS_clear(src);
02093 #endif // KEY
02094 DST_INFO_IDX dst_idx = DST_INVALID_INIT;
02095
02096
02097
02098
02099 char *name1 = 0;
02100 if(DECL_ORIGINAL_TYPE(decl)== 0) {
02101
02102 name1 = Get_Name(TREE_TYPE(decl));
02103 } else {
02104
02105 #ifdef KEY
02106
02107
02108 name1 = Get_Name(TREE_TYPE(decl));
02109 #else
02110 name1 = Get_Name(DECL_ORIGINAL_TYPE(decl));
02111 #endif
02112 }
02113
02114
02115
02116
02117 std::string names(name1);
02118 DST_Type_Map::iterator p =
02119 basetypes.find(names);
02120 if(p != basetypes.end()) {
02121
02122 DST_INFO_IDX t = (*p).second;
02123
02124 return t;
02125 }
02126
02127 DST_INFO_IDX current_scope_idx =
02128 DST_get_context(DECL_CONTEXT(decl));
02129
02130
02131
02132 #ifdef KEY
02133
02134 tree undt = DECL_ORIGINAL_TYPE(decl);
02135 #else
02136 tree undt = DECL_RESULT(decl);
02137 #endif
02138 TY_IDX base;
02139
02140 if(!undt) {
02141 DevWarn ("DST no result type for typedef decl: impossible");
02142 return DST_INVALID_IDX;
02143 }
02144
02145
02146 base = Get_TY(undt);
02147 DST_INFO_IDX dst =
02148 Create_DST_type_For_Tree(undt,base,
02149 0);
02150
02151 dst_idx = DST_mk_typedef( src,
02152 name1,
02153 dst,
02154 DST_INVALID_IDX);
02155 DST_append_child(current_scope_idx,dst_idx);
02156
02157 basetypes[names] = dst_idx;
02158 #ifdef KEY
02159 TYPE_DST_IDX(decl) = dst_idx;
02160 #else
02161 TYPE_DST_IDX(undt) = dst_idx;
02162 #endif
02163
02164 return dst_idx;
02165 }
02166
02167 static DST_INFO_IDX
02168 DST_Create_Parmvar(ST *var_st, tree param)
02169 {
02170 USRCPOS src;
02171
02172
02173
02174
02175
02176 #ifdef KEY
02177 USRCPOS_srcpos(src) = Get_Srcpos();
02178 #else
02179 USRCPOS_clear(src);
02180 #endif // KEY
02181
02182
02183 DST_INFO_IDX type_idx = DST_INVALID_INIT;
02184
02185 ST * st = Get_ST(param);
02186
02187
02188 tree type = TREE_TYPE(param);
02189
02190 TY_IDX ty_idx = Get_TY(type);
02191
02192 DST_INFO_IDX dtype = DECL_DST_IDX(param);
02193 return dtype;
02194 }
02195
02196
02197
02198
02199
02200
02201
02202 static DST_INFO_IDX
02203 DST_find_class_member(char * linkage_name_in, tree myrecord)
02204 {
02205 DST_INFO_IDX return_member_dst = DST_INVALID_INIT;
02206 if(!linkage_name_in)
02207 return return_member_dst;
02208 tree field = TREE_PURPOSE(myrecord);
02209 for( ; field ; field = TREE_CHAIN(field) )
02210 {
02211 if(TREE_CODE(field) == VAR_DECL) {
02212
02213 char * linkage_name =
02214 IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME (field));
02215 if(linkage_name &&
02216 (strcmp(linkage_name, linkage_name_in) == 0)) {
02217 return_member_dst = DECL_DST_FIELD_IDX(field);
02218 return return_member_dst;
02219 }
02220 }
02221 }
02222 tree methods = TYPE_METHODS(myrecord);
02223 for ( ; methods != NULL_TREE; methods = TREE_CHAIN(methods)) {
02224 if(TREE_CODE(methods) == FUNCTION_DECL ) {
02225 if ( DECL_ARTIFICIAL(methods)) {
02226
02227
02228 continue;
02229 } else {
02230 char * linkage_name =
02231 IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME (methods));
02232 if(linkage_name &&
02233 (strcmp(linkage_name, linkage_name_in) == 0)) {
02234 return_member_dst = DECL_DST_FIELD_IDX(methods);
02235 return return_member_dst;
02236 }
02237 }
02238 }
02239 }
02240
02241
02242 return return_member_dst;
02243 }
02244
02245 static DST_INFO_IDX
02246 DST_Create_var(ST *var_st, tree decl)
02247 {
02248 USRCPOS src;
02249
02250
02251
02252
02253
02254
02255
02256 int is_external = TREE_PUBLIC(decl);
02257 int external_decl = DECL_EXTERNAL(decl);
02258 tree context = DECL_CONTEXT(decl);
02259
02260
02261
02262
02263 if(external_decl) {
02264 if( context && TREE_CODE(context) == RECORD_TYPE) {
02265
02266 DST_INFO_IDX no_info = DST_INVALID_INIT;
02267 return no_info;
02268 }
02269
02270
02271 }
02272 char *field_name = Get_Name(decl);
02273 #ifdef KEY
02274 char *linkage_name = "";
02275 if (!DECL_ARTIFICIAL (decl) && DECL_NAME(decl))
02276 linkage_name = IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME (decl));
02277 #else
02278 char *linkage_name =
02279 IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME (decl));
02280 #endif // KEY
02281
02282 int class_var_found_member = 0;
02283 DST_INFO_IDX class_var_idx = DST_INVALID_INIT;
02284 if(context && TREE_CODE(context) == RECORD_TYPE) {
02285
02286 class_var_idx =
02287 DST_find_class_member(linkage_name, context);
02288 if(!DST_IS_NULL(class_var_idx)) {
02289 class_var_found_member = 1;
02290 field_name = 0;
02291
02292
02293 }
02294
02295
02296
02297 char *classname = Get_Name(context);
02298 if(classname && !class_var_found_member) {
02299 int len = strlen(classname);
02300 char* newname = new char[len+5
02301 ];
02302
02303
02304
02305 strcpy(newname,classname);
02306 strcpy(newname+len,"::");
02307 if(field_name) {
02308
02309
02310
02311 field_name = Index_To_Str(Save_Str2(newname,field_name));
02312 }
02313
02314 delete [] newname;
02315 }
02316
02317
02318 }
02319
02320 #ifdef KEY
02321 USRCPOS_srcpos(src) = Get_Srcpos();
02322 #else
02323 USRCPOS_clear(src);
02324 #endif // KEY
02325 DST_INFO_IDX dst = DST_INVALID_INIT;
02326
02327 DST_INFO_IDX type = TYPE_DST_IDX(TREE_TYPE(decl));
02328
02329
02330 #ifdef KEY
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344 if (field_name && strcmp(field_name, "") == 0 &&
02345 TREE_CODE(TREE_TYPE(decl)) == UNION_TYPE &&
02346 TREE_PURPOSE(TREE_TYPE(decl)) &&
02347
02348
02349
02350 (enum cplus_tree_code) TREE_CODE(TREE_PURPOSE(TREE_TYPE(decl))) !=
02351 TEMPLATE_DECL) {
02352 tree field = TREE_PURPOSE(TREE_TYPE(decl));
02353 DST_INFO_IDX current_scope_idx =
02354 DST_get_context(DECL_CONTEXT(decl));
02355 for( ; field ; field = TREE_CHAIN(field) )
02356 {
02357 field_name = Get_Name(field);
02358 if (TREE_CODE(field) == FIELD_DECL ||
02359 TREE_CODE(field) == VAR_DECL) {
02360 dst = DST_mk_variable(src,
02361 field_name,
02362 TYPE_DST_IDX(TREE_TYPE(field)),
02363 0,
02364 ST_st_idx(var_st),
02365 DST_INVALID_IDX,
02366 external_decl,
02367 FALSE,
02368 is_external,
02369 FALSE );
02370
02371 if (field_name != NULL && *field_name != '\0')
02372 DST_append_child (current_scope_idx, dst);
02373 }
02374
02375 }
02376 return dst;
02377 }
02378 #endif
02379 dst = DST_mk_variable(
02380 src,
02381 field_name,
02382 type,
02383 0,
02384 ST_st_idx(var_st),
02385 DST_INVALID_IDX,
02386 external_decl,
02387 FALSE,
02388 is_external,
02389 FALSE );
02390
02391 DST_INFO_IDX current_scope_idx =
02392 DST_get_context(DECL_CONTEXT(decl));
02393
02394
02395 #ifdef KEY
02396
02397
02399
02400
02401 #else
02402
02403
02404
02405
02406
02407
02408
02409 #endif
02410
02411
02412
02413
02414
02415 if(class_var_found_member) {
02416 DST_add_specification_to_variable(dst, class_var_idx);
02417 }
02418
02419
02420 #ifdef KEY
02421
02422 if (field_name != NULL && *field_name != '\0')
02423 #endif
02424 DST_append_child (current_scope_idx, dst);
02425 return dst;
02426
02427 }
02428
02429
02430
02431
02432
02433
02434
02435
02436 static void
02437 DST_enter_param_vars(tree fndecl,
02438 DST_INFO_IDX parent_idx,
02439 tree parameter_list,
02440 int is_abstract_root,
02441 int is_declaration_only)
02442 {
02443 USRCPOS src;
02444 USRCPOS_srcpos(src) = Get_Srcpos();
02445
02446
02447 tree pdecl = parameter_list;
02448
02449 for( ; pdecl; pdecl = TREE_CHAIN(pdecl)) {
02450 #ifdef KEY
02451
02452
02453
02454 if(TREE_CODE(pdecl) == INDIRECT_REF) {
02455 TREE_SET_CODE(pdecl, PARM_DECL);
02456
02457 DST_INFO_IDX param_idx = DST_INVALID_INIT;
02458 DST_INFO_IDX type_idx = DST_INVALID_INIT;
02459 BOOL is_artificial = DECL_ARTIFICIAL(pdecl);
02460 int decl_to_be_restored = 0;
02461 int type_to_be_restored = 0;
02462 tree type = TREE_TYPE(pdecl);
02463
02464
02465 DST_INFO_IDX save_type_idx = TYPE_DST_IDX(type);
02466 DST_INFO_IDX save_decl_idx = DECL_DST_IDX(pdecl);
02467
02468 ST *st = 0;
02469 if(!is_declaration_only) {
02470 st = Get_ST(TREE_OPERAND(pdecl, 0));
02471
02472
02473
02474 }
02475
02476
02477
02478 TY_IDX ty_idx = Get_TY(type);
02479
02480
02481 type_idx = TYPE_DST_IDX(type);
02482
02483 char *name = Get_Name(pdecl);
02484
02485 DST_INFO_IDX initinfo = DST_INVALID_IDX;
02486
02487
02488
02489
02490
02491
02492
02493 ST_IDX loc = (is_abstract_root || is_declaration_only)?
02494 ST_IDX_ZERO: ST_st_idx(st);
02495 DST_INFO_IDX aroot = DST_INVALID_IDX;
02496 if(!is_abstract_root && !is_declaration_only) {
02497
02498 aroot = DECL_DST_ABSTRACT_ROOT_IDX(pdecl);
02499 }
02500
02501
02502 param_idx = DST_mk_formal_parameter(
02503 src,
02504 name,
02505 type_idx,
02506 loc,
02507
02508
02509
02510 aroot,
02511
02512
02513 initinfo,
02514 0?TRUE:FALSE,
02515 FALSE,
02516 is_artificial,
02517 is_declaration_only);
02518
02519
02520
02521
02522 DST_RESET_assoc_fe (DST_INFO_flag(DST_INFO_IDX_TO_PTR(param_idx)));
02523
02524
02525
02526
02527
02528
02529
02530 if(is_abstract_root) {
02531 DECL_DST_ABSTRACT_ROOT_IDX(pdecl) = param_idx;
02532 }
02533 if (!is_declaration_only && !is_abstract_root) {
02534 DECL_DST_IDX(pdecl) = param_idx;
02535 }
02536
02537 DST_append_child(parent_idx,param_idx);
02538
02539 DST_SET_deref(DST_INFO_flag( DST_INFO_IDX_TO_PTR(param_idx)));
02540
02541 TREE_SET_CODE(pdecl, INDIRECT_REF);
02542 } else
02543 #endif
02544 if(TREE_CODE_CLASS(TREE_CODE(pdecl)) != 'd') {
02545 DevWarn("parameter node not decl! tree node code %d ",
02546 TREE_CODE(pdecl));
02547 } else {
02548 DST_INFO_IDX param_idx = DST_INVALID_INIT;
02549 DST_INFO_IDX type_idx = DST_INVALID_INIT;
02550 BOOL is_artificial = DECL_ARTIFICIAL(pdecl);
02551 int decl_to_be_restored = 0;
02552 int type_to_be_restored = 0;
02553 tree type = TREE_TYPE(pdecl);
02554
02555
02556 DST_INFO_IDX save_type_idx = TYPE_DST_IDX(type);
02557 DST_INFO_IDX save_decl_idx = DECL_DST_IDX(pdecl);
02558
02559 ST *st = 0;
02560 if(!is_declaration_only) {
02561 st = Get_ST(pdecl);
02562
02563
02564
02565
02566 }
02567
02568
02569
02570 TY_IDX ty_idx = Get_TY(type);
02571
02572
02573 type_idx = TYPE_DST_IDX(type);
02574
02575 char *name = Get_Name(pdecl);
02576
02577 DST_INFO_IDX initinfo = DST_INVALID_IDX;
02578
02579
02580
02581
02582
02583
02584
02585 ST_IDX loc = (is_abstract_root || is_declaration_only)?
02586 ST_IDX_ZERO: ST_st_idx(st);
02587 DST_INFO_IDX aroot = DST_INVALID_IDX;
02588 if(!is_abstract_root && !is_declaration_only) {
02589
02590 aroot = DECL_DST_ABSTRACT_ROOT_IDX(pdecl);
02591 }
02592
02593
02594 param_idx = DST_mk_formal_parameter(
02595 src,
02596 name,
02597 type_idx,
02598 loc,
02599
02600
02601
02602 aroot,
02603
02604
02605 initinfo,
02606 0?TRUE:FALSE,
02607 FALSE,
02608 is_artificial,
02609 is_declaration_only);
02610
02611
02612
02613
02614 DST_RESET_assoc_fe (DST_INFO_flag(DST_INFO_IDX_TO_PTR(param_idx)));
02615
02616
02617
02618
02619
02620
02621
02622 if(is_abstract_root) {
02623 DECL_DST_ABSTRACT_ROOT_IDX(pdecl) = param_idx;
02624 }
02625 if (!is_declaration_only && !is_abstract_root) {
02626 DECL_DST_IDX(pdecl) = param_idx;
02627 }
02628
02629 DST_append_child(parent_idx,param_idx);
02630 }
02631 }
02632 }
02633
02634
02635
02636
02637 DST_INFO_IDX
02638 DST_Create_Subprogram (ST *func_st,tree fndecl)
02639 {
02640 USRCPOS src;
02641 USRCPOS_srcpos(src) = Get_Srcpos();
02642 DST_INFO_IDX dst = DST_INVALID_INIT;
02643 DST_INFO_IDX ret_dst = DST_INVALID_IDX;
02644
02645 DST_INFO_IDX current_scope_idx = fndecl ?
02646 (DST_get_context(DECL_CONTEXT(fndecl))):
02647 comp_unit_idx;
02648
02649
02650 BOOL is_prototyped = FALSE;
02651
02652
02653 if(Debug_Level >= 2 && fndecl) {
02654
02655 #ifndef KEY
02656 tree resdecl = DECL_RESULT(fndecl);
02657 tree restype = 0;
02658 if( resdecl) {
02659 restype = TREE_TYPE(resdecl);
02660 }
02661 #else
02662
02663
02664 tree restype = 0;
02665 if (TREE_TYPE(fndecl))
02666 restype = TREE_TYPE(TREE_TYPE(fndecl));
02667 #endif
02668 if(restype) {
02669 TY_IDX itx = Get_TY(restype);
02670 ret_dst = TYPE_DST_IDX(restype);
02671 }
02672
02673 tree type = TREE_TYPE(fndecl);
02674 if(type) {
02675 tree arg_types = TYPE_ARG_TYPES(type);
02676 if(arg_types) {
02677 is_prototyped = TRUE;
02678 }
02679 }
02680 }
02681
02682
02683 #ifndef KEY
02684 char * basename =
02685 IDENTIFIER_POINTER (DECL_NAME (fndecl));
02686 #else
02687 char * basename;
02688 if (fndecl)
02689 basename = IDENTIFIER_POINTER (DECL_NAME (fndecl));
02690 else
02691 basename = ST_name(func_st);
02692 #endif
02693 char * linkage_name = ST_name(func_st);
02694 #ifdef KEY
02695
02696 if (Debug_Level > 0 && fndecl &&
02697 IDENTIFIER_OPNAME_P (DECL_NAME(fndecl)) &&
02698 IDENTIFIER_TYPENAME_P (DECL_NAME(fndecl))) {
02699 basename = cplus_demangle(linkage_name, DMGL_PARAMS | DMGL_ANSI |
02700 DMGL_TYPES);
02701 if (basename) {
02702 basename = strstr(basename, "operator ");
02703 FmtAssert(basename, ("NYI"));
02704 } else {
02705
02706
02707
02708
02709
02710
02711
02712
02713 DevWarn(
02714 "encountered a mangled name that can not be demangled using c++filt");
02715 basename = IDENTIFIER_POINTER (DECL_NAME (fndecl));
02716 }
02717 }
02718 #endif
02719
02720 char * funcname = basename;
02721 int is_abstract_root = 0;
02722 DST_INFO_IDX class_func_idx = DST_INVALID_INIT;
02723 int class_func_found_member = 0;
02724 #ifdef KEY
02725 tree context = NULL;
02726 if (fndecl) context = DECL_CONTEXT(fndecl);
02727 #else
02728 tree context = DECL_CONTEXT(fndecl);
02729 #endif
02730 if(context && TREE_CODE(context) == RECORD_TYPE) {
02731
02732 class_func_idx =
02733 DST_find_class_member(linkage_name, context);
02734 if(!DST_IS_NULL(class_func_idx)) {
02735 class_func_found_member = 1;
02736 funcname = 0;
02737
02738
02739
02740 USRCPOS_clear(src);
02741 }
02742
02743
02744
02745 char *classname = Get_Name(context);
02746 if(classname && !class_func_found_member) {
02747 int len = strlen(classname);
02748 char* newname = new char[len+5
02749 ];
02750
02751
02752
02753 strcpy(newname,classname);
02754 strcpy(newname+len,"::");
02755 if(funcname) {
02756
02757
02758
02759 funcname = Index_To_Str(Save_Str2(newname,funcname));
02760 }
02761
02762 delete [] newname;
02763 }
02764 }
02765
02766 linkage_name = ST_name(func_st);
02767 ST_IDX fstidx = ST_st_idx(func_st);
02768
02769 dst = DST_mk_subprogram(
02770 src,
02771 funcname,
02772 ret_dst,
02773 DST_INVALID_IDX,
02774 fstidx,
02775 DW_INL_not_inlined,
02776 DW_VIRTUALITY_none,
02777 0,
02778 FALSE,
02779 #ifdef KEY
02780 FALSE,
02781 #endif
02782 is_prototyped,
02783 ! ST_is_export_local(func_st) );
02784
02785 DST_RESET_assoc_fe (DST_INFO_flag(DST_INFO_IDX_TO_PTR(dst)));
02786 DST_append_child (current_scope_idx, dst);
02787
02788 if(class_func_found_member) {
02789 DST_add_specification_to_subprogram(dst, class_func_idx);
02790 }
02791
02792 if(linkage_name && funcname && strcmp(linkage_name,funcname)) {
02793
02794 DST_add_linkage_name_to_subprogram(dst, linkage_name);
02795 }
02796 if( !DST_IS_NULL(DECL_DST_ABSTRACT_ROOT_IDX(fndecl))) {
02797
02798 DevWarn("Concrete function instance has abstract root! %s\n",
02799 basename);
02800 }
02801
02802
02803 if(fndecl) {
02804 DECL_DST_IDX(fndecl) = dst;
02805 }
02806
02807
02808
02809
02810 #ifndef KEY
02811 if(is_prototyped) {
02812 #else
02813
02814
02815
02816 if (fndecl) {
02817 #endif
02818 tree parms = DECL_ARGUMENTS(fndecl);
02819 if(!parms) {
02820
02821
02822
02823
02824 } else {
02825 DST_enter_param_vars(fndecl,
02826 dst,
02827 parms,
02828 0,
02829 0 );
02830 }
02831
02832 }
02833
02834 return dst;
02835 }
02836
02837 DST_INFO_IDX
02838 DST_Get_Comp_Unit (void)
02839 {
02840 return comp_unit_idx;
02841 }
02842
02843
02844
02845
02846 void
02847 DST_build(int num_copts,
02848 char *copts[])
02849 {
02850 char *src_path, *comp_info;
02851
02852 dst_initialized = TRUE;
02853
02854
02855 DST_Init (NULL, 0);
02856
02857
02858
02859
02860
02861
02862
02863 if (Orig_Src_File_Name != NULL)
02864 {
02865 src_path = Orig_Src_File_Name;
02866 }
02867
02868
02869
02870
02871
02872
02873
02874
02875 if (Debug_Level > 0)
02876 {
02877 int host_name_length = 0;
02878
02879 current_host_dir = &cwd_buffer[0];
02880 if (gethostname(current_host_dir, MAXHOSTNAMELEN) == 0)
02881 {
02882
02883 host_name_length = strlen(current_host_dir);
02884 if(strchr(current_host_dir,'.')) {
02885
02886
02887
02888 } else {
02889 current_host_dir[host_name_length] = '.';
02890 if (getdomainname(¤t_host_dir[host_name_length+1],
02891 MAXHOSTNAMELEN-host_name_length) == 0)
02892 {
02893
02894 host_name_length += strlen(¤t_host_dir[host_name_length]);
02895 }
02896 }
02897
02898 }
02899 current_host_dir[host_name_length++] = ':';
02900 current_working_dir = &cwd_buffer[host_name_length];
02901 }
02902 else
02903 {
02904 current_host_dir = NULL;
02905 current_working_dir = &cwd_buffer[0];
02906 }
02907 strcpy(current_working_dir, Get_Current_Working_Directory());
02908 if (current_working_dir == NULL) {
02909 perror("getcwd");
02910 exit(2);
02911 }
02912
02913
02914 #ifndef KEY
02915 comp_info = DST_get_command_line_options(num_copts, copts);
02916 #else
02917 comp_info = (char *)malloc(sizeof(char)*100);
02918 #ifdef PSC_TO_OPEN64
02919 strcpy(comp_info, "openCC ");
02920 #endif
02921 if (INCLUDE_STAMP)
02922 strcat(comp_info, INCLUDE_STAMP);
02923 #endif
02924
02925 {
02926 comp_unit_idx = DST_mk_compile_unit((char*)dump_base_name,
02927 current_host_dir,
02928 comp_info,
02929 DW_LANG_C_plus_plus,
02930 DW_ID_case_sensitive);
02931 }
02932
02933 free(comp_info);
02934
02935 WFE_Set_Line_And_File (0, Orig_Src_File_Name);
02936 }
02937
02938 void
02939 WFE_Set_Line_And_File (UINT line, const char* f)
02940 {
02941 if (!dst_initialized) return;
02942
02943
02944
02945 char* file = const_cast<char*>(f);
02946
02947
02948 char *dir;
02949 char *file_name = drop_path(file);;
02950 char buf[256];
02951 if (file_name == file) {
02952
02953 #ifdef TARG_SL
02954
02955 dir = NULL;
02956 }
02957 #else
02958 dir = current_working_dir;
02959 }
02960 else if (strncmp(file, "./", 2) == 0) {
02961
02962 dir = current_working_dir;
02963 }
02964 #endif
02965 else {
02966
02967 strcpy (buf, file);
02968 dir = drop_path(buf);
02969 --dir;
02970 *dir = '\0';
02971 dir = buf;
02972 }
02973
02974 current_dir = Get_Dir_Dst_Info (dir);
02975 current_file = Get_File_Dst_Info (file_name, current_dir);
02976 }
02977
02978 #ifdef KEY
02979 void WFE_Macro_Define (UINT line, const char *buffer)
02980 {
02981 DST_mk_macr(line, (char *)buffer, 1 );
02982 return;
02983 }
02984
02985 void WFE_Macro_Undef (UINT line, const char *buffer)
02986 {
02987 DST_mk_macr(line, (char *)buffer, 2 );
02988 return;
02989 }
02990
02991 void WFE_Macro_Start_File (UINT line, UINT file)
02992 {
02993 DST_mk_macr_start_file(line, file);
02994 }
02995
02996 void WFE_Macro_End_File (void)
02997 {
02998 DST_mk_macr_end_file();
02999 }
03000 #endif