Blame src/definition.h

Packit 1c1d7e
/******************************************************************************
Packit 1c1d7e
 *
Packit 1c1d7e
 * 
Packit 1c1d7e
 *
Packit 1c1d7e
 * Copyright (C) 1997-2015 by Dimitri van Heesch.
Packit 1c1d7e
 *
Packit 1c1d7e
 * Permission to use, copy, modify, and distribute this software and its
Packit 1c1d7e
 * documentation under the terms of the GNU General Public License is hereby 
Packit 1c1d7e
 * granted. No representations are made about the suitability of this software 
Packit 1c1d7e
 * for any purpose. It is provided "as is" without express or implied warranty.
Packit 1c1d7e
 * See the GNU General Public License for more details.
Packit 1c1d7e
 *
Packit 1c1d7e
 * Documents produced by Doxygen are derivative works derived from the
Packit 1c1d7e
 * input used in their production; they are not affected by this license.
Packit 1c1d7e
 *
Packit 1c1d7e
 */
Packit 1c1d7e
Packit 1c1d7e
#ifndef DEFINITION_H
Packit 1c1d7e
#define DEFINITION_H
Packit 1c1d7e
Packit 1c1d7e
#include <qlist.h>
Packit 1c1d7e
#include <qdict.h>
Packit 1c1d7e
Packit 1c1d7e
#include "types.h"
Packit 1c1d7e
Packit 1c1d7e
class FileDef;
Packit 1c1d7e
class OutputList;
Packit 1c1d7e
class SectionDict;
Packit 1c1d7e
class MemberSDict;
Packit 1c1d7e
class MemberDef;
Packit 1c1d7e
class GroupDef;
Packit 1c1d7e
class GroupList;
Packit 1c1d7e
struct ListItemInfo;
Packit 1c1d7e
struct SectionInfo;
Packit 1c1d7e
class Definition;
Packit 1c1d7e
class DefinitionImpl;
Packit 1c1d7e
class FTextStream;
Packit 1c1d7e
  
