/*********************************************************************
Copyright (C) 2001 by
Alexander Berthold, alexander-berthold@web.de.
Hoegestr. 54
79108 Freiburg i. Breisgau
Germany
-- This file is part of cxAnalyzer --
"cxAnalyzer" is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or any later version.
"cxAnalyzer" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with "cxAnalyzer"; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
---------------------------------------------------------------
If you find any bugs or if you make other corrections/
enhancements, i'd appreciate if you'd let me know about
that. My email is
alexander-berthold@web.de
If you share this code, do not remove this text.
---------------------------------------------------------------
*********************************************************************/
// cxaParseBranch.cpp: implementation of the cxaParseBranch class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "cxAnalyzerTypeMap.h"
#include "cxaToken.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
bool cxaParseBranch::fCompareToIDValue(const cxAnalyzerTypeMap* patmMap, int nIDValue) const
{
int nAtmTypeCmp = patmMap->nGetAtmTypeFor(nIDValue);
if(nAtmType==nAtmTypeCmp)
return true;
else
return false;
}
cxaParseBranch* cxaParseBranch::papbGetParent() const
{
cxaParseElement *papeParent = tGetParent();
if(papeParent) ASSERT(papeParent->fIsBranch());
return ((cxaParseBranch*)papeParent);
}
bool cxaParseBranch::fIsFrontNULLToken() const
{
ASSERT(!fIsEmpty());
cxaParseElement *papeFront = tGetFront();
cxaParseNode *papnFront = NULL;
if(papeFront->fIsBranch())
return false;
papnFront =(cxaParseNode*)papeFront;
if(papnFront->patGetToken() == NULL)
return true;
return false;
}
bool cxaParseBranch::fIsBackNULLToken() const
{
ASSERT(!fIsEmpty());
cxaParseElement *papeBack = tGetBack();
cxaParseNode *papnBack = NULL;
if(papeBack->fIsBranch())
return false;
papnBack =(cxaParseNode*)papeBack;
if(papnBack->patGetToken() == NULL)
return true;
return false;
}
cxaParseNode *cxaParseBranch::papnGetFrontNode() const
{
ASSERT(!fIsEmpty());
cxaParseElement *papeFront = tGetFront();
if(papeFront->fIsBranch())
return NULL;
return ((cxaParseNode*)papeFront);
}
cxaParseNode *cxaParseBranch::papnGetBackNode() const
{
ASSERT(!fIsEmpty());
cxaParseElement *papeBack = tGetBack();
if(papeBack->fIsBranch())
return NULL;
return ((cxaParseNode*)papeBack);
}
cxaParseElement *cxaParseBranch::papeGetFrontElement() const
{
cxaParseElement *papeFront = tGetFront();
return papeFront;
}
cxaParseElement *cxaParseBranch::papeGetBackElement() const
{
cxaParseElement *papeBack = tGetBack();
return papeBack;
}
void cxaParseBranch::vEnumBegin(sit_data_t* psData) const
{
psData->papbBranch =this;
psData->pos0 =begin();
ASSERT(psData->pos0!=end());
}
bool cxaParseBranch::fHelpNext(sit_data_t* psData, bool& fBreak) const
{
ASSERT(psData->pos0!=psData->papbBranch->end());
fBreak =false;
for(;;)
{
psData->pos0++;
while(psData->pos0==psData->papbBranch->end())
{
cxaParseElement *papeNext = psData->papbBranch->tGetNext();
if(papeNext==NULL)
return false;
if(papeNext->fIsBranch()==false)
return false;
psData->papbBranch=(cxaParseBranch*)papeNext;
psData->pos0 =psData->papbBranch->begin();
fBreak =true;
}
if( (*psData->pos0)->fIsBranch() )
return true;
if( ((cxaParseNode*)(*psData->pos0))->patGetToken()!=NULL)
return true;
}
return true;
}
bool cxaParseBranch::fEnumNext(sit_data_t* psData) const
{
if(psData->pos0==psData->papbBranch->end())
return false;
ASSERT(*psData->pos0!=NULL); // forgot to call vEnumBegin()?
bool fIsBranch = (*psData->pos0)->fIsBranch();
bool fBreak = false;
if(fIsBranch)
{
for(;;)
{
if(!fHelpNext(psData,fBreak))
return false;
if(fBreak)
return true;
if( (*psData->pos0)->fIsNode() )
return true;
}
}
else
{
if(!fHelpNext(psData,fBreak))
return false;
return true;
}
}
const cxaParseElement* cxaParseBranch::papeEnumGetAt(sit_data_t* psData) const
{
if(psData->pos0==psData->papbBranch->end())
{
cxaParseBranch::const_iterator it = psData->papbBranch->begin();
for(;it!=psData->papbBranch->end();it++)
{
const cxaParseElement* papeCur = (*it);
ASSERT(papeCur->fIsBranch());
return papeCur;
}
ASSERT(false);
return NULL;
}
ASSERT(psData->pos0!=psData->papbBranch->end());
return (*psData->pos0);
}
void cxaParseBranch::vEnumEnd(sit_data_t* /*sData*/) const
{
}
void spaces(int nSpaces)
{
int i;
for(i=0;i<nSpaces;i++) TRACE(_T(" "));
}
void cxaParseBranch::vDump(int nSpaces) const
{
const_iterator it;
for(it=begin();it!=end();it++)
{
const cxaParseElement *pape = (*it);
if(pape->fIsBranch())
{
cxaParseBranch *papb = ((cxaParseBranch*)pape);
char c1,c2;
if(papb->fIsLeftBound()) c1='('; else c1='[';
if(papb->fIsRightBound()) c2=')'; else c2=']';
spaces(nSpaces);
// TRACE(_T("<< BEGIN %c%d%c\n"), c1, ((cxaParseBranch*)pape)->nGetPrecPrio() , c2);
TRACE(_T("<< BEGIN %c%d%c {id=%d,atm=%d}\n"), c1, ((cxaParseBranch*)pape)->nGetPrecPrio() , c2,
papb->nGetIDValue(),papb->nGetAtmType());
((cxaParseBranch*)pape)->vDump(nSpaces+1);
spaces(nSpaces);
TRACE(_T("END >>\n"));
}
else
{
spaces(nSpaces);
const cxaToken* pat=((cxaParseNode*)pape)->patGetToken();
if(pat)
TRACE(_T("* %s,%d,%d\n"), pat->lpszTokenText, pat->nAtmType, pat->nIDValue);
else
TRACE(_T("* NULL\n"));
}
}
}