X-Git-Url: http://git.buserror.net/cgi-bin/gitweb.cgi?p=polintos%2Fscott%2Fpriv.git;a=blobdiff_plain;f=idlcomp%2Flanguages%2Fc%2B%2B%2Fc%2B%2B.h;h=771cba1ccf97f09a77fb876623cb68d9bb6a0233;hp=4717233185de8d6987ff4ce384261831980b5ce9;hb=ed94ee97c9872c957efa4790c4ea073f371262a6;hpb=7da27a216a7f4bb3331fe315cdbec69bfcf2c762 diff --git a/idlcomp/languages/c++/c++.h b/idlcomp/languages/c++/c++.h index 4717233..771cba1 100644 --- a/idlcomp/languages/c++/c++.h +++ b/idlcomp/languages/c++/c++.h @@ -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(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 {