TDocParser.h

Go to the documentation of this file.
00001 // @(#)root/html:$Id: TDocParser.h 35685 2010-09-23 17:12:07Z axel $
00002 // Author: Axel Naumann 2007-01-09
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TDocParser
00013 #define ROOT_TDocParser
00014 
00015 ////////////////////////////////////////////////////////////////////////////
00016 //                                                                        //
00017 // TDocParser                                                             //
00018 //                                                                        //
00019 // Parses documentation in source files                                   //
00020 //                                                                        //
00021 ////////////////////////////////////////////////////////////////////////////
00022 
00023 #include <list>
00024 #include <set>
00025 #include <map>
00026 
00027 #ifndef ROOT_TObject
00028 #include "TObject.h"
00029 #endif
00030 #ifndef ROOT_THashList
00031 #include "THashList.h"
00032 #endif
00033 #ifndef ROOT_TString
00034 #include "TString.h"
00035 #endif
00036 #ifndef ROOT_Riosfwd
00037 #include "Riosfwd.h"
00038 #endif
00039 
00040 class TBaseClass;
00041 class TClass;
00042 class TClassDocOutput;
00043 class TDocOutput;
00044 class THtml;
00045 
00046 class TDocMethodWrapper: public TObject {
00047 public:
00048    virtual TMethod* GetMethod() const = 0;
00049    virtual Int_t GetOverloadIdx() const = 0;
00050    enum { kDocumented = 14 };
00051 };
00052 
00053 class TDocParser: public TObject {
00054 protected:
00055    enum EDocContext {
00056       kIgnore,
00057       kDocFunc,
00058       kDocClass,
00059       kNumDocContexts
00060    };
00061 
00062 public:
00063    enum ESourceInfo {
00064       kInfoLastUpdate,
00065       kInfoAuthor,
00066       kInfoCopyright,
00067       kInfoLastChanged,
00068       kInfoLastGenerated,
00069       kNumSourceInfos
00070    };
00071    enum EAccess {
00072       kPrivate,
00073       kProtected,
00074       kPublic
00075    };
00076    enum EParseContext {
00077       kNoContext,
00078       kCode,
00079       kComment,
00080       kDirective,
00081       kString,
00082       kKeyword,
00083       kCPP,
00084       kVerbatim,
00085       kNumParseContexts,
00086       kParseContextMask = BIT(4) - 1
00087    };
00088    enum EParseContextFlag {
00089       kCXXComment = BIT(4), // kComment is a C++ comment, or macro/html/latex content is surrounded by /* */
00090       kParseContextFlagMask = (UInt_t)(~(BIT(4) - 1))
00091 
00092    };
00093 
00094 protected:
00095    THtml*         fHtml;            // THtml object using us
00096    TDocOutput*    fDocOutput;       // TDocOutput invoking us
00097    UInt_t         fLineNo;          // current line number
00098    TString        fLineRaw;         // current line
00099    TString        fLineStripped;    // current line without surrounding spaces
00100    TString        fLineComment;         // current line with links and directives for doc
00101    TString        fLineSource;      // current line with links
00102    TString        fComment;         // current comment
00103    TString        fFirstClassDoc;   // first class-doc found - per file, taken if fLastClassDoc is empty
00104    TString        fLastClassDoc;    // last class-doc found - becomes class doc at ClassImp or first method
00105    TClass*        fCurrentClass;    // current class context of sources being parsed
00106    TClass*        fRecentClass;     // recently seen class context of sources being parsed, e.g. for Convert()
00107    TString        fCurrentModule;   // current module context of sources being parsed
00108    TString        fCurrentMethodTag;// name_idx of the currently parsed method
00109    Int_t          fDirectiveCount;  // index of directive for current method
00110    Long_t         fLineNumber;      // source line number
00111    TString        fCurrentFile;     // current source / header file name
00112    std::map<std::string /*name*/, Int_t > fMethodCounts;     // number of undocumented overloads
00113    EDocContext    fDocContext;      // current context of parsed sources for documenting
00114    std::list<UInt_t> fParseContext; // current context of parsed sources
00115    Bool_t         fCheckForMethod;  // whether to check the current line for a method
00116    enum {
00117       kClassDoc_Uninitialized,
00118       kClassDoc_LookingNothingFound,
00119       kClassDoc_LookingHaveSomething,
00120       kClassDoc_Written,
00121       kClassDoc_Ignore,
00122       kClassDoc_NumStates
00123    }              fClassDocState; // whether we found the class description
00124    Bool_t         fCommentAtBOL;    // at the beginning of the current line, fParseContext contained kComment
00125    TString        fClassDescrTag;   // tag for finding the class description
00126    TString        fSourceInfoTags[kNumSourceInfos]; // tags for source info elements (copyright, last changed, author)
00127    TList          fDirectiveHandlers;// handler for doc directives (TDocDirective objects)
00128    Bool_t         fAllowDirectives;  // whether directives are to be interpreted
00129    std::set<UInt_t> fExtraLinesWithAnchor; // lines that need an additional anchor
00130    TString        fSourceInfo[kNumSourceInfos];// author, last changed, ...
00131    THashList      fMethods[3];      // methods as TMethodWrapper objects (by access)
00132    TList          fDataMembers[6];  // data members (by access, plus enums)
00133 
00134    static std::set<std::string>  fgKeywords; // C++ keywords
00135 
00136    void           AddClassMethodsRecursively(TBaseClass* bc);
00137    void           AddClassDataMembersRecursively(TBaseClass* bc);
00138    EParseContext  Context() const { return fParseContext.empty() ? kComment : (EParseContext)(fParseContext.back() & kParseContextMask); }
00139    virtual void   ExpandCPPLine(TString& line, Ssiz_t& pos);
00140    virtual Bool_t HandleDirective(TString& keyword, Ssiz_t& pos, 
00141       TString& word, Ssiz_t& copiedToCommentUpTo);
00142    virtual void   InitKeywords() const;
00143    virtual TClass* IsDirective(const TString& line, Ssiz_t pos, const TString& word, Bool_t& begin) const;
00144    TMethod*       LocateMethodInCurrentLine(Ssiz_t& posMethodName, TString& ret, 
00145       TString& name, TString& params, Bool_t& isconst,
00146       std::ostream &srcOut, TString &anchor, 
00147       std::ifstream& sourcefile, Bool_t allowPureVirtual);
00148    void           LocateMethodsInSource(std::ostream& out);
00149    void           LocateMethodsInHeaderInline(std::ostream& out);
00150    void           LocateMethodsInHeaderClassDecl(std::ostream& out);
00151    void           LocateMethods(std::ostream& out, const char* filename,
00152                                 Bool_t lookForSourceInfo = kTRUE, 
00153                                 Bool_t useDocxxStyle = kFALSE, 
00154                                 Bool_t allowPureVirtual = kFALSE,
00155                                 const char* methodPattern = 0, 
00156                                 const char* sourceExt = 0);
00157    virtual Bool_t ProcessComment();
00158    void           RemoveCommentContext(Bool_t cxxcomment);
00159    void           WriteClassDoc(std::ostream& out, Bool_t first = kTRUE);
00160    void           WriteMethod(std::ostream& out, TString& ret, 
00161                               TString& name, TString& params,
00162                               Bool_t isconst,
00163                               const char* file, TString& anchor,
00164                               TString& codeOneLiner);
00165    void           WriteSourceLine(std::ostream& out);
00166 
00167 public:
00168    TDocParser(TClassDocOutput& docOutput, TClass* cl);
00169    TDocParser(TDocOutput& docOutput);
00170    virtual       ~TDocParser();
00171 
00172    static void   AnchorFromLine(const TString& line, TString& anchor);
00173    void          Convert(std::ostream& out, std::istream& in, const char* relpath,
00174                          Bool_t isCode, Bool_t interpretDirectives);
00175    void          DecrementMethodCount(const char* name);
00176    virtual void  DecorateKeywords(std::ostream& out, const char* text);
00177    virtual void  DecorateKeywords(TString& text);
00178    virtual void  DeleteDirectiveOutput() const;
00179    const TList*  GetMethods(EAccess access) const { return &fMethods[access]; }
00180    TClass*       GetCurrentClass() const { return fCurrentClass; }
00181    void          GetCurrentModule(TString& out_module) const;
00182    TDocOutput*   GetDocOutput() const { return fDocOutput; }
00183    Long_t        GetLineNumber() const { return fLineNumber; }
00184    const TList*  GetDataMembers(EAccess access) const { return &fDataMembers[access]; }
00185    const TList*  GetEnums(EAccess access) const { return &fDataMembers[access+3]; }
00186    const char*   GetSourceInfo(ESourceInfo type) const { return fSourceInfo[type]; }
00187    void          SetCurrentModule(const char* module) { fCurrentModule = module; }
00188 
00189    UInt_t        InContext(Int_t context) const;
00190    static Bool_t IsName(UChar_t c);
00191    static Bool_t IsWord(UChar_t c);
00192 
00193    virtual void  Parse(std::ostream& out);
00194    static Bool_t Strip(TString& s);
00195 
00196    ClassDef(TDocParser,0); // parser for reference documentation
00197 };
00198 
00199 #endif // ROOT_TDocParser

Generated on Tue Jul 5 14:24:42 2011 for ROOT_528-00b_version by  doxygen 1.5.1