utl_global.cpp

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,322 行 · 第 1/3 页

CPP
1,322
字号
// utl_global.cpp,v 1.103 2004/01/07 23:18:10 bala Exp

/*

COPYRIGHT

Copyright 1992, 1993, 1994 Sun Microsystems, Inc.  Printed in the United
States of America.  All Rights Reserved.

This product is protected by copyright and distributed under the following
license restricting its use.

The Interface Definition Language Compiler Front End (CFE) is made
available for your use provided that you include this license and copyright
notice on all media and documentation and the software program in which
this product is incorporated in whole or part. You may copy and extend
functionality (but may not remove functionality) of the Interface
Definition Language CFE without charge, but you are not authorized to
license or distribute it to anyone else except as part of a product or
program developed by you or with the express written consent of Sun
Microsystems, Inc. ("Sun").

The names of Sun Microsystems, Inc. and any of its subsidiaries or
affiliates may not be used in advertising or publicity pertaining to
distribution of Interface Definition Language CFE as permitted herein.

This license is effective until terminated by Sun for failure to comply
with this license.  Upon termination, you shall destroy or return all code
and documentation for the Interface Definition Language CFE.

INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
DEALING, USAGE OR TRADE PRACTICE.

INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.

SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.

IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

Use, duplication, or disclosure by the government is subject to
restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
52.227-19.

Sun, Sun Microsystems and the Sun logo are trademarks or registered
trademarks of Sun Microsystems, Inc.

SunSoft, Inc.
2550 Garcia Avenue
Mountain View, California  94043

NOTE:

SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
trademarks or registered trademarks of Sun Microsystems, Inc.

*/

#include "idl_global.h"
#include "global_extern.h"
#include "ast_root.h"
#include "ast_generator.h"
#include "utl_identifier.h"
#include "utl_indenter.h"
#include "utl_err.h"
#include "utl_string.h"
#include "ace/OS_NS_stdio.h"

ACE_RCSID (util,
           utl_global,
           "utl_global.cpp,v 1.103 2004/01/07 23:18:10 bala Exp")

// Define an increment for the size of the array used to store names of
// included files.
#undef INCREMENT
#define INCREMENT 64

static long seen_once[INCREMENT] = {0};

IDL_GlobalData::dsf::dsf (void)
  : interface_seen_ (0),
    valuetype_seen_ (0),
    abstract_iface_seen_ (0),
    local_iface_seen_ (0),
    non_local_iface_seen_ (0),
    fwd_iface_seen_ (0),
    fwd_valuetype_seen_ (0),
    basic_type_seen_ (0),
    ambiguous_type_seen_ (0),
    enum_seen_ (0),
    string_seen_ (0),
    array_seen_ (0),
    aggregate_seen_ (0),
    union_seen_ (0),
    exception_seen_ (0),
    operation_seen_ (0),
    non_local_op_seen_ (0),
    typecode_seen_ (0),
    any_seen_ (0),
    parametermode_seen_ (0),
    base_object_seen_ (0),
    valuefactory_seen_ (0),

    seq_seen_ (0),
    iface_seq_seen_ (0),
    vt_seq_seen_ (0),
    array_seq_seen_ (0),
    pseudo_seq_seen_ (0),
    string_seq_seen_ (0),
    wstring_seq_seen_ (0),
    octet_seq_seen_ (0),

    basic_arg_seen_ (0),
    bd_string_arg_seen_ (0),
    fixed_array_arg_seen_ (0),
    fixed_size_arg_seen_ (0),
    object_arg_seen_ (0),
    special_basic_arg_seen_ (0),
    ub_string_arg_seen_ (0),
    var_array_arg_seen_ (0),
    var_size_arg_seen_ (0)
{}

