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