📄 srcparser.cpp
字号:
{
return ( GetOutterContext()->GetContextType() == SP_CTX_FILE );
}
bool spContext::IsInNameSpace()
{
return ( GetOutterContext()->GetContextType() == SP_CTX_NAMESPACE );
}
bool spContext::IsInClass()
{
return ( GetOutterContext()->GetContextType() == SP_CTX_CLASS );
}
bool spContext::IsInOperation()
{
return ( GetOutterContext()->GetContextType() == SP_CTX_OPERATION );
}
spClass& spContext::GetClass()
{
wxASSERT( GetOutterContext()->GetType() == SP_CTX_CLASS );
return *((spClass*)m_pParent );
}
spFile& spContext::GetFile()
{
wxASSERT( GetOutterContext()->GetType() == SP_CTX_FILE );
return *((spFile*)m_pParent );
}
spNameSpace& spContext::GetNameSpace()
{
wxASSERT( GetOutterContext()->GetType() == SP_CTX_NAMESPACE );
return *((spNameSpace*)m_pParent );
}
spOperation& spContext::GetOperation()
{
wxASSERT( GetOutterContext()->GetType() == SP_CTX_OPERATION );
return *((spOperation*)m_pParent );
}
/***** Implementation for class spClass *****/
void spClass::SortMembers()
{
// TBD::
}
/***** Implementation for class spOperation *****/
spOperation::spOperation()
: mHasDefinition( false )
{
mIsConstant =
mIsVirtual =
mHasDefinition = false;
}
wxString spOperation::GetFullName(MarkupTagsT tags)
{
wxString txt = tags[TAG_BOLD].start + m_RetType;
txt += _T(" ");
txt += m_Name;
txt += _T("( ");
txt += tags[TAG_BOLD].end;
for( size_t i = 0; i != mMembers.size(); ++i )
{
// DBG::
wxASSERT( mMembers[i]->GetContextType() == SP_CTX_PARAMETER );
spParameter& param = *((spParameter*)mMembers[i]);
if ( i != 0 )
txt += _T(", ");
txt += tags[TAG_BOLD].start;
txt += param.m_Type;
txt += tags[TAG_BOLD].end;
txt += tags[TAG_ITALIC].start;
txt += _T(" ");
txt += param.m_Name;
if ( !param.m_InitVal.empty() )
{
txt += _T(" = ");
txt += tags[TAG_BOLD].start;
txt += param.m_InitVal;
txt += tags[TAG_BOLD].end;
}
txt += tags[TAG_ITALIC].end;;
}
txt += tags[TAG_BOLD].start;
txt += " )";
txt += tags[TAG_BOLD].end;
// TBD:: constantness of method
return txt;
}
/***** Implemenentation for class spPreprocessorLine *****/
wxString spPreprocessorLine::CPP_GetIncludedFileNeme() const
{
wxASSERT( GetStatementType() == SP_PREP_DEF_INCLUDE_FILE );
size_t i = 0;
while( i < m_Line.length() && m_Line[i] != _T('"') && m_Line[i] != _T('<') )
++i;
++i;
size_t start = i;
while( i < m_Line.length() && m_Line[i] != _T('"') && m_Line[i] != _T('>') )
++i;
if ( start < m_Line.length() )
{
wxString fname;
fname.append( m_Line, start, ( i - start ) );
return fname;
}
else
return wxEmptyString; // syntax error probably
}
/***** Implemenentation for class SourceParserBase *****/
SourceParserBase::SourceParserBase()
: mpFileBuf( NULL ),
mFileBufSz( 0 ),
mpPlugin( NULL )
{}
SourceParserBase::~SourceParserBase()
{
if ( mpFileBuf ) free( mpFileBuf );
if ( mpPlugin ) delete mpPlugin;
}
spFile* SourceParserBase::ParseFile( const char* fname )
{
// FIXME:: the below should not be fixed!
const size_t MAX_BUF_SIZE = 1024*256;
if ( !mpFileBuf ) mpFileBuf = (char*)malloc( MAX_BUF_SIZE );
mFileBufSz = MAX_BUF_SIZE;
FILE* fp = fopen( fname, "rt" );
if ( !fp ) return NULL;
int sz = fread( mpFileBuf, 1, mFileBufSz, fp );
return Parse( mpFileBuf, mpFileBuf + sz );
}
void SourceParserBase::SetPlugin( SourceParserPlugin* pPlugin )
{
if ( mpPlugin ) delete mpPlugin;
mpPlugin = pPlugin;
}
// ===========================================================================
// debug methods
// ===========================================================================
#ifdef __WXDEBUG__
void spContext::Dump(const wxString& indent) const
{
DumpThis(indent);
// increase it for the children
wxString indentChild = indent + " ";
for ( MMemberListT::const_iterator i = mMembers.begin();
i != mMembers.end();
i++ ) {
(*i)->Dump(indentChild);
}
}
void spContext::DumpThis(const wxString& WXUNUSED(indent)) const
{
wxFAIL_MSG("abstract base class can't be found in parser tree!");
}
void spParameter::DumpThis(const wxString& indent) const
{
wxLogDebug("%sparam named '%s' of type '%s'",
indent.c_str(), m_Name.c_str(), m_Type.c_str());
}
void spAttribute::DumpThis(const wxString& indent) const
{
wxLogDebug("%svariable named '%s' of type '%s'",
indent.c_str(), m_Name.c_str(), m_Type.c_str());
}
void spOperation::DumpThis(const wxString& indent) const
{
wxString protection;
if ( !mScope.empty() ) {
switch ( mVisibility ) {
case SP_VIS_PUBLIC:
protection = "public";
break;
case SP_VIS_PROTECTED:
protection = "protected";
break;
case SP_VIS_PRIVATE:
protection = "private";
break;
default:
wxFAIL_MSG("unknown protection type");
}
}
else {
protection = "global";
}
wxString constStr,virtualStr;
if(mIsConstant) constStr = _T("const ");
if(mIsVirtual) virtualStr = _T("virtual ");
wxLogDebug("%s%s%s%s function named '%s::%s' of type '%s'",
indent.c_str(),
constStr.c_str(),
virtualStr.c_str(),
protection.c_str(),
mScope.c_str(), m_Name.c_str(), m_RetType.c_str());
}
void spPreprocessorLine::DumpThis(const wxString& indent) const
{
wxString kind;
switch ( mDefType ) {
case SP_PREP_DEF_DEFINE_SYMBOL:
kind = "define";
break;
case SP_PREP_DEF_REDEFINE_SYMBOL:
kind = "redefine";
break;
case SP_PREP_DEF_INCLUDE_FILE:
kind.Printf("include (%s)", CPP_GetIncludedFileNeme().c_str());
break;
case SP_PREP_DEF_OTHER:
kind = "other";
break;
}
wxLogDebug("%spreprocessor statement: %s",
indent.c_str(), kind.c_str());
}
void spClass::DumpThis(const wxString& indent) const
{
wxString base;
for ( StrListT::const_iterator i = m_SuperClassNames.begin();
i != m_SuperClassNames.end();
i++ ) {
if ( !base.empty() )
base += ", ";
base += *i;
}
if ( !base )
base = "none";
wxString kind;
switch ( mClassSubType ) {
case SP_CLTYPE_CLASS:
kind = "class";
break;
case SP_CLTYPE_TEMPLATE_CLASS:
kind = "template class";
break;
case SP_CLTYPE_STRUCTURE:
kind = "struc";
break;
case SP_CLTYPE_UNION:
kind = "union";
break;
case SP_CLTYPE_INTERFACE:
kind = "interface";
break;
default:
wxFAIL_MSG("unknown class subtype");
}
wxLogDebug("%s%s named '%s' (base classes: %s)",
indent.c_str(), kind.c_str(),
m_Name.c_str(), base.c_str());
}
void spEnumeration::DumpThis(const wxString& indent) const
{
wxLogDebug("%senum named '%s'",
indent.c_str(), m_Name.c_str());
}
void spTypeDef::DumpThis(const wxString& indent) const
{
wxLogDebug("%stypedef %s = %s",
indent.c_str(), m_Name.c_str(), m_OriginalType.c_str());
}
void spFile::DumpThis(const wxString& indent) const
{
wxLogDebug("%sfile '%s'",
indent.c_str(), m_FileName.c_str());
}
#endif // __WXDEBUG__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -