Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_structure.cpp
blob06a9f79708d0d1a357d56227f3d906ccbb5a644a
2 //=============================================================================
3 /**
4 * @file be_structure.cpp
6 * Extension of class AST_Structure that provides additional means for C++
7 * mapping.
9 * @author Copyright 1994-1995 by Sun Microsystems
10 * @author Inc. and Aniruddha Gokhale
12 //=============================================================================
14 #include "be_structure.h"
15 #include "be_field.h"
16 #include "be_codegen.h"
17 #include "be_helper.h"
18 #include "be_visitor.h"
19 #include "be_extern.h"
21 #include "utl_identifier.h"
22 #include "idl_defines.h"
23 #include "global_extern.h"
25 be_structure::be_structure (UTL_ScopedName *n,
26 bool local,
27 bool abstract)
28 : COMMON_Base (local,
29 abstract),
30 AST_Decl (AST_Decl::NT_struct,
31 n),
32 AST_Type (AST_Decl::NT_struct,
33 n),
34 AST_ConcreteType (AST_Decl::NT_struct,
35 n),
36 UTL_Scope (AST_Decl::NT_struct),
37 AST_Structure (n,
38 local,
39 abstract),
40 be_scope (AST_Decl::NT_struct),
41 be_decl (AST_Decl::NT_struct,
42 n),
43 be_type (AST_Decl::NT_struct,
46 if (!this->imported ())
48 idl_global->aggregate_seen_ = true;
52 be_structure::be_structure (AST_Decl::NodeType nt,
53 UTL_ScopedName *n,
54 bool local,
55 bool abstract)
56 : COMMON_Base (local,
57 abstract),
58 AST_Decl (nt,
59 n),
60 AST_Type (nt,
61 n),
62 AST_ConcreteType (nt,
63 n),
64 UTL_Scope (nt),
65 AST_Structure (nt,
67 local,
68 abstract),
69 be_scope (nt),
70 be_decl (nt,
71 n),
72 be_type (nt,
75 if (!this->imported ())
77 idl_global->aggregate_seen_ = true;
81 void
82 be_structure::redefine (AST_Structure *from)
84 be_structure *bs = dynamic_cast<be_structure*> (from);
85 this->common_varout_gen_ = bs->common_varout_gen_;
86 this->AST_Structure::redefine (from);
89 // Overridden method
90 void
91 be_structure::gen_ostream_operator (TAO_OutStream *os,
92 bool /* use_underscore */)
94 *os << be_nl
95 << "std::ostream& operator<< (" << be_idt << be_idt_nl
96 << "std::ostream &strm," << be_nl
97 << "const " << this->name () << " &";
99 long n = this->pd_decls_used;
101 // be_exception is a subclass and could be empty.
102 if (n > 0)
104 *os << "_tao_aggregate";
107 *os << be_uidt_nl
108 << ")" << be_uidt_nl
109 << "{" << be_idt_nl
110 << "strm << \"" << this->name () << "(\"";
112 for (long i = 0; i < n; ++i)
114 be_field *f = dynamic_cast<be_field*> (this->pd_decls[i]);
116 // We don't want any decls, just members.
117 if (f == 0)
119 continue;
122 if (i != 0)
124 *os << " << \", \"";
127 *os << be_nl
128 << " << ";
130 ACE_CString instance_name ("_tao_aggregate.");
131 instance_name += f->local_name ()->get_string ();
132 AST_Decl::NodeType nt = f->field_type ()->node_type ();
133 bool member_use_underscore =
134 nt == AST_Decl::NT_array || nt == AST_Decl::NT_sequence;
135 f->gen_member_ostream_operator (os,
136 instance_name.c_str (),
137 member_use_underscore,
138 false);
141 *os << be_nl
142 << " << \")\";" << be_nl_2
143 << "return strm;" << be_uidt_nl
144 << "}" << be_nl;
147 void
148 be_structure::destroy (void)
150 // Call the destroy methods of our base classes.
151 this->be_scope::destroy ();
152 this->be_type::destroy ();
153 this->AST_Structure::destroy ();
157 be_structure::accept (be_visitor *visitor)
159 return visitor->visit_structure (this);
162 IMPL_NARROW_FROM_DECL (be_structure)
163 IMPL_NARROW_FROM_SCOPE (be_structure)