/*
 *    @(#) 1.10 src/somk/somcsr.h, somk.api, som3.0 9/25/96 17:03:04 [12/22/96 21:33:30]
 */
/*
 *   COMPONENT_NAME: somk
 *
 *   ORIGINS: 27
 *
 *
 *    25H7912  (C)  COPYRIGHT International Business Machines Corp. 1992,1996,1996  
 *   All Rights Reserved
 *   Licensed Materials - Property of IBM
 *   US Government Users Restricted Rights - Use, duplication or
 *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

#ifndef somcsr_included
#define somcsr_included

/**********************************************************************/
/* Here we define structures actually needed at emit time to emit an  */
/* initialized marshal plan (csr).  Definitions needed only to        */
/* generate and analyze a csr are in cpct_csr.h.  All names intro-    */
/* duced in this file should begin with som or SOM since they will    */
/* be present in .ih and .xih files that are included in class im-    */
/* plementations.                                                     */
/**********************************************************************/

/* A length-counted TDC stream */
struct somcsr_tdcstream {
    long tdcstream_len;
    octet *tdcs;
};

/* User exception attribute structures */

struct somcsr_exception_entry {
    char *exn_string_ident;
    struct somcsr_tdcstream exn_tdcs;
};

struct somcsr_Exception_Attributes {
    long num_exns;
    struct somcsr_exception_entry *exns;
};

/* Context attribute structure */

struct somcsr_Context_Attributes {
  char **fields;
};

/* Union attribute structures */

/* [case_val] is the value of the case, and [case_tdc/len] is
   the actual TDC stream. */

struct somcsr_union_case {
  long case_val;
  struct somcsr_tdcstream case_tdcs;
};

/* [default_index] is the index of the default case in the
   [cases] array.  If it is [-1], then there is no default case */

struct somcsr_Union_Attributes {
  long default_index;
  long num_cases;
  struct somcsr_union_case *cases;
};

/* Foreign Marshaler attribute structures                             */
/* NOTE: The values used for the direction and function arguments below
   must come from the enumerations defined in datmarsh.idl. */

typedef void SOMLINK somcsr_Static_foreign_marshaler
  (void * latent_param,
   char * foreign_addr,
   unsigned long direction,
   unsigned long function,
   void * stream,
   Environment *ev);

/*
 * The next typedef is needed prior to the macro redefinition below because
 * the explicit pointer qualification in somcsr_Static_foreign_marshaler *
 * will result in a syntax error (after macro expansion).  Pointers to
 * static foreign marshaler * functions must be declared with the
 * somcsr_Static_foreign_marshal_ptr to avoid this error.  See marshfun below
 * for an example.
 */
typedef somcsr_Static_foreign_marshaler * somcsr_Static_foreign_marshal_ptr;

/*
 * The type definition for somcsr_Static_foreign_marshaler specifies
 * system linkage, but the C Set++ compiler doesn't apply this correctly
 * when somcsr_Static_foreign_marshaler is used in a second or subsequent
 * declaration for a function.  We work around this compiler problem by
 * redefining the type name for the function to include an explicit _System
 * keyword.  This problem doesn't occur with VisualAge C++.
 */
#if (defined(__IBMC__) && __IBMC__ < 300) || \
    (defined(__IBMCPP__) && __IBMCPP__ < 300)
#define somcsr_Static_foreign_marshaler somcsr_Static_foreign_marshaler _System
#endif

SOMEXTERN somcsr_Static_foreign_marshaler somcsr_static_foreign_octet_marshaler;

struct somcsr_ForeignStatic_Attributes {
  char *marshfun_name;
  somcsr_Static_foreign_marshal_ptr marshfun;
  char *latent_param_name;
  void *latent_param;
};
struct somcsr_ForeignDynamic_Attributes {
  char *class_name;
  long vers_major;
  long vers_minor;
  char *latent_param;
};

/* attrKind exists as a check; it records whether the attribute structure
   was converted dynamically or compiled into a DLL; a ForeignStatic marshaler
   only legal in the latter case */


enum attrKind {somcsr_Converted, somcsr_Compiled}; /* #21904 */

struct somcsr_Foreign_Attributes {
  enum attrKind attrKind;      /* #21904 */
  boolean is_static;
  struct somcsr_ForeignStatic_Attributes *_static;
  struct somcsr_ForeignDynamic_Attributes *_dynamic;

};

/**********************************************************************/
/* Marshal Plan Rows                                                  */
/**********************************************************************/

/* All marshal plan rows begin with the following standard header */

typedef struct somMpRowStruct {
   struct somMpRowStruct * next;
   unsigned long rowtype;
} somMpRow;

/* The following rowtypes are defined                                 */

/* The `long return' rowtype is present for methods returning
   aggregate (struct or union) results, where the length of the result is
  too large to be represented in a short varint (eg, greater than 127
  bytes).  This is expected to be very rare; however, correctness
  dictates that we check for this case and do the right thing.
*/

typedef struct somMpRowLongretStruct {
  somMpRow hdr;  /* rowtype == 0 */
  unsigned long rlvaluelen;
} somMpRowLongret;

#define SOM_MP_ROWTYPE_LONGRET 0

/* The `redispatch/apply' rowtype exists as a transition aid for carrying
   forward the SOM 2.x style somMethodInfo structure while reusing the
   emitted fields that used to point to somMethodInfo.  What we do is to
   incorporate somMethodInfo as a marshal plan row.  Eventually, we can get
   rid of somMethodInfo entirely, since it is possible to support redispatch
   and apply stubs based only on information in the csr. */

typedef struct somMpRowMethodInfoStruct {
  somMpRow hdr;  /* rowtype == 1 */
  somMethodInfo minfo;
} somMpRowMethodInfo;

#define SOM_MP_ROWTYPE_METHODINFO 1

#endif /* somcsr_included */
