utl_err.cpp

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

CPP
1,310
字号
// utl_err.cpp,v 1.29 2003/11/10 20:29:26 dhinton 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.

 */

// utl_err.cc - Implementation of error reporting object for IDL
//              compiler program

#include "utl_err.h"
#include "utl_identifier.h"
#include "utl_string.h"
#include "global_extern.h"
#include "nr_extern.h"
#include "ast_interface.h"
#include "ast_enum.h"
#include "ast_union.h"
#include "ast_union_label.h"
#include "idl_defines.h"

// FUZZ: disable check_for_streams_include
#include "ace/streams.h"

ACE_RCSID (util, 
           utl_err, 
           "utl_err.cpp,v 1.29 2003/11/10 20:29:26 dhinton Exp")

// Convert an error code into a const char *
static const char *
error_string (UTL_Error::ErrorCode c)
{
  switch (c)
  {
    case UTL_Error::EIDL_OK:
      return "all is fine ";
    case UTL_Error::EIDL_SYNTAX_ERROR:
      return "";
    case UTL_Error::EIDL_REDEF:
      return "illegal redefinition ";
    case UTL_Error::EIDL_DEF_USE:
      return "redefinition after use, ";
    case UTL_Error::EIDL_MULTIPLE_BRANCH:
      return "union with duplicate branch label ";
    case UTL_Error::EIDL_COERCION_FAILURE:
      return "coercion failure ";
    case UTL_Error::EIDL_SCOPE_CONFLICT:
      return "definition scope is different than fwd declare scope, ";
    case UTL_Error::EIDL_ONEWAY_CONFLICT:
      return "oneway operation with OUT or INOUT parameters, ";
    case UTL_Error::EIDL_PREFIX_CONFLICT:
      return "prefix at declaration differs from prefix at definition or use, ";
    case UTL_Error::EIDL_ILLEGAL_VERSION:
      return "illegal version number, ";
    case UTL_Error::EIDL_VERSION_RESET:
      return "version already set by #pragma version or #pragma id, ";
    case UTL_Error::EIDL_ID_RESET:
      return "cannot reset id to a different string, ";
    case UTL_Error::EIDL_TYPEID_RESET:
      return "repo id already set by previous call to 'typeid', ";
    case UTL_Error::EIDL_INVALID_TYPEID:
      return "'typeid' may not be applied to this type, ";
    case UTL_Error::EIDL_INVALID_TYPEPREFIX:
      return "'typeprefix' may not be applied to this type, ";
    case UTL_Error::EIDL_DISC_TYPE:
      return "union with illegal discriminator type, ";
    case UTL_Error::EIDL_LABEL_TYPE:
      return "label type incompatible with union discriminator type, ";
    case UTL_Error::EIDL_ILLEGAL_ADD:
      return "forward declared type may be used only as a sequence element, ";
    case UTL_Error::EIDL_ILLEGAL_USE:
      return "illegal type used in expression, ";
    case UTL_Error::EIDL_ILLEGAL_RAISES:
      return "error in or illegal use of raises(..) clause, ";
    case UTL_Error::EIDL_ILLEGAL_CONTEXT:
      return "error in context(..) clause, ";
    case UTL_Error::EIDL_CANT_INHERIT:
      // More intelligible message printed by error routine.
      return "";
    case UTL_Error::EIDL_CANT_SUPPORT:
      // More intelligible message printed by error routine.
      return "";
    case UTL_Error::EIDL_LOOKUP_ERROR:
      return "error in lookup of symbol: ";
    case UTL_Error::EIDL_INHERIT_FWD_ERROR:
      // More intelligible message printed by error routine.
      return "";
    case UTL_Error::EIDL_SUPPORTS_FWD_ERROR:
      // More intelligible message printed by error routine.
      return "";
    case UTL_Error::EIDL_PRIMARY_KEY_ERROR:
      // More intelligible message printed by error routine.
      return "";
    case UTL_Error::EIDL_CONSTANT_EXPECTED:
      return "constant expected: ";
    case UTL_Error::EIDL_INTERFACE_EXPECTED:
      return "interface expected: ";
    case UTL_Error::EIDL_VALUETYPE_EXPECTED:
      return "value type expected: ";
    case UTL_Error::EIDL_CONCRETE_VT_EXPECTED:
      return "concrete value type expected: ";
    case UTL_Error::EIDL_ABSTRACT_EXPECTED:
      return "abstract type expected: ";
    case UTL_Error::EIDL_EVENTTYPE_EXPECTED:
      return "event type expected: ";
    case UTL_Error::EIDL_EVAL_ERROR:
      return "expression evaluation error: ";
    case UTL_Error::EIDL_INCOMPATIBLE_TYPE:
      return "incompatible types in constant assignment: ";
    case UTL_Error::EIDL_NAME_CASE_ERROR:
      return "identifier spellings differ only in case: ";
    case UTL_Error::EIDL_NAME_CASE_WARNING:
      return "Warning - identifier spellings differ only in case: ";
    case UTL_Error::EIDL_KEYWORD_ERROR:
      return "spelling differs from IDL keyword only in case: ";
    case UTL_Error::EIDL_KEYWORD_WARNING:
      return "Warning - spelling differs from IDL keyword only in case: ";
    case UTL_Error::EIDL_ENUM_VAL_EXPECTED:
      return "enumerator expected: ";
    case UTL_Error::EIDL_ENUM_VAL_NOT_FOUND:
      return "enumerator by this name not defined: ";
    case UTL_Error::EIDL_AMBIGUOUS:
      return "ambiguous definition: ";
    case UTL_Error::EIDL_DECL_NOT_DEFINED:
      return "forward declared but never defined: ";
    case UTL_Error::EIDL_FWD_DECL_LOOKUP:
      /* More intelligible message printed by error routine */
      return "";
    case UTL_Error::EIDL_RECURSIVE_TYPE:
      return "illegal recursive use of type: ";
    case UTL_Error::EIDL_NONVOID_ONEWAY:
      return "non-void return type in oneway operation: ";
    case UTL_Error::EIDL_REDEF_SCOPE:
      return "redefinition inside defining scope: ";
    case UTL_Error::EIDL_NOT_A_TYPE:
      return "specified symbol is not a type: ";
    case UTL_Error::EIDL_UNDERSCORE:
      return "identifier has more than one leading underscore: ";
    case UTL_Error::EIDL_EMPTY_MODULE:
      return "module must contain at least one declaration: ";
    case UTL_Error::EIDL_BACK_END:
      return "back end: ";
  }

  return 0;
}

