macro.cpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 579 行 · 第 1/2 页

CPP
579
字号
            continue;
        }
        if( _temp->numValues != fileInfo->numValues ){
            continue;
        }
        // Compare the "defined" ids
        if( fileInfo->defined.numEntries != 0 &&
            memcmp( _temp->defined.strings, fileInfo->defined.strings,
                    fileInfo->defined.numEntries ) != 0 ){
            continue;
        }
        // Compare the "undefined" ids
        if( fileInfo->undefed.numEntries != 0 &&
            memcmp( _temp->undefed.strings, fileInfo->undefed.strings,
                    fileInfo->undefed.numEntries ) != 0 ){
            continue;
        }
        if( fileInfo->numValues == 0 ){
            result = FALSE;
            break;
        }
        // Compare the values
        value = _temp->values.First();
        result = FALSE;
        while( value != NULL ){
            other = fileInfo->values.Find( value->macroNameID );
            if( other == NULL ){
                result = TRUE;
                break;
            }
            if( value->numParams != other->numParams ||
                value->length != other->length ||
                ( value->length != 0 &&
                memcmp( value->defn, other->defn, value->length ) != 0 ) ){
                result = TRUE;
                break;
            }
            value = _temp->values.Next();
        }
    }
    if( result ){
        if( headInfo == NULL ){
            _fileInfo->Insert( _temp->filenameID, _temp );
        } else {
            _temp->next = headInfo->next;
            headInfo->next = _temp;
        }
        _count += 1;
    } else {
        delete _temp;
        _state = IGNORE;
        _ignoreDepth = 1;
    }
    _temp = NULL;
    return result;
}


void DependList::EndFile()
/************************/
{
    if( _state == IGNORE ){
        _ignoreDepth -= 1;
        if( _ignoreDepth == 0 ){
            _state = USE;
        }
    }
}


void DependList::StartTemplate()
/******************************/
{
    if( _state != IGNORE ){
        _templateDepth += 1;
    }
}


void DependList::EndTemplate()
/****************************/
{
    if( _state != IGNORE && _templateDepth > 0 ){
        _templateDepth -= 1;
    }
}


WBool DependList::SaveTo( CacheOutFile *cache )
/*******************************************/
{
    FileGuardInfo       *currFile;
    DependValRec        *currValue;
    int                 i;
    int                 limit;

    cache->StartComponent( "Guards" );
    cache->AddDword( _count );
    currFile = _fileInfo->First();
    while( currFile != NULL ){
        cache->AddDword( currFile->filenameID );
        limit = currFile->defined.numEntries;
        cache->AddDword( limit );
        for( i=0; i<limit; i++ ){
            cache->AddDword( currFile->defined.strings[i] );
        }
        limit = currFile->undefed.numEntries;
        cache->AddDword( limit );
        for( i=0; i<limit; i++ ){
            cache->AddDword( currFile->undefed.strings[i] );
        }
        limit = currFile->numValues;
        cache->AddDword( limit );
        currValue = currFile->values.First();
        while( currValue != NULL ){
            cache->AddDword( currValue->macroNameID );
            cache->AddDword( currValue->numParams );
            cache->AddDword( currValue->length );
            cache->AddData( currValue->defn, currValue->length );
            currValue = currFile->values.Next();
        }
        if( currFile->next != NULL ){
            currFile = currFile->next;
        } else {
            currFile = _fileInfo->Next();
        }
    }
    cache->EndComponent();
    return TRUE;
}


