summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/PSS/PSDL_Scope.h
blob: 0e7ad9d08626a531ab3f3a45283d74f4902aec78 (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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* -*- C++ -*- */
// $Id$
//
// ==================================================================
//
// = LIBRARY
//    PSS
//
// = FILENAME
//    PSDL_Scope
//
// = DESCRIPTION
//    This Class is a base class for building the ASTs. The derived
//    classes override the virtual methods that they need. The class
//    also contains the methods which are common to all the derived
//    classes.
//
// = AUTHOR
//    Priyanka Gontla <gontla_p@ociweb.com>
//
// ==================================================================

#ifndef TAO_PSDL_SCOPE_H
#define TAO_PSDL_SCOPE_H

#include /**/ "ace/pre.h"

#include "tao/corbafwd.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "psdl_export.h"

#include "tao/TAO_Singleton.h"

#include "ace/Hash_Map_Manager_T.h"
#include "ace/Array_Base.h"
#include "ace/SString.h"


// Fwd Declarations.
class TAO_PSDL_Node;
class TAO_PSDL_Scope;
class TAO_PSDL_Root_Scope;
class TAO_PSDL_Stream;

typedef ACE_Hash_Map_Manager_Ex<ACE_CString, TAO_PSDL_Scope *, ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, TAO_SYNCH_MUTEX> Scope_Map;

typedef Scope_Map::iterator Scope_Map_Iterator;

class TAO_PSDL_Export TAO_PSDL_Scope
{
  // The TAO_PSDL_Scope class serves two purposes. One it acts as the
  // base class from which the child classes derive to be able to add
  // the members in their scopes. TAO_PSDL_Root_Scope is the root
  // scope where any thing goes into. If there is a module in the idl
  // file, all the members in the module are to be added to an
  // instance of TAO_PSDL_Module_Scope. And, it also acts as a class
  // that has the common members to be accessed by all the derived
  // classes. For example, add_module_to_scope is the common method
  // for all the sub-classes to invoke from the add_module method.
  friend class TAO_Singleton<TAO_PSDL_Scope, TAO_SYNCH_MUTEX>;

public:

  TAO_PSDL_Scope (void);

  virtual ~TAO_PSDL_Scope (void);

  /// The add functions are overridden by the derived classes to add
  /// the respective types in their scopes. The return value is a '0'
  /// if successful and '-1' if it ends up as a failure.
  virtual int add_module (ACE_CString identifier);

  virtual int add_interface (ACE_CString identifier);

  virtual int add_struct (ACE_CString identifier);

  virtual int add_typedef (ACE_CString identifier,
                           ACE_CString identifier_type);

  virtual int add_const_decl (ACE_CString identifier,
                              ACE_CString identifier_type);

  virtual int add_except_decl (ACE_CString identifier,
                               ACE_CString identifier_type);

  virtual int add_exception (ACE_CString identifier);

  virtual int add_op_dcl (ACE_CString identifier);

  virtual int add_member_decl (ACE_CString identifier,
                               ACE_CString identifier_type);

  /// Return the top scope.
  virtual TAO_PSDL_Scope *pop_top_scope (void);

  /// Push the scope that is passed into the stack of scopes.
  virtual void push_scope (TAO_PSDL_Scope *scope);

  /// Return the pointer to the parent scope.
  virtual TAO_PSDL_Scope *parent_scope (void);

  /// Return the pointer to Scope_Map of the instance.
  virtual Scope_Map *scope_map (void);

  /// Function to help indent the output of the parse tree.
  virtual void dump (CORBA::ULong depth);

  /// Function to find the TAO_PSDL_Scope for the given identifier_name
  virtual int find (const ACE_CString &identifier_name,
                    ACE_CString &identifier_type);

  /// Function to check if a particular identifier_name exists in the
  /// scope.
  virtual int find (const ACE_CString &identifier_name);

  /// To get the name of the module to which an identifier_name
  /// belongs. returns '0' on succes and '-1' on failure.
  virtual int get_module_name (const ACE_CString &identifier_name,
                               ACE_CString &module_name);

  /// To get the name of the interface to which an identifier_name
  /// belongs. returns '0' on succes and '-1' on failure.
  virtual int get_interface_name (const ACE_CString &identifier_name,
                                  ACE_CString &interface_name);

  /// Each identifier will have an instance of a derived type of
  /// TAO_PSDL_Scope *.. the following method is an accessor to the
  /// type of the identifier name
  virtual ACE_CString identifier_type (void);
  virtual ACE_CString module_name (void);
  virtual ACE_CString interface_name (void);

  /// As the function name implies, the following methods help add the
  /// respective types to the scope passed in. The return value is a
  /// '0' on success and '-1' on a failure.
  int add_module_to_scope (ACE_CString identifier,
                           TAO_PSDL_Scope *scope);

  int add_interface_to_scope (ACE_CString identifier,
                              TAO_PSDL_Scope *scope);

  int add_interface_dcl_to_scope (ACE_CString identifier,
                                  TAO_PSDL_Scope *scope);

  int add_struct_to_scope (ACE_CString identifier,
                           TAO_PSDL_Scope *scope);

  int add_typedef_to_scope (ACE_CString identifier,
                            ACE_CString identifier_type,
                            TAO_PSDL_Scope *scope);

  int add_const_decl_to_scope (ACE_CString identifier,
                               ACE_CString identifier_type,
                               TAO_PSDL_Scope *scope);

  int add_except_decl_to_scope (ACE_CString identifier,
                                ACE_CString identifier_type,
                                TAO_PSDL_Scope *scope);

  int add_exception_to_scope (ACE_CString identifier,
                              TAO_PSDL_Scope *scope);

  int add_scoped_decl_to_scope (ACE_CString identifier,
                                ACE_CString identifier_type,
                                TAO_PSDL_Scope *scope);

  int add_enum_decl_to_scope (ACE_CString identifier,
                              ACE_CString identifier_type,
                              TAO_PSDL_Scope *scope);

  int add_op_dcl_to_scope (ACE_CString identifier,
                           TAO_PSDL_Scope *scope);

  int add_member_decl_to_scope (ACE_CString identifier,
                                ACE_CString identifier_type,
                                TAO_PSDL_Scope *scope);

  /// Set the root scope the very first time.
  void set_root_scope (void);

  /// Set and get the name of the stub that has to be generated. The name
  /// is based on the input file that is passed to the compiler.
  void set_stub_prefix (const char *filename);
  const ACE_CString &get_stub_prefix (void);

  /// These methods help write the header files that needs to be
  /// included and other initialization part to the stubs.
  void header_initialization (TAO_PSDL_Stream *ps_sh);
  void stub_initialization (TAO_PSDL_Stream *ps_si);

  /// Get the pointer to the TAO_PSDL_Stream for the stub header.
  TAO_PSDL_Stream *get_sh (void);

  /// Get the pointer to the TAO_PSDL_Stream for the stub
  /// implementation file.
  TAO_PSDL_Stream *get_si (void);

  /// Get the pointer to the TAO_PSDL_Stream for the stub
  /// inline file.
  TAO_PSDL_Stream *get_sinline (void);

  /// As the name suggests, check if the identifier name is already
  /// used for something else in the sc
  int check_identifier (ACE_CString identifier,
                        TAO_PSDL_Scope *scope);

  /// This is to check if a forward declaration has been done
  /// already.
  void check_name_in_scope (ACE_CString identifier,
                            TAO_PSDL_Scope *scope);

  /// Return a unique instance
  static TAO_PSDL_Scope *instance (void);

  /// This wont be necessary in the final version .. its helpful to
  /// print the symbol table to the std output for now.
  void print_depth (CORBA::ULong depth);

  /// Method used to set the scope back to the previous one.
  void set_scope (void);

  /// Set interface scope to the previous one.
  void set_interface_scope (void);

  /// Set module scope to the previous one.
  void set_module_scope (void);

  /// Methods to save and retrieve the identifier values.
  void save_identifier (ACE_CString identifier);
  ACE_CString get_identifier (void);

  /// Accessor methods to the name of the name_space: Module name
  void set_name_space (ACE_CString name_space);
  ACE_CString get_name_space (void);

  /// Accessor methods to the name of the current interface.
  void set_interface_name (ACE_CString interface_name);
  ACE_CString get_interface_name (void);

  // Helper method for the semantic checking. By converting all the
  // identifiers to lower case before adding to the scope.
  void to_lower_case (ACE_CString &identifier);

  /// Helper method to convert the int value of the identifier type to
  /// its string equivalent based on the conversion values generated
  /// by the Yacc Parser (please see PSDL_y.h for the conversion values).
  ACE_CString convert_str (int identifier_type);

private:

  /// Array of TAO_PSDL_Scope pointers to be used with the singleton
  /// instance.
  TAO_PSDL_Scope **psdl_scope_;

  /// Save the psdl_scopes for use while writing
  /// to stubs.
  ACE_Array_Base <TAO_PSDL_Scope *> ast_scope_;

  /// Arrays to save the module and interface names
  ACE_Array_Base <ACE_CString> module_names_;
  ACE_Array_Base <ACE_CString> interface_names_;

  /// Count of the members in the psdl_scope_
  unsigned long psdl_scope_top_;

  /// Pointer to the instance of the TAO_PSDL_Root_Scope.
  TAO_PSDL_Root_Scope *root_scope_;

  /// Identifier used for the save_identifier and get_identifier
  /// methods.
  ACE_CString identifier_;

  /// Save for use while writing to stubs.
  ACE_CString name_space_;
  ACE_CString interface_name_;

  /// Name of the filename that is passed to the compiler psdl_tao.
  ACE_CString stub_prefix_;

  /// Pointers to the TAO_PSDL_Streams for the stub header,
  /// implementation and inline files.
  TAO_PSDL_Stream *ps_sh_;
  TAO_PSDL_Stream *ps_si_;
  TAO_PSDL_Stream *ps_sin_;

};

#include /**/ "ace/post.h"

#endif /* TAO_PSDL_SCOPE_H */