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 240 of file codefragment.cpp.

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

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: