brseinfo.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 998 行 · 第 1/3 页
C
998 行
/****************************************************************************
*
* 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: Generate browsing information.
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <malloc.h>
#include "ftnstd.h"
#include "errcod.h"
#include "global.h"
#include "cpopt.h"
#include "progsw.h"
#include "brseinfo.h"
#include "sdfile.h"
#include "dw.h"
#include "astype.h"
#include "browscli.h"
#include "fmemmgr.h"
#include "types.h"
#include "ferror.h"
// linked list storage facility
typedef struct sym_list {
struct sym_list *link; // link
sym_id id; // symbol entry id
dw_handle dbh; // dwarf handle
struct sym_list *children; // children of this entry
} sym_list;
typedef dw_handle (*func)( sym_id ste_ptr, dw_handle handle );
extern int AllocName(int);
extern int MakeName(char *,char *,char *);
extern char *SDFName(char *fn);
static void BIAdd2List(sym_list **,sym_id,dw_handle);
static void BIWalkList(sym_list **,func,int);
static dw_handle BIGetAnyType(sym_id);
static dw_handle BIGetType(sym_id);
static dw_handle BIGetSPType(sym_id);
static dw_handle BIGetArrayType(sym_id);
static dw_handle BIGetStructType(sym_id,dw_handle);
static dw_handle BILateRefSym(sym_id,dw_handle);
static dw_handle BIStartStructType(sym_id,int);
static dw_handle BIGetUnionType(sym_id);
static void BIOutSP(sym_id);
static void BISolidifyFunction(sym_id,dw_handle);
static void BIOutDummies(entry_pt *);
static void BIOutDeclareSP(sym_id,long);
static void BIOutSF(sym_id);
static void BIOutSPDumInfo(sym_id);
static void BIOutVar(sym_id);
static void BIOutConst(sym_id);
static void BIDumpAllEntryPoints(entry_pt *,int);
static dw_handle BIGetHandle(sym_id);
static void BISetHandle(sym_id,dw_handle);
static char * BIMKFullPath(const char *);
static void BIInitBaseTypes(void);
extern char BrowseExtn[];
static dw_client cBIId;
static dw_loc_handle justJunk;
static char fullPathName[ PATH_MAX + 1 ];
static dw_handle subProgTyHandle;
static unsigned_32 currState = 0;
static sym_list *fixStructs = NULL;
static sym_list *fixSubParms = NULL;
static dw_handle baseTypes[LAST_BASE_TYPE + 1];
#define BI_STATE_IN_COMMON_BLOCK 0x00000001
#define BI_STATE_IN_STMT_FUNC 0x00000002
#define BI_STATE_RESOLVED 0x00000004
#define BI_STATE_IN_SCOPE 0x00000008
#define BI_NAMELIST_UNDEFINED 0x00000010
static bool BrInitialized;
#if ( _CPU == 8086 )
#define ARCHITECTURE sizeof( short )
#else
#define ARCHITECTURE sizeof( long )
#endif
#define _GenerateBrInfo() ((Options & OPT_BROWSE) && \
(BrInitialized) && \
(ProgSw & PS_DONT_GENERATE))
#define _isFundamentalType( typ ) \
(((int)typ >= FIRST_BASE_TYPE) && ((int)typ <= LAST_BASE_TYPE))
void BIInit( void ) {
//================
dw_init_info init_dwl;
dw_cu_info cu;
BrInitialized = TRUE;
if( !_GenerateBrInfo() ) return;
init_dwl.language = DWLANG_FORTRAN;
init_dwl.compiler_options = DW_CM_BROWSER | DW_CM_UPPER;
init_dwl.producer_name = "WATCOM FORTRAN 77";
if ( !setjmp( init_dwl.exception_handler ) ) {
CLIInit( &(init_dwl.funcs), MEM_SECTION );
cBIId = DWInit( &init_dwl );
justJunk = DWLocFini( cBIId, DWLocInit( cBIId ) );
cu.source_filename=BIMKFullPath( CurrFile->name );
cu.directory=".";
cu.flags = TRUE;
cu.offset_size = ARCHITECTURE;
cu.segment_size = 0;
cu.model = DW_MODEL_NONE;
cu.inc_list = NULL;
cu.inc_list_len = 0;
cu.dbg_pch = NULL;
DWBeginCompileUnit( cBIId, &cu );
BISetSrcFile();
} else {
BrInitialized = FALSE;
Error( SM_BROWSE_ERROR );
}
BIInitBaseTypes();
}
void BIEnd( void ) {
//===============
char fn[MAX_FILE+1];
if( !_GenerateBrInfo() ) return;
MakeName( SDFName( SrcName ), BrowseExtn, fn );
DWEndCompileUnit( cBIId );
DWLocTrash( cBIId, justJunk );
DWFini( cBIId );
CLIDump( fn );
CLIClear();
}
void BIStartSubProg( void ) {
//========================
}
void BIStartSubroutine( void ) {
//===========================
if( _GenerateBrInfo() ) {
if ( ( SubProgId->ns.flags & SY_SUBPROG_TYPE ) != SY_BLOCK_DATA ){
BIOutSrcLine();
BIOutSP( SubProgId );
}
currState |= BI_STATE_IN_SCOPE;
}
}
void BIFiniStartOfSubroutine( void ) {
//=================================
if( _GenerateBrInfo() && (currState & BI_STATE_IN_SCOPE) ) {
if ( ( SubProgId->ns.flags & SY_SUBPROG_TYPE ) == SY_FUNCTION ){
BISolidifyFunction( SubProgId, subProgTyHandle );
}
if ( ( SubProgId->ns.flags & SY_SUBPROG_TYPE ) != SY_BLOCK_DATA ){
if ( currState & BI_STATE_IN_SCOPE ) {
BIOutDummies( Entries );
}
}
BIWalkList( &fixSubParms, &BILateRefSym, TRUE );
currState |= BI_STATE_RESOLVED;
}
}
void BIEndSubProg( void ) {
//======================
if( _GenerateBrInfo() ) {
if ( ( SubProgId->ns.flags & SY_SUBPROG_TYPE ) == SY_BLOCK_DATA ) {
BIEndBlockData();
} else {
BIDumpAllEntryPoints( Entries, 0 );
DWEndSubroutine ( cBIId );
}
currState &= ~( BI_STATE_IN_SCOPE | BI_STATE_RESOLVED );
}
}
void BIResolveUndefTypes( void ) {
//==========================
if( _GenerateBrInfo() ) {
BIWalkList( &fixStructs, &BIGetStructType, TRUE );
}
}
void BIEndSF( sym_id ste_ptr ) {
//=================================
if( _GenerateBrInfo() ) {
DWEndSubroutine ( cBIId );
BIRefSymbol( BIGetHandle( ste_ptr ) );
currState &= ~BI_STATE_IN_STMT_FUNC;
}
}
void BIStartRBorEP( sym_id ste_ptr ) {
//=======================================
if( _GenerateBrInfo() ) {
BIOutSP( ste_ptr );
if ( ste_ptr->ns.flags & SY_SENTRY ) {
BIOutDummies( ArgList );
}
}
}
void BIEndRBorEP( void ) {
//===========================
if( _GenerateBrInfo() ) {
DWEndSubroutine ( cBIId );
}
}
void BIStartComBlock( sym_id ste_ptr ) {
//=========================================
char name[MAX_SYMLEN+1];
if( _GenerateBrInfo() ) {
memset( name, 0, MAX_SYMLEN+1 );
DWDeclPos( cBIId, CurrFile->rec, 0 );
currState |= BI_STATE_IN_COMMON_BLOCK;
DWIncludeCommonBlock( cBIId, DWBeginCommonBlock( cBIId, justJunk, 0,
strncpy( name, ste_ptr->ns.name, ste_ptr->ns.name_len ), 0 ) );
}
}
void BIEndComBlock( void ) {
//=============================
if( _GenerateBrInfo() ) {
currState &= ~BI_STATE_IN_COMMON_BLOCK;
DWEndCommonBlock ( cBIId );
}
}
void BIStartBlockData( sym_id ste_ptr ) {
//==========================================
char name[MAX_SYMLEN+1];
if( _GenerateBrInfo() ) {
memset( name, 0, MAX_SYMLEN+1 );
DWDeclPos( cBIId, CurrFile->rec, 0 );
DWBeginLexicalBlock( cBIId, 0,
strncpy( name, ste_ptr->ns.name, ste_ptr->ns.name_len ) );
}
}
void BIEndBlockData( void ) {
//==============================
if( _GenerateBrInfo() ) {
currState &= ~BI_STATE_IN_COMMON_BLOCK;
DWEndLexicalBlock ( cBIId );
}
}
void BIOutComSymbol( sym_id ste_ptr ) {
//========================================
if( _GenerateBrInfo() ) {
BIOutVar( ste_ptr );
}
}
void BIOutNameList( sym_id ste_ptr ) {
//=======================================
char name[33];
grp_entry *ge;
dw_handle var;
if( _GenerateBrInfo() ) {
if( !( ste_ptr->nl.dbh ) ) {
strncpy( name, ste_ptr->nl.name, ste_ptr->nl.name_len );
name[ste_ptr->nl.name_len] = 0;
BIOutSrcLine();
ge = ste_ptr->nl.group_list;
while( ge != NULL ) {
var = BIGetHandle( ge->sym );
if( !var ) {
BIOutSymbol( ge->sym );
}
ge = ge->link;
}
ste_ptr->nl.dbh = DWNameListBegin( cBIId, name );
ge = ste_ptr->nl.group_list;
while( ge != NULL ) {
DWNameListItem( cBIId, BIGetHandle( ge->sym ) );
ge = ge->link;
}
DWEndNameList( cBIId );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?