]> git.buserror.net Git - polintos/scott/priv.git/blobdiff - idlcomp/languages/c++/c++.h
Initial struct marshalling.
[polintos/scott/priv.git] / idlcomp / languages / c++ / c++.h
index 4717233185de8d6987ff4ce384261831980b5ce9..771cba1ccf97f09a77fb876623cb68d9bb6a0233 100644 (file)
@@ -27,6 +27,47 @@ void cpp_output_type(ostream &file, CompiledBasicType &t, bool is_mutable);
 
 void cpp_output_one_param(ostream &file, Param *p, bool is_server,
                           bool is_copy = false);
+
+enum CPPTraversal {
+       trav_full,         // Full, final output
+       trav_obj_def,      // Object struct definition
+       trav_obj_stub,     // Object pointer stub,
+                      // so it can be used in structs.
+       trav_nsdecl,       // _ns declaration
+       trav_forward,      // Forward declaration of
+                      // structs/interfaces in nsdecl
+
+       num_traversals,
+       
+       // Values beyond this point are not part of the
+       // above sequential pass scheme; they are merely
+       // for dynamic dispatch.
+       trav_marshall,
+       trav_unmarshall,
+};
+
+// Per-symbol language-private data
+struct CPPData : public Releasable {
+       // The traversal indices are also passed as "arg1" to determine
+       // which pass to generate.  Higher numbers are performed first.
+       
+       int traversed[num_traversals];
+
+       CPPData() : Releasable(1)
+       {
+               memset(traversed, 0, sizeof(traversed));
+       }
+};
+
+static inline CPPData &cpp_symdata(Symbol *sym)
+{
+       if (!sym->lang_priv)
+               sym->lang_priv = new CPPData;
+
+       CPPData *ptr = dynamic_cast<CPPData *>(sym->lang_priv);
+       assert(ptr);
+       return *ptr;
+}
        
 // Each IDL namespace is mapped to a C++ header file,
 // represented by a CPPFile.
@@ -54,6 +95,24 @@ class CPPFile : public LangCallback {
        // The implementation is delayed to avoid circular dependency problems.
 
        void output_casts(Interface *sym);
+       
+       //// Marshalling methods
+       
+       void output_marshall_pass(Struct *sym, int pass);
+       void output_marshall_method(Struct *sym);
+       void output_marshall_inline_method(Struct *sym);
+       void marshall_members(Struct *sym);
+
+       void output_marshall_array(Datum *d);
+       void output_marshall(Struct *sym, Datum *d);
+       void output_marshall(Interface *sym, Datum *d);
+       void output_marshall(Enum *sym, Datum *d);
+       void output_marshall(BitField *sym, Datum *d);
+       void output_marshall(BasicType *sym, Datum *d);
+       void output_marshall(CompiledBasicType &cbt, Datum *d);
+
+       void align_type(Symbol *sym);
+       void grow_buf();
 
        // Output the downcast and implicit upcast methods for
        // the given interface/superinterface pair.
@@ -78,24 +137,22 @@ class CPPFile : public LangCallback {
        void output_methods(Interface *iface, Interface *super, bool prototype);
        void output_method_defs(Interface *iface);
 
-       void CPPFile::output_one_method(Interface *iface, Method *m, 
-                                       bool prototype, bool retval);
-       void CPPFile::output_one_method_ptr(Method *m, Interface *iface);
+       void output_one_method(Interface *iface, Method *m,
+                              bool prototype, bool retval);
+       void output_one_method_ptr(Method *m, Interface *iface);
        
-       static void output_iface_ns(CPPFile *file, NameSpace *sym);
-
        //// Misc members:
 
-       // Output the static const guid[] value.
+       // Output the static const guid[] value, and the IFaceInfo struct.
 
        void output_guid(const uint64_t *guid);
+       void output_ifaceinfo(Interface *iface);
 
        // Output a datum in the given struct, along with any necessary
        // padding.  Return the offset of the next datum.
        
        int output_datum(Struct *ns, Datum *d, int offset);
 
-       static void output_vstruct_ns(CPPFile *file, NameSpace *sym);
        void output_vstruct_info(Struct *sym);
        void output_vstruct_main(Struct *sym);
        void output_struct_ctor(Struct *sym, bool extra_vstruct);
@@ -141,8 +198,10 @@ class CPPFile : public LangCallback {
        // namespace, before any namespace members have been
        // emitted.
        
-       typedef void (*nsdecl_callback)(CPPFile *file, NameSpace *ns);
-       void output_nsdecl(NameSpace *ns, nsdecl_callback cb = NULL);
+       void output_nsdecl_begin(NameSpace *ns);
+       void output_nsdecl_children(NameSpace *ns);
+       void output_nsdecl_end(NameSpace *ns);
+       void output_nsdecl(NameSpace *ns);
 
        void output_aliases_and_types(NameSpace *ns);
        
@@ -176,28 +235,15 @@ class CPPFile : public LangCallback {
 
        int first_traversal;
 
-       // The traversal indices are also passed as "arg1" to determine
-       // which pass to generate.  Higher numbers are performed first.
-       
-       enum {
-               trav_full = 0,     // Full, final output
-               trav_obj_def = 1,  // Object struct definition
-               trav_obj_stub = 2, // Object pointer stub,
-                             // so it can be used in structs.
-               trav_nsdecl = 3,   // _ns declaration
-               trav_forward = 4,  // Forward declaration of
-                             // structs/interfaces in nsdecl
-       };
-
        bool pass_needed(Symbol *sym, int pass)
        {
-               return first_traversal > sym->traversed[pass];
+               return first_traversal > cpp_symdata(sym).traversed[pass];
        }
 
        void output_pass(Symbol *sym, int pass)
        {
                if (pass_needed(sym, pass)) {
-                       sym->traversed[pass] = traversal;
+                       cpp_symdata(sym).traversed[pass] = traversal;
                        sym->output_lang(this, pass);
                }
        }
@@ -237,6 +283,18 @@ public:
        void output(Alias *sym, int pass = trav_full, void *arg2 = NULL);
        void output(TypeDef *sym, int pass = trav_full, void *arg2 = NULL);
        void output(Datum *sym, int pass = trav_full, void *arg2 = NULL);
+
+       void marshall(Struct *sym);
+       void marshall(Interface *sym);
+       void marshall(BitField *sym);
+       void marshall(Enum *sym);
+       void marshall(BasicType *sym);
+
+       void unmarshall(Struct *sym);
+       void unmarshall(Interface *sym);
+       void unmarshall(BitField *sym);
+       void unmarshall(Enum *sym);
+       void unmarshall(BasicType *sym);
 };
 
 class CPPBinding : public Language {