IDL_GlobalData::IDL_GlobalData (void)
  : decls_seen_info_ (0),
    pd_root (0),
    pd_gen (0),
    pd_err (0),
    pd_err_count (0),
    pd_lineno (0),
    pd_filename (0),
    pd_main_filename (0),
    pd_real_filename (0),
    pd_stripped_filename (0),
    pd_import (I_FALSE),
    pd_in_main_file (I_FALSE),
    pd_prog_name (0),
    pd_cpp_location (0),
    pd_compile_flags (0),
    pd_be (0),
    pd_local_escapes (0),
    pd_indent (0),
    pd_read_from_stdin (I_FALSE),
    pd_include_file_names (0),
    pd_n_include_file_names (0),
    pd_n_alloced_file_names (0),
    included_idl_files_ (0),
    n_included_idl_files_ (0),
    n_allocated_idl_files_ (0),
    pd_parse_state (PS_NoState),
    pd_idl_src_file (0),
    gperf_path_ (0),
    temp_dir_ (0),
    ident_string_ (0),
    obv_support_ (I_TRUE),
    case_diff_error_ (I_TRUE),
    nest_orb_ (I_FALSE),
    idl_flags_ (""),
    preserve_cpp_keywords_ (I_TRUE)
{
  // Path for the perfect hash generator(gperf) program.
  // Default is $ACE_ROOT/bin/gperf unless ACE_GPERF is defined.
  // Use ACE_GPERF if $ACE_ROOT hasn't been set or won't be set
  // in the environment.
  // Form the absolute pathname.
  char* ace_root = ACE_OS::getenv ("ACE_ROOT");
  if (ace_root == 0)
    // This may not cause any problem if -g option is used to specify
    // the correct path for the  gperf program. Let us ignore this
    // error here. It will be caught when we check the existence of
    // the perfect hasher and at that time, we can switch over to some
    // other scheme.
    {
#if defined (ACE_GPERF)
      // The actual gperf program must be included in the definition of
      // ACE_GPERF, not just the directory in which it is located.
      const char ace_gperf[] = ACE_GPERF;
      ACE_NEW (this->gperf_path_,
               char [ACE_OS::strlen (ace_gperf) + 1]);
      ACE_OS::sprintf (this->gperf_path_,
                       "%s",
                       ace_gperf);
#else
      this->gperf_path_ = 0;
#endif
    }
  else
    {
#if defined (ACE_GPERF)
      const char ace_gperf[] = ACE_GPERF;
      ACE_NEW (this->gperf_path_,
               char [ACE_OS::strlen (ace_root)
                     + ACE_OS::strlen (ace_gperf)
                     + 1]);
#  if defined (ACE_WIN32)
      ACE_OS::sprintf (this->gperf_path_,
                       "%s\\bin\\%s",
                       ace_root,
                       ace_gperf);
#  else /* Not ACE_WIN32 */
      ACE_OS::sprintf (this->gperf_path_,
                       "%s/bin/%s",
                       ace_root,
                       ace_gperf);
#  endif /* ACE_WIN32 */
#else /* Not ACE_GPERF */
      // Set it to the default value.
      ACE_NEW (this->gperf_path_,
               char [ACE_OS::strlen (ace_root)
                     + ACE_OS::strlen ("/bin/gperf")
                     + 1]);
#  if defined (ACE_WIN32)
      ACE_OS::sprintf (this->gperf_path_,
                       "%s\\bin\\gperf",
                       ace_root);
#  else /* Not ACE_WIN32 */
      ACE_OS::sprintf (this->gperf_path_,
                       "%s/bin/gperf",
                       ace_root);
#  endif /* ACE_WIN32 */
#endif /* ACE_GPERF */
    }

  // Initialize the decls seen info masks

  const ACE_UINT64 cursor = 1U;

  ACE_SET_BITS (this->decls_seen_masks.interface_seen_,         cursor);
  ACE_SET_BITS (this->decls_seen_masks.valuetype_seen_,         cursor << 1);
  ACE_SET_BITS (this->decls_seen_masks.abstract_iface_seen_,    cursor << 2);
  ACE_SET_BITS (this->decls_seen_masks.local_iface_seen_,       cursor << 3);
  ACE_SET_BITS (this->decls_seen_masks.non_local_iface_seen_,   cursor << 4);
  ACE_SET_BITS (this->decls_seen_masks.fwd_iface_seen_,         cursor << 5);
  ACE_SET_BITS (this->decls_seen_masks.fwd_valuetype_seen_,     cursor << 6);
  ACE_SET_BITS (this->decls_seen_masks.basic_type_seen_,        cursor << 7);
  ACE_SET_BITS (this->decls_seen_masks.ambiguous_type_seen_,    cursor << 8);
  ACE_SET_BITS (this->decls_seen_masks.enum_seen_,              cursor << 9);
  ACE_SET_BITS (this->decls_seen_masks.string_seen_,            cursor << 10);
  ACE_SET_BITS (this->decls_seen_masks.array_seen_,             cursor << 11);
  ACE_SET_BITS (this->decls_seen_masks.aggregate_seen_,         cursor << 12);
  ACE_SET_BITS (this->decls_seen_masks.union_seen_,             cursor << 13);
  ACE_SET_BITS (this->decls_seen_masks.exception_seen_,         cursor << 14);
  ACE_SET_BITS (this->decls_seen_masks.operation_seen_,         cursor << 15);
  ACE_SET_BITS (this->decls_seen_masks.non_local_op_seen_,      cursor << 16);
  ACE_SET_BITS (this->decls_seen_masks.typecode_seen_,          cursor << 17);
  ACE_SET_BITS (this->decls_seen_masks.any_seen_,               cursor << 18);
  ACE_SET_BITS (this->decls_seen_masks.parametermode_seen_,     cursor << 19);
  ACE_SET_BITS (this->decls_seen_masks.base_object_seen_,       cursor << 20);
  ACE_SET_BITS (this->decls_seen_masks.valuefactory_seen_,      cursor << 21);

  ACE_SET_BITS (this->decls_seen_masks.seq_seen_,               cursor << 22);
  ACE_SET_BITS (this->decls_seen_masks.iface_seq_seen_,         cursor << 23);
  ACE_SET_BITS (this->decls_seen_masks.vt_seq_seen_,            cursor << 24);
  ACE_SET_BITS (this->decls_seen_masks.array_seq_seen_,         cursor << 25);
  ACE_SET_BITS (this->decls_seen_masks.pseudo_seq_seen_,        cursor << 26);
  ACE_SET_BITS (this->decls_seen_masks.string_seq_seen_,        cursor << 27);
  ACE_SET_BITS (this->decls_seen_masks.wstring_seq_seen_,       cursor << 28);
  ACE_SET_BITS (this->decls_seen_masks.octet_seq_seen_,         cursor << 29);

  ACE_SET_BITS (this->decls_seen_masks.basic_arg_seen_,         cursor << 30);
  ACE_SET_BITS (this->decls_seen_masks.bd_string_arg_seen_,     cursor << 31);
  ACE_SET_BITS (this->decls_seen_masks.fixed_array_arg_seen_,   cursor << 32);
  ACE_SET_BITS (this->decls_seen_masks.fixed_size_arg_seen_,    cursor << 33);
  ACE_SET_BITS (this->decls_seen_masks.object_arg_seen_,        cursor << 34);
  ACE_SET_BITS (this->decls_seen_masks.special_basic_arg_seen_, cursor << 35);
  ACE_SET_BITS (this->decls_seen_masks.ub_string_arg_seen_,     cursor << 36);
  ACE_SET_BITS (this->decls_seen_masks.var_array_arg_seen_,     cursor << 37);
  ACE_SET_BITS (this->decls_seen_masks.var_size_arg_seen_,      cursor << 38);
}

