home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cplusplus-8 / cplus-field.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-20  |  17.7 KB  |  920 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*        cplus-field.c                        */
  4. /*                                    */
  5. /*    Code for handling XREF output from g++                */
  6. /*                                    */
  7. /************************************************************************/
  8.  
  9.  
  10. #ifdef FIELD_XREF
  11.  
  12. #include "config.h"
  13.  
  14. #include <stdio.h>
  15. #include <ctype.h>
  16. #include <strings.h>
  17.  
  18. #include "tree.h"
  19. #include "cplus-tree.h"
  20. #include "input.h"
  21.  
  22.  
  23.  
  24.  
  25. /************************************************************************/
  26. /*                                    */
  27. /*    Common definitions                        */
  28. /*                                    */
  29. /************************************************************************/
  30.  
  31. typedef int    Integer;
  32. typedef char *    String;
  33.  
  34.  
  35. #ifndef TRUE
  36. #define TRUE 1
  37. #endif
  38. #ifndef FALSE
  39. #define FALSE 0
  40. #endif
  41. #ifndef NULL
  42. #define NULL 0
  43. #endif
  44.  
  45.  
  46. #define PALLOC(typ) ((typ *) calloc(1,sizeof(typ)))
  47.  
  48.  
  49. #define SALLOC(str) ((String) ((str == NULL) ? NULL : (strcpy(malloc(strlen(str)+1),str))))
  50. #define SFREE(str) (str != NULL && (free(str),0))
  51.  
  52. #define STREQL(s1,s2) (strcmp((s1),(s2)) == 0)
  53. #define STRNEQ(s1,s2) (strcmp((s1),(s2)) != 0)
  54. #define STRLSS(s1,s2) (strcmp((s1),(s2)) < 0)
  55. #define STRLEQ(s1,s2) (strcmp((s1),(s2)) <= 0)
  56. #define STRGTR(s1,s2) (strcmp((s1),(s2)) > 0)
  57. #define STRGEQ(s1,s2) (strcmp((s1),(s2)) >= 0)
  58.  
  59.  
  60.  
  61.  
  62.  
  63. /************************************************************************/
  64. /*                                    */
  65. /*    Type definitions                        */
  66. /*                                    */
  67. /************************************************************************/
  68.  
  69.  
  70. typedef struct _XREF_FILE *    XREF_FILE;
  71. typedef struct _XREF_SCOPE *    XREF_SCOPE;
  72.  
  73.  
  74.  
  75. typedef struct _XREF_FILE {
  76.    String name;
  77.    XREF_FILE next;
  78. } XREF_FILE_INFO;
  79.  
  80.  
  81.  
  82.  
  83.  
  84. typedef struct _XREF_SCOPE {
  85.    Integer gid;
  86.    Integer lid;
  87.    XREF_FILE file;
  88.    Integer start;
  89.    XREF_SCOPE outer;
  90. } XREF_SCOPE_INFO;
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. /************************************************************************/
  98. /*                                    */
  99. /*    Local storage                            */
  100. /*                                    */
  101. /************************************************************************/
  102.  
  103.  
  104. static    char        doing_xref = 0;
  105. static    FILE *        xref_file = NULL;
  106. static    char        xref_name[1024];
  107. static    XREF_FILE    all_files = NULL;
  108. static    String        wd_name = NULL;
  109. static    XREF_SCOPE    cur_scope = NULL;
  110. static    Integer     scope_ctr = 0;
  111. static    XREF_FILE    last_file = NULL;
  112. static    tree        last_fct = NULL;
  113.  
  114.  
  115.  
  116.  
  117. /************************************************************************/
  118. /*                                    */
  119. /*    Forward definitions                        */
  120. /*                                    */
  121. /************************************************************************/
  122.  
  123.  
  124. extern    void        FIELD_xref_begin();
  125. extern    void        FIELD_xref_end();
  126. extern    void        FIELD_xref_file();
  127. extern    void        FIELD_xref_start_scope();
  128. extern    void        FIELD_xref_end_scope();
  129. extern    void        FIELD_xref_ref();
  130. extern    void        FIELD_xref_decl();
  131. extern    void        FIELD_xref_call();
  132. extern    void        FIELD_xref_function();
  133. extern    void        FIELD_xref_assign();
  134. extern    void        FIELD_xref_hier();
  135. extern    void        FIELD_xref_member();
  136.  
  137.  
  138. static    void        gen_assign();
  139. static    XREF_FILE    find_file();
  140. static    String        filename();
  141. static    String        fctname();
  142. static    String        declname();
  143. static    void        simplify_type();
  144. static    String        fixname();
  145. static    void        open_xref_file();
  146.  
  147. extern    char *        type_as_string();
  148.  
  149.  
  150.  
  151.  
  152. /************************************************************************/
  153. /*                                    */
  154. /*    FIELD_xref_begin -- start cross referencing            */
  155. /*                                    */
  156. /************************************************************************/
  157.  
  158.  
  159. void
  160. FIELD_xref_begin(file)
  161.    String file;
  162. {
  163.    String s,t;
  164.  
  165.    doing_xref = 1;
  166.  
  167.    if (file != NULL && STRNEQ(file,"-")) {
  168.       open_xref_file(file);
  169.       FIELD_xref_file(file);
  170.     };
  171. };
  172.  
  173.  
  174.  
  175.  
  176.  
  177. /************************************************************************/
  178. /*                                    */
  179. /*    FIELD_xref_end -- finish cross referencing            */
  180. /*                                    */
  181. /************************************************************************/
  182.  
  183.  
  184. void
  185. FIELD_xref_end(ect)
  186.    int ect;
  187. {
  188.    XREF_FILE xf;
  189.  
  190.    if (!doing_xref) return;
  191.  
  192.    xf = find_file(input_filename);
  193.    if (xf == NULL) return;
  194.  
  195.    while (cur_scope != NULL) {
  196.       FIELD_xref_end_scope(cur_scope->gid,0,0,0,0);
  197.     };
  198.  
  199.    doing_xref = 0;
  200.  
  201.    if (xref_file == NULL) return;
  202.  
  203.    fclose(xref_file);
  204.  
  205.    xref_file = NULL;
  206.    all_files = NULL;
  207.  
  208.    if (ect > 0) unlink(xref_name);
  209. };
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216. /************************************************************************/
  217. /*                                    */
  218. /*    FIELD_xref_file -- handle file xrefing                */
  219. /*                                    */
  220. /************************************************************************/
  221.  
  222.  
  223. void
  224. FIELD_xref_file(name)
  225.    String name;
  226. {
  227.    XREF_FILE xf;
  228.    char wdbuf[1024];
  229.  
  230.    if (!doing_xref || name == NULL) return;
  231.  
  232.    if (xref_file == NULL) {
  233.       open_xref_file(name);
  234.       if (!doing_xref) return;
  235.     };
  236.  
  237.    if (all_files == NULL) {
  238.       fprintf(xref_file,"SCP * 0 0 0 0 RESET\n");
  239.     };
  240.  
  241.    xf = find_file(name);
  242.    if (xf != NULL) return;
  243.  
  244.    xf = PALLOC(XREF_FILE_INFO);
  245.    xf->name = SALLOC(name);
  246.    xf->next = all_files;
  247.    all_files = xf;
  248.  
  249.    if (wd_name == NULL) {
  250.       getwd(wdbuf);
  251.       wd_name = SALLOC(wdbuf);
  252.     };
  253.  
  254.    fprintf(xref_file,"FIL %s %s 0\n",name,wd_name);
  255.  
  256.    filename(xf);
  257.    fctname(NULL);
  258. };
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265. /************************************************************************/
  266. /*                                    */
  267. /*    FIELD_xref_start_scope -- begin a scope             */
  268. /*    FIELD_xref_end_scope -- finish a scope                */
  269. /*                                    */
  270. /************************************************************************/
  271.  
  272.  
  273. void
  274. FIELD_xref_start_scope(id)
  275.    Integer id;
  276. {
  277.    XREF_SCOPE xs;
  278.    XREF_FILE xf;
  279.  
  280.    if (!doing_xref) return;
  281.    xf = find_file(input_filename);
  282.  
  283.    xs = PALLOC(XREF_SCOPE_INFO);
  284.    xs->file = xf;
  285.    xs->start = lineno;
  286.    if (xs->start <= 0) xs->start = 1;
  287.    xs->gid = id;
  288.    xs->lid = ++scope_ctr;
  289.    xs->outer = cur_scope;
  290.    cur_scope = xs;
  291. };
  292.  
  293.  
  294.  
  295.  
  296.  
  297. void
  298. FIELD_xref_end_scope(id,inid,prm,keep,trns)
  299.    Integer id;
  300.    Integer inid;
  301.    Integer prm,keep,trns;
  302. {
  303.    XREF_FILE xf;
  304.    XREF_SCOPE xs,lxs,oxs;
  305.    String stype;
  306.  
  307.    if (!doing_xref) return;
  308.    xf = find_file(input_filename);
  309.    if (xf == NULL) return;
  310.  
  311.    lxs = NULL;
  312.    for (xs = cur_scope; xs != NULL; xs = xs->outer) {
  313.       if (xs->gid == id) break;
  314.       lxs = xs;
  315.     };
  316.    if (xs == NULL) return;
  317.  
  318.    if (inid != 0) {
  319.       for (oxs = cur_scope; oxs != NULL; oxs = oxs->outer) {
  320.      if (oxs->gid == inid) break;
  321.        };
  322.       if (oxs == NULL) return;
  323.       inid = oxs->lid;
  324.     };
  325.  
  326.    if (prm == 2) stype = "SUE";
  327.    else if (prm != 0) stype = "ARGS";
  328.    else if (keep == 2 || inid != 0) stype = "INTERN";
  329.    else stype = "EXTERN";
  330.  
  331.    fprintf(xref_file,"SCP %s %d %d %d %d %s\n",
  332.           filename(xf),xs->start,lineno,xs->lid,inid,stype);
  333.  
  334.    if (lxs == NULL) cur_scope = xs->outer;
  335.    else lxs->outer = xs->outer;
  336.  
  337.    free(xs);
  338. };
  339.  
  340.  
  341.  
  342.  
  343.  
  344. /************************************************************************/
  345. /*                                    */
  346. /*    FIELD_xref_ref -- handle reference                */
  347. /*                                    */
  348. /************************************************************************/
  349.  
  350.  
  351. void
  352. FIELD_xref_ref(fct,name)
  353.    tree fct;
  354.    String name;
  355. {
  356.    XREF_FILE xf;
  357.  
  358.    if (!doing_xref) return;
  359.    xf = find_file(input_filename);
  360.    if (xf == NULL) return;
  361.  
  362.    fprintf(xref_file,"REF %s %d %s %s\n",
  363.           filename(xf),lineno,fctname(fct),name);
  364. };
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371. /************************************************************************/
  372. /*                                    */
  373. /*    FIELD_xref_decl -- handle declaration                */
  374. /*                                    */
  375. /************************************************************************/
  376.  
  377.  
  378. void
  379. FIELD_xref_decl(fct,decl)
  380.    tree fct;
  381.    tree decl;
  382. {
  383.    XREF_FILE xf;
  384.    String cls;
  385.    String name;
  386.    char buf[10240];
  387.  
  388.    if (!doing_xref) return;
  389.    xf = find_file(input_filename);
  390.    if (xf == NULL) return;
  391.  
  392.    if (DECL_NAME(decl) == NULL) return;
  393.  
  394.    if (TREE_CODE(decl) == TYPE_DECL) cls = "TYPEDEF";
  395.    else if (TREE_CODE(decl) == FIELD_DECL) cls = "FIELD";
  396.    else if (TREE_CODE(decl) == VAR_DECL) {
  397.       if (fct == NULL && TREE_STATIC(decl) &&
  398.          TREE_READONLY(decl) && DECL_INITIAL(decl) != 0 &&
  399.          !TREE_PUBLIC(decl) && !TREE_EXTERNAL(decl) &&
  400.          DECL_MODE(decl) != BLKmode) cls = "CONST";
  401.       else if (TREE_EXTERNAL(decl)) cls = "EXTERN";
  402.       else if (TREE_PUBLIC(decl)) cls = "EXTDEF";
  403.       else if (TREE_STATIC(decl)) cls = "STATIC";
  404.       else if (TREE_REGDECL(decl)) cls = "REGISTER";
  405.       else cls = "AUTO";
  406.     }
  407.    else if (TREE_CODE(decl) == PARM_DECL) cls = "PARAM";
  408.    else if (TREE_CODE(decl) == FIELD_DECL) cls = "FIELD";
  409.    else if (TREE_CODE(decl) == CONST_DECL) cls = "CONST";
  410.    else if (TREE_CODE(decl) == FUNCTION_DECL) {
  411.       if (TREE_EXTERNAL(decl)) cls = "EXTERN";
  412.       else if (TREE_PUBLIC(decl)) cls = "EFUNCTION";
  413.       else cls = "SFUNCTION";
  414.     }
  415.    else if (TREE_CODE(decl) == LABEL_DECL) cls = "LABEL";
  416.    else if (TREE_CODE(decl) == UNION_TYPE) {
  417.       cls = "UNIONID";
  418.       decl = TYPE_NAME(decl);
  419.     }
  420.    else if (TREE_CODE(decl) == RECORD_TYPE) {
  421.       if (CLASSTYPE_DECLARED_CLASS(decl)) cls = "CLASSID";
  422.       else cls = "STRUCTID";
  423.       decl = TYPE_NAME(decl);
  424.     }
  425.    else if (TREE_CODE(decl) == ENUMERAL_TYPE) {
  426.       cls = "ENUMID";
  427.       decl = TYPE_NAME(decl);
  428.     }
  429.    else cls = "UNKNOWN";
  430.  
  431.    name = IDENTIFIER_POINTER(DECL_NAME(decl));
  432.  
  433.    type_as_string(buf,TREE_TYPE(decl));
  434.    simplify_type(buf);
  435.  
  436.    fprintf(xref_file,"DCL %s %d %s %d %s %s %s\n",
  437.           filename(xf),lineno,name,
  438.           (cur_scope != NULL ? cur_scope->lid : 0),
  439.           cls,fctname(fct),buf);
  440. };
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447. /************************************************************************/
  448. /*                                    */
  449. /*    FIELD_xref_call -- handle call                    */
  450. /*                                    */
  451. /************************************************************************/
  452.  
  453.  
  454. void
  455. FIELD_xref_call(fct,name)
  456.    tree fct;
  457.    String name;
  458. {
  459.    XREF_FILE xf;
  460.    char buf[1024];
  461.  
  462.    if (!doing_xref) return;
  463.    xf = find_file(input_filename);
  464.    if (xf == NULL) return;
  465.    name = fixname(name,buf);
  466.  
  467.    fprintf(xref_file,"CAL %s %d %s %s\n",
  468.           filename(xf),lineno,name,fctname(fct));
  469. };
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476. /************************************************************************/
  477. /*                                    */
  478. /*    FIELD_xref_function -- handle functions             */
  479. /*                                    */
  480. /************************************************************************/
  481.  
  482.  
  483. void
  484. FIELD_xref_function(fct,args)
  485.    tree fct;
  486.    tree args;
  487. {
  488.    XREF_FILE xf;
  489.    int ct;
  490.    char buf[1024];
  491.  
  492.    if (!doing_xref) return;
  493.    xf = find_file(input_filename);
  494.    if (xf == NULL) return;
  495.  
  496.    ct = 0;
  497.    buf[0] = 0;
  498.    if (args == NULL) args = DECL_ARGUMENTS(fct);
  499.  
  500.    FIELD_xref_decl(NULL,fct);
  501.  
  502.    for ( ; args != NULL; args = TREE_CHAIN(args)) {
  503.       FIELD_xref_decl(fct,args);
  504.       if (ct != 0) strcat(buf,",");
  505.       strcat(buf,declname(args));
  506.       ++ct;
  507.     };
  508.  
  509.    fprintf(xref_file,"PRC %s %d %s %d %d %s\n",
  510.           filename(xf),lineno,declname(fct),
  511.           (cur_scope != NULL ? cur_scope->lid : 0),
  512.           ct,buf);
  513. };
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520. /************************************************************************/
  521. /*                                    */
  522. /*    FIELD_xref_assign -- handle assignment                */
  523. /*                                    */
  524. /************************************************************************/
  525.  
  526.  
  527. void
  528. FIELD_xref_assign(name)
  529.    tree name;
  530. {
  531.    XREF_FILE xf;
  532.  
  533.    if (!doing_xref) return;
  534.    xf = find_file(input_filename);
  535.    if (xf == NULL) return;
  536.  
  537.    gen_assign(xf,name);
  538. };
  539.  
  540.  
  541.  
  542. static void
  543. gen_assign(xf,name)
  544.    XREF_FILE xf;
  545.    tree name;
  546. {
  547.    String s;
  548.  
  549.    s = NULL;
  550.  
  551.    switch (TREE_CODE(name)) {
  552.       case IDENTIFIER_NODE :
  553.      s = IDENTIFIER_POINTER(name);
  554.      break;
  555.       case VAR_DECL :
  556.      s = declname(name);
  557.      break;
  558.       case COMPONENT_REF :
  559.      gen_assign(xf,TREE_OPERAND(name,0));
  560.      gen_assign(xf,TREE_OPERAND(name,1));
  561.      break;
  562.       case INDIRECT_REF :
  563.       case OFFSET_REF :
  564.       case ARRAY_REF :
  565.       case BUFFER_REF :
  566.      gen_assign(xf,TREE_OPERAND(name,0));
  567.      break;
  568.       case COMPOUND_EXPR :
  569.      gen_assign(xf,TREE_OPERAND(name,1));
  570.      break;
  571.       default :
  572.      break;
  573.     };
  574.  
  575.    if (s != NULL) {
  576.       fprintf(xref_file,"ASG %s %d %s\n",filename(xf),lineno,s);
  577.     };
  578. };
  579.  
  580.  
  581.  
  582.  
  583.  
  584. /************************************************************************/
  585. /*                                    */
  586. /*    FIELD_xref_hier -- handle hierarchy                */
  587. /*                                    */
  588. /************************************************************************/
  589.  
  590.  
  591. void
  592. FIELD_xref_hier(cls,base,pub,virt,frnd)
  593.    String cls;
  594.    String base;
  595.    int pub;
  596.    int virt;
  597.    int frnd;
  598. {
  599.    XREF_FILE xf;
  600.  
  601.    if (!doing_xref) return;
  602.    xf = find_file(input_filename);
  603.    if (xf == NULL) return;
  604.  
  605.    fprintf(xref_file,"HIE %s %d %s %s %d %d %d\n",
  606.           filename(xf),lineno,cls,base,pub,virt,frnd);
  607. };
  608.  
  609.  
  610.  
  611.  
  612.  
  613. /************************************************************************/
  614. /*                                    */
  615. /*    FIELD_xref_member -- handle member                */
  616. /*                                    */
  617. /************************************************************************/
  618.  
  619.  
  620. void
  621. FIELD_xref_member(cls,fld)
  622.    tree cls;
  623.    tree fld;
  624. {
  625.    XREF_FILE xf;
  626.    String prot;
  627.    Integer confg,pure;
  628.    String d,p;
  629.    Integer i;
  630.    char buf[1024],bufa[1024];
  631.  
  632.    if (!doing_xref) return;
  633.    xf = find_file(fld->decl.filename);
  634.    if (xf == NULL) return;
  635.  
  636.    if (TREE_PRIVATE(fld)) prot = "PRIVATE";
  637.    else if (TREE_PROTECTED(fld)) prot = "PROTECTED";
  638.    else prot = "PUBLIC";
  639.  
  640.    confg = 0;
  641.    if (TREE_CODE(fld) == FUNCTION_DECL && DECL_CONST_MEMFUNC_P(fld)) confg = 1;
  642.    else if (TREE_CODE(fld) == CONST_DECL) confg = 1;
  643.  
  644.    pure = 0;
  645.    if (TREE_CODE(fld) == FUNCTION_DECL && DECL_ABSTRACT_VIRTUAL_P(fld)) pure = 1;
  646.  
  647.    d = IDENTIFIER_POINTER(cls);
  648.    sprintf(buf,"%d%s",strlen(d),d);
  649.    i = strlen(buf);
  650.    strcpy(bufa,declname(fld));
  651.    for (p = &bufa[1]; *p != 0; ++p) {
  652.       if (p[0] == '_' && p[1] == '_' && p[2] >= '0' && p[2] <= '9') {
  653.      if (strncmp(&p[2],buf,i) == 0) *p = 0;
  654.      break;
  655.        }
  656.       else if (p[0] == '_' && p[1] == '_' && p[2] == 'C' && p[3] >= '0' && p[3] <= '9') {
  657.      if (strncmp(&p[3],buf,i) == 0) *p = 0;
  658.      break;
  659.        };
  660.     };
  661.  
  662.    fprintf(xref_file,"MEM %s %d %s %s %s %d %d %d %d %d %d %d\n",
  663.           filename(xf),fld->decl.linenum,d,
  664.           bufa,
  665.           prot,
  666.           (TREE_CODE(fld) == FUNCTION_DECL ? 0 : 1),
  667.           (TREE_INLINE(fld) ? 1 : 0),
  668.           (DECL_FRIEND_P(fld) ? 1 : 0),
  669.           (DECL_VIRTUAL_P(fld) ? 1 : 0),
  670.           (TREE_STATIC(fld) ? 1 : 0),
  671.           pure,confg);
  672. };
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679. /************************************************************************/
  680. /*                                    */
  681. /*    find_file -- find file entry given name             */
  682. /*                                    */
  683. /************************************************************************/
  684.  
  685.  
  686.  
  687. static XREF_FILE
  688. find_file(name)
  689.    String name;
  690. {
  691.    XREF_FILE xf;
  692.  
  693.    for (xf = all_files; xf != NULL; xf = xf->next) {
  694.       if (STREQL(name,xf->name)) break;
  695.     };
  696.  
  697.    return xf;
  698. };
  699.  
  700.  
  701.  
  702.  
  703.  
  704. /************************************************************************/
  705. /*                                    */
  706. /*    filename -- return name for output                */
  707. /*                                    */
  708. /************************************************************************/
  709.  
  710.  
  711. static String
  712. filename(xf)
  713.    XREF_FILE xf;
  714. {
  715.    if (xf == NULL) {
  716.       last_file = NULL;
  717.       return "*";
  718.     };
  719.  
  720.    if (last_file == xf) return "*";
  721.  
  722.    last_file = xf;
  723.  
  724.    return xf->name;
  725. };
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732. /************************************************************************/
  733. /*                                    */
  734. /*    fctname -- return name for function                */
  735. /*                                    */
  736. /************************************************************************/
  737.  
  738.  
  739. static String
  740. fctname(fct)
  741.    tree fct;
  742. {
  743.    extern char * declname();
  744.    static char fctbuf[1024];
  745.    String s;
  746.  
  747.    if (fct == NULL && last_fct == NULL) return "*";
  748.  
  749.    if (fct == NULL) {
  750.       last_fct = NULL;
  751.       return "*TOP*";
  752.     };
  753.  
  754.    if (fct == last_fct) return "*";
  755.  
  756.    last_fct = fct;
  757.  
  758.    s = declname(fct);
  759.    s = fixname(s,fctbuf);
  760.  
  761.    return s;
  762. };
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769. /************************************************************************/
  770. /*                                    */
  771. /*    declname -- print name for declaration                */
  772. /*                                    */
  773. /************************************************************************/
  774.  
  775.  
  776. static String
  777. declname(dcl)
  778.    tree dcl;
  779. {
  780.    if (DECL_NAME(dcl) == NULL) return "?";
  781.  
  782.    return IDENTIFIER_POINTER (DECL_NAME (dcl));
  783. }
  784.  
  785.  
  786.  
  787.  
  788.  
  789. /************************************************************************/
  790. /*                                    */
  791. /*    simplify_type -- simplify a type string             */
  792. /*                                    */
  793. /************************************************************************/
  794.  
  795.  
  796. static void
  797. simplify_type(typ)
  798.    String typ;
  799. {
  800.    String s;
  801.    Integer lvl,i;
  802.  
  803.    i = strlen(typ);
  804.    while (i > 0 && isspace(typ[i-1])) typ[--i] = 0;
  805.  
  806.    if (i > 7 && STREQL(&typ[i-5],"const")) {
  807.       typ[i-5] = 0;
  808.       i -= 5;
  809.     };
  810.  
  811.    if (typ[i-1] != ')') return;
  812.  
  813.    s = &typ[i-2];
  814.    lvl = 1;
  815.    while (*s != 0) {
  816.       if (*s == ')') ++lvl;
  817.       else if (*s == '(') {
  818.      --lvl;
  819.      if (lvl == 0) {
  820.         s[1] = ')';
  821.         s[2] = 0;
  822.         break;
  823.       };
  824.        };
  825.       --s;
  826.     };
  827.  
  828.    if (*s != 0 && s[-1] == ')') {
  829.       --s;
  830.       --s;
  831.       if (*s == '(') s[2] = 0;
  832.       else if (*s == ':') {
  833.      while (*s != '(') --s;
  834.      s[1] = ')';
  835.      s[2] = 0;
  836.        };
  837.     };
  838. };
  839.  
  840.  
  841.  
  842.  
  843.  
  844. /************************************************************************/
  845. /*                                    */
  846. /*    fixname -- fixup a function name (take care of embedded spaces    */
  847. /*                                    */
  848. /************************************************************************/
  849.  
  850.  
  851. static String
  852. fixname(nam,buf)
  853.    String nam;
  854.    String buf;
  855. {
  856.    String s,t;
  857.    int fg;
  858.  
  859.    s = nam;
  860.    t = buf;
  861.    fg = 0;
  862.  
  863.    while (*s != 0) {
  864.       if (*s == ' ') {
  865.      *t++ = '\36';
  866.      ++fg;
  867.        }
  868.       else *t++ = *s;
  869.       ++s;
  870.     };
  871.  
  872.    if (fg == 0) return nam;
  873.  
  874.    return buf;
  875. };
  876.  
  877.  
  878.  
  879.  
  880.  
  881. /************************************************************************/
  882. /*                                    */
  883. /*    open_xref_file -- open file for xrefing             */
  884. /*                                    */
  885. /************************************************************************/
  886.  
  887.  
  888. static void
  889. open_xref_file(file)
  890.    String file;
  891. {
  892.    String s,t;
  893.  
  894.    s = rindex(file,'/');
  895.    if (s == NULL) sprintf(xref_name,".%s.gxref",file);
  896.    else {
  897.       ++s;
  898.       strcpy(xref_name,file);
  899.       t = rindex(xref_name,'/');
  900.       ++t;
  901.       *t++ = '.';
  902.       strcpy(t,s);
  903.       strcat(t,".gxref");
  904.     };
  905.  
  906.    xref_file = fopen(xref_name,"w");
  907.  
  908.    if (xref_file == NULL) {
  909.       error("Can't create cross-reference file `%s'",xref_name);
  910.       doing_xref = 0;
  911.     };
  912. };
  913.  
  914.  
  915.  
  916. #endif
  917.  
  918.  
  919. /* end of cplus-field.c */
  920.