Doxygen
Loading...
Searching...
No Matches
CodeFragmentManager Class Reference

#include <src/codefragment.h>

Classes

struct  Private
 

Public Member Functions

void parseCodeFragment (OutputCodeList &codeOutList, const QCString &fileName, const QCString &blockId, const QCString &scopeName, bool showLineNumbers, bool trimLeft, bool stripCodeComments)
 

Static Public Member Functions

static CodeFragmentManagerinstance ()
 

Private Member Functions

 CodeFragmentManager ()
 
 ~CodeFragmentManager ()
 

Private Attributes

std::unique_ptr< Privatep
 

Detailed Description

Definition at line 29 of file codefragment.h.

Constructor & Destructor Documentation

◆ CodeFragmentManager()

CodeFragmentManager::CodeFragmentManager ( )
private

Definition at line 183 of file codefragment.cpp.

183 : p(std::make_unique<Private>())
184{
185}
std::unique_ptr< Private > p

References p.

Referenced by instance(), and ~CodeFragmentManager().

◆ ~CodeFragmentManager()

CodeFragmentManager::~CodeFragmentManager ( )
privatedefault

References CodeFragmentManager().

Member Function Documentation

◆ instance()

◆ parseCodeFragment()

void CodeFragmentManager::parseCodeFragment ( OutputCodeList & codeOutList,
const QCString & fileName,
const QCString & blockId,
const QCString & scopeName,
bool showLineNumbers,
bool trimLeft,
bool stripCodeComments )

Definition at line 238 of file codefragment.cpp.

246{
247 AUTO_TRACE("CodeFragmentManager::parseCodeFragment({},blockId={},scopeName={},showLineNumber={},trimLeft={},stripCodeComments={}",
248 fileName, blockId, scopeName, showLineNumbers, trimLeft, stripCodeComments);
249 std::string fragmentKey=fileName.str()+":"+scopeName.str();
250 std::unordered_map< std::string,std::unique_ptr<Private::FragmentInfo> >::iterator it;
251 bool inserted = false;
252 {
253 // create new entry if it is not yet in the map
254 std::lock_guard lock(p->mutex);
255 it = p->fragments.find(fragmentKey);
256 if (it == p->fragments.end())
257 {
258 it = p->fragments.emplace(fragmentKey, std::make_unique<Private::FragmentInfo>()).first;
259 inserted = true;
260 AUTO_TRACE_ADD("new fragment");
261 }
262 }
263 // only lock the one item we are working with
264 auto &codeFragment = it->second;
265 std::lock_guard lock(codeFragment->mutex);
266 if (inserted) // new entry, need to parse the file and record the output and cache it
267 {
268 SrcLangExt langExt = getLanguageFromFileName(fileName);
269 FileInfo cfi( fileName.str() );
270 auto fd = createFileDef( cfi.dirPath(), cfi.fileName() );
272 intf->resetCodeParserState();
273 bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
274 bool needs2PassParsing =
275 Doxygen::parseSourcesNeeded && // we need to parse (filtered) sources for cross-references
276 !filterSourceFiles && // but user wants to show sources as-is
277 !getFileFilter(fileName,TRUE).isEmpty(); // and there is a filter used while parsing
278 codeFragment->fileContents = readTextFileByName(fileName);
279 //printf("fileContents=[%s]\n",qPrint(codeFragment->fileContents));
280 if (needs2PassParsing)
281 {
282 OutputCodeList devNullList;
283 devNullList.add<DevNullCodeGenerator>();
284 intf->parseCode(devNullList,
285 scopeName,
286 codeFragment->fileContents,
287 langExt,
288 stripCodeComments, // actually not important here
289 false,
290 QCString()
291 );
292 }
293 codeFragment->findBlockMarkers();
294 if (codeFragment->fileContents.length()>0) // parse the normal version
295 {
296 intf->parseCode(codeFragment->recorderCodeList,
297 scopeName,
298 codeFragment->fileContents,
299 langExt, // lang
300 false, // strip code comments (overruled before replaying)
301 false, // isExampleBlock
302 QCString(), // exampleName
303 fd.get(), // fileDef
304 -1, // startLine
305 -1, // endLine
306 true, // inlineFragment
307 nullptr, // memberDef
308 true, // showLineNumbers
309 nullptr, // searchCtx
310 false // collectXRefs
311 );
312 }
313 }
314 // use the recorded OutputCodeList from the cache to output a pre-recorded fragment
315 auto blockKv = codeFragment->blocksById.find(blockId.str());
316 if (blockKv != codeFragment->blocksById.end())
317 {
318 const auto &marker = blockKv->second;
319 int startLine = marker->lines[0];
320 int endLine = marker->lines[1];
321 int indent = marker->indent;
322 AUTO_TRACE_ADD("replay(start={},end={},indent={}) fileContentsTrimLeft.empty()={}",
323 startLine,endLine,indent,codeFragment->fileContentsTrimLeft.isEmpty());
324 auto recorder = codeFragment->recorderCodeList.get<OutputCodeRecorder>(OutputType::Recorder);
325 recorder->replay(codeOutList,
326 startLine+1,
327 endLine,
328 showLineNumbers,
329 stripCodeComments,
330 trimLeft ? static_cast<size_t>(indent) : 0
331 );
332 }
333 else
334 {
335 AUTO_TRACE_ADD("block not found!");
336 }
337}
static bool parseSourcesNeeded
Definition doxygen.h:123
static ParserManager * parserManager
Definition doxygen.h:131
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:194
std::unique_ptr< CodeParserInterface > getCodeParser(const QCString &extension)
Gets the interface to the parser associated with a given extension.
Definition parserintf.h:218
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:537
static QCString readTextFileByName(const QCString &file)
#define Config_getBool(name)
Definition config.h:33
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:47
#define AUTO_TRACE(...)
Definition docnode.cpp:46
std::unique_ptr< FileDef > createFileDef(const QCString &p, const QCString &n, const QCString &ref, const QCString &dn)
Definition filedef.cpp:267
#define TRUE
Definition qcstring.h:37
SrcLangExt
Language as given by extension.
Definition types.h:42
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
Definition util.cpp:5645
QCString getFileFilter(const QCString &name, bool isSourceCode)
Definition util.cpp:1342
QCString getFileNameExtension(const QCString &fn)
Definition util.cpp:5687

References OutputCodeList::add(), AUTO_TRACE, AUTO_TRACE_ADD, Config_getBool, createFileDef(), FileInfo::dirPath(), FileInfo::fileName(), getFileFilter(), getFileNameExtension(), getLanguageFromFileName(), QCString::isEmpty(), p, Doxygen::parserManager, Doxygen::parseSourcesNeeded, readTextFileByName(), Recorder, OutputCodeRecorder::replay(), QCString::str(), and TRUE.

Referenced by DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), ManDocVisitor::operator()(), RTFDocVisitor::operator()(), and XmlDocVisitor::operator()().

Member Data Documentation

◆ p

std::unique_ptr<Private> CodeFragmentManager::p
private

Definition at line 47 of file codefragment.h.

Referenced by CodeFragmentManager(), and parseCodeFragment().


The documentation for this class was generated from the following files: