be_produce.cpp

Go to the documentation of this file.
00001 // $Id: be_produce.cpp 80536 2008-01-31 19:38:14Z cleeland $
00002 
00003 /*
00004 
00005 COPYRIGHT
00006 
00007 Copyright 1992, 1993, 1994 Sun Microsystems, Inc.  Printed in the United
00008 States of America.  All Rights Reserved.
00009 
00010 This product is protected by copyright and distributed under the following
00011 license restricting its use.
00012 
00013 The Interface Definition Language Compiler Front End (CFE) is made
00014 available for your use provided that you include this license and copyright
00015 notice on all media and documentation and the software program in which
00016 this product is incorporated in whole or part. You may copy and extend
00017 functionality (but may not remove functionality) of the Interface
00018 Definition Language CFE without charge, but you are not authorized to
00019 license or distribute it to anyone else except as part of a product or
00020 program developed by you or with the express written consent of Sun
00021 Microsystems, Inc. ("Sun").
00022 
00023 The names of Sun Microsystems, Inc. and any of its subsidiaries or
00024 affiliates may not be used in advertising or publicity pertaining to
00025 distribution of Interface Definition Language CFE as permitted herein.
00026 
00027 This license is effective until terminated by Sun for failure to comply
00028 with this license.  Upon termination, you shall destroy or return all code
00029 and documentation for the Interface Definition Language CFE.
00030 
00031 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
00032 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
00033 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
00034 DEALING, USAGE OR TRADE PRACTICE.
00035 
00036 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
00037 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
00038 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
00039 
00040 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
00041 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
00042 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
00043 
00044 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
00045 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
00046 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00047 
00048 Use, duplication, or disclosure by the government is subject to
00049 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
00050 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
00051 52.227-19.
00052 
00053 Sun, Sun Microsystems and the Sun logo are trademarks or registered
00054 trademarks of Sun Microsystems, Inc.
00055 
00056 SunSoft, Inc.
00057 2550 Garcia Avenue
00058 Mountain View, California  94043
00059 
00060 NOTE:
00061 
00062 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
00063 trademarks or registered trademarks of Sun Microsystems, Inc.
00064 
00065  */
00066 
00067 // BE_produce.cc - Produce the work of the BE - does nothing in the
00068 //                 dummy BE
00069 
00070 #include "global_extern.h"
00071 #include "TAO_IFR_BE_Export.h"
00072 #include "be_extern.h"
00073 #include "fe_extern.h"
00074 #include "ast_root.h"
00075 #include "ifr_visitor_macro.h"
00076 #include "ifr_removing_visitor.h"
00077 #include "ifr_adding_visitor.h"
00078 
00079 ACE_RCSID (be,
00080            be_produce,
00081            "$Id: be_produce.cpp 80536 2008-01-31 19:38:14Z cleeland $")
00082 
00083 // Clean up before exit, whether successful or not.
00084 TAO_IFR_BE_Export void
00085 BE_cleanup (void)
00086 {
00087   idl_global->destroy ();
00088 }
00089 
00090 // Abort this run of the BE.
00091 TAO_IFR_BE_Export void
00092 BE_abort (void)
00093 {
00094   ACE_ERROR ((LM_ERROR,
00095               ACE_TEXT ("Fatal Error - Aborting\n")));
00096 
00097   // BE_cleanup will be called after the exception is caught.
00098   throw Bailout ();
00099 }
00100 
00101 void
00102 BE_create_holding_scope (void)
00103 {
00104   CORBA::ModuleDef_ptr scope = CORBA::ModuleDef::_nil ();
00105 
00106   // If we are multi-threaded, it may already be created.
00107   CORBA::Contained_var result =
00108     be_global->repository ()->lookup_id (be_global->holding_scope_name ());
00109 
00110   // Will live until the repository goes away for good.
00111   if (CORBA::is_nil (result.in ()))
00112     {
00113       scope =
00114         be_global->repository ()->create_module (
00115                                       be_global->holding_scope_name (),
00116                                       be_global->holding_scope_name (),
00117                                       "1.0"
00118                                     );
00119     }
00120   else
00121     {
00122       scope = CORBA::ModuleDef::_narrow (result.in ());
00123     }
00124 
00125   be_global->holding_scope (scope);
00126 }
00127 
00128 int
00129 BE_ifr_repo_init (void)
00130 {
00131   try
00132   {
00133     CORBA::Object_var object =
00134       be_global->orb ()->resolve_initial_references ("InterfaceRepository");
00135 
00136     if (CORBA::is_nil (object.in ()))
00137       {
00138         ACE_ERROR_RETURN ((
00139             LM_ERROR,
00140             ACE_TEXT ("Null objref from resolve_initial_references\n")
00141           ),
00142           -1
00143         );
00144       }
00145 
00146     CORBA::Repository_var repo =
00147       CORBA::Repository::_narrow (object.in ());
00148 
00149     if (CORBA::is_nil (repo.in ()))
00150       {
00151         ACE_ERROR_RETURN ((
00152             LM_ERROR,
00153             ACE_TEXT ("CORBA::Repository::_narrow failed\n")
00154           ),
00155           -1
00156         );
00157       }
00158 
00159     be_global->repository (repo._retn ());
00160   }
00161   catch (CORBA::ORB::InvalidName &)
00162   {
00163     ACE_ERROR ((LM_ERROR,
00164                 ACE_TEXT ("resolution of Interface Repository failed\n")));
00165     throw Bailout ();
00166   }
00167 
00168   return 0;
00169 }
00170 
00171 // Do the work of this BE. This is the starting point for code generation.
00172 TAO_IFR_BE_Export void
00173 BE_produce (void)
00174 {
00175   try
00176     {
00177       int status = BE_ifr_repo_init ();
00178 
00179       if (status != 0)
00180         {
00181           return;
00182         }
00183 
00184       BE_create_holding_scope ();
00185 
00186       // Get the root node.
00187       AST_Decl *d = idl_global->root ();
00188       AST_Root *root = AST_Root::narrow_from_decl (d);
00189 
00190       if (root == 0)
00191         {
00192           ACE_ERROR ((LM_ERROR,
00193                       ACE_TEXT ("(%N:%l) BE_produce - ")
00194                       ACE_TEXT ("No Root\n")));
00195 
00196           BE_abort ();
00197         }
00198 
00199       if (be_global->removing ())
00200         {
00201           ifr_removing_visitor visitor;
00202 
00203           TAO_IFR_VISITOR_WRITE_GUARD;
00204 
00205           // If the visitor is dispatched this way, we need to override
00206           // only visit_scope() for the removing visitor.
00207           if (visitor.visit_scope (root) == -1)
00208             {
00209               ACE_ERROR ((
00210                   LM_ERROR,
00211                   ACE_TEXT ("(%N:%l) BE_produce -")
00212                   ACE_TEXT (" failed to accept removing visitor\n")
00213                 ));
00214 
00215               BE_abort ();
00216             }
00217         }
00218       else
00219         {
00220           ifr_adding_visitor visitor (d, 0, be_global->allow_duplicate_typedefs ());
00221 
00222           TAO_IFR_VISITOR_WRITE_GUARD;
00223 
00224           if (root->ast_accept (&visitor) == -1)
00225             {
00226               ACE_ERROR ((
00227                   LM_ERROR,
00228                   ACE_TEXT ("(%N:%l) BE_produce -")
00229                   ACE_TEXT (" failed to accept adding visitor\n")
00230                 ));
00231 
00232               BE_abort ();
00233             }
00234         }
00235     }
00236   catch (const CORBA::Exception& ex)
00237     {
00238       ex._tao_print_exception (ACE_TEXT ("BE_produce"));
00239 
00240     }
00241 
00242   // Clean up.
00243   BE_cleanup ();
00244 }

Generated on Tue Feb 2 17:50:49 2010 for TAO_IFR by  doxygen 1.4.7