⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srcparser.h

📁 Wxpython Implemented on Windows CE, Source code
💻 H
📖 第 1 页 / 共 2 页
字号:

    // see comments on mpFirstOccurence member variable
    bool IsFirstOccurence();
    spContext* GetFirstOccurence();

    // returns not-NULL value if this context
    // is aggregated by another cotnext
    spContext* GetOutterContext();

    // perhaps more intuitive alias for `GetOutterContext()'
    inline spContext* GetParent() { return m_pParent; }

    bool HasOutterContext();

    // add one aggregate (or child) into this context
    void AddMember ( spContext* pMember );
    MMemberListT& GetMembers();

    // append comment to the comment list decribing
    // this context
    void AddComment( spComment* pComment );

    // returns NULL, if the context with the given
    // name and type is not contained by this context
    // and it's children. Children's children are not
    // searched recursivelly if searchSubMembers is false

    spContext* FindContext( const wxString& identifier,
                            int   contextType      = SP_CTX_ANY,
                            bool  searchSubMembers = true
                          );

    // removes this context from it's parent
    // (NOTE:: context should have an outter cotnext
    //  to when this method is called, otherwise removal
    //  will result assertion failure)
    void RemoveThisContext();

    // returns true, if this object is aggregated in the file
    bool IsInFile();

    // true, if outter context is a namespace
    bool IsInNameSpace();

    // true, if outter context is a class
    bool IsInClass();

    // true, if outter cotext is an operation (true for "spParameter"s)
    bool IsInOperation();

    // true if the context is public
    bool IsPublic() const { return mVisibility == SP_VIS_PUBLIC; }

    // NOTE:: method returns not the type of this object
    //          but the file/namespace/class/operation or file in which this
    //          attribute is contained. First, check for the type of
    //        context using the above method.

    //          Requiering container which does not exist, will result
    //        in assertion failure

    spClass&     GetClass();
    spFile&      GetFile();
    spNameSpace& GetNameSpace();
    spOperation& GetOperation();

    // each new context should override this method
    // to return it's specific type
    virtual int GetContextType() const { return SP_CTX_UNKNOWN; }

    // perhaps more intuitive short-cut
    inline int GetType() { return GetContextType(); }

    // cast this context to the desired type - returns NULL if type is wrong
    spAttribute *CastToAttribute()
    {
        return GetContextType() == SP_CTX_ATTRIBUTE ? (spAttribute *)this
                                                    : NULL;
    }

    // derived classes override this to invoke VisitXXX method
    // which corresponds to the class of specific context,
    // - this is what the "Visitor" pattern told us ^)

    // if method is not overriden, then it's probably user-defined
    // custom context

    virtual void AcceptVisitor( spVisitor& visitor )

        { visitor.VisitCustomContext( *this );    };

    // called by visitors, to remove given subcontext
    // of this context object
    void RemoveChild( spContext* pChild );

    void RemoveChildren();

    spContext* GetEnclosingContext( int mask = SP_CTX_ANY );

#ifdef __WXDEBUG__
    virtual void Dump(const wxString& indent) const;
#endif  // __WXDEBUG__

    DECLARE_DUMP
};

// stores information about single argument of operation

class spParameter : public spContext
{
public:
    // type of argument (parameter)
    wxString m_Type;

    // "stringified" initial value
    wxString m_InitVal;

public:
    virtual int GetContextType() const { return SP_CTX_PARAMETER; }

    virtual void AcceptVisitor( spVisitor& visitor )
        { visitor.VisitParameter( *this ); }

    DECLARE_DUMP
};


// stores information about member(or global) variable

class spAttribute : public spContext
{
public:
    // type of the attribute
    wxString m_Type;

    // it's initial value
    wxString m_InitVal;

    // constantness
    bool   mIsConstant;
public:

    virtual int GetContextType() const { return SP_CTX_ATTRIBUTE; }

    virtual void AcceptVisitor( spVisitor& visitor )
        { visitor.VisitAttribute( *this ); }

    DECLARE_DUMP
};

class spOperation : public spContext
{
public:
    // type of return value
    wxString    m_RetType;

    // argument list
    //MParamListT mParams;

    // true, if operation does not modify
    // the content of the object
    bool        mIsConstant;

    // flag, specific to C++
    bool        mIsVirtual;

    // true, if definition follows the declaration immediatelly
    bool        mHasDefinition;

    // scope if any (e.g. MyClass::MyFunction(), scope stirng is "MyClass" )
    // usually found along with implementation of the method, which is now skipped

    wxString    mScope;

public:
    spOperation();

    // returns full declaration of the operations
    // (ret val., identifier, arg. list),

    // arguments are marked up with italic,
    // default values marked up with bold-italic,
    // all the rest is marked as bold