IDL_GlobalData::~IDL_GlobalData (void)
{
}

// Get or set scopes stack
UTL_ScopeStack &
IDL_GlobalData::scopes (void)
{
  return this->pd_scopes;
}

// Get or set root of AST
AST_Root *
IDL_GlobalData::root (void)
{
  return this->pd_root;
}

void
IDL_GlobalData::set_root (AST_Root *r)
{
  this->pd_root = r;
}

// Get or set generator object
AST_Generator *
IDL_GlobalData::gen (void)
{
  return this->pd_gen;
}

void
IDL_GlobalData::set_gen (AST_Generator *g)
{
  this->pd_gen = g;
}

// Get or set error object
UTL_Error *
IDL_GlobalData::err (void)
{
  return this->pd_err;
}

void
IDL_GlobalData::set_err (UTL_Error *e)
{
  this->pd_err = e;
}

// Get or set error count
long
IDL_GlobalData::err_count (void)
{
  return this->pd_err_count;
}

void
IDL_GlobalData::set_err_count (long c)
{
  this->pd_err_count = c;
}

// Get or set line number
long
IDL_GlobalData::lineno (void)
{
  return this->pd_lineno;
}

void
IDL_GlobalData::set_lineno (long n)
{
  this->pd_lineno = n;
}

// Get or set file name being read now
UTL_String *
IDL_GlobalData::filename (void)
{
  return this->pd_filename;
}

void
IDL_GlobalData::set_filename (UTL_String *s)
{
  if (this->pd_filename != 0)
    {
      this->pd_filename->destroy ();
      delete this->pd_filename;
      this->pd_filename = 0;
    }

  this->pd_filename = s;
}

// Get or set main file name
UTL_String *
IDL_GlobalData::main_filename (void)
{
  return this->pd_main_filename;
}

void
IDL_GlobalData::set_main_filename (UTL_String *n)
{
  if (this->pd_main_filename != 0)
    {
      this->pd_main_filename->destroy ();
      delete this->pd_main_filename;
      this->pd_main_filename = 0;
    }

  this->pd_main_filename = n;
}

// Get or set real file name
UTL_String *
IDL_GlobalData::real_filename (void)
{
  return this->pd_real_filename;
}

void
IDL_GlobalData::set_real_filename (UTL_String *n)
{
  if (this->pd_real_filename != 0)
    {
      this->pd_real_filename->destroy ();
      delete this->pd_real_filename;
      this->pd_real_filename = 0;
    }

  this->pd_real_filename = n;
}

// Get or set indicator whether import is on
idl_bool
IDL_GlobalData::imported (void)
{
  return this->pd_in_main_file ? I_FALSE : pd_import;
}

idl_bool
IDL_GlobalData::import (void)
{
  return this->pd_import;
}

void
IDL_GlobalData::set_import (idl_bool is_in)
{
  this->pd_import = is_in;
}

// Get or set indicator whether we're reading the main file now
idl_bool
IDL_GlobalData::in_main_file (void)
{
  return this->pd_in_main_file;
}

void

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?