📄 symbols.cpp
字号:
// ScopeSymbols.cpp: implementation of the CSymbols class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Symbols.h"
#include "Xml.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSymbols::CSymbols()
{
}
CSymbols::~CSymbols()
{
POSITION pos = mGlobalList.GetTailPosition();
while(pos != NULL)
delete mGlobalList.GetPrev(pos);
}
GLOBALSYMBAL* CSymbols::QueryGlobalItem( CPage* ipPage)
{
GLOBALSYMBAL* pGolbal = NULL;
if(!mGlobalList.IsEmpty())
{
pGolbal = mGlobalList.GetTail();
if(pGolbal->pPage == ipPage)
return pGolbal;
POSITION pos = mGlobalList.GetTailPosition();
while(pos != NULL)
{
POSITION currPos = pos;
pGolbal = mGlobalList.GetPrev(pos);
//该页已存在,移到最后,以便提高一页中有大量函数时
//查找当前代码页的速度
if(pGolbal->pPage == ipPage)
{
mGlobalList.RemoveAt(currPos);
mGlobalList.AddTail(pGolbal);
return pGolbal;
}
}
}
//不存在,新建一个,在析构函数中删除
pGolbal = new GLOBALSYMBAL();
mGlobalList.AddTail(pGolbal);
return pGolbal;
}
void CSymbols::AddVariable(CVariable* ipVar, CPage* ipPage)
{
GLOBALSYMBAL* pGolbal = QueryGlobalItem(ipPage);
if(pGolbal == NULL)
{
ASSERT(FALSE);
return;
}
pGolbal->variableList.AddTail(ipVar);
}
void CSymbols::AddFunction(CExFunction* ipFunc, CPage* ipPage)
{
GLOBALSYMBAL* pGolbal = QueryGlobalItem(ipPage);
if(pGolbal == NULL)
{
ASSERT(FALSE);
return;
}
pGolbal->functionList.AddTail(ipFunc);
}
void CSymbols::AddType(CType* ipType, CPage* ioPage/*=NULL*/)
{
#ifdef _DEBUG
POSITION pos = mTypeList.GetHeadPosition();
while(pos != NULL)
{
CType* pType = mTypeList.GetNext(pos);
if(pType == ipType)
return;
}
#endif
mTypeList.AddTail(ipType);
}
void CSymbols::OutputSymbols(LPCTSTR iDocDir)
{
CXml xmlClassList(100), xmlGloFunc(100);
xmlClassList.AddNode("<ClassList>", NULL, NULL, "</ClassList>");
xmlGloFunc.AddNode("<GloFunction>", NULL, NULL, "</GloFunction>");
CString tag, fullName;
POSITION pos = mGlobalList.GetHeadPosition();
while(pos != NULL)
{
GLOBALSYMBAL* pGlobal = mGlobalList.GetNext(pos);
CExFunctionList* pFunList = &pGlobal->functionList;
POSITION funPos = pFunList->GetHeadPosition();
while(funPos != NULL)
{
CExFunction* pFun = pFunList->GetNext(funPos);
pFun->GetFullName(fullName);;
tag.Format("<Function name=\"%s\">", fullName);
xmlGloFunc.AddNode(tag, "<GloFunction>", NULL, "</Function>");
}
CVariableList* pVarList = &pGlobal->variableList;
POSITION varPos = pVarList->GetHeadPosition();
while(varPos != NULL)
{
CVariable* pVar = pVarList->GetNext(varPos);
CString type;
pVar->GetType(type);
CString fullName;
pVar->GetFullName(fullName);
TRACE2("%s %s\n", type, fullName);
}
}
const UINT DESC_LEN = 50;
pos = mTypeList.GetHeadPosition();
while(pos != NULL)
{
CType* pType = mTypeList.GetNext(pos);
if(pType->IsClassOrInterface())
{
pType->GetFullName(fullName);
tag.Format("<class name=\"%s\">", fullName);
xmlClassList.AddNode(tag, "<ClassList>", NULL, "</class>");
CString comment;
pType->GetComment(comment);
CString desc;
CIdentifier::GetStringLeft(desc, comment, DESC_LEN);
xmlClassList.AddNode("<desc>", "<ClassList>"+tag, desc, "</desc>");
pType->OutputSymbols(iDocDir);
}
}
CString docDir(iDocDir);
xmlGloFunc.Save(docDir + "GlobalFunc.xml");
xmlClassList.Save(docDir + "ClassList.xml");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -