1 |
loizides |
1.1 |
// @(#)root/html:$Id: TDocParser.h 26807 2008-12-10 17:47:42Z axel $
|
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 |
|
|
#ifndef ROOT_TObject
|
28 |
|
|
#include "TObject.h"
|
29 |
|
|
#endif
|
30 |
|
|
#ifndef ROOT_TList
|
31 |
|
|
#include "TList.h"
|
32 |
|
|
#endif
|
33 |
|
|
#ifndef ROOT_TString
|
34 |
|
|
#include "TString.h"
|
35 |
|
|
#endif
|
36 |
|
|
#ifndef ROOT_Riosfwd
|
37 |
|
|
#include "Riosfwd.h"
|
38 |
|
|
#endif
|
39 |
|
|
|
40 |
|
|
class TBaseClass;
|
41 |
|
|
class TClass;
|
42 |
|
|
class TClassDocOutput;
|
43 |
|
|
class TDocOutput;
|
44 |
|
|
class THtml;
|
45 |
|
|
|
46 |
|
|
class TDocParser: public TObject {
|
47 |
|
|
protected:
|
48 |
|
|
enum EDocContext {
|
49 |
|
|
kIgnore,
|
50 |
|
|
kDocFunc,
|
51 |
|
|
kDocClass,
|
52 |
|
|
kNumDocContexts
|
53 |
|
|
};
|
54 |
|
|
|
55 |
|
|
public:
|
56 |
|
|
enum ESourceInfo {
|
57 |
|
|
kInfoLastUpdate,
|
58 |
|
|
kInfoAuthor,
|
59 |
|
|
kInfoCopyright,
|
60 |
|
|
kInfoLastChanged,
|
61 |
|
|
kInfoLastGenerated,
|
62 |
|
|
kNumSourceInfos
|
63 |
|
|
};
|
64 |
|
|
enum EAccess {
|
65 |
|
|
kPrivate,
|
66 |
|
|
kProtected,
|
67 |
|
|
kPublic
|
68 |
|
|
};
|
69 |
|
|
enum EParseContext {
|
70 |
|
|
kNoContext,
|
71 |
|
|
kCode,
|
72 |
|
|
kComment,
|
73 |
|
|
kDirective,
|
74 |
|
|
kString,
|
75 |
|
|
kKeyword,
|
76 |
|
|
kCPP,
|
77 |
|
|
kVerbatim,
|
78 |
|
|
kNumParseContexts,
|
79 |
|
|
kParseContextMask = BIT(4) - 1
|
80 |
|
|
};
|
81 |
|
|
enum EParseContextFlag {
|
82 |
|
|
kCXXComment = BIT(4), // kComment is a C++ comment, or macro/html/latex content is surrounded by /* */
|
83 |
|
|
kParseContextFlagMask = ~(BIT(4) - 1)
|
84 |
|
|
|
85 |
|
|
};
|
86 |
|
|
|
87 |
|
|
class TMethodWrapper: public TObject {
|
88 |
|
|
public:
|
89 |
|
|
virtual const TMethod* GetMethod() const = 0;
|
90 |
|
|
};
|
91 |
|
|
|
92 |
|
|
protected:
|
93 |
|
|
THtml* fHtml; // THtml object using us
|
94 |
|
|
TDocOutput* fDocOutput; // TDocOutput invoking us
|
95 |
|
|
UInt_t fLineNo; // current line number
|
96 |
|
|
TString fLineRaw; // current line
|
97 |
|
|
TString fLineStripped; // current line without surrounding spaces
|
98 |
|
|
TString fLineComment; // current line with links and directives for doc
|
99 |
|
|
TString fLineSource; // current line with links
|
100 |
|
|
TString fComment; // current comment
|
101 |
|
|
TString fFirstClassDoc; // first class-doc found - per file, taken if fLastClassDoc is empty
|
102 |
|
|
TString fLastClassDoc; // last class-doc found - becomes class doc at ClassImp or first method
|
103 |
|
|
TClass* fCurrentClass; // current class context of sources being parsed
|
104 |
|
|
TClass* fRecentClass; // recently seen class context of sources being parsed, e.g. for Convert()
|
105 |
|
|
TString fCurrentModule; // current module context of sources being parsed
|
106 |
|
|
TString fCurrentMethodTag;// name_idx of the currently parsed method
|
107 |
|
|
Int_t fDirectiveCount; // index of directive for current method
|
108 |
|
|
TString fCurrentFile; // current source / header file name
|
109 |
|
|
std::map<std::string /*name*/, Int_t > fMethodCounts; // current class's method names
|
110 |
|
|
EDocContext fDocContext; // current context of parsed sources for documenting
|
111 |
|
|
std::list<UInt_t> fParseContext; // current context of parsed sources
|
112 |
|
|
Bool_t fCheckForMethod; // whether to check the current line for a method
|
113 |
|
|
enum {
|
114 |
|
|
kClassDoc_Uninitialized,
|
115 |
|
|
kClassDoc_LookingNothingFound,
|
116 |
|
|
kClassDoc_LookingHaveSomething,
|
117 |
|
|
kClassDoc_Written,
|
118 |
|
|
kClassDoc_Ignore,
|
119 |
|
|
kClassDoc_NumStates
|
120 |
|
|
} fClassDocState; // whether we found the class description
|
121 |
|
|
Bool_t fCommentAtBOL; // at the beginning of the current line, fParseContext contained kComment
|
122 |
|
|
TString fClassDescrTag; // tag for finding the class description
|
123 |
|
|
TString fSourceInfoTags[kNumSourceInfos]; // tags for source info elements (copyright, last changed, author)
|
124 |
|
|
TList fDirectiveHandlers;// handler for doc directives (TDocDirective objects)
|
125 |
|
|
std::set<UInt_t> fExtraLinesWithAnchor; // lines that need an additional anchor
|
126 |
|
|
TString fSourceInfo[kNumSourceInfos];// author, last changed, ...
|
127 |
|
|
TList fMethods[3]; // methods as TMethodWrapper objects (by access)
|
128 |
|
|
TList fDataMembers[6]; // data members (by access, plus enums)
|
129 |
|
|
|
130 |
|
|
static std::set<std::string> fgKeywords; // C++ keywords
|
131 |
|
|
|
132 |
|
|
void AddClassMethodsRecursively(TBaseClass* bc);
|
133 |
|
|
void AddClassDataMembersRecursively(TBaseClass* bc);
|
134 |
|
|
EParseContext Context() const { return fParseContext.empty() ? kComment : (EParseContext)(fParseContext.back() & kParseContextMask); }
|
135 |
|
|
virtual void ExpandCPPLine(TString& line, Ssiz_t& pos);
|
136 |
|
|
virtual Bool_t HandleDirective(TString& keyword, Ssiz_t& pos,
|
137 |
|
|
TString& word, Ssiz_t& copiedToCommentUpTo);
|
138 |
|
|
virtual void InitKeywords() const;
|
139 |
|
|
virtual TClass* IsDirective(const TString& line, Ssiz_t pos, const TString& word, Bool_t& begin) const;
|
140 |
|
|
TMethod* LocateMethodInCurrentLine(Ssiz_t& posMethodName, TString& ret,
|
141 |
|
|
TString& name, TString& params, std::ostream &srcOut, TString &anchor,
|
142 |
|
|
std::ifstream& sourcefile, Bool_t allowPureVirtual);
|
143 |
|
|
void LocateMethodsInSource(std::ostream& out);
|
144 |
|
|
void LocateMethodsInHeaderInline(std::ostream& out);
|
145 |
|
|
void LocateMethodsInHeaderClassDecl(std::ostream& out);
|
146 |
|
|
void LocateMethods(std::ostream& out, const char* filename,
|
147 |
|
|
Bool_t lookForSourceInfo = kTRUE,
|
148 |
|
|
Bool_t useDocxxStyle = kFALSE,
|
149 |
|
|
Bool_t allowPureVirtual = kFALSE,
|
150 |
|
|
const char* methodPattern = 0,
|
151 |
|
|
const char* sourceExt = 0);
|
152 |
|
|
virtual Bool_t ProcessComment();
|
153 |
|
|
void RemoveCommentContext(Bool_t cxxcomment);
|
154 |
|
|
void WriteClassDoc(std::ostream& out, Bool_t first = kTRUE);
|
155 |
|
|
void WriteMethod(std::ostream& out, TString& ret,
|
156 |
|
|
TString& name, TString& params,
|
157 |
|
|
const char* file, TString& anchor,
|
158 |
|
|
TString& codeOneLiner);
|
159 |
|
|
void WriteSourceLine(std::ostream& out);
|
160 |
|
|
|
161 |
|
|
public:
|
162 |
|
|
TDocParser(TClassDocOutput& docOutput, TClass* cl);
|
163 |
|
|
TDocParser(TDocOutput& docOutput);
|
164 |
|
|
virtual ~TDocParser();
|
165 |
|
|
|
166 |
|
|
static void AnchorFromLine(const TString& line, TString& anchor);
|
167 |
|
|
void Convert(std::ostream& out, std::istream& in, const char* relpath,
|
168 |
|
|
Bool_t isCode);
|
169 |
|
|
void DecrementMethodCount(const char* name);
|
170 |
|
|
virtual void DecorateKeywords(std::ostream& out, const char* text);
|
171 |
|
|
virtual void DecorateKeywords(TString& text);
|
172 |
|
|
virtual void DeleteDirectiveOutput() const;
|
173 |
|
|
const TList* GetMethods(EAccess access) const { return &fMethods[access]; }
|
174 |
|
|
TClass* GetCurrentClass() const { return fCurrentClass; }
|
175 |
|
|
void GetCurrentModule(TString& out_module) const;
|
176 |
|
|
TDocOutput* GetDocOutput() const { return fDocOutput; }
|
177 |
|
|
const TList* GetDataMembers(EAccess access) const { return &fDataMembers[access]; }
|
178 |
|
|
const TList* GetEnums(EAccess access) const { return &fDataMembers[access+3]; }
|
179 |
|
|
const char* GetSourceInfo(ESourceInfo type) const { return fSourceInfo[type]; }
|
180 |
|
|
void SetCurrentModule(const char* module) { fCurrentModule = module; }
|
181 |
|
|
|
182 |
|
|
UInt_t InContext(Int_t context) const;
|
183 |
|
|
static Bool_t IsName(UChar_t c);
|
184 |
|
|
static Bool_t IsWord(UChar_t c);
|
185 |
|
|
|
186 |
|
|
virtual void Parse(std::ostream& out);
|
187 |
|
|
static Bool_t Strip(TString& s);
|
188 |
|
|
|
189 |
|
|
ClassDef(TDocParser,0); // parser for reference documentation
|
190 |
|
|
};
|
191 |
|
|
|
192 |
|
|
#endif // ROOT_TDocParser
|