brmwrite.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 908 行 · 第 1/3 页
C
908 行
/****************************************************************************
*
* 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 <stdio.h>
#include <errno.h>
#ifdef OPT_BR
#include "preproc.h"
#include "memmgr.h"
#include "errdefns.h"
#include "srcfile.h"
#include "iosupp.h"
#include "initdefs.h"
#include "brinfoim.h"
#include "ring.h"
#include "stats.h"
#include "template.h"
#include "icodes.h"
#include "icopmask.h"
#include "brmtypes.h"
#include "b_write.h"
#ifndef NDEBUG
#include "dbg.h"
#include "pragdefn.h"
#endif
//extern CLASSINFO *ClassInfoGetIndex( CLASSINFO *c );
static BRI_HANDLE bri_handle;
static BRI_StringID addString // ADD A STRING
( char const * str ) // - the string
{
return BRIAddString( bri_handle, (BRI_StringID)str, str );
}
static BRI_StringID addStringLower // ADD A STRING, IN LOWER CASE
( BRI_StringID id // - id to be used
, char const * str ) // - the string
{
char buffer[ 256 ]; // - buffer big enough for most file names
char * alloced = NULL; // - allocated buffer
char * lowername = buffer; // - buffer used
BRI_StringID string_id; // - return: string id
int buf_size; // - buffer size required
buf_size = strlen(str) + 1;
buf_size *= sizeof(char);
if( buf_size > sizeof( buffer ) ) {
alloced = (char*)CMemAlloc( buf_size );
lowername = alloced;
}
lowername = memcpy( lowername, str, buf_size );
lowername = strlwr( lowername );
string_id = BRIAddString( bri_handle, id, lowername );
if( NULL != alloced ) {
CMemFree( alloced );
}
return string_id;
}
static BRI_StringID addStringFile // ADD A STRING, FOR A FILE
( SRCFILE file ) // - id of file
{
return addStringLower( (BRI_StringID)file, SrcFileFullName( file ) );
}
#if 0
static int trivialTypeDef
( SYMBOL sym )
{
int result = FALSE;
if( sym->id == SC_TYPEDEF ) {
if( sym->sym_type->of->id == TYP_CLASS ) {
if( sym->sym_type->of->u.c.info->name == sym->name->name ){
result = TRUE;
}
}
}
return result;
}
#endif
#if 0
static SYMBOL findClassSymbol
( TYPE cltype )
{
SYMBOL result = NULL;
SCOPE clscope, parent;
SYMBOL sym, last;
if( cltype->id != TYP_CLASS ){
return NULL;
}
clscope = cltype->u.c.scope;
if( clscope != NULL ){
parent = clscope->enclosing;
if( parent != NULL ){
sym = ScopeOrderedFirst( parent );
if( sym != NULL ){
last = ScopeOrderedLast( parent );
for( ; sym != NULL ; sym = ScopeOrderedNext( last, sym ) ) {
if( sym->name->name == cltype->u.c.info->name &&
(sym->id == SC_CLASS_TEMPLATE ||
sym->id == SC_TYPEDEF) ){
result = sym;
break;
}
}
}
}
}
return result;
}
#endif
static BRI_SymbolID symbolIDForClass( CLASSINFO *c )
{
return ~((BRI_SymbolID) ClassInfoGetIndex( c ));
}
// NOTE: the following static data is initialized and de-initialized
// by brinfWriteFileContents().
static uint_32 * type_ops=NULL;
static int type_ops_size=0;
static BRI_TypeID writeType // DUMP A TYPE
( TYPE dtype ) // - type to dump
{
BRI_TypeID result = (BRI_TypeID) TypeGetIndex( dtype );
BRI_TypeID sub_type;
BRI_TypeID host_type;
int num_ops;
int i;
if( dtype == NULL ) {
return (BRI_TypeID) 0;
}
if( ! BRITypeAlreadySeen( bri_handle, result ) ) {
switch( dtype->id ) {
case TYP_BOOL:
case TYP_CHAR:
case TYP_SCHAR:
case TYP_UCHAR:
case TYP_WCHAR:
case TYP_SSHORT:
case TYP_USHORT:
case TYP_SINT:
case TYP_UINT:
case TYP_SLONG:
case TYP_ULONG:
case TYP_SLONG64:
case TYP_ULONG64:
case TYP_FLOAT:
case TYP_DOUBLE:
case TYP_LONG_DOUBLE:
case TYP_VOID:
case TYP_DOT_DOT_DOT:
case TYP_GENERIC:
BRIAddType( bri_handle
, result
, BRI_TC_BaseType
, 1
, (uint_32) dtype->id );
break;
case TYP_ENUM:
BRIAddType( bri_handle
, result
, BRI_TC_Enum
, 2
, (uint_32) dtype->u.t.sym->name->name
, (uint_32) dtype->u.t.sym );
break;
case TYP_POINTER:
sub_type = writeType( dtype->of );
BRIAddType( bri_handle
, result
, (BRI_TypeCode) dtype->id
, 1
, sub_type );
break;
case TYP_TYPEDEF:
sub_type = writeType( dtype->of );
BRIAddType( bri_handle
, result
, (BRI_TypeCode) dtype->id
, 1
, sub_type );
break;
case TYP_CLASS:
{
BRI_TypeCode code = BRI_TC_Class;
if( dtype->flag & TF1_UNION ){
code = BRI_TC_Union;
} else if( dtype->flag & TF1_STRUCT ){
code = BRI_TC_Struct;
}
BRIAddType( bri_handle
, result
, code
, 2
, addString( dtype->u.c.info->name )
, symbolIDForClass( dtype->u.c.info ) );
}
break;
case TYP_BITFIELD:
BRIAddType( bri_handle
, result
, BRI_TC_BitField
, 1
, dtype->u.b.field_width );
break;
case TYP_FUNCTION:
num_ops = 1 + dtype->u.f.args->num_args;
if( num_ops > type_ops_size ){
CMemFree( type_ops );
type_ops_size = num_ops;
type_ops = CMemAlloc( type_ops_size * sizeof(uint_32) );
}
type_ops[0] = writeType( dtype->of );
for( i=1; i<num_ops; i++ ) {
type_ops[i] = writeType(dtype->u.f.args->type_list[i-1]);
}
BRIVAddType( bri_handle
, result
, BRI_TC_Function
, num_ops
, type_ops );
break;
case TYP_ARRAY:
sub_type = writeType( dtype->of );
BRIAddType( bri_handle
, result
, BRI_TC_Array
, 2
, dtype->u.a.array_size
, sub_type );
break;
case TYP_MODIFIER:
sub_type = writeType( dtype->of );
BRIAddType( bri_handle
, result
, BRI_TC_Modifier
, 2
, dtype->flag
, sub_type );
break;
case TYP_MEMBER_POINTER:
sub_type = writeType( dtype->of );
host_type = writeType( dtype->u.mp.host );
BRIAddType( bri_handle
, result
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?