fmtsym.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 472 行 · 第 1/2 页
C
472 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include "plusplus.h"
#include "errdefns.h"
#include "ppops.h"
#include "vbuf.h"
#include "dbg.h"
#include "fmttype.h"
#include "template.h"
#include "fmtsym.h"
static char scopeError[] = "***SCOPE ERROR***";
static char scopeSep[] = "::";
static char dtorPrefix[] = "~";
static char functionDelim[] = "' in '";
static char constructorName[] = "constructor";
static char destructorName[] = "destructor";
static char operatorSuffix[] = "()";
static char operatorPrefix[] = "operator ";
static char operatorUnknown[] = "conversion operator";
static char nullSymbol[] = "***NULL SYMBOL POINTER***";
static char nullSymname[] = "<null name>";
static char templateParmStart[] = "<";
static char templateParmNext[] = ",";
static char templateParmStop[] = ">";
static char templateParmUnknown[] = "?";
static char *fmtSymCgop( CGOP number )
/************************************/
{
char *name; // - name
static char *opNames[] ={ // - opcode names (binary,unary)
#include "ppopssym.h"
};
if( number >= ( sizeof( opNames ) / sizeof( opNames[0] ) ) ) {
name = "***INVALID CGOP***";
} else if( strlen( opNames[ number ] ) == 0 ) {
name = "***INVALID CGOP LENGTH***";
} else {
name = opNames[ number ];
}
return( name );
}
static void fmtSymFunction( SYMBOL sym, VBUF *prefix, VBUF *suffix,
/*****************************************************************/
FMT_CONTROL control )
{
unsigned num_def;
TYPE fn_type;
num_def = 0;
for( ; sym->id == SC_DEFAULT; sym = sym->thread ) {
++num_def;
}
fn_type = sym->sym_type;
if( num_def != 0 && TypeHasEllipsisArg( fn_type ) ) {
/* '...' is an extra last argument in the type if it has defargs */
++num_def;
}
FormatFunctionType( fn_type, prefix, suffix, num_def, control );
}
static void fmtSymOpName( SYMBOL sym, VBUF *pvbuf )
/*************************************************/
{
VBUF prefix, suffix;
TYPE type;
VbufInit( pvbuf );
VStrNull( pvbuf );
type = FunctionDeclarationType( sym->sym_type );
if( type != NULL ) {
FormatFunctionType( type->of
, &prefix
, &suffix
, 0
, FormatTypeDefault | FF_TYPEDEF_STOP );
if( suffix.buf != NULL ) {
VStrConcStrRev( pvbuf, suffix.buf );
}
VStrTruncWhite( pvbuf );
if( prefix.buf != NULL ) {
VStrConcStrRev( pvbuf, prefix.buf );
}
VbufFree( &prefix );
VbufFree( &suffix );
}
}
static boolean fmtSymName( SYMBOL sym, char *name, VBUF *pvprefix,
/****************************************************************/
VBUF *pvbuf, FMT_CONTROL control )
// returns TRUE if sym is CTOR/DTOR so that the caller drop the return type
{
VBUF prefix, suffix, op_name;
CGOP oper;
boolean ctordtor = FALSE;
if( name == NULL ) {
name = nullSymname;
}
if( CppLookupName( name, &oper ) ) {
switch( oper ) {
case CO_CONVERT:
if( sym == NULL ) {
VStrConcStrRev( pvbuf, operatorSuffix );
VStrConcStrRev( pvbuf, operatorUnknown );
} else {
fmtSymOpName( sym, &op_name );
fmtSymFunction( sym
, &prefix
, &suffix
, (FormatTypeDefault & ~FF_USE_VOID)
| FF_DROP_RETURN );
if( suffix.buf != NULL ) {
VStrConcStrRev( pvbuf, suffix.buf );
}
VStrConcStr( pvbuf, op_name.buf );
VStrConcStrRev( pvbuf, operatorPrefix );
if( prefix.buf != NULL ) {
VStrConcStrRev( pvbuf, prefix.buf );
}
VbufFree( &op_name );
VbufFree( &prefix );
VbufFree( &suffix );
}
break;
case CO_CTOR:
if( sym == NULL ) {
VStrConcStrRev( pvbuf, constructorName );
} else {
ctordtor = TRUE;
name = SimpleTypeName( ScopeClass( SymScope( sym ) ) );
fmtSymFunction( sym, &prefix, &suffix, FormatTypeDefault );
if( suffix.buf != NULL ) {
VStrConcStrRev( pvbuf, suffix.buf );
}
if( name != NULL ) {
VStrConcStrRev( pvbuf, name );
}
if( prefix.buf != NULL ) {
VStrConcStrRev( pvprefix, prefix.buf );
}
VbufFree( &prefix );
VbufFree( &suffix );
}
break;
case CO_DTOR:
if( sym == NULL ) {
VStrConcStrRev( pvbuf, destructorName );
} else {
ctordtor = TRUE;
name = SimpleTypeName( ScopeClass( SymScope( sym ) ) );
fmtSymFunction( sym, &prefix, &suffix, FormatTypeDefault );
if( suffix.buf != NULL ) {
VStrConcStrRev( pvbuf, suffix.buf );
}
if( name != NULL ) {
VStrConcStrRev( pvbuf, name );
}
VStrConcStrRev( pvbuf, dtorPrefix );
if( prefix.buf != NULL ) {
VStrConcStrRev( pvprefix, prefix.buf );
}
VbufFree( &prefix );
VbufFree( &suffix );
}
break;
default:
if( sym == NULL ) {
VStrConcStrRev( pvbuf, fmtSymCgop( oper ) );
VStrConcStrRev( pvbuf, operatorPrefix );
} else {
fmtSymFunction( sym, &prefix, &suffix, FormatTypeDefault | control );
if( suffix.buf != NULL ) {
VStrConcStrRev( pvbuf, suffix.buf );
}
VStrConcStrRev( pvbuf, fmtSymCgop( oper ) );
VStrConcStrRev( pvbuf, operatorPrefix );
if( prefix.buf != NULL ) {
VStrConcStrRev( pvprefix, prefix.buf );
}
VbufFree( &prefix );
VbufFree( &suffix );
}
break;
}
} else {
if( sym == NULL ) {
VStrConcStrRev( pvbuf, name );
} else {
if( SymIsFunction( sym ) ) {
fmtSymFunction( sym, &prefix, &suffix, FormatTypeDefault | control );
} else if( !SymIsTypedef( sym ) ) {
FormatType( sym->sym_type, &prefix, &suffix );
} else {
VbufInit( &prefix );
VbufInit( &suffix );
}
if( suffix.buf != NULL ) {
VStrConcStrRev( pvbuf, suffix.buf );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?