// Print out an error message header on cerr
static void
idl_error_header (UTL_Error::ErrorCode c,
                  long lineno,
                  UTL_String *s)
{
  ACE_ERROR ((LM_ERROR,
              "%s: \"%s\", line %d: %s",
              idl_global->prog_name (),
              idl_global->read_from_stdin () ? "standard input"
                                             : s->get_string (),
              lineno == -1 ? idl_global->lineno () : lineno,
              error_string (c)));
}

// Convert the type of an AST_Expression to a char *.
static const char *
exprtype_to_string (AST_Expression::ExprType t)
{
  switch (t) {
  case AST_Expression::EV_short:
    return "short";
  case AST_Expression::EV_ushort:
    return "unsigned short";
  case AST_Expression::EV_long:
    return "long";
  case AST_Expression::EV_ulong:
    return "unsigned long";
  case AST_Expression::EV_float:
    return "float";
  case AST_Expression::EV_double:
    return "double";
  case AST_Expression::EV_char:
    return "char";
  case AST_Expression::EV_octet:
    return "octet";
  case AST_Expression::EV_bool:
    return "boolean";
  case AST_Expression::EV_string:
    return "string";
  case AST_Expression::EV_enum:
    return "enum";
  case AST_Expression::EV_void:
    return "void";
  case AST_Expression::EV_none:
    return "none";
  case AST_Expression::EV_wchar:
    return "wchar";
  case AST_Expression::EV_longlong:
  case AST_Expression::EV_ulonglong:
  case AST_Expression::EV_longdouble:
  case AST_Expression::EV_wstring:
  case AST_Expression::EV_any:
  case AST_Expression::EV_object:
    return 0;
  }
  return 0;
}

// Convert a parse state into a possible error message
static const char *
parse_state_to_error_message (IDL_GlobalData::ParseState ps)
{
  switch (ps) 
  {
  case IDL_GlobalData::PS_NoState:
    return "Statement cannot be parsed";
  case IDL_GlobalData::PS_TypeDeclSeen:
    return "Malformed typedef declaration";
  case IDL_GlobalData::PS_TypeIdDeclSeen:
    return "Malformed type id declaration";
  case IDL_GlobalData::PS_TypePrefixDeclSeen:
    return "Malformed type prefix declaration";
  case IDL_GlobalData::PS_ConstDeclSeen:
    return "Malformed const declaration";
  case IDL_GlobalData::PS_ExceptDeclSeen:
    return "Malformed exception declaration";
  case IDL_GlobalData::PS_InterfaceDeclSeen:
    return "Malformed interface declaration";
  case IDL_GlobalData::PS_ValueTypeDeclSeen:
    return "Malformed value type declaration";
  case IDL_GlobalData::PS_ComponentDeclSeen:
    return "Malformed component declaration";
  case IDL_GlobalData::PS_HomeDeclSeen:
    return "Malformed home declaration";
  case IDL_GlobalData::PS_EventDeclSeen:
    return "Malformed event type declaration";
  case IDL_GlobalData::PS_ModuleDeclSeen:
    return "Malformed module declaration";
  case IDL_GlobalData::PS_AttrDeclSeen:
    return "Malformed attribute declaration";
  case IDL_GlobalData::PS_OpDeclSeen:
    return "Malformed operation declaration";
  case IDL_GlobalData::PS_ProvidesDeclSeen:
    return "Malformed provides declaration";
  case IDL_GlobalData::PS_UsesDeclSeen:
    return "Malformed uses declaration";
  case IDL_GlobalData::PS_EmitsDeclSeen:
    return "Malformed emits declaration";
  case IDL_GlobalData::PS_PublishesDeclSeen:
    return "Malformed publishes declaration";
  case IDL_GlobalData::PS_ConsumesDeclSeen:
    return "Malformed consumes declaration";
  case IDL_GlobalData::PS_FactoryDeclSeen:
    return "Malformed factory declaration";
  case IDL_GlobalData::PS_FinderDeclSeen:
    return "Malformed finder declaration";
  case IDL_GlobalData::PS_ModuleSeen:
    return "Missing module identifier following MODULE keyword";
  case IDL_GlobalData::PS_ModuleIDSeen:
    return "Missing '{' or illegal syntax following module identifier";
  case IDL_GlobalData::PS_ModuleSqSeen:
    return "Illegal syntax following module '{' opener";
  case IDL_GlobalData::PS_ModuleQsSeen:
    return "Illegal syntax following module '}' closer";
  case IDL_GlobalData::PS_ModuleBodySeen:
    return "Illegal syntax following module body statement(s)";
  case IDL_GlobalData::PS_InheritColonSeen:
    return "Illegal syntax following ':' starting inheritance list";
  case IDL_GlobalData::PS_InheritSpecSeen:
    return "Missing '{' or illegal syntax following inheritance spec";
  case IDL_GlobalData::PS_SupportSpecSeen:

⌨️ 快捷键说明

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