summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_interface/amh_si.cpp
blob: 10118851bcfa11e2f74f73fcaad3fcaf2e6723b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//=============================================================================
/**
*  @file   amh_si.cpp
*
*  $Id$
*
*  Specialized interface visitor for AMH generates code that is
*  specific to AMH interfaces.
*
*  @author Jeff Parsons <j.parsons@vanderbilt.edu>
*/
//=============================================================================

ACE_RCSID (be_visitor_interface,
           amh_si,
           "$Id$")

be_visitor_amh_interface_si::be_visitor_amh_interface_si (
    be_visitor_context *ctx
  )
  : be_visitor_interface_si (ctx)
{
}

be_visitor_amh_interface_si::~be_visitor_amh_interface_si (void)
{
}

int
be_visitor_amh_interface_si::visit_interface (be_interface *node)
{
  if (node->srv_inline_gen () || node->imported () || node->is_local ())
    {
      return 0;
    }

  // Do not generate AMH classes for any sort of implied IDL.
  if (node->original_interface () != 0)
    {
      return 0;
    }

  TAO_OutStream *os = this->ctx_->stream ();

  int status =
    node->traverse_inheritance_graph (
              be_visitor_amh_interface_si::gen_skel_helper,
              os
            );

  if (status == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_amh_interface_si::"
                         "visit_interface - "
                         "inheritance graph traversal failed\n"),
                        -1);
    }

  return 0;
}

int
be_visitor_amh_interface_si::gen_skel_helper (be_interface *derived,
                                              be_interface *ancestor,
                                              TAO_OutStream *os)
{
  // If derived and ancestor are same, skip it.
  if (derived == ancestor)
    {
      return 0;
    }

  // If an operation or an attribute is abstract (declared in an
  // abstract interface), we will either generate the full
  // definition (if there are no concrete interfaces between the
  // abstract ancestor and us) or, if there is a concrete ancestor
  // in between, we will catch its definition elsewhere in this
  // traversal.
  if (ancestor->is_abstract ())
    {
      return 0;
    }

  // Else generate code that does the cast to the appropriate type.

  if (ancestor->nmembers () > 0)
    {
      // If there are elements in ancestor scope i.e., any operations and
      // attributes defined by "ancestor", become methods on the derived class
      // which call the corresponding method of the base class by doing the
      // proper casting.

      ACE_CString ancestor_name ("POA_");
      char *buf = 0;
      ancestor->compute_full_name ("AMH_", "", buf);
      ancestor_name += buf;
      // buf was allocated by ACE_OS::strdup, so we need to use free instead
      // of delete.
      ACE_OS::free (buf);
      buf = 0;

      const char *ancestor_amh_name = ancestor_name.fast_rep ();

      ACE_CString derived_name ("POA_");
      derived->compute_full_name ("AMH_", "", buf);
      derived_name += buf;
      // buf was allocated by ACE_OS::strdup, so we need to use free instead
      // of delete.
      ACE_OS::free (buf);
      buf = 0;

      const char *derived_amh_name = derived_name.fast_rep ();

      for (UTL_ScopeActiveIterator si (ancestor, UTL_Scope::IK_decls);
           !si.is_done ();
           si.next ())
        {
          // Get the next AST decl node
          AST_Decl *d = si.item ();

          if (d->node_type () == AST_Decl::NT_op)
            {
              *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
                  << "// " << __FILE__ << ":" << __LINE__;

              *os << be_nl << be_nl;

              // Generate code in the inline file.
              // Generate the static method corresponding to this method.
              *os << "ACE_INLINE" << be_nl
                  << "void" << be_nl
                  << derived_amh_name << "::"
                  << d->local_name ()
                  << "_skel (" << be_idt << be_idt_nl
                  << "TAO_ServerRequest & req," << be_nl
                  << "void * context," << be_nl
                  << "void * obj" << env_decl << be_uidt_nl
                  << ")" << be_uidt_nl
                  << "{" << be_idt_nl;
              *os << ancestor_amh_name
                  << "* const impl = static_cast<"
                  << derived_amh_name
                  << " *> (obj);" << be_nl;
              *os << ancestor_amh_name
                  << "::" << d->local_name ()
                  << "_skel (" << be_idt << be_idt_nl
                  << "req," << be_nl
                  << "context," << be_nl
                  << "impl" << env_arg << be_uidt_nl
                  << ");" << be_uidt << be_uidt_nl
                  << "}";
            }
          else if (d->node_type () == AST_Decl::NT_attr)
            {
              AST_Attribute *attr = AST_Attribute::narrow_from_decl (d);

              if (attr == 0)
                {
                  return -1;
                }

              *os << be_nl << be_nl;

              // Generate code in the inline file.
              // Generate the static method corresponding to this method.
              *os << "ACE_INLINE" << be_nl
                  << "void" << be_nl
                  << derived_amh_name << "::_get_"
                  << d->local_name ()
                  << "_skel (" << be_idt << be_idt_nl
                  << "TAO_ServerRequest & req," << be_nl
                  << "void * context," << be_nl
                  << "void * obj" << env_decl << be_uidt_nl
                  << ")" << be_uidt_nl
                  << "{" << be_idt_nl;

              *os << ancestor_amh_name
                  << "* const impl = static_cast<"
                  << derived_amh_name
                  << " *> (obj);" << be_nl;

              *os << ancestor_amh_name
                  << "::_get_" << d->local_name ()
                  << "_skel (" << be_idt << be_idt_nl
                  << "req," << be_nl
                  << "context," << be_nl
                  << "impl" << env_arg << be_uidt_nl
                  << ");" << be_uidt << be_uidt_nl
                  << "}";

              if (!attr->readonly ())
                {
                  *os << be_nl << be_nl;

                  // Generate code in the inline file.
                  // Generate the static method corresponding to
                  // this method.
                  *os << "ACE_INLINE" << be_nl
                      << "void" << be_nl
                      << derived_amh_name
                      << "::_set_" << d->local_name ()
                      << "_skel (" << be_idt << be_idt_nl
                      << "TAO_ServerRequest & req," << be_nl
                      << "void * context," << be_nl
                      << "void * obj" << env_decl << be_uidt_nl
                      << ")" << be_uidt_nl
                      << "{" << be_idt_nl;

                  *os << ancestor_amh_name
                      << "* const impl = static_cast<"
                      << derived_amh_name
                      << " *> (obj);" << be_nl;

                  *os << ancestor_amh_name
                      << "::_set_" << d->local_name ()
                      << "_skel (" << be_idt << be_idt_nl
                      << "req," << be_nl
                      << "context," << be_nl
                      << "impl" << env_arg << be_uidt_nl
                      << ");" << be_uidt << be_uidt_nl
                      << "}";
                }
            }
        } // End of FOR
    }

  return 0;
}