WBool DependList::LoadFrom( CacheInFile *cache )
/********************************************/
{
    WBool               result;
    FileGuardInfo       *newFile;
    DependValRec        *newValue;
    int                 fileCount;
    FileGuardInfo       *lastFile;
    int                 limit,i,max;
    uint_32             id;


    result = cache->OpenComponent( "Guards" );
    if( !result ){
        return result;
    }

    cache->ReadDword( &fileCount );
    _count = fileCount;
    lastFile = NULL;
    while( fileCount > 0 ){
        newFile = new FileGuardInfo;
        cache->ReadDword( &id );
        newFile->filenameID = id;
        cache->ReadDword( &limit );
        max = limit>0?limit:BRM_NUM_IDS;
        newFile->defined.strings = new BRI_StringID[ max ];
        newFile->defined.maxEntries = max;
        newFile->defined.numEntries = limit;
        for( i=0; i<limit; i++ ){
            cache->ReadDword( &newFile->defined.strings[i] );
        }
        cache->ReadDword( &limit );
        max = limit>0?limit:BRM_NUM_IDS;
        newFile->undefed.strings = new BRI_StringID[ max ];
        newFile->undefed.maxEntries = max;
        newFile->undefed.numEntries = limit;
        for( i=0; i<limit; i++ ){
            cache->ReadDword( &newFile->undefed.strings[i] );
        }
        cache->ReadDword( &limit );
        newFile->numValues = limit;
        for( i=0; i<limit; i++ ){
            newValue = new DependValRec;
            cache->ReadDword( &newValue->macroNameID );
            cache->ReadDword( &newValue->numParams );
            cache->ReadDword( &newValue->length );
            if( newValue->length > 0 ){
                newValue->defn = new uint_8[newValue->length];
                cache->ReadData( newValue->defn, newValue->length );
            } else {
                newValue->defn = NULL;
            }
            newFile->values.Insert( newValue->macroNameID, newValue );
        }
        if( lastFile != NULL && lastFile->filenameID == id ){
            lastFile->next = newFile;
        } else {
            _fileInfo->Insert( id, newFile );
        }
        lastFile = newFile;
        fileCount--;
    }
    cache->CloseComponent();
    return result;
}


MacroList::MacroList()
/********************/
{
    _macroNames = new StringIDs(LIST_BLOCK);
}


MacroList::~MacroList()
/*********************/
{
    delete _macroNames;
}


WBool MacroList::HaveSeen( BRI_StringID macroName )
/***********************************************/
{
    int         i;

    for( i=0; i<_macroNames->numEntries; i++ ){
        if( _macroNames->strings[i] == macroName ){
            return TRUE;
        }
    }

    return FALSE;
}


void MacroList::AddMacroDecl( BRI_StringID macroName, BRI_SymbolID symID )
/************************************************************************/
{
    DeclRec     *decl;

    if( _macroNames->numEntries == _macroNames->maxEntries ){
        _macroNames->DoubleSize();
    }
    _macroNames->strings[ _macroNames->numEntries++ ] = macroName;

    decl = new DeclRec;
    decl->index = (BRI_SymbolID) symID;
    decl->attribs = BRI_SA_Macro;
    decl->nameID = macroName;
    decl->typeID = (BRI_TypeID) 0;

    CurrBrowser->declList()->Insert( decl );
}


WBool MacroList::SaveTo( CacheOutFile *cache )
/******************************************/
{
    int         i;

    cache->StartComponent( "Macros" );
    cache->AddDword( _macroNames->numEntries );
    for( i=0; i<_macroNames->numEntries; i++ ){
        cache->AddDword( _macroNames->strings[i] );
    }
    cache->EndComponent();
    return TRUE;
}


WBool MacroList::LoadFrom( CacheInFile *cache )
/*******************************************/
{
    WBool       result;
    int         limit,i;

    result = cache->OpenComponent( "Macros" );
    if( !result ){
        return result;
    }

    if( _macroNames->strings ){
        delete[] _macroNames->strings;
    }
    cache->ReadDword( &limit );
    _macroNames->maxEntries = limit;
    _macroNames->numEntries = limit;
    _macroNames->strings = new BRI_StringID[ limit ];
    for( i=0; i<limit; i++ ){
        cache->ReadDword( &_macroNames->strings[i] );
    }
    cache->CloseComponent();
    return result;
}

⌨️ 快捷键说明

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