13 // Output the namespace-qualified symbol name, including
14 // user namespaces. A prefix for the final component (i.e. the
15 // actual name) can optionally be specified.
17 void cpp_output_name(ostream &file, Symbol *sym, const char *prefix = "");
19 // Output the C++ type, not including the array, including
22 void cpp_output_type(ostream &file, Type *t, bool array, bool is_mutable);
23 void cpp_output_type(ostream &file, CompiledBasicType &t, bool is_mutable);
25 // Output the param's fully-qualified type, a space, and the name
28 void cpp_output_one_param(ostream &file, Param *p, bool is_server,
29 bool is_copy = false);
32 trav_full, // Full, final output
33 trav_obj_def, // Object struct definition
34 trav_obj_stub, // Object pointer stub,
35 // so it can be used in structs.
36 trav_nsdecl, // _ns declaration
37 trav_forward, // Forward declaration of
38 // structs/interfaces in nsdecl
42 // Values beyond this point are not part of the
43 // above sequential pass scheme; they are merely
44 // for dynamic dispatch.
49 // Per-symbol language-private data
50 struct CPPData : public Releasable {
51 // The traversal indices are also passed as "arg1" to determine
52 // which pass to generate. Higher numbers are performed first.
54 int traversed[num_traversals];
56 CPPData() : Releasable(1)
58 memset(traversed, 0, sizeof(traversed));
62 static inline CPPData &cpp_symdata(Symbol *sym)
65 sym->lang_priv = new CPPData;
67 CPPData *ptr = dynamic_cast<CPPData *>(sym->lang_priv);
72 // Each IDL namespace is mapped to a C++ header file,
73 // represented by a CPPFile.
75 class CPPFile : public LangCallback {
82 //// Interface caller-side members:
84 // Outputs the body of the internal _i_<ifacename> struct,
85 // containing a vtable pointer (and definition).
87 void output_internal(Interface *sym);
89 // Outputs the user-visible class wrapper that is used to
90 // allow implicit upcasts.
92 void output_wrapper(Interface *sym);
94 // Output implementations of the cast methods prototyped in the wrapper.
95 // The implementation is delayed to avoid circular dependency problems.
97 void output_casts(Interface *sym);
99 //// Marshalling methods
101 void output_marshall_pass(Struct *sym, int pass);
103 void output_marshall(Struct *sym, Datum *d);
104 void output_marshall(Interface *sym, Datum *d);
105 void output_marshall(Enum *sym, Datum *d);
106 void output_marshall(BitField *sym, Datum *d);
107 void output_marshall(BasicType *sym, Datum *d);
108 void output_marshall(CompiledBasicType &cbt, Datum *d);
110 void align_type(Symbol *sym);
111 void grow_buf(Symbol *sym);
113 // Output the downcast and implicit upcast methods for
114 // the given interface/superinterface pair.
116 static void wrapper_cast_callback(Interface *iface, void *arg);
117 void output_downcast(Interface *iface, Interface *super);
118 void output_upcast(Interface *iface, Interface *super);
120 static void wrapper_cast_proto_callback(Interface *iface, void *arg);
121 void output_downcast_proto(Interface *iface, Interface *super);
122 void output_upcast_proto(Interface *iface, Interface *super);
124 static void wrapper_method_proto_callback(Interface *iface, void *arg);
125 static void wrapper_method_callback(Interface *iface, void *arg);
127 void output_iface_tbl(Interface *iface);
128 static void tbl_callback(Interface *iface, void *arg);
129 void output_iface_tbl_entry(Interface *iface, Interface *super);
131 static void output_method_ptrs_callback(Interface *iface, void *arg);
132 void output_method_ptrs(Interface *iface);
133 void output_methods(Interface *iface, Interface *super, bool prototype);
134 void output_method_defs(Interface *iface);
136 void output_one_method(Interface *iface, Method *m,
137 bool prototype, bool retval);
138 void output_one_method_ptr(Method *m, Interface *iface);
142 // Output the static const guid[] value, and the IFaceInfo struct.
144 void output_guid(const uint64_t *guid);
145 void output_ifaceinfo(Interface *iface);
147 // Output a datum in the given struct, along with any necessary
148 // padding. Return the offset of the next datum.
150 int output_datum(Struct *ns, Datum *d, int offset);
152 void output_vstruct_info(Struct *sym);
153 void output_vstruct_main(Struct *sym);
154 void output_struct_ctor(Struct *sym, bool extra_vstruct);
155 int output_struct_ctor_rec1(Struct *sym, int num);
156 int output_struct_ctor_rec2(Struct *sym, int num);
158 void output_bf_elem(Datum *d, int pos, int bits, string &prefix);
159 void output_bf(BitField *bf, int bits, int typebits, string &prefix);
161 // Call ns_in on the symbol in order to declare the containing
162 // namespace. Call ns_out when finished. ns_out also takes care
163 // of inserting the extra newline separating declarations. The
164 // "extra" parameter allows extra output passes to have unique
165 // #ifndef names, and should have a trailing underscore.
167 void ns_in(Symbol *sym, const char *extra = "DEF_");
168 void ns_out(Symbol *sym);
170 // As above, but also outputs non-user namespaces (optionally
171 // including "sym" itself).
173 void all_ns_in(Symbol *sym, bool include_self = false,
174 const char *extra = "DEF_");
175 void all_ns_out(Symbol *sym, bool include_self = false);
177 // Output a protective #ifndef/#define block to keep a type
178 // from being declared more than once. Call ifndef_out()
181 void ifndef_in(Symbol *sym, const char *extra = "DEF_");
184 // Return the namespace-qualified symbol name, excluding
185 // user namespaces. This is used when defining a name
186 // which (if it is nested) has been previously forward
187 // declared. A prefix for the final component (i.e. the
188 // actual name) can optionally be specified.
190 String &get_definition_name(Symbol *sym, const char *prefix = "");
192 // Output the _ns declaration of a struct or interface.
193 // If a callback is supplied, it is called inside the
194 // namespace, before any namespace members have been
197 void output_nsdecl_begin(NameSpace *ns);
198 void output_nsdecl_children(NameSpace *ns);
199 void output_nsdecl_end(NameSpace *ns);
200 void output_nsdecl(NameSpace *ns);
202 void output_aliases_and_types(NameSpace *ns);
204 // When a top-level struct or interface is about to be generated,
205 // it is scanned for other types which need to be generated. If the
206 // full definition is needed, it goes on the need_to_declare list;
207 // otherwise, it goes on the need_to_forward_declare list. When
208 // processing the lists, if a node has already been marked as
209 // traversed, it is skipped.
211 // Full declaration is needed for superstructs, superinterfaces,
212 // inline structs (once implemented) used, and typedefs used.
213 // It is also necessary to fully declare any type which contains
214 // a type whose forward declaration is needed, as such types
215 // cannot (as far as I know) be forward-declared.
217 std::list<Symbol *> need_to_declare;
219 // Forward declaration is needed for types used via a pointer only.
221 std::list<Symbol *> need_to_forward_declare;
223 void declare_dependencies(Struct *sym);
224 void declare_dependencies(Interface *iface, bool need_obj_def = false);
225 void declare_type_dependency(Type *t, bool need_obj_def = false);
227 // This is the traversal of the first namespace; any symbol
228 // whose last traversal is at least this has been written to
229 // at least one of the included namespaces (and/or the
230 // current namespace).
234 bool pass_needed(Symbol *sym, int pass)
236 return first_traversal > cpp_symdata(sym).traversed[pass];
239 void output_pass(Symbol *sym, int pass)
241 if (pass_needed(sym, pass)) {
242 cpp_symdata(sym).traversed[pass] = traversal;
243 sym->output_lang(this, pass);
247 bool do_extra_newline;
251 indent.indent_level++;
252 do_extra_newline = false;
257 indent.indent_level--;
258 do_extra_newline = true;
263 if (do_extra_newline)
266 do_extra_newline = true;
270 CPPFile(UserNameSpace *ns, const char *dir);
273 void output(UserNameSpace *sym, int pass = trav_full, void *arg2 = NULL);
274 void output(Struct *sym, int pass = trav_full, void *arg2 = NULL);
275 void output(Interface *sym, int pass = trav_full, void *arg2 = NULL);
276 void output(BitField *sym, int pass = trav_full, void *arg2 = NULL);
277 void output(Enum *sym, int pass = trav_full, void *arg2 = NULL);
278 void output(BasicType *sym, int pass = trav_full, void *arg2 = NULL);
279 void output(Alias *sym, int pass = trav_full, void *arg2 = NULL);
280 void output(TypeDef *sym, int pass = trav_full, void *arg2 = NULL);
281 void output(Datum *sym, int pass = trav_full, void *arg2 = NULL);
283 void marshall(Struct *sym);
284 void marshall(Interface *sym);
285 void marshall(BitField *sym);
286 void marshall(Enum *sym);
287 void marshall(BasicType *sym);
289 void unmarshall(Struct *sym);
290 void unmarshall(Interface *sym);
291 void unmarshall(BitField *sym);
292 void unmarshall(Enum *sym);
293 void unmarshall(BasicType *sym);
296 class CPPBinding : public Language {
305 void output_root(UserNameSpace *ns, const char *dir);
306 void output_server(UserNameSpace *ns, const char *dir);