PSDL_Scope.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 // PSDL_Scope.h,v 1.3 2003/08/02 18:10:48 bala Exp
00003 //
00004 // ==================================================================
00005 //
00006 // = LIBRARY
00007 //    PSS
00008 //
00009 // = FILENAME
00010 //    PSDL_Scope
00011 //
00012 // = DESCRIPTION
00013 //    This Class is a base class for building the ASTs. The derived
00014 //    classes override the virtual methods that they need. The class
00015 //    also contains the methods which are common to all the derived
00016 //    classes.
00017 //
00018 // = AUTHOR
00019 //    Priyanka Gontla <gontla_p@ociweb.com>
00020 //
00021 // ==================================================================
00022 
00023 #ifndef TAO_PSDL_SCOPE_H
00024 #define TAO_PSDL_SCOPE_H
00025 
00026 #include /**/ "ace/pre.h"
00027 
00028 #include "tao/corbafwd.h"
00029 
00030 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00031 # pragma once
00032 #endif /* ACE_LACKS_PRAGMA_ONCE */
00033 
00034 #include "psdl_export.h"
00035 
00036 #include "tao/TAO_Singleton.h"
00037 
00038 #include "ace/Hash_Map_Manager_T.h"
00039 #include "ace/Array_Base.h"
00040 #include "ace/SString.h"
00041 
00042 
00043 // Fwd Declarations.
00044 class TAO_PSDL_Node;
00045 class TAO_PSDL_Scope;
00046 class TAO_PSDL_Root_Scope;
00047 class TAO_PSDL_Stream;
00048 
00049 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;
00050 
00051 typedef Scope_Map::iterator Scope_Map_Iterator;
00052 
00053 class TAO_PSDL_Export TAO_PSDL_Scope
00054 {
00055   // The TAO_PSDL_Scope class serves two purposes. One it acts as the
00056   // base class from which the child classes derive to be able to add
00057   // the members in their scopes. TAO_PSDL_Root_Scope is the root
00058   // scope where any thing goes into. If there is a module in the idl
00059   // file, all the members in the module are to be added to an
00060   // instance of TAO_PSDL_Module_Scope. And, it also acts as a class
00061   // that has the common members to be accessed by all the derived
00062   // classes. For example, add_module_to_scope is the common method
00063   // for all the sub-classes to invoke from the add_module method.
00064   friend class TAO_Singleton<TAO_PSDL_Scope, TAO_SYNCH_MUTEX>;
00065 
00066 public:
00067 
00068   TAO_PSDL_Scope (void);
00069 
00070   virtual ~TAO_PSDL_Scope (void);
00071 
00072   /// The add functions are overridden by the derived classes to add
00073   /// the respective types in their scopes. The return value is a '0'
00074   /// if successful and '-1' if it ends up as a failure.
00075   virtual int add_module (ACE_CString identifier);
00076 
00077   virtual int add_interface (ACE_CString identifier);
00078 
00079   virtual int add_struct (ACE_CString identifier);
00080 
00081   virtual int add_typedef (ACE_CString identifier,
00082                            ACE_CString identifier_type);
00083 
00084   virtual int add_const_decl (ACE_CString identifier,
00085                               ACE_CString identifier_type);
00086 
00087   virtual int add_except_decl (ACE_CString identifier,
00088                                ACE_CString identifier_type);
00089 
00090   virtual int add_exception (ACE_CString identifier);
00091 
00092   virtual int add_op_dcl (ACE_CString identifier);
00093 
00094   virtual int add_member_decl (ACE_CString identifier,
00095                                ACE_CString identifier_type);
00096 
00097   /// Return the top scope.
00098   virtual TAO_PSDL_Scope *pop_top_scope (void);
00099 
00100   /// Push the scope that is passed into the stack of scopes.
00101   virtual void push_scope (TAO_PSDL_Scope *scope);
00102 
00103   /// Return the pointer to the parent scope.
00104   virtual TAO_PSDL_Scope *parent_scope (void);
00105 
00106   /// Return the pointer to Scope_Map of the instance.
00107   virtual Scope_Map *scope_map (void);
00108 
00109   /// Function to help indent the output of the parse tree.
00110   virtual void dump (CORBA::ULong depth);
00111 
00112   /// Function to find the TAO_PSDL_Scope for the given identifier_name
00113   virtual int find (const ACE_CString &identifier_name,
00114                     ACE_CString &identifier_type);
00115 
00116   /// Function to check if a particular identifier_name exists in the
00117   /// scope.
00118   virtual int find (const ACE_CString &identifier_name);
00119 
00120   /// To get the name of the module to which an identifier_name
00121   /// belongs. returns '0' on succes and '-1' on failure.
00122   virtual int get_module_name (const ACE_CString &identifier_name,
00123                                ACE_CString &module_name);
00124 
00125   /// To get the name of the interface to which an identifier_name
00126   /// belongs. returns '0' on succes and '-1' on failure.
00127   virtual int get_interface_name (const ACE_CString &identifier_name,
00128                                   ACE_CString &interface_name);
00129 
00130   /// Each identifier will have an instance of a derived type of
00131   /// TAO_PSDL_Scope *.. the following method is an accessor to the
00132   /// type of the identifier name
00133   virtual ACE_CString identifier_type (void);
00134   virtual ACE_CString module_name (void);
00135   virtual ACE_CString interface_name (void);
00136 
00137   /// As the function name implies, the following methods help add the
00138   /// respective types to the scope passed in. The return value is a
00139   /// '0' on success and '-1' on a failure.
00140   int add_module_to_scope (ACE_CString identifier,
00141                            TAO_PSDL_Scope *scope);
00142 
00143   int add_interface_to_scope (ACE_CString identifier,
00144                               TAO_PSDL_Scope *scope);
00145 
00146   int add_interface_dcl_to_scope (ACE_CString identifier,
00147                                   TAO_PSDL_Scope *scope);
00148 
00149   int add_struct_to_scope (ACE_CString identifier,
00150                            TAO_PSDL_Scope *scope);
00151 
00152   int add_typedef_to_scope (ACE_CString identifier,
00153                             ACE_CString identifier_type,
00154                             TAO_PSDL_Scope *scope);
00155 
00156   int add_const_decl_to_scope (ACE_CString identifier,
00157                                ACE_CString identifier_type,
00158                                TAO_PSDL_Scope *scope);
00159 
00160   int add_except_decl_to_scope (ACE_CString identifier,
00161                                 ACE_CString identifier_type,
00162                                 TAO_PSDL_Scope *scope);
00163 
00164   int add_exception_to_scope (ACE_CString identifier,
00165                               TAO_PSDL_Scope *scope);
00166 
00167   int add_scoped_decl_to_scope (ACE_CString identifier,
00168                                 ACE_CString identifier_type,
00169                                 TAO_PSDL_Scope *scope);
00170 
00171   int add_enum_decl_to_scope (ACE_CString identifier,
00172                               ACE_CString identifier_type,
00173                               TAO_PSDL_Scope *scope);
00174 
00175   int add_op_dcl_to_scope (ACE_CString identifier,
00176                            TAO_PSDL_Scope *scope);
00177 
00178   int add_member_decl_to_scope (ACE_CString identifier,
00179                                 ACE_CString identifier_type,
00180                                 TAO_PSDL_Scope *scope);
00181 
00182   /// Set the root scope the very first time.
00183   void set_root_scope (void);
00184 
00185   /// Set and get the name of the stub that has to be generated. The name
00186   /// is based on the input file that is passed to the compiler.
00187   void set_stub_prefix (const char *filename);
00188   const ACE_CString &get_stub_prefix (void);
00189 
00190   /// These methods help write the header files that needs to be
00191   /// included and other initialization part to the stubs.
00192   void header_initialization (TAO_PSDL_Stream *ps_sh);
00193   void stub_initialization (TAO_PSDL_Stream *ps_si);
00194 
00195   /// Get the pointer to the TAO_PSDL_Stream for the stub header.
00196   TAO_PSDL_Stream *get_sh (void);
00197 
00198   /// Get the pointer to the TAO_PSDL_Stream for the stub
00199   /// implementation file.
00200   TAO_PSDL_Stream *get_si (void);
00201 
00202   /// Get the pointer to the TAO_PSDL_Stream for the stub
00203   /// inline file.
00204   TAO_PSDL_Stream *get_sinline (void);
00205 
00206   /// As the name suggests, check if the identifier name is already
00207   /// used for something else in the sc
00208   int check_identifier (ACE_CString identifier,
00209                         TAO_PSDL_Scope *scope);
00210 
00211   /// This is to check if a forward declaration has been done
00212   /// already.
00213   void check_name_in_scope (ACE_CString identifier,
00214                             TAO_PSDL_Scope *scope);
00215 
00216   /// Return a unique instance
00217   static TAO_PSDL_Scope *instance (void);
00218 
00219   /// This wont be necessary in the final version .. its helpful to
00220   /// print the symbol table to the std output for now.
00221   void print_depth (CORBA::ULong depth);
00222 
00223   /// Method used to set the scope back to the previous one.
00224   void set_scope (void);
00225 
00226   /// Set interface scope to the previous one.
00227   void set_interface_scope (void);
00228 
00229   /// Set module scope to the previous one.
00230   void set_module_scope (void);
00231 
00232   /// Methods to save and retrieve the identifier values.
00233   void save_identifier (ACE_CString identifier);
00234   ACE_CString get_identifier (void);
00235 
00236   /// Accessor methods to the name of the name_space: Module name
00237   void set_name_space (ACE_CString name_space);
00238   ACE_CString get_name_space (void);
00239 
00240   /// Accessor methods to the name of the current interface.
00241   void set_interface_name (ACE_CString interface_name);
00242   ACE_CString get_interface_name (void);
00243 
00244   // Helper method for the semantic checking. By converting all the
00245   // identifiers to lower case before adding to the scope.
00246   void to_lower_case (ACE_CString &identifier);
00247 
00248   /// Helper method to convert the int value of the identifier type to
00249   /// its string equivalent based on the conversion values generated
00250   /// by the Yacc Parser (please see PSDL_y.h for the conversion values).
00251   ACE_CString convert_str (int identifier_type);
00252 
00253 private:
00254 
00255   /// Array of TAO_PSDL_Scope pointers to be used with the singleton
00256   /// instance.
00257   TAO_PSDL_Scope **psdl_scope_;
00258 
00259   /// Save the psdl_scopes for use while writing
00260   /// to stubs.
00261   ACE_Array_Base <TAO_PSDL_Scope *> ast_scope_;
00262 
00263   /// Arrays to save the module and interface names
00264   ACE_Array_Base <ACE_CString> module_names_;
00265   ACE_Array_Base <ACE_CString> interface_names_;
00266 
00267   /// Count of the members in the psdl_scope_
00268   unsigned long psdl_scope_top_;
00269 
00270   /// Pointer to the instance of the TAO_PSDL_Root_Scope.
00271   TAO_PSDL_Root_Scope *root_scope_;
00272 
00273   /// Identifier used for the save_identifier and get_identifier
00274   /// methods.
00275   ACE_CString identifier_;
00276 
00277   /// Save for use while writing to stubs.
00278   ACE_CString name_space_;
00279   ACE_CString interface_name_;
00280 
00281   /// Name of the filename that is passed to the compiler psdl_tao.
00282   ACE_CString stub_prefix_;
00283 
00284   /// Pointers to the TAO_PSDL_Streams for the stub header,
00285   /// implementation and inline files.
00286   TAO_PSDL_Stream *ps_sh_;
00287   TAO_PSDL_Stream *ps_si_;
00288   TAO_PSDL_Stream *ps_sin_;
00289 
00290 };
00291 
00292 #include /**/ "ace/post.h"
00293 
00294 #endif /* TAO_PSDL_SCOPE_H */

Generated on Thu Nov 9 14:07:04 2006 for TAO_PSS by doxygen 1.3.6