📄 identifier.cpp
字号:
#include "stdafx.h"
#include "IdenItem.h"
#include "Identifiers.h"
#include "CPGlobals.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
BEGIN_TEST_DUMP(CIdentifier)
//TEST_DUMP(mpPage)
//TEST_DUMP(mLine)
//TEST_DUMP(mColumn)
TEST_DUMP(mName)
TEST_DUMP(mpCurrScope)
TEST_DUMP(mpScope)
END_TEST_DUMP()
CIdentifier::CIdentifier(CPage* ipPage/*=NULL*/, int iLine/*=1*/, int iColumn/*=1*/)
:
mpPage(ipPage),
mLine(iLine),
mColumn(iColumn),
mDefined(FALSE)
{
mpCurrScope = NULL;
mpScope = NULL;
mTrim = 0;
}
CIdentifier::~CIdentifier()
{
delete mpCurrScope;
delete mpScope;
}
BOOL CIdentifier::IsVisibleByPage(CPage* ipVisibler)
{
if(mpPage == NULL || ipVisibler == NULL)
return TRUE;
if(mpPage == ipVisibler)
return TRUE;
return ipVisibler->IsIncludedPage(mpPage);
}
BOOL CIdentifier::BeforeParseUnknowCode(CTokenList& ioList,
POSITION& ioPos,
CTokenList& oDeclList,
UINT& oSymType,
BOOL& oDefinition)
{
oDefinition = FALSE;
oSymType = SYM_UNKNOW;
int symCount = 0; //可能表达类型或变量名或函数名的token数量
BOOL fondAssign = FALSE; //是否出现赋值操作符
CToken* pToken = NULL;
while(ioPos != NULL)
{
NEXT_TOKEN_OR_BREAK();
ASSERT(pToken != NULL);
if(pToken->IsType(TT_WORD))
{
CIdenItem* pIdenItem = gIdens.Search(pToken->GetContent());
if(pIdenItem == NULL || pIdenItem->keyIndex == KEY_NOT || pIdenItem->IsDataType())
symCount++;
}
else if(pToken->IsType(TT_SEMICOLON)) //;
{
break;
}
else if(oSymType == SYM_FUNCTION && pToken->IsType(TT_LSQUARE)) // {
{
oDefinition = TRUE;
break;
}
else if(!fondAssign && pToken->IsType(TT_LPARAN)) // (
{
oSymType = SYM_FUNCTION;
}
else if(pToken->IsType(TT_ASSIGN)) // =
{
fondAssign = TRUE;
}
oDeclList.AddTail(pToken);
}
if(oSymType == SYM_UNKNOW && symCount >= 2)
oSymType = SYM_VARIABLE;
return (oSymType != SYM_UNKNOW);
}
BOOL CIdentifier::IsWordFinish(CString& iStr)
{
if(iStr.IsEmpty())
return FALSE;
char ch = iStr.GetAt(iStr.GetLength()-1);
if(ch >= 'a' && ch <= 'z')
return TRUE;
if(ch >= 'A' && ch <= 'Z')
return TRUE;
if(ch >= '0' && ch <= '9')
return TRUE;
if(ch == '_')
return TRUE;
return FALSE;
}
void CIdentifier::CatDataType(CString& oType, CToken& oToken)
{
if(!oToken.IsType(TT_WORD))
{
oType += oToken.GetContent();
}
else
{
if(IsWordFinish(oType))
oType += ' ';
oType += oToken.GetContent();
}
}
void CIdentifier::SetCurrScope(LPCTSTR iScope)
{
if(mpCurrScope == NULL)
mpCurrScope = new CString(iScope);//在析构函数中删除
else
*mpCurrScope += iScope;
}
void CIdentifier::SetScope(LPCTSTR iScope)
{
if(mpScope == NULL)
mpScope = new CString(iScope);//在析构函数中删除
else
*mpScope += iScope;
}
void CIdentifier::SetScopeReverse(LPCTSTR iScope)
{
if(mpScope == NULL)
mpScope = new CString(iScope);//在析构函数中删除
else
mpScope->Insert(0, iScope);
}
void CIdentifier::GetFullName(CString& oFullName)
{
oFullName.Empty();
if(mpCurrScope != NULL)
oFullName += *mpCurrScope;
if(mpScope != NULL)
oFullName += *mpScope;
oFullName += mName;
}
void CIdentifier::GetStringLeft(CString& oDes, CString& oSrc, UINT iLen)
{
if((UINT)oSrc.GetLength() <= iLen)
{
oDes = oSrc;
return;
}
UINT i = 0;
for(; i<iLen; i++)
{
BYTE b = (BYTE)oSrc.GetAt(i);
if(::IsDBCSLeadByte(b))
i++;
}
oDes = oSrc.Left(i) + "...";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -