Logo ROOT   6.16/01
Reference Guide
TDocParser.h
Go to the documentation of this file.
1// @(#)root/html:$Id$
2// Author: Axel Naumann 2007-01-09
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TDocParser
13#define ROOT_TDocParser
14
15////////////////////////////////////////////////////////////////////////////
16// //
17// TDocParser //
18// //
19// Parses documentation in source files //
20// //
21////////////////////////////////////////////////////////////////////////////
22
23#include <list>
24#include <set>
25#include <map>
26
27#include "TObject.h"
28#include "THashList.h"
29#include "TString.h"
30
31class TBaseClass;
32class TClass;
33class TClassDocOutput;
34class TDocOutput;
35class THtml;
36
38public:
39 virtual TMethod* GetMethod() const = 0;
40 virtual Int_t GetOverloadIdx() const = 0;
41 enum { kDocumented = 14 };
42};
43
44class TDocParser: public TObject {
45protected:
51 };
52
53public:
61 };
62 enum EAccess {
66 };
77 kParseContextMask = BIT(4) - 1
78 };
80 kCXXComment = BIT(4), // kComment is a C++ comment, or macro/html/latex content is surrounded by /* */
81 kParseContextFlagMask = (UInt_t)(~(BIT(4) - 1))
82
83 };
84
85protected:
86 THtml* fHtml; // THtml object using us
87 TDocOutput* fDocOutput; // TDocOutput invoking us
88 UInt_t fLineNo; // current line number
89 TString fLineRaw; // current line
90 TString fLineStripped; // current line without surrounding spaces
91 TString fLineComment; // current line with links and directives for doc
92 TString fLineSource; // current line with links
93 TString fComment; // current comment
94 TString fFirstClassDoc; // first class-doc found - per file, taken if fLastClassDoc is empty
95 TString fLastClassDoc; // last class-doc found - becomes class doc at ClassImp or first method
96 TClass* fCurrentClass; // current class context of sources being parsed
97 TClass* fRecentClass; // recently seen class context of sources being parsed, e.g. for Convert()
98 TString fCurrentModule; // current module context of sources being parsed
99 TString fCurrentMethodTag;// name_idx of the currently parsed method
100 Int_t fDirectiveCount; // index of directive for current method
101 Long_t fLineNumber; // source line number
102 TString fCurrentFile; // current source / header file name
103 std::map<std::string /*name*/, Int_t > fMethodCounts; // number of undocumented overloads
104 EDocContext fDocContext; // current context of parsed sources for documenting
105 std::list<UInt_t> fParseContext; // current context of parsed sources
106 Bool_t fCheckForMethod; // whether to check the current line for a method
107 enum {
114 } fClassDocState; // whether we found the class description
115 Bool_t fCommentAtBOL; // at the beginning of the current line, fParseContext contained kComment
116 TString fClassDescrTag; // tag for finding the class description
117 TString fSourceInfoTags[kNumSourceInfos]; // tags for source info elements (copyright, last changed, author)
118 TList fDirectiveHandlers;// handler for doc directives (TDocDirective objects)
119 Bool_t fAllowDirectives; // whether directives are to be interpreted
120 std::set<UInt_t> fExtraLinesWithAnchor; // lines that need an additional anchor
121 TString fSourceInfo[kNumSourceInfos];// author, last changed, ...
122 THashList fMethods[3]; // methods as TMethodWrapper objects (by access)
123 TList fDataMembers[6]; // data members (by access, plus enums)
124
125 static std::set<std::string> fgKeywords; // C++ keywords
126
130 virtual void ExpandCPPLine(TString& line, Ssiz_t& pos);
131 virtual Bool_t HandleDirective(TString& keyword, Ssiz_t& pos,
132 TString& word, Ssiz_t& copiedToCommentUpTo);
133 virtual void InitKeywords() const;
134 virtual TClass* IsDirective(const TString& line, Ssiz_t pos, const TString& word, Bool_t& begin) const;
135 TMethod* LocateMethodInCurrentLine(Ssiz_t& posMethodName, TString& ret,
136 TString& name, TString& params, Bool_t& isconst,
137 std::ostream &srcOut, TString &anchor,
138 std::ifstream& sourcefile, Bool_t allowPureVirtual);
139 void LocateMethodsInSource(std::ostream& out);
140 void LocateMethodsInHeaderInline(std::ostream& out);
141 void LocateMethodsInHeaderClassDecl(std::ostream& out);
142 void LocateMethods(std::ostream& out, const char* filename,
143 Bool_t lookForSourceInfo = kTRUE,
144 Bool_t useDocxxStyle = kFALSE,
145 Bool_t allowPureVirtual = kFALSE,
146 const char* methodPattern = 0,
147 const char* sourceExt = 0);
148 virtual Bool_t ProcessComment();
149 void RemoveCommentContext(Bool_t cxxcomment);
150 void WriteClassDoc(std::ostream& out, Bool_t first = kTRUE);
151 void WriteMethod(std::ostream& out, TString& ret,
152 TString& name, TString& params,
153 Bool_t isconst,
154 const char* file, TString& anchor,
155 TString& codeOneLiner);
156 void WriteSourceLine(std::ostream& out);
157
158public:
159 TDocParser(TClassDocOutput& docOutput, TClass* cl);
160 TDocParser(TDocOutput& docOutput);
161 virtual ~TDocParser();
162
163 static void AnchorFromLine(const TString& line, TString& anchor);
164 void Convert(std::ostream& out, std::istream& in, const char* relpath,
165 Bool_t isCode, Bool_t interpretDirectives);
166 void DecrementMethodCount(const char* name);
167 virtual void DecorateKeywords(std::ostream& out, const char* text);
168 virtual void DecorateKeywords(TString& text);
169 virtual void DeleteDirectiveOutput() const;
170 const TList* GetMethods(EAccess access) const { return &fMethods[access]; }
172 void GetCurrentModule(TString& out_module) const;
173 TDocOutput* GetDocOutput() const { return fDocOutput; }
174 Long_t GetLineNumber() const { return fLineNumber; }
175 const TList* GetDataMembers(EAccess access) const { return &fDataMembers[access]; }
176 const TList* GetEnums(EAccess access) const { return &fDataMembers[access+3]; }
177 const char* GetSourceInfo(ESourceInfo type) const { return fSourceInfo[type]; }
178 void SetCurrentModule(const char* module) { fCurrentModule = module; }
179
180 UInt_t InContext(Int_t context) const;
181 static Bool_t IsName(UChar_t c);
182 static Bool_t IsWord(UChar_t c);
183
184 virtual void Parse(std::ostream& out);
185 static Bool_t Strip(TString& s);
186
187 ClassDef(TDocParser,0); // parser for reference documentation
188};
189
190#endif // ROOT_TDocParser
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:41
unsigned char UChar_t
Definition: RtypesCore.h:34
int Ssiz_t
Definition: RtypesCore.h:63
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:324
#define BIT(n)
Definition: Rtypes.h:82
int type
Definition: TGX11.cxx:120
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:33
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
virtual Int_t GetOverloadIdx() const =0
virtual TMethod * GetMethod() const =0
static void AnchorFromLine(const TString &line, TString &anchor)
Create an anchor from the given line, by hashing it and convertig the hash into a custom base64 strin...
Definition: TDocParser.cxx:381
static Bool_t IsWord(UChar_t c)
Check if c is a valid first character for C++ name.
EParseContext Context() const
Definition: TDocParser.h:129
EDocContext fDocContext
Definition: TDocParser.h:104
void LocateMethodsInSource(std::ostream &out)
Given fCurrentClass, look for methods in its source file, and extract documentation to out,...
void WriteClassDoc(std::ostream &out, Bool_t first=kTRUE)
Write the class description depending (among others) on fClassDocState.
TString fCurrentFile
Definition: TDocParser.h:102
TString fCurrentModule
Definition: TDocParser.h:98
std::set< UInt_t > fExtraLinesWithAnchor
Definition: TDocParser.h:120
const TList * GetMethods(EAccess access) const
Definition: TDocParser.h:170
const char * GetSourceInfo(ESourceInfo type) const
Definition: TDocParser.h:177
void LocateMethodsInHeaderClassDecl(std::ostream &out)
Given fCurrentClass, look for methods in its header file's class declaration block,...
virtual void ExpandCPPLine(TString &line, Ssiz_t &pos)
Expand preprocessor statements.
Definition: TDocParser.cxx:911
Long_t fLineNumber
Definition: TDocParser.h:101
THtml * fHtml
Definition: TDocParser.h:86
void SetCurrentModule(const char *module)
Definition: TDocParser.h:178
@ kNumParseContexts
Definition: TDocParser.h:76
@ kParseContextMask
Definition: TDocParser.h:77
TString fComment
Definition: TDocParser.h:93
TClass * fRecentClass
Definition: TDocParser.h:97
const TList * GetDataMembers(EAccess access) const
Definition: TDocParser.h:175
void LocateMethodsInHeaderInline(std::ostream &out)
Given fCurrentClass, look for methods in its header file, and extract documentation to out.
virtual TClass * IsDirective(const TString &line, Ssiz_t pos, const TString &word, Bool_t &begin) const
return whether word at line's pos is a valid directive, and returns its TDocDirective's TClass object...
TList fDirectiveHandlers
Definition: TDocParser.h:118
static std::set< std::string > fgKeywords
Definition: TDocParser.h:125
static Bool_t Strip(TString &s)
strips ' ', tabs, and newlines from both sides of str
void WriteMethod(std::ostream &out, TString &ret, TString &name, TString &params, Bool_t isconst, const char *file, TString &anchor, TString &codeOneLiner)
Write a method, forwarding to TClassDocOutput.
TMethod * LocateMethodInCurrentLine(Ssiz_t &posMethodName, TString &ret, TString &name, TString &params, Bool_t &isconst, std::ostream &srcOut, TString &anchor, std::ifstream &sourcefile, Bool_t allowPureVirtual)
Search for a method starting at posMethodName, and return its return type, its name,...
TClass * fCurrentClass
Definition: TDocParser.h:96
virtual void InitKeywords() const
fill C++ keywords into fgKeywords
void RemoveCommentContext(Bool_t cxxcomment)
remove the top-most comment context that matches cxxcomment,
Bool_t fCommentAtBOL
Definition: TDocParser.h:115
TString fSourceInfoTags[kNumSourceInfos]
Definition: TDocParser.h:117
@ kParseContextFlagMask
Definition: TDocParser.h:81
TString fLineSource
Definition: TDocParser.h:92
@ kNumDocContexts
Definition: TDocParser.h:50
TString fCurrentMethodTag
Definition: TDocParser.h:99
TString fSourceInfo[kNumSourceInfos]
Definition: TDocParser.h:121
TDocParser(TClassDocOutput &docOutput, TClass *cl)
Constructor called for parsing class sources.
Definition: TDocParser.cxx:150
void DecrementMethodCount(const char *name)
reduce method count for method called name, removing it from fMethodCounts once the count reaches 0.
Definition: TDocParser.cxx:869
virtual Bool_t ProcessComment()
Parse the current line as a comment, handling directives and re-formatting the comment: remove "/*",...
Bool_t fAllowDirectives
Definition: TDocParser.h:119
static Bool_t IsName(UChar_t c)
Check if c is a valid C++ name character.
UInt_t fLineNo
Definition: TDocParser.h:88
@ kInfoLastChanged
Definition: TDocParser.h:58
@ kNumSourceInfos
Definition: TDocParser.h:60
@ kInfoLastUpdate
Definition: TDocParser.h:55
@ kInfoCopyright
Definition: TDocParser.h:57
@ kInfoLastGenerated
Definition: TDocParser.h:59
virtual ~TDocParser()
destructor, checking whether all methods have been found for gDebug > 3
Definition: TDocParser.cxx:211
Long_t GetLineNumber() const
Definition: TDocParser.h:174
void GetCurrentModule(TString &out_module) const
Return the name of module for which sources are currently parsed.
Definition: TDocParser.cxx:967
void Convert(std::ostream &out, std::istream &in, const char *relpath, Bool_t isCode, Bool_t interpretDirectives)
Parse text file "in", add links etc, and write output to "out".
Definition: TDocParser.cxx:402
void LocateMethods(std::ostream &out, const char *filename, Bool_t lookForSourceInfo=kTRUE, Bool_t useDocxxStyle=kFALSE, Bool_t allowPureVirtual=kFALSE, const char *methodPattern=0, const char *sourceExt=0)
Collect methods from the source or header file called filename.
TString fFirstClassDoc
Definition: TDocParser.h:94
TDocOutput * GetDocOutput() const
Definition: TDocParser.h:173
std::list< UInt_t > fParseContext
Definition: TDocParser.h:105
THashList fMethods[3]
Definition: TDocParser.h:122
Bool_t fCheckForMethod
Definition: TDocParser.h:106
enum TDocParser::@86 fClassDocState
UInt_t InContext(Int_t context) const
checks whether we are in a parse context, return the entry closest to the current context.
void AddClassMethodsRecursively(TBaseClass *bc)
Add accessible (i.e.
Definition: TDocParser.cxx:235
const TList * GetEnums(EAccess access) const
Definition: TDocParser.h:176
TDocOutput * fDocOutput
Definition: TDocParser.h:87
std::map< std::string, Int_t > fMethodCounts
Definition: TDocParser.h:103
TString fLastClassDoc
Definition: TDocParser.h:95
void WriteSourceLine(std::ostream &out)
Write fLineSource to out.
TString fLineStripped
Definition: TDocParser.h:90
void AddClassDataMembersRecursively(TBaseClass *bc)
Add data members of fCurrentClass and of bc to datamembers, recursively.
Definition: TDocParser.cxx:306
TString fLineRaw
Definition: TDocParser.h:89
TString fClassDescrTag
Definition: TDocParser.h:116
virtual void DecorateKeywords(std::ostream &out, const char *text)
Expand keywords in text, writing to out.
Definition: TDocParser.cxx:450
TString fLineComment
Definition: TDocParser.h:91
virtual Bool_t HandleDirective(TString &keyword, Ssiz_t &pos, TString &word, Ssiz_t &copiedToCommentUpTo)
Process directives to the documentation engine, like "Begin_Html" / "End_Html", "Begin_Macro" / "End_...
Definition: TDocParser.cxx:977
virtual void DeleteDirectiveOutput() const
Delete output generated by prior runs of all known directives; the output file names might have chang...
Definition: TDocParser.cxx:884
TClass * GetCurrentClass() const
Definition: TDocParser.h:171
@ kClassDoc_Ignore
Definition: TDocParser.h:112
@ kClassDoc_NumStates
Definition: TDocParser.h:113
@ kClassDoc_Uninitialized
Definition: TDocParser.h:108
@ kClassDoc_Written
Definition: TDocParser.h:111
@ kClassDoc_LookingNothingFound
Definition: TDocParser.h:109
@ kClassDoc_LookingHaveSomething
Definition: TDocParser.h:110
Int_t fDirectiveCount
Definition: TDocParser.h:100
virtual void Parse(std::ostream &out)
Locate methods, starting in the source file, then inline, then immediately inside the class declarati...
TList fDataMembers[6]
Definition: TDocParser.h:123
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
Definition: THtml.h:40
A doubly linked list.
Definition: TList.h:44
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:131
TText * text
TLine * line
static constexpr double s
Definition: file.py:1
Definition: first.py:1