    // NOTE:: this method may be overriden by class
    //        specific to concrete parser, to provide
    //        language-dependent reperesnetation of
    //        operation and it's argumetn list
    //
    // the default implementation outputs name in
    // C++/Java syntax

    virtual wxString GetFullName(MarkupTagsT tags);

    virtual int GetContextType() const { return SP_CTX_OPERATION; }

    virtual void AcceptVisitor( spVisitor& visitor )
        { visitor.VisitOperation( *this ); }

    DECLARE_DUMP
};

// stores infromation about preprocessor directive

class spPreprocessorLine : public spContext
{

public:

    // prepocessor statement including '#' and
    // attached multiple lines with '\' character
    wxString m_Line;

    int    mDefType; // see SP_PREP_DEFINITION_TYPES enumeration

public:

    virtual int GetContextType() const { return SP_CTX_PREPROCESSOR; }

    virtual int GetStatementType() const { return mDefType; }

    wxString CPP_GetIncludedFileNeme() const;

    virtual void AcceptVisitor( spVisitor& visitor )
        { visitor.VisitPreprocessorLine( *this ); }

    DECLARE_DUMP
};

// stores information about the class

class spClass : public spContext
{
public:
    // list of superclasses/interfaces
    StrListT     m_SuperClassNames;

    // see SP_CLASS_TYPES enumeration
    int          mClassSubType;

    // see SP_INHERITANCE_TYPES enumeration
    int          mInheritanceType;

    // valid if mClassSubType is SP_CLTYPE_TEMPLATE_CLASS
    wxString     mTemplateTypes;

    // true, if it's and interface of abstract base class
    bool         mIsAbstract;

public:
    // sorts class members in the following order:
    //
    // (by "privacy level" - first private, than protected, public)
    //
    //     within above set
    //
    //       (by member type - attributes first, than methods, nested classes)
    //
    //          within above set
    //
    //             (by identifier of the member)

    virtual void SortMembers();

    virtual int GetContextType() const { return SP_CTX_CLASS; }

    virtual void AcceptVisitor( spVisitor& visitor )
        { visitor.VisitClass( *this ); }

    DECLARE_DUMP
};

// stores information about enum statement

class spEnumeration  : public spContext
{
public:
    wxString m_EnumContent; // full-text content of enumeration

public:
    virtual int GetContextType() const { return SP_CTX_ENUMERATION; }

    virtual void AcceptVisitor( spVisitor& visitor )
        { visitor.VisitEnumeration( *this ); }

    DECLARE_DUMP
};

class spTypeDef  : public spContext
{
public:
    // the original type which is redefined
    // by this type definition
    wxString m_OriginalType;

public:
    virtual int GetContextType() const { return SP_CTX_TYPEDEF; }

    virtual void AcceptVisitor( spVisitor& visitor )
        { visitor.VisitTypeDef( *this ); }

    DECLARE_DUMP
};

// NOTE:: files context may be put to other
//        file context, resulting in a collection
//        of parsed file contexts, with a virtual "superfile"

class spFile : public spContext
{
public:
    // since file name cannot be determined from
    // source code, filling in this field is optional
    wxString m_FileName;

public:
    virtual int GetContextType() const { return SP_CTX_FILE; }

    virtual void AcceptVisitor( spVisitor& visitor )
        { visitor.VisitFile( *this ); }

    DECLARE_DUMP
};

//TODO:: comments.

class SourceParserPlugin
{
public:
    virtual bool CanUnderstandContext( char* cur, char* end, spContext* pOuttterCtx ) = 0;
    virtual void ParseContext( char* start, char*& cur, char* end, spContext* pOuttterCtx ) = 0;
};

// abstract interface for source parsers
// which can output parsing results in the
// form of context-tree, where each node
// should be derivative of spContext, (see
// above classes)

class SourceParserBase
{
private:
    // auto-resizing file buffer, created in ParseFile()
    // to reuse large heap block for multiple parsings

    char* mpFileBuf;
    int   mFileBufSz;

protected:
    SourceParserPlugin* mpPlugin;

protected:
    // value is set in the derived parser classes
    int mParserStatus;

public:
    SourceParserBase();
    virtual ~SourceParserBase();

    // loads entier source file(as text) into memory,
    // and passes it's contents to ParseAll() method,
    // memory occupied by source text is released after
    // parsing is done
    //
    // (NOTE:: this is the default implementation),

    virtual spFile* ParseFile( const char* fname );

    // should returns the root-node of the created context tree
    // (user is responsible for releasing it from the heep)
    // "end" should point to the (last character + 1) of the
    // source text area

    virtual spFile* Parse( char* start, char* end ) = 0;

    // returns parser "status word" (specific to concrete parser)
    int GetParserStatus() { return mParserStatus; }

    void SetPlugin( SourceParserPlugin* pPlugin );
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -