home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / cplus-edsel.c < prev    next >
C/C++ Source or Header  |  1991-06-03  |  20KB  |  939 lines

  1. /* Interface to LUCID Cadillac system for GNU compiler.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "config.h"
  21.  
  22. #include "tree.h"
  23. #include "flags.h"
  24. #include "cplus-tree.h"
  25. #include "assert.h"
  26. #include <stdio.h>
  27. #include "obstack.h"
  28.  
  29. #ifdef CADILLAC
  30. #include <compilerreq.h>
  31. #include <compilerconn.h>
  32. #include <sys/time.h>
  33. #include <sys/types.h>
  34. #include <errno.h>
  35. #include <sys/file.h>
  36.  
  37. #define obstack_chunk_alloc xmalloc
  38. #define obstack_chunk_free free
  39.  
  40. extern int xmalloc ();
  41. extern void free ();
  42.  
  43. void init_cadillac ();
  44.  
  45. extern char *input_filename;
  46. extern int lineno;
  47.  
  48. /* Put random information we might want to get back from
  49.    Cadillac here.  */
  50. typedef struct
  51. {
  52.   /* The connection to the Cadillac kernel.  */
  53.   Connection *conn;
  54.  
  55.   /* Input and output file descriptors for Cadillac.  */
  56.   short fd_input, fd_output;
  57.  
  58.   /* #include nesting of current file.  */
  59.   short depth;
  60.  
  61.   /* State variables for the connection.  */
  62.   char messages;
  63.   char conversion;
  64.   char emission;
  65.   char process_until;
  66.  
  67.   /* #if level of current file.  */
  68.   int iflevel;
  69.  
  70.   /* Line number that starts current source file.  */
  71.   int lineno;
  72.  
  73.   /* Name of current file.  */
  74.   char *filename;
  75.  
  76.   /* Where to stop processing (if process_until is set).  */
  77.   char *end_filename;
  78.   int end_position;
  79.  
  80. } cadillac_struct;
  81. static cadillac_struct cadillacObj;
  82.  
  83. /* Nonzero if in the process of exiting.  */
  84. static int exiting;
  85.  
  86. void cadillac_note_source ();
  87. static void CWriteLanguageDecl ();
  88. static void CWriteLanguageType ();
  89. static void CWriteTopLevel ();
  90. static void cadillac_note_filepos ();
  91. static void cadillac_process_request (), cadillac_process_requests ();
  92. static void cadillac_switch_source ();
  93. static void exit_cadillac ();
  94.  
  95. /* Blocking test.  */
  96. static int
  97. readable_p (fd)
  98.      int fd;
  99. {
  100.   fd_set f;
  101.  
  102.   FD_ZERO (&f);
  103.   FD_SET (fd, &f);
  104.  
  105.   return select (32, &f, NULL, NULL, 0) == 1;
  106. }
  107.  
  108. static CObjectType *tree_to_cadillac_map;
  109. struct obstack cadillac_obstack;
  110.  
  111.  
  112. #include "stack.h"
  113.  
  114. struct context_level
  115. {
  116.   struct stack_level base;
  117.  
  118.   tree context;
  119. };
  120.  
  121. /* Stack for maintaining contexts (in case functions or types are nested).
  122.    When defining a struct type, the `context' field is the RECORD_TYPE.
  123.    When defining a function, the `context' field is the FUNCTION_DECL.  */
  124.  
  125. static struct context_level *context_stack;
  126.  
  127. static struct context_level *
  128. push_context_level (stack, obstack)
  129.      struct stack_level *stack;
  130.      struct obstack *obstack;
  131. {
  132.   struct context_level tem;
  133.  
  134.   tem.base.prev = stack;
  135.   return (struct context_level *)push_stack_level (obstack, &tem, sizeof (tem));
  136. }
  137.  
  138. /* Discard a level of search allocation.  */
  139.  
  140. static struct context_level *
  141. pop_context_level (stack)
  142.      struct context_level *stack;
  143. {
  144.   stack = (struct context_level *)pop_stack_level (stack);
  145.   return stack;
  146. }
  147.  
  148. void
  149. init_cadillac ()
  150. {
  151.   extern FILE *finput;
  152.   extern int errno;
  153.   CCompilerMessage* req;
  154.   cadillac_struct *cp = &cadillacObj;
  155.   int i;
  156.  
  157.   if (! flag_cadillac)
  158.     return;
  159.  
  160.   tree_to_cadillac_map = (CObjectType*) xmalloc (sizeof (CObjectType) * LAST_CPLUS_TREE_CODE);
  161.   for (i = 0; i < LAST_CPLUS_TREE_CODE; i++)
  162.     tree_to_cadillac_map[i] = MiscOType;
  163.   tree_to_cadillac_map[RECORD_TYPE] = StructOType;
  164.   tree_to_cadillac_map[UNION_TYPE] = UnionOType;
  165.   tree_to_cadillac_map[ENUMERAL_TYPE] = EnumTypeOType;
  166.   tree_to_cadillac_map[TYPE_DECL] = TypedefOType;
  167.   tree_to_cadillac_map[VAR_DECL] = VariableOType;
  168.   tree_to_cadillac_map[CONST_DECL] = EnumConstantOType;
  169.   tree_to_cadillac_map[FUNCTION_DECL] = FunctionOType;
  170.   tree_to_cadillac_map[FIELD_DECL] = FieldOType;
  171.  
  172. #ifdef sun
  173.   on_exit (&exit_cadillac, 0);
  174. #endif
  175.  
  176.   gcc_obstack_init (&cadillac_obstack);
  177.  
  178.   /* Yow!  This is the way Cadillac was designed to deal with
  179.      Oregon C++ compiler!  */
  180.   cp->fd_input = flag_cadillac;
  181.   cp->fd_output = flag_cadillac;
  182.  
  183.   /* Start in "turned-on" state.  */
  184.   cp->messages = 1;
  185.   cp->conversion = 1;
  186.   cp->emission = 1;
  187.  
  188.   /* Establish a connection with Cadillac here.  */
  189.   cp->conn = NewConnection (cp, cp->fd_input, cp->fd_output);
  190.  
  191.   CWriteHeader (cp->conn, WaitingMType, 0);
  192.   CWriteRequestBuffer (cp->conn);
  193.  
  194.   if (!readable_p (cp->fd_input))
  195.     ;
  196.  
  197.   req = CReadCompilerMessage (cp->conn);
  198.  
  199.   if (!req)
  200.     switch (errno)
  201.       {
  202.       case EWOULDBLOCK:
  203.     sleep (5);
  204.     return;
  205.       
  206.       case 0:
  207.     fatal ("init_cadillac: EOF on connection to kernel, exiting\n");
  208.     break;
  209.  
  210.       default:
  211.     perror ("Editor to kernel connection");
  212.     exit (0);
  213.       }
  214. }
  215.  
  216. static void
  217. cadillac_process_requests (conn)
  218.      Connection *conn;
  219. {
  220.   CCompilerMessage *req;
  221.   while (req = (CCompilerMessage*) CPeekNextRequest (conn))
  222.     {
  223.       req = CReadCompilerMessage (conn);
  224.       cadillac_process_request (&cadillacObj, req);
  225.     }
  226. }
  227.  
  228. static void
  229. cadillac_process_request (cp, req)
  230.      cadillac_struct *cp;
  231.      CCompilerMessage *req;
  232. {
  233.   if (! req)
  234.     return;
  235.  
  236.   switch (req->reqType)
  237.     {
  238.     case ProcessUntilMType:
  239.       if (cp->process_until)
  240.     abort ();
  241.       cp->process_until = 1;
  242.       /* This is not really right.  */
  243.       cp->end_position = ((CCompilerCommand*)req)->processuntil.position;
  244. #if 0
  245.       cp->end_filename = req->processuntil.filename;
  246. #endif
  247.       break;
  248.  
  249.     case CommandMType:
  250.       switch (req->header.data)
  251.     {
  252.     case MessagesOnCType:
  253.       cp->messages = 1;
  254.       break;
  255.     case MessagesOffCType:
  256.       cp->messages = 0;
  257.       break;
  258.     case ConversionOnCType:
  259.       cp->conversion = 1;
  260.       break;
  261.     case ConversionOffCType:
  262.       cp->conversion = 0;
  263.       break;
  264.     case EmissionOnCType:
  265.       cp->emission = 1;
  266.       break;
  267.     case EmissionOffCType:
  268.       cp->emission = 0;
  269.       break;
  270.  
  271.     case FinishAnalysisCType:
  272.       return;
  273.  
  274.     case PuntAnalysisCType:
  275.     case ContinueAnalysisCType:
  276.     case GotoFileposCType:
  277.     case OpenSucceededCType:
  278.     case OpenFailedCType:
  279.       fprintf (stderr, "request type %d not implemented\n", req->reqType);
  280.       return;
  281.  
  282.     case DieCType:
  283.       if (! exiting)
  284.         abort ();
  285.       return;
  286.  
  287.     }
  288.       break;
  289.  
  290.     default:
  291.       fatal ("unknown request type %d", req->reqType);
  292.     }
  293. }
  294.  
  295. void
  296. cadillac_start ()
  297. {
  298.   Connection *conn = cadillacObj.conn;
  299.   CCompilerMessage *req;
  300.  
  301.   /* Let Cadillac know that we start in C++ language scope.  */
  302.   CWriteHeader (conn, ForeignLinkageMType, LinkCPlus);
  303.   CWriteLength (conn);
  304.   CWriteRequestBuffer (conn);
  305.  
  306.   cadillac_process_requests (conn);
  307. }
  308.  
  309. static void
  310. cadillac_printf (msg, name)
  311. {
  312.   if (cadillacObj.messages)
  313.     printf ("[%s,%4d] %s `%s'\n", input_filename, lineno, msg, name);
  314. }
  315.  
  316. void
  317. cadillac_start_decl (decl)
  318.      tree decl;
  319. {
  320.   Connection *conn = cadillacObj.conn;
  321.   CObjectType object_type = tree_to_cadillac_map [TREE_CODE (decl)];
  322.  
  323.   if (context_stack)
  324.     switch (TREE_CODE (context_stack->context))
  325.       {
  326.       case FUNCTION_DECL:
  327.     /* Currently, cadillac only implements top-level forms.  */
  328.     return;
  329.       case RECORD_TYPE:
  330.       case UNION_TYPE:
  331.     cadillac_printf ("start class-level decl", IDENTIFIER_POINTER (DECL_NAME (decl)));
  332.     break;
  333.       default:
  334.     abort ();
  335.       }
  336.   else
  337.     {
  338.       cadillac_printf ("start top-level decl", IDENTIFIER_POINTER (DECL_NAME (decl)));
  339.       CWriteTopLevel (conn, StartMType);
  340.     }
  341.  
  342.   CWriteLanguageDecl (conn, decl, tree_to_cadillac_map[TREE_CODE (decl)]);
  343.   CWriteRequestBuffer (conn);
  344.   cadillac_process_requests (conn);
  345. }
  346.  
  347. void
  348. cadillac_finish_decl (decl)
  349.      tree decl;
  350. {
  351.   Connection *conn = cadillacObj.conn;
  352.  
  353.   if (context_stack)
  354.     switch (TREE_CODE (context_stack->context))
  355.       {
  356.       case FUNCTION_DECL:
  357.     return;
  358.       case RECORD_TYPE:
  359.       case UNION_TYPE:
  360.     cadillac_printf ("end class-level decl", IDENTIFIER_POINTER (DECL_NAME (decl)));
  361.     CWriteHeader (conn, EndDefMType, 0);
  362.     CWriteLength (conn);
  363.     break;
  364.       default:
  365.     abort ();
  366.       }
  367.   else
  368.     {
  369.       cadillac_printf ("end top-level decl", IDENTIFIER_POINTER (DECL_NAME (decl)));
  370.       CWriteHeader (conn, EndDefMType, 0);
  371.       CWriteLength (conn);
  372.       CWriteTopLevel (conn, StopMType);
  373.     }
  374.  
  375.   CWriteRequestBuffer (conn);
  376.   cadillac_process_requests (conn);
  377. }
  378.  
  379. void
  380. cadillac_start_function (fndecl)
  381.      tree fndecl;
  382. {
  383.   Connection *conn = cadillacObj.conn;
  384.  
  385.   if (context_stack)
  386.     /* nested functions not yet handled.  */
  387.     abort ();
  388.  
  389.   cadillac_printf ("start top-level function", lang_printable_name (fndecl));
  390.   context_stack = push_context_level (context_stack, &cadillac_obstack);
  391.   context_stack->context = fndecl;
  392.  
  393.   CWriteTopLevel (conn, StartMType);
  394.   assert (TREE_CODE (fndecl) == FUNCTION_DECL);
  395.   CWriteLanguageDecl (conn, fndecl,
  396.               (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE
  397.                ? MemberFnOType : FunctionOType));
  398.   CWriteRequestBuffer (conn);
  399.   cadillac_process_requests (conn);
  400. }
  401.  
  402. void
  403. cadillac_finish_function (fndecl)
  404.      tree fndecl;
  405. {
  406.   Connection *conn = cadillacObj.conn;
  407.  
  408.   cadillac_printf ("end top-level function", lang_printable_name (fndecl));
  409.   context_stack = pop_context_level (context_stack);
  410.  
  411.   if (context_stack)
  412.     /* nested functions not yet implemented.  */
  413.     abort ();
  414.  
  415.   CWriteHeader (conn, EndDefMType, 0);
  416.   CWriteLength (conn);
  417.   CWriteTopLevel (conn, StopMType);
  418.   CWriteRequestBuffer (conn);
  419.   cadillac_process_requests (conn);
  420. }
  421.  
  422. void
  423. cadillac_finish_anon_union (decl)
  424.      tree decl;
  425. {
  426.   Connection *conn = cadillacObj.conn;
  427.  
  428.   if (! global_bindings_p ())
  429.     return;
  430.   cadillac_printf ("finish top-level anon union", "");
  431.   CWriteHeader (conn, EndDefMType, 0);
  432.   CWriteLength (conn);
  433.   CWriteTopLevel (conn, StopMType);
  434.   CWriteRequestBuffer (conn);
  435.   cadillac_process_requests (conn);
  436. }
  437.  
  438. void
  439. cadillac_start_enum (type)
  440.      tree type;
  441. {
  442.   Connection *conn = cadillacObj.conn;
  443.  
  444.   tree name = TYPE_NAME (type);
  445.  
  446.   if (TREE_CODE (name) == TYPE_DECL)
  447.     name = DECL_NAME (name);
  448.  
  449.   if (context_stack)
  450.     switch (TREE_CODE (context_stack->context))
  451.       {
  452.       case FUNCTION_DECL:
  453.     return;
  454.       case RECORD_TYPE:
  455.       case UNION_TYPE:
  456.     break;
  457.       default:
  458.     abort ();
  459.       }
  460.   else
  461.     {
  462.       cadillac_printf ("start top-level enum", IDENTIFIER_POINTER (name));
  463.       CWriteTopLevel (conn, StartMType);
  464.     }
  465.  
  466.   CWriteLanguageType (conn, type, tree_to_cadillac_map[ENUMERAL_TYPE]);
  467. }
  468.  
  469. void
  470. cadillac_finish_enum (type)
  471.      tree type;
  472. {
  473.   Connection *conn = cadillacObj.conn;
  474.   tree name = TYPE_NAME (type);
  475.  
  476.   if (TREE_CODE (name) == TYPE_DECL)
  477.     name = DECL_NAME (name);
  478.  
  479.   if (context_stack)
  480.     switch (TREE_CODE (context_stack->context))
  481.       {
  482.       case FUNCTION_DECL:
  483.     return;
  484.       case RECORD_TYPE:
  485.       case UNION_TYPE:
  486.     CWriteHeader (conn, EndDefMType, 0);
  487.     CWriteLength (conn);
  488.     break;
  489.       default:
  490.     abort ();
  491.       }
  492.   else
  493.     {
  494.       CWriteHeader (conn, EndDefMType, 0);
  495.       CWriteLength (conn);
  496.       cadillac_printf ("finish top-level enum", IDENTIFIER_POINTER (name));
  497.       CWriteTopLevel (conn, StopMType);
  498.     }
  499.  
  500.   CWriteRequestBuffer (conn);
  501.   cadillac_process_requests (conn);
  502. }
  503.  
  504. void
  505. cadillac_start_struct (type)
  506.      tree type;
  507. {
  508.   Connection *conn = cadillacObj.conn;
  509.   tree name = TYPE_NAME (type);
  510.  
  511.   if (TREE_CODE (name) == TYPE_DECL)
  512.     name = DECL_NAME (name);
  513.  
  514.   if (context_stack)
  515.     switch (TREE_CODE (context_stack->context))
  516.       {
  517.       case FUNCTION_DECL:
  518.     return;
  519.       case RECORD_TYPE:
  520.       case UNION_TYPE:
  521.     return;
  522.       default:
  523.     abort ();
  524.       }
  525.   else
  526.     {
  527.       cadillac_printf ("start struct", IDENTIFIER_POINTER (name));
  528.       CWriteTopLevel (conn, StartMType);
  529.     }
  530.  
  531.   context_stack = push_context_level (context_stack, &cadillac_obstack);
  532.   context_stack->context = type;
  533.  
  534.   CWriteLanguageType (conn, type,
  535.               TYPE_LANG_SPECIFIC (type) && CLASSTYPE_DECLARED_CLASS (type) ? ClassOType : tree_to_cadillac_map[TREE_CODE (type)]);
  536. }
  537.  
  538. void
  539. cadillac_finish_struct (type)
  540.      tree type;
  541. {
  542.   Connection *conn = cadillacObj.conn;
  543.   tree name = TYPE_NAME (type);
  544.  
  545.   if (TREE_CODE (name) == TYPE_DECL)
  546.     name = DECL_NAME (name);
  547.  
  548.   context_stack = pop_context_level (context_stack);
  549.   if (context_stack)
  550.     return;
  551.  
  552.   cadillac_printf ("finish struct", IDENTIFIER_POINTER (name));
  553.   CWriteHeader (conn, EndDefMType, 0);
  554.   CWriteLength (conn);
  555.   CWriteTopLevel (conn, StopMType);
  556.   CWriteRequestBuffer (conn);
  557.   cadillac_process_requests (conn);
  558. }
  559.  
  560. void
  561. cadillac_finish_exception (type)
  562.      tree type;
  563. {
  564.   Connection *conn = cadillacObj.conn;
  565.  
  566.   fatal ("cadillac_finish_exception");
  567.   CWriteHeader (conn, EndDefMType, 0);
  568.   CWriteLength (conn);
  569.   CWriteTopLevel (conn, StopMType);
  570.   CWriteRequestBuffer (conn);
  571.   cadillac_process_requests (conn);
  572. }
  573.  
  574. void
  575. cadillac_push_class (type)
  576.      tree type;
  577. {
  578. }
  579.  
  580. void
  581. cadillac_pop_class ()
  582. {
  583. }
  584.  
  585. void
  586. cadillac_push_lang (name)
  587.      tree name;
  588. {
  589.   Connection *conn = cadillacObj.conn;
  590.   CLinkLanguageType m;
  591.  
  592.   if (name == lang_name_cplusplus)
  593.     m = LinkCPlus;
  594.   else if (name == lang_name_c)
  595.     m = LinkC;
  596.   else
  597.     abort ();
  598.   CWriteHeader (conn, ForeignLinkageMType, m);
  599.   CWriteRequestBuffer (conn);
  600.   cadillac_process_requests (conn);
  601. }
  602.  
  603. void
  604. cadillac_pop_lang ()
  605. {
  606.   Connection *conn = cadillacObj.conn;
  607.  
  608.   CWriteHeader (conn, ForeignLinkageMType, LinkPop);
  609.   CWriteRequestBuffer (conn);
  610.   cadillac_process_requests (conn);
  611. }
  612.  
  613. void
  614. cadillac_finish_stmt ()
  615. {
  616. }
  617.  
  618. void
  619. cadillac_note_source ()
  620. {
  621.   cadillacObj.lineno = lineno;
  622.   cadillacObj.filename = input_filename;
  623. }
  624.  
  625. static void
  626. CWriteTopLevel (conn, m)
  627.      Connection *conn;
  628.      CMessageSubType m;
  629. {
  630.   static context_id = 0;
  631.   CWriteHeader (conn, TopLevelFormMType, m);
  632.   cadillac_note_filepos ();
  633.  
  634.   /* Eventually, this will point somewhere into the digest file.  */
  635.   context_id += 1;
  636.   CWriteSomething (conn, &context_id, sizeof (BITS32));
  637.  
  638.   CWriteSomething (conn, &cadillacObj.iflevel, sizeof (BITS32));
  639.   CWriteLength (conn);
  640. }
  641.  
  642. static void
  643. cadillac_note_filepos ()
  644. {
  645.   extern FILE *finput;
  646.   int pos = ftell (finput);
  647.   CWriteSomething (cadillacObj.conn, &pos, sizeof (BITS32));
  648. }
  649.  
  650. void
  651. cadillac_switch_source (startflag)
  652.      int startflag;
  653. {
  654.   Connection *conn = cadillacObj.conn;
  655.   /* Send out the name of the source file being compiled.  */
  656.  
  657.   CWriteHeader (conn, SourceFileMType, startflag ? StartMType : StopMType);
  658.   CWriteSomething (conn, &cadillacObj.depth, sizeof (BITS16));
  659.   CWriteVstring0 (conn, input_filename);
  660.   CWriteLength (conn);
  661.   CWriteRequestBuffer (conn);
  662.   cadillac_process_requests (conn);
  663. }
  664.  
  665. void
  666. cadillac_push_source ()
  667. {
  668.   cadillacObj.depth += 1;
  669.   cadillac_switch_source (1);
  670. }
  671.  
  672. void
  673. cadillac_pop_source ()
  674. {
  675.   cadillacObj.depth -= 1;
  676.   cadillac_switch_source (0);
  677. }
  678.  
  679. struct cadillac_mdep
  680. {
  681.   short object_type;
  682.   char linkage;
  683.   char access;
  684.   short length;
  685. };
  686.  
  687. static void
  688. CWriteLanguageElem (conn, p, name)
  689.      Connection *conn;
  690.      struct cadillac_mdep *p;
  691.      char *name;
  692. {
  693.   CWriteSomething (conn, &p->object_type, sizeof (BITS16));
  694.   CWriteSomething (conn, &p->linkage, sizeof (BITS8));
  695.   CWriteSomething (conn, &p->access, sizeof (BITS8));
  696.   CWriteSomething (conn, &p->length, sizeof (BITS16));
  697.   CWriteVstring0 (conn, name);
  698.  
  699. #if 0
  700.   /* Don't write date_type.  */
  701.   CWriteVstring0 (conn, "");
  702. #endif
  703.   CWriteLength (conn);
  704. }
  705.  
  706. static void
  707. CWriteLanguageDecl (conn, decl, object_type)
  708.      Connection *conn;
  709.      tree decl;
  710.      CObjectType object_type;
  711. {
  712.   struct cadillac_mdep foo;
  713.   tree name;
  714.  
  715.   CWriteHeader (conn, LanguageElementMType, StartDefineMType);
  716.   foo.object_type = object_type;
  717.   if (decl_type_context (decl))
  718.     {
  719.       foo.linkage = ParentLinkage;
  720.       if (TREE_PRIVATE (decl))
  721.     foo.access = PrivateAccess;
  722.       else if (TREE_PROTECTED (decl))
  723.     foo.access = ProtectedAccess;
  724.       else
  725.     foo.access = PublicAccess;
  726.     }
  727.   else
  728.     {
  729.       if (TREE_PUBLIC (decl))
  730.     foo.linkage = GlobalLinkage;
  731.       else
  732.     foo.linkage = FileLinkage;
  733.       foo.access = PublicAccess;
  734.     }
  735.   if (TREE_CODE (decl) == FUNCTION_DECL)
  736.     name = DECL_ORIGINAL_NAME (decl);
  737.   else
  738.     name = DECL_NAME (decl);
  739.   foo.length = IDENTIFIER_LENGTH (name);
  740.  
  741.   CWriteLanguageElem (conn, &foo, IDENTIFIER_POINTER (name));
  742.   CWriteRequestBuffer (conn);
  743.   cadillac_process_requests (conn);
  744. }
  745.  
  746. static void
  747. CWriteLanguageType (conn, type, object_type)
  748.      Connection *conn;
  749.      tree type;
  750.      CObjectType object_type;
  751. {
  752.   struct cadillac_mdep foo;
  753.   tree name = TYPE_NAME (type);
  754.  
  755.   CWriteHeader (conn, LanguageElementMType, StartDefineMType);
  756.   foo.object_type = object_type;
  757.   if (current_class_type)
  758.     {
  759.       foo.linkage = ParentLinkage;
  760.       if (TREE_PRIVATE (type))
  761.     foo.access = PrivateAccess;
  762.       else if (TREE_PROTECTED (type))
  763.     foo.access = ProtectedAccess;
  764.       else
  765.     foo.access = PublicAccess;
  766.     }
  767.   else
  768.     {
  769.       foo.linkage = NoLinkage;
  770.       foo.access = PublicAccess;
  771.     }
  772.   if (TREE_CODE (name) == TYPE_DECL)
  773.     name = DECL_NAME (name);
  774.  
  775.   foo.length = IDENTIFIER_LENGTH (name);
  776.  
  777.   CWriteLanguageElem (conn, &foo, IDENTIFIER_POINTER (name));
  778.   CWriteRequestBuffer (conn);
  779.   cadillac_process_requests (conn);
  780. }
  781.  
  782. static void
  783. CWriteUseObject (conn, type, object_type, use)
  784.      Connection *conn;
  785.      tree type;
  786.      CObjectType object_type;
  787.      CMessageSubType use;
  788. {
  789.   struct cadillac_mdep foo;
  790.   tree name = NULL_TREE;
  791.  
  792.   CWriteHeader (conn, LanguageElementMType, use);
  793.   foo.object_type = object_type;
  794.   if (current_class_type)
  795.     {
  796.       foo.linkage = ParentLinkage;
  797.       if (TREE_PRIVATE (type))
  798.     foo.access = PrivateAccess;
  799.       else if (TREE_PROTECTED (type))
  800.     foo.access = ProtectedAccess;
  801.       else
  802.     foo.access = PublicAccess;
  803.     }
  804.   else
  805.     {
  806.       foo.linkage = NoLinkage;
  807.       foo.access = PublicAccess;
  808.     }
  809.   switch (TREE_CODE (type))
  810.     {
  811.     case VAR_DECL:
  812.     case FIELD_DECL:
  813.     case TYPE_DECL:
  814.     case CONST_DECL:
  815.       name = DECL_NAME (type);
  816.       break;
  817.  
  818.     case FUNCTION_DECL:
  819.       /* @@ not quite right.  */
  820.       name = DECL_ORIGINAL_NAME (type);
  821.       break;
  822.  
  823.     default:
  824.       abort ();
  825.   }
  826.  
  827.   foo.length = IDENTIFIER_LENGTH (name);
  828.  
  829.   CWriteLanguageElem (conn, &foo, IDENTIFIER_POINTER (name));
  830.   CWriteRequestBuffer (conn);
  831.   cadillac_process_requests (conn);
  832. }
  833.  
  834. /* Here's how we exit under cadillac.  */
  835.  
  836. static void
  837. exit_cadillac ()
  838. {
  839.   extern int errorcount;
  840.  
  841.   Connection *conn = cadillacObj.conn;
  842.  
  843.   if (flag_cadillac)
  844.     {
  845.       CCompilerMessage *req;
  846.  
  847.       CWriteHeader (conn, FinishedMType,
  848.             errorcount ? 0 : CsObjectWritten | CsComplete);
  849.       /* Bye, bye!  */
  850.       CWriteRequestBuffer (conn);
  851.  
  852.       /* Block on read.  */
  853.       while (! readable_p (cadillacObj.fd_input))
  854.     {
  855.       if (exiting)
  856.         abort ();
  857.       exiting = 1;
  858.     }
  859.       exiting = 1;
  860.  
  861.       req = CReadCompilerMessage (conn);
  862.       cadillac_process_request (&cadillacObj, req);
  863.     }
  864. }
  865.  
  866. #else
  867. /* Stubs.  */
  868. void init_cadillac () {}
  869. void cadillac_start () {}
  870. void cadillac_start_decl (decl)
  871.      tree decl;
  872. {}
  873. void
  874. cadillac_finish_decl (decl)
  875.      tree decl;
  876. {}
  877. void
  878. cadillac_start_function (fndecl)
  879.      tree fndecl;
  880. {}
  881. void
  882. cadillac_finish_function (fndecl)
  883.      tree fndecl;
  884. {}
  885. void
  886. cadillac_finish_anon_union (decl)
  887.      tree decl;
  888. {}
  889. void
  890. cadillac_start_enum (type)
  891.      tree type;
  892. {}
  893. void
  894. cadillac_finish_enum (type)
  895.      tree type;
  896. {}
  897. void
  898. cadillac_start_struct (type)
  899.      tree type;
  900. {}
  901. void
  902. cadillac_finish_struct (type)
  903.      tree type;
  904. {}
  905. void
  906. cadillac_finish_exception (type)
  907.      tree type;
  908. {}
  909. void
  910. cadillac_push_class (type)
  911.      tree type;
  912. {}
  913. void
  914. cadillac_pop_class ()
  915. {}
  916. void
  917. cadillac_push_lang (name)
  918.      tree name;
  919. {}
  920. void
  921. cadillac_pop_lang ()
  922. {}
  923. void
  924. cadillac_note_source ()
  925. {}
  926. void
  927. cadillac_finish_stmt ()
  928. {}
  929. void
  930. cadillac_switch_source ()
  931. {}
  932. void
  933. cadillac_push_source ()
  934. {}
  935. void
  936. cadillac_pop_source ()
  937. {}
  938. #endif
  939.