summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_interface/interface_is.cpp
blob: d786778da987ba103e260721f4eeb95a68a1ddd8 (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

//=============================================================================
/**
 *  @file    interface_is.cpp
 *
 *  Visitor generating code for Interfaces in the implementation skeletons file.
 *
 *  @author Yamuna Krishnamurthy (yamuna@cs.wustl.edu)
 */
//=============================================================================

#include "interface.h"

be_visitor_interface_is::be_visitor_interface_is (be_visitor_context *ctx)
  : be_visitor_interface (ctx)
{
}

be_visitor_interface_is::~be_visitor_interface_is ()
{
}

int
be_visitor_interface_is::visit_interface (be_interface *node)
{
  if (node->impl_skel_gen () || node->imported () || node->is_abstract ())
    {
      return 0;
    }

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

  // Generate the skeleton class name.

  if (be_global->gen_impl_debug_info ())
    {
      TAO_INSERT_COMMENT (os);
    }

  *os << "// Implementation skeleton constructor" << be_nl;

  // Find if we are at the top scope or inside some module.
  *os << be_global->impl_class_prefix () << node->flat_name ()
      << be_global->impl_class_suffix () <<"::"
      << be_global->impl_class_prefix () << node->flat_name ()
      << be_global->impl_class_suffix ()
      << " ()" << be_nl;

  *os << "{" << be_nl
      << "}" << be_nl_2;

  os->indent ();
  *os << "// Implementation skeleton destructor" << be_nl;

  *os << be_global->impl_class_prefix () << node->flat_name ()
      << be_global->impl_class_suffix () <<"::~"
      << be_global->impl_class_prefix () << node->flat_name ()
      << be_global->impl_class_suffix ()
      << " ()" << be_nl;

  *os << "{" <<be_nl;
  *os << "}" << be_nl_2;

  if (be_global->gen_copy_ctor () && !node->is_local ())
    {
      *os << "//Implementation Skeleton Copy Constructor" << be_nl;

      *os << be_global->impl_class_prefix () << node->flat_name ()
          << be_global->impl_class_suffix () <<"::"
          << be_global->impl_class_prefix () << node->flat_name ()
          << be_global->impl_class_suffix () << " (const "
          << be_global->impl_class_prefix () << node->flat_name ()
          << be_global->impl_class_suffix () << "& rhs)" << be_idt_nl
          << ": TAO_Abstract_ServantBase (rhs)," << be_nl
          << "  TAO_ServantBase (rhs)";

      if (node->traverse_inheritance_graph (be_interface::copy_ctor_helper,
                                            os)
           == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "be_visitor_interface_is::visit_interface - "
                             " copy ctor generation failed\n"),
                            -1);
        }

      if (!node->is_local ())
        {
          *os << "," << be_nl;

          if (node->is_nested ())
            {
              be_decl *scope = nullptr;
              scope = dynamic_cast<be_scope*> (node->defined_in ())->decl ();

              *os << "  POA_" << scope->name () << "::"
                  << node->local_name () << " (rhs)";
            }
          else
            {
              *os << "  " << node->full_skel_name () << " (rhs)";
            }
        }

      *os << be_uidt_nl
          << "{" << be_nl
          << "}" << be_nl << be_uidt_nl;
    }

  if (be_global->gen_assign_op ())
    {
      *os << "//Implementation Skeleton Copy Assignment" << be_nl;

      *os << be_global->impl_class_prefix () << node->flat_name ()
          << be_global->impl_class_suffix () << "& "
          << be_global->impl_class_prefix () << node->flat_name ()
          << be_global->impl_class_suffix () << "::operator=(const "
          << be_global->impl_class_prefix () << node->flat_name ()
          << be_global->impl_class_suffix () << "& t)" <<be_idt_nl
          << "{" << be_idt_nl
          << "return *this;" << be_uidt_nl
          << "}" << be_nl << be_uidt_nl;
    }

  // Generate code for elements in the scope (e.g., operations).

  if (this->visit_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_interface_is::"
                         "visit_interface - "
                         "codegen for scope failed\n"),
                        -1);
    }

  int status =
    node->traverse_inheritance_graph (
              be_visitor_interface_is::method_helper,
              os
            );

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

  return 0;
}


// Helper method to generate the members in the scope of the base classes.
int
be_visitor_interface_is::method_helper (be_interface *derived,
                                        be_interface *node,
                                        TAO_OutStream *os)
{
  if (ACE_OS::strcmp (derived->flat_name (), node->flat_name ()) != 0)
    {
      be_visitor_context ctx;
      ctx.state (TAO_CodeGen::TAO_ROOT_IS);
      ctx.interface (derived);
      ctx.stream (os);
      be_visitor_interface_is visitor (&ctx);

      if (visitor.visit_scope (node) == -1)

        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "be_visitor_interface_is::"
                             "method_helper\n"),
                            -1);
        }

    }

  return 0;
}