Packit 1c1d7e
/** Data associated with a detailed description. */
Packit 1c1d7e
struct DocInfo
Packit 1c1d7e
{
Packit 1c1d7e
    QCString doc;  
Packit 1c1d7e
    int      line;
Packit 1c1d7e
    QCString file;
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
/** Data associated with a brief description. */
Packit 1c1d7e
struct BriefInfo
Packit 1c1d7e
{
Packit 1c1d7e
    QCString doc;  
Packit 1c1d7e
    QCString tooltip;  
Packit 1c1d7e
    int      line;
Packit 1c1d7e
    QCString file;
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
/** Data associated with description found in the body. */
Packit 1c1d7e
struct BodyInfo
Packit 1c1d7e
{
Packit 1c1d7e
    int      startLine;   //!< line number of the start of the definition
Packit 1c1d7e
    int      endLine;     //!< line number of the end of the definition
Packit 1c1d7e
    FileDef *fileDef;     //!< file definition containing the function body
Packit 1c1d7e
};
Packit 1c1d7e
    
Packit 1c1d7e
/** Abstract interface for a Definition or DefinitionList */
Packit 1c1d7e
class DefinitionIntf
Packit 1c1d7e
{
Packit 1c1d7e
  public:
Packit 1c1d7e
    DefinitionIntf() {}
Packit 1c1d7e
    virtual ~DefinitionIntf() {}
Packit 1c1d7e
    /*! Types of derived classes */
Packit 1c1d7e
    enum DefType 
Packit 1c1d7e
    { 
Packit 1c1d7e
      TypeClass      = 0, 
Packit 1c1d7e
      TypeFile       = 1, 
Packit 1c1d7e
      TypeNamespace  = 2, 
Packit 1c1d7e
      TypeMember     = 3, 
Packit 1c1d7e
      TypeGroup      = 4, 
Packit 1c1d7e
      TypePackage    = 5, 
Packit 1c1d7e
      TypePage       = 6, 
Packit 1c1d7e
      TypeDir        = 7, 
Packit 1c1d7e
      TypeSymbolList = 8
Packit 1c1d7e
    };
Packit 1c1d7e
    /*! Use this for dynamic inspection of the type of the derived class */
Packit 1c1d7e
    virtual DefType definitionType() const = 0;
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
/** The common base class of all entity definitions found in the sources. 
Packit 1c1d7e
 *
Packit 1c1d7e
 *  This can be a class or a member function, or a file, or a namespace, etc.
Packit 1c1d7e
 *  Use definitionType() to find which type of definition this is.
Packit 1c1d7e
 */
Packit 1c1d7e
class Definition : public DefinitionIntf
Packit 1c1d7e
{
Packit 1c1d7e
  public:
Packit 1c1d7e
    struct Cookie
Packit 1c1d7e
    {
Packit 1c1d7e
      virtual ~Cookie() {}
Packit 1c1d7e
    };
Packit 1c1d7e
Packit 1c1d7e
    /*! Create a new definition */
Packit 1c1d7e
    Definition(
Packit 1c1d7e
        const char *defFileName,int defLine,int defColumn,
Packit 1c1d7e
        const char *name,const char *b=0,const char *d=0,
Packit 1c1d7e
        bool isSymbol=TRUE);
Packit 1c1d7e
Packit 1c1d7e
    /*! Destroys the definition */
Packit 1c1d7e
    virtual ~Definition();
Packit 1c1d7e
Packit 1c1d7e
    //-----------------------------------------------------------------------------------
Packit 1c1d7e
    // ----  getters -----
Packit 1c1d7e
    //-----------------------------------------------------------------------------------
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the name of the definition */
Packit 1c1d7e
    const QCString& name() const { return m_name; }
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the name of the definition as it appears in the output */
Packit 1c1d7e
    virtual QCString displayName(bool includeScope=TRUE) const = 0;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the local name without any scope qualifiers. */
Packit 1c1d7e
    QCString localName() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the fully qualified name of this definition
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual QCString qualifiedName() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the name of this definition as it appears in the symbol map.
Packit 1c1d7e
     */
Packit 1c1d7e
    QCString symbolName() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the base file name (without extension) of this definition.
Packit 1c1d7e
     *  as it is referenced to/written to disk.
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual QCString getOutputFileBase() const = 0;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the anchor within a page where this item can be found */
Packit 1c1d7e
    virtual QCString anchor() const = 0;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the name of the source listing of this definition. */
Packit 1c1d7e
    virtual QCString getSourceFileBase() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the anchor of the source listing of this definition. */
Packit 1c1d7e
    virtual QCString getSourceAnchor() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the detailed description of this definition */
Packit 1c1d7e
    virtual QCString documentation() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the line number at which the detailed documentation was found. */
Packit 1c1d7e
    int docLine() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the file in which the detailed documentation block was found.
Packit 1c1d7e
     *  This can differ from getDefFileName().
Packit 1c1d7e
     */
Packit 1c1d7e
    QCString docFile() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the brief description of this definition. This can include commands. */
Packit 1c1d7e
    virtual QCString briefDescription(bool abbreviate=FALSE) const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns a plain text version of the brief description suitable for use
Packit 1c1d7e
     *  as a tool tip. 
Packit 1c1d7e
     */
Packit 1c1d7e
    QCString briefDescriptionAsTooltip() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the line number at which the brief description was found. */
Packit 1c1d7e
    int briefLine() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the documentation found inside the body of a member */
Packit 1c1d7e
    QCString inbodyDocumentation() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the file in which the in body documentation was found */
Packit 1c1d7e
    QCString inbodyFile() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the line at which the first in body documentation 
Packit 1c1d7e
        part was found */
Packit 1c1d7e
    int inbodyLine() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the file in which the brief description was found. 
Packit 1c1d7e
     *  This can differ from getDefFileName().
Packit 1c1d7e
     */
Packit 1c1d7e
    QCString briefFile() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! returns the file in which this definition was found */
Packit 1c1d7e
    QCString getDefFileName() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! returns the extension of the file in which this definition was found */
Packit 1c1d7e
    QCString getDefFileExtension() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! returns the line number at which the definition was found */
Packit 1c1d7e
    int getDefLine() const { return m_defLine; }
Packit 1c1d7e
Packit 1c1d7e
    /*! returns the column number at which the definition was found */
Packit 1c1d7e
    int getDefColumn() const { return m_defColumn; }
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns TRUE iff the definition is documented 
Packit 1c1d7e
     *  (which could be generated documentation) 
Packit 1c1d7e
     *  @see hasUserDocumentation()
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual bool hasDocumentation() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns TRUE iff the definition is documented by the user. */
Packit 1c1d7e
    virtual bool hasUserDocumentation() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns TRUE iff it is possible to link to this item within this
Packit 1c1d7e
     *  project. 
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual bool isLinkableInProject() const = 0;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns TRUE iff it is possible to link to this item. This can
Packit 1c1d7e
     *  be a link to another project imported via a tag file. 
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual bool isLinkable() const = 0;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns TRUE iff the name is part of this project and 
Packit 1c1d7e
     *  may appear in the output 
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual bool isVisibleInProject() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns TRUE iff the name may appear in the output */
Packit 1c1d7e
    virtual bool isVisible() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns TRUE iff this item is supposed to be hidden from the output. */
Packit 1c1d7e
    bool isHidden() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! returns TRUE if this entity was artificially introduced, for 
Packit 1c1d7e
     *  instance because it is used to show a template instantiation relation. 
Packit 1c1d7e
     */
Packit 1c1d7e
    bool isArtificial() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! If this definition was imported via a tag file, this function
Packit 1c1d7e
     *  returns the tagfile for the external project. This can be
Packit 1c1d7e
     *  translated into an external link target via 
Packit 1c1d7e
     *  Doxygen::tagDestinationDict
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual QCString getReference() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns TRUE if this definition is imported via a tag file. */
Packit 1c1d7e
    virtual bool isReference() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Convenience method to return a resolved external link */
Packit 1c1d7e
    QCString externalReference(const QCString &relPath) const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the first line of the body of this item (applicable to classes and 
Packit 1c1d7e
     *  functions).
Packit 1c1d7e
     */
Packit 1c1d7e
    int getStartBodyLine() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the last line of the body of this item (applicable to classes and 
Packit 1c1d7e
     *  functions).
Packit 1c1d7e
     */
Packit 1c1d7e
    int getEndBodyLine() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Returns the file in which the body of this item is located or 0 if no
Packit 1c1d7e
     *  body is available.
Packit 1c1d7e
     */
Packit 1c1d7e
    FileDef *getBodyDef() const;
Packit 1c1d7e
Packit 1c1d7e
    /** Returns the programming language this definition was written in. */
Packit 1c1d7e
    SrcLangExt getLanguage() const;
Packit 1c1d7e
Packit 1c1d7e
    GroupList *partOfGroups() const;
Packit 1c1d7e
    bool isLinkableViaGroup() const;
Packit 1c1d7e
Packit 1c1d7e
    QList<ListItemInfo> *xrefListItems() const;
Packit 1c1d7e
Packit 1c1d7e
    virtual Definition *findInnerCompound(const char *name) const ;
Packit 1c1d7e
    virtual Definition *getOuterScope() const;
Packit 1c1d7e
Packit 1c1d7e
    MemberSDict *getReferencesMembers() const;
Packit 1c1d7e
    MemberSDict *getReferencedByMembers() const;
Packit 1c1d7e
Packit 1c1d7e
    bool hasSections() const;
Packit 1c1d7e
    bool hasSources() const;
Packit 1c1d7e
Packit 1c1d7e
    /** returns TRUE if this class has a brief description */
Packit 1c1d7e
    bool hasBriefDescription() const;
Packit 1c1d7e
Packit 1c1d7e
    QCString id() const;
Packit 1c1d7e
Packit 1c1d7e
    //-----------------------------------------------------------------------------------
Packit 1c1d7e
    // ----  setters -----
Packit 1c1d7e
    //-----------------------------------------------------------------------------------
Packit 1c1d7e
Packit 1c1d7e
    /*! Sets a new \a name for the definition */
Packit 1c1d7e
    virtual void setName(const char *name);
Packit 1c1d7e
Packit 1c1d7e
    /*! Sets a unique id for the symbol. Used for libclang integration. */
Packit 1c1d7e
    void setId(const char *name);
Packit 1c1d7e
Packit 1c1d7e
    /*! Sets the documentation of this definition to \a d. */
Packit 1c1d7e
    virtual void setDocumentation(const char *d,const char *docFile,int docLine,bool stripWhiteSpace=TRUE);
Packit 1c1d7e
Packit 1c1d7e
    /*! Sets the brief description of this definition to \a b.
Packit 1c1d7e
     *  A dot is added to the sentence if not available.
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual void setBriefDescription(const char *b,const char *briefFile,int briefLine);
Packit 1c1d7e
Packit 1c1d7e
    /*! Set the documentation that was found inside the body of an item.
Packit 1c1d7e
     *  If there was already some documentation set, the new documentation
Packit 1c1d7e
     *  will be appended.
Packit 1c1d7e
     */
Packit 1c1d7e
    virtual void setInbodyDocumentation(const char *d,const char *docFile,int docLine);
Packit 1c1d7e
Packit 1c1d7e
    /*! Sets the tag file id via which this definition was imported. */
Packit 1c1d7e
    void setReference(const char *r);
Packit 1c1d7e
Packit 1c1d7e
    /*! Add the list of anchors that mark the sections that are found in the 
Packit 1c1d7e
     * documentation.
Packit 1c1d7e
     */
Packit 1c1d7e
    void addSectionsToDefinition(QList<SectionInfo> *anchorList);
Packit 1c1d7e
Packit 1c1d7e
    // source references
Packit 1c1d7e
    void setBodySegment(int bls,int ble);
Packit 1c1d7e
    void setBodyDef(FileDef *fd);
Packit 1c1d7e
    void addSourceReferencedBy(MemberDef *d);
Packit 1c1d7e
    void addSourceReferences(MemberDef *d);
Packit 1c1d7e
Packit 1c1d7e
    void setRefItems(const QList<ListItemInfo> *sli);
Packit 1c1d7e
    void mergeRefItems(Definition *d);
Packit 1c1d7e
    virtual void addInnerCompound(Definition *d);
Packit 1c1d7e
    virtual void setOuterScope(Definition *d);
Packit 1c1d7e
Packit 1c1d7e
    virtual void setHidden(bool b);
Packit 1c1d7e
Packit 1c1d7e
    void setArtificial(bool b);
Packit 1c1d7e
    void setLanguage(SrcLangExt lang);
Packit 1c1d7e
Packit 1c1d7e
    //-----------------------------------------------------------------------------------
Packit 1c1d7e
    // --- actions ----
Packit 1c1d7e
    //-----------------------------------------------------------------------------------
Packit 1c1d7e
Packit 1c1d7e
    void writeSourceDef(OutputList &ol,const char *scopeName);
Packit 1c1d7e
    void writeInlineCode(OutputList &ol,const char *scopeName);
Packit 1c1d7e
    void writeSourceRefs(OutputList &ol,const char *scopeName);
Packit 1c1d7e
    void writeSourceReffedBy(OutputList &ol,const char *scopeName);
Packit 1c1d7e
    void makePartOfGroup(GroupDef *gd);
Packit 1c1d7e
    //void writePathFragment(OutputList &ol) const;
Packit 1c1d7e
    void writeNavigationPath(OutputList &ol) const;
Packit 1c1d7e
    QCString navigationPathAsString() const;
Packit 1c1d7e
    virtual void writeQuickMemberLinks(OutputList &,MemberDef *) const {}
Packit 1c1d7e
    virtual void writeSummaryLinks(OutputList &) {}
Packit 1c1d7e
    QCString pathFragment() const;
Packit 1c1d7e
Packit 1c1d7e
    /*! Writes the documentation anchors of the definition to 
Packit 1c1d7e
     *  the Doxygen::tagFile stream.
Packit 1c1d7e
     */
Packit 1c1d7e
    void writeDocAnchorsToTagFile(FTextStream &);
Packit 1c1d7e
    void setLocalName(const QCString name);
Packit 1c1d7e
Packit 1c1d7e
    void addSectionsToIndex();
Packit 1c1d7e
    void writeToc(OutputList &ol);
Packit 1c1d7e
Packit 1c1d7e
    void setCookie(Cookie *cookie) { delete m_cookie; m_cookie = cookie; }
Packit 1c1d7e
    Cookie *cookie() const { return m_cookie; }
Packit 1c1d7e
Packit 1c1d7e
  protected:
Packit 1c1d7e
Packit 1c1d7e
    Definition(const Definition &d);
Packit 1c1d7e
Packit 1c1d7e
  private: 
Packit 1c1d7e
    static void addToMap(const char *name,Definition *d);
Packit 1c1d7e
    static void removeFromMap(Definition *d);
Packit 1c1d7e
Packit 1c1d7e
    void _setSymbolName(const QCString &name);
Packit 1c1d7e
Packit 1c1d7e
    int  _getXRefListId(const char *listName) const;
Packit 1c1d7e
    void _writeSourceRefList(OutputList &ol,const char *scopeName,
Packit 1c1d7e
                       const QCString &text,MemberSDict *members,bool);
Packit 1c1d7e
    void _setBriefDescription(const char *b,const char *briefFile,int briefLine);
Packit 1c1d7e
    void _setDocumentation(const char *d,const char *docFile,int docLine,bool stripWhiteSpace,bool atTop);
Packit 1c1d7e
    void _setInbodyDocumentation(const char *d,const char *docFile,int docLine);
Packit 1c1d7e
    bool _docsAlreadyAdded(const QCString &doc,QCString &sigList);
Packit 1c1d7e
    DefinitionImpl *m_impl; // internal structure holding all private data
Packit 1c1d7e
    QCString m_name;
Packit 1c1d7e
    bool m_isSymbol;
Packit 1c1d7e
    QCString m_symbolName;
Packit 1c1d7e
    int m_defLine;
Packit 1c1d7e
    int m_defColumn;
Packit 1c1d7e
    Cookie *m_cookie;
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
/** A list of Definition objects. */
Packit 1c1d7e
class DefinitionList : public QList<Definition>, public DefinitionIntf
Packit 1c1d7e
{
Packit 1c1d7e
  public:
Packit 1c1d7e
    ~DefinitionList() {}
Packit 1c1d7e
    DefType definitionType() const { return TypeSymbolList; }
Packit 1c1d7e
    int compareValues(const Definition *item1,const Definition *item2) const
Packit 1c1d7e
    {
Packit 1c1d7e
      return qstricmp(item1->name(),item2->name());
Packit 1c1d7e
    }
Packit 1c1d7e
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
/** An iterator for Definition objects in a DefinitionList. */
Packit 1c1d7e
class DefinitionListIterator : public QListIterator<Definition>
Packit 1c1d7e
{
Packit 1c1d7e
  public:
Packit 1c1d7e
    DefinitionListIterator(const DefinitionList &l) :
Packit 1c1d7e
      QListIterator<Definition>(l) {}
Packit 1c1d7e
    ~DefinitionListIterator() {}
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
/** Reads a fragment from file \a fileName starting with line \a startLine
Packit 1c1d7e
 *  and ending with line \a endLine. The result is returned as a string 
Packit 1c1d7e
 *  via \a result. The function returns TRUE if successful and FALSE 
Packit 1c1d7e
 *  in case of an error.
Packit 1c1d7e
 */
Packit 1c1d7e
bool readCodeFragment(const char *fileName, 
Packit 1c1d7e
                      int &startLine,int &endLine,
Packit 1c1d7e
                      QCString &result);
Packit 1c1d7e
#endif