macro.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 579 行 · 第 1/2 页
CPP
579 行
/****************************************************************************
*
* 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 "wpch.hpp"
#include "decl.hpp"
#include "macro.hpp"
#include "handle.hpp"
#include "avltree.hpp"
#include "cache.hpp"
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
extern Browser *CurrBrowser;
#define LIST_BLOCK 0x100
#define BRM_NUM_IDS 0x10
struct StringIDs {
StringIDs();
StringIDs( int startSize );
~StringIDs();
void DoubleSize();
BRI_StringID *strings;
int maxEntries;
int numEntries;
};
struct FileGuardInfo {
FileGuardInfo();
FileGuardInfo( BRI_StringID fname );
~FileGuardInfo();
FileGuardInfo *next;
BRI_StringID filenameID;
StringIDs defined;
StringIDs undefed;
AvlTree<DependValRec> values;
int numValues;
};
int compareStringIDs( const void *op1, const void *op2 )
/******************************************************/
{
return *((BRI_StringID *) op2) - *((BRI_StringID *) op1);
}
StringIDs::StringIDs()
/********************/
{
strings = NULL;
maxEntries = 0;
numEntries = 0;
}
StringIDs::StringIDs( int startSize )
/***********************************/
{
strings = new BRI_StringID[startSize];
maxEntries = startSize;
numEntries = 0;
}
StringIDs::~StringIDs()
/*********************/
{
delete[] strings;
}
inline void StringIDs::DoubleSize()
/*********************************/
{
BRI_StringID *newNames;
newNames = new BRI_StringID[ 2*maxEntries ];
memcpy( newNames, strings,
maxEntries * sizeof(BRI_StringID) );
delete[] strings;
strings = newNames;
maxEntries *= 2;
}
FileGuardInfo::FileGuardInfo()
/****************************/
{
next = NULL;
filenameID = (BRI_StringID) 0;
numValues = 0;
}
FileGuardInfo::FileGuardInfo(BRI_StringID fname)
: defined( BRM_NUM_IDS )
, undefed( BRM_NUM_IDS )
/**********************************************/
{
next = NULL;
filenameID = fname;
numValues = 0;
}
FileGuardInfo::~FileGuardInfo()
/*****************************/
{
DependValRec *val;
val = values.First();
while( val != NULL ){
if( val->defn != NULL ){
delete[] val->defn;
}
delete val;
val = values.Next();
}
}
DependList::DependList()
/**********************/
{
_fileInfo = new AvlTree<FileGuardInfo>;
_count = 0;
_state = USE;
_temp = NULL;
}
DependList::~DependList()
/***********************/
{
FileGuardInfo *current;
FileGuardInfo *prev;
if( _temp != NULL ){
delete _temp;
}
current = _fileInfo->First();
while( current != NULL ){
do {
prev = current;
current = current->next;
delete prev;
} while( current != NULL );
current = _fileInfo->Next();
}
delete _fileInfo;
}
void DependList::StartFile( BRI_StringID filename )
/*************************************************/
{
if( _templateDepth > 0 ){
return;
}
if( _state == USE ){
if( _temp != NULL ){
delete _temp;
}
_temp = new FileGuardInfo(filename);
} else {
_ignoreDepth += 1;
}
return;
}
void DependList::AddDepDefined( BRI_StringID macroName )
/******************************************************/
{
if( _templateDepth > 0 ){
return;
}
WAssert( _temp != NULL );
if( _temp->defined.numEntries == _temp->defined.maxEntries ){
_temp->defined.DoubleSize();
}
_temp->defined.strings[_temp->defined.numEntries++] = macroName;
return;
}
void DependList::AddDepUndefed( BRI_StringID macroName )
/******************************************************/
{
if( _templateDepth > 0 ){
return;
}
WAssert( _temp != NULL );
if( _temp->undefed.numEntries == _temp->undefed.maxEntries ){
_temp->undefed.DoubleSize();
}
_temp->undefed.strings[_temp->undefed.numEntries++] = macroName;
return;
}
void DependList::AddDepMacValue( DependValRec *value )
/****************************************************/
{
DependValRec *previous;
if( _templateDepth > 0 ){
return;
}
WAssert( _temp != NULL );
previous = _temp->values.Find( value->macroNameID );
if( previous == NULL ){
_temp->values.Insert( value->macroNameID, value );
_temp->numValues++;
} else {
delete value;
}
return;
}
WBool DependList::IncludeFile()
/***************************/
{
WBool result;
FileGuardInfo *fileInfo, *headInfo;
DependValRec *value, *other;
if( _templateDepth > 0 ){
return TRUE;
}
WAssert( _temp != NULL );
qsort( _temp->defined.strings, _temp->defined.numEntries,
sizeof(BRI_StringID), &::compareStringIDs );
qsort( _temp->undefed.strings, _temp->undefed.numEntries,
sizeof(BRI_StringID), &::compareStringIDs );
result = TRUE;
headInfo = _fileInfo->Find( _temp->filenameID );
fileInfo = headInfo;
for( ; fileInfo != NULL && result; fileInfo = fileInfo->next ){
if( _temp->defined.numEntries != fileInfo->defined.numEntries ){
continue;
}
if( _temp->undefed.numEntries != fileInfo->undefed.numEntries ){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?