browserutil.cpp
来自「用bcg库编写的java IDE 源码」· C++ 代码 · 共 2,177 行 · 第 1/4 页
CPP
2,177 行
#include "stdafx.h"
#include "browser.h"
#include "BaseTextBuffer.h"
#include "ptrStack.h"
#pragma optimize("t",on)
static LPCTSTR m_lszpBasicTypes[]=
{
_T("byte"),
_T("short"),
_T("char"),
_T("long"),
_T("float"),
_T("double"),
_T("boolean"),
_T("int"),
NULL
};
static bool basictype(LPCTSTR lszpToken)
{
for(int I=0; m_lszpBasicTypes[I] != NULL; I++)
if(::strcmp(m_lszpBasicTypes[I],lszpToken) == 0)return true;
return false;
}
//__DeclBound
__DeclBound::__DeclBound()
{
m_nStartIndex = -1;
m_nStartLine = -1;
m_nEndIndex = -1;
m_nEndLine = -1;
}
__DeclBound::__DeclBound(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
{
m_nStartIndex = nStartIndex;m_nStartLine = nStartLine;
m_nEndIndex = nEndIndex;m_nEndLine = nEndLine;
}
bool __DeclBound::operator>(__DeclBound declBound)
{
if(m_nStartLine > declBound.m_nEndLine)
return true;
if(m_nStartLine == declBound.m_nEndLine)
if(m_nStartIndex>declBound.m_nEndIndex)
return true;
return false;
}
bool __DeclBound::operator<(__DeclBound declBound)
{
if(m_nEndLine < declBound.m_nStartLine)
return true;
if(m_nEndLine == declBound.m_nStartLine)
if(m_nEndIndex<declBound.m_nStartIndex)
return true;
return false;
}
void __DeclBound::operator=(__DeclBound declBound)
{
m_nStartIndex = declBound.m_nStartIndex;
m_nStartLine = declBound.m_nStartLine;
m_nEndIndex = declBound.m_nEndIndex;
m_nEndLine = declBound.m_nEndLine;
}
void __DeclBound::Set(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
{
m_nStartIndex = nStartIndex;m_nStartLine = nStartLine;
m_nEndIndex = nEndIndex;m_nEndLine = nEndLine;
}
bool __DeclBound::operator>(__DeclPoint pt)
{
if(m_nStartLine > pt.m_nLine)return true;
if((m_nStartLine == pt.m_nLine)&&(m_nStartIndex > pt.m_nIndex))return true;
return false;
}
bool __DeclBound::operator==(__DeclBound declBound)
{
if(m_nStartIndex == declBound.m_nStartIndex)
if(m_nStartLine == declBound.m_nStartLine)
if(m_nEndIndex == declBound.m_nEndIndex)
if(m_nEndLine == declBound.m_nEndLine)
return true;
return false;
}
bool __DeclBound::operator<(__DeclPoint pt)
{
if(m_nEndLine < pt.m_nLine)return true;
if((m_nEndLine == pt.m_nLine) && (m_nEndIndex < pt.m_nIndex))return true;
return false;
}
bool __DeclBound::PointInDeclBlock(__DeclPoint& declPt)
{
ASSERT(FALSE);
/**
if(!m_pBlockEndLine)//unbalanced braces
{
if(declPt.m_nLine>m_nEndLine)
return true;
else
if((declPt.m_nLine == m_nEndLine)&&(declPt.m_nIndex>m_nEndIndex))
return true;
}
else
{ //on endline
if(declPt.m_nLine == m_nEndLine)
{
//if the block is one line
if((m_nEndLine == (*m_pBlockEndLine))&&((*m_pBlockEndLine) == declPt.m_nLine))
return ((declPt.m_nIndex>m_nEndIndex)&&(declPt.m_nIndex<=(*m_pBlockEndIndex)));
//else
return(declPt.m_nIndex>m_nEndIndex);
}
else//block line
if(declPt.m_nLine == (*m_pBlockEndLine))
return (declPt.m_nIndex<=(*m_pBlockEndIndex));
else//between
return((declPt.m_nLine>m_nEndLine)&&(declPt.m_nLine<(*m_pBlockEndLine)));
}return false;**/return false;
}
bool __DeclBound::PointInDecl(__DeclPoint& declPt)
{
if(m_nStartLine == m_nEndLine)
{
if(m_nStartLine == declPt.m_nLine)
{
if((declPt.m_nIndex>=m_nStartIndex)&&(declPt.m_nIndex<=m_nEndIndex))
return true;
else
if((declPt.m_nIndex == m_nStartIndex))//must be '{'or '}'
return true;
}
else
return false;
}
else
{
if((declPt.m_nLine>m_nStartLine)&&(declPt.m_nLine<m_nEndLine))
return true;
else
if((declPt.m_nLine == m_nStartLine)&&(declPt.m_nIndex>=m_nStartIndex))
return true;
else
if((declPt.m_nLine == m_nEndLine)&&(declPt.m_nIndex<=m_nEndIndex))
return true;
}
return false;
}
bool __DeclBound::BoundInDecl(__DeclBound& declBound)
{
if(declBound.m_nEndLine == -1)//insert context
{
if(m_nStartLine == m_nEndLine)
{
if(m_nStartLine == declBound.m_nStartLine)
{
if((declBound.m_nStartIndex>=m_nStartIndex)&&(declBound.m_nStartIndex<=m_nEndIndex))
return true;
}
else
return false;
}
else
{
if(declBound.m_nStartLine>m_nStartLine&&declBound.m_nStartLine<m_nEndLine)
return true;
else
if((declBound.m_nStartIndex>=m_nStartIndex)&&(declBound.m_nStartLine == m_nStartLine))
return true;
else
if((declBound.m_nStartIndex<=m_nEndIndex)&&(declBound.m_nStartLine == m_nEndLine))
return true;
}
}
else //delete context
{
//swallowed by multi-line delete
if(
((declBound.m_nStartLine < m_nStartLine)||
((declBound.m_nStartLine == m_nStartLine)&&
(declBound.m_nStartIndex < m_nStartIndex)))
&&
((declBound.m_nEndLine > m_nEndLine)||((declBound.m_nEndLine == m_nEndLine)
&&(declBound.m_nEndIndex > m_nEndIndex)))
)
return true;
__DeclPoint nPt(declBound.m_nStartIndex,declBound.m_nStartLine);
__DeclPoint nePt(declBound.m_nEndIndex,declBound.m_nEndLine);
return(PointInDecl(nPt)||PointInDecl(nePt));
}return false;
}
bool __DeclBound::BoundInDecl(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
{
if(nEndLine == -1)//insert context
{
if(m_nStartLine == m_nEndLine)
{
if(m_nStartLine == nStartLine)
{
if((nStartIndex>=m_nStartIndex)&&(nStartIndex<=m_nEndIndex))
return true;
}
else
return false;
}
else
{
if(nStartLine>m_nStartLine&&nStartLine<m_nEndLine)
return true;
else
if((nStartIndex>=m_nStartIndex)&&(nStartLine == m_nStartLine))
return true;
else
if((nStartIndex<=m_nEndIndex)&&(nStartLine == m_nEndLine))
return true;
}
}
else //delete context
{
//swallowed by multi-line delete
if(
((nStartLine < m_nStartLine)||
((nStartLine == m_nStartLine)&&
(nStartIndex < m_nStartIndex)))
&&
((nEndLine > m_nEndLine)||((nEndLine == m_nEndLine)
&&(nEndIndex > m_nEndIndex)))
)
return true;
__DeclPoint nPt(nStartIndex,nStartLine);
__DeclPoint nePt(nEndIndex,nEndLine);
return(PointInDecl(nPt)||PointInDecl(nePt));
}
return false;
}
//*******************************************__CBaseDecl**************************//
__CBaseDecl::__CBaseDecl(){}
__CBaseDecl::__CBaseDecl(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
{
m_pBound = new __DeclBound(nStartIndex,nStartLine,nEndIndex,nEndLine);
m_pParent = NULL;
m_hTreeLoc = NULL;
m_strAccessModifier = _T("private");
}
__CBaseDecl::~__CBaseDecl()
{
delete m_pBound;
if((m_nDeclKind == ENDBRACE_DECL)&&(m_pParent != NULL))
m_pParent->SetEndBrace(NULL);
/**
if((m_nDeclKind == ENDBRACE_DECL)&&(m_pParent != NULL))
{
m_pDeclMgr->getDeclList()->GetNext(m_nMainPos);
if(m_nMainPos)
m_pDeclMgr->ResetParent(m_pDeclMgr->getDeclList()->GetAt(m_nMainPos),m_pParent,END_BRACE);
}**/
//if(m_pParent)
// m_pParent->RemoveMember(m_nPos);
}
void __CBaseDecl::setKind(int kind){m_nDeclKind = kind;}
bool __CBaseDecl::update(__DeclBound& declBound,CDeclManager* pDeclMgr)
{
if(m_pBound->BoundInDecl(declBound))
return true;
//**pDeclMgr->updateBlock(this);
return false;
}
bool __CBaseDecl::update(int nStartIndex,int nStartLine,CDeclManager* pDeclMgr)
{
if(m_pBound->BoundInDecl(nStartIndex,nStartLine,-1,-1))return true;
//**pDeclMgr->updateBlock(this);
return false;
}
void __CBaseDecl::move(HTREEITEM,bool){}
bool __CBaseDecl::IsNamed(CString strName)
{
return(m_strDeclName.Compare(strName) == 0);
}
POSITION __CBaseDecl::skipBlock()
{
POSITION pos = m_nMainPos;
m_pDeclMgr->getDeclList()->GetNext(pos);
return pos;
}
//******************************CFieldDecl****************************************//
CFieldDecl::CFieldDecl()
{
m_nDeclKind = FIELD_DECL;
m_nFieldPos = NULL;
}
CFieldDecl::CFieldDecl(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
:__CBaseDecl(nStartIndex,nStartLine,nEndIndex,nEndLine)
{
m_nDeclKind = FIELD_DECL;
m_nFieldPos = NULL;
}
CFieldDecl::~CFieldDecl()
{
//TRACE("deleting field...\n");
if(m_pParent != NULL)
m_pParent->RemoveMember(m_nPos);
}
void CFieldDecl::setLoc(int i,HTREEITEM loc)
{
m_lVars[i]->m_hLoc = loc;
}
HTREEITEM CFieldDecl::getLoc(int i)
{
return m_lVars[i]->m_hLoc;
}
bool CFieldDecl::PointInDeclScope(__DeclPoint& declPt)
{
return false;
}
void CFieldDecl::addVarName(CString strName,HTREEITEM hLoc)
{
_var* pVar = new _var(strName,hLoc);
m_lVars.Add(pVar);
}
int CFieldDecl::getcount()
{
return m_lVars.GetSize();
}
CString CFieldDecl::getVar(int nIndex)
{
ASSERT(nIndex<m_lVars.GetSize());
return m_lVars[nIndex]->m_strName;
}
void CFieldDecl::moveVariables(HTREEITEM,BOOL /*= FALSE*/)
{
}
POSITION CFieldDecl::getFieldPos()
{
return m_nFieldPos;
}
void CFieldDecl::setFieldPos(POSITION pos)
{
m_nFieldPos = pos;
}
//CString CFieldDecl::getType(){return m_strType;}
//*****************************CMethodDecl****************************************//
CMethodDecl::CMethodDecl()
{
m_nDeclKind = METHOD_DECL;
m_bImplemented = true;
m_nMethodPos = NULL;
}
CMethodDecl::CMethodDecl(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
:CBlockDecl(nStartIndex,nStartLine,nEndIndex,nEndLine)
{
m_nDeclKind = METHOD_DECL;
m_bImplemented = true;
m_nMethodPos = NULL;
}
CMethodDecl::~CMethodDecl()
{
/*
m_pDeclMgr->removeBlock(m_nStoragePos);
if(m_pDeclMgr->validDoc())
{
if(m_pBound->m_nStartLine<m_pDeclMgr->getLineCount())
m_pDeclMgr->removeNode(m_pBound->m_nStartLine,m_pBound->m_nStartIndex);
}
delete m_pBound;
*/
}
void CMethodDecl::BuildInfo(CStringList& lstrSrc)
{
for(POSITION pos = lstrSrc.GetHeadPosition(); pos !=NULL;)
m_lstrInfo.AddTail(lstrSrc.GetNext(pos));
}
bool CMethodDecl::PointInDeclBlock(__DeclPoint& declPt)
{
if(!m_bImplemented)return false;
else
return CBlockDecl::PointInDeclBlock(declPt);
}
bool CMethodDecl::IsImplemented(){return m_bImplemented;}
void CMethodDecl::SetImplemented(bool bImplemented){m_bImplemented = bImplemented;}
POSITION CMethodDecl::getMethodPos()
{
return m_nMethodPos;
}
CString CMethodDecl::getParameterizedName(){return m_strParameterizedName;}
void CMethodDecl::setParameterizedName(CString strPname){
m_strParameterizedName = strPname;
}
void CMethodDecl::setReturnType(CString strType){m_strReturnType = strType;}
CString CMethodDecl::getReturnType(){return m_strReturnType;}
void CMethodDecl::setMethodPos(POSITION pos)
{
m_nMethodPos = pos;
}
BOOL CMethodDecl::Match(CStringList& lstrArgs)
{
return FALSE;
}
//*******************************CClassDecl***************************************//
CClassDecl::CClassDecl()
{
}
CClassDecl::CClassDecl(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
:CTypeDecl(nStartIndex,nStartLine,nEndIndex,nEndLine)
{
m_nDeclKind = CLASS_DECL;
}
CClassDecl::~CClassDecl()
{
/*
m_pDeclMgr->removeBlock(m_nStoragePos);
if(m_pDeclMgr->validDoc())
{
if(m_pBound->m_nStartLine<m_pDeclMgr->getLineCount())
m_pDeclMgr->removeNode(m_pBound->m_nStartLine,m_pBound->m_nStartIndex);
}
delete m_pBound;
*/
}
//*******************************CinterfaceDecl***********************************//
CInterfaceDecl::CInterfaceDecl()
{
}
CInterfaceDecl::CInterfaceDecl(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
:CTypeDecl(nStartIndex,nStartLine,nEndIndex,nEndLine)
{
m_nDeclKind = INTERFACE_DECL;
}
CInterfaceDecl::~CInterfaceDecl()
{
/*
m_pDeclMgr->removeBlock(m_nStoragePos);
if(m_pDeclMgr->validDoc())
{
if(m_pBound->m_nStartLine<m_pDeclMgr->getLineCount())
m_pDeclMgr->removeNode(m_pBound->m_nStartLine,m_pBound->m_nStartIndex);
}
delete m_pBound;
*/
}
//CTypeDecl
CTypeDecl::CTypeDecl(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
:CBlockDecl(nStartIndex,nStartLine,nEndIndex,nEndLine)
{
}
CTypeDecl::CTypeDecl()
{
}
CTypeDecl::~CTypeDecl()
{
/*
for(POSITION pos = m_lMembers.GetHeadPosition(); pos !=NULL;)
{
__CBaseDecl* pDecl = m_lMembers.GetNext(pos);
m_pDeclMgr->RemoveDecl(pDecl->getMainPos());
delete pDecl;
}
*/
if(m_pParent == NULL)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?