wbrowse.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 2,128 行 · 第 1/5 页
CPP
2,128 行
{
static const int result = sizeof(uint_8)
+ sizeof(uint_16);
int_8 dcol;
int_16 dline;
// Read the data from the browse file.
infile.Read( &dcol, sizeof(int_8), 1 );
infile.Read( &dline, sizeof(int_16), 1 );
// Update the current line and column.
_usages->Delta( dcol, dline );
return result;
}
int Browser::ReadUsage(BrmFile &infile)
/************************************/
{
static const int result = BRI_SIZE_REFERENCETYPE
+ sizeof(int_8)
+ sizeof(int_16)
+ sizeof(BRI_SymbolID);
UsageRec * usageRec;
int_8 dcol;
int_16 dline;
uint_32 newId;
if( !_scopes->Ignore() && !_guards->Ignore() ){
usageRec = new UsageRec;
// Read the data from the disk.
usageRec->type = (BRI_ReferenceType) 0;
infile.Read( &usageRec->type, BRI_SIZE_REFERENCETYPE, 1 );
infile.Read( &dcol, sizeof(int_8), 1 );
infile.Read( &dline, sizeof(int_16), 1 );
infile.Read( &usageRec->targetID, sizeof(BRI_SymbolID), 1 );
// Record the current scope.
usageRec->enclosing = indexOf( _scopes->Current() );
// Add the reference.
_usages->Delta( dcol, dline );
_usages->Insert( usageRec );
// If the target of this reference has already been processed,
// set the target id to the correct value. Otherwise, make
// a note and get back to it later.
if( usageRec->type == BRI_RT_TypeOf ){
newId = _typeIndex->NewId( usageRec->typeID );
} else {
newId = _declIndex->NewId( usageRec->targetID );
}
if( newId != 0x0 ){
usageRec->typeID = (BRI_TypeID) newId;
} else {
_usageReIndex->Append( usageRec );
}
} else {
// Read the data from the browse file.
infile.Skip( BRI_SIZE_REFERENCETYPE );
infile.Read( &dcol, sizeof(int_8), 1 );
infile.Read( &dline, sizeof(int_16), 1 );
infile.Skip( sizeof(BRI_SymbolID) );
// Update the current line and column.
_usages->Delta( dcol, dline );
}
return result;
}
int Browser::ReadString(BrmFile &infile)
/*************************************/
{
static const int result = sizeof(BRI_StringID)
+ sizeof(uint_32);
uint_32 stringLen;
BRI_StringID oldStringID;
BRI_StringID newStringID;
char *buffer;
// Read the data from the browse file.
infile.Read( &oldStringID, sizeof(BRI_StringID), 1 );
infile.Read( &stringLen, sizeof(uint_32), 1 );
if( _bufLen < stringLen ){
delete[] _buffer;
_buffer = new uint_8[ stringLen ];
_bufLen = stringLen;
}
buffer = (char *) _buffer;
infile.Read( buffer, 1, stringLen );
// Add the string to the string table.
newStringID = _strings->Insert( buffer );
_stringIndex->ChangeTo( oldStringID, newStringID );
return result + stringLen;
}
int Browser::ReadType(BrmFile &infile)
/***********************************/
{
static const int result = sizeof(BRI_TypeID)
+ BRI_SIZE_TYPECODE
+ sizeof(uint_32);
TypeRec * typeRec = new TypeRec;
TypeRec * actualType;
uint_32 numOps;
uint_32 * ops;
int i;
int mustReIndex = 0;
// Read the data from the browse file.
infile.Read( &typeRec->index, sizeof(BRI_TypeID), 1 );
typeRec->typeCode = (BRI_TypeCode) 0;
infile.Read( &typeRec->typeCode, BRI_SIZE_TYPECODE, 1 );
infile.Read( &numOps, sizeof(uint_32), 1 );
WAssert( numOps > 0 );
if( numOps * sizeof(uint_32) > _bufLen ){
delete[] _buffer;
_buffer = new uint_8[ numOps * sizeof( uint_32 ) ];
_bufLen = numOps * sizeof( uint_32 );
}
ops = (uint_32 *) _buffer;
infile.Read( ops, sizeof(uint_32), numOps );
// Oy! Does C++ have a type system or what?
switch( typeRec->typeCode ){
case BRI_TC_None:
break;
case BRI_TC_BaseType:
typeRec->bt.baseType = (BRI_BaseTypes) ops[0];
break;
case BRI_TC_Modifier:
typeRec->fp.flags = ops[0];
typeRec->fp.parent = _typeIndex->NewId( ops[1] );
break;
case BRI_TC_Pointer:
case BRI_TC_Reference:
case BRI_TC_TypeDef:
typeRec->p.parent = _typeIndex->NewId( ops[0] );
break;
case BRI_TC_PtrToMember:
typeRec->cm.host = _typeIndex->NewId( ops[0] );
typeRec->cm.member = _typeIndex->NewId( ops[1] );
break;
case BRI_TC_Array:
typeRec->se.size = ops[0];
typeRec->se.element = _typeIndex->NewId( ops[1] );
break;
case BRI_TC_Function:
typeRec->ra.args = new BRI_TypeID[numOps];
typeRec->ra.numArgs = numOps;
for( i=0; i<numOps; i++ ){
typeRec->ra.args[i] = _typeIndex->NewId( ops[i] );
}
break;
case BRI_TC_Class:
case BRI_TC_Struct:
case BRI_TC_Union:
case BRI_TC_Enum:
if( _scopes->Ignore() ){
delete typeRec;
return result + numOps*sizeof( uint_32 );
}
typeRec->ns.nameID = _stringIndex->NewId( ops[0] );
typeRec->ns.symbolID = (BRI_SymbolID) ops[1];
mustReIndex = 1;
break;
case BRI_TC_BitField:
typeRec->w.width = ops[0];
break;
}
// Add the type to the type list.
actualType = _types->AddType( typeRec );
if( actualType == typeRec ){
if( mustReIndex ){
_typeReIndex->Append( typeRec );
}
} else {
if( mustReIndex && actualType->ns.symbolID == BRI_NULL_ID ){
actualType->ns.symbolID = typeRec->ns.symbolID;
_typeReIndex->Append( actualType );
}
delete typeRec;
}
return result + numOps * sizeof(uint_32);
}
int Browser::ReadGuard(BrmFile &infile)
/************************************/
{
static const int result = BRI_SIZE_GUARDTYPES
+ sizeof(BRI_StringID)
+ sizeof( uint_32 )
+ sizeof( uint_32 );
BRI_GuardTypes type;
BRI_StringID stringID;
BRI_SymbolID symID;
uint_32 numParams;
uint_32 length;
uint_8 *buffer;
UsageRec *usage;
DefnRec *defn;
DependValRec *guard;
// Read the data from the browse file.
type = (BRI_GuardTypes) 0;
infile.Read( &type, BRI_SIZE_GUARDTYPES, 1 );
infile.Read( &stringID, sizeof(BRI_StringID), 1 );
infile.Read( &numParams, sizeof(uint_32), 1 );
infile.Read( &length, sizeof(uint_32), 1 );
if( length > 0 ){
if( length > _bufLen ){
delete[] _buffer;
_buffer = new uint_8[ length ];
_bufLen = length;
}
buffer = _buffer;
infile.Read( buffer, sizeof(uint_8), length );
} else {
buffer = NULL;
}
stringID = _stringIndex->NewId( stringID );
switch( type ){
case BRI_GT_Value:
if( _state == GUARD_SEARCH ){
guard = new DependValRec;
guard->macroNameID = stringID;
guard->numParams = numParams;
guard->length = length;
if( length > 0 ){
guard->defn = new uint_8[ length ];
memcpy( guard->defn, buffer, length );
} else {
guard->defn = NULL;
}
_guards->AddDepMacValue( guard );
}
break;
case BRI_GT_Defined:
if( _state == GUARD_SEARCH ){
_guards->AddDepDefined( stringID );
}
break;
case BRI_GT_NotDefined:
if( _state == GUARD_SEARCH ){
_guards->AddDepUndefed( stringID );
}
break;
case BRI_GT_Declaration:
if( !_macros->HaveSeen( stringID ) ){
symID = _declIndex->StealId();
_macros->AddMacroDecl( stringID, symID );
_macrosToSyms->ChangeTo( stringID, symID );
} else {
symID = _macrosToSyms->NewId( stringID );
}
defn = new DefnRec;
defn->index = symID;
defn->column = _usages->GetColumn();
defn->line = _usages->GetLine();
defn->filenameID = _usages->GetFileName();
_defns->AddDefinition( defn );
break;
case BRI_GT_RefValue:
case BRI_GT_RefUndef:
usage = new UsageRec;
usage->type = BRI_RT_Macro;
usage->targetID = _macrosToSyms->NewId( stringID );
usage->enclosing = indexOf( _scopes->Head() );
_usages->Insert( usage );
break;
}
return result + length;
}
int Browser::ReadDefinition(BrmFile &infile)
/*****************************************/
{
static const int result = sizeof(uint_32)
+ sizeof(uint_32)
+ sizeof(BRI_StringID)
+ sizeof(BRI_SymbolID);
DefnRec * defnRec;
uint_32 newId;
if( !_scopes->Ignore() ){
defnRec = new DefnRec;
// Read the data from the browse file.
infile.Read( &defnRec->column, sizeof(uint_32), 1 );
infile.Read( &defnRec->line, sizeof(uint_32), 1 );
infile.Read( &defnRec->filenameID, sizeof(BRI_StringID), 1 );
infile.Read( &defnRec->index, sizeof(BRI_SymbolID), 1 );
// Re-index vital information now.
defnRec->filenameID = _stringIndex->NewId( defnRec->filenameID );
// If the symbol being defined has already been processed, set
// the index number appropriately. Otherwise, make a note and do
// it later.
newId = _declIndex->NewId( defnRec->index );
if( newId != 0x0 ){
defnRec->index = newId;
_defns->AddDefinition( defnRec );
} else {
_defnReIndex->Append( defnRec );
_defns->AddTempDefinition( defnRec );
}
} else {
infile.Skip( result );
}
return result;
}
int Browser::ReadPCHInclude(BrmFile &infile)
/*****************************************/
{
int result = sizeof(BRI_StringID);
BRI_StringID fileNameID;
WBool seenBefore = FALSE;
if( !_scopes->Ignore() && !_guards->Ignore() ){
infile.Read( &fileNameID, sizeof(BRI_StringID), 1 );
fileNameID = _stringIndex->NewId( fileNameID );
WAssert( fileNameID != BRI_NULL_ID );
seenBefore = _declIndex->HaveSeenPCH( fileNameID );
if( seenBefore ){
_declIndex->PCHUse( fileNameID );
_typeIndex->PCHUse( fileNameID );
_stringIndex->PCHUse( fileNameID );
_scopeIndex->PCHUse( fileNameID );
} else {
BrmFilePch pchFile;
char const *fileName;
fileName = _strings->Lookup( fileNameID );
WAssert( fileName != NULL );
_declIndex->PCHRecord( fileNameID );
_typeIndex->PCHRecord( fileNameID );
_stringIndex->PCHRecord( fileNameID );
_scopeIndex->PCHRecord( fileNameID );
pchFile.Open( fileName );
if( !pchFile ){
MERGE_ERROR( FILE_ERR, fileName, 0 );
result = -1;
} else {
if( !ProcessFile( pchFile ) ){
result = -1;
}
pchFile.Close();
}
_declIndex->PCHStopRecording();
_typeIndex->PCHStopRecording();
_stringIndex->PCHStopRecording();
_scopeIndex->PCHStopRecording();
}
} else {
infile.Skip( result );
}
return result;
}
WBool Browser::ProcessFile(BrmFile &infile)
/****************************************/
{
BRI_Header briHeader;
int fileLen;
int delta;
int filePos;
int recordFlag;
// Get the file length, for error checking.
fileLen = infile.Size();
// Read the browse file header.
infile.Read( &briHeader, sizeof( briHeader ), 1 );
if( briHeader.magic != BRI_MAGIC || briHeader.file_len != fileLen ){
MERGE_ERROR( BAD_CHECKSUM, 0, 0 );
return FALSE;
}
// Read the records from the browse file.
filePos = sizeof( briHeader );
while( filePos < fileLen ){
recordFlag = infile.GetChar();
if( recordFlag == EOF ){
MERGE_ERROR( EOF_ERR, fileLen, 0 );
CurrBrowser = NULL;
return FALSE;
}
filePos ++;
if( _state == GUARD_SEARCH ){
if( recordFlag != BRI_Rec_String &&
recordFlag != BRI_Rec_Guard ){
_guards->IncludeFile();
_state = NORMAL;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?