summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_interface/amh_ch.cpp
blob: 1e4deb2c6348b6d70dd926dedcba233f9437c210 (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
//=============================================================================
/**
*  @file   amh_ch.cpp
*
*  $Id$
*
*  Specialized interface visitor for AMH-RH generates code that is 
*  specific to AMH interfaces.
*
*  @author Mayur Deshpande <mayur@ics.uci.edu>
*/
//=============================================================================

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

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

be_visitor_amh_interface_ch::~be_visitor_amh_interface_ch (void)
{
}

int
be_visitor_amh_interface_ch::visit_interface (be_interface *node)
{
  TAO_OutStream *os = this->ctx_->stream ();

  // If not already generated and not imported.
  if (!node->cli_hdr_gen () && !node->imported ())
    {
      // == STEP 1:  generate the class name and class names we inherit ==

      // Generate the ifdefined macro for  the _ptr type.
      os->gen_ifdef_macro (node->flat_name (),
                           "_ptr");

      // The following two are required to be under the ifdef macro to avoid
      // multiple declarations.

      // Forward declaration.
      *os << "class " << node->local_name () << ";" << be_nl;
      // Generate the _ptr declaration.
      *os << "typedef " << node->local_name () << " *"
          << node->local_name () << "_ptr;" << be_nl;

      os->gen_endif ();

      // Generate the ifdefined macro for the var type.
      os->gen_ifdef_macro (node->flat_name (), "_var");

      // Generate the _var declaration.
      if (node->gen_var_defn () == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_interface_ch::"
                             "visit_interface - "
                             "codegen for _var failed\n"),
                            -1);
        }

      os->gen_endif ();

    }

  // The above code could have been executed by the forward declaration
  // as long as it wasn't imported. The code below can only be
  // executed by an interface definition, also non-imported.
  if (node->imported ())
    {
      return 0;
    }

  // Now the interface definition itself.
  os->gen_ifdef_macro (node->flat_name ());

  // Now generate the class definition.
  *os << "class " << be_global->stub_export_macro ()
      << " " << node->local_name () << be_idt_nl
      << ": " ;

  // If node interface inherits from other interfaces.
  if (node->n_inherits () > 0)
    {
      *os << be_idt;

      for (int i = 0; i < node->n_inherits (); i++)
        {
          *os << "public virtual "
              << node->inherits ()[i]->name ();

          if (i < node->n_inherits () - 1)
            {
              // Node has multiple inheritance, so put a comma.
              *os << "," << be_nl;
            }
        }

      *os << be_uidt << be_uidt_nl;
    }
  else
    {
      // We do not inherit from anybody, hence we do so from the base
      // CORBA::Object class.
      *os << "public virtual CORBA_Object" << be_uidt_nl;
    }

  // Generate the body.

  *os << "{" << be_nl
      << "public:" << be_idt_nl

      // Generate the _ptr_type and _var_type typedefs.
      << "typedef " << node->local_name () << "_ptr _ptr_type;"
      << be_nl
      << "typedef " << node->local_name () << "_var _var_type;"
      << be_nl;

  // Generate code for the interface definition by traversing thru the
  // elements of its scope. We depend on the front-end to have made sure
  // that only legal syntactic elements appear in our scope.

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

  node->cli_hdr_gen (I_TRUE);

  return 0;
}