summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_module.cpp
blob: f51a834806b965729312ecf67efe230340b5a36b (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
// $Id$
// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    be_module.cpp
//
// = DESCRIPTION
//    Extension of class AST_Module that provides additional means for C++
//    mapping of a module
//
// = AUTHOR
//    Copyright 1994-1995 by Sun Microsystems, Inc.
//    and
//    Aniruddha Gokhale
//
// ============================================================================

#include	"idl.h"
#include	"idl_extern.h"
#include	"be.h"

/*
 * BE_Module
 */
be_module::be_module (void)
{
}

be_module::be_module (UTL_ScopedName *n, UTL_StrList *p)
  : AST_Decl (AST_Decl::NT_module, n, p),
    UTL_Scope (AST_Decl::NT_module)
{
}

// ----------------------------------------
//            CODE GENERATION METHODS
// ----------------------------------------

// generate the client header
int be_module::gen_client_header (void)
{
  TAO_OutStream *ch; // output stream
  TAO_NL  nl;        // end line


  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_MODULE_CH); // set the current code generation state
  ch = cg->client_header (); // get the stream

  // XXXASG - Modules really map to namespace. We need to see if our target
  // compiler supports namespaces or not. For this release we opt to generate a
  // class definition for a module

  ch->indent (); // start with whatever indentation level we are at

  // now generate the class definition
  *ch << "class " << idl_global->export_macro ()
      << " " << local_name ();

  // generate the body
  *ch << "{" << nl;
  *ch << "public:\n";
  ch->incr_indent (0);

  // generate code for the module 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 (be_scope::gen_client_header () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_module::gen_client_header\n"));
      ACE_ERROR ((LM_ERROR, "Scope code generation failure\n"));
      return -1;
    }

  ch->decr_indent ();
  *ch << "};\n\n";
  cg->pop ();
  return 0;
}

int be_module::gen_client_stubs (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_MODULE_CS); // set the current code generation state

  // gen code for elements in the scope
  if (be_scope::gen_client_stubs () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_module::gen_client_stubs\n"));
      ACE_ERROR ((LM_ERROR, "Scope code generation failure\n"));
      return -1;
    }

  cg->pop ();
  return 0;
}

int be_module::gen_server_header (void)
{
  TAO_OutStream *sh; // output stream
  TAO_NL  nl;        // end line
  AST_Decl *d;

  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_MODULE_SH); // set the current code generation state

  sh = cg->server_header ();

  // generate the skeleton class name

  sh->indent (); // start with whatever indentation level we are at

  // now generate the class definition. The prefix POA_ is prepended to our
  // name only if we are the outermost module
  d = ScopeAsDecl (this->defined_in ());

  *sh << "class " << idl_global->export_macro ()
      << " ";
  if (d->node_type () == AST_Decl::NT_root)
    // we are outermost module
    *sh << "POA_" << local_name () << nl;
  else
    // we are inside another module
    *sh << local_name () << nl;

  *sh << "{" << nl;
  *sh << "public:\n";
  sh->incr_indent (0);

  if (be_scope::gen_server_header () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_module::gen_server_header\n"));
      ACE_ERROR ((LM_ERROR, "Scope code generation failure\n"));
      return -1;
    }

  sh->decr_indent ();
  *sh << "};\n\n";
  cg->pop ();
  return 0;
}

int be_module::gen_server_skeletons (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_MODULE_SS); // set the current code generation state

  if (be_scope::gen_server_skeletons () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_module::gen_server_skeletons\n"));
      ACE_ERROR ((LM_ERROR, "Scope code generation failure\n"));
      return -1;
    }
  cg->pop ();
  return 0;
}

// Generates the client-side inline information
int
be_module::gen_client_inline (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_MODULE_CI); // set the current code generation state

  // gen code for elements in the scope
  if (be_scope::gen_client_inline () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_module::gen_client_inline\n"));
      ACE_ERROR ((LM_ERROR, "Scope code generation failure\n"));
      return -1;
    }

  cg->pop ();
  return 0;
}

// Generates the server-side inline
int
be_module::gen_server_inline (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_MODULE_SI); // set the current code generation state

  // gen code for elements in the scope
  if (be_scope::gen_server_inline () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_module::gen_server_inline\n"));
      ACE_ERROR ((LM_ERROR, "Scope code generation failure\n"));
      return -1;
    }

  cg->pop ();
  return 0;
}

// compute the size type of the node in question
int
be_module::compute_size_type (void)
{
  // our size does not matter
  return 0;
}

int
be_module::accept (be_visitor *visitor)
{
  return visitor->visit_module (this);
}

// Narrowing
IMPL_NARROW_METHODS3 (be_module, AST_Module, be_scope, be_decl)
IMPL_NARROW_FROM_DECL (be_module)
IMPL_NARROW_FROM_SCOPE